MuK IT GmbH
6 years ago
7 changed files with 294 additions and 1 deletions
-
2muk_web_utils/__manifest__.py
-
5muk_web_utils/doc/changelog.rst
-
57muk_web_utils/static/src/js/core/utils.js
-
128muk_web_utils/static/src/js/fields/share.js
-
33muk_web_utils/static/src/scss/share.scss
-
67muk_web_utils/static/src/xml/share.xml
-
3muk_web_utils/template/assets.xml
@ -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 <http://www.gnu.org/licenses/>.
|
|||
* |
|||
**********************************************************************************/ |
|||
|
|||
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,'<a href="$1">$1</a> ') |
|||
.replace(/[\n\r]/g,'<br/>'); |
|||
} |
|||
|
|||
return { |
|||
isUrl: isUrl, |
|||
parseText2Html: parseText2Html, |
|||
}; |
|||
|
|||
}); |
@ -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 <http://www.gnu.org/licenses/>.
|
|||
* |
|||
**********************************************************************************/ |
|||
|
|||
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; |
|||
|
|||
}); |
@ -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 <http://www.gnu.org/licenses/>. |
|||
* |
|||
**********************************************************************************/ |
|||
|
|||
.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; |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,67 @@ |
|||
<?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.CharShare"> |
|||
<div class="dropdown mk_share_dropdown"> |
|||
<button class="btn btn-sm btn-primary dropdown-toggle mk_share_button" type="button" data-toggle="dropdown"> |
|||
<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> |
|||
</div> |
|||
</t> |
|||
|
|||
<t t-name="muk_web_utils.ShareMessage"> |
|||
<div> |
|||
<t t-if="values.url"> |
|||
<p><span t-esc="values.name"/> shared a link with you!</p> |
|||
<a t-attf-href="#{values.url}" style="background-color: #875A7B; padding: 10px; text-decoration: none; color: #fff; border-radius: 5px; font-size: 12px;"> |
|||
<strong>Open</strong> |
|||
</a> |
|||
</t> |
|||
<t t-else=""> |
|||
<p><span t-esc="values.name"/> shared a message with you!</p> |
|||
<p t-esc="values.text" /> |
|||
</t> |
|||
</div> |
|||
</t> |
|||
|
|||
</templates> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue