Browse Source

publish muk_web_utils - 12.0

pull/35/head
MuK IT GmbH 6 years ago
parent
commit
572a513a59
  1. 113
      muk_web_utils/static/src/js/fields/share.js
  2. 28
      muk_web_utils/static/src/scss/share.scss
  3. 26
      muk_web_utils/static/src/xml/share.xml

113
muk_web_utils/static/src/js/fields/share.js

@ -27,53 +27,56 @@ var registry = require('web.field_registry');
var utils = require('muk_web_utils.utils'); var utils = require('muk_web_utils.utils');
var AbstractField = require('web.AbstractField');
var _t = core._t; var _t = core._t;
var QWeb = core.qweb; var QWeb = core.qweb;
var CharShare = fields.CharCopyClipboard.extend({
events: _.extend({}, fields.CharCopyClipboard.prototype.events, {
var ShareMixin = {
fieldDependencies: _.extend({}, AbstractField.prototype.fieldDependencies, {
display_name: {type: 'char'},
}),
events: _.extend({}, fields.InputField.prototype.events, {
'click .mk_share_dropdown_message': '_onShareMessageClick', 'click .mk_share_dropdown_message': '_onShareMessageClick',
'click .mk_share_dropdown_note': '_onShareNoteClick', 'click .mk_share_dropdown_note': '_onShareNoteClick',
'click .mk_share_dropdown_mail': '_onShareMailClick', 'click .mk_share_dropdown_mail': '_onShareMailClick',
'click .mk_share_dropdown_send': '_onShareSendClick', 'click .mk_share_dropdown_send': '_onShareSendClick',
}), }),
init: function(parent, name, record) {
init: function(parent, name, record) {
this._super.apply(this, arguments); this._super.apply(this, arguments);
this.fields = record.fields;
this.navigator = window.navigator.share; this.navigator = window.navigator.share;
this.chatter = _.contains(odoo._modules, "mail"); this.chatter = _.contains(odoo._modules, "mail");
this.shareOptions = _.defaults(this.nodeOptions, {
subjectTemplate: _t("<%= name %> shared a message!"),
textTemplate: _t("<%= value %>"),
bodyTemplate: 'muk_web_utils.ShareMessage',
});
this.shareOptions = _.extend({}, this.shareOptions, {
res_model: this.recordData[this.nodeOptions.res_model] || this.model,
res_id: this.recordData[this.nodeOptions.res_id] || this.res_id,
});
}, },
_render: function() {
this._super.apply(this, arguments);
this.$el.addClass('mk_field_share');
this.$el.prepend($(QWeb.render('muk_web_utils.CharShare', {
navigator: !!this.navigator,
chatter: !!this.chatter,
})));
},
_getShareMessage: function() {
getShareMessageValues: function(message) {
var values = { var values = {
name: session.partner_display_name, name: session.partner_display_name,
record: this.recordData.display_name,
url: utils.isUrl(this.value) && this.value, url: utils.isUrl(this.value) && this.value,
text: this.value,
value: this.value,
}; };
var message = QWeb.render('muk_web_utils.ShareMessage', {
values: values,
});
return { return {
subject: values.name + _t(" shared a message!"),
url: values.url,
body: message,
subject: _.template(this.shareOptions.subjectTemplate)(values),
body: QWeb.render(this.shareOptions.bodyTemplate, values),
text: _.template(this.shareOptions.textTemplate)(values),
} }
}, },
_openShareChat: function(note) {
var values = this._getShareMessage();
openShareChat: function(note) {
var values = this.getShareMessageValues();
var context = { var context = {
default_is_log: !!note,
default_is_log: note,
default_body: values.body, default_body: values.body,
default_subject: values.subject, default_subject: values.subject,
default_model: this.recordData[this.attrs.res_model] || this.model,
default_res_id: this.recordData[this.attrs.res_id] || this.res_id,
default_model: this.shareOptions.res_model,
default_res_id: this.shareOptions.res_id,
mail_post_autofollow: false, mail_post_autofollow: false,
}; };
this.do_action({ this.do_action({
@ -89,40 +92,62 @@ var CharShare = fields.CharCopyClipboard.extend({
_onShareMessageClick: function(event) { _onShareMessageClick: function(event) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
this._openShareChat(false);
this.openShareChat(false);
}, },
_onShareNoteClick: function(event) { _onShareNoteClick: function(event) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
this._openShareChat(true);
this.openShareChat(true);
}, },
_onShareMailClick: function(event) { _onShareMailClick: function(event) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
var values = this._getShareMessage();
window.location.href = "mailto:?subject=" + values.subject + "&body=" + this.value;
var values = this.getShareMessageValues();
var subject = "subject=" + values.subject;
var body = "&body=" + encodeURIComponent(values.text);
window.location.href = "mailto:?" + subject + body;
}, },
_onShareSendClick: function(event) { _onShareSendClick: function(event) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
var values = this._getShareMessage();
if (values.url) {
navigator.share({
title: values.subject,
url: values.url,
});
} else {
navigator.share({
title: values.subject,
text: this.value,
});
}
var values = this.getShareMessageValues();
navigator.share({
title: values.subject,
text: values.text,
url: utils.isUrl(this.value) && this.value
});
}, },
};
var CharShare = fields.CharCopyClipboard.extend(ShareMixin, {
_render: function() {
this._super.apply(this, arguments);
this.$el.addClass('mk_field_share');
this.$el.prepend($(QWeb.render('muk_web_utils.CharShare', {
navigator: !!this.navigator,
chatter: !!this.chatter,
})));
},
});
var TextShare = fields.TextCopyClipboard.extend(ShareMixin, {
_render: function() {
this._super.apply(this, arguments);
this.$el.addClass('mk_field_share');
this.$el.prepend($(QWeb.render('muk_web_utils.TextShare', {
navigator: !!this.navigator,
chatter: !!this.chatter,
})));
}
}); });
registry.add('share', CharShare);
registry.add('share_char', CharShare);
registry.add('share_text', TextShare);
return CharShare;
return {
ShareMixin: ShareMixin,
CharShare: CharShare,
TextShare: TextShare,
};
}); });

28
muk_web_utils/static/src/scss/share.scss

@ -17,17 +17,21 @@
* *
**********************************************************************************/ **********************************************************************************/
.o_field_widget {
&.mk_field_share {
padding-left: 90px;
.mk_share_dropdown {
@include o-position-absolute($top: 0, $left: 0);
height: 100%;
.mk_share_button {
@include o-position-absolute($top: 0, $left: 0);
height: 100%;
padding: 0 10px;
}
}
.o_field_widget.mk_field_share {
padding-left: 90px;
.mk_share_dropdown {
@include o-position-absolute($top: 0, $left: 0);
.mk_share_button {
padding: 0 10px;
}
&.mk_share_char {
height: 100%;
}
&.mk_share_text {
.dropdown-menu {
line-height: 0.1
}
}
} }
} }

26
muk_web_utils/static/src/xml/share.xml

@ -19,8 +19,8 @@
<templates id="template" xml:space="preserve"> <templates id="template" xml:space="preserve">
<t t-name="muk_web_utils.CharShare">
<div class="btn-group mk_share_dropdown">
<t t-name="muk_web_utils.Share">
<div t-attf-class="btn-group mk_share_dropdown #{share_class}">
<button class="btn btn-sm btn-primary dropdown-toggle mk_share_button" type="button" data-toggle="dropdown"> <button class="btn btn-sm btn-primary dropdown-toggle mk_share_button" type="button" data-toggle="dropdown">
<span class="fa fa-share-alt"></span> <span class="fa fa-share-alt"></span>
<span>Share</span> <span>Share</span>
@ -49,17 +49,29 @@
</div> </div>
</t> </t>
<t t-name="muk_web_utils.CharShare">
<t t-call="muk_web_utils.Share">
<t t-set="share_class" t-value="'mk_share_char'"/>
</t>
</t>
<t t-name="muk_web_utils.TextShare">
<t t-call="muk_web_utils.Share">
<t t-set="share_class" t-value="'mk_share_text'"/>
</t>
</t>
<t t-name="muk_web_utils.ShareMessage"> <t t-name="muk_web_utils.ShareMessage">
<div> <div>
<t t-if="values.url">
<p><span t-esc="values.name"/> shared a link with you!</p>
<a t-attf-href="#{values.url}" style="background-color: #875A7B; padding: 10px; text-decoration: none; color: #fff; border-radius: 5px; font-size: 12px;">
<t t-if="url">
<p><span t-esc="name"/> shared a link with you!</p>
<a t-attf-href="#{url}" style="background-color: #875A7B; padding: 10px; text-decoration: none; color: #fff; border-radius: 5px; font-size: 12px;">
<strong>Open</strong> <strong>Open</strong>
</a> </a>
</t> </t>
<t t-else=""> <t t-else="">
<p><span t-esc="values.name"/> shared a message with you!</p>
<p t-esc="values.text" />
<p><span t-esc="name"/> shared a message with you!</p>
<p t-esc="value" />
</t> </t>
</div> </div>
</t> </t>

Loading…
Cancel
Save