From fd297aa4e919a37c68248381ef841c0b26222ba1 Mon Sep 17 00:00:00 2001 From: MuK IT GmbH Date: Sun, 4 Nov 2018 01:49:13 +0000 Subject: [PATCH] publish muk_web_utils - 12.0 --- muk_web_utils/__manifest__.py | 2 +- muk_web_utils/static/src/js/fields/share.js | 164 +++++++++++++++++--- muk_web_utils/static/src/scss/share.scss | 40 +++-- muk_web_utils/static/src/xml/share.xml | 66 +++++--- 4 files changed, 212 insertions(+), 60 deletions(-) diff --git a/muk_web_utils/__manifest__.py b/muk_web_utils/__manifest__.py index cbfa4cf..666484f 100644 --- a/muk_web_utils/__manifest__.py +++ b/muk_web_utils/__manifest__.py @@ -20,7 +20,7 @@ { "name": "MuK Web Utils", "summary": """Utility Features""", - "version": "12.0.2.2.0", + "version": "12.0.2.2.1", "category": "Extra Tools", "license": "AGPL-3", "author": "MuK IT", diff --git a/muk_web_utils/static/src/js/fields/share.js b/muk_web_utils/static/src/js/fields/share.js index edc4fc6..38f11c6 100644 --- a/muk_web_utils/static/src/js/fields/share.js +++ b/muk_web_utils/static/src/js/fields/share.js @@ -33,29 +33,6 @@ var _t = core._t; var QWeb = core.qweb; 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_note': '_onShareNoteClick', - 'click .mk_share_dropdown_mail': '_onShareMailClick', - 'click .mk_share_dropdown_send': '_onShareSendClick', - }), - init: function(parent, name, record) { - this._super.apply(this, arguments); - this.navigator = window.navigator.share; - 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, - }); - }, getShareMessageValues: function(message) { var values = { name: session.partner_display_name, @@ -67,6 +44,7 @@ var ShareMixin = { subject: _.template(this.shareOptions.subjectTemplate)(values), body: QWeb.render(this.shareOptions.bodyTemplate, values), text: _.template(this.shareOptions.textTemplate)(values), + url: utils.isUrl(this.value) && this.value, } }, openShareChat: function(note) { @@ -114,12 +92,35 @@ var ShareMixin = { navigator.share({ title: values.subject, text: values.text, - url: utils.isUrl(this.value) && this.value + url: values.url, }); }, }; var CharShare = fields.CharCopyClipboard.extend(ShareMixin, { + fieldDependencies: _.extend({}, fields.CharCopyClipboard.fieldDependencies, { + display_name: {type: 'char'}, + }), + events: _.extend({}, fields.CharCopyClipboard.events, { + 'click .mk_share_dropdown_message': '_onShareMessageClick', + 'click .mk_share_dropdown_note': '_onShareNoteClick', + 'click .mk_share_dropdown_mail': '_onShareMailClick', + 'click .mk_share_dropdown_send': '_onShareSendClick', + }), + init: function(parent, name, record) { + this._super.apply(this, arguments); + this.navigator = window.navigator.share; + 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'); @@ -131,6 +132,29 @@ var CharShare = fields.CharCopyClipboard.extend(ShareMixin, { }); var TextShare = fields.TextCopyClipboard.extend(ShareMixin, { + fieldDependencies: _.extend({}, fields.TextCopyClipboard.fieldDependencies, { + display_name: {type: 'char'}, + }), + events: _.extend({}, fields.TextCopyClipboard.events, { + 'click .mk_share_dropdown_message': '_onShareMessageClick', + 'click .mk_share_dropdown_note': '_onShareNoteClick', + 'click .mk_share_dropdown_mail': '_onShareMailClick', + 'click .mk_share_dropdown_send': '_onShareSendClick', + }), + init: function(parent, name, record) { + this._super.apply(this, arguments); + this.navigator = window.navigator.share; + 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'); @@ -141,13 +165,105 @@ var TextShare = fields.TextCopyClipboard.extend(ShareMixin, { } }); +var BinaryShare = fields.FieldBinaryFile.extend(ShareMixin, { + fieldDependencies: _.extend({}, fields.FieldBinaryFile.fieldDependencies, { + display_name: {type: 'char'}, + }), + events: _.extend({}, fields.FieldBinaryFile.events, { + 'click .mk_share_dropdown_message': '_onShareMessageClick', + 'click .mk_share_dropdown_note': '_onShareNoteClick', + 'click .mk_share_dropdown_mail': '_onShareMailClick', + 'click .mk_share_dropdown_send': '_onShareSendClick', + }), + init: function () { + this._super.apply(this, arguments); + if (!this.field.attachment) { + throw _.str.sprintf(_t( + "The field '%s' must be a binary field with an set " + + "attachment flag for the share widget to work." + ), this.field.string); + } + this.navigator = window.navigator.share; + this.chatter = _.contains(odoo._modules, "mail"); + this.shareOptions = _.defaults(this.nodeOptions, { + subjectTemplate: _t("<%= name %> shared a file!"), + textTemplate: _t("<%= value %>"), + bodyTemplate: 'muk_web_utils.ShareBinaryMessage', + }); + 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, + }); + }, + willStart: function() { + var def = this.value && this.res_id ? this._fetchShareUrl() : $.when(); + return $.when(this._super.apply(this, arguments), def); + }, + getShareMessageValues: function() { + var values = { + name: session.partner_display_name, + record: this.recordData.display_name, + url: this.shareUrl, + value: this.shareUrl, + }; + return { + subject: _.template(this.shareOptions.subjectTemplate)(values), + body: QWeb.render(this.shareOptions.bodyTemplate, values), + text: _.template(this.shareOptions.textTemplate)(values), + url: this.shareUrl, + } + }, + _fetchShareUrl: function() { + var self = this; + var def = $.Deferred(); + this._rpc({ + model: 'ir.attachment', + method: 'search', + args: [[ + ['res_id', '=', this.res_id], + ['res_field', '=', this.name], + ['res_model', '=', this.model], + ]], + kwargs: { + context: session.user_context, + }, + }).then(function(attchments) { + self._rpc({ + model: 'ir.attachment', + method: 'generate_access_token', + args: attchments + }).then(function(access_token) { + self.shareUrl = session.url('/web/content', { + model: self.model, + field: self.name, + id: self.res_id, + access_token: access_token.shift(), + }); + def.resolve(); + }); + }); + return def; + }, + _renderReadonly: function () { + this._super.apply(this, arguments); + this.$el.addClass('mk_field_share'); + this.$el.append($(QWeb.render('muk_web_utils.BinaryShare', { + navigator: !!this.navigator, + chatter: !!this.chatter, + share: !!this.shareUrl, + }))); + }, +}); + registry.add('share_char', CharShare); registry.add('share_text', TextShare); +registry.add('share_binary', BinaryShare); return { ShareMixin: ShareMixin, CharShare: CharShare, TextShare: TextShare, + BinaryShare: BinaryShare, }; }); \ No newline at end of file diff --git a/muk_web_utils/static/src/scss/share.scss b/muk_web_utils/static/src/scss/share.scss index 5a17d8f..72fc23c 100644 --- a/muk_web_utils/static/src/scss/share.scss +++ b/muk_web_utils/static/src/scss/share.scss @@ -18,20 +18,34 @@ **********************************************************************************/ .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%; - + &.o_field_copy { + 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 + } + } } - &.mk_share_text { - .dropdown-menu { - line-height: 0.1 - } + } + &.o_form_uri { + .mk_share_dropdown { + margin-left: 0.5rem; + .mk_share_button { + padding: 0.25rem 0.4rem; + font-size: 0.8rem; + line-height: 0.5; + border-radius: 0.2rem; + margin-bottom: 0.12rem; + } } } } \ No newline at end of file diff --git a/muk_web_utils/static/src/xml/share.xml b/muk_web_utils/static/src/xml/share.xml index b7b92c7..e080565 100644 --- a/muk_web_utils/static/src/xml/share.xml +++ b/muk_web_utils/static/src/xml/share.xml @@ -25,27 +25,31 @@ Share - + + + + + + @@ -61,11 +65,20 @@ + +
+ + +
+
+

shared a link with you!

- + Open
@@ -76,4 +89,13 @@
+ +
+

shared a file with you!

+ + Download + +
+
+ \ No newline at end of file