var QWeb = openerp.web.qweb,
_t = openerp.web._t;
-openerp.web.Notification = openerp.web.Widget.extend(/** @lends openerp.web.Notification# */{
+openerp.web.Notification = openerp.web.OldWidget.extend(/** @lends openerp.web.Notification# */{
template: 'Notification',
- identifier_prefix: 'notification-',
init: function() {
this._super.apply(this, arguments);
this._super.apply(this, arguments);
this.$element.notify({
speed: 500,
- expires: 1500
+ expires: 2500
});
},
- notify: function(title, text) {
+ notify: function(title, text, sticky) {
+ sticky = !!sticky;
+ var opts = {};
+ if (sticky) {
+ opts.expires = false;
+ }
this.$element.notify('create', {
title: title,
text: text
- });
+ }, opts);
},
- warn: function(title, text) {
+ warn: function(title, text, sticky) {
+ sticky = !!sticky;
+ var opts = {};
+ if (sticky) {
+ opts.expires = false;
+ }
this.$element.notify('create', 'oe_notification_alert', {
title: title,
text: text
- });
+ }, opts);
}
});
+openerp.web.dialog = function(element) {
+ var result = element.dialog.apply(element, _.rest(_.toArray(arguments)));
+ result.dialog("widget").addClass("openerp");
+ return result;
+}
+
openerp.web.Dialog = openerp.web.OldWidget.extend(/** @lends openerp.web.Dialog# */{
dialog_title: "",
- identifier_prefix: 'dialog',
/**
* @constructs openerp.web.Dialog
* @extends openerp.web.OldWidget
*
* @param parent
- * @param dialog_options
+ * @param options
*/
- init: function (parent, dialog_options) {
+ init: function (parent, options, content) {
var self = this;
this._super(parent);
+ if (content) {
+ this.$element = content instanceof $ ? content : $(content);
+ }
this.dialog_options = {
modal: true,
destroy_on_close: true,
max_width: '95%',
height: 'auto',
min_height: 0,
- max_height: '95%',
+ max_height: this.get_height('100%') - 140,
autoOpen: false,
position: [false, 50],
- autoResize : 'auto',
buttons: {},
beforeClose: function () { self.on_close(); },
resizeStop: this.on_resized
this.dialog_options.buttons[f.substr(10)] = this[f];
}
}
- if (dialog_options) {
- this.set_options(dialog_options);
- }
- },
- set_options: function(options) {
- options = options || {};
- options.width = this.get_width(options.width || this.dialog_options.width);
- options.min_width = this.get_width(options.min_width || this.dialog_options.min_width);
- options.max_width = this.get_width(options.max_width || this.dialog_options.max_width);
- options.height = this.get_height(options.height || this.dialog_options.height);
- options.min_height = this.get_height(options.min_height || this.dialog_options.min_height);
- options.max_height = this.get_height(options.max_height || this.dialog_options.max_height);
-
- if (options.width !== 'auto') {
- if (options.width > options.max_width) options.width = options.max_width;
- if (options.width < options.min_width) options.width = options.min_width;
+ if (options) {
+ _.extend(this.dialog_options, options);
}
- if (options.height !== 'auto') {
- if (options.height > options.max_height) options.height = options.max_height;
- if (options.height < options.min_height) options.height = options.min_height;
+ if (this.dialog_options.autoOpen) {
+ this.open();
+ } else {
+ openerp.web.dialog(this.$element, this.get_options());
}
- if (!options.title && this.dialog_title) {
- options.title = this.dialog_title;
+ },
+ get_options: function(options) {
+ var self = this,
+ o = _.extend({}, this.dialog_options, options || {});
+ _.each(['width', 'height'], function(unit) {
+ o[unit] = self['get_' + unit](o[unit]);
+ o['min_' + unit] = self['get_' + unit](o['min_' + unit] || 0);
+ o['max_' + unit] = self['get_' + unit](o['max_' + unit] || 0);
+ 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];
+ });
+ if (!o.title && this.dialog_title) {
+ o.title = this.dialog_title;
}
- _.extend(this.dialog_options, options);
+ return o;
},
get_width: function(val) {
return this.get_size(val.toString(), $(window.top).width());
return parseInt(val, 10);
}
},
- start: function () {
- this.$element.dialog(this.dialog_options);
- this._super();
- return this;
- },
- open: function(dialog_options) {
+ open: function(options) {
// TODO fme: bind window on resize
if (this.template) {
this.$element.html(this.render());
}
- this.set_options(dialog_options);
- this.$element.dialog(this.dialog_options).dialog('open');
+ var o = this.get_options(options);
+ openerp.web.dialog(this.$element, o).dialog('open');
+ if (o.height === 'auto' && o.max_height) {
+ this.$element.css({ 'max-height': o.max_height, 'overflow-y': 'auto' });
+ }
return this;
},
close: function() {
}
},
on_resized: function() {
- if (openerp.connection.debug) {
- console.log("Dialog resized to %d x %d", this.$element.width(), this.$element.height());
- }
+ //openerp.log("Dialog resized to %d x %d", this.$element.width(), this.$element.height());
},
- stop: function () {
+ destroy: function () {
// Destroy widget
this.close();
this.$element.dialog('destroy');
});
openerp.web.CrashManager = openerp.web.CallbackEnabled.extend({
- init: function() {
- this._super();
- openerp.connection.on_rpc_error.add(this.on_rpc_error);
- },
on_rpc_error: function(error) {
- this.error = error;
if (error.data.fault_code) {
var split = ("" + error.data.fault_code).split('\n')[0].split(' -- ');
if (split.length > 1) {
}
},
on_managed_error: function(error) {
- $('<div>' + QWeb.render('CrashManagerWarning', {error: error}) + '</div>').dialog({
+ openerp.web.dialog($('<div>' + QWeb.render('CrashManagerWarning', {error: error}) + '</div>'), {
title: "OpenERP " + _.str.capitalize(error.type),
buttons: [
{text: _t("Ok"), click: function() { $(this).dialog("close"); }}
var buttons = {};
if (openerp.connection.openerp_entreprise) {
buttons[_t("Send OpenERP Enterprise Report")] = function() {
- $this = $(this);
+ var $this = $(this);
var issuename = $('#issuename').val();
var explanation = $('#explanation').val();
var remark = $('#remark').val();
};
}
var dialog = new openerp.web.Dialog(this, {
- title: "OpenERP " + _.str.capitalize(this.error.type),
- autoOpen: true,
+ title: "OpenERP " + _.str.capitalize(error.type),
width: '80%',
height: '50%',
min_width: '800px',
min_height: '600px',
buttons: buttons
- }).start();
+ }).open();
dialog.$element.html(QWeb.render('CrashManagerError', {session: openerp.connection, error: error}));
- },
+ }
});
-openerp.web.Loading = openerp.web.Widget.extend(/** @lends openerp.web.Loading# */{
+openerp.web.Loading = openerp.web.OldWidget.extend(/** @lends openerp.web.Loading# */{
template: 'Loading',
/**
* @constructs openerp.web.Loading
- * @extends openerp.web.Widget
+ * @extends openerp.web.OldWidget
*
* @param parent
* @param element_id
this.session.on_rpc_request.add_first(this.request_call);
this.session.on_rpc_response.add_last(this.response_call);
},
- stop: function() {
+ destroy: function() {
this.session.on_rpc_request.remove(this.request_call);
this.session.on_rpc_response.remove(this.response_call);
this.on_rpc_event(-this.count);
this.count += increment;
if (this.count > 0) {
- //this.$element.html(QWeb.render("Loading", {}));
- $(".loading",this.$element).html("Loading ("+this.count+")");
+ $(".loading",this.$element).text(_.str.sprintf(
+ _t("Loading (%d)"), this.count));
$(".loading",this.$element).show();
- this.widget_parent.$element.addClass('loading');
+ this.getParent().$element.addClass('loading');
} else {
this.count = 0;
clearTimeout(this.long_running_timer);
$.unblockUI();
}
$(".loading",this.$element).fadeOut();
- this.widget_parent.$element.removeClass('loading');
+ this.getParent().$element.removeClass('loading');
}
}
});
-openerp.web.Database = openerp.web.Widget.extend(/** @lends openerp.web.Database# */{
+openerp.web.Database = openerp.web.OldWidget.extend(/** @lends openerp.web.Database# */{
template: "DatabaseManager",
/**
* @constructs openerp.web.Database
- * @extends openerp.web.Widget
+ * @extends openerp.web.OldWidget
*
* @param parent
* @param element_id
init: function(parent, element_id, option_id) {
this._super(parent, element_id);
this.unblockUIFunction = $.unblockUI;
+ $.validator.addMethod('matches', function (s, _, re) {
+ return new RegExp(re).test(s);
+ }, _t("Invalid database name"));
},
start: function() {
this.$option_id = $("#oe_db_options");
var self = this;
- var fetch_db = this.rpc("/web/database/get_list", {}, function(result) {
- self.db_list = result.db_list;
- });
+ var fetch_db = this.rpc("/web/database/get_list", {}).pipe(
+ function(result) { self.db_list = result.db_list; },
+ function (_, ev) { ev.preventDefault(); self.db_list = null; });
var fetch_langs = this.rpc("/web/session/get_lang_list", {}, function(result) {
if (result.error) {
self.display_error(result);
self.hide();
});
},
- stop: function () {
+ destroy: function () {
this.hide();
this.$option_id.empty();
var admin = result[1][0];
setTimeout(function () {
- self.widget_parent.do_login(
+ self.getParent().do_login(
info.db, admin.login, admin.password);
- self.stop();
+ self.destroy();
self.unblockUI();
});
});
* @param {String} error.error message of the error dialog
*/
display_error: function (error) {
- return $('<div>').dialog({
+ return openerp.web.dialog($('<div>'), {
modal: true,
title: error.title,
buttons: [
self.display_error(result);
return;
}
- self.db_list.push(self.to_object(fields)['db_name']);
- self.db_list.sort();
- self.widget_parent.set_db_list(self.db_list);
+ if (self.db_list) {
+ self.db_list.push(self.to_object(fields)['db_name']);
+ self.db_list.sort();
+ self.getParent().set_db_list(self.db_list);
+ }
var form_obj = self.to_object(fields);
self.wait_for_newdb(result, {
password: form_obj['super_admin_pwd'],
return;
}
$db_list.find(':selected').remove();
- self.db_list.splice(_.indexOf(self.db_list, db, true), 1);
- self.widget_parent.set_db_list(self.db_list);
+ if (self.db_list) {
+ self.db_list.splice(_.indexOf(self.db_list, db, true), 1);
+ self.getParent().set_db_list(self.db_list);
+ }
self.do_notify("Dropping database", "The database '" + db + "' has been dropped");
});
}
self.blockUI();
self.session.get_file({
form: form,
- error: function (body) {
- var error = body.firstChild.data.split('|');
- self.display_error({
- title: error[0],
- error: error[1]
- });
+ success: function () {
+ self.do_notify(_t("Backed"),
+ _t("Database backed up successfully"));
},
- complete: $.proxy(self, 'unblockUI')
+ error: openerp.webclient.crashmanager.on_rpc_error,
+ complete: function() {
+ self.unblockUI();
+ }
});
}
});
})
}
},
- complete: $.proxy(self, 'unblockUI')
+ complete: function() {
+ self.unblockUI();
+ self.do_notify(_t("Restored"), _t("Database restored successfully"));
+ }
});
}
});
}
});
-openerp.web.Login = openerp.web.Widget.extend(/** @lends openerp.web.Login# */{
+openerp.web.Login = openerp.web.OldWidget.extend(/** @lends openerp.web.Login# */{
remember_credentials: true,
template: "Login",
- identifier_prefix: 'oe-app-login-',
/**
* @constructs openerp.web.Login
- * @extends openerp.web.Widget
+ * @extends openerp.web.OldWidget
*
* @param parent
* @param element_id
}
var $e = this.$element;
var db = $e.find("form [name=db]").val();
+ if (!db) {
+ this.do_warn("Login", "No database selected !");
+ return false;
+ }
var login = $e.find("form input[name=login]").val();
var password = $e.find("form input[name=password]").val();
*/
do_login: function (db, login, password) {
var self = this;
+ this.$element.removeClass('login_invalid');
this.session.on_session_invalid.add({
callback: function () {
self.$element.addClass("login_invalid");
}
}
});
- },
-});
-
-openerp.web.Header = openerp.web.Widget.extend(/** @lends openerp.web.Header# */{
- template: "Header",
- identifier_prefix: 'oe-app-header-',
- /**
- * @constructs openerp.web.Header
- * @extends openerp.web.Widget
- *
- * @param parent
- */
- init: function(parent) {
- this._super(parent);
- this.qs = "?" + jQuery.param.querystring();
- this.$content = $();
- this.update_promise = $.Deferred().resolve();
- },
- start: function() {
- this._super();
- },
- do_update: function () {
- var self = this;
- var fct = function() {
- self.$content.remove();
- if (!self.session.uid)
- return;
- var func = new openerp.web.Model("res.users").get_func("read");
- return func(self.session.uid, ["name", "company_id"]).pipe(function(res) {
- self.$content = $(QWeb.render("Header-content", {widget: self, user: res}));
- self.$content.appendTo(self.$element);
- self.$element.find(".logout").click(self.on_logout);
- self.$element.find("a.preferences").click(self.on_preferences);
- self.$element.find(".about").click(self.on_about);
- return self.shortcut_load();
- });
- };
- this.update_promise = this.update_promise.pipe(fct, fct);
- },
- on_about: function() {
- var self = this;
- self.rpc("/web/webclient/version_info", {}).then(function(res) {
- var $help = $(QWeb.render("About-Page", {version_info: res}));
- $help.dialog({autoOpen: true,
- modal: true, width: 960, title: _t("About")});
- });
- },
- shortcut_load :function(){
- var self = this,
- sc = self.session.shortcuts,
- shortcuts_ds = new openerp.web.DataSet(this, 'ir.ui.view_sc');
- // TODO: better way to communicate between sections.
- // sc.bindings, because jquery does not bind/trigger on arrays...
- if (!sc.binding) {
- sc.binding = {};
- $(sc.binding).bind({
- 'add': function (e, attrs) {
- shortcuts_ds.create(attrs, function (out) {
- $('<li>', {
- 'data-shortcut-id':out.result,
- 'data-id': attrs.res_id
- }).text(attrs.name)
- .appendTo(self.$element.find('.oe-shortcuts ul'));
- attrs.id = out.result;
- sc.push(attrs);
- });
- },
- 'remove-current': function () {
- var menu_id = self.session.active_id;
- var $shortcut = self.$element
- .find('.oe-shortcuts li[data-id=' + menu_id + ']');
- var shortcut_id = $shortcut.data('shortcut-id');
- $shortcut.remove();
- shortcuts_ds.unlink([shortcut_id]);
- var sc_new = _.reject(sc, function(shortcut){ return shortcut_id === shortcut.id});
- sc.splice(0, sc.length);
- sc.push.apply(sc, sc_new);
- }
- });
- }
- return this.rpc('/web/session/sc_list', {}, function(shortcuts) {
- sc.splice(0, sc.length);
- sc.push.apply(sc, shortcuts);
-
- self.$element.find('.oe-shortcuts')
- .html(QWeb.render('Shortcuts', {'shortcuts': shortcuts}))
- .undelegate('li', 'click')
-
- .delegate('li', 'click', function(e) {
- e.stopPropagation();
- var id = $(this).data('id');
- self.session.active_id = id;
- self.rpc('/web/menu/action', {'menu_id':id}, function(ir_menu_data) {
- if (ir_menu_data.action.length){
- self.on_action(ir_menu_data.action[0][2]);
- }
- });
- });
- });
- },
-
- on_action: function(action) {
- },
- on_preferences: function(){
- var self = this;
- var action_manager = new openerp.web.ActionManager(this);
- var dataset = new openerp.web.DataSet (this,'res.users',this.context);
- dataset.call ('action_get','',function (result){
- self.rpc('/web/action/load', {action_id:result}, function(result){
- action_manager.do_action(_.extend(result['result'], {
- res_id: self.session.uid,
- res_model: 'res.users',
- flags: {
- action_buttons: false,
- search_view: false,
- sidebar: false,
- views_switcher: false,
- pager: false
- }
- }));
- });
- });
- this.dialog = new openerp.web.Dialog(this,{
- title: _t("Preferences"),
- width: '700px',
- buttons: [
- {text: _t("Change password"), click: function(){ self.change_password(); }},
- {text: _t("Cancel"), click: function(){ $(this).dialog('destroy'); }},
- {text: _t("Save"), click: function(){
- var inner_viewmanager = action_manager.inner_viewmanager;
- inner_viewmanager.views[inner_viewmanager.active_view].controller.do_save()
- .then(function() {
- self.dialog.stop();
- window.location.reload();
- });
- }
- }
- ]
- });
- this.dialog.start().open();
- action_manager.appendTo(this.dialog);
- action_manager.render(this.dialog);
- },
-
- change_password :function() {
- var self = this;
- this.dialog = new openerp.web.Dialog(this, {
- title: _t("Change Password"),
- width : 'auto'
- });
- this.dialog.start().open();
- this.dialog.$element.html(QWeb.render("Change_Pwd", self));
- this.dialog.$element.find("form[name=change_password_form]").validate({
- submitHandler: function (form) {
- self.rpc("/web/session/change_password",{
- 'fields': $(form).serializeArray()
- }, function(result) {
- if (result.error) {
- self.display_error(result);
- return;
- } else {
- self.session.logout();
- }
- });
- }
- });
- },
- display_error: function (error) {
- return $('<div>').dialog({
- modal: true,
- title: error.title,
- buttons: [
- {text: _("Ok"), click: function() { $(this).dialog("close"); }}
- ]
- }).html(error.error);
- },
- on_logout: function() {
}
});
* @extends openerp.web.Widget
*
* @param parent
- * @param element_id
- * @param secondary_menu_id
*/
- init: function(parent, element_id, secondary_menu_id) {
- this._super(parent, element_id);
- this.secondary_menu_id = secondary_menu_id;
- this.$secondary_menu = $("#" + secondary_menu_id);
- this.menu = false;
- this.folded = false;
- if (window.localStorage) {
- this.folded = localStorage.getItem('oe_menu_folded') === 'true';
- }
- this.float_timeout = 700;
- },
- start: function() {
- this.$secondary_menu.addClass(this.folded ? 'oe_folded' : 'oe_unfolded');
- },
+ template: 'Menu',
do_reload: function() {
var self = this;
return this.rpc("/web/menu/load", {}, this.on_loaded).then(function () {
},
on_loaded: function(data) {
this.data = data;
- this.$element.html(QWeb.render("Menu", { widget : this }));
+ this.render_element();
+ if (!this.$secondary_menu && this.getParent()) {
+ // TODO: create Widget openerp.web.SubMenu
+ this.$secondary_menu = this.getParent().$element.find('.oe_secondary_menu');
+ }
this.$secondary_menu.html(QWeb.render("Menu.secondary", { widget : this }));
this.$element.add(this.$secondary_menu).find("a").click(this.on_menu_click);
- this.$secondary_menu.find('.oe_toggle_secondary_menu').click(this.on_toggle_fold);
- },
- on_toggle_fold: function() {
- this.$secondary_menu.toggleClass('oe_folded').toggleClass('oe_unfolded');
- if (this.folded) {
- this.$secondary_menu.find('.oe_secondary_menu.active').show();
- } else {
- this.$secondary_menu.find('.oe_secondary_menu').hide();
- }
- this.folded = !this.folded;
- if (window.localStorage) {
- localStorage.setItem('oe_menu_folded', this.folded.toString());
- }
},
/**
* Opens a given menu by id, as if a user had browsed to that menu by hand
* @param {Number} menu_id database id of the terminal menu to select
*/
open_menu: function (menu_id) {
- this.$element.add(this.$secondary_menu).find('.active')
- .removeClass('active');
+ this.$element.add(this.$secondary_menu).find('.oe_active')
+ .removeClass('oe_active');
this.$secondary_menu.find('> .oe_secondary_menu').hide();
var $primary_menu;
if ($secondary_submenu.length) {
for(;;) {
if ($secondary_submenu.hasClass('leaf')) {
- $secondary_submenu.addClass('active');
+ $secondary_submenu.addClass('oe_active');
} else if ($secondary_submenu.hasClass('submenu')) {
$secondary_submenu.addClass('opened')
}
if (!$primary_menu.length) {
return;
}
- $primary_menu.addClass('active');
+ $primary_menu.addClass('oe_active');
this.$secondary_menu.find(
- 'div[data-menu-parent=' + $primary_menu.data('menu') + ']').show();
+ 'div[data-menu-parent=' + $primary_menu.data('menu') + ']').addClass('oe_active');
},
on_menu_click: function(ev, id) {
id = id || 0;
},
do_menu_click: function($clicked_menu, manual) {
var $sub_menu, $main_menu,
- active = $clicked_menu.is('.active'),
- sub_menu_visible = false;
+ active = $clicked_menu.is('.oe_active'),
+ sub_menu_visible = false,
+ has_submenu_items = false;
if (this.$secondary_menu.has($clicked_menu).length) {
$sub_menu = $clicked_menu.parents('.oe_secondary_menu');
}
sub_menu_visible = $sub_menu.is(':visible');
+ has_submenu_items = !!$sub_menu.children().length;
this.$secondary_menu.find('.oe_secondary_menu').hide();
- $('.active', this.$element.add(this.$secondary_menu)).removeClass('active');
- $main_menu.add($clicked_menu).add($sub_menu).addClass('active');
+ $('.oe_active', this.$element.add(this.$secondary_menu)).removeClass('oe_active');
+ $main_menu.add($clicked_menu).add($sub_menu).addClass('oe_active');
- if (!(this.folded && manual)) {
- this.do_show_secondary($sub_menu, $main_menu);
- } else {
- this.do_show_secondary();
+ if (has_submenu_items) {
+ if (!manual) {
+ this.do_show_secondary($sub_menu, $main_menu);
+ } else {
+ this.do_show_secondary();
+ }
}
if ($main_menu != $clicked_menu) {
if ($clicked_menu.is('.submenu')) {
- $sub_menu.find('.submenu.opened').each(function() {
- if (!$(this).next().has($clicked_menu).length && !$(this).is($clicked_menu)) {
- $(this).removeClass('opened').next().hide();
- }
- });
$clicked_menu.toggleClass('opened').next().toggle();
} else if ($clicked_menu.is('.leaf')) {
- $sub_menu.toggle(!this.folded);
- return true;
- }
- } else if (this.folded) {
- if (active && sub_menu_visible) {
- $sub_menu.hide();
return true;
}
- return manual;
} else {
return true;
}
return false;
},
do_hide_secondary: function() {
- this.$secondary_menu.hide();
+ //this.$secondary_menu.hide();
},
do_show_secondary: function($sub_menu, $main_menu) {
var self = this;
if (!arguments.length) {
return;
}
- if (this.folded) {
- var css = $main_menu.position(),
- fold_width = this.$secondary_menu.width() + 2,
- window_width = $(window).width();
- css.top += 33;
- css.left -= Math.round(($sub_menu.width() - $main_menu.width()) / 2);
- css.left = css.left < fold_width ? fold_width : css.left;
- if ((css.left + $sub_menu.width()) > window_width) {
- delete(css.left);
- css.right = 1;
- }
- $sub_menu.css(css);
- $sub_menu.mouseenter(function() {
- clearTimeout($sub_menu.data('timeoutId'));
- $sub_menu.data('timeoutId', null);
- return false;
- }).mouseleave(function(evt) {
- var timeoutId = setTimeout(function() {
- if (self.folded && $sub_menu.data('timeoutId')) {
- $sub_menu.hide().unbind('mouseenter').unbind('mouseleave');
- }
- }, self.float_timeout);
- $sub_menu.data('timeoutId', timeoutId);
- return false;
- });
- }
$sub_menu.show();
},
on_menu_action_loaded: function(data) {
}
});
+openerp.web.DropDownMenu = openerp.web.Widget.extend(/** @lends openerp.web.DropDownMenu# */{
+ template: "DropDownMenu",
+ /**
+ * @constructs openerp.web.DropDownMenu
+ * @extends openerp.web.Widget
+ *
+ * @param parent
+ */
+ init: function(parent) {
+ this._super(parent);
+ this.update_promise = $.Deferred().resolve();
+ },
+ start: function() {
+ var self = this;
+ this._super.apply(this, arguments);
+ $('html').bind('click', function() {
+ self.$element.find('.oe_dropdown_options').hide();
+ });
+ this.$element.find('.oe_dropdown_toggle').click(function() {
+ self.$element.find('.oe_dropdown_options').toggle();
+ return false;
+ });
+ this.$element.on('click', '.oe_dropdown_options li a[data-menu]', function() {
+ var f = self['on_menu_' + $(this).data('menu')];
+ f && f($(this));
+ self.$element.find('.oe_dropdown_options').hide();
+ return false;
+ });
+ },
+ change_password :function() {
+ var self = this;
+ this.dialog = new openerp.web.Dialog(this, {
+ title: _t("Change Password"),
+ width : 'auto'
+ }).open();
+ this.dialog.$element.html(QWeb.render("Change_Pwd", self));
+ this.dialog.$element.find("form[name=change_password_form]").validate({
+ submitHandler: function (form) {
+ self.rpc("/web/session/change_password",{
+ 'fields': $(form).serializeArray()
+ }, function(result) {
+ if (result.error) {
+ self.display_error(result);
+ return;
+ } else {
+ openerp.webclient.on_logout();
+ }
+ });
+ }
+ });
+ },
+ display_error: function (error) {
+ return openerp.web.dialog($('<div>'), {
+ modal: true,
+ title: error.title,
+ buttons: [
+ {text: _("Ok"), click: function() { $(this).dialog("close"); }}
+ ]
+ }).html(error.error);
+ },
+ do_update: function () {
+ var self = this;
+ var fct = function() {
+ var $avatar = self.$element.find('.oe_topbar_avatar');
+ $avatar.attr('src', $avatar.data('default-src'));
+ if (!self.session.uid)
+ return;
+ var func = new openerp.web.Model("res.users").get_func("read");
+ return func(self.session.uid, ["name", "company_id"]).pipe(function(res) {
+ // TODO: Only show company if multicompany in use
+ self.$element.find('.oe_topbar_name').text(res.name + '/' + res.company_id[1]);
+ return self.shortcut_load();
+ });
+ };
+ this.update_promise = this.update_promise.pipe(fct, fct);
+ },
+ on_action: function() {
+ },
+ shortcut_load :function(){
+ var self = this,
+ sc = self.session.shortcuts,
+ shortcuts_ds = new openerp.web.DataSet(this, 'ir.ui.view_sc');
+ self.$element.find('.oe_dropdown_options a[data-menu=shortcut]').each(function() {
+ $(this).parent().remove();
+ });
+ // TODO: better way to communicate between sections.
+ // sc.bindings, because jquery does not bind/trigger on arrays...
+ if (!sc.binding) {
+ sc.binding = {};
+ $(sc.binding).bind({
+ 'add': function (e, attrs) {
+ shortcuts_ds.create(attrs, function (out) {
+ var shortcut = QWeb.render('DropDownMenu.shortcut', {
+ shortcuts : [{
+ name : attrs.name,
+ id : out.result,
+ res_id : attrs.res_id
+ }]
+ });
+ $(shortcut).appendTo(self.$element.find('.oe_dropdown_options'));
+ attrs.id = out.result;
+ sc.push(attrs);
+ });
+ },
+ 'remove-current': function () {
+ var menu_id = self.session.active_id;
+ var $shortcut = self.$element.find('.oe_dropdown_options li a[data-id=' + menu_id + ']');
+ var shortcut_id = $shortcut.data('shortcut-id');
+ $shortcut.remove();
+ shortcuts_ds.unlink([shortcut_id]);
+ var sc_new = _.reject(sc, function(shortcut){ return shortcut_id === shortcut.id});
+ sc.splice(0, sc.length);
+ sc.push.apply(sc, sc_new);
+ }
+ });
+ }
+ return this.rpc('/web/session/sc_list', {}, function(shortcuts) {
+ sc.splice(0, sc.length);
+ sc.push.apply(sc, shortcuts);
+
+ $(QWeb.render('DropDownMenu.shortcut', {'shortcuts': shortcuts}))
+ .appendTo(self.$element.find('.oe_dropdown_options'));
+ });
+ },
+ on_menu_logout: function() {
+ },
+ on_menu_settings: function() {
+ var self = this;
+ var action_manager = new openerp.web.ActionManager(this);
+ var dataset = new openerp.web.DataSet (this,'res.users',this.context);
+ dataset.call ('action_get','',function (result){
+ self.rpc('/web/action/load', {action_id:result}, function(result){
+ action_manager.do_action(_.extend(result['result'], {
+ res_id: self.session.uid,
+ res_model: 'res.users',
+ flags: {
+ action_buttons: false,
+ search_view: false,
+ sidebar: false,
+ views_switcher: false,
+ pager: false
+ }
+ }));
+ });
+ });
+ this.dialog = new openerp.web.Dialog(this,{
+ title: _t("Preferences"),
+ width: '700px',
+ buttons: [
+ {text: _t("Cancel"), click: function(){ $(this).dialog('destroy'); }},
+ {text: _t("Change password"), click: function(){ self.change_password(); }},
+ {text: _t("Save"), click: function(){
+ var inner_viewmanager = action_manager.inner_viewmanager;
+ inner_viewmanager.views[inner_viewmanager.active_view].controller.do_save()
+ .then(function() {
+ self.dialog.destroy();
+ // needs to refresh interface in case language changed
+ window.location.reload();
+ });
+ }
+ }
+ ]
+ }).open();
+ action_manager.appendTo(this.dialog);
+ action_manager.render(this.dialog);
+ },
+ on_menu_about: function() {
+ var self = this;
+ self.rpc("/web/webclient/version_info", {}).then(function(res) {
+ var $help = $(QWeb.render("About-Page", {version_info: res}));
+ $help.find('a.oe_activate_debug_mode').click(function (e) {
+ e.preventDefault();
+ window.location = $.param.querystring(
+ window.location.href, 'debug');
+ });
+ openerp.web.dialog($help, {autoOpen: true,
+ modal: true, width: 960, title: _t("About")});
+ });
+ },
+ on_menu_shortcut: function($link) {
+ var self = this,
+ id = $link.data('id');
+ self.session.active_id = id;
+ self.rpc('/web/menu/action', {'menu_id': id}, function(ir_menu_data) {
+ if (ir_menu_data.action.length){
+ self.on_action(ir_menu_data.action[0][2]);
+ }
+ });
+ }
+});
+
openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClient */{
/**
* @constructs openerp.web.WebClient
* @extends openerp.web.Widget
- *
- * @param element_id
*/
init: function(parent) {
var self = this;
this._super(parent);
openerp.webclient = this;
-
+ this.querystring = '?' + jQuery.param.querystring();
this._current_state = null;
},
- render_element: function() {
- this.$element = $('<body/>');
- this.$element.attr("id", "oe");
- this.$element.addClass("openerp");
- },
start: function() {
var self = this;
+ this.$element.addClass("openerp openerp2");
if (jQuery.param != undefined && jQuery.deparam(jQuery.param.querystring()).kitten != undefined) {
this.$element.addClass("kitten-mode-activated");
this.$element.delegate('img.oe-record-edit-link-img', 'hover', function(e) {
});
this.session.on_session_valid.add(function() {
self.show_application();
-
- self.header.do_update();
+
+ self.dropdown_menu.do_update();
self.menu.do_reload();
if(self.action_manager)
- self.action_manager.stop();
+ self.action_manager.destroy();
self.action_manager = new openerp.web.ActionManager(self);
self.action_manager.appendTo($("#oe_app"));
self.bind_hashchange();
+ var version_label = _t("OpenERP - Unsupported/Community Version");
if (!self.session.openerp_entreprise) {
- self.$element.find('.oe_footer_powered').append('<span> - <a href="http://www.openerp.com/support-or-publisher-warranty-contract" target="_blank">Unsupported/Community Version</a></span>');
- $('title').html('OpenERP - Unsupported/Community Version');
+ self.$element.find('.oe_footer_powered').append(_.str.sprintf('<span> - <a href="http://www.openerp.com/support-or-publisher-warranty-contract" target="_blank">%s</a></span>', version_label));
+ document.title = version_label;
}
});
},
var self = this;
this.destroy_content();
this.show_common();
- self.$table = $(QWeb.render("Interface", {}));
+ self.$table = $(QWeb.render("WebClient", {}));
self.$element.append(self.$table);
- self.header = new openerp.web.Header(self);
- self.header.on_logout.add(self.on_logout);
- self.header.on_action.add(self.on_menu_action);
- self.header.appendTo($("#oe_header"));
- self.menu = new openerp.web.Menu(self, "oe_menu", "oe_secondary_menu");
- self.menu.on_action.add(self.on_menu_action);
- self.menu.start();
+ self.menu = new openerp.web.Menu(self);
+ self.menu.replace(this.$element.find('.oe_menu_placeholder'));
+ self.menu.on_action.add(this.proxy('on_menu_action'));
+ self.dropdown_menu = new openerp.web.DropDownMenu(self);
+ self.dropdown_menu.replace(this.$element.find('.oe_dropdown_menu_placeholder'));
+ self.dropdown_menu.on_menu_logout.add(this.proxy('on_logout'));
+ self.dropdown_menu.on_action.add(this.proxy('on_menu_action'));
},
show_common: function() {
var self = this;
- self.crashmanager = new openerp.web.CrashManager();
- self.notification = new openerp.web.Notification(self);
- self.notification.appendTo(self.$element);
- self.loading = new openerp.web.Loading(self);
- self.loading.appendTo(self.$element);
+ if (!this.crashmanager) {
+ this.crashmanager = new openerp.web.CrashManager();
+ openerp.connection.on_rpc_error.add(this.crashmanager.on_rpc_error);
+ window.onerror = function (message, file, line) {
+ self.crashmanager.on_traceback({
+ type: _t("Client Error"),
+ message: message,
+ data: {debug: file + ':' + line}
+ });
+ }
+ }
+ this.notification = new openerp.web.Notification(this);
+ this.notification.appendTo(this.$element);
+ this.loading = new openerp.web.Loading(this);
+ this.loading.appendTo(this.$element);
},
destroy_content: function() {
- _.each(_.clone(this.widget_children), function(el) {
- el.stop();
+ _.each(_.clone(this.getChildren()), function(el) {
+ el.destroy();
});
this.$element.children().remove();
},
do_reload: function() {
- return this.session.session_init().pipe(_.bind(function() {this.menu.do_reload();}, this));
+ var self = this;
+ return this.session.session_reload().pipe(function () {
+ openerp.connection.load_modules(true).pipe(
+ self.menu.proxy('do_reload')); });
+
},
do_notify: function() {
var n = this.notification;
n.warn.apply(n, arguments);
},
on_logout: function() {
- this.session.session_logout();
- this.header.do_update();
- $(window).unbind('hashchange', this.on_hashchange);
- this.do_push_state({});
- //would be cool to be able to do this, but I think it will make addons do strange things
- //this.show_login();
- window.location.reload();
+ var self = this;
+ this.session.session_logout().then(function () {
+ $(window).unbind('hashchange', self.on_hashchange);
+ self.do_push_state({});
+ //would be cool to be able to do this, but I think it will make addons do strange things
+ //this.show_login();
+ window.location.reload();
+ });
},
bind_hashchange: function() {
$(window).bind('hashchange', this.on_hashchange);
on_hashchange: function(event) {
var state = event.getState(true);
if (!_.isEqual(this._current_state, state)) {
- this.action_manager.do_load_state(state);
+ this.action_manager.do_load_state(state, !!this._current_state);
}
this._current_state = state;
},
self.menu.on_menu_click(null, action.menu_id);
});
}
- },
+ }
});
-openerp.web.EmbeddedClient = openerp.web.Widget.extend({
+openerp.web.EmbeddedClient = openerp.web.OldWidget.extend({
template: 'EmptyComponent',
init: function(action_id, options) {
this._super();
self.am.do_action(action);
});
- },
+ }
});