2011-03-16 23:56:34 +00:00
|
|
|
/*---------------------------------------------------------
|
2011-08-11 03:10:00 +00:00
|
|
|
* OpenERP Web chrome
|
2011-03-16 23:56:34 +00:00
|
|
|
*---------------------------------------------------------*/
|
2012-04-17 11:48:37 +00:00
|
|
|
openerp.web.chrome = function(instance) {
|
|
|
|
var QWeb = instance.web.qweb,
|
|
|
|
_t = instance.web._t;
|
2011-03-16 23:56:34 +00:00
|
|
|
|
2012-04-17 11:48:37 +00:00
|
|
|
instance.web.Notification = instance.web.Widget.extend({
|
2011-10-13 10:26:53 +00:00
|
|
|
template: 'Notification',
|
2011-10-13 15:03:17 +00:00
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
2012-06-11 09:06:22 +00:00
|
|
|
instance.web.notification = this;
|
2011-10-13 15:03:17 +00:00
|
|
|
},
|
2011-10-13 10:26:53 +00:00
|
|
|
start: function() {
|
|
|
|
this._super.apply(this, arguments);
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.notify({
|
2011-07-22 11:21:08 +00:00
|
|
|
speed: 500,
|
2012-01-25 09:24:23 +00:00
|
|
|
expires: 2500
|
2011-04-10 00:12:22 +00:00
|
|
|
});
|
|
|
|
},
|
2012-02-13 12:38:05 +00:00
|
|
|
notify: function(title, text, sticky) {
|
|
|
|
sticky = !!sticky;
|
|
|
|
var opts = {};
|
|
|
|
if (sticky) {
|
|
|
|
opts.expires = false;
|
|
|
|
}
|
2012-11-22 15:11:25 +00:00
|
|
|
return this.$el.notify('create', {
|
2011-07-22 11:21:08 +00:00
|
|
|
title: title,
|
|
|
|
text: text
|
2012-02-13 12:38:05 +00:00
|
|
|
}, opts);
|
2011-04-10 00:12:22 +00:00
|
|
|
},
|
2012-02-13 12:38:05 +00:00
|
|
|
warn: function(title, text, sticky) {
|
|
|
|
sticky = !!sticky;
|
|
|
|
var opts = {};
|
|
|
|
if (sticky) {
|
|
|
|
opts.expires = false;
|
|
|
|
}
|
2012-11-22 15:11:25 +00:00
|
|
|
return this.$el.notify('create', 'oe_notification_alert', {
|
2011-07-22 11:21:08 +00:00
|
|
|
title: title,
|
2011-10-28 08:52:12 +00:00
|
|
|
text: text
|
2012-02-13 12:38:05 +00:00
|
|
|
}, opts);
|
2011-10-28 08:52:12 +00:00
|
|
|
}
|
2011-04-10 00:12:22 +00:00
|
|
|
});
|
|
|
|
|
2013-01-02 09:46:08 +00:00
|
|
|
instance.web.action_notify = function(element, action) {
|
|
|
|
element.do_notify(action.params.title, action.params.text, action.params.sticky);
|
|
|
|
};
|
|
|
|
instance.web.client_actions.add("action_notify", "instance.web.action_notify");
|
|
|
|
|
|
|
|
instance.web.action_warn = function(element, action) {
|
|
|
|
element.do_warn(action.params.title, action.params.text, action.params.sticky);
|
|
|
|
};
|
|
|
|
instance.web.client_actions.add("action_warn", "instance.web.action_warn");
|
|
|
|
|
2012-05-16 14:13:28 +00:00
|
|
|
/**
|
|
|
|
* The very minimal function everything should call to create a dialog
|
|
|
|
* in OpenERP Web Client.
|
|
|
|
*/
|
2012-04-17 11:48:37 +00:00
|
|
|
instance.web.dialog = function(element) {
|
2012-02-17 11:43:57 +00:00
|
|
|
var result = element.dialog.apply(element, _.rest(_.toArray(arguments)));
|
2012-11-15 16:41:32 +00:00
|
|
|
result.dialog("widget").openerpClass();
|
2012-02-17 11:43:57 +00:00
|
|
|
return result;
|
2012-05-15 07:41:39 +00:00
|
|
|
};
|
2012-02-17 11:43:57 +00:00
|
|
|
|
2012-11-22 10:07:38 +00:00
|
|
|
/**
|
|
|
|
A useful class to handle dialogs.
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
- $buttons: A jQuery element targeting a dom part where buttons can be added. It always exists
|
|
|
|
during the lifecycle of the dialog.
|
|
|
|
*/
|
2012-04-17 11:48:37 +00:00
|
|
|
instance.web.Dialog = instance.web.Widget.extend({
|
2011-06-16 14:37:11 +00:00
|
|
|
dialog_title: "",
|
2012-11-22 10:07:38 +00:00
|
|
|
/**
|
|
|
|
Constructor.
|
|
|
|
|
|
|
|
@param {Widget} parent
|
|
|
|
@param {dictionary} options A dictionary that will be forwarded to jQueryUI Dialog. Additionaly, that
|
|
|
|
dictionary can contain the following keys:
|
2012-11-26 10:05:01 +00:00
|
|
|
- buttons: Deprecated. The buttons key is not propagated to jQueryUI Dialog. It must be a dictionary (key = button
|
|
|
|
label, value = click handler) or a list of dictionaries (each element in the dictionary is send to the
|
|
|
|
corresponding method of a jQuery element targeting the <button> tag). It is deprecated because all dialogs
|
|
|
|
in OpenERP must be personalized in some way (button in red, link instead of button, ...) and this
|
|
|
|
feature does not allow that kind of personalization.
|
2012-11-22 10:09:53 +00:00
|
|
|
- destroy_on_close: Default true. If true and the dialog is closed, it is automatically destroyed.
|
2012-11-22 10:07:38 +00:00
|
|
|
@param {jQuery object} content Some content to replace this.$el .
|
|
|
|
*/
|
2012-01-11 11:06:48 +00:00
|
|
|
init: function (parent, options, content) {
|
2011-07-26 10:01:36 +00:00
|
|
|
var self = this;
|
2011-07-18 12:54:22 +00:00
|
|
|
this._super(parent);
|
2012-08-02 14:36:50 +00:00
|
|
|
this.content_to_set = content;
|
2011-08-08 17:14:07 +00:00
|
|
|
this.dialog_options = {
|
2011-06-16 14:37:11 +00:00
|
|
|
modal: true,
|
2011-12-21 13:43:06 +00:00
|
|
|
destroy_on_close: true,
|
2012-07-13 22:25:28 +00:00
|
|
|
width: 900,
|
2011-06-16 14:37:11 +00:00
|
|
|
min_width: 0,
|
2011-12-21 13:43:06 +00:00
|
|
|
max_width: '95%',
|
2011-06-21 12:07:50 +00:00
|
|
|
height: 'auto',
|
2011-06-16 14:37:11 +00:00
|
|
|
min_height: 0,
|
2012-11-20 09:50:42 +00:00
|
|
|
max_height: $(window.top).height() - 200,
|
2011-06-21 12:07:50 +00:00
|
|
|
autoOpen: false,
|
2012-08-13 10:32:56 +00:00
|
|
|
position: [false, 40],
|
2012-11-20 09:50:42 +00:00
|
|
|
buttons: null,
|
2012-10-16 09:58:24 +00:00
|
|
|
beforeClose: function () {
|
|
|
|
self.trigger("closing");
|
|
|
|
},
|
2012-11-20 09:50:42 +00:00
|
|
|
resizeStop: function() {
|
|
|
|
self.trigger("resized");
|
|
|
|
},
|
2011-06-21 12:07:50 +00:00
|
|
|
};
|
2012-01-10 10:03:49 +00:00
|
|
|
if (options) {
|
|
|
|
_.extend(this.dialog_options, options);
|
2011-06-21 12:07:50 +00:00
|
|
|
}
|
2012-10-15 13:52:36 +00:00
|
|
|
this.on("closing", this, this._closing);
|
2012-11-20 14:18:07 +00:00
|
|
|
this.$buttons = $('<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix"><span class="oe_dialog_custom_buttons"/></div>');
|
2011-06-21 12:07:50 +00:00
|
|
|
},
|
2012-11-26 10:05:01 +00:00
|
|
|
_get_options: function() {
|
2012-11-20 09:50:42 +00:00
|
|
|
var self = this;
|
2012-11-26 10:05:01 +00:00
|
|
|
var o = _.extend({}, this.dialog_options);
|
2012-11-20 09:50:42 +00:00
|
|
|
var sizes = {
|
|
|
|
width: $(window.top).width(),
|
|
|
|
height: $(window.top).height(),
|
|
|
|
};
|
|
|
|
_.each(sizes, function(available_size, unit) {
|
2012-11-20 14:18:07 +00:00
|
|
|
o[unit] = self._get_size(o[unit], available_size);
|
2012-11-20 09:50:42 +00:00
|
|
|
o['min_' + unit] = self._get_size(o['min_' + unit] || 0, available_size);
|
|
|
|
o['max_' + unit] = self._get_size(o['max_' + unit] || 0, available_size);
|
|
|
|
if (o[unit] !== 'auto' && o['min_' + unit] && o[unit] < o['min_' + unit]) {
|
|
|
|
o[unit] = o['min_' + unit];
|
|
|
|
}
|
|
|
|
if (o[unit] !== 'auto' && o['max_' + unit] && o[unit] > o['max_' + unit]) {
|
|
|
|
o[unit] = o['max_' + unit];
|
|
|
|
}
|
2012-01-10 10:03:49 +00:00
|
|
|
});
|
2012-11-20 09:50:42 +00:00
|
|
|
o.title = o.title || this.dialog_title;
|
2012-01-10 10:03:49 +00:00
|
|
|
return o;
|
2011-06-16 14:37:11 +00:00
|
|
|
},
|
2012-11-20 09:50:42 +00:00
|
|
|
_get_size: function(val, available_size) {
|
|
|
|
val = val.toString();
|
2011-06-21 12:07:50 +00:00
|
|
|
if (val === 'auto') {
|
2011-06-16 14:37:11 +00:00
|
|
|
return val;
|
2012-11-20 09:50:42 +00:00
|
|
|
} else if (val.slice(-1) === "%") {
|
2011-06-16 14:37:11 +00:00
|
|
|
return Math.round(available_size / 100 * parseInt(val.slice(0, -1), 10));
|
|
|
|
} else {
|
2012-08-07 07:33:39 +00:00
|
|
|
return parseInt(val, 10);
|
2011-06-16 14:37:11 +00:00
|
|
|
}
|
|
|
|
},
|
2012-08-02 14:36:50 +00:00
|
|
|
renderElement: function() {
|
|
|
|
if (this.content_to_set) {
|
|
|
|
this.setElement(this.content_to_set);
|
|
|
|
} else if (this.template) {
|
|
|
|
this._super();
|
2011-06-21 12:07:50 +00:00
|
|
|
}
|
2012-08-02 14:36:50 +00:00
|
|
|
},
|
2012-11-22 10:07:38 +00:00
|
|
|
/**
|
2012-11-22 10:09:53 +00:00
|
|
|
Opens the popup. Inits the dialog if it is not already inited.
|
2012-11-22 10:07:38 +00:00
|
|
|
|
|
|
|
@return this
|
|
|
|
*/
|
2012-11-26 10:05:01 +00:00
|
|
|
open: function() {
|
2012-11-20 14:18:07 +00:00
|
|
|
if (!this.dialog_inited) {
|
2012-11-26 10:05:01 +00:00
|
|
|
this.init_dialog();
|
2012-11-20 14:18:07 +00:00
|
|
|
}
|
2012-11-22 10:07:38 +00:00
|
|
|
this.$el.dialog('open');
|
2012-11-20 14:18:07 +00:00
|
|
|
this.$el.dialog("widget").append(this.$buttons);
|
2011-08-22 10:19:34 +00:00
|
|
|
return this;
|
2011-06-21 12:07:50 +00:00
|
|
|
},
|
2012-11-20 09:50:42 +00:00
|
|
|
_add_buttons: function(buttons) {
|
2012-11-08 10:42:48 +00:00
|
|
|
var self = this;
|
2012-11-20 14:18:07 +00:00
|
|
|
var $customButons = this.$buttons.find('.oe_dialog_custom_buttons').empty();
|
2012-11-20 09:50:42 +00:00
|
|
|
_.each(buttons, function(fn, text) {
|
|
|
|
// buttons can be object or array
|
|
|
|
if (!_.isFunction(fn)) {
|
|
|
|
text = fn.text;
|
|
|
|
fn = fn.click;
|
|
|
|
}
|
|
|
|
var $but = $(QWeb.render('WidgetButton', { widget : { string: text, node: { attrs: {} }}}));
|
2012-11-20 14:18:07 +00:00
|
|
|
$customButons.append($but);
|
2012-11-08 10:42:48 +00:00
|
|
|
$but.on('click', function(ev) {
|
|
|
|
fn.call(self.$el, ev);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2012-11-22 10:07:38 +00:00
|
|
|
/**
|
2012-11-22 10:09:53 +00:00
|
|
|
Initializes the popup.
|
2012-11-22 10:07:38 +00:00
|
|
|
|
|
|
|
@return The result returned by start().
|
|
|
|
*/
|
2012-11-26 10:05:01 +00:00
|
|
|
init_dialog: function() {
|
|
|
|
var options = this._get_options();
|
2012-11-22 10:07:38 +00:00
|
|
|
if (options.buttons) {
|
|
|
|
this._add_buttons(options.buttons);
|
|
|
|
delete(options.buttons);
|
|
|
|
}
|
2012-08-02 14:36:50 +00:00
|
|
|
this.renderElement();
|
2012-11-20 09:50:42 +00:00
|
|
|
instance.web.dialog(this.$el, options);
|
2012-11-22 10:07:38 +00:00
|
|
|
if (options.height === 'auto' && options.max_height) {
|
|
|
|
this.$el.css({ 'max-height': options.max_height, 'overflow-y': 'auto' });
|
|
|
|
}
|
2012-08-02 14:36:50 +00:00
|
|
|
this.dialog_inited = true;
|
2012-10-03 12:56:29 +00:00
|
|
|
var res = this.start();
|
2012-08-02 14:36:50 +00:00
|
|
|
return res;
|
|
|
|
},
|
2012-11-22 10:07:38 +00:00
|
|
|
/**
|
2012-11-22 10:09:53 +00:00
|
|
|
Closes the popup, if destroy_on_close was passed to the constructor, it is also destroyed.
|
2012-11-22 10:07:38 +00:00
|
|
|
*/
|
2012-10-15 13:38:15 +00:00
|
|
|
close: function() {
|
2012-11-06 10:08:16 +00:00
|
|
|
if (this.dialog_inited && this.$el.is(":data(dialog)")) {
|
2012-11-05 10:36:17 +00:00
|
|
|
this.$el.dialog('close');
|
|
|
|
}
|
2012-10-15 13:38:15 +00:00
|
|
|
},
|
2012-10-15 13:52:36 +00:00
|
|
|
_closing: function() {
|
2012-08-02 14:36:50 +00:00
|
|
|
if (this.__tmp_dialog_destroying)
|
|
|
|
return;
|
2011-12-21 13:43:06 +00:00
|
|
|
if (this.dialog_options.destroy_on_close) {
|
2012-08-02 14:36:50 +00:00
|
|
|
this.__tmp_dialog_closing = true;
|
2012-07-03 09:53:11 +00:00
|
|
|
this.destroy();
|
2012-08-02 14:36:50 +00:00
|
|
|
this.__tmp_dialog_closing = undefined;
|
2011-12-21 13:43:06 +00:00
|
|
|
}
|
|
|
|
},
|
2012-11-22 10:07:38 +00:00
|
|
|
/**
|
2012-11-22 10:09:53 +00:00
|
|
|
Destroys the popup, also closes it.
|
2012-11-22 10:07:38 +00:00
|
|
|
*/
|
2012-02-21 16:29:12 +00:00
|
|
|
destroy: function () {
|
2012-11-20 14:18:07 +00:00
|
|
|
this.$buttons.remove();
|
2012-07-03 09:53:11 +00:00
|
|
|
_.each(this.getChildren(), function(el) {
|
|
|
|
el.destroy();
|
|
|
|
});
|
2012-07-23 13:49:14 +00:00
|
|
|
if (! this.__tmp_dialog_closing) {
|
2012-08-02 14:36:50 +00:00
|
|
|
this.__tmp_dialog_destroying = true;
|
|
|
|
this.close();
|
|
|
|
this.__tmp_dialog_destroying = undefined;
|
|
|
|
}
|
2012-11-20 14:18:07 +00:00
|
|
|
if (this.dialog_inited && !this.isDestroyed() && this.$el.is(":data(dialog)")) {
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.dialog('destroy');
|
2012-07-13 15:01:56 +00:00
|
|
|
}
|
2011-09-28 15:16:13 +00:00
|
|
|
this._super();
|
2011-06-16 14:37:11 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-11-10 19:34:40 +00:00
|
|
|
instance.web.CrashManager = instance.web.Class.extend({
|
2012-11-15 12:03:31 +00:00
|
|
|
init: function() {
|
|
|
|
this.active = true;
|
|
|
|
},
|
|
|
|
|
2012-10-11 00:37:29 +00:00
|
|
|
rpc_error: function(error) {
|
2012-11-15 12:03:31 +00:00
|
|
|
if (!this.active) {
|
|
|
|
return;
|
|
|
|
}
|
2013-01-08 16:41:04 +00:00
|
|
|
// yes, exception handling is shitty
|
|
|
|
if (error.code === 300 && error.data && error.data.type == "client_exception" && error.data.debug.match("SessionExpiredException")) {
|
|
|
|
this.show_warning({type: "Session Expired", data: { fault_code: "Your OpenERP session expired. Please refresh the current web page." }});
|
|
|
|
return;
|
|
|
|
}
|
2011-06-22 14:57:57 +00:00
|
|
|
if (error.data.fault_code) {
|
2011-09-12 16:03:26 +00:00
|
|
|
var split = ("" + error.data.fault_code).split('\n')[0].split(' -- ');
|
2011-06-22 14:57:57 +00:00
|
|
|
if (split.length > 1) {
|
|
|
|
error.type = split.shift();
|
|
|
|
error.data.fault_code = error.data.fault_code.substr(error.type.length + 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (error.code === 200 && error.type) {
|
2012-10-11 00:37:29 +00:00
|
|
|
this.show_warning(error);
|
2011-06-21 12:10:02 +00:00
|
|
|
} else {
|
2012-10-11 00:37:29 +00:00
|
|
|
this.show_error(error);
|
2011-06-21 12:10:02 +00:00
|
|
|
}
|
2011-10-17 15:24:00 +00:00
|
|
|
},
|
2012-10-11 00:37:29 +00:00
|
|
|
show_warning: function(error) {
|
2012-11-15 12:03:31 +00:00
|
|
|
if (!this.active) {
|
|
|
|
return;
|
|
|
|
}
|
2012-05-15 07:41:39 +00:00
|
|
|
instance.web.dialog($('<div>' + QWeb.render('CrashManager.warning', {error: error}) + '</div>'), {
|
2011-11-15 12:30:59 +00:00
|
|
|
title: "OpenERP " + _.str.capitalize(error.type),
|
2011-12-15 10:40:31 +00:00
|
|
|
buttons: [
|
|
|
|
{text: _t("Ok"), click: function() { $(this).dialog("close"); }}
|
|
|
|
]
|
2011-10-17 15:24:00 +00:00
|
|
|
});
|
|
|
|
},
|
2012-10-11 00:37:29 +00:00
|
|
|
show_error: function(error) {
|
2012-11-15 12:03:31 +00:00
|
|
|
if (!this.active) {
|
|
|
|
return;
|
|
|
|
}
|
2011-12-27 15:59:15 +00:00
|
|
|
var buttons = {};
|
2012-08-27 21:32:12 +00:00
|
|
|
buttons[_t("Ok")] = function() {
|
|
|
|
$(this).dialog("close");
|
|
|
|
};
|
2012-04-17 11:48:37 +00:00
|
|
|
var dialog = new instance.web.Dialog(this, {
|
2012-02-06 16:23:47 +00:00
|
|
|
title: "OpenERP " + _.str.capitalize(error.type),
|
2011-12-07 11:00:57 +00:00
|
|
|
width: '80%',
|
|
|
|
height: '50%',
|
2011-10-17 15:24:00 +00:00
|
|
|
min_width: '800px',
|
|
|
|
min_height: '600px',
|
2011-12-23 12:06:34 +00:00
|
|
|
buttons: buttons
|
2012-01-11 11:06:48 +00:00
|
|
|
}).open();
|
2012-08-24 18:27:07 +00:00
|
|
|
dialog.$el.html(QWeb.render('CrashManager.error', {session: instance.session, error: error}));
|
2012-06-18 14:02:50 +00:00
|
|
|
},
|
2012-10-11 00:37:29 +00:00
|
|
|
show_message: function(exception) {
|
|
|
|
this.show_error({
|
2012-07-13 15:01:56 +00:00
|
|
|
type: _t("Client Error"),
|
|
|
|
message: exception,
|
|
|
|
data: {debug: ""}
|
|
|
|
});
|
2012-06-18 14:02:50 +00:00
|
|
|
},
|
2011-04-04 19:52:16 +00:00
|
|
|
});
|
|
|
|
|
2012-04-17 11:48:37 +00:00
|
|
|
instance.web.Loading = instance.web.Widget.extend({
|
2012-11-29 00:22:00 +00:00
|
|
|
template: _t("Loading"),
|
2011-11-15 16:55:30 +00:00
|
|
|
init: function(parent) {
|
|
|
|
this._super(parent);
|
2011-03-16 23:56:34 +00:00
|
|
|
this.count = 0;
|
2011-10-27 13:58:28 +00:00
|
|
|
this.blocked_ui = false;
|
2012-09-28 00:24:51 +00:00
|
|
|
this.session.on("request", this, this.request_call);
|
|
|
|
this.session.on("response", this, this.response_call);
|
2012-10-11 00:37:29 +00:00
|
|
|
this.session.on("response_failed", this, this.response_call);
|
2012-01-04 18:11:50 +00:00
|
|
|
},
|
2012-02-21 16:29:12 +00:00
|
|
|
destroy: function() {
|
2012-01-04 18:21:12 +00:00
|
|
|
this.on_rpc_event(-this.count);
|
2012-01-04 18:11:50 +00:00
|
|
|
this._super();
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
2012-09-28 00:24:51 +00:00
|
|
|
request_call: function() {
|
|
|
|
this.on_rpc_event(1);
|
|
|
|
},
|
|
|
|
response_call: function() {
|
|
|
|
this.on_rpc_event(-1);
|
|
|
|
},
|
2011-03-16 23:56:34 +00:00
|
|
|
on_rpc_event : function(increment) {
|
2011-10-27 13:58:28 +00:00
|
|
|
var self = this;
|
|
|
|
if (!this.count && increment === 1) {
|
|
|
|
// Block UI after 3s
|
|
|
|
this.long_running_timer = setTimeout(function () {
|
|
|
|
self.blocked_ui = true;
|
2012-07-24 14:12:20 +00:00
|
|
|
instance.web.blockUI();
|
2011-10-27 13:58:28 +00:00
|
|
|
}, 3000);
|
|
|
|
}
|
|
|
|
|
2011-03-16 23:56:34 +00:00
|
|
|
this.count += increment;
|
2011-11-15 16:55:30 +00:00
|
|
|
if (this.count > 0) {
|
2012-08-14 15:29:00 +00:00
|
|
|
if (instance.session.debug) {
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.text(_.str.sprintf( _t("Loading (%d)"), this.count));
|
2012-08-02 14:36:50 +00:00
|
|
|
} else {
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.text(_t("Loading"));
|
2012-08-02 14:36:50 +00:00
|
|
|
}
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.show();
|
|
|
|
this.getParent().$el.addClass('oe_wait');
|
2011-03-16 23:56:34 +00:00
|
|
|
} else {
|
2011-11-15 16:55:30 +00:00
|
|
|
this.count = 0;
|
2011-10-27 13:58:28 +00:00
|
|
|
clearTimeout(this.long_running_timer);
|
|
|
|
// Don't unblock if blocked by somebody else
|
|
|
|
if (self.blocked_ui) {
|
|
|
|
this.blocked_ui = false;
|
2012-07-24 14:12:20 +00:00
|
|
|
instance.web.unblockUI();
|
2011-10-27 13:58:28 +00:00
|
|
|
}
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.fadeOut();
|
|
|
|
this.getParent().$el.removeClass('oe_wait');
|
2011-03-16 23:56:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-04-17 11:48:37 +00:00
|
|
|
instance.web.DatabaseManager = instance.web.Widget.extend({
|
2012-04-08 16:52:25 +00:00
|
|
|
init: function(parent) {
|
|
|
|
this._super(parent);
|
2012-07-24 14:12:20 +00:00
|
|
|
this.unblockUIFunction = instance.web.unblockUI;
|
2012-01-17 12:00:35 +00:00
|
|
|
$.validator.addMethod('matches', function (s, _, re) {
|
|
|
|
return new RegExp(re).test(s);
|
|
|
|
}, _t("Invalid database name"));
|
2011-07-26 08:03:18 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
2011-06-29 06:17:55 +00:00
|
|
|
var self = this;
|
2012-08-07 12:50:37 +00:00
|
|
|
$('.oe_secondary_menus_container,.oe_user_menu_placeholder').empty();
|
2012-10-30 14:06:30 +00:00
|
|
|
var fetch_db = this.rpc("/web/database/get_list", {}).then(
|
2012-05-15 07:41:39 +00:00
|
|
|
function(result) {
|
2012-10-25 15:47:45 +00:00
|
|
|
self.db_list = result;
|
2012-04-08 22:42:01 +00:00
|
|
|
},
|
2012-05-15 07:41:39 +00:00
|
|
|
function (_, ev) {
|
2012-04-08 22:42:01 +00:00
|
|
|
ev.preventDefault();
|
2012-05-15 07:41:39 +00:00
|
|
|
self.db_list = null;
|
2012-04-08 22:42:01 +00:00
|
|
|
});
|
2012-10-30 14:06:30 +00:00
|
|
|
var fetch_langs = this.rpc("/web/session/get_lang_list", {}).done(function(result) {
|
2012-10-25 15:47:45 +00:00
|
|
|
self.lang_list = result;
|
2011-07-01 06:58:42 +00:00
|
|
|
});
|
2012-10-30 14:06:30 +00:00
|
|
|
return $.when(fetch_db, fetch_langs).done(self.do_render);
|
2012-04-08 22:42:01 +00:00
|
|
|
},
|
|
|
|
do_render: function() {
|
|
|
|
var self = this;
|
2012-08-14 10:38:15 +00:00
|
|
|
instance.webclient.toggle_bars(true);
|
2012-08-24 18:27:07 +00:00
|
|
|
self.$el.html(QWeb.render("DatabaseManager", { widget : self }));
|
2012-08-11 21:48:09 +00:00
|
|
|
$('.oe_user_menu_placeholder').append(QWeb.render("DatabaseManager.user_menu",{ widget : self }));
|
|
|
|
$('.oe_secondary_menus_container').append(QWeb.render("DatabaseManager.menu",{ widget : self }));
|
2012-08-08 05:52:36 +00:00
|
|
|
$('ul.oe_secondary_submenu > li:first').addClass('oe_active')
|
2012-08-07 06:50:51 +00:00
|
|
|
$('ul.oe_secondary_submenu > li').bind('click', function (event) {
|
2012-08-11 21:48:09 +00:00
|
|
|
var menuitem = $(this);
|
|
|
|
menuitem.addClass('oe_active').siblings().removeClass('oe_active');
|
|
|
|
var form_id =menuitem.find('a').attr('href');
|
|
|
|
$(form_id).show().siblings().hide();
|
2012-08-07 06:50:51 +00:00
|
|
|
event.preventDefault();
|
2012-05-15 07:53:20 +00:00
|
|
|
});
|
2012-08-11 21:48:09 +00:00
|
|
|
$('#back-to-login').click(self.do_exit);
|
2012-08-24 18:27:07 +00:00
|
|
|
self.$el.find("td").addClass("oe_form_group_cell");
|
|
|
|
self.$el.find("tr td:first-child").addClass("oe_form_group_cell_label");
|
|
|
|
self.$el.find("label").addClass("oe_form_label");
|
|
|
|
self.$el.find("form[name=create_db_form]").validate({ submitHandler: self.do_create });
|
2012-10-19 10:12:59 +00:00
|
|
|
self.$el.find("form[name=duplicate_db_form]").validate({ submitHandler: self.do_duplicate });
|
2012-08-24 18:27:07 +00:00
|
|
|
self.$el.find("form[name=drop_db_form]").validate({ submitHandler: self.do_drop });
|
|
|
|
self.$el.find("form[name=backup_db_form]").validate({ submitHandler: self.do_backup });
|
|
|
|
self.$el.find("form[name=restore_db_form]").validate({ submitHandler: self.do_restore });
|
|
|
|
self.$el.find("form[name=change_pwd_form]").validate({
|
2012-04-08 22:42:01 +00:00
|
|
|
messages: {
|
2012-11-29 00:22:00 +00:00
|
|
|
old_pwd: _t("Please enter your previous password"),
|
|
|
|
new_pwd: _t("Please enter your new password"),
|
2012-04-08 22:42:01 +00:00
|
|
|
confirm_pwd: {
|
2012-11-29 00:22:00 +00:00
|
|
|
required: _t("Please confirm your new password"),
|
|
|
|
equalTo: _t("The confirmation does not match the password")
|
2012-04-08 22:42:01 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
submitHandler: self.do_change_password
|
|
|
|
});
|
2011-07-26 08:03:18 +00:00
|
|
|
},
|
2012-02-21 16:29:12 +00:00
|
|
|
destroy: function () {
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.find('#db-create, #db-drop, #db-backup, #db-restore, #db-change-password, #back-to-login').unbind('click').end().empty();
|
2011-11-15 12:30:59 +00:00
|
|
|
this._super();
|
2011-11-15 09:34:48 +00:00
|
|
|
},
|
2011-08-01 09:56:49 +00:00
|
|
|
/**
|
|
|
|
* Converts a .serializeArray() result into a dict. Does not bother folding
|
|
|
|
* multiple identical keys into an array, last key wins.
|
|
|
|
*
|
|
|
|
* @param {Array} array
|
|
|
|
*/
|
|
|
|
to_object: function (array) {
|
|
|
|
var result = {};
|
|
|
|
_(array).each(function (record) {
|
|
|
|
result[record.name] = record.value;
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
},
|
2011-12-05 13:24:25 +00:00
|
|
|
/**
|
|
|
|
* Blocks UI and replaces $.unblockUI by a noop to prevent third parties
|
|
|
|
* from unblocking the UI
|
|
|
|
*/
|
|
|
|
blockUI: function () {
|
2012-07-24 14:12:20 +00:00
|
|
|
instance.web.blockUI();
|
|
|
|
instance.web.unblockUI = function () {};
|
2011-12-05 13:24:25 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Reinstates $.unblockUI so third parties can play with blockUI, and
|
|
|
|
* unblocks the UI
|
|
|
|
*/
|
|
|
|
unblockUI: function () {
|
2012-07-24 14:12:20 +00:00
|
|
|
instance.web.unblockUI = this.unblockUIFunction;
|
|
|
|
instance.web.unblockUI();
|
2011-12-05 13:24:25 +00:00
|
|
|
},
|
2011-08-02 09:13:44 +00:00
|
|
|
/**
|
|
|
|
* Displays an error dialog resulting from the various RPC communications
|
|
|
|
* failing over themselves
|
|
|
|
*
|
|
|
|
* @param {Object} error error description
|
|
|
|
* @param {String} error.title title of the error dialog
|
|
|
|
* @param {String} error.error message of the error dialog
|
|
|
|
*/
|
|
|
|
display_error: function (error) {
|
2012-04-17 11:48:37 +00:00
|
|
|
return instance.web.dialog($('<div>'), {
|
2011-08-02 09:13:44 +00:00
|
|
|
modal: true,
|
|
|
|
title: error.title,
|
2011-12-15 10:40:31 +00:00
|
|
|
buttons: [
|
|
|
|
{text: _t("Ok"), click: function() { $(this).dialog("close"); }}
|
|
|
|
]
|
2011-08-02 09:13:44 +00:00
|
|
|
}).html(error.error);
|
|
|
|
},
|
2012-04-08 22:42:01 +00:00
|
|
|
do_create: function(form) {
|
2011-07-26 08:03:18 +00:00
|
|
|
var self = this;
|
2012-04-08 22:42:01 +00:00
|
|
|
var fields = $(form).serializeArray();
|
2012-10-30 14:06:30 +00:00
|
|
|
self.rpc("/web/database/create", {'fields': fields}).done(function(result) {
|
2012-04-08 22:42:01 +00:00
|
|
|
var form_obj = self.to_object(fields);
|
2012-07-26 09:07:12 +00:00
|
|
|
var client_action = {
|
|
|
|
type: 'ir.actions.client',
|
|
|
|
tag: 'login',
|
|
|
|
params: {
|
|
|
|
'db': form_obj['db_name'],
|
|
|
|
'login': 'admin',
|
|
|
|
'password': form_obj['create_admin_pwd'],
|
2012-08-06 15:02:48 +00:00
|
|
|
'login_successful': function() {
|
2012-08-21 17:12:05 +00:00
|
|
|
self.do_action("reload");
|
2012-08-06 15:02:48 +00:00
|
|
|
},
|
2012-07-26 09:07:12 +00:00
|
|
|
},
|
2013-01-25 11:01:59 +00:00
|
|
|
_push_me: false,
|
2012-07-26 09:07:12 +00:00
|
|
|
};
|
|
|
|
self.do_action(client_action);
|
2011-07-26 08:03:18 +00:00
|
|
|
});
|
2011-07-13 07:07:12 +00:00
|
|
|
},
|
2012-10-19 10:12:59 +00:00
|
|
|
do_duplicate: function(form) {
|
|
|
|
var self = this;
|
|
|
|
var fields = $(form).serializeArray();
|
|
|
|
self.rpc("/web/database/duplicate", {'fields': fields}).then(function(result) {
|
|
|
|
if (result.error) {
|
|
|
|
self.display_error(result);
|
|
|
|
return;
|
|
|
|
}
|
2012-11-29 00:22:00 +00:00
|
|
|
self.do_notify(_t("Duplicating database"), _t("The database has been duplicated."));
|
2012-10-19 10:12:59 +00:00
|
|
|
self.start();
|
|
|
|
});
|
|
|
|
},
|
2012-04-08 22:42:01 +00:00
|
|
|
do_drop: function(form) {
|
2011-07-26 08:03:18 +00:00
|
|
|
var self = this;
|
2012-04-08 22:42:01 +00:00
|
|
|
var $form = $(form),
|
|
|
|
fields = $form.serializeArray(),
|
|
|
|
$db_list = $form.find('[name=drop_db]'),
|
|
|
|
db = $db_list.val();
|
2012-11-29 00:22:00 +00:00
|
|
|
if (!db || !confirm(_.str.sprintf(_t("Do you really want to delete the database: %s ?"), db))) {
|
2012-04-08 22:42:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-10-30 14:06:30 +00:00
|
|
|
self.rpc("/web/database/drop", {'fields': fields}).done(function(result) {
|
2012-04-08 22:42:01 +00:00
|
|
|
if (result.error) {
|
|
|
|
self.display_error(result);
|
|
|
|
return;
|
2011-08-01 09:17:33 +00:00
|
|
|
}
|
2012-11-29 00:22:00 +00:00
|
|
|
self.do_notify(_t("Dropping database"), _.str.sprintf(_t("The database %s has been dropped"), db));
|
2012-04-08 22:42:01 +00:00
|
|
|
self.start();
|
2011-06-29 18:15:57 +00:00
|
|
|
});
|
2011-07-13 07:07:12 +00:00
|
|
|
},
|
2012-04-08 22:42:01 +00:00
|
|
|
do_backup: function(form) {
|
2011-07-26 08:03:18 +00:00
|
|
|
var self = this;
|
2012-04-08 22:42:01 +00:00
|
|
|
self.blockUI();
|
|
|
|
self.session.get_file({
|
|
|
|
form: form,
|
|
|
|
success: function () {
|
|
|
|
self.do_notify(_t("Backed"), _t("Database backed up successfully"));
|
|
|
|
},
|
2012-06-21 09:04:25 +00:00
|
|
|
error: function(error){
|
|
|
|
if(error){
|
|
|
|
self.display_error({
|
2012-11-29 00:22:00 +00:00
|
|
|
title: _t("Backup Database"),
|
2012-05-15 09:00:51 +00:00
|
|
|
error: 'AccessDenied'
|
2012-06-21 09:04:25 +00:00
|
|
|
});
|
|
|
|
}
|
2012-05-15 09:00:51 +00:00
|
|
|
},
|
2012-04-08 22:42:01 +00:00
|
|
|
complete: function() {
|
|
|
|
self.unblockUI();
|
2011-08-01 10:44:53 +00:00
|
|
|
}
|
|
|
|
});
|
2011-07-13 07:07:12 +00:00
|
|
|
},
|
2012-04-08 22:42:01 +00:00
|
|
|
do_restore: function(form) {
|
2011-07-26 08:03:18 +00:00
|
|
|
var self = this;
|
2012-04-08 22:42:01 +00:00
|
|
|
self.blockUI();
|
|
|
|
$(form).ajaxSubmit({
|
|
|
|
url: '/web/database/restore',
|
|
|
|
type: 'POST',
|
|
|
|
resetForm: true,
|
|
|
|
success: function (body) {
|
|
|
|
// If empty body, everything went fine
|
|
|
|
if (!body) { return; }
|
2011-08-02 09:13:44 +00:00
|
|
|
|
2012-04-08 22:42:01 +00:00
|
|
|
if (body.indexOf('403 Forbidden') !== -1) {
|
|
|
|
self.display_error({
|
2012-11-29 00:22:00 +00:00
|
|
|
title: _t("Access Denied"),
|
|
|
|
error: _t("Incorrect super-administrator password")
|
2012-05-15 07:41:39 +00:00
|
|
|
});
|
2012-04-08 22:42:01 +00:00
|
|
|
} else {
|
|
|
|
self.display_error({
|
2012-11-29 00:22:00 +00:00
|
|
|
title: _t("Restore Database"),
|
|
|
|
error: _t("Could not restore the database")
|
2012-05-15 07:41:39 +00:00
|
|
|
});
|
2012-04-08 22:42:01 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
complete: function() {
|
|
|
|
self.unblockUI();
|
|
|
|
self.do_notify(_t("Restored"), _t("Database restored successfully"));
|
2011-08-01 10:44:53 +00:00
|
|
|
}
|
|
|
|
});
|
2011-07-26 08:03:18 +00:00
|
|
|
},
|
2012-04-08 22:42:01 +00:00
|
|
|
do_change_password: function(form) {
|
2011-07-26 08:03:18 +00:00
|
|
|
var self = this;
|
2012-04-08 22:42:01 +00:00
|
|
|
self.rpc("/web/database/change_password", {
|
|
|
|
'fields': $(form).serializeArray()
|
2012-10-30 14:06:30 +00:00
|
|
|
}).done(function(result) {
|
2012-04-08 22:42:01 +00:00
|
|
|
if (result.error) {
|
|
|
|
self.display_error(result);
|
|
|
|
return;
|
2011-08-01 10:44:53 +00:00
|
|
|
}
|
2012-08-07 12:22:28 +00:00
|
|
|
self.unblockUI();
|
2012-11-29 00:22:00 +00:00
|
|
|
self.do_notify(_t("Changed Password"), _t("Password has been changed successfully"));
|
2011-08-01 10:44:53 +00:00
|
|
|
});
|
2012-04-08 16:52:25 +00:00
|
|
|
},
|
|
|
|
do_exit: function () {
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.remove();
|
2012-12-11 15:18:24 +00:00
|
|
|
instance.webclient.show_login();
|
2011-07-26 08:03:18 +00:00
|
|
|
}
|
2011-04-05 15:53:48 +00:00
|
|
|
});
|
2012-07-26 01:36:28 +00:00
|
|
|
instance.web.client_actions.add("database_manager", "instance.web.DatabaseManager");
|
2011-04-05 15:53:48 +00:00
|
|
|
|
2012-04-17 11:48:37 +00:00
|
|
|
instance.web.Login = instance.web.Widget.extend({
|
2011-09-27 09:32:32 +00:00
|
|
|
template: "Login",
|
2012-04-08 16:52:25 +00:00
|
|
|
remember_credentials: true,
|
2012-05-23 16:29:03 +00:00
|
|
|
|
2012-11-05 13:00:53 +00:00
|
|
|
init: function(parent, action) {
|
2011-09-27 09:32:32 +00:00
|
|
|
this._super(parent);
|
2011-06-08 09:44:26 +00:00
|
|
|
this.has_local_storage = typeof(localStorage) != 'undefined';
|
2012-08-15 16:46:30 +00:00
|
|
|
this.db_list = null;
|
2011-06-08 09:44:26 +00:00
|
|
|
this.selected_db = null;
|
|
|
|
this.selected_login = null;
|
2012-11-05 13:00:53 +00:00
|
|
|
this.params = action.params || {};
|
2012-11-14 15:17:14 +00:00
|
|
|
if (_.isEmpty(this.params)) {
|
|
|
|
this.params = $.bbq.getState(true);
|
|
|
|
}
|
2012-08-01 15:39:27 +00:00
|
|
|
|
|
|
|
if (this.params.login_successful) {
|
|
|
|
this.on('login_successful', this, this.params.login_successful);
|
|
|
|
}
|
2011-07-05 04:38:11 +00:00
|
|
|
|
2011-10-14 15:49:50 +00:00
|
|
|
if (this.has_local_storage && this.remember_credentials) {
|
2011-06-08 09:44:26 +00:00
|
|
|
this.selected_db = localStorage.getItem('last_db_login_success');
|
|
|
|
this.selected_login = localStorage.getItem('last_login_login_success');
|
2012-05-15 07:41:39 +00:00
|
|
|
if (jQuery.deparam(jQuery.param.querystring()).debug !== undefined) {
|
2011-09-02 09:46:26 +00:00
|
|
|
this.selected_password = localStorage.getItem('last_password_login_success');
|
|
|
|
}
|
2011-07-12 09:11:31 +00:00
|
|
|
}
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
2011-06-06 11:43:06 +00:00
|
|
|
var self = this;
|
2012-08-24 18:27:07 +00:00
|
|
|
self.$el.find("form").submit(self.on_submit);
|
|
|
|
self.$el.find('.oe_login_manage_db').click(function() {
|
2012-07-26 09:07:12 +00:00
|
|
|
self.do_action("database_manager");
|
|
|
|
});
|
2012-11-19 17:00:42 +00:00
|
|
|
var d = $.when();
|
|
|
|
if ($.deparam.querystring().db) {
|
|
|
|
self.params.db = $.deparam.querystring().db;
|
|
|
|
}
|
2013-01-02 09:46:08 +00:00
|
|
|
if ($.param.fragment().token) {
|
|
|
|
self.params.token = $.param.fragment().token;
|
|
|
|
}
|
2012-11-19 17:00:42 +00:00
|
|
|
// used by dbmanager.do_create via internal client action
|
|
|
|
if (self.params.db && self.params.login && self.params.password) {
|
|
|
|
d = self.do_login(self.params.db, self.params.login, self.params.password);
|
2012-08-15 16:46:30 +00:00
|
|
|
} else {
|
2012-11-19 17:00:42 +00:00
|
|
|
if (self.params.db) {
|
|
|
|
self.on_db_loaded([self.params.db])
|
|
|
|
} else {
|
|
|
|
d = self.rpc("/web/database/get_list", {}).done(self.on_db_loaded).fail(self.on_db_failed);
|
|
|
|
}
|
2012-05-23 16:29:03 +00:00
|
|
|
}
|
|
|
|
return d;
|
2011-06-08 08:54:07 +00:00
|
|
|
},
|
2012-08-15 16:46:30 +00:00
|
|
|
on_db_loaded: function (result) {
|
2012-11-11 16:32:43 +00:00
|
|
|
this.db_list = result;
|
2012-08-15 16:46:30 +00:00
|
|
|
this.$("[name=db]").replaceWith(QWeb.render('Login.dblist', { db_list: this.db_list, selected_db: this.selected_db}));
|
|
|
|
if(this.db_list.length === 0) {
|
2012-07-26 09:07:12 +00:00
|
|
|
this.do_action("database_manager");
|
2012-08-15 16:46:30 +00:00
|
|
|
} else if(this.db_list.length === 1) {
|
|
|
|
this.$('div.oe_login_dbpane').hide();
|
2012-05-23 16:29:03 +00:00
|
|
|
} else {
|
2012-08-15 16:46:30 +00:00
|
|
|
this.$('div.oe_login_dbpane').show();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
on_db_failed: function (error, event) {
|
|
|
|
if (error.data.fault_code === 'AccessDenied') {
|
|
|
|
event.preventDefault();
|
2012-05-23 16:29:03 +00:00
|
|
|
}
|
2011-11-15 13:29:14 +00:00
|
|
|
},
|
2011-03-16 23:56:34 +00:00
|
|
|
on_submit: function(ev) {
|
2011-12-20 15:05:56 +00:00
|
|
|
if(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
}
|
2012-08-15 16:46:30 +00:00
|
|
|
var db = this.$("form [name=db]").val();
|
2012-02-13 10:01:02 +00:00
|
|
|
if (!db) {
|
2012-11-29 00:22:00 +00:00
|
|
|
this.do_warn(_t("Login"), _t("No database selected !"));
|
2012-02-13 10:01:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-08-15 16:46:30 +00:00
|
|
|
var login = this.$("form input[name=login]").val();
|
|
|
|
var password = this.$("form input[name=password]").val();
|
2011-08-02 08:28:03 +00:00
|
|
|
|
|
|
|
this.do_login(db, login, password);
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Performs actual login operation, and UI-related stuff
|
|
|
|
*
|
|
|
|
* @param {String} db database to log in
|
|
|
|
* @param {String} login user login
|
|
|
|
* @param {String} password user password
|
|
|
|
*/
|
|
|
|
do_login: function (db, login, password) {
|
|
|
|
var self = this;
|
2012-09-26 09:50:04 +00:00
|
|
|
self.hide_error();
|
2012-06-27 12:53:16 +00:00
|
|
|
self.$(".oe_login_pane").fadeOut("slow");
|
2012-10-30 14:06:30 +00:00
|
|
|
return this.session.session_authenticate(db, login, password).then(function() {
|
2011-12-22 11:46:35 +00:00
|
|
|
if (self.has_local_storage) {
|
|
|
|
if(self.remember_credentials) {
|
|
|
|
localStorage.setItem('last_db_login_success', db);
|
|
|
|
localStorage.setItem('last_login_login_success', login);
|
2012-05-15 07:41:39 +00:00
|
|
|
if (jQuery.deparam(jQuery.param.querystring()).debug !== undefined) {
|
2011-12-22 11:46:35 +00:00
|
|
|
localStorage.setItem('last_password_login_success', password);
|
2011-06-08 09:44:26 +00:00
|
|
|
}
|
2011-12-22 11:46:35 +00:00
|
|
|
} else {
|
|
|
|
localStorage.setItem('last_db_login_success', '');
|
|
|
|
localStorage.setItem('last_login_login_success', '');
|
|
|
|
localStorage.setItem('last_password_login_success', '');
|
2011-06-08 09:44:26 +00:00
|
|
|
}
|
2011-03-16 23:56:34 +00:00
|
|
|
}
|
2012-07-26 16:16:05 +00:00
|
|
|
self.trigger('login_successful');
|
2012-09-26 09:50:04 +00:00
|
|
|
}, function () {
|
2012-08-14 10:38:15 +00:00
|
|
|
self.$(".oe_login_pane").fadeIn("fast", function() {
|
2012-11-29 00:22:00 +00:00
|
|
|
self.show_error(_t("Invalid username or password"));
|
2012-08-14 10:38:15 +00:00
|
|
|
});
|
2011-03-16 23:56:34 +00:00
|
|
|
});
|
2012-07-26 01:36:28 +00:00
|
|
|
},
|
2012-09-26 09:50:04 +00:00
|
|
|
show_error: function(message) {
|
|
|
|
this.$el.addClass("oe_login_invalid");
|
|
|
|
this.$(".oe_login_error_message").text(message);
|
|
|
|
},
|
|
|
|
hide_error: function() {
|
|
|
|
this.$el.removeClass('oe_login_invalid');
|
|
|
|
},
|
2012-07-26 01:36:28 +00:00
|
|
|
});
|
|
|
|
instance.web.client_actions.add("login", "instance.web.Login");
|
2011-03-16 23:56:34 +00:00
|
|
|
|
2012-10-31 12:01:17 +00:00
|
|
|
|
2012-11-14 23:37:43 +00:00
|
|
|
/**
|
|
|
|
* Redirect to url by replacing window.location
|
|
|
|
* If wait is true, sleep 1s and wait for the server i.e. after a restart.
|
|
|
|
*/
|
|
|
|
instance.web.redirect = function(url, wait) {
|
|
|
|
// Dont display a dialog if some xmlhttprequest are in progress
|
|
|
|
if (instance.client && instance.client.crashmanager) {
|
2012-11-15 12:03:31 +00:00
|
|
|
instance.client.crashmanager.active = false;
|
2012-11-14 23:37:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var wait_server = function() {
|
|
|
|
instance.session.rpc("/web/webclient/version_info", {}).done(function() {
|
|
|
|
window.location = url;
|
|
|
|
}).fail(function() {
|
|
|
|
setTimeout(wait_server, 250);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
if (wait) {
|
|
|
|
setTimeout(wait_server, 1000);
|
|
|
|
} else {
|
|
|
|
window.location = url;
|
|
|
|
}
|
2012-11-15 12:03:31 +00:00
|
|
|
};
|
2012-11-14 23:37:43 +00:00
|
|
|
|
2012-08-06 10:33:30 +00:00
|
|
|
/**
|
|
|
|
* Client action to reload the whole interface.
|
2012-11-14 23:37:43 +00:00
|
|
|
* If params.menu_id, it opens the given menu entry.
|
|
|
|
* If params.wait, reload will wait the openerp server to be reachable before reloading
|
2012-08-06 10:33:30 +00:00
|
|
|
*/
|
2012-11-05 13:00:53 +00:00
|
|
|
instance.web.Reload = function(parent, action) {
|
|
|
|
var params = action.params || {};
|
|
|
|
var menu_id = params.menu_id || false;
|
2012-10-03 11:42:58 +00:00
|
|
|
var l = window.location;
|
2012-08-16 13:34:59 +00:00
|
|
|
|
2012-10-03 11:42:58 +00:00
|
|
|
var sobj = $.deparam(l.search.substr(1));
|
|
|
|
sobj.ts = new Date().getTime();
|
|
|
|
var search = '?' + $.param(sobj);
|
2012-08-16 13:34:59 +00:00
|
|
|
|
2012-10-03 11:42:58 +00:00
|
|
|
var hash = l.hash;
|
|
|
|
if (menu_id) {
|
|
|
|
hash = "#menu_id=" + menu_id;
|
2012-08-06 10:33:30 +00:00
|
|
|
}
|
2012-10-03 11:42:58 +00:00
|
|
|
var url = l.protocol + "//" + l.host + l.pathname + search + hash;
|
2012-11-14 23:37:43 +00:00
|
|
|
|
|
|
|
instance.web.redirect(url, params.wait);
|
2012-10-03 11:42:58 +00:00
|
|
|
};
|
2012-08-06 10:33:30 +00:00
|
|
|
instance.web.client_actions.add("reload", "instance.web.Reload");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client action to go back in breadcrumb history.
|
|
|
|
* If can't go back in history stack, will go back to home.
|
|
|
|
*/
|
2012-11-05 13:00:53 +00:00
|
|
|
instance.web.HistoryBack = function(parent) {
|
2012-10-03 11:42:58 +00:00
|
|
|
if (!parent.history_back()) {
|
2012-11-14 23:37:43 +00:00
|
|
|
instance.web.Home(parent);
|
2012-08-06 10:33:30 +00:00
|
|
|
}
|
2012-10-03 11:42:58 +00:00
|
|
|
};
|
2012-08-06 10:33:30 +00:00
|
|
|
instance.web.client_actions.add("history_back", "instance.web.HistoryBack");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client action to go back home.
|
|
|
|
*/
|
2012-11-14 23:37:43 +00:00
|
|
|
instance.web.Home = function(parent, action) {
|
|
|
|
var url = '/' + (window.location.search || '');
|
|
|
|
instance.web.redirect(url, action.params && action.params.wait);
|
|
|
|
};
|
2012-08-06 10:33:30 +00:00
|
|
|
instance.web.client_actions.add("home", "instance.web.Home");
|
|
|
|
|
2012-08-08 19:28:55 +00:00
|
|
|
instance.web.ChangePassword = instance.web.Widget.extend({
|
|
|
|
template: "ChangePassword",
|
|
|
|
start: function() {
|
|
|
|
var self = this;
|
2012-11-29 00:22:00 +00:00
|
|
|
this.getParent().dialog_title = _t("Change Password");
|
2012-11-12 13:07:56 +00:00
|
|
|
var $button = self.$el.find('.oe_form_button');
|
2012-11-19 07:11:42 +00:00
|
|
|
$button.appendTo(this.getParent().$buttons);
|
|
|
|
$button.eq(2).click(function(){
|
2012-11-16 11:08:38 +00:00
|
|
|
self.getParent().close();
|
|
|
|
})
|
2012-11-19 07:11:42 +00:00
|
|
|
$button.eq(0).click(function(){
|
2012-11-16 11:08:38 +00:00
|
|
|
self.rpc("/web/session/change_password",{
|
|
|
|
'fields': $("form[name=change_password_form]").serializeArray()
|
|
|
|
}).done(function(result) {
|
|
|
|
if (result.error) {
|
|
|
|
self.display_error(result);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
instance.webclient.on_logout();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
2012-08-08 19:28:55 +00:00
|
|
|
},
|
|
|
|
display_error: function (error) {
|
|
|
|
return instance.web.dialog($('<div>'), {
|
|
|
|
modal: true,
|
|
|
|
title: error.title,
|
|
|
|
buttons: [
|
2012-08-09 06:19:36 +00:00
|
|
|
{text: _t("Ok"), click: function() { $(this).dialog("close"); }}
|
2012-08-08 19:28:55 +00:00
|
|
|
]
|
|
|
|
}).html(error.error);
|
|
|
|
},
|
|
|
|
})
|
|
|
|
instance.web.client_actions.add("change_password", "instance.web.ChangePassword");
|
|
|
|
|
2012-04-17 11:48:37 +00:00
|
|
|
instance.web.Menu = instance.web.Widget.extend({
|
2012-02-23 15:39:21 +00:00
|
|
|
template: 'Menu',
|
2012-02-29 13:02:35 +00:00
|
|
|
init: function() {
|
2012-11-29 16:42:53 +00:00
|
|
|
var self = this;
|
2012-02-29 13:02:35 +00:00
|
|
|
this._super.apply(this, arguments);
|
|
|
|
this.has_been_loaded = $.Deferred();
|
2012-03-27 19:32:12 +00:00
|
|
|
this.maximum_visible_links = 'auto'; // # of menu to show. 0 = do not crop, 'auto' = algo
|
2012-04-29 23:09:26 +00:00
|
|
|
this.data = {data:{children:[]}};
|
2012-12-12 20:51:20 +00:00
|
|
|
this.on("menu_loaded", this, function (menu_data) {
|
2012-12-13 10:58:21 +00:00
|
|
|
self.reflow();
|
2012-11-29 16:42:53 +00:00
|
|
|
// launch the fetch of needaction counters, asynchronous
|
2012-12-12 20:51:20 +00:00
|
|
|
if (!_.isEmpty(menu_data.all_menu_ids)) {
|
|
|
|
this.rpc("/web/menu/load_needaction", {menu_ids: menu_data.all_menu_ids}).done(function(r) {
|
|
|
|
self.on_needaction_loaded(r);
|
|
|
|
});
|
|
|
|
}
|
2012-11-29 16:42:53 +00:00
|
|
|
});
|
2012-12-19 09:55:50 +00:00
|
|
|
var lazyreflow = _.debounce(this.reflow.bind(this), 200);
|
|
|
|
instance.web.bus.on('resize', this, function() {
|
|
|
|
self.$el.height(0);
|
|
|
|
lazyreflow();
|
|
|
|
});
|
2012-02-29 13:02:35 +00:00
|
|
|
},
|
2012-03-06 11:02:12 +00:00
|
|
|
start: function() {
|
|
|
|
this._super.apply(this, arguments);
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$secondary_menus = this.getParent().$el.find('.oe_secondary_menus_container');
|
2012-07-02 09:56:42 +00:00
|
|
|
this.$secondary_menus.on('click', 'a[data-menu]', this.on_menu_click);
|
2012-04-29 23:09:26 +00:00
|
|
|
return this.do_reload();
|
2012-03-06 11:02:12 +00:00
|
|
|
},
|
2011-10-13 08:14:45 +00:00
|
|
|
do_reload: function() {
|
2012-10-18 08:50:28 +00:00
|
|
|
var self = this;
|
2012-10-30 14:06:30 +00:00
|
|
|
return this.rpc("/web/menu/load", {}).done(function(r) {
|
2012-10-18 08:50:28 +00:00
|
|
|
self.menu_loaded(r);
|
|
|
|
});
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
2012-10-18 08:50:28 +00:00
|
|
|
menu_loaded: function(data) {
|
2012-03-27 19:32:12 +00:00
|
|
|
var self = this;
|
2012-12-11 02:13:38 +00:00
|
|
|
this.data = {data: data};
|
2012-02-29 11:07:44 +00:00
|
|
|
this.renderElement();
|
2012-04-29 23:09:26 +00:00
|
|
|
this.$secondary_menus.html(QWeb.render("Menu.secondary", { widget : this }));
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.on('click', 'a[data-menu]', this.on_menu_click);
|
2012-02-28 13:41:21 +00:00
|
|
|
// Hide second level submenus
|
|
|
|
this.$secondary_menus.find('.oe_menu_toggler').siblings('.oe_secondary_submenu').hide();
|
2012-04-29 23:09:26 +00:00
|
|
|
if (self.current_menu) {
|
|
|
|
self.open_menu(self.current_menu);
|
|
|
|
}
|
2012-10-18 08:50:28 +00:00
|
|
|
this.trigger('menu_loaded', data);
|
2012-02-29 13:02:35 +00:00
|
|
|
this.has_been_loaded.resolve();
|
2012-11-27 14:29:44 +00:00
|
|
|
},
|
|
|
|
on_needaction_loaded: function(data) {
|
|
|
|
var self = this;
|
|
|
|
this.needaction_data = data;
|
2012-12-11 02:13:38 +00:00
|
|
|
_.each(this.needaction_data, function (item, menu_id) {
|
2012-11-27 14:29:44 +00:00
|
|
|
var $item = self.$secondary_menus.find('a[data-menu="' + menu_id + '"]');
|
2013-01-22 14:38:42 +00:00
|
|
|
$item.find('.oe_menu_counter').remove();
|
2012-11-27 14:29:44 +00:00
|
|
|
if (item.needaction_counter && item.needaction_counter > 0) {
|
2012-11-29 16:14:28 +00:00
|
|
|
$item.append(QWeb.render("Menu.needaction_counter", { widget : item }));
|
2012-11-27 14:29:44 +00:00
|
|
|
}
|
|
|
|
});
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
2012-12-13 13:01:18 +00:00
|
|
|
/**
|
|
|
|
* Reflow the menu items and dock overflowing items into a "More" menu item.
|
|
|
|
* Automatically called when 'menu_loaded' event is triggered and on window resizing.
|
|
|
|
*/
|
2012-12-13 10:58:21 +00:00
|
|
|
reflow: function() {
|
|
|
|
var self = this;
|
2012-12-19 09:55:50 +00:00
|
|
|
this.$el.height('auto').show();
|
2012-12-17 12:32:56 +00:00
|
|
|
var $more_container = this.$('.oe_menu_more_container').hide();
|
|
|
|
var $more = this.$('.oe_menu_more');
|
2012-12-17 12:36:58 +00:00
|
|
|
$more.children('li').insertBefore($more_container);
|
2012-12-17 13:21:08 +00:00
|
|
|
var $toplevel_items = this.$el.children('li').not($more_container).hide();
|
|
|
|
$toplevel_items.each(function() {
|
2012-12-13 11:32:20 +00:00
|
|
|
var remaining_space = self.$el.parent().width() - $more_container.outerWidth();
|
2012-12-13 11:04:32 +00:00
|
|
|
self.$el.parent().children(':visible').each(function() {
|
|
|
|
remaining_space -= $(this).outerWidth();
|
|
|
|
});
|
2012-12-13 10:58:21 +00:00
|
|
|
if ($(this).width() > remaining_space) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$(this).show();
|
|
|
|
});
|
2012-12-17 13:21:08 +00:00
|
|
|
$more.append($toplevel_items.filter(':hidden').show());
|
2012-12-13 10:58:21 +00:00
|
|
|
$more_container.toggle(!!$more.children().length);
|
2012-12-13 12:26:34 +00:00
|
|
|
// Hide toplevel item if there is only one
|
2012-12-17 12:36:58 +00:00
|
|
|
var $toplevel = this.$el.children("li:visible");
|
2012-12-13 12:26:34 +00:00
|
|
|
if ($toplevel.length === 1) {
|
|
|
|
$toplevel.hide();
|
|
|
|
}
|
2012-12-13 10:58:21 +00:00
|
|
|
},
|
2011-12-22 15:34:49 +00:00
|
|
|
/**
|
|
|
|
* Opens a given menu by id, as if a user had browsed to that menu by hand
|
|
|
|
* except does not trigger any event on the way
|
|
|
|
*
|
2012-02-29 13:02:35 +00:00
|
|
|
* @param {Number} id database id of the terminal menu to select
|
2011-12-22 15:34:49 +00:00
|
|
|
*/
|
2012-02-28 13:41:21 +00:00
|
|
|
open_menu: function (id) {
|
2012-09-05 13:45:53 +00:00
|
|
|
this.current_menu = id;
|
|
|
|
this.session.active_id = id;
|
2012-02-28 13:41:21 +00:00
|
|
|
var $clicked_menu, $sub_menu, $main_menu;
|
2012-08-24 18:27:07 +00:00
|
|
|
$clicked_menu = this.$el.add(this.$secondary_menus).find('a[data-menu=' + id + ']');
|
2012-04-29 23:09:26 +00:00
|
|
|
this.trigger('open_menu', id, $clicked_menu);
|
2011-12-22 15:34:49 +00:00
|
|
|
|
2012-02-28 13:41:21 +00:00
|
|
|
if (this.$secondary_menus.has($clicked_menu).length) {
|
|
|
|
$sub_menu = $clicked_menu.parents('.oe_secondary_menu');
|
2012-08-24 18:27:07 +00:00
|
|
|
$main_menu = this.$el.find('a[data-menu=' + $sub_menu.data('menu-parent') + ']');
|
2011-12-22 15:34:49 +00:00
|
|
|
} else {
|
2012-02-28 13:41:21 +00:00
|
|
|
$sub_menu = this.$secondary_menus.find('.oe_secondary_menu[data-menu-parent=' + $clicked_menu.attr('data-menu') + ']');
|
|
|
|
$main_menu = $clicked_menu;
|
2011-12-22 15:34:49 +00:00
|
|
|
}
|
2012-02-28 13:41:21 +00:00
|
|
|
|
|
|
|
// Activate current main menu
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.find('.oe_active').removeClass('oe_active');
|
2012-02-28 13:41:21 +00:00
|
|
|
$main_menu.addClass('oe_active');
|
|
|
|
|
|
|
|
// Show current sub menu
|
|
|
|
this.$secondary_menus.find('.oe_secondary_menu').hide();
|
|
|
|
$sub_menu.show();
|
|
|
|
|
2012-04-30 16:54:55 +00:00
|
|
|
// Hide/Show the leftbar menu depending of the presence of sub-items
|
|
|
|
this.$secondary_menus.parent('.oe_leftbar').toggle(!!$sub_menu.children().length);
|
|
|
|
|
2012-02-28 13:41:21 +00:00
|
|
|
// Activate current menu item and show parents
|
|
|
|
this.$secondary_menus.find('.oe_active').removeClass('oe_active');
|
|
|
|
if ($main_menu !== $clicked_menu) {
|
|
|
|
$clicked_menu.parents().show();
|
|
|
|
if ($clicked_menu.is('.oe_menu_toggler')) {
|
|
|
|
$clicked_menu.toggleClass('oe_menu_opened').siblings('.oe_secondary_submenu:first').toggle();
|
|
|
|
} else {
|
|
|
|
$clicked_menu.parent().addClass('oe_active');
|
|
|
|
}
|
2011-12-22 15:34:49 +00:00
|
|
|
}
|
|
|
|
},
|
2012-04-29 23:09:26 +00:00
|
|
|
/**
|
|
|
|
* Call open_menu with the first menu_item matching an action_id
|
|
|
|
*
|
|
|
|
* @param {Number} id the action_id to match
|
|
|
|
*/
|
2012-02-29 13:02:35 +00:00
|
|
|
open_action: function (id) {
|
2012-08-24 18:27:07 +00:00
|
|
|
var $menu = this.$el.add(this.$secondary_menus).find('a[data-action-id="' + id + '"]');
|
2012-05-15 07:41:39 +00:00
|
|
|
var menu_id = $menu.data('menu');
|
|
|
|
if (menu_id) {
|
2012-02-29 13:02:35 +00:00
|
|
|
this.open_menu(menu_id);
|
|
|
|
}
|
|
|
|
},
|
2012-04-29 23:09:26 +00:00
|
|
|
/**
|
|
|
|
* Process a click on a menu item
|
|
|
|
*
|
|
|
|
* @param {Number} id the menu_id
|
2012-07-02 07:52:43 +00:00
|
|
|
* @param {Boolean} [needaction=false] whether the triggered action should execute in a `needs action` context
|
2012-04-29 23:09:26 +00:00
|
|
|
*/
|
2012-06-08 11:23:58 +00:00
|
|
|
menu_click: function(id, needaction) {
|
|
|
|
if (!id) { return; }
|
|
|
|
|
|
|
|
// find back the menuitem in dom to get the action
|
2012-08-24 18:27:07 +00:00
|
|
|
var $item = this.$el.find('a[data-menu=' + id + ']');
|
2012-06-08 11:23:58 +00:00
|
|
|
if (!$item.length) {
|
|
|
|
$item = this.$secondary_menus.find('a[data-menu=' + id + ']');
|
|
|
|
}
|
|
|
|
var action_id = $item.data('action-id');
|
|
|
|
// If first level menu doesnt have action trigger first leaf
|
|
|
|
if (!action_id) {
|
2012-08-24 18:27:07 +00:00
|
|
|
if(this.$el.has($item).length) {
|
2012-06-08 11:23:58 +00:00
|
|
|
var $sub_menu = this.$secondary_menus.find('.oe_secondary_menu[data-menu-parent=' + id + ']');
|
|
|
|
var $items = $sub_menu.find('a[data-action-id]').filter('[data-action-id!=""]');
|
|
|
|
if($items.length) {
|
|
|
|
action_id = $items.data('action-id');
|
|
|
|
id = $items.data('menu');
|
2012-05-15 07:41:39 +00:00
|
|
|
}
|
2011-03-22 11:49:19 +00:00
|
|
|
}
|
2012-06-08 11:23:58 +00:00
|
|
|
}
|
|
|
|
if (action_id) {
|
|
|
|
this.trigger('menu_click', {
|
|
|
|
action_id: action_id,
|
|
|
|
needaction: needaction,
|
2012-09-05 13:45:53 +00:00
|
|
|
id: id,
|
|
|
|
previous_menu_id: this.current_menu // Here we don't know if action will fail (in which case we have to revert menu)
|
2012-06-08 11:23:58 +00:00
|
|
|
}, $item);
|
2011-09-20 10:23:50 +00:00
|
|
|
}
|
2012-09-05 13:45:53 +00:00
|
|
|
this.open_menu(id);
|
2011-09-20 10:23:50 +00:00
|
|
|
},
|
2012-04-29 23:09:26 +00:00
|
|
|
/**
|
|
|
|
* Jquery event handler for menu click
|
|
|
|
*
|
|
|
|
* @param {Event} ev the jquery event
|
|
|
|
*/
|
|
|
|
on_menu_click: function(ev) {
|
2012-06-19 21:22:12 +00:00
|
|
|
ev.preventDefault();
|
2012-07-02 07:52:43 +00:00
|
|
|
var needaction = $(ev.target).is('div.oe_menu_counter');
|
2012-06-08 11:23:58 +00:00
|
|
|
this.menu_click($(ev.currentTarget).data('menu'), needaction);
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-04-17 11:48:37 +00:00
|
|
|
instance.web.UserMenu = instance.web.Widget.extend({
|
2012-02-29 14:15:27 +00:00
|
|
|
template: "UserMenu",
|
2012-02-23 17:44:39 +00:00
|
|
|
init: function(parent) {
|
|
|
|
this._super(parent);
|
2012-02-27 13:45:31 +00:00
|
|
|
this.update_promise = $.Deferred().resolve();
|
2012-02-23 17:44:39 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
var self = this;
|
|
|
|
this._super.apply(this, arguments);
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.on('click', '.oe_dropdown_menu li a[data-menu]', function(ev) {
|
2012-06-19 20:55:30 +00:00
|
|
|
ev.preventDefault();
|
2012-02-23 17:44:39 +00:00
|
|
|
var f = self['on_menu_' + $(this).data('menu')];
|
2012-05-15 07:41:39 +00:00
|
|
|
if (f) {
|
|
|
|
f($(this));
|
|
|
|
}
|
2012-02-23 17:44:39 +00:00
|
|
|
});
|
|
|
|
},
|
2012-02-27 13:45:31 +00:00
|
|
|
do_update: function () {
|
|
|
|
var self = this;
|
|
|
|
var fct = function() {
|
2012-08-24 18:27:07 +00:00
|
|
|
var $avatar = self.$el.find('.oe_topbar_avatar');
|
2012-02-27 13:45:31 +00:00
|
|
|
$avatar.attr('src', $avatar.data('default-src'));
|
|
|
|
if (!self.session.uid)
|
|
|
|
return;
|
2012-04-17 11:48:37 +00:00
|
|
|
var func = new instance.web.Model("res.users").get_func("read");
|
2013-02-27 11:31:32 +00:00
|
|
|
return self.alive(func(self.session.uid, ["name", "company_id"])).then(function(res) {
|
2012-04-27 22:11:50 +00:00
|
|
|
var topbar_name = res.name;
|
2012-08-14 15:29:00 +00:00
|
|
|
if(instance.session.debug)
|
|
|
|
topbar_name = _.str.sprintf("%s (%s)", topbar_name, instance.session.db);
|
2012-04-27 22:11:50 +00:00
|
|
|
if(res.company_id[0] > 1)
|
|
|
|
topbar_name = _.str.sprintf("%s (%s)", topbar_name, res.company_id[1]);
|
2012-08-24 18:27:07 +00:00
|
|
|
self.$el.find('.oe_topbar_name').text(topbar_name);
|
2013-01-03 14:19:45 +00:00
|
|
|
if (!instance.session.debug) {
|
|
|
|
topbar_name = _.str.sprintf("%s (%s)", topbar_name, instance.session.db);
|
2012-11-27 08:36:30 +00:00
|
|
|
}
|
2012-11-14 17:41:50 +00:00
|
|
|
var avatar_src = self.session.url('/web/binary/image', {model:'res.users', field: 'image_small', id: self.session.uid});
|
2012-03-30 07:53:17 +00:00
|
|
|
$avatar.attr('src', avatar_src);
|
2012-02-27 13:45:31 +00:00
|
|
|
});
|
|
|
|
};
|
2012-10-30 14:06:30 +00:00
|
|
|
this.update_promise = this.update_promise.then(fct, fct);
|
2012-02-27 13:45:31 +00:00
|
|
|
},
|
2013-02-06 15:07:24 +00:00
|
|
|
on_menu_help: function() {
|
|
|
|
window.open('http://help.openerp.com', '_blank');
|
|
|
|
},
|
2012-02-23 17:44:39 +00:00
|
|
|
on_menu_logout: function() {
|
2012-10-11 09:45:38 +00:00
|
|
|
this.trigger('user_logout');
|
2012-02-23 17:44:39 +00:00
|
|
|
},
|
|
|
|
on_menu_settings: function() {
|
|
|
|
var self = this;
|
2012-09-06 10:25:26 +00:00
|
|
|
if (!this.getParent().has_uncommitted_changes()) {
|
2012-11-16 09:42:00 +00:00
|
|
|
self.rpc("/web/action/load", { action_id: "base.action_res_users_my" }).done(function(result) {
|
2012-10-05 11:30:46 +00:00
|
|
|
result.res_id = instance.session.uid;
|
|
|
|
self.getParent().action_manager.do_action(result);
|
2012-09-06 10:25:26 +00:00
|
|
|
});
|
|
|
|
}
|
2012-02-27 13:45:31 +00:00
|
|
|
},
|
|
|
|
on_menu_about: function() {
|
|
|
|
var self = this;
|
2012-10-30 14:06:30 +00:00
|
|
|
self.rpc("/web/webclient/version_info", {}).done(function(res) {
|
2012-04-27 22:11:50 +00:00
|
|
|
var $help = $(QWeb.render("UserMenu.about", {version_info: res}));
|
2012-02-27 13:45:31 +00:00
|
|
|
$help.find('a.oe_activate_debug_mode').click(function (e) {
|
|
|
|
e.preventDefault();
|
2012-10-12 14:49:43 +00:00
|
|
|
window.location = $.param.querystring( window.location.href, 'debug');
|
2012-02-27 13:45:31 +00:00
|
|
|
});
|
2012-04-17 11:48:37 +00:00
|
|
|
instance.web.dialog($help, {autoOpen: true,
|
2012-07-26 12:20:06 +00:00
|
|
|
modal: true, width: 507, height: 290, resizable: false, title: _t("About")});
|
2012-02-27 13:45:31 +00:00
|
|
|
});
|
|
|
|
},
|
2012-02-23 17:44:39 +00:00
|
|
|
});
|
|
|
|
|
2012-07-17 16:00:50 +00:00
|
|
|
instance.web.Client = instance.web.Widget.extend({
|
2012-07-19 11:14:14 +00:00
|
|
|
init: function(parent, origin) {
|
2012-07-17 16:00:50 +00:00
|
|
|
instance.client = instance.webclient = this;
|
2012-01-04 09:12:22 +00:00
|
|
|
this._super(parent);
|
2012-07-21 18:09:41 +00:00
|
|
|
this.origin = origin;
|
2012-03-08 16:52:25 +00:00
|
|
|
},
|
2011-03-16 23:56:34 +00:00
|
|
|
start: function() {
|
2011-11-15 17:04:08 +00:00
|
|
|
var self = this;
|
2012-10-30 14:06:30 +00:00
|
|
|
return instance.session.session_bind(this.origin).then(function() {
|
2012-11-19 10:07:34 +00:00
|
|
|
var $e = $(QWeb.render(self._template, {widget: self}));
|
2012-07-25 09:34:37 +00:00
|
|
|
self.replaceElement($e);
|
2012-11-15 16:41:32 +00:00
|
|
|
$e.openerpClass();
|
2012-07-19 11:14:14 +00:00
|
|
|
self.bind_events();
|
2012-07-26 08:12:34 +00:00
|
|
|
return self.show_common();
|
2011-11-15 17:04:08 +00:00
|
|
|
});
|
2012-07-17 16:00:50 +00:00
|
|
|
},
|
|
|
|
bind_events: function() {
|
|
|
|
var self = this;
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.on('mouseenter', '.oe_systray > div:not([data-tipsy=true])', function() {
|
2012-03-01 09:58:07 +00:00
|
|
|
$(this).attr('data-tipsy', 'true').tipsy().trigger('mouseenter');
|
|
|
|
});
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.on('click', '.oe_dropdown_toggle', function(ev) {
|
2012-06-25 15:01:50 +00:00
|
|
|
ev.preventDefault();
|
2012-07-11 14:44:40 +00:00
|
|
|
var $toggle = $(this);
|
2012-07-27 13:26:53 +00:00
|
|
|
var $menu = $toggle.siblings('.oe_dropdown_menu');
|
|
|
|
$menu = $menu.size() >= 1 ? $menu : $toggle.find('.oe_dropdown_menu');
|
2012-06-19 20:55:30 +00:00
|
|
|
var state = $menu.is('.oe_opened');
|
|
|
|
setTimeout(function() {
|
|
|
|
// Do not alter propagation
|
2012-07-11 14:44:40 +00:00
|
|
|
$toggle.add($menu).toggleClass('oe_opened', !state);
|
2012-06-20 15:03:04 +00:00
|
|
|
if (!state) {
|
|
|
|
// Move $menu if outside window's edge
|
|
|
|
var doc_width = $(document).width();
|
|
|
|
var offset = $menu.offset();
|
|
|
|
var menu_width = $menu.width();
|
2012-07-19 15:36:05 +00:00
|
|
|
var x = doc_width - offset.left - menu_width - 2;
|
2012-06-20 15:03:04 +00:00
|
|
|
if (x < 0) {
|
|
|
|
$menu.offset({ left: offset.left + x }).width(menu_width);
|
|
|
|
}
|
|
|
|
}
|
2012-06-19 20:55:30 +00:00
|
|
|
}, 0);
|
|
|
|
});
|
2012-08-01 11:39:24 +00:00
|
|
|
instance.web.bus.on('click', this, function(ev) {
|
2012-08-06 14:00:44 +00:00
|
|
|
$.fn.tipsy.clear();
|
2012-08-01 11:39:24 +00:00
|
|
|
if (!$(ev.target).is('input[type=file]')) {
|
2012-08-24 18:27:07 +00:00
|
|
|
self.$el.find('.oe_dropdown_menu.oe_opened, .oe_dropdown_toggle.oe_opened').removeClass('oe_opened');
|
2012-08-01 11:39:24 +00:00
|
|
|
}
|
2012-06-19 20:55:30 +00:00
|
|
|
});
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
2012-05-22 16:11:33 +00:00
|
|
|
show_common: function() {
|
2012-01-04 18:11:50 +00:00
|
|
|
var self = this;
|
2012-05-22 16:11:33 +00:00
|
|
|
this.crashmanager = new instance.web.CrashManager();
|
2012-10-11 00:37:29 +00:00
|
|
|
instance.session.on('error', this.crashmanager, this.crashmanager.rpc_error);
|
2012-05-22 16:11:33 +00:00
|
|
|
self.notification = new instance.web.Notification(this);
|
2012-08-24 18:27:07 +00:00
|
|
|
self.notification.appendTo(self.$el);
|
2012-05-22 16:11:33 +00:00
|
|
|
self.loading = new instance.web.Loading(self);
|
2012-08-24 18:27:07 +00:00
|
|
|
self.loading.appendTo(self.$el);
|
2012-05-22 16:11:33 +00:00
|
|
|
self.action_manager = new instance.web.ActionManager(self);
|
2012-07-17 16:00:50 +00:00
|
|
|
self.action_manager.appendTo(self.$('.oe_application'));
|
|
|
|
},
|
2012-08-14 10:38:15 +00:00
|
|
|
toggle_bars: function(value) {
|
|
|
|
this.$('tr:has(td.oe_topbar),.oe_leftbar').toggle(value);
|
2012-09-06 10:25:26 +00:00
|
|
|
},
|
|
|
|
has_uncommitted_changes: function() {
|
|
|
|
return false;
|
|
|
|
},
|
2012-07-17 16:00:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
instance.web.WebClient = instance.web.Client.extend({
|
2012-07-19 11:14:14 +00:00
|
|
|
_template: 'WebClient',
|
2012-12-18 11:17:34 +00:00
|
|
|
events: {
|
|
|
|
'click .oe_logo_edit_admin': 'logo_edit'
|
|
|
|
},
|
2012-07-17 16:00:50 +00:00
|
|
|
init: function(parent) {
|
|
|
|
this._super(parent);
|
|
|
|
this._current_state = null;
|
2012-12-13 14:09:14 +00:00
|
|
|
this.menu_dm = new instance.web.DropMisordered();
|
|
|
|
this.action_mutex = new $.Mutex();
|
2012-07-17 16:00:50 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
var self = this;
|
2012-10-30 14:06:30 +00:00
|
|
|
return $.when(this._super()).then(function() {
|
2012-07-17 16:00:50 +00:00
|
|
|
if (jQuery.param !== undefined && jQuery.deparam(jQuery.param.querystring()).kitten !== undefined) {
|
|
|
|
$("body").addClass("kitten-mode-activated");
|
2013-01-31 10:48:04 +00:00
|
|
|
$("body").css("background-image", "url(" + instance.session.origin + "/web/static/src/img/back-enable.jpg" + ")");
|
2012-07-17 16:00:50 +00:00
|
|
|
if ($.blockUI) {
|
|
|
|
$.blockUI.defaults.message = '<img src="http://www.amigrave.com/kitten.gif">';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!self.session.session_is_valid()) {
|
|
|
|
self.show_login();
|
|
|
|
} else {
|
|
|
|
self.show_application();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2012-07-21 18:09:41 +00:00
|
|
|
set_title: function(title) {
|
|
|
|
title = _.str.clean(title);
|
|
|
|
var sep = _.isEmpty(title) ? '' : ' - ';
|
|
|
|
document.title = title + sep + 'OpenERP';
|
|
|
|
},
|
2012-07-17 16:00:50 +00:00
|
|
|
show_common: function() {
|
|
|
|
var self = this;
|
2012-07-18 13:10:04 +00:00
|
|
|
this._super();
|
2012-05-22 16:11:33 +00:00
|
|
|
window.onerror = function (message, file, line) {
|
2012-10-11 00:37:29 +00:00
|
|
|
self.crashmanager.show_error({
|
2012-05-22 16:11:33 +00:00
|
|
|
type: _t("Client Error"),
|
|
|
|
message: message,
|
|
|
|
data: {debug: file + ':' + line}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
},
|
|
|
|
show_login: function() {
|
2012-08-14 10:38:15 +00:00
|
|
|
this.toggle_bars(false);
|
2012-10-11 00:02:17 +00:00
|
|
|
|
|
|
|
var state = $.bbq.getState(true);
|
2012-08-14 09:46:54 +00:00
|
|
|
var action = {
|
2012-10-12 12:54:18 +00:00
|
|
|
type: 'ir.actions.client',
|
|
|
|
tag: 'login',
|
|
|
|
_push_me: false,
|
2012-08-14 09:46:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.action_manager.do_action(action);
|
|
|
|
this.action_manager.inner_widget.on('login_successful', this, function() {
|
|
|
|
this.show_application(); // will load the state we just pushed
|
|
|
|
});
|
2012-01-04 18:11:50 +00:00
|
|
|
},
|
|
|
|
show_application: function() {
|
|
|
|
var self = this;
|
2012-08-14 10:38:15 +00:00
|
|
|
self.toggle_bars(true);
|
2012-12-11 11:18:24 +00:00
|
|
|
self.update_logo();
|
2012-04-17 11:48:37 +00:00
|
|
|
self.menu = new instance.web.Menu(self);
|
2012-08-24 18:27:07 +00:00
|
|
|
self.menu.replace(this.$el.find('.oe_menu_placeholder'));
|
2012-04-29 23:09:26 +00:00
|
|
|
self.menu.on('menu_click', this, this.on_menu_action);
|
2012-04-17 11:48:37 +00:00
|
|
|
self.user_menu = new instance.web.UserMenu(self);
|
2012-08-24 18:27:07 +00:00
|
|
|
self.user_menu.replace(this.$el.find('.oe_user_menu_placeholder'));
|
2012-10-12 14:49:43 +00:00
|
|
|
self.user_menu.on('user_logout', self, self.on_logout);
|
2012-04-29 23:09:26 +00:00
|
|
|
self.user_menu.do_update();
|
2012-05-22 16:11:33 +00:00
|
|
|
self.bind_hashchange();
|
2012-06-25 13:52:15 +00:00
|
|
|
self.set_title();
|
2012-11-22 15:11:25 +00:00
|
|
|
self.check_timezone();
|
|
|
|
},
|
2012-12-11 11:18:24 +00:00
|
|
|
update_logo: function() {
|
|
|
|
var img = this.session.url('/web/binary/company_logo');
|
2012-12-18 11:17:34 +00:00
|
|
|
this.$('.oe_logo img').attr('src', '').attr('src', img);
|
|
|
|
this.$('.oe_logo_edit').toggleClass('oe_logo_edit_admin', this.session.uid === 1);
|
|
|
|
},
|
|
|
|
logo_edit: function(ev) {
|
|
|
|
var self = this;
|
2013-02-27 11:31:32 +00:00
|
|
|
new self.alive(instance.web.Model("res.users").get_func("read")(this.session.uid, ["company_id"])).then(function(res) {
|
2012-12-18 11:17:34 +00:00
|
|
|
self.rpc("/web/action/load", { action_id: "base.action_res_company_form" }).done(function(result) {
|
|
|
|
result.res_id = res['company_id'][0];
|
|
|
|
result.target = "new";
|
|
|
|
result.views = [[false, 'form']];
|
|
|
|
result.flags = {
|
|
|
|
action_buttons: true,
|
|
|
|
};
|
|
|
|
self.action_manager.do_action(result);
|
|
|
|
var form = self.action_manager.dialog_widget.views.form.controller;
|
|
|
|
form.on("on_button_cancel", self.action_manager.dialog, self.action_manager.dialog.close);
|
|
|
|
form.on('record_saved', self, function() {
|
|
|
|
self.action_manager.dialog.close();
|
|
|
|
self.update_logo();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return false;
|
2012-12-11 11:18:24 +00:00
|
|
|
},
|
2012-11-22 15:11:25 +00:00
|
|
|
check_timezone: function() {
|
|
|
|
var self = this;
|
2013-02-27 11:31:32 +00:00
|
|
|
return self.alive(new instance.web.Model('res.users').call('read', [[this.session.uid], ['tz_offset']])).then(function(result) {
|
2012-11-29 21:04:36 +00:00
|
|
|
var user_offset = result[0]['tz_offset'];
|
|
|
|
var offset = -(new Date().getTimezoneOffset());
|
|
|
|
// _.str.sprintf()'s zero front padding is buggy with signed decimals, so doing it manually
|
|
|
|
var browser_offset = (offset < 0) ? "-" : "+";
|
|
|
|
browser_offset += _.str.sprintf("%02d", Math.abs(offset / 60));
|
|
|
|
browser_offset += _.str.sprintf("%02d", Math.abs(offset % 60));
|
|
|
|
if (browser_offset !== user_offset) {
|
2012-11-29 21:37:43 +00:00
|
|
|
var $icon = $(QWeb.render('WebClient.timezone_systray'));
|
|
|
|
$icon.on('click', function() {
|
2012-11-29 21:49:19 +00:00
|
|
|
var notification = self.do_warn(_t("Timezone mismatch"), QWeb.render('WebClient.timezone_notification', {
|
2012-11-29 21:37:43 +00:00
|
|
|
user_timezone: instance.session.user_context.tz || 'UTC',
|
|
|
|
user_offset: user_offset,
|
|
|
|
browser_offset: browser_offset,
|
|
|
|
}), true);
|
|
|
|
notification.element.find('.oe_webclient_timezone_notification').on('click', function() {
|
|
|
|
notification.close();
|
|
|
|
}).find('a').on('click', function() {
|
|
|
|
notification.close();
|
|
|
|
self.user_menu.on_menu_settings();
|
|
|
|
return false;
|
|
|
|
});
|
2012-11-29 21:04:36 +00:00
|
|
|
});
|
2012-11-29 21:37:43 +00:00
|
|
|
$icon.appendTo(self.$('.oe_systray'));
|
2012-11-29 21:04:36 +00:00
|
|
|
}
|
|
|
|
});
|
2012-01-04 18:11:50 +00:00
|
|
|
},
|
|
|
|
destroy_content: function() {
|
2012-02-21 15:51:34 +00:00
|
|
|
_.each(_.clone(this.getChildren()), function(el) {
|
2012-02-21 16:29:12 +00:00
|
|
|
el.destroy();
|
2012-01-04 18:11:50 +00:00
|
|
|
});
|
2012-08-24 18:27:07 +00:00
|
|
|
this.$el.children().remove();
|
2012-01-04 18:11:50 +00:00
|
|
|
},
|
2011-10-13 23:20:54 +00:00
|
|
|
do_reload: function() {
|
2012-01-13 15:08:29 +00:00
|
|
|
var self = this;
|
2012-10-30 14:06:30 +00:00
|
|
|
return this.session.session_reload().then(function () {
|
|
|
|
instance.session.load_modules(true).then(
|
2012-01-13 15:08:29 +00:00
|
|
|
self.menu.proxy('do_reload')); });
|
|
|
|
|
2011-10-13 23:20:54 +00:00
|
|
|
},
|
2011-10-13 15:30:23 +00:00
|
|
|
do_notify: function() {
|
|
|
|
var n = this.notification;
|
2012-11-22 15:11:25 +00:00
|
|
|
return n.notify.apply(n, arguments);
|
2011-10-13 15:30:23 +00:00
|
|
|
},
|
|
|
|
do_warn: function() {
|
|
|
|
var n = this.notification;
|
2012-11-22 15:11:25 +00:00
|
|
|
return n.warn.apply(n, arguments);
|
2011-10-13 15:30:23 +00:00
|
|
|
},
|
2011-12-16 01:25:42 +00:00
|
|
|
on_logout: function() {
|
2012-09-06 10:50:35 +00:00
|
|
|
var self = this;
|
2012-09-06 10:25:26 +00:00
|
|
|
if (!this.has_uncommitted_changes()) {
|
2012-10-30 14:06:30 +00:00
|
|
|
this.session.session_logout().done(function () {
|
2012-09-05 15:20:30 +00:00
|
|
|
$(window).unbind('hashchange', self.on_hashchange);
|
|
|
|
self.do_push_state({});
|
|
|
|
window.location.reload();
|
|
|
|
});
|
|
|
|
}
|
2011-08-10 00:38:57 +00:00
|
|
|
},
|
2011-12-12 16:44:55 +00:00
|
|
|
bind_hashchange: function() {
|
2012-04-19 21:53:44 +00:00
|
|
|
var self = this;
|
2011-12-12 16:44:55 +00:00
|
|
|
$(window).bind('hashchange', this.on_hashchange);
|
2011-12-09 16:31:14 +00:00
|
|
|
|
2011-12-12 14:20:12 +00:00
|
|
|
var state = $.bbq.getState(true);
|
2012-08-08 18:08:16 +00:00
|
|
|
if (_.isEmpty(state) || state.action == "login") {
|
2012-10-30 14:06:30 +00:00
|
|
|
self.menu.has_been_loaded.done(function() {
|
2012-08-24 18:27:07 +00:00
|
|
|
var first_menu_id = self.menu.$el.find("a:first").data("menu");
|
2012-04-29 23:09:26 +00:00
|
|
|
if(first_menu_id) {
|
|
|
|
self.menu.menu_click(first_menu_id);
|
|
|
|
}
|
2012-04-19 21:53:44 +00:00
|
|
|
});
|
2012-08-08 18:08:16 +00:00
|
|
|
} else {
|
|
|
|
$(window).trigger('hashchange');
|
2011-12-09 16:31:14 +00:00
|
|
|
}
|
2011-07-19 12:32:46 +00:00
|
|
|
},
|
2011-12-12 16:44:55 +00:00
|
|
|
on_hashchange: function(event) {
|
2012-05-15 15:17:56 +00:00
|
|
|
var self = this;
|
2013-02-20 08:44:37 +00:00
|
|
|
var stringstate = event.getState(false);
|
|
|
|
if (!_.isEqual(this._current_state, stringstate)) {
|
|
|
|
var state = event.getState(true);
|
2012-11-15 17:12:01 +00:00
|
|
|
if(!state.action && state.menu_id) {
|
2012-10-30 14:06:30 +00:00
|
|
|
self.menu.has_been_loaded.done(function() {
|
|
|
|
self.menu.do_reload().done(function() {
|
2012-11-15 17:12:01 +00:00
|
|
|
self.menu.menu_click(state.menu_id);
|
2012-05-15 15:34:23 +00:00
|
|
|
});
|
2012-05-15 15:17:56 +00:00
|
|
|
});
|
|
|
|
} else {
|
2012-10-12 12:54:18 +00:00
|
|
|
state._push_me = false; // no need to push state back...
|
2012-05-15 15:17:56 +00:00
|
|
|
this.action_manager.do_load_state(state, !!this._current_state);
|
|
|
|
}
|
2011-09-14 13:03:08 +00:00
|
|
|
}
|
2013-02-20 08:44:37 +00:00
|
|
|
this._current_state = stringstate;
|
2011-09-14 13:03:08 +00:00
|
|
|
},
|
2011-12-14 16:09:58 +00:00
|
|
|
do_push_state: function(state) {
|
2012-06-12 14:19:43 +00:00
|
|
|
this.set_title(state.title);
|
2012-07-26 00:42:27 +00:00
|
|
|
delete state.title;
|
2011-12-09 16:31:14 +00:00
|
|
|
var url = '#' + $.param(state);
|
2013-02-20 08:44:37 +00:00
|
|
|
this._current_state = $.deparam($.param(state), false); // stringify all values
|
2011-12-12 16:44:55 +00:00
|
|
|
$.bbq.pushState(url);
|
2012-10-26 14:05:15 +00:00
|
|
|
this.trigger('state_pushed', state);
|
2011-09-14 13:03:08 +00:00
|
|
|
},
|
2012-06-08 11:23:58 +00:00
|
|
|
on_menu_action: function(options) {
|
|
|
|
var self = this;
|
2012-12-13 14:09:14 +00:00
|
|
|
return this.menu_dm.add(this.rpc("/web/action/load", { action_id: options.action_id }))
|
2012-10-30 14:06:30 +00:00
|
|
|
.then(function (result) {
|
2012-12-13 14:09:14 +00:00
|
|
|
return self.action_mutex.exec(function() {
|
|
|
|
if (options.needaction) {
|
2013-02-13 14:39:53 +00:00
|
|
|
result.context = new instance.web.CompoundContext(result.context, {
|
|
|
|
search_default_message_unread: true,
|
|
|
|
search_disable_custom_filters: true,
|
|
|
|
});
|
2012-12-13 14:09:14 +00:00
|
|
|
}
|
2012-12-17 15:00:05 +00:00
|
|
|
var completed = $.Deferred();
|
|
|
|
$.when(self.action_manager.do_action(result, {
|
2012-12-13 14:09:14 +00:00
|
|
|
clear_breadcrumbs: true,
|
|
|
|
action_menu_id: self.menu.current_menu,
|
|
|
|
})).fail(function() {
|
|
|
|
self.menu.open_menu(options.previous_menu_id);
|
2012-12-17 15:00:05 +00:00
|
|
|
}).always(function() {
|
|
|
|
completed.resolve();
|
2012-12-13 14:09:14 +00:00
|
|
|
});
|
2012-12-17 15:00:05 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
completed.resolve();
|
|
|
|
}, 2000);
|
|
|
|
// We block the menu when clicking on an element until the action has correctly finished
|
|
|
|
// loading. If something crash, there is a 2 seconds timeout before it's unblocked.
|
|
|
|
return completed;
|
2012-09-05 13:45:53 +00:00
|
|
|
});
|
2012-06-08 11:23:58 +00:00
|
|
|
});
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
2012-03-07 15:05:00 +00:00
|
|
|
set_content_full_screen: function(fullscreen) {
|
2013-01-25 10:05:47 +00:00
|
|
|
$(document.body).css('overflow-y', fullscreen ? 'hidden' : 'scroll');
|
|
|
|
this.$('.oe_webclient').toggleClass(
|
|
|
|
'oe_content_full_screen', fullscreen);
|
2012-09-06 10:25:26 +00:00
|
|
|
},
|
|
|
|
has_uncommitted_changes: function() {
|
|
|
|
var $e = $.Event('clear_uncommitted_changes');
|
2012-09-06 13:26:02 +00:00
|
|
|
instance.web.bus.trigger('clear_uncommitted_changes', $e);
|
2012-09-06 10:25:26 +00:00
|
|
|
if ($e.isDefaultPrevented()) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return this._super.apply(this, arguments);
|
|
|
|
}
|
|
|
|
},
|
2011-03-16 23:56:34 +00:00
|
|
|
});
|
|
|
|
|
2012-07-17 16:00:50 +00:00
|
|
|
instance.web.EmbeddedClient = instance.web.Client.extend({
|
2012-07-19 11:14:14 +00:00
|
|
|
_template: 'EmbedClient',
|
|
|
|
init: function(parent, origin, dbname, login, key, action_id, options) {
|
|
|
|
this._super(parent, origin);
|
2012-12-19 02:49:46 +00:00
|
|
|
this.bind_credentials(dbname, login, key);
|
2011-12-14 12:56:58 +00:00
|
|
|
this.action_id = action_id;
|
|
|
|
this.options = options || {};
|
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
var self = this;
|
2012-10-30 14:06:30 +00:00
|
|
|
return $.when(this._super()).then(function() {
|
2012-11-08 16:34:58 +00:00
|
|
|
return self.authenticate().then(function() {
|
2012-09-27 13:34:44 +00:00
|
|
|
if (!self.action_id) {
|
|
|
|
return;
|
|
|
|
}
|
2012-10-30 14:06:30 +00:00
|
|
|
return self.rpc("/web/action/load", { action_id: self.action_id }).done(function(result) {
|
2012-10-05 11:30:46 +00:00
|
|
|
var action = result;
|
2012-07-19 11:14:14 +00:00
|
|
|
action.flags = _.extend({
|
|
|
|
//views_switcher : false,
|
|
|
|
search_view : false,
|
|
|
|
action_buttons : false,
|
|
|
|
sidebar : false
|
|
|
|
//pager : false
|
|
|
|
}, self.options, action.flags || {});
|
2011-12-14 12:56:58 +00:00
|
|
|
|
2012-09-27 13:34:44 +00:00
|
|
|
self.do_action(action);
|
2012-07-19 11:14:14 +00:00
|
|
|
});
|
2012-07-17 16:00:50 +00:00
|
|
|
});
|
2011-12-14 12:56:58 +00:00
|
|
|
});
|
2012-07-17 16:00:50 +00:00
|
|
|
},
|
2012-09-27 13:34:44 +00:00
|
|
|
|
|
|
|
do_action: function(action) {
|
|
|
|
return this.action_manager.do_action(action);
|
2012-10-15 16:23:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
authenticate: function() {
|
|
|
|
var s = instance.session;
|
|
|
|
if (s.session_is_valid() && s.db === this.dbname && s.login === this.login) {
|
|
|
|
return $.when();
|
|
|
|
}
|
|
|
|
return instance.session.session_authenticate(this.dbname, this.login, this.key, true);
|
|
|
|
},
|
|
|
|
|
2012-12-19 02:49:46 +00:00
|
|
|
bind_credentials: function(dbname, login, key) {
|
2012-10-15 16:23:46 +00:00
|
|
|
this.dbname = dbname;
|
|
|
|
this.login = login;
|
|
|
|
this.key = key;
|
|
|
|
},
|
|
|
|
|
2011-12-14 12:56:58 +00:00
|
|
|
});
|
|
|
|
|
2012-04-17 11:48:37 +00:00
|
|
|
instance.web.embed = function (origin, dbname, login, key, action, options) {
|
2011-12-16 16:51:46 +00:00
|
|
|
$('head').append($('<link>', {
|
|
|
|
'rel': 'stylesheet',
|
|
|
|
'type': 'text/css',
|
|
|
|
'href': origin +'/web/webclient/css'
|
|
|
|
}));
|
2011-12-16 15:37:36 +00:00
|
|
|
var currentScript = document.currentScript;
|
|
|
|
if (!currentScript) {
|
|
|
|
var sc = document.getElementsByTagName('script');
|
|
|
|
currentScript = sc[sc.length-1];
|
|
|
|
}
|
2012-07-19 11:14:14 +00:00
|
|
|
var client = new instance.web.EmbeddedClient(null, origin, dbname, login, key, action, options);
|
2012-07-17 16:00:50 +00:00
|
|
|
client.insertAfter(currentScript);
|
2012-05-15 07:41:39 +00:00
|
|
|
};
|
2011-12-14 12:56:58 +00:00
|
|
|
|
2011-03-16 23:56:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|