1 /*---------------------------------------------------------
3 *---------------------------------------------------------*/
4 openerp.web.chrome = function(openerp) {
5 var QWeb = openerp.web.qweb,
8 openerp.web.Notification = openerp.web.Widget.extend(/** @lends openerp.web.Notification# */{
9 template: 'Notification',
10 identifier_prefix: 'notification-',
13 this._super.apply(this, arguments);
14 openerp.notification = this;
18 this._super.apply(this, arguments);
19 this.$element.notify({
24 notify: function(title, text) {
25 this.$element.notify('create', {
30 warn: function(title, text) {
31 this.$element.notify('create', 'oe_notification_alert', {
39 openerp.web.Dialog = openerp.web.OldWidget.extend(/** @lends openerp.web.Dialog# */{
41 identifier_prefix: 'dialog',
43 * @constructs openerp.web.Dialog
44 * @extends openerp.web.OldWidget
47 * @param dialog_options
49 init: function (parent, dialog_options) {
52 this.dialog_options = {
62 beforeClose: function () { self.on_close(); }
65 if (f.substr(0, 10) == 'on_button_') {
66 this.dialog_options.buttons[f.substr(10)] = this[f];
70 this.set_options(dialog_options);
73 set_options: function(options) {
74 options = options || {};
75 options.width = this.get_width(options.width || this.dialog_options.width);
76 options.min_width = this.get_width(options.min_width || this.dialog_options.min_width);
77 options.max_width = this.get_width(options.max_width || this.dialog_options.max_width);
78 options.height = this.get_height(options.height || this.dialog_options.height);
79 options.min_height = this.get_height(options.min_height || this.dialog_options.min_height);
80 options.max_height = this.get_height(options.max_height || this.dialog_options.max_width);
82 if (options.width !== 'auto') {
83 if (options.width > options.max_width) options.width = options.max_width;
84 if (options.width < options.min_width) options.width = options.min_width;
86 if (options.height !== 'auto') {
87 if (options.height > options.max_height) options.height = options.max_height;
88 if (options.height < options.min_height) options.height = options.min_height;
90 if (!options.title && this.dialog_title) {
91 options.title = this.dialog_title;
93 _.extend(this.dialog_options, options);
95 get_width: function(val) {
96 return this.get_size(val.toString(), $(window.top).width());
98 get_height: function(val) {
99 return this.get_size(val.toString(), $(window.top).height());
101 get_size: function(val, available_size) {
102 if (val === 'auto') {
104 } else if (val.slice(-1) == "%") {
105 return Math.round(available_size / 100 * parseInt(val.slice(0, -1), 10));
107 return parseInt(val, 10);
111 this.$dialog = $(this.$element).dialog(this.dialog_options);
115 open: function(dialog_options) {
116 // TODO fme: bind window on resize
118 this.$element.html(this.render());
120 this.set_options(dialog_options);
121 this.$dialog.dialog(this.dialog_options).dialog('open');
125 // Closes the dialog but leave it in a state where it could be opened again.
126 this.$dialog.dialog('close');
128 on_close: function() {
133 this.$dialog.dialog('destroy');
138 openerp.web.CrashManager = openerp.web.CallbackEnabled.extend({
141 openerp.connection.on_rpc_error.add(this.on_rpc_error);
143 on_rpc_error: function(error) {
145 if (error.data.fault_code) {
146 var split = ("" + error.data.fault_code).split('\n')[0].split(' -- ');
147 if (split.length > 1) {
148 error.type = split.shift();
149 error.data.fault_code = error.data.fault_code.substr(error.type.length + 4);
152 if (error.code === 200 && error.type) {
153 this.on_managed_error(error);
155 this.on_traceback(error);
158 on_managed_error: function(error) {
159 $('<div>' + QWeb.render('DialogWarning', {error: error}) + '</div>').dialog({
160 title: "OpenERP " + _.str.capitalize(error.type),
162 {text: _t("Ok"), click: function() { $(this).dialog("close"); }}
166 on_traceback: function(error) {
167 var dialog = new openerp.web.Dialog(this, {
168 title: "OpenERP " + _.str.capitalize(error.type),
175 {text: _t("Ok"), click: function() { $(this).dialog("close"); }}
178 dialog.$element.html(QWeb.render('DialogTraceback', {error: error}));
182 openerp.web.Loading = openerp.web.Widget.extend(/** @lends openerp.web.Loading# */{
185 * @constructs openerp.web.Loading
186 * @extends openerp.web.Widget
191 init: function(parent) {
194 this.blocked_ui = false;
195 this.session.on_rpc_request.add_first(this.on_rpc_event, 1);
196 this.session.on_rpc_response.add_last(this.on_rpc_event, -1);
198 on_rpc_event : function(increment) {
200 if (!this.count && increment === 1) {
202 this.long_running_timer = setTimeout(function () {
203 self.blocked_ui = true;
208 this.count += increment;
209 if (this.count > 0) {
210 //this.$element.html(QWeb.render("Loading", {}));
211 this.$element.html("Loading ("+this.count+")");
212 this.$element.show();
213 this.widget_parent.$element.addClass('loading');
216 clearTimeout(this.long_running_timer);
217 // Don't unblock if blocked by somebody else
218 if (self.blocked_ui) {
219 this.blocked_ui = false;
222 this.$element.fadeOut();
223 this.widget_parent.$element.removeClass('loading');
228 openerp.web.Database = openerp.web.Widget.extend(/** @lends openerp.web.Database# */{
230 * @constructs openerp.web.Database
231 * @extends openerp.web.Widget
237 init: function(parent, element_id, option_id) {
238 this._super(parent, element_id);
239 this.$option_id = $('#' + option_id);
240 this.unblockUIFunction = $.unblockUI;
244 this.$element.html(QWeb.render("Database", this));
247 var fetch_db = this.rpc("/web/database/get_list", {}, function(result) {
248 self.db_list = result.db_list;
250 var fetch_langs = this.rpc("/web/session/get_lang_list", {}, function(result) {
252 self.display_error(result);
255 self.lang_list = result.lang_list;
257 $.when(fetch_db, fetch_langs).then(function () {self.do_create();});
259 this.$element.find('#db-create').click(this.do_create);
260 this.$element.find('#db-drop').click(this.do_drop);
261 this.$element.find('#db-backup').click(this.do_backup);
262 this.$element.find('#db-restore').click(this.do_restore);
263 this.$element.find('#db-change-password').click(this.do_change_password);
264 this.$element.find('#back-to-login').click(function() {
270 this.$option_id.empty();
273 .find('#db-create, #db-drop, #db-backup, #db-restore, #db-change-password, #back-to-login')
280 this.$element.closest(".openerp")
281 .removeClass("login-mode")
282 .addClass("database_block");
285 this.$element.closest(".openerp")
286 .addClass("login-mode")
287 .removeClass("database_block")
290 * Converts a .serializeArray() result into a dict. Does not bother folding
291 * multiple identical keys into an array, last key wins.
293 * @param {Array} array
295 to_object: function (array) {
297 _(array).each(function (record) {
298 result[record.name] = record.value;
303 * Waits until the new database is done creating, then unblocks the UI and
304 * logs the user in as admin
306 * @param {Number} db_creation_id identifier for the db-creation operation, used to fetch the current installation progress
307 * @param {Object} info info fields for this database creation
308 * @param {String} info.db name of the database being created
309 * @param {String} info.password super-admin password for the database
311 wait_for_newdb: function (db_creation_id, info) {
313 self.rpc('/web/database/progress', {
315 password: info.password
316 }, function (result) {
317 var progress = result[0];
318 // I'd display a progress bar, but turns out the progress status
319 // the server report kind-of blows goats: it's at 0 for ~75% of
320 // the installation, then jumps to 75%, then jumps down to either
321 // 0 or ~40%, then back up to 75%, then terminates. Let's keep that
322 // mess hidden behind a not-very-useful but not overly weird
325 setTimeout(function () {
326 self.wait_for_newdb(db_creation_id, info);
331 var admin = result[1][0];
332 setTimeout(function () {
333 self.widget_parent.do_login(
334 info.db, admin.login, admin.password);
341 * Blocks UI and replaces $.unblockUI by a noop to prevent third parties
342 * from unblocking the UI
344 blockUI: function () {
346 $.unblockUI = function () {};
349 * Reinstates $.unblockUI so third parties can play with blockUI, and
352 unblockUI: function () {
353 $.unblockUI = this.unblockUIFunction;
357 * Displays an error dialog resulting from the various RPC communications
358 * failing over themselves
360 * @param {Object} error error description
361 * @param {String} error.title title of the error dialog
362 * @param {String} error.error message of the error dialog
364 display_error: function (error) {
365 return $('<div>').dialog({
369 {text: _t("Ok"), click: function() { $(this).dialog("close"); }}
371 }).html(error.error);
373 do_create: function() {
375 self.$option_id.html(QWeb.render("Database.CreateDB", self));
376 self.$option_id.find("form[name=create_db_form]").validate({
377 submitHandler: function (form) {
378 var fields = $(form).serializeArray();
380 self.rpc("/web/database/create", {'fields': fields}, function(result) {
383 self.display_error(result);
386 self.db_list.push(self.to_object(fields)['db_name']);
388 self.widget_parent.set_db_list(self.db_list);
389 var form_obj = self.to_object(fields);
390 self.wait_for_newdb(result, {
391 password: form_obj['super_admin_pwd'],
392 db: form_obj['db_name']
398 do_drop: function() {
400 self.$option_id.html(QWeb.render("DropDB", self));
401 self.$option_id.find("form[name=drop_db_form]").validate({
402 submitHandler: function (form) {
404 fields = $form.serializeArray(),
405 $db_list = $form.find('select[name=drop_db]'),
408 if (!confirm("Do you really want to delete the database: " + db + " ?")) {
411 self.rpc("/web/database/drop", {'fields': fields}, function(result) {
413 self.display_error(result);
416 $db_list.find(':selected').remove();
417 self.db_list.splice(_.indexOf(self.db_list, db, true), 1);
418 self.widget_parent.set_db_list(self.db_list);
419 self.do_notify("Dropping database", "The database '" + db + "' has been dropped");
424 do_backup: function() {
427 .html(QWeb.render("BackupDB", self))
428 .find("form[name=backup_db_form]").validate({
429 submitHandler: function (form) {
431 self.session.get_file({
433 error: function (body) {
434 var error = body.firstChild.data.split('|');
440 complete: $.proxy(self, 'unblockUI')
445 do_restore: function() {
447 self.$option_id.html(QWeb.render("RestoreDB", self));
449 self.$option_id.find("form[name=restore_db_form]").validate({
450 submitHandler: function (form) {
453 url: '/web/database/restore',
456 success: function (body) {
457 // TODO: ui manipulations
458 // note: response objects don't work, but we have the
459 // HTTP body of the response~~
461 // If empty body, everything went fine
462 if (!body) { return; }
464 if (body.indexOf('403 Forbidden') !== -1) {
466 title: 'Access Denied',
467 error: 'Incorrect super-administrator password'
471 title: 'Restore Database',
472 error: 'Could not restore the database'
476 complete: $.proxy(self, 'unblockUI')
481 do_change_password: function() {
483 self.$option_id.html(QWeb.render("Change_DB_Pwd", self));
485 self.$option_id.find("form[name=change_pwd_form]").validate({
487 old_pwd: "Please enter your previous password",
488 new_pwd: "Please enter your new password",
490 required: "Please confirm your new password",
491 equalTo: "The confirmation does not match the password"
494 submitHandler: function (form) {
495 self.rpc("/web/database/change_password", {
496 'fields': $(form).serializeArray()
497 }, function(result) {
499 self.display_error(result);
502 self.do_notify("Changed Password", "Password has been changed successfully");
509 openerp.web.Login = openerp.web.Widget.extend(/** @lends openerp.web.Login# */{
510 remember_credentials: true,
513 identifier_prefix: 'oe-app-login-',
515 * @constructs openerp.web.Login
516 * @extends openerp.web.Widget
522 init: function(parent) {
524 this.has_local_storage = typeof(localStorage) != 'undefined';
525 this.selected_db = null;
526 this.selected_login = null;
528 if (this.has_local_storage && this.remember_credentials) {
529 this.selected_db = localStorage.getItem('last_db_login_success');
530 this.selected_login = localStorage.getItem('last_login_login_success');
531 if (jQuery.deparam(jQuery.param.querystring()).debug != undefined) {
532 this.selected_password = localStorage.getItem('last_password_login_success');
536 var qs = jQuery.deparam(jQuery.param.querystring());
538 this.selected_db = qs.db;
541 this.selected_login = qs.login;
547 this.database = new openerp.web.Database(
548 this, "oe_database", "oe_db_options");
549 this.database.start();
551 this.$element.find('#oe-db-config').click(function() {
552 self.database.show();
555 this.$element.find("form").submit(this.on_submit);
557 this.rpc("/web/database/get_list", {}, function(result) {
558 self.set_db_list(result.db_list);
560 function(error, event) {
561 if (error.data.fault_code === 'AccessDenied') {
562 event.preventDefault();
568 this.database.stop();
571 set_db_list: function (list) {
572 this.$element.find("[name=db]").replaceWith(
573 openerp.web.qweb.render('Login_dblist', {
574 db_list: list, selected_db: this.selected_db}))
576 on_login_invalid: function() {
577 this.$element.closest(".openerp").addClass("login-mode");
579 on_login_valid: function() {
580 this.$element.closest(".openerp").removeClass("login-mode");
582 on_submit: function(ev) {
584 var $e = this.$element;
585 var db = $e.find("form [name=db]").val();
586 var login = $e.find("form input[name=login]").val();
587 var password = $e.find("form input[name=password]").val();
589 this.do_login(db, login, password);
592 * Performs actual login operation, and UI-related stuff
594 * @param {String} db database to log in
595 * @param {String} login user login
596 * @param {String} password user password
598 do_login: function (db, login, password) {
600 this.session.session_authenticate(db, login, password).then(function() {
601 if(self.session.session_is_valid()) {
602 if (self.has_local_storage) {
603 if(self.remember_credentials) {
604 localStorage.setItem('last_db_login_success', db);
605 localStorage.setItem('last_login_login_success', login);
606 if (jQuery.deparam(jQuery.param.querystring()).debug != undefined) {
607 localStorage.setItem('last_password_login_success', password);
610 localStorage.setItem('last_db_login_success', '');
611 localStorage.setItem('last_login_login_success', '');
612 localStorage.setItem('last_password_login_success', '');
615 self.on_login_valid();
617 self.$element.addClass("login_invalid");
618 self.on_login_invalid();
622 do_ask_login: function(continuation) {
623 this.on_login_invalid();
625 .removeClass("login_invalid");
626 this.on_login_valid.add({
629 callback: continuation || function() {}
634 openerp.web.Header = openerp.web.Widget.extend(/** @lends openerp.web.Header# */{
636 identifier_prefix: 'oe-app-header-',
638 * @constructs openerp.web.Header
639 * @extends openerp.web.Widget
643 init: function(parent) {
645 this.qs = "?" + jQuery.param.querystring();
647 this.update_promise = $.Deferred().resolve();
652 do_update: function () {
654 var fct = function() {
655 self.$content.remove();
656 if (!self.session.uid)
658 var func = new openerp.web.Model("res.users").get_func("read");
659 return func(self.session.uid, ["name", "company_id"]).pipe(function(res) {
660 self.$content = $(QWeb.render("Header-content", {widget: self, user: res}));
661 self.$content.appendTo(self.$element);
662 self.$element.find(".logout").click(self.on_logout);
663 self.$element.find("a.preferences").click(self.on_preferences);
664 self.$element.find(".about").click(self.on_about);
665 return self.shortcut_load();
668 this.update_promise = this.update_promise.pipe(fct, fct);
670 on_about: function() {
672 self.rpc("/web/webclient/version_info", {}).then(function(res) {
673 var $help = $(QWeb.render("About-Page", {version_info: res}));
674 $help.dialog({autoOpen: true,
675 modal: true, width: 960, title: _t("About")});
678 shortcut_load :function(){
680 sc = self.session.shortcuts,
681 shortcuts_ds = new openerp.web.DataSet(this, 'ir.ui.view_sc');
682 // TODO: better way to communicate between sections.
683 // sc.bindings, because jquery does not bind/trigger on arrays...
687 'add': function (e, attrs) {
688 shortcuts_ds.create(attrs, function (out) {
690 'data-shortcut-id':out.result,
691 'data-id': attrs.res_id
693 .appendTo(self.$element.find('.oe-shortcuts ul'));
694 attrs.id = out.result;
698 'remove-current': function () {
699 var menu_id = self.session.active_id;
700 var $shortcut = self.$element
701 .find('.oe-shortcuts li[data-id=' + menu_id + ']');
702 var shortcut_id = $shortcut.data('shortcut-id');
704 shortcuts_ds.unlink([shortcut_id]);
705 var sc_new = _.reject(sc, function(shortcut){ return shortcut_id === shortcut.id});
706 sc.splice(0, sc.length);
707 sc.push.apply(sc, sc_new);
711 return this.rpc('/web/session/sc_list', {}, function(shortcuts) {
712 sc.splice(0, sc.length);
713 sc.push.apply(sc, shortcuts);
715 self.$element.find('.oe-shortcuts')
716 .html(QWeb.render('Shortcuts', {'shortcuts': shortcuts}))
717 .undelegate('li', 'click')
719 .delegate('li', 'click', function(e) {
721 var id = $(this).data('id');
722 self.session.active_id = id;
723 self.rpc('/web/menu/action', {'menu_id':id}, function(ir_menu_data) {
724 if (ir_menu_data.action.length){
725 self.on_action(ir_menu_data.action[0][2]);
732 on_action: function(action) {
734 on_preferences: function(){
736 var action_manager = new openerp.web.ActionManager(this);
737 var dataset = new openerp.web.DataSet (this,'res.users',this.context);
738 dataset.call ('action_get','',function (result){
739 self.rpc('/web/action/load', {action_id:result}, function(result){
740 action_manager.do_action(_.extend(result['result'], {
741 res_id: self.session.uid,
742 res_model: 'res.users',
744 action_buttons: false,
747 views_switcher: false,
753 this.dialog = new openerp.web.Dialog(this,{
755 title: _t("Preferences"),
759 {text: _t("Change password"), click: function(){ self.change_password(); }},
760 {text: _t("Cancel"), click: function(){ $(this).dialog('destroy'); }},
761 {text: _t("Save"), click: function(){
762 var inner_viewmanager = action_manager.inner_viewmanager;
763 inner_viewmanager.views[inner_viewmanager.active_view].controller.do_save()
766 window.location.reload();
772 this.dialog.start().open();
773 action_manager.appendTo(this.dialog);
774 action_manager.render(this.dialog);
777 change_password :function() {
779 this.dialog = new openerp.web.Dialog(this,{
781 title: _t("Change Password"),
785 this.dialog.start().open();
786 this.dialog.$element.html(QWeb.render("Change_Pwd", self));
787 this.dialog.$element.find("form[name=change_password_form]").validate({
788 submitHandler: function (form) {
789 self.rpc("/web/session/change_password",{
790 'fields': $(form).serializeArray()
791 }, function(result) {
793 self.display_error(result);
796 self.session.logout();
802 display_error: function (error) {
803 return $('<div>').dialog({
807 {text: _("Ok"), click: function() { $(this).dialog("close"); }}
809 }).html(error.error);
811 on_logout: function() {
815 openerp.web.Menu = openerp.web.Widget.extend(/** @lends openerp.web.Menu# */{
817 * @constructs openerp.web.Menu
818 * @extends openerp.web.Widget
822 * @param secondary_menu_id
824 init: function(parent, element_id, secondary_menu_id) {
825 this._super(parent, element_id);
826 this.secondary_menu_id = secondary_menu_id;
827 this.$secondary_menu = $("#" + secondary_menu_id);
830 if (window.localStorage) {
831 this.folded = localStorage.getItem('oe_menu_folded') === 'true';
833 this.float_timeout = 700;
836 this.$secondary_menu.addClass(this.folded ? 'oe_folded' : 'oe_unfolded');
838 do_reload: function() {
839 return this.rpc("/web/menu/load", {}, this.on_loaded);
841 on_loaded: function(data) {
843 this.$element.html(QWeb.render("Menu", { widget : this }));
844 this.$secondary_menu.html(QWeb.render("Menu.secondary", { widget : this }));
845 this.$element.add(this.$secondary_menu).find("a").click(this.on_menu_click);
846 this.$secondary_menu.find('.oe_toggle_secondary_menu').click(this.on_toggle_fold);
848 on_toggle_fold: function() {
849 this.$secondary_menu.toggleClass('oe_folded').toggleClass('oe_unfolded');
851 this.$secondary_menu.find('.oe_secondary_menu.active').show();
853 this.$secondary_menu.find('.oe_secondary_menu').hide();
855 this.folded = !this.folded;
856 if (window.localStorage) {
857 localStorage.setItem('oe_menu_folded', this.folded.toString());
860 on_menu_click: function(ev, id) {
862 var $clicked_menu, manual = false;
865 // We can manually activate a menu with it's id (for hash url mapping)
867 $clicked_menu = this.$element.find('a[data-menu=' + id + ']');
868 if (!$clicked_menu.length) {
869 $clicked_menu = this.$secondary_menu.find('a[data-menu=' + id + ']');
872 $clicked_menu = $(ev.currentTarget);
873 id = $clicked_menu.data('menu');
876 if (this.do_menu_click($clicked_menu, manual) && id) {
877 this.session.active_id = id;
878 this.rpc('/web/menu/action', {'menu_id': id}, this.on_menu_action_loaded);
881 ev.stopPropagation();
885 do_menu_click: function($clicked_menu, manual) {
886 var $sub_menu, $main_menu,
887 active = $clicked_menu.is('.active'),
888 sub_menu_visible = false;
890 if (this.$secondary_menu.has($clicked_menu).length) {
891 $sub_menu = $clicked_menu.parents('.oe_secondary_menu');
892 $main_menu = this.$element.find('a[data-menu=' + $sub_menu.data('menu-parent') + ']');
894 $sub_menu = this.$secondary_menu.find('.oe_secondary_menu[data-menu-parent=' + $clicked_menu.attr('data-menu') + ']');
895 $main_menu = $clicked_menu;
898 sub_menu_visible = $sub_menu.is(':visible');
899 this.$secondary_menu.find('.oe_secondary_menu').hide();
901 $('.active', this.$element.add(this.$secondary_menu)).removeClass('active');
902 $main_menu.add($clicked_menu).add($sub_menu).addClass('active');
904 if (!(this.folded && manual)) {
905 this.do_show_secondary($sub_menu, $main_menu);
907 this.do_show_secondary();
910 if ($main_menu != $clicked_menu) {
911 if ($clicked_menu.is('.submenu')) {
912 $sub_menu.find('.submenu.opened').each(function() {
913 if (!$(this).next().has($clicked_menu).length && !$(this).is($clicked_menu)) {
914 $(this).removeClass('opened').next().hide();
917 $clicked_menu.toggleClass('opened').next().toggle();
918 } else if ($clicked_menu.is('.leaf')) {
919 $sub_menu.toggle(!this.folded);
922 } else if (this.folded) {
923 if (active && sub_menu_visible) {
933 do_hide_secondary: function() {
934 this.$secondary_menu.hide();
936 do_show_secondary: function($sub_menu, $main_menu) {
938 this.$secondary_menu.show();
939 if (!arguments.length) {
943 var css = $main_menu.position(),
944 fold_width = this.$secondary_menu.width() + 2,
945 window_width = $(window).width();
947 css.left -= Math.round(($sub_menu.width() - $main_menu.width()) / 2);
948 css.left = css.left < fold_width ? fold_width : css.left;
949 if ((css.left + $sub_menu.width()) > window_width) {
954 $sub_menu.mouseenter(function() {
955 clearTimeout($sub_menu.data('timeoutId'));
956 $sub_menu.data('timeoutId', null);
958 }).mouseleave(function(evt) {
959 var timeoutId = setTimeout(function() {
960 if (self.folded && $sub_menu.data('timeoutId')) {
961 $sub_menu.hide().unbind('mouseenter').unbind('mouseleave');
963 }, self.float_timeout);
964 $sub_menu.data('timeoutId', timeoutId);
970 on_menu_action_loaded: function(data) {
972 if (data.action.length) {
973 var action = data.action[0][2];
974 self.on_action(action);
976 self.on_action({type: 'null_action'});
979 on_action: function(action) {
983 openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClient */{
985 * @constructs openerp.web.WebClient
986 * @extends openerp.web.Widget
990 init: function(element_id) {
992 this._super(null, element_id);
993 openerp.webclient = this;
995 this.notification = new openerp.web.Notification(this);
996 this.loading = new openerp.web.Loading(this);
997 this.crashmanager = new openerp.web.CrashManager();
999 this.header = new openerp.web.Header(this);
1000 this.login = new openerp.web.Login(this);
1001 this.header.on_logout.add(this.on_logout);
1002 this.header.on_action.add(this.on_menu_action);
1004 this._current_state = null;
1007 this._super.apply(this, arguments);
1009 this.session.bind().then(function() {
1011 if (jQuery.param != undefined && jQuery.deparam(jQuery.param.querystring()).kitten != undefined) {
1012 this.$element.addClass("kitten-mode-activated");
1013 this.$element.delegate('img.oe-record-edit-link-img', 'hover', function(e) {
1014 self.$element.toggleClass('clark-gable');
1017 self.$element.html(QWeb.render("Interface", params));
1018 self.menu = new openerp.web.Menu(self, "oe_menu", "oe_secondary_menu");
1019 self.menu.on_action.add(self.on_menu_action);
1021 self.notification.prependTo(self.$element);
1022 self.loading.appendTo($('#oe_loading'));
1023 self.header.appendTo($("#oe_header"));
1024 self.login.appendTo($('#oe_login'));
1026 self.login.on_login_invalid();
1028 this.session.ready.then(function() {
1029 self.login.on_login_valid();
1030 self.header.do_update();
1031 self.menu.do_reload();
1032 if(self.action_manager)
1033 self.action_manager.stop();
1034 self.action_manager = new openerp.web.ActionManager(self);
1035 self.action_manager.appendTo($("#oe_app"));
1036 self.bind_hashchange();
1039 do_reload: function() {
1040 return $.when(this.session.session_init(),this.menu.do_reload());
1042 do_notify: function() {
1043 var n = this.notification;
1044 n.notify.apply(n, arguments);
1046 do_warn: function() {
1047 var n = this.notification;
1048 n.warn.apply(n, arguments);
1050 on_logout: function() {
1051 this.session.session_logout();
1052 this.login.on_login_invalid();
1053 this.header.do_update();
1054 $(window).unbind('hashchange', this.on_hashchange);
1055 this.do_push_state({});
1056 if(this.action_manager)
1057 this.action_manager.stop();
1058 this.action_manager = null;
1060 bind_hashchange: function() {
1061 $(window).bind('hashchange', this.on_hashchange);
1063 var state = $.bbq.getState(true);
1064 if (! _.isEmpty(state)) {
1065 $(window).trigger('hashchange');
1067 this.action_manager.do_action({type: 'ir.actions.client', tag: 'default_home'});
1070 on_hashchange: function(event) {
1071 var state = event.getState(true);
1072 if (!_.isEqual(this._current_state, state)) {
1073 this.action_manager.do_load_state(state);
1075 this._current_state = state;
1077 do_push_state: function(state) {
1078 var url = '#' + $.param(state);
1079 this._current_state = _.clone(state);
1080 $.bbq.pushState(url);
1082 on_menu_action: function(action) {
1083 this.action_manager.do_action(action);
1085 do_action: function(action) {
1087 // TODO replace by client action menuclick
1088 if(action.type === "ir.ui.menu") {
1089 this.do_reload().then(function () {
1090 self.menu.on_menu_click(null, action.menu_id);
1096 openerp.web.EmbeddedClient = openerp.web.Widget.extend({
1097 template: 'EmptyComponent',
1098 init: function(action_id, options) {
1100 // TODO take the xmlid of a action instead of its id
1101 this.action_id = action_id;
1102 this.options = options || {};
1103 this.am = new openerp.web.ActionManager(this);
1108 this.am.appendTo(this.$element.addClass('openerp'));
1109 return this.rpc("/web/action/load", { action_id: this.action_id }, function(result) {
1110 var action = result.result;
1111 action.flags = _.extend({
1112 //views_switcher : false,
1113 search_view : false,
1114 action_buttons : false,
1117 }, self.options, action.flags || {});
1119 self.am.do_action(action);
1125 openerp.web.embed = function (origin, dbname, login, key, action, options) {
1126 var currentScript = document.currentScript;
1127 if (!currentScript) {
1128 var sc = document.getElementsByTagName('script');
1129 currentScript = sc[sc.length-1];
1131 openerp.connection.bind(origin).then(function () {
1132 openerp.connection.session_authenticate(dbname, login, key).then(function () {
1133 var client = new session.web.EmbeddedClient(action_id, options);
1134 client.insertAfter(currentScript);
1141 // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: