diff --git a/muk_web_utils/__manifest__.py b/muk_web_utils/__manifest__.py
index 4fbbf10..3a8ab64 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.3.0",
+ "version": "12.0.2.4.0",
"category": "Extra Tools",
"license": "AGPL-3",
"author": "MuK IT",
diff --git a/muk_web_utils/doc/changelog.rst b/muk_web_utils/doc/changelog.rst
index c0b8c16..32da76c 100644
--- a/muk_web_utils/doc/changelog.rst
+++ b/muk_web_utils/doc/changelog.rst
@@ -1,3 +1,8 @@
+`2.4.0`
+-------
+
+- Added widget to share binary fields
+
`2.3.0`
-------
diff --git a/muk_web_utils/static/src/js/fields/copy.js b/muk_web_utils/static/src/js/fields/copy.js
new file mode 100644
index 0000000..07553b8
--- /dev/null
+++ b/muk_web_utils/static/src/js/fields/copy.js
@@ -0,0 +1,131 @@
+/**********************************************************************************
+*
+* Copyright (C) 2017 MuK IT GmbH
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*
+**********************************************************************************/
+
+odoo.define('muk_web_utils.copy', function (require) {
+"use strict";
+
+var core = require('web.core');
+var session = require('web.session');
+var fields = require('web.basic_fields');
+var registry = require('web.field_registry');
+
+var _t = core._t;
+var QWeb = core.qweb;
+
+var BinaryFileCopy = fields.FieldBinaryFile.extend({
+ 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.accessToken = !!this.nodeOptions.token;
+ },
+ willStart: function() {
+ var def = this.value && this.res_id ? this._fetchShareUrl() : $.when();
+ return $.when(this._super.apply(this, arguments), def);
+ },
+ start: function() {
+ var self = this;
+ var res = this._super.apply(this, arguments);
+ var $clipboardBtn = this.$('.mk_copy_binary');
+ this.clipboard = new ClipboardJS($clipboardBtn[0], {
+ text: function (trigger) {
+ return self.shareUrl;
+ },
+ container: self.$el[0]
+ });
+ this.clipboard.on('success', function (event) {
+ _.defer(function () {
+ $clipboardBtn.tooltip('show');
+ _.delay(function () {
+ $clipboardBtn.tooltip('hide');
+ }, 800);
+ });
+ });
+ $clipboardBtn.click(function(event) {
+ event.stopPropagation();
+ });
+ $clipboardBtn.tooltip({
+ title: _t('Link Copied!'),
+ trigger: 'manual',
+ placement: 'bottom'
+ });
+ return res;
+ },
+ _fetchShareUrl: function() {
+ var self = this;
+ var def = $.Deferred();
+ if (this.accessToken) {
+ 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();
+ });
+ });
+ } else {
+ this.shareUrl = session.url('/web/content', {
+ model: self.model,
+ field: self.name,
+ id: self.res_id,
+ });
+ def.resolve();
+ }
+ return def;
+ },
+ _renderReadonly: function () {
+ this._super.apply(this, arguments);
+ this.$el.addClass('mk_field_copy');
+ this.$el.append($(QWeb.render('muk_web_utils.BinaryFieldCopy')));
+ },
+ destroy: function () {
+ this._super.apply(this, arguments);
+ this.clipboard.destroy();
+ },
+});
+
+registry.add('binary_copy', BinaryFileCopy);
+
+return {
+ BinaryFileCopy: BinaryFileCopy,
+};
+
+});
\ No newline at end of file
diff --git a/muk_web_utils/static/src/js/fields/share.js b/muk_web_utils/static/src/js/fields/share.js
index 38f11c6..0175731 100644
--- a/muk_web_utils/static/src/js/fields/share.js
+++ b/muk_web_utils/static/src/js/fields/share.js
@@ -17,7 +17,7 @@
*
**********************************************************************************/
-odoo.define('muk_web_utils.CharShare', function (require) {
+odoo.define('muk_web_utils.share', function (require) {
"use strict";
var core = require('web.core');
@@ -26,8 +26,7 @@ var fields = require('web.basic_fields');
var registry = require('web.field_registry');
var utils = require('muk_web_utils.utils');
-
-var AbstractField = require('web.AbstractField');
+var copy = require('muk_web_utils.copy');
var _t = core._t;
var QWeb = core.qweb;
@@ -165,7 +164,7 @@ var TextShare = fields.TextCopyClipboard.extend(ShareMixin, {
}
});
-var BinaryShare = fields.FieldBinaryFile.extend(ShareMixin, {
+var BinaryFileShare = copy.BinaryFileCopy.extend(ShareMixin, {
fieldDependencies: _.extend({}, fields.FieldBinaryFile.fieldDependencies, {
display_name: {type: 'char'},
}),
@@ -177,12 +176,6 @@ var BinaryShare = fields.FieldBinaryFile.extend(ShareMixin, {
}),
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, {
@@ -195,10 +188,6 @@ var BinaryShare = fields.FieldBinaryFile.extend(ShareMixin, {
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,
@@ -212,37 +201,6 @@ var BinaryShare = fields.FieldBinaryFile.extend(ShareMixin, {
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);
@@ -257,13 +215,13 @@ var BinaryShare = fields.FieldBinaryFile.extend(ShareMixin, {
registry.add('share_char', CharShare);
registry.add('share_text', TextShare);
-registry.add('share_binary', BinaryShare);
+registry.add('share_binary', BinaryFileShare);
return {
ShareMixin: ShareMixin,
CharShare: CharShare,
TextShare: TextShare,
- BinaryShare: BinaryShare,
+ BinaryFileShare: BinaryFileShare,
};
});
\ No newline at end of file
diff --git a/muk_web_utils/static/src/scss/copy.scss b/muk_web_utils/static/src/scss/copy.scss
new file mode 100644
index 0000000..7daa798
--- /dev/null
+++ b/muk_web_utils/static/src/scss/copy.scss
@@ -0,0 +1,31 @@
+/**********************************************************************************
+*
+* Copyright (C) 2017 MuK IT GmbH
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*
+**********************************************************************************/
+
+.o_field_widget.mk_field_copy {
+ .mk_copy_binary {
+ margin-left: 0.5rem;
+ .mk_copy_button {
+ font-size: 0.8rem;
+ line-height: 0.5;
+ border-radius: 0.2rem;
+ margin-bottom: 0.12rem;
+ padding: 0.25rem 0.4rem;
+ }
+ }
+}
\ 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 72fc23c..8342f0c 100644
--- a/muk_web_utils/static/src/scss/share.scss
+++ b/muk_web_utils/static/src/scss/share.scss
@@ -38,7 +38,7 @@
}
&.o_form_uri {
.mk_share_dropdown {
- margin-left: 0.5rem;
+ margin-left: 0.2rem;
.mk_share_button {
padding: 0.25rem 0.4rem;
font-size: 0.8rem;
diff --git a/muk_web_utils/static/src/xml/copy.xml b/muk_web_utils/static/src/xml/copy.xml
new file mode 100644
index 0000000..97ff3f7
--- /dev/null
+++ b/muk_web_utils/static/src/xml/copy.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/muk_web_utils/template/assets.xml b/muk_web_utils/template/assets.xml
index 80e4594..9325b4e 100644
--- a/muk_web_utils/template/assets.xml
+++ b/muk_web_utils/template/assets.xml
@@ -34,11 +34,13 @@
+
+