summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/chrome.js
diff options
context:
space:
mode:
authorvta vta@openerp.com <>2012-11-08 14:20:49 +0100
committervta vta@openerp.com <>2012-11-08 14:20:49 +0100
commit2576cd9d5cdf34c3233a0cdae7d8439bce85de1c (patch)
tree08b44ce4e44d01018a32097acb902ee1eb2bb2fa /addons/web/static/src/js/chrome.js
parent6a229f4385db0a2961116fcf599502288089cb38 (diff)
parentd0400362d636cbe2677c29a9196d63f419b72bff (diff)
[MERGE] Latest trunk.
bzr revid: vta@openerp.com-20121108132049-7ape10oz1gvz4vi8
Diffstat (limited to 'addons/web/static/src/js/chrome.js')
-rw-r--r--addons/web/static/src/js/chrome.js90
1 files changed, 49 insertions, 41 deletions
diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js
index 81334cd6589..9c249a5fb0c 100644
--- a/addons/web/static/src/js/chrome.js
+++ b/addons/web/static/src/js/chrome.js
@@ -81,9 +81,6 @@ instance.web.Dialog = instance.web.Widget.extend({
}
}
if (options) {
- if (options.buttons) {
- this.params_buttons = true;
- }
_.extend(this.dialog_options, options);
}
this.on("closing", this, this._closing);
@@ -129,6 +126,8 @@ instance.web.Dialog = instance.web.Widget.extend({
if (! this.dialog_inited)
this.init_dialog();
var o = this.get_options(options);
+ this.add_buttons(o.buttons);
+ delete(o.buttons);
this.$buttons.appendTo($("body"));
instance.web.dialog(this.$el, o).dialog('open');
this.$el.dialog("widget").find(".ui-dialog-buttonpane").remove();
@@ -138,22 +137,30 @@ instance.web.Dialog = instance.web.Widget.extend({
}
return this;
},
+ add_buttons: function(buttons) {
+ var self = this;
+ _.each(buttons, function(fn, but) {
+ var $but = $(QWeb.render('WidgetButton', { widget : { string: but, node: { attrs: {} }}}));
+ self.$buttons.append($but);
+ $but.on('click', function(ev) {
+ fn.call(self.$el, ev);
+ });
+ });
+ },
init_dialog: function(options) {
this.renderElement();
var o = this.get_options(options);
instance.web.dialog(this.$el, o);
- if (! this.params_buttons) {
- this.$buttons = $('<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" />');
- this.$el.dialog("widget").append(this.$buttons);
- } else {
- this.$buttons = this.$el.dialog("widget").find(".ui-dialog-buttonpane");
- }
+ this.$buttons = $('<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" />');
+ this.$el.dialog("widget").append(this.$buttons);
this.dialog_inited = true;
var res = this.start();
return res;
},
close: function() {
- this.$el.dialog('close');
+ if (this.dialog_inited && this.$el.is(":data(dialog)")) {
+ this.$el.dialog('close');
+ }
},
_closing: function() {
if (this.__tmp_dialog_destroying)
@@ -175,7 +182,7 @@ instance.web.Dialog = instance.web.Widget.extend({
this.close();
this.__tmp_dialog_destroying = undefined;
}
- if (! this.isDestroyed()) {
+ if (this.dialog_inited && !this.isDestroyed()) {
this.$el.dialog('destroy');
}
this._super();
@@ -294,7 +301,7 @@ instance.web.DatabaseManager = instance.web.Widget.extend({
start: function() {
var self = this;
$('.oe_secondary_menus_container,.oe_user_menu_placeholder').empty();
- var fetch_db = this.rpc("/web/database/get_list", {}).pipe(
+ var fetch_db = this.rpc("/web/database/get_list", {}).then(
function(result) {
self.db_list = result.db_list;
},
@@ -302,10 +309,10 @@ instance.web.DatabaseManager = instance.web.Widget.extend({
ev.preventDefault();
self.db_list = null;
});
- var fetch_langs = this.rpc("/web/session/get_lang_list", {}).then(function(result) {
+ var fetch_langs = this.rpc("/web/session/get_lang_list", {}).done(function(result) {
self.lang_list = result.lang_list;
});
- return $.when(fetch_db, fetch_langs).then(self.do_render);
+ return $.when(fetch_db, fetch_langs).done(self.do_render);
},
do_render: function() {
var self = this;
@@ -394,7 +401,7 @@ instance.web.DatabaseManager = instance.web.Widget.extend({
do_create: function(form) {
var self = this;
var fields = $(form).serializeArray();
- self.rpc("/web/database/create", {'fields': fields}).then(function(result) {
+ self.rpc("/web/database/create", {'fields': fields}).done(function(result) {
var form_obj = self.to_object(fields);
var client_action = {
type: 'ir.actions.client',
@@ -420,7 +427,7 @@ instance.web.DatabaseManager = instance.web.Widget.extend({
if (!db || !confirm("Do you really want to delete the database: " + db + " ?")) {
return;
}
- self.rpc("/web/database/drop", {'fields': fields}).then(function(result) {
+ self.rpc("/web/database/drop", {'fields': fields}).done(function(result) {
if (result.error) {
self.display_error(result);
return;
@@ -483,7 +490,7 @@ instance.web.DatabaseManager = instance.web.Widget.extend({
var self = this;
self.rpc("/web/database/change_password", {
'fields': $(form).serializeArray()
- }).then(function(result) {
+ }).done(function(result) {
if (result.error) {
self.display_error(result);
return;
@@ -504,13 +511,13 @@ instance.web.Login = instance.web.Widget.extend({
template: "Login",
remember_credentials: true,
- init: function(parent, params) {
+ init: function(parent, action) {
this._super(parent);
this.has_local_storage = typeof(localStorage) != 'undefined';
this.db_list = null;
this.selected_db = null;
this.selected_login = null;
- this.params = params || {};
+ this.params = action.params || {};
if (this.params.login_successful) {
this.on('login_successful', this, this.params.login_successful);
@@ -581,7 +588,7 @@ instance.web.Login = instance.web.Widget.extend({
var self = this;
self.hide_error();
self.$(".oe_login_pane").fadeOut("slow");
- return this.session.session_authenticate(db, login, password).pipe(function() {
+ return this.session.session_authenticate(db, login, password).then(function() {
if (self.has_local_storage) {
if(self.remember_credentials) {
localStorage.setItem('last_db_login_success', db);
@@ -616,8 +623,9 @@ instance.web.client_actions.add("login", "instance.web.Login");
* Client action to reload the whole interface.
* If params has an entry 'menu_id', it opens the given menu entry.
*/
-instance.web.Reload = function(parent, params) {
- var menu_id = (params && params.menu_id) || false;
+instance.web.Reload = function(parent, action) {
+ var params = action.params || {};
+ var menu_id = params.menu_id || false;
var l = window.location;
var sobj = $.deparam(l.search.substr(1));
@@ -638,7 +646,7 @@ 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.
*/
-instance.web.HistoryBack = function(parent, params) {
+instance.web.HistoryBack = function(parent) {
if (!parent.history_back()) {
window.location = '/' + (window.location.search || '');
}
@@ -649,7 +657,7 @@ instance.web.client_actions.add("history_back", "instance.web.HistoryBack");
* Client action to go back home.
*/
instance.web.Home = instance.web.Widget.extend({
- init: function(parent, params) {
+ init: function(parent) {
window.location = '/' + (window.location.search || '');
}
});
@@ -663,7 +671,7 @@ instance.web.ChangePassword = instance.web.Widget.extend({
submitHandler: function (form) {
self.rpc("/web/session/change_password",{
'fields': $(form).serializeArray()
- }).then(function(result) {
+ }).done(function(result) {
if (result.error) {
self.display_error(result);
return;
@@ -702,7 +710,7 @@ instance.web.Menu = instance.web.Widget.extend({
},
do_reload: function() {
var self = this;
- return this.rpc("/web/menu/load", {}).then(function(r) {
+ return this.rpc("/web/menu/load", {}).done(function(r) {
self.menu_loaded(r);
});
},
@@ -872,7 +880,7 @@ instance.web.UserMenu = instance.web.Widget.extend({
if (!self.session.uid)
return;
var func = new instance.web.Model("res.users").get_func("read");
- return func(self.session.uid, ["name", "company_id"]).pipe(function(res) {
+ return func(self.session.uid, ["name", "company_id"]).then(function(res) {
var topbar_name = res.name;
if(instance.session.debug)
topbar_name = _.str.sprintf("%s (%s)", topbar_name, instance.session.db);
@@ -883,7 +891,7 @@ instance.web.UserMenu = instance.web.Widget.extend({
$avatar.attr('src', avatar_src);
});
};
- this.update_promise = this.update_promise.pipe(fct, fct);
+ this.update_promise = this.update_promise.then(fct, fct);
},
on_menu_logout: function() {
this.trigger('user_logout');
@@ -899,7 +907,7 @@ instance.web.UserMenu = instance.web.Widget.extend({
},
on_menu_about: function() {
var self = this;
- self.rpc("/web/webclient/version_info", {}).then(function(res) {
+ self.rpc("/web/webclient/version_info", {}).done(function(res) {
var $help = $(QWeb.render("UserMenu.about", {version_info: res}));
$help.find('a.oe_activate_debug_mode').click(function (e) {
e.preventDefault();
@@ -919,7 +927,7 @@ instance.web.Client = instance.web.Widget.extend({
},
start: function() {
var self = this;
- return instance.session.session_bind(this.origin).pipe(function() {
+ return instance.session.session_bind(this.origin).then(function() {
var $e = $(QWeb.render(self._template, {}));
self.replaceElement($e);
self.bind_events();
@@ -986,7 +994,7 @@ instance.web.WebClient = instance.web.Client.extend({
},
start: function() {
var self = this;
- return $.when(this._super()).pipe(function() {
+ return $.when(this._super()).then(function() {
self.$el.on('click', '.oe_logo', function() {
self.action_manager.do_action('home');
});
@@ -1055,8 +1063,8 @@ instance.web.WebClient = instance.web.Client.extend({
},
do_reload: function() {
var self = this;
- return this.session.session_reload().pipe(function () {
- instance.session.load_modules(true).pipe(
+ return this.session.session_reload().then(function () {
+ instance.session.load_modules(true).then(
self.menu.proxy('do_reload')); });
},
@@ -1071,7 +1079,7 @@ instance.web.WebClient = instance.web.Client.extend({
on_logout: function() {
var self = this;
if (!this.has_uncommitted_changes()) {
- this.session.session_logout().then(function () {
+ this.session.session_logout().done(function () {
$(window).unbind('hashchange', self.on_hashchange);
self.do_push_state({});
window.location.reload();
@@ -1084,7 +1092,7 @@ instance.web.WebClient = instance.web.Client.extend({
var state = $.bbq.getState(true);
if (_.isEmpty(state) || state.action == "login") {
- self.menu.has_been_loaded.then(function() {
+ self.menu.has_been_loaded.done(function() {
var first_menu_id = self.menu.$el.find("a:first").data("menu");
if(first_menu_id) {
self.menu.menu_click(first_menu_id);
@@ -1099,8 +1107,8 @@ instance.web.WebClient = instance.web.Client.extend({
var state = event.getState(true);
if (!_.isEqual(this._current_state, state)) {
if(state.action_id === undefined && state.menu_id) {
- self.menu.has_been_loaded.then(function() {
- self.menu.do_reload().then(function() {
+ self.menu.has_been_loaded.done(function() {
+ self.menu.do_reload().done(function() {
self.menu.menu_click(state.menu_id)
});
});
@@ -1122,7 +1130,7 @@ instance.web.WebClient = instance.web.Client.extend({
on_menu_action: function(options) {
var self = this;
return this.rpc("/web/action/load", { action_id: options.action_id })
- .pipe(function (result) {
+ .then(function (result) {
var action = result;
if (options.needaction) {
action.context.search_default_message_unread = true;
@@ -1168,9 +1176,9 @@ instance.web.EmbeddedClient = instance.web.Client.extend({
},
start: function() {
var self = this;
- return $.when(this._super()).pipe(function() {
- return instance.session.session_authenticate(self.dbname, self.login, self.key, true).pipe(function() {
- return self.rpc("/web/action/load", { action_id: self.action_id }).then(function(result) {
+ return $.when(this._super()).then(function() {
+ return instance.session.session_authenticate(self.dbname, self.login, self.key, true).then(function() {
+ return self.rpc("/web/action/load", { action_id: self.action_id }).done(function(result) {
var action = result;
action.flags = _.extend({
//views_switcher : false,