diff --git a/muk_web_utils/__manifest__.py b/muk_web_utils/__manifest__.py index 2fd0830..cbfa4cf 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.1.0", + "version": "12.0.2.2.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 c659e2d..8576dd3 100644 --- a/muk_web_utils/doc/changelog.rst +++ b/muk_web_utils/doc/changelog.rst @@ -1,6 +1,11 @@ `2.1.0` ------- +- Added widget to share text fields + +`2.1.0` +------- + - Automatic labels on settings `2.0.0` diff --git a/muk_web_utils/static/src/js/core/utils.js b/muk_web_utils/static/src/js/core/utils.js new file mode 100644 index 0000000..ecc19e8 --- /dev/null +++ b/muk_web_utils/static/src/js/core/utils.js @@ -0,0 +1,57 @@ +/********************************************************************************** +* +* 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.utils', function (require) { +"use strict"; + +var core = require('web.core'); + +var _t = core._t; +var QWeb = core.qweb; + +function isUrl(string) { + var protocolAndDomainRE = /^(?:\w+:)?\/\/(\S+)$/; + var localhostDomainRE = /^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/ + var nonLocalhostDomainRE = /^[^\s\.]+\.\S{2,}$/; + var match = string.match(protocolAndDomainRE); + if (!match) { + return false; + } + var everythingAfterProtocol = match[1]; + if (!everythingAfterProtocol) { + return false; + } + if (localhostDomainRE.test(everythingAfterProtocol) || nonLocalhostDomainRE.test(everythingAfterProtocol)) { + return true; + } + return false; +} + +function parseText2Html(text) { + return text + .replace(/((?:https?|ftp):\/\/[\S]+)/g,'$1 ') + .replace(/[\n\r]/g,'
'); +} + +return { + isUrl: isUrl, + parseText2Html: parseText2Html, +}; + +}); \ 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 new file mode 100644 index 0000000..f850490 --- /dev/null +++ b/muk_web_utils/static/src/js/fields/share.js @@ -0,0 +1,128 @@ +/********************************************************************************** +* +* 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.CharShare', 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 utils = require('muk_web_utils.utils'); + +var _t = core._t; +var QWeb = core.qweb; + +var CharShare = fields.CharCopyClipboard.extend({ + events: _.extend({}, fields.CharCopyClipboard.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.fields = record.fields; + this.navigator = window.navigator.share; + this.chatter = _.contains(odoo._modules, "mail"); + }, + _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() { + var values = { + name: session.partner_display_name, + url: utils.isUrl(this.value) && this.value, + text: this.value, + }; + var message = QWeb.render('muk_web_utils.ShareMessage', { + values: values, + }); + return { + subject: values.name + _t(" shared a message!"), + url: values.url, + body: message, + } + }, + _openShareChat: function(note) { + var values = this._getShareMessage(); + var context = { + default_is_log: !!note, + default_body: values.body, + 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, + mail_post_autofollow: false, + }; + this.do_action({ + type: 'ir.actions.act_window', + res_model: 'mail.compose.message', + view_mode: 'form', + view_type: 'form', + views: [[false, 'form']], + target: 'new', + context: context, + }); + }, + _onShareMessageClick: function(event) { + event.preventDefault(); + event.stopPropagation(); + this._openShareChat(false); + }, + _onShareNoteClick: function(event) { + event.preventDefault(); + event.stopPropagation(); + this._openShareChat(true); + }, + _onShareMailClick: function(event) { + event.preventDefault(); + event.stopPropagation(); + var values = this._getShareMessage(); + window.location.href = "mailto:?subject=" + values.subject + "&body=" + this.value; + }, + _onShareSendClick: function(event) { + event.preventDefault(); + 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, + }); + } + + }, +}); + +registry.add('share', CharShare); + +return CharShare; + +}); \ 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 new file mode 100644 index 0000000..7f163bc --- /dev/null +++ b/muk_web_utils/static/src/scss/share.scss @@ -0,0 +1,33 @@ +/********************************************************************************** +* +* 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_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; + } + } + } +} \ 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 new file mode 100644 index 0000000..076d47a --- /dev/null +++ b/muk_web_utils/static/src/xml/share.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + +
+ +

shared a link with you!

+ + Open + +
+ +

shared a message with you!

+

+ +

+
+ +
\ No newline at end of file diff --git a/muk_web_utils/template/assets.xml b/muk_web_utils/template/assets.xml index 09d7c71..12bb6a3 100644 --- a/muk_web_utils/template/assets.xml +++ b/muk_web_utils/template/assets.xml @@ -24,9 +24,12 @@ + + +