1 /*---------------------------------------------------------
3 *---------------------------------------------------------*/
5 openerp.base.chrome = function(openerp) {
7 openerp.base.Session = openerp.base.Widget.extend( /** @lends openerp.base.Session# */{
10 * @param element_id to use for exception reporting
14 init: function(parent, element_id, server, port) {
15 this._super(parent, element_id);
16 this.server = (server == undefined) ? location.hostname : server;
17 this.port = (port == undefined) ? location.port : port;
18 this.rpc_mode = (server == location.hostname) ? "ajax" : "jsonp";
24 this.session_id = false;
25 this.module_list = [];
26 this.module_loaded = {"base": true};
30 this.session_restore();
33 * Executes an RPC call, registering the provided callbacks.
35 * Registers a default error callback if none is provided, and handles
36 * setting the correct session id and session context in the parameter
39 * @param {String} url RPC endpoint
40 * @param {Object} params call parameters
41 * @param {Function} success_callback function to execute on RPC call success
42 * @param {Function} error_callback function to execute on RPC call failure
43 * @returns {jQuery.Deferred} jquery-provided ajax deferred
45 rpc: function(url, params, success_callback, error_callback) {
47 // Construct a JSON-RPC2 request, method is currently unused
48 params.session_id = this.session_id;
50 // Call using the rpc_mode
51 var deferred = $.Deferred();
57 }).then(function () {deferred.resolve.apply(deferred, arguments);},
58 function(error) {deferred.reject(error, $.Event());});
59 return deferred.fail(function() {
60 deferred.fail(function(error, event) {
61 if (!event.isDefaultPrevented()) {
62 self.on_rpc_error(error, event);
65 }).then(success_callback, error_callback).promise();
70 * @returns {jQuery.Deferred} ajax-based deferred object
72 rpc_ajax: function(url, payload) {
74 this.on_rpc_request();
75 // url can be an $.ajax option object
76 if (_.isString(url)) {
85 contentType: 'application/json',
86 data: JSON.stringify(payload),
89 var deferred = $.Deferred();
90 $.ajax(ajax).done(function(response, textStatus, jqXHR) {
91 self.on_rpc_response();
92 if (!response.error) {
93 deferred.resolve(response["result"], textStatus, jqXHR);
96 if (response.error.data.type !== "session_invalid") {
97 deferred.reject(response.error);
101 self.on_session_invalid(function() {
102 self.rpc(url, payload.params,
104 deferred.resolve.apply(deferred, arguments);
106 function(error, event) {
107 event.preventDefault();
108 deferred.reject.apply(deferred, arguments);
111 }).fail(function(jqXHR, textStatus, errorThrown) {
112 self.on_rpc_response();
115 message: "XmlHttpRequestError " + errorThrown,
116 data: {type: "xhr"+textStatus, debug: jqXHR.responseText, objects: [jqXHR, errorThrown] }
118 deferred.reject(error);
120 return deferred.promise();
122 on_rpc_request: function() {
124 on_rpc_response: function() {
126 on_rpc_error: function(error) {
129 * The session is validated either by login or by restoration of a previous session
131 on_session_valid: function() {
132 if(!openerp._modules_loaded)
135 on_session_invalid: function(contination) {
137 session_is_valid: function() {
140 session_login: function(db, login, password, success_callback) {
144 this.password = password;
145 var params = { db: this.db, login: this.login, password: this.password };
146 this.rpc("/base/session/login", params, function(result) {
147 self.session_id = result.session_id;
148 self.uid = result.uid;
150 self.on_session_valid();
151 if (success_callback)
155 session_logout: function() {
159 * Reloads uid and session_id from local storage, if they exist
161 session_restore: function () {
162 this.uid = this.get_cookie('uid');
163 this.session_id = this.get_cookie('session_id');
164 this.db = this.get_cookie('db');
165 this.login = this.get_cookie('login');
166 // we should do an rpc to confirm that this session_id is valid and if it is retrieve the information about db and login
167 // then call on_session_valid
168 this.on_session_valid();
171 * Saves the session id and uid locally
173 session_save: function () {
174 this.set_cookie('uid', this.uid);
175 this.set_cookie('session_id', this.session_id);
176 this.set_cookie('db', this.db);
177 this.set_cookie('login', this.login);
181 delete this.session_id;
184 this.set_cookie('uid', '');
185 this.set_cookie('session_id', '');
186 this.set_cookie('db', '');
187 this.set_cookie('login', '');
188 this.on_session_invalid(function() {});
191 * Fetches a cookie stored by an openerp session
194 * @param name the cookie's name
196 get_cookie: function (name) {
197 var nameEQ = this.element_id + '|' + name + '=';
198 var cookies = document.cookie.split(';');
199 for(var i=0; i<cookies.length; ++i) {
200 var cookie = cookies[i].replace(/^\s*/, '');
201 if(cookie.indexOf(nameEQ) === 0) {
202 return JSON.parse(decodeURIComponent(cookie.substring(nameEQ.length)));
208 * Create a new cookie with the provided name and value
211 * @param name the cookie's name
212 * @param value the cookie's value
213 * @param ttl the cookie's time to live, 1 year by default, set to -1 to delete
215 set_cookie: function (name, value, ttl) {
216 ttl = ttl || 24*60*60*365;
218 this.element_id + '|' + name + '=' + encodeURIComponent(JSON.stringify(value)),
220 'expires=' + new Date(new Date().getTime() + ttl*1000).toGMTString()
224 * Load additional web addons of that instance and init them
226 load_modules: function() {
228 this.rpc('/base/session/modules', {}, function(result) {
229 self.module_list = result;
230 var modules = self.module_list.join(',');
231 if(self.debug || true) {
232 self.rpc('/base/webclient/csslist', {"mods": modules}, self.do_load_css);
233 self.rpc('/base/webclient/jslist', {"mods": modules}, self.do_load_js);
235 self.do_load_css(["/base/webclient/css?mods="+modules]);
236 self.do_load_js(["/base/webclient/js?mods="+modules]);
238 openerp._modules_loaded = true;
241 do_load_css: function (files) {
242 _.each(files, function (file) {
243 $('head').append($('<link>', {
250 do_load_js: function(files) {
252 if(files.length != 0) {
253 var file = files.shift();
254 var tag = document.createElement('script');
255 tag.type = 'text/javascript';
257 tag.onload = tag.onreadystatechange = function() {
258 if ( (tag.readyState && tag.readyState != "loaded" && tag.readyState != "complete") || tag.onload_done )
260 tag.onload_done = true;
261 self.do_load_js(files);
263 document.head.appendChild(tag);
265 this.on_modules_loaded();
268 on_modules_loaded: function() {
269 for(var j=0; j<this.module_list.length; j++) {
270 var mod = this.module_list[j];
271 if(this.module_loaded[mod])
275 if(openerp._openerp[mod] != undefined) {
276 openerp._openerp[mod](openerp);
277 this.module_loaded[mod] = true;
283 openerp.base.Notification = openerp.base.Widget.extend({
284 init: function(parent, element_id) {
285 this._super(parent, element_id);
286 this.$element.notify({
291 notify: function(title, text) {
292 this.$element.notify('create', {
297 warn: function(title, text) {
298 this.$element.notify('create', 'oe_notification_alert', {
305 openerp.base.Dialog = openerp.base.OldWidget.extend({
307 identifier_prefix: 'dialog',
308 init: function (parent, dialog_options) {
311 this.dialog_options = {
321 beforeClose: function () {
325 for (var f in this) {
326 if (f.substr(0, 10) == 'on_button_') {
327 this.dialog_options.buttons[f.substr(10)] = this[f];
330 if (dialog_options) {
331 this.set_options(dialog_options);
334 set_options: function(options) {
335 options = options || {};
336 options.width = this.get_width(options.width || this.dialog_options.width);
337 options.min_width = this.get_width(options.min_width || this.dialog_options.min_width);
338 options.max_width = this.get_width(options.max_width || this.dialog_options.max_width);
339 options.height = this.get_height(options.height || this.dialog_options.height);
340 options.min_height = this.get_height(options.min_height || this.dialog_options.min_height);
341 options.max_height = this.get_height(options.max_height || this.dialog_options.max_width);
343 if (options.width !== 'auto') {
344 if (options.width > options.max_width) options.width = options.max_width;
345 if (options.width < options.min_width) options.width = options.min_width;
347 if (options.height !== 'auto') {
348 if (options.height > options.max_height) options.height = options.max_height;
349 if (options.height < options.min_height) options.height = options.min_height;
351 if (!options.title && this.dialog_title) {
352 options.title = this.dialog_title;
354 _.extend(this.dialog_options, options);
356 get_width: function(val) {
357 return this.get_size(val.toString(), $(window.top).width());
359 get_height: function(val) {
360 return this.get_size(val.toString(), $(window.top).height());
362 get_size: function(val, available_size) {
363 if (val === 'auto') {
365 } else if (val.slice(-1) == "%") {
366 return Math.round(available_size / 100 * parseInt(val.slice(0, -1), 10));
368 return parseInt(val, 10);
371 start: function (auto_open) {
372 this.$dialog = $('<div id="' + this.element_id + '"></div>').dialog(this.dialog_options);
373 if (auto_open !== false) {
378 open: function(dialog_options) {
379 // TODO fme: bind window on resize
381 this.$element.html(this.render());
383 this.set_options(dialog_options);
384 this.$dialog.dialog(this.dialog_options).dialog('open');
387 // Closes the dialog but leave it in a state where it could be opened again.
388 this.$dialog.dialog('close');
390 on_close: function() {
395 this.$dialog.dialog('destroy');
399 openerp.base.CrashManager = openerp.base.Dialog.extend({
400 identifier_prefix: 'dialog_crash',
401 init: function(parent) {
403 this.session.on_rpc_error.add(this.on_rpc_error);
405 on_button_Ok: function() {
408 on_rpc_error: function(error) {
410 if (error.data.fault_code) {
411 var split = error.data.fault_code.split('\n')[0].split(' -- ');
412 if (split.length > 1) {
413 error.type = split.shift();
414 error.data.fault_code = error.data.fault_code.substr(error.type.length + 4);
417 if (error.code === 200 && error.type) {
418 this.dialog_title = "OpenERP " + _.capitalize(error.type);
419 this.template = 'DialogWarning';
425 this.dialog_title = "OpenERP Error";
426 this.template = 'DialogTraceback';
435 openerp.base.Loading = openerp.base.Widget.extend({
436 init: function(parent, element_id) {
437 this._super(parent, element_id);
439 this.session.on_rpc_request.add_first(this.on_rpc_event, 1);
440 this.session.on_rpc_response.add_last(this.on_rpc_event, -1);
442 on_rpc_event : function(increment) {
443 this.count += increment;
445 //this.$element.html(QWeb.render("Loading", {}));
446 this.$element.html("Loading ("+this.count+")");
447 this.$element.show();
449 this.$element.fadeOut();
454 openerp.base.Database = openerp.base.Widget.extend({
455 init: function(parent, element_id, option_id) {
456 this._super(parent, element_id);
457 this.$option_id = $('#' + option_id);
460 this.$element.html(QWeb.render("Database", this));
461 this.$element.closest(".openerp")
462 .removeClass("login-mode")
463 .addClass("database_block");
467 var fetch_db = this.rpc("/base/database/get_list", {}, function(result) {
468 self.db_list = result.db_list;
470 var fetch_langs = this.rpc("/base/session/get_lang_list", {}, function(result) {
472 self.display_error(result);
475 self.lang_list = result.lang_list;
477 $.when(fetch_db, fetch_langs).then(function () {self.do_create();});
479 this.$element.find('#db-create').click(this.do_create);
480 this.$element.find('#db-drop').click(this.do_drop);
481 this.$element.find('#db-backup').click(this.do_backup);
482 this.$element.find('#db-restore').click(this.do_restore);
483 this.$element.find('#db-change-password').click(this.do_change_password);
484 this.$element.find('#back-to-login').click(function() {
489 this.$option_id.empty();
492 .find('#db-create, #db-drop, #db-backup, #db-restore, #db-change-password, #back-to-login')
496 .addClass("login-mode")
497 .removeClass("database_block")
503 * Converts a .serializeArray() result into a dict. Does not bother folding
504 * multiple identical keys into an array, last key wins.
506 * @param {Array} array
508 to_object: function (array) {
510 _(array).each(function (record) {
511 result[record.name] = record.value;
516 * Waits until the new database is done creating, then unblocks the UI and
517 * logs the user in as admin
519 * @param {Number} db_creation_id identifier for the db-creation operation, used to fetch the current installation progress
520 * @param {Object} info info fields for this database creation
521 * @param {String} info.db name of the database being created
522 * @param {String} info.password super-admin password for the database
524 wait_for_newdb: function (db_creation_id, info) {
526 self.rpc('/base/database/progress', {
528 password: info.password
529 }, function (result) {
530 var progress = result[0];
531 // I'd display a progress bar, but turns out the progress status
532 // the server report kind-of blows goats: it's at 0 for ~75% of
533 // the installation, then jumps to 75%, then jumps down to either
534 // 0 or ~40%, then back up to 75%, then terminates. Let's keep that
535 // mess hidden behind a not-very-useful but not overly weird
538 setTimeout(function () {
539 self.wait_for_newdb(db_creation_id, info);
544 var admin = result[1][0];
545 setTimeout(function () {
547 self.widget_parent.do_login(
548 info.db, admin.login, admin.password);
554 * Displays an error dialog resulting from the various RPC communications
555 * failing over themselves
557 * @param {Object} error error description
558 * @param {String} error.title title of the error dialog
559 * @param {String} error.error message of the error dialog
561 display_error: function (error) {
562 return $('<div>').dialog({
567 $(this).dialog("close");
570 }).html(error.error);
572 do_create: function() {
574 self.$option_id.html(QWeb.render("CreateDB", self));
576 self.$option_id.find("form[name=create_db_form]").validate({
577 submitHandler: function (form) {
578 var fields = $(form).serializeArray();
580 self.rpc("/base/database/create", {'fields': fields}, function(result) {
583 self.display_error(result);
586 self.db_list.push(self.to_object(fields)['db_name']);
588 var form_obj = self.to_object(fields);
589 self.wait_for_newdb(result, {
590 password: form_obj['super_admin_pwd'],
591 db: form_obj['db_name']
598 do_drop: function() {
600 self.$option_id.html(QWeb.render("DropDB", self));
602 self.$option_id.find("form[name=drop_db_form]").validate({
603 submitHandler: function (form) {
605 fields = $form.serializeArray(),
606 $db_list = $form.find('select[name=drop_db]'),
609 if (!confirm("Do you really want to delete the database: " + db + " ?")) {
612 self.rpc("/base/database/drop", {'fields': fields}, function(result) {
614 self.display_error(result);
617 $db_list.find(':selected').remove();
618 self.db_list.splice(_.indexOf(self.db_list, db, true), 1);
619 self.notification.notify("Dropping database", "The database '" + db + "' has been dropped");
625 wait_for_file: function (token, cleanup) {
627 cookie_name = 'fileToken',
628 cookie_length = cookie_name.length;
629 this.backup_timer = setInterval(function () {
630 var cookies = document.cookie.split(';');
631 for(var i=0; i<cookies.length; ++i) {
632 var cookie = cookies[i].replace(/^\s*/, '');
633 if(!cookie.indexOf(cookie_name) === 0) { continue; }
634 var cookie_val = cookie.substring(cookie_length + 1);
635 if(parseInt(cookie_val, 10) !== token) { continue; }
638 clearInterval(self.backup_timer);
640 document.cookie = _.sprintf("%s=;expires=%s;path=/",
641 cookie_name, new Date().toGMTString());
643 if (cleanup) { cleanup(); }
647 do_backup: function() {
649 self.$option_id.html(QWeb.render("BackupDB", self));
651 self.$option_id.find("form[name=backup_db_form]").validate({
652 submitHandler: function (form) {
654 // need to detect when the file is done downloading (not used
655 // yet, but we'll need it to fix the UI e.g. with a throbber
656 // while dump is being generated), iframe load event only fires
657 // when the iframe content loads, so we need to go smarter:
658 // http://geekswithblogs.net/GruffCode/archive/2010/10/28/detecting-the-file-download-dialog-in-the-browser.aspx
659 var $target = $('#backup-target'),
660 token = new Date().getTime();
661 if (!$target.length) {
662 $target = $('<iframe id="backup-target" style="display: none;">')
663 .appendTo(document.body)
666 clearInterval(self.backup_timer);
667 var error = this.contentDocument.body
676 $(form).find('input[name=token]').val(token);
679 self.wait_for_file(token, function () {
686 do_restore: function() {
688 self.$option_id.html(QWeb.render("RestoreDB", self));
690 self.$option_id.find("form[name=restore_db_form]").validate({
691 submitHandler: function (form) {
694 url: '/base/database/restore',
697 success: function (body) {
698 // TODO: ui manipulations
699 // note: response objects don't work, but we have the
700 // HTTP body of the response~~
702 // If empty body, everything went fine
703 if (!body) { return; }
705 if (body.indexOf('403 Forbidden') !== -1) {
707 title: 'Access Denied',
708 error: 'Incorrect super-administrator password'
712 title: 'Restore Database',
713 error: 'Could not restore the database'
717 complete: function () {
725 do_change_password: function() {
727 self.$option_id.html(QWeb.render("Change_DB_Pwd", self));
729 self.$option_id.find("form[name=change_pwd_form]").validate({
731 old_pwd: "Please enter your previous password",
732 new_pwd: "Please enter your new password",
734 required: "Please confirm your new password",
735 equalTo: "The confirmation does not match the password"
738 submitHandler: function (form) {
739 self.rpc("/base/database/change_password", {
740 'fields': $(form).serializeArray()
741 }, function(result) {
743 self.display_error(result);
746 self.notification.notify("Changed Password", "Password has been changed successfully");
753 openerp.base.Login = openerp.base.Widget.extend({
754 remember_creditentials: true,
756 init: function(parent, element_id) {
757 this._super(parent, element_id);
758 this.has_local_storage = typeof(localStorage) != 'undefined';
759 this.selected_db = null;
760 this.selected_login = null;
762 if (this.has_local_storage && this.remember_creditentials) {
763 this.selected_db = localStorage.getItem('last_db_login_success');
764 this.selected_login = localStorage.getItem('last_login_login_success');
766 if (jQuery.deparam(jQuery.param.querystring()).debug != undefined) {
767 this.selected_db = this.selected_db || "trunk";
768 this.selected_login = this.selected_login || "admin";
769 this.selected_password = this.selected_password || "a";
774 this.rpc("/base/database/get_list", {}, function(result) {
775 self.db_list = result.db_list;
781 display: function() {
784 this.$element.html(QWeb.render("Login", this));
785 this.database = new openerp.base.Database(
786 this, "oe_database", "oe_db_options");
788 this.$element.find('#oe-db-config').click(function() {
789 self.database.start();
792 this.$element.find("form").submit(this.on_submit);
794 on_login_invalid: function() {
795 this.$element.closest(".openerp").addClass("login-mode");
797 on_login_valid: function() {
798 this.$element.closest(".openerp").removeClass("login-mode");
800 on_submit: function(ev) {
802 var $e = this.$element;
803 var db = $e.find("form [name=db]").val();
804 var login = $e.find("form input[name=login]").val();
805 var password = $e.find("form input[name=password]").val();
807 this.do_login(db, login, password);
810 * Performs actual login operation, and UI-related stuff
812 * @param {String} db database to log in
813 * @param {String} login user login
814 * @param {String} password user password
816 do_login: function (db, login, password) {
818 this.session.session_login(db, login, password, function() {
819 if(self.session.session_is_valid()) {
820 if (self.has_local_storage) {
821 if(self.remember_creditentials) {
822 localStorage.setItem('last_db_login_success', db);
823 localStorage.setItem('last_login_login_success', login);
825 localStorage.setItem('last_db_login_success', '');
826 localStorage.setItem('last_login_login_success', '');
829 self.on_login_valid();
831 self.$element.addClass("login_invalid");
832 self.on_login_invalid();
836 do_ask_login: function(continuation) {
837 this.on_login_invalid();
839 .removeClass("login_invalid");
840 this.on_login_valid.add({
843 callback: continuation
846 on_logout: function() {
847 this.session.logout();
851 openerp.base.Header = openerp.base.Widget.extend({
852 init: function(parent, element_id) {
853 this._super(parent, element_id);
858 do_update: function() {
859 this.$element.html(QWeb.render("Header", this));
860 this.$element.find(".logout").click(this.on_logout);
862 on_logout: function() {}
865 openerp.base.Menu = openerp.base.Widget.extend({
866 init: function(parent, element_id, secondary_menu_id) {
867 this._super(parent, element_id);
868 this.secondary_menu_id = secondary_menu_id;
869 this.$secondary_menu = $("#" + secondary_menu_id).hide();
873 this.rpc("/base/menu/load", {}, this.on_loaded);
875 on_loaded: function(data) {
877 this.$element.html(QWeb.render("Menu", this.data));
878 for (var i = 0; i < this.data.data.children.length; i++) {
879 var v = { menu : this.data.data.children[i] };
880 this.$secondary_menu.append(QWeb.render("Menu.secondary", v));
882 this.$secondary_menu.find("div.menu_accordion").accordion({
887 this.$secondary_menu.find("div.submenu_accordion").accordion({
895 this.$element.add(this.$secondary_menu).find("a").click(this.on_menu_click);
897 on_menu_click: function(ev, id) {
899 var $menu, $parent, $secondary;
902 // We can manually activate a menu with it's id (for hash url mapping)
903 $menu = this.$element.find('a[data-menu=' + id + ']');
905 $menu = this.$secondary_menu.find('a[data-menu=' + id + ']');
908 $menu = $(ev.currentTarget);
909 id = $menu.data('menu');
911 if (this.$secondary_menu.has($menu).length) {
912 $secondary = $menu.parents('.menu_accordion');
913 $parent = this.$element.find('a[data-menu=' + $secondary.data('menu-parent') + ']');
916 $secondary = this.$secondary_menu.find('.menu_accordion[data-menu-parent=' + $menu.attr('data-menu') + ']');
919 this.$secondary_menu.find('.menu_accordion').hide();
920 // TODO: ui-accordion : collapse submenus and expand the good one
924 this.rpc('/base/menu/action', {'menu_id': id},
925 this.on_menu_action_loaded);
928 $('.active', this.$element.add(this.$secondary_menu.show())).removeClass('active');
929 $parent.addClass('active');
930 $menu.addClass('active');
931 $menu.parent('h4').addClass('active');
933 return !$menu.is(".leaf");
935 on_menu_action_loaded: function(data) {
937 if (data.action.length) {
938 var action = data.action[0][2];
939 self.on_action(action);
942 on_action: function(action) {
946 openerp.base.Homepage = openerp.base.Widget.extend({
949 openerp.base.Preferences = openerp.base.Widget.extend({
952 openerp.base.ImportExport = openerp.base.Widget.extend({
955 openerp.base.WebClient = openerp.base.Widget.extend({
956 init: function(element_id) {
957 this._super(null, element_id);
959 QWeb.add_template("/base/static/src/xml/base.xml");
961 if(jQuery.param != undefined && jQuery.deparam(jQuery.param.querystring()).kitten != undefined) {
962 this.$element.addClass("kitten-mode-activated");
964 this.$element.html(QWeb.render("Interface", params));
966 this.session = new openerp.base.Session(this,"oe_errors");
967 this.loading = new openerp.base.Loading(this,"oe_loading");
968 this.crashmanager = new openerp.base.CrashManager(this);
969 this.crashmanager.start(false);
971 // Do you autorize this ? will be replaced by notify() in controller
972 openerp.base.Widget.prototype.notification = new openerp.base.Notification(this, "oe_notification");
974 this.header = new openerp.base.Header(this, "oe_header");
975 this.login = new openerp.base.Login(this, "oe_login");
976 this.header.on_logout.add(this.login.on_logout);
978 this.session.on_session_invalid.add(this.login.do_ask_login);
979 this.session.on_session_valid.add_last(this.header.do_update);
980 this.session.on_session_valid.add_last(this.on_logged);
982 this.menu = new openerp.base.Menu(this, "oe_menu", "oe_secondary_menu");
983 this.menu.on_action.add(this.on_menu_action);
987 this.session.start();
991 this.notification.notify("OpenERP Client", "The openerp client has been initialized.");
993 on_logged: function() {
994 this.action_manager = new openerp.base.ActionManager(this, "oe_app");
995 this.action_manager.start();
997 // if using saved actions, load the action and give it to action manager
998 var parameters = jQuery.deparam(jQuery.param.querystring());
999 if (parameters["s_action"] != undefined) {
1000 var key = parseInt(parameters["s_action"], 10);
1002 this.rpc("/base/session/get_session_action", {key:key}, function(action) {
1003 self.action_manager.do_action(action);
1005 } else if (openerp._modules_loaded) { // TODO: find better option than this
1006 this.load_url_state()
1008 this.session.on_modules_loaded.add({
1009 callback: $.proxy(this, 'load_url_state'),
1016 * Loads state from URL if any, or checks if there is a home action and
1017 * loads that, assuming we're at the index
1019 load_url_state: function () {
1021 // TODO: add actual loading if there is url state to unpack, test on window.location.hash
1024 if (!this.session.uid) { return; }
1025 var ds = new openerp.base.DataSetSearch(this, 'res.users');
1026 ds.read_ids([this.session.uid], ['action_id'], function (users) {
1027 var home_action = users[0].action_id;
1029 self.default_home();
1032 self.execute_home_action(home_action[0], ds);
1035 default_home: function () { },
1037 * Bundles the execution of the home action
1039 * @param {Number} action action id
1040 * @param {openerp.base.DataSet} dataset action executor
1042 execute_home_action: function (action, dataset) {
1044 this.rpc('/base/action/load', {
1046 context: dataset.get_context()
1048 var action = meh.result;
1049 action.context = _.extend(action.context || {}, {
1051 active_ids: [false],
1052 active_model: dataset.model
1054 self.action_manager.do_action(action);
1057 on_menu_action: function(action) {
1058 this.action_manager.do_action(action);
1060 do_about: function() {
1064 openerp.base.webclient = function(element_id) {
1065 // TODO Helper to start webclient rename it openerp.base.webclient
1066 var client = new openerp.base.WebClient(element_id);
1073 // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: