Browse Source

publish muk_web_utils - 12.0

pull/35/head
MuK IT GmbH 6 years ago
parent
commit
fd297aa4e9
  1. 2
      muk_web_utils/__manifest__.py
  2. 164
      muk_web_utils/static/src/js/fields/share.js
  3. 40
      muk_web_utils/static/src/scss/share.scss
  4. 66
      muk_web_utils/static/src/xml/share.xml

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

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

40
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;
}
}
}
}

66
muk_web_utils/static/src/xml/share.xml

@ -25,27 +25,31 @@
<span class="fa fa-share-alt"></span>
<span>Share</span>
</button>
<div class="dropdown-menu">
<h6 class="dropdown-header">Internal</h6>
<a t-if="chatter" class="dropdown-item mk_share_dropdown_message" href="#">
<span class="fa fa-comments"></span>
<span>Message</span>
</a>
<a t-if="chatter" class="dropdown-item mk_share_dropdown_note" href="#">
<span class="fa fa-sticky-note-o"></span>
<span>Note</span>
</a>
<div class="dropdown-divider"></div>
<h6 class="dropdown-header">External</h6>
<a class="dropdown-item mk_share_dropdown_mail" href="#">
<span class="fa fa-envelope"></span>
<span>Mail</span>
</a>
<a t-if="navigator" class="dropdown-item mk_share_dropdown_send" href="#">
<span class="fa fa-paper-plane"></span>
<span>Send</span>
</a>
</div>
<t t-call="muk_web_utils.ShareDropdown" />
</div>
</t>
<t t-name="muk_web_utils.ShareDropdown">
<div class="dropdown-menu">
<h6 class="dropdown-header">Internal</h6>
<a t-if="chatter" class="dropdown-item mk_share_dropdown_message" href="#">
<span class="fa fa-comments"></span>
<span>Message</span>
</a>
<a t-if="chatter" class="dropdown-item mk_share_dropdown_note" href="#">
<span class="fa fa-sticky-note-o"></span>
<span>Note</span>
</a>
<div class="dropdown-divider"></div>
<h6 class="dropdown-header">External</h6>
<a class="dropdown-item mk_share_dropdown_mail" href="#">
<span class="fa fa-envelope"></span>
<span>Mail</span>
</a>
<a t-if="navigator" class="dropdown-item mk_share_dropdown_send" href="#">
<span class="fa fa-paper-plane"></span>
<span>Send</span>
</a>
</div>
</t>
@ -61,11 +65,20 @@
</t>
</t>
<t t-name="muk_web_utils.BinaryShare">
<div t-if="share" t-attf-class="btn-group mk_share_dropdown">
<button class="btn btn-sm btn-outline-primary dropdown-toggle mk_share_button" type="button" data-toggle="dropdown">
<span class="fa fa-share-alt"></span>
</button>
<t t-call="muk_web_utils.ShareDropdown" />
</div>
</t>
<t t-name="muk_web_utils.ShareMessage">
<div>
<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;">
<a t-attf-href="#{url}" target="_blank" style="background-color: #875A7B; padding: 10px; text-decoration: none; color: #fff; border-radius: 5px; font-size: 12px;">
<strong>Open</strong>
</a>
</t>
@ -76,4 +89,13 @@
</div>
</t>
<t t-name="muk_web_utils.ShareBinaryMessage">
<div>
<p><span t-esc="name"/> shared a file with you!</p>
<a t-attf-href="#{url}" target="_blank" style="background-color: #875A7B; padding: 10px; text-decoration: none; color: #fff; border-radius: 5px; font-size: 12px;">
<strong>Download</strong>
</a>
</div>
</t>
</templates>
Loading…
Cancel
Save