[REF] various addons: update to the new module system
This commit is contained in:
@@ -1,9 +1,16 @@
|
||||
openerp.mail_tip = function(session) {
|
||||
session.mail.Thread.include({
|
||||
message_fetch: function() {
|
||||
return this._super.apply(this, arguments).done(function() {
|
||||
openerp.web.bus.trigger('chatter_messages_fetched');
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
odoo.define(['mail.mail', 'web.core'], function (require) {
|
||||
"use strict";
|
||||
|
||||
var mail = require('mail.mail');
|
||||
var core = require('web.core');
|
||||
|
||||
mail.Thread.include({
|
||||
message_fetch: function() {
|
||||
return this._super.apply(this, arguments).done(function() {
|
||||
core.bus.trigger('chatter_messages_fetched');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -1,88 +1,91 @@
|
||||
openerp.pad = function(instance) {
|
||||
var _t = instance.web._t;
|
||||
|
||||
instance.web.form.FieldPad = instance.web.form.AbstractField.extend(instance.web.form.ReinitializeWidgetMixin, {
|
||||
template: 'FieldPad',
|
||||
content: "",
|
||||
init: function() {
|
||||
var self = this;
|
||||
this._super.apply(this, arguments);
|
||||
this._configured_deferred = this.view.dataset.call('pad_is_configured').done(function(data) {
|
||||
self.set("configured", !!data);
|
||||
}).fail(function(data, event) {
|
||||
event.preventDefault();
|
||||
self.set("configured", true);
|
||||
});
|
||||
this.pad_loading_request = null;
|
||||
},
|
||||
initialize_content: function() {
|
||||
var self = this;
|
||||
this.$('.oe_pad_switch').click(function() {
|
||||
self.$el.toggleClass('oe_pad_fullscreen');
|
||||
self.$el.find('.oe_pad_switch').toggleClass('fa-expand fa-compress');
|
||||
self.view.$el.find('.oe_chatter').toggle();
|
||||
$('#oe_main_menu_navbar').toggle();
|
||||
});
|
||||
this._configured_deferred.always(function() {
|
||||
var configured = self.get('configured');
|
||||
self.$(".oe_unconfigured").toggle(!configured);
|
||||
self.$(".oe_configured").toggle(configured);
|
||||
});
|
||||
this.render_value();
|
||||
},
|
||||
render_value: function() {
|
||||
var self = this;
|
||||
$.when(this._configured_deferred, this.pad_loading_request).always(function() {
|
||||
if (! self.get('configured')) {
|
||||
return;
|
||||
};
|
||||
var value = self.get('value');
|
||||
if (self.get('effective_readonly')) {
|
||||
if (_.str.startsWith(value, 'http')) {
|
||||
self.pad_loading_request = self.view.dataset.call('pad_get_content', {url: value}).done(function(data) {
|
||||
self.$('.oe_pad_content').removeClass('oe_pad_loading').html('<div class="oe_pad_readonly"><div>');
|
||||
self.$('.oe_pad_readonly').html(data);
|
||||
}).fail(function() {
|
||||
self.$('.oe_pad_content').text(_t('Unable to load pad'));
|
||||
});
|
||||
} else {
|
||||
self.$('.oe_pad_content').addClass('oe_pad_loading').show().text(_t("This pad will be initialized on first edit"));
|
||||
}
|
||||
odoo.define('pad.pad', ['web.core', 'web.form_common'], function (require) {
|
||||
|
||||
var core = require('web.core');
|
||||
var form_common = require('web.form_common');
|
||||
|
||||
var _t = core._t;
|
||||
|
||||
var FieldPad = form_common.AbstractField.extend(form_common.ReinitializeWidgetMixin, {
|
||||
template: 'FieldPad',
|
||||
content: "",
|
||||
init: function() {
|
||||
var self = this;
|
||||
this._super.apply(this, arguments);
|
||||
this._configured_deferred = this.view.dataset.call('pad_is_configured').done(function(data) {
|
||||
self.set("configured", !!data);
|
||||
}).fail(function(data, event) {
|
||||
event.preventDefault();
|
||||
self.set("configured", true);
|
||||
});
|
||||
this.pad_loading_request = null;
|
||||
},
|
||||
initialize_content: function() {
|
||||
var self = this;
|
||||
this.$('.oe_pad_switch').click(function() {
|
||||
self.$el.toggleClass('oe_pad_fullscreen');
|
||||
self.$el.find('.oe_pad_switch').toggleClass('fa-expand fa-compress');
|
||||
self.view.$el.find('.oe_chatter').toggle();
|
||||
$('#oe_main_menu_navbar').toggle();
|
||||
});
|
||||
this._configured_deferred.always(function() {
|
||||
var configured = self.get('configured');
|
||||
self.$(".oe_unconfigured").toggle(!configured);
|
||||
self.$(".oe_configured").toggle(configured);
|
||||
});
|
||||
this.render_value();
|
||||
},
|
||||
render_value: function() {
|
||||
var self = this;
|
||||
$.when(this._configured_deferred, this.pad_loading_request).always(function() {
|
||||
if (! self.get('configured')) {
|
||||
return;
|
||||
}
|
||||
var value = self.get('value');
|
||||
if (self.get('effective_readonly')) {
|
||||
if (_.str.startsWith(value, 'http')) {
|
||||
self.pad_loading_request = self.view.dataset.call('pad_get_content', {url: value}).done(function(data) {
|
||||
self.$('.oe_pad_content').removeClass('oe_pad_loading').html('<div class="oe_pad_readonly"><div>');
|
||||
self.$('.oe_pad_readonly').html(data);
|
||||
}).fail(function() {
|
||||
self.$('.oe_pad_content').text(_t('Unable to load pad'));
|
||||
});
|
||||
} else {
|
||||
self.$('.oe_pad_content').addClass('oe_pad_loading').show().text(_t("This pad will be initialized on first edit"));
|
||||
}
|
||||
else {
|
||||
var def = $.when();
|
||||
if (! value || !_.str.startsWith(value, 'http')) {
|
||||
def = self.view.dataset.call('pad_generate_url', {
|
||||
context: {
|
||||
model: self.view.model,
|
||||
field_name: self.name,
|
||||
object_id: self.view.datarecord.id
|
||||
},
|
||||
}).done(function(data) {
|
||||
if (! data.url) {
|
||||
self.set("configured", false);
|
||||
} else {
|
||||
self.set("value", data.url);
|
||||
}
|
||||
});
|
||||
}
|
||||
def.then(function() {
|
||||
value = self.get('value');
|
||||
if (_.str.startsWith(value, 'http')) {
|
||||
var content = '<iframe width="100%" height="100%" frameborder="0" src="' + value + '?showChat=false&userName=' + self.session.username + '"></iframe>';
|
||||
self.$('.oe_pad_content').html(content);
|
||||
self._dirty_flag = true;
|
||||
}
|
||||
else {
|
||||
self.$('.oe_pad_content').text(value);
|
||||
}
|
||||
else {
|
||||
var def = $.when();
|
||||
if (! value || !_.str.startsWith(value, 'http')) {
|
||||
def = self.view.dataset.call('pad_generate_url', {
|
||||
context: {
|
||||
model: self.view.model,
|
||||
field_name: self.name,
|
||||
object_id: self.view.datarecord.id
|
||||
},
|
||||
}).done(function(data) {
|
||||
if (! data.url) {
|
||||
self.set("configured", false);
|
||||
} else {
|
||||
self.set("value", data.url);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
def.then(function() {
|
||||
value = self.get('value');
|
||||
if (_.str.startsWith(value, 'http')) {
|
||||
var content = '<iframe width="100%" height="100%" frameborder="0" src="' + value + '?showChat=false&userName=' + self.session.username + '"></iframe>';
|
||||
self.$('.oe_pad_content').html(content);
|
||||
self._dirty_flag = true;
|
||||
}
|
||||
else {
|
||||
self.$('.oe_pad_content').text(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
instance.web.form.widgets = instance.web.form.widgets.extend({
|
||||
'pad': 'instance.web.form.FieldPad',
|
||||
});
|
||||
};
|
||||
core.form_widget_registry.add('pad', FieldPad);
|
||||
|
||||
});
|
||||
@@ -1,45 +1,52 @@
|
||||
openerp.project = function(openerp) {
|
||||
openerp.web_kanban.KanbanView.include({
|
||||
project_display_members_names: function() {
|
||||
/*
|
||||
* Set avatar title for members.
|
||||
* In kanban views, many2many fields only return a list of ids.
|
||||
* We can implement return value of m2m fields like [(1,"Adminstration"),...].
|
||||
*/
|
||||
var self = this;
|
||||
var members_ids = [];
|
||||
odoo.define('project.update_kanban', ['web_kanban.common', 'web_kanban.KanbanView', 'web.data', 'web.session'], function (require) {
|
||||
|
||||
// Collect members ids
|
||||
self.$el.find('img[data-member_id]').each(function() {
|
||||
members_ids.push($(this).data('member_id'));
|
||||
var kanban_common = require('web_kanban.common');
|
||||
var KanbanView = require('web_kanban.KanbanView');
|
||||
var data = require('web.data');
|
||||
var session = require('web.session');
|
||||
|
||||
KanbanView.include({
|
||||
project_display_members_names: function() {
|
||||
/*
|
||||
* Set avatar title for members.
|
||||
* In kanban views, many2many fields only return a list of ids.
|
||||
* We can implement return value of m2m fields like [(1,"Adminstration"),...].
|
||||
*/
|
||||
var self = this;
|
||||
var members_ids = [];
|
||||
|
||||
// Collect members ids
|
||||
self.$el.find('img[data-member_id]').each(function() {
|
||||
members_ids.push($(this).data('member_id'));
|
||||
});
|
||||
|
||||
// Find their matching names
|
||||
var dataset = new data.DataSetSearch(self, 'res.users', session.context, [['id', 'in', _.uniq(members_ids)]]);
|
||||
dataset.read_slice(['id', 'name']).done(function(result) {
|
||||
_.each(result, function(v, k) {
|
||||
// Set the proper value in the DOM
|
||||
self.$el.find('img[data-member_id=' + v.id + ']').attr('title', v.name).tooltip();
|
||||
});
|
||||
});
|
||||
},
|
||||
on_groups_started: function() {
|
||||
var self = this;
|
||||
self._super.apply(self, arguments);
|
||||
|
||||
// Find their matching names
|
||||
var dataset = new openerp.web.DataSetSearch(self, 'res.users', self.session.context, [['id', 'in', _.uniq(members_ids)]]);
|
||||
dataset.read_slice(['id', 'name']).done(function(result) {
|
||||
_.each(result, function(v, k) {
|
||||
// Set the proper value in the DOM
|
||||
self.$el.find('img[data-member_id=' + v.id + ']').attr('title', v.name).tooltip();
|
||||
});
|
||||
});
|
||||
},
|
||||
on_groups_started: function() {
|
||||
var self = this;
|
||||
self._super.apply(self, arguments);
|
||||
|
||||
if (self.dataset.model === 'project.project') {
|
||||
self.project_display_members_names();
|
||||
}
|
||||
if (self.dataset.model === 'project.project') {
|
||||
self.project_display_members_names();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
openerp.web_kanban.KanbanRecord.include({
|
||||
on_card_clicked: function() {
|
||||
if (this.view.dataset.model === 'project.project') {
|
||||
this.$('.oe_kanban_project_list a').first().click();
|
||||
} else {
|
||||
this._super.apply(this, arguments);
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
kanban_common.KanbanRecord.include({
|
||||
on_card_clicked: function() {
|
||||
if (this.view.dataset.model === 'project.project') {
|
||||
this.$('.oe_kanban_project_list a').first().click();
|
||||
} else {
|
||||
this._super.apply(this, arguments);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,27 +1,34 @@
|
||||
openerp.purchase_requisition = function(instance) {
|
||||
var QWeb = instance.web.qweb,
|
||||
_t = instance.web._t;
|
||||
odoo.define('purchase_requisition.purchase_requisition', ['web.core', 'web.ListView', 'web.Model'], function (require) {
|
||||
"use strict";
|
||||
|
||||
instance.web.purchase_requisition = instance.web.purchase_requisition || {};
|
||||
var core = require('web.core');
|
||||
var Model = require('web.Model');
|
||||
var ListView = require('web.ListView');
|
||||
|
||||
instance.web.views.add('tree_purchase_order_line_compare', 'instance.web.purchase_requisition.CompareListView');
|
||||
instance.web.purchase_requisition.CompareListView = instance.web.ListView.extend({
|
||||
init: function() {
|
||||
var self = this;
|
||||
this._super.apply(this, arguments);
|
||||
this.on('list_view_loaded', this, function() {
|
||||
if(self.__parentedParent.$el.find('.oe_generate_po').length == 0){
|
||||
var button = $("<button type='button' class='oe_button oe_highlight oe_generate_po'>Generate PO</button>")
|
||||
.click(this.proxy('generate_purchase_order'));
|
||||
self.__parentedParent.$el.find('.oe_list_buttons').append(button);
|
||||
}
|
||||
});
|
||||
},
|
||||
generate_purchase_order: function () {
|
||||
var self = this;
|
||||
new instance.web.Model(self.dataset.model).call("generate_po",[self.dataset.context.tender_id,self.dataset.context]).then(function(result) {
|
||||
self.ViewManager.ActionManager.history_back();
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
var QWeb = core.qweb;
|
||||
var _t = core._t;
|
||||
|
||||
|
||||
var CompareListView = ListView.extend({
|
||||
init: function() {
|
||||
var self = this;
|
||||
this._super.apply(this, arguments);
|
||||
this.on('list_view_loaded', this, function() {
|
||||
if(self.__parentedParent.$el.find('.oe_generate_po').length == 0){
|
||||
var button = $("<button type='button' class='oe_button oe_highlight oe_generate_po'>Generate PO</button>")
|
||||
.click(this.proxy('generate_purchase_order'));
|
||||
self.__parentedParent.$el.find('.oe_list_buttons').append(button);
|
||||
}
|
||||
});
|
||||
},
|
||||
generate_purchase_order: function () {
|
||||
var self = this;
|
||||
new Model(self.dataset.model).call("generate_po",[self.dataset.context.tender_id,self.dataset.context]).then(function(result) {
|
||||
self.ViewManager.ActionManager.history_back();
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
core.view_registry.add('tree_purchase_order_line_compare', CompareListView);
|
||||
|
||||
});
|
||||
|
||||
@@ -1,97 +1,106 @@
|
||||
openerp.report = function(instance) {
|
||||
var wkhtmltopdf_state;
|
||||
odoo.define('report.report', ['web.ActionManager', 'web.core', 'web.crash_manager', 'web.framework', 'web.session'], function (require) {
|
||||
|
||||
var trigger_download = function(session, response, c, action, options) {
|
||||
session.get_file({
|
||||
url: '/report/download',
|
||||
data: {data: JSON.stringify(response)},
|
||||
complete: openerp.web.unblockUI,
|
||||
error: c.rpc_error.bind(c),
|
||||
success: function(){
|
||||
if (action && options && !action.dialog) {
|
||||
options.on_close();
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
var ActionManager = require('web.ActionManager');
|
||||
var core = require('web.core');
|
||||
var crash_manager = require('web.crash_manager');
|
||||
var framework = require('web.framework');
|
||||
var session = require('web.session');
|
||||
|
||||
instance.web.ActionManager = instance.web.ActionManager.extend({
|
||||
ir_actions_report_xml: function(action, options) {
|
||||
var self = this;
|
||||
instance.web.blockUI();
|
||||
action = _.clone(action);
|
||||
_t = instance.web._t;
|
||||
var _t = core._t;
|
||||
var wkhtmltopdf_state;
|
||||
|
||||
// QWeb reports
|
||||
if ('report_type' in action && (action.report_type == 'qweb-html' || action.report_type == 'qweb-pdf' || action.report_type == 'controller')) {
|
||||
var report_url = '';
|
||||
switch (action.report_type) {
|
||||
case 'qweb-html':
|
||||
report_url = '/report/html/' + action.report_name;
|
||||
break;
|
||||
case 'qweb-pdf':
|
||||
report_url = '/report/pdf/' + action.report_name;
|
||||
break;
|
||||
case 'controller':
|
||||
report_url = action.report_file;
|
||||
break;
|
||||
default:
|
||||
report_url = '/report/html/' + action.report_name;
|
||||
break;
|
||||
}
|
||||
|
||||
// generic report: no query string
|
||||
// particular: query string of action.data.form and context
|
||||
if (!('data' in action) || !(action.data)) {
|
||||
if ('active_ids' in action.context) {
|
||||
report_url += "/" + action.context.active_ids.join(',');
|
||||
}
|
||||
} else {
|
||||
report_url += "?options=" + encodeURIComponent(JSON.stringify(action.data));
|
||||
report_url += "&context=" + encodeURIComponent(JSON.stringify(action.context));
|
||||
}
|
||||
|
||||
var response = new Array();
|
||||
response[0] = report_url;
|
||||
response[1] = action.report_type;
|
||||
var c = openerp.webclient.crashmanager;
|
||||
|
||||
if (action.report_type == 'qweb-html') {
|
||||
window.open(report_url, '_blank', 'scrollbars=1,height=900,width=1280');
|
||||
instance.web.unblockUI();
|
||||
} else if (action.report_type === 'qweb-pdf') {
|
||||
// Trigger the download of the pdf/controller report
|
||||
(wkhtmltopdf_state = wkhtmltopdf_state || openerp.session.rpc('/report/check_wkhtmltopdf')).then(function (presence) {
|
||||
// Fallback on html if wkhtmltopdf is not installed or if OpenERP is started with one worker
|
||||
if (presence === 'install') {
|
||||
self.do_notify(_t('Report'), _t('Unable to find Wkhtmltopdf on this \
|
||||
system. The report will be shown in html.<br><br><a href="http://wkhtmltopdf.org/" target="_blank">\
|
||||
wkhtmltopdf.org</a>'), true);
|
||||
report_url = report_url.substring(12)
|
||||
window.open('/report/html/' + report_url, '_blank', 'height=768,width=1024');
|
||||
instance.web.unblockUI();
|
||||
return;
|
||||
} else if (presence === 'workers') {
|
||||
self.do_notify(_t('Report'), _t('You need to start OpenERP with at least two \
|
||||
workers to print a pdf version of the reports.'), true);
|
||||
report_url = report_url.substring(12)
|
||||
window.open('/report/html/' + report_url, '_blank', 'height=768,width=1024');
|
||||
instance.web.unblockUI();
|
||||
return;
|
||||
} else if (presence === 'upgrade') {
|
||||
self.do_notify(_t('Report'), _t('You should upgrade your version of\
|
||||
Wkhtmltopdf to at least 0.12.0 in order to get a correct display of headers and footers as well as\
|
||||
support for table-breaking between pages.<br><br><a href="http://wkhtmltopdf.org/" \
|
||||
target="_blank">wkhtmltopdf.org</a>'), true);
|
||||
}
|
||||
return trigger_download(self.session, response, c, action, options);
|
||||
});
|
||||
} else if (action.report_type === 'controller') {
|
||||
return trigger_download(self.session, response, c, action, options);
|
||||
}
|
||||
} else {
|
||||
return self._super(action, options);
|
||||
var trigger_download = function(session, response, c, action, options) {
|
||||
session.get_file({
|
||||
url: '/report/download',
|
||||
data: {data: JSON.stringify(response)},
|
||||
complete: framework.unblockUI,
|
||||
error: c.rpc_error.bind(c),
|
||||
success: function(){
|
||||
if (action && options && !action.dialog) {
|
||||
options.on_close();
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
ActionManager.include({
|
||||
ir_actions_report_xml: function(action, options) {
|
||||
var self = this;
|
||||
framework.blockUI();
|
||||
action = _.clone(action);
|
||||
_t = core._t;
|
||||
|
||||
// QWeb reports
|
||||
if ('report_type' in action && (action.report_type == 'qweb-html' || action.report_type == 'qweb-pdf' || action.report_type == 'controller')) {
|
||||
var report_url = '';
|
||||
switch (action.report_type) {
|
||||
case 'qweb-html':
|
||||
report_url = '/report/html/' + action.report_name;
|
||||
break;
|
||||
case 'qweb-pdf':
|
||||
report_url = '/report/pdf/' + action.report_name;
|
||||
break;
|
||||
case 'controller':
|
||||
report_url = action.report_file;
|
||||
break;
|
||||
default:
|
||||
report_url = '/report/html/' + action.report_name;
|
||||
break;
|
||||
}
|
||||
|
||||
// generic report: no query string
|
||||
// particular: query string of action.data.form and context
|
||||
if (!('data' in action) || !(action.data)) {
|
||||
if ('active_ids' in action.context) {
|
||||
report_url += "/" + action.context.active_ids.join(',');
|
||||
}
|
||||
} else {
|
||||
report_url += "?options=" + encodeURIComponent(JSON.stringify(action.data));
|
||||
report_url += "&context=" + encodeURIComponent(JSON.stringify(action.context));
|
||||
}
|
||||
|
||||
var response = new Array();
|
||||
response[0] = report_url;
|
||||
response[1] = action.report_type;
|
||||
var c = crash_manager;
|
||||
|
||||
if (action.report_type == 'qweb-html') {
|
||||
window.open(report_url, '_blank', 'scrollbars=1,height=900,width=1280');
|
||||
framework.unblockUI();
|
||||
} else if (action.report_type === 'qweb-pdf') {
|
||||
// Trigger the download of the pdf/controller report
|
||||
(wkhtmltopdf_state = wkhtmltopdf_state || session.rpc('/report/check_wkhtmltopdf')).then(function (presence) {
|
||||
// Fallback on html if wkhtmltopdf is not installed or if OpenERP is started with one worker
|
||||
if (presence === 'install') {
|
||||
self.do_notify(_t('Report'), _t('Unable to find Wkhtmltopdf on this \
|
||||
system. The report will be shown in html.<br><br><a href="http://wkhtmltopdf.org/" target="_blank">\
|
||||
wkhtmltopdf.org</a>'), true);
|
||||
report_url = report_url.substring(12);
|
||||
window.open('/report/html/' + report_url, '_blank', 'height=768,width=1024');
|
||||
framework.unblockUI();
|
||||
return;
|
||||
} else if (presence === 'workers') {
|
||||
self.do_notify(_t('Report'), _t('You need to start OpenERP with at least two \
|
||||
workers to print a pdf version of the reports.'), true);
|
||||
report_url = report_url.substring(12);
|
||||
window.open('/report/html/' + report_url, '_blank', 'height=768,width=1024');
|
||||
framework.unblockUI();
|
||||
return;
|
||||
} else if (presence === 'upgrade') {
|
||||
self.do_notify(_t('Report'), _t('You should upgrade your version of\
|
||||
Wkhtmltopdf to at least 0.12.0 in order to get a correct display of headers and footers as well as\
|
||||
support for table-breaking between pages.<br><br><a href="http://wkhtmltopdf.org/" \
|
||||
target="_blank">wkhtmltopdf.org</a>'), true);
|
||||
}
|
||||
return trigger_download(self.session, response, c, action, options);
|
||||
});
|
||||
} else if (action.report_type === 'controller') {
|
||||
return trigger_download(self.session, response, c, action, options);
|
||||
}
|
||||
} else {
|
||||
return self._super(action, options);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,45 +1,53 @@
|
||||
openerp.crm = function(openerp) {
|
||||
openerp.web_kanban.KanbanView.include({
|
||||
crm_display_members_names: function() {
|
||||
/*
|
||||
* Set avatar title for members.
|
||||
* In kanban views, many2many fields only return a list of ids.
|
||||
* We can implement return value of m2m fields like [(1,"Adminstration"),...].
|
||||
*/
|
||||
var self = this;
|
||||
var members_ids = [];
|
||||
odoo.define('sales_team.update_kanban', ['web_kanban.KanbanView', 'web_kanban.common', 'web.data', 'web.session'], function (require) {
|
||||
"use strict";
|
||||
|
||||
// Collect members ids
|
||||
self.$el.find('img[data-member_id]').each(function() {
|
||||
members_ids.push($(this).data('member_id'));
|
||||
var KanbanView = require('web_kanban.KanbanView');
|
||||
var kanban_common = require('web_kanban.common');
|
||||
var data = require('web.data');
|
||||
var session = require('web.session');
|
||||
|
||||
KanbanView.include({
|
||||
crm_display_members_names: function() {
|
||||
/*
|
||||
* Set avatar title for members.
|
||||
* In kanban views, many2many fields only return a list of ids.
|
||||
* We can implement return value of m2m fields like [(1,"Adminstration"),...].
|
||||
*/
|
||||
var self = this;
|
||||
var members_ids = [];
|
||||
|
||||
// Collect members ids
|
||||
self.$el.find('img[data-member_id]').each(function() {
|
||||
members_ids.push($(this).data('member_id'));
|
||||
});
|
||||
|
||||
// Find their matching names
|
||||
var dataset = new data.DataSetSearch(self, 'res.users', session.context, [['id', 'in', _.uniq(members_ids)]]);
|
||||
dataset.read_slice(['id', 'name']).done(function(result) {
|
||||
_.each(result, function(v) {
|
||||
// Set the proper value in the DOM
|
||||
self.$el.find('img[data-member_id=' + v.id + ']').attr('title', v.name).tooltip();
|
||||
});
|
||||
});
|
||||
},
|
||||
on_groups_started: function() {
|
||||
var self = this;
|
||||
self._super.apply(self, arguments);
|
||||
|
||||
// Find their matching names
|
||||
var dataset = new openerp.web.DataSetSearch(self, 'res.users', self.session.context, [['id', 'in', _.uniq(members_ids)]]);
|
||||
dataset.read_slice(['id', 'name']).done(function(result) {
|
||||
_.each(result, function(v, k) {
|
||||
// Set the proper value in the DOM
|
||||
self.$el.find('img[data-member_id=' + v.id + ']').attr('title', v.name).tooltip();
|
||||
});
|
||||
});
|
||||
},
|
||||
on_groups_started: function() {
|
||||
var self = this;
|
||||
self._super.apply(self, arguments);
|
||||
if (self.dataset.model === 'crm.team') {
|
||||
self.crm_display_members_names();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
if (self.dataset.model === 'crm.team') {
|
||||
self.crm_display_members_names();
|
||||
}
|
||||
},
|
||||
});
|
||||
kanban_common.KanbanRecord.include({
|
||||
on_card_clicked: function() {
|
||||
if (this.view.dataset.model === 'crm.team') {
|
||||
this.$('.oe_kanban_crm_salesteams_list a').first().click();
|
||||
} else {
|
||||
this._super.apply(this, arguments);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
openerp.web_kanban.KanbanRecord.include({
|
||||
on_card_clicked: function() {
|
||||
if (this.view.dataset.model === 'crm.team') {
|
||||
this.$('.oe_kanban_crm_salesteams_list a').first().click();
|
||||
} else {
|
||||
this._super.apply(this, arguments);
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
+119
-109
@@ -1,122 +1,132 @@
|
||||
odoo.define(['mail.mail', 'web.core', 'web.data', 'web.Model', 'web.pyeval', 'web.session', 'web.Sidebar', 'web.ViewManager'], function (require) {
|
||||
|
||||
openerp.share = function(session) {
|
||||
var _t = session.web._t;
|
||||
var has_action_id = false;
|
||||
var mail = require('mail.mail');
|
||||
var core = require('web.core');
|
||||
var data = require('web.data');
|
||||
var Model = require('web.Model');
|
||||
var pyeval = require('web.pyeval');
|
||||
var session = require('web.session');
|
||||
var Sidebar = require('web.Sidebar');
|
||||
var ViewManager = require('web.ViewManager');
|
||||
|
||||
function launch_wizard(self, view, user_type, invite) {
|
||||
var action = view.getParent().action;
|
||||
var Share = new session.web.DataSet(self, 'share.wizard', view.dataset.get_context());
|
||||
var domain = new session.web.CompoundDomain(view.dataset.domain);
|
||||
if (view.fields_view.type == 'form') {
|
||||
domain = new session.web.CompoundDomain(domain, [['id', '=', view.datarecord.id]]);
|
||||
}
|
||||
if (view.fields_view.type == 'form') rec_name = view.datarecord.name;
|
||||
else rec_name = '';
|
||||
session.web.pyeval.eval_domains_and_contexts({
|
||||
domains: [domain],
|
||||
contexts: [Share.get_context()]
|
||||
}).done(function (result) {
|
||||
Share.create({
|
||||
name: action.name,
|
||||
record_name: rec_name,
|
||||
domain: result.domain,
|
||||
action_id: action.id,
|
||||
user_type: user_type || 'embedded',
|
||||
view_type: view.fields_view.type,
|
||||
invite: invite || false,
|
||||
}).done(function(share_id) {
|
||||
var step1 = Share.call('go_step_1', [[share_id], Share.get_context()]).done(function(result) {
|
||||
var action = result;
|
||||
self.do_action(action);
|
||||
});
|
||||
var _t = core._t;
|
||||
var has_action_id = false;
|
||||
|
||||
function launch_wizard(self, view, user_type, invite) {
|
||||
var action = view.getParent().action;
|
||||
var Share = new data.DataSet(self, 'share.wizard', view.dataset.get_context());
|
||||
var domain = new data.CompoundDomain(view.dataset.domain);
|
||||
var rec_name;
|
||||
if (view.fields_view.type == 'form') {
|
||||
domain = new data.CompoundDomain(domain, [['id', '=', view.datarecord.id]]);
|
||||
}
|
||||
if (view.fields_view.type == 'form') rec_name = view.datarecord.name;
|
||||
else rec_name = '';
|
||||
pyeval.eval_domains_and_contexts({
|
||||
domains: [domain],
|
||||
contexts: [Share.get_context()]
|
||||
}).done(function (result) {
|
||||
Share.create({
|
||||
name: action.name,
|
||||
record_name: rec_name,
|
||||
domain: result.domain,
|
||||
action_id: action.id,
|
||||
user_type: user_type || 'embedded',
|
||||
view_type: view.fields_view.type,
|
||||
invite: invite || false,
|
||||
}).done(function(share_id) {
|
||||
Share.call('go_step_1', [[share_id], Share.get_context()]).done(function(result) {
|
||||
var action = result;
|
||||
self.do_action(action);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function has_share(yes, no) {
|
||||
if (!session.share_flag) {
|
||||
session.share_flag = $.Deferred(function() {
|
||||
var func = new Model("share.wizard").get_func("has_share");
|
||||
func(session.uid).then(function(res) {
|
||||
if(res) {
|
||||
session.share_flag.resolve();
|
||||
} else {
|
||||
session.share_flag.reject();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
session.share_flag.done(yes).fail(no);
|
||||
}
|
||||
|
||||
function has_share(yes, no) {
|
||||
if (!session.session.share_flag) {
|
||||
session.session.share_flag = $.Deferred(function() {
|
||||
var func = new session.web.Model("share.wizard").get_func("has_share");
|
||||
func(session.session.uid).then(function(res) {
|
||||
if(res) {
|
||||
session.session.share_flag.resolve();
|
||||
} else {
|
||||
session.session.share_flag.reject();
|
||||
}
|
||||
});
|
||||
});
|
||||
/* Extend the Sidebar to add Share and Embed links in the 'More' menu */
|
||||
Sidebar.include({
|
||||
|
||||
start: function() {
|
||||
var self = this;
|
||||
this._super(this);
|
||||
has_share(function() {
|
||||
self.add_items('other', [
|
||||
{ label: _t('Share'),
|
||||
callback: self.on_click_share,
|
||||
classname: 'oe_share' },
|
||||
{ label: _t('Embed'),
|
||||
callback: self.on_click_share_link,
|
||||
classname: 'oe_share' },
|
||||
]);
|
||||
});
|
||||
},
|
||||
|
||||
on_click_share: function() {
|
||||
var view = this.getParent();
|
||||
launch_wizard(this, view, 'emails', false);
|
||||
},
|
||||
|
||||
on_click_share_link: function() {
|
||||
var view = this.getParent();
|
||||
launch_wizard(this, view, 'embedded', false);
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Extends mail (Chatter widget)
|
||||
* - show the 'invite' button' only we came on the form view through
|
||||
* an action. We do this because 'invite' is based on the share
|
||||
* mechanism, and it tries to share an action.
|
||||
*/
|
||||
mail.RecordThread.include( {
|
||||
start: function() {
|
||||
var start_res = this._super.apply(this, arguments);
|
||||
if (has_action_id) {
|
||||
this.$el.find('button.oe_share_invite').show();
|
||||
}
|
||||
session.session.share_flag.done(yes).fail(no);
|
||||
return start_res;
|
||||
}
|
||||
});
|
||||
|
||||
/* Extend the Sidebar to add Share and Embed links in the 'More' menu */
|
||||
session.web.Sidebar = session.web.Sidebar.extend({
|
||||
ViewManager.include({
|
||||
start: function() {
|
||||
var self = this;
|
||||
this.check_if_action_is_defined();
|
||||
has_share(function() {
|
||||
self.$el.delegate('button.oe_share_invite', 'click', self.on_click_share_invite);
|
||||
});
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
start: function() {
|
||||
var self = this;
|
||||
this._super(this);
|
||||
has_share(function() {
|
||||
self.add_items('other', [
|
||||
{ label: _t('Share'),
|
||||
callback: self.on_click_share,
|
||||
classname: 'oe_share' },
|
||||
{ label: _t('Embed'),
|
||||
callback: self.on_click_share_link,
|
||||
classname: 'oe_share' },
|
||||
]);
|
||||
});
|
||||
},
|
||||
|
||||
on_click_share: function(item) {
|
||||
var view = this.getParent()
|
||||
launch_wizard(this, view, 'emails', false);
|
||||
},
|
||||
|
||||
on_click_share_link: function(item) {
|
||||
var view = this.getParent()
|
||||
launch_wizard(this, view, 'embedded', false);
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Extends mail (Chatter widget)
|
||||
* - show the 'invite' button' only we came on the form view through
|
||||
* an action. We do this because 'invite' is based on the share
|
||||
* mechanism, and it tries to share an action.
|
||||
*/
|
||||
session.mail.RecordThread.include( {
|
||||
start: function() {
|
||||
start_res = this._super.apply(this, arguments);
|
||||
if (has_action_id) {
|
||||
this.$el.find('button.oe_share_invite').show();
|
||||
}
|
||||
return start_res;
|
||||
check_if_action_is_defined: function() {
|
||||
if (this.action && this.action.id) {
|
||||
has_action_id = true;
|
||||
}
|
||||
});
|
||||
else {
|
||||
has_action_id = false;
|
||||
}
|
||||
},
|
||||
|
||||
session.web.ViewManager.include({
|
||||
start: function() {
|
||||
var self = this;
|
||||
this.check_if_action_is_defined();
|
||||
has_share(function() {
|
||||
self.$el.delegate('button.oe_share_invite', 'click', self.on_click_share_invite);
|
||||
});
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
check_if_action_is_defined: function() {
|
||||
if (this.action && this.action.id) {
|
||||
has_action_id = true;
|
||||
}
|
||||
else {
|
||||
has_action_id = false;
|
||||
}
|
||||
},
|
||||
|
||||
on_click_share_invite: function(e) {
|
||||
e.preventDefault();
|
||||
launch_wizard(this, this.views[this.active_view].controller, 'emails', true);
|
||||
},
|
||||
});
|
||||
};
|
||||
on_click_share_invite: function(e) {
|
||||
e.preventDefault();
|
||||
launch_wizard(this, this.views[this.active_view].controller, 'emails', true);
|
||||
},
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user