Browse Source

publish muk_web_utils - 12.0

pull/35/head
MuK IT GmbH 6 years ago
parent
commit
79ef45fd7d
  1. 2
      muk_web_utils/__manifest__.py
  2. 5
      muk_web_utils/doc/changelog.rst
  3. 131
      muk_web_utils/static/src/js/fields/copy.js
  4. 52
      muk_web_utils/static/src/js/fields/share.js
  5. 31
      muk_web_utils/static/src/scss/copy.scss
  6. 2
      muk_web_utils/static/src/scss/share.scss
  7. 30
      muk_web_utils/static/src/xml/copy.xml
  8. 2
      muk_web_utils/template/assets.xml

2
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",

5
muk_web_utils/doc/changelog.rst

@ -1,3 +1,8 @@
`2.4.0`
-------
- Added widget to share binary fields
`2.3.0`
-------

131
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 <http://www.gnu.org/licenses/>.
*
**********************************************************************************/
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,
};
});

52
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,
};
});

31
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 <http://www.gnu.org/licenses/>.
*
**********************************************************************************/
.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;
}
}
}

2
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;

30
muk_web_utils/static/src/xml/copy.xml

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2018 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 <http://www.gnu.org/licenses/>.
-->
<templates id="template" xml:space="preserve">
<t t-name="muk_web_utils.BinaryFieldCopy">
<div class="d-inline-block mk_copy_binary">
<button class="btn btn-sm btn-outline-primary mk_copy_button" type="button">
<span class="fa fa-clipboard"></span>
</button>
</div>
</t>
</templates>

2
muk_web_utils/template/assets.xml

@ -34,11 +34,13 @@
<link rel="stylesheet" type="text/scss" href="/muk_web_utils/static/src/scss/variables.scss" />
<link rel="stylesheet" type="text/scss" href="/muk_web_utils/static/src/scss/switch.scss" />
<link rel="stylesheet" type="text/scss" href="/muk_web_utils/static/src/scss/module.scss" />
<link rel="stylesheet" type="text/scss" href="/muk_web_utils/static/src/scss/copy.scss" />
<link rel="stylesheet" type="text/scss" href="/muk_web_utils/static/src/scss/share.scss" />
</xpath>
<xpath expr="//script[last()]" position="after">
<script type="text/javascript" src="/muk_web_utils/static/src/js/core/utils.js"></script>
<script type="text/javascript" src="/muk_web_utils/static/src/js/fields/module.js"></script>
<script type="text/javascript" src="/muk_web_utils/static/src/js/fields/copy.js"></script>
<script type="text/javascript" src="/muk_web_utils/static/src/js/fields/share.js"></script>
<script type="text/javascript" src="/muk_web_utils/static/src/js/views/form/renderer.js"></script>
</xpath>

Loading…
Cancel
Save