1 /*---------------------------------------------------------
3 *---------------------------------------------------------*/
5 openerp.base.chrome = function(openerp) {
7 openerp.base.callback = function(obj, method) {
8 var callback = function() {
9 var args = Array.prototype.slice.call(arguments);
11 for(var i = 0; i < callback.callback_chain.length; i++) {
12 var c = callback.callback_chain[i];
14 callback.callback_chain.splice(i, 1);
17 r = c.callback.apply(c.self, c.args.concat(args));
18 // TODO special value to stop the chain
19 // openerp.base.callback_stop
23 callback.callback_chain = [];
24 callback.add = function(f) {
25 if(typeof(f) == 'function') {
26 f = { callback: f, args: Array.prototype.slice.call(arguments, 1) };
28 f.self = f.self || null;
29 f.args = f.args || [];
30 f.unique = !!f.unique;
31 if(f.position == 'last') {
32 callback.callback_chain.push(f);
34 callback.callback_chain.unshift(f);
38 callback.add_first = function(f) {
39 return callback.add.apply(null,arguments);
41 callback.add_last = function(f) {
44 args: Array.prototype.slice.call(arguments, 1),
52 args:Array.prototype.slice.call(arguments, 2)
57 * Base error for lookup failure
61 openerp.base.NotFound = Class.extend( /** @lends openerp.base.NotFound# */ {
63 openerp.base.KeyNotFound = openerp.base.NotFound.extend( /** @lends openerp.base.KeyNotFound# */ {
65 * Thrown when a key could not be found in a mapping
68 * @extends openerp.base.NotFound
69 * @param {String} key the key which could not be found
71 init: function (key) {
74 toString: function () {
75 return "The key " + this.key + " was not found";
78 openerp.base.ObjectNotFound = openerp.base.NotFound.extend( /** @lends openerp.base.ObjectNotFound# */ {
80 * Thrown when an object path does not designate a valid class or object
81 * in the openerp hierarchy.
84 * @extends openerp.base.NotFound
85 * @param {String} path the invalid object path
87 init: function (path) {
90 toString: function () {
91 return "Could not find any object of path " + this.path;
94 openerp.base.Registry = Class.extend( /** @lends openerp.base.Registry# */ {
96 * Stores a mapping of arbitrary key (strings) to object paths (as strings
99 * Resolves those paths at query time in order to always fetch the correct
100 * object, even if those objects have been overloaded/replaced after the
101 * registry was created.
103 * An object path is simply a dotted name from the openerp root to the
104 * object pointed to (e.g. ``"openerp.base.Session"`` for an OpenERP
108 * @param {Object} mapping a mapping of keys to object-paths
110 init: function (mapping) {
111 this.map = mapping || {};
114 * Retrieves the object matching the provided key string.
116 * @param {String} key the key to fetch the object for
117 * @returns {Class} the stored class, to initialize
119 * @throws {openerp.base.KeyNotFound} if the object was not in the mapping
120 * @throws {openerp.base.ObjectNotFound} if the object path was invalid
122 get_object: function (key) {
123 var path_string = this.map[key];
124 if (path_string === undefined) {
125 throw new openerp.base.KeyNotFound(key);
128 var object_match = openerp;
129 var path = path_string.split('.');
130 // ignore first section
131 for(var i=1; i<path.length; ++i) {
132 object_match = object_match[path[i]];
134 if (object_match === undefined) {
135 throw new openerp.base.ObjectNotFound(path_string);
141 * Tries a number of keys, and returns the first object matching one of
144 * @param {Array} keys a sequence of keys to fetch the object for
145 * @returns {Class} the first class found matching an object
147 * @throws {openerp.base.KeyNotFound} if none of the keys was in the mapping
148 * @trows {openerp.base.ObjectNotFound} if a found object path was invalid
150 get_any: function (keys) {
151 for (var i=0; i<keys.length; ++i) {
153 return this.get_object(keys[i]);
155 if (e instanceof openerp.base.KeyNotFound) {
161 throw new openerp.base.KeyNotFound(keys.join(','));
164 * Adds a new key and value to the registry.
166 * This method can be chained.
168 * @param {String} key
169 * @param {String} object_path fully qualified dotted object path
170 * @returns {openerp.base.Registry} itself
172 add: function (key, object_path) {
173 this.map[key] = object_path;
177 * Creates and returns a copy of the current mapping, with the provided
178 * mapping argument added in (replacing existing keys if needed)
180 * @param {Object} [mapping={}] a mapping of keys to object-paths
182 clone: function (mapping) {
183 return new openerp.base.Registry(
184 _.extend({}, this.map, mapping || {}));
188 openerp.base.BasicController = Class.extend( /** @lends openerp.base.BasicController# */{
190 * rpc operations, event binding and callback calling should be done in
191 * start() instead of init so that event can be hooked in between.
195 init: function(element_id) {
196 this.element_id = element_id;
197 this.$element = $('#' + element_id);
199 openerp.screen[element_id] = this;
202 // Transform on_* method into openerp.base.callbacks
203 for (var name in this) {
204 if(typeof(this[name]) == "function") {
205 this[name].debug_name = name;
206 // bind ALL function to this not only on_and _do ?
207 if((/^on_|^do_/).test(name)) {
208 this[name] = openerp.base.callback(this, this[name]);
215 * event binding, rpc and callback calling required to initialize the
216 * object can happen here
218 * Returns a promise object letting callers (subclasses and direct callers)
219 * know when this component is done starting
221 * @returns {jQuery.Deferred}
224 // returns an already fulfilled promise. Maybe we could return nothing?
225 // $.when can take non-deferred and in that case it simply considers
226 // them all as fulfilled promises.
227 // But in thise case we *have* to ensure callers use $.when and don't
228 // try to call deferred methods on this return value.
229 return $.Deferred().done().promise();
234 var args = Array.prototype.slice.call(arguments);
235 var caller = arguments.callee.caller;
236 // TODO add support for line number using
237 // https://github.com/emwendelin/javascript-stacktrace/blob/master/stacktrace.js
238 // args.unshift("" + caller.debug_name);
239 this.on_log.apply(this,args);
242 if(window.openerp.debug || (window.location.search.indexOf('?debug') !== -1)) {
246 console.log(arguments);
250 var a = Array.prototype.slice.call(arguments, 0);
251 for(var i = 0; i < a.length; i++) {
252 var v = a[i]==null ? "null" : a[i].toString();
254 notify = v.match(/^not/);
255 body = v.match(/^bod/);
258 $('<pre></pre>').text(v).appendTo($('body'));
260 if(notify && this.notification) {
261 this.notification.notify("Logging:",v);
270 * Generates an inherited class that replaces all the methods by null methods (methods
271 * that does nothing and always return undefined).
273 * @param {Class} claz
274 * @param {dict} add Additional functions to override.
277 openerp.base.generate_null_object_class = function(claz, add) {
279 var copy_proto = function(prototype) {
280 for (var name in prototype) {
281 if(typeof prototype[name] == "function") {
282 newer[name] = function() {};
285 if (prototype.prototype)
286 copy_proto(prototype.prototype);
288 copy_proto(claz.prototype);
289 newer.init = openerp.base.BasicController.prototype.init;
290 var tmpclass = claz.extend(newer);
291 return tmpclass.extend(add || {});
294 openerp.base.Notification = openerp.base.BasicController.extend({
295 init: function(element_id) {
296 this._super(element_id);
297 this.$element.notify({
302 notify: function(title, text) {
303 this.$element.notify('create', {
308 warn: function(title, text) {
309 this.$element.notify('create', 'oe_notification_alert', {
316 openerp.base.Session = openerp.base.BasicController.extend( /** @lends openerp.base.Session# */{
319 * @extends openerp.base.BasicController
320 * @param element_id to use for exception reporting
324 init: function(element_id, server, port) {
325 this._super(element_id);
326 this.server = (server == undefined) ? location.hostname : server;
327 this.port = (port == undefined) ? location.port : port;
328 this.rpc_mode = (server == location.hostname) ? "ajax" : "jsonp";
334 this.session_id = false;
335 this.module_list = [];
336 this.module_loaded = {"base": true};
340 this.session_restore();
343 * Executes an RPC call, registering the provided callbacks.
345 * Registers a default error callback if none is provided, and handles
346 * setting the correct session id and session context in the parameter
349 * @param {String} url RPC endpoint
350 * @param {Object} params call parameters
351 * @param {Function} success_callback function to execute on RPC call success
352 * @param {Function} error_callback function to execute on RPC call failure
354 * @returns {jQuery.Deferred} jquery-provided ajax deferred
356 rpc: function(url, params, success_callback, error_callback) {
358 // Construct a JSON-RPC2 request, method is currently unused
359 params.session_id = this.session_id;
361 // Call using the rpc_mode
362 var deferred = $.Deferred();
368 }).then(function () {deferred.resolve.apply(deferred, arguments);},
369 function(error) {deferred.reject(error, $.Event());});
370 return deferred.fail(function() {
371 deferred.fail(function(error, event) {
372 if (!event.isDefaultPrevented()) {
373 self.on_rpc_error(error, event);
376 }).then(success_callback, error_callback).promise();
381 * @returns {jQuery.Deferred} ajax-based deferred object
383 rpc_ajax: function(url, payload) {
385 this.on_rpc_request();
386 // url can be an $.ajax option object
387 if (_.isString(url)) {
392 var ajax = _.extend({
396 contentType: 'application/json',
397 data: JSON.stringify(payload),
400 var deferred = $.Deferred();
401 $.ajax(ajax).done(function(response, textStatus, jqXHR) {
402 self.on_rpc_response();
403 if (response.error) {
404 if (response.error.data.type == "session_invalid") {
406 self.on_session_invalid(function() {
407 self.rpc(url, payload.params,
408 function() {deferred.resolve.apply(deferred, arguments);},
409 function(error, event) {event.preventDefault();
410 deferred.reject.apply(deferred, arguments);});
413 deferred.reject(response.error);
416 deferred.resolve(response["result"], textStatus, jqXHR);
418 }).fail(function(jqXHR, textStatus, errorThrown) {
419 self.on_rpc_response();
422 message: "XmlHttpRequestError " + errorThrown,
423 data: {type: "xhr"+textStatus, debug: jqXHR.responseText, objects: [jqXHR, errorThrown] }
425 deferred.reject(error);
427 return deferred.promise();
429 on_rpc_request: function() {
431 on_rpc_response: function() {
433 on_rpc_error: function(error) {
436 * The session is validated either by login or by restoration of a previous session
438 on_session_valid: function() {
439 if(!openerp._modules_loaded)
442 on_session_invalid: function(contination) {
444 session_is_valid: function() {
447 session_login: function(db, login, password, success_callback) {
451 this.password = password;
452 var params = { db: this.db, login: this.login, password: this.password };
453 this.rpc("/base/session/login", params, function(result) {
454 self.session_id = result.session_id;
455 self.uid = result.uid;
457 self.on_session_valid();
458 if (success_callback)
462 session_logout: function() {
466 * Reloads uid and session_id from local storage, if they exist
468 session_restore: function () {
469 this.uid = this.get_cookie('uid');
470 this.session_id = this.get_cookie('session_id');
471 // we should do an rpc to confirm that this session_id is valid and if it is retrieve the information about db and login
472 // then call on_session_valid
473 this.on_session_valid();
476 * Saves the session id and uid locally
478 session_save: function () {
479 this.set_cookie('uid', this.uid);
480 this.set_cookie('session_id', this.session_id);
483 this.uid = this.get_cookie('uid');
484 this.session_id = this.get_cookie('session_id');
485 this.set_cookie('uid', '');
486 this.set_cookie('session_id', '');
487 this.on_session_invalid(function() {});
490 * Fetches a cookie stored by an openerp session
493 * @param name the cookie's name
495 get_cookie: function (name) {
496 var nameEQ = this.element_id + '|' + name + '=';
497 var cookies = document.cookie.split(';');
498 for(var i=0; i<cookies.length; ++i) {
499 var cookie = cookies[i].replace(/^\s*/, '');
500 if(cookie.indexOf(nameEQ) === 0) {
501 return decodeURIComponent(cookie.substring(nameEQ.length));
507 * Create a new cookie with the provided name and value
510 * @param name the cookie's name
511 * @param value the cookie's value
512 * @param ttl the cookie's time to live, 1 year by default, set to -1 to delete
514 set_cookie: function (name, value, ttl) {
515 ttl = ttl || 24*60*60*365;
517 this.element_id + '|' + name + '=' + encodeURIComponent(value),
519 'expires=' + new Date(new Date().getTime() + ttl*1000).toGMTString()
523 * Load additional web addons of that instance and init them
525 load_modules: function() {
527 this.rpc('/base/session/modules', {}, function(result) {
528 self.module_list = result['modules'];
529 var modules = self.module_list.join(',');
530 self.rpc('/base/session/csslist', {mods: modules}, self.do_load_css);
531 self.rpc('/base/session/jslist', {"mods": modules}, self.debug ? self.do_load_modules_debug : self.do_load_modules_prod);
532 openerp._modules_loaded = true;
535 do_load_css: function (result) {
536 _.each(result.files, function (file) {
537 $('head').append($('<link>', {
544 do_load_modules_debug: function(result) {
545 $LAB.setOptions({AlwaysPreserveOrder: true})
546 .script(result.files)
547 .wait(this.on_modules_loaded);
549 do_load_modules_prod: function() {
551 // /base/session/css?mod=mod1,mod2,mod3
552 // /base/session/js?mod=mod1,mod2,mod3
553 // use $.getScript(‘your_3rd_party-script.js’); ? i want to keep lineno !
555 on_modules_loaded: function() {
556 for(var j=0; j<this.module_list.length; j++) {
557 var mod = this.module_list[j];
558 if(this.module_loaded[mod])
562 if(openerp._openerp[mod] != undefined) {
563 openerp._openerp[mod](openerp);
564 this.module_loaded[mod] = true;
570 // A controller takes an already existing element
573 openerp.base.Controller = openerp.base.BasicController.extend( /** @lends openerp.base.Controller# */{
575 * Controller manifest used to declare standard controller attributes
577 controller_manifest: {
580 element_post_prefix: false
583 * Controller registry,
585 controller_registry: {
588 * Add a new child controller
590 controller_get: function(key) {
591 return this.controller_registry[key];
592 // OR should build it ? setting parent correctly ?
593 // function construct(constructor, args) {
595 // return constructor.apply(this, args);
597 // F.prototype = constructor.prototype;
600 // var obj = this.controller_registry[key];
602 // return construct(obj, Array.prototype.slice.call(arguments, 1));
605 controller_new: function(key) {
607 // OR should contrustct it ? setting parent correctly ?
608 function construct(constructor, args) {
610 return constructor.apply(this, args);
612 F.prototype = constructor.prototype;
615 var obj = this.controller_registry[key];
617 // TODO Prepend parent
618 return construct(obj, Array.prototype.slice.call(arguments, 1));
623 * @extends openerp.base.BasicController
625 init: function(parent_or_session, element_id) {
626 this._super(element_id);
627 this.controller_parent = null;
628 this.controller_children = [];
629 if(parent_or_session) {
630 if(parent_or_session.session) {
631 this.parent = parent_or_session;
632 this.session = this.parent.session;
633 if(this.parent.children) {
634 this.parent.children.push(this);
637 // TODO remove Backward compatilbility
638 this.session = parent_or_session;
641 // Apply manifest options
642 if(this.controller_manifest) {
643 var register = this.controller_manifest.register;
644 // TODO accept a simple string
646 for(var i=0; i<register.length; i++) {
647 this.controller_registry[register[i]] = this;
650 // TODO if post prefix
651 //this.element_id = _.uniqueId(_.toArray(arguments).join('_'));
655 * Performs a JSON-RPC call
657 * @param {String} url endpoint url
658 * @param {Object} data RPC parameters
659 * @param {Function} success RPC call success callback
660 * @param {Function} error RPC call error callback
661 * @returns {jQuery.Deferred} deferred object for the RPC call
663 rpc: function(url, data, success, error) {
664 // TODO: support additional arguments ?
665 return this.session.rpc(url, data, success, error);
669 // A widget is a controller that doesnt take an element_id
670 // it render its own html that you should insert into the dom
671 // and bind it a start()
674 // render() and insert it place it where you want
676 openerp.base.BaseWidget = openerp.base.Controller.extend({
678 * The name of the QWeb template that will be used for rendering. Must be
679 * redefined in subclasses or the render() method can not be used.
685 * The prefix used to generate an id automatically. Should be redefined in
686 * subclasses. If it is not defined, a default identifier will be used.
690 identifier_prefix: 'generic-identifier',
692 * Base class for widgets. Handle rendering (based on a QWeb template),
693 * identifier generation, parenting and destruction of the widget.
694 * Also initialize the identifier.
697 * @params {openerp.base.search.BaseWidget} parent The parent widget.
699 init: function (parent, session) {
700 this._super(session);
703 this.set_parent(parent);
704 this.make_id(this.identifier_prefix);
707 * Sets and returns a globally unique identifier for the widget.
709 * If a prefix is appended, the identifier will be appended to it.
711 * @params sections prefix sections, empty/falsy sections will be removed
713 make_id: function () {
714 this.element_id = _.uniqueId(_.toArray(arguments).join('_'));
715 return this.element_id;
718 * "Starts" the widgets. Called at the end of the rendering, this allows
719 * to get a jQuery object referring to the DOM ($element attribute).
723 var tmp = document.getElementById(this.element_id);
724 this.$element = tmp ? $(tmp) : null;
727 * "Stops" the widgets. Called when the view destroys itself, this
728 * lets the widgets clean up after themselves.
731 var tmp_children = this.children;
733 _.each(tmp_children, function(x) {
736 if(this.$element != null) {
737 this.$element.remove();
739 this.set_parent(null);
743 * Set the parent of this component, also un-register the previous parent
746 * @param {openerp.base.BaseWidget} parent The new parent.
748 set_parent: function(parent) {
750 this.parent.children = _.without(this.parent.children, this);
752 this.parent = parent;
754 parent.children.push(this);
758 * Render the widget. This.template must be defined.
759 * The content of the current object is passed as context to the template.
761 * @param {object} additional Additional context arguments to pass to the template.
763 render: function (additional) {
764 return QWeb.render(this.template, _.extend({}, this, additional != null ? additional : {}));
768 openerp.base.Dialog = openerp.base.BaseWidget.extend({
770 identifier_prefix: 'dialog',
771 init: function (session, options) {
772 this._super(null, session);
784 for (var f in this) {
785 if (f.substr(0, 10) == 'on_button_') {
786 this.options.buttons[f.substr(10)] = this[f];
790 this.set_options(options);
793 set_options: function(options) {
794 options = options || {};
795 options.width = this.get_width(options.width || this.options.width);
796 options.min_width = this.get_width(options.min_width || this.options.min_width);
797 options.max_width = this.get_width(options.max_width || this.options.max_width);
798 options.height = this.get_height(options.height || this.options.height);
799 options.min_height = this.get_height(options.min_height || this.options.min_height);
800 options.max_height = this.get_height(options.max_height || this.options.max_width);
802 if (options.width !== 'auto') {
803 if (options.width > options.max_width) options.width = options.max_width;
804 if (options.width < options.min_width) options.width = options.min_width;
806 if (options.height !== 'auto') {
807 if (options.height > options.max_height) options.height = options.max_height;
808 if (options.height < options.min_height) options.height = options.min_height;
810 if (!options.title && this.dialog_title) {
811 options.title = this.dialog_title;
813 _.extend(this.options, options);
815 get_width: function(val) {
816 return this.get_size(val.toString(), $(window.top).width());
818 get_height: function(val) {
819 return this.get_size(val.toString(), $(window.top).height());
821 get_size: function(val, available_size) {
822 if (val === 'auto') {
824 } else if (val.slice(-1) == "%") {
825 return Math.round(available_size / 100 * parseInt(val.slice(0, -1), 10));
827 return parseInt(val, 10);
830 start: function (auto_open) {
831 this.$dialog = $('<div id="' + this.element_id + '"></div>').dialog(this.options);
832 if (auto_open !== false) {
837 open: function(options) {
838 // TODO fme: bind window on resize
840 this.$element.html(this.render());
842 this.set_options(options);
843 this.$dialog.dialog(this.options).dialog('open');
845 close: function(options) {
846 this.$dialog.dialog('close');
849 this.$dialog.dialog('destroy');
853 openerp.base.CrashManager = openerp.base.Dialog.extend({
854 identifier_prefix: 'dialog_crash',
855 init: function(session) {
856 this._super(session);
857 this.session.on_rpc_error.add(this.on_rpc_error);
859 on_button_Ok: function() {
862 on_rpc_error: function(error) {
864 if (error.data.fault_code) {
865 var split = error.data.fault_code.split('\n')[0].split(' -- ');
866 if (split.length > 1) {
867 error.type = split.shift();
868 error.data.fault_code = error.data.fault_code.substr(error.type.length + 4);
871 if (error.code === 200 && error.type) {
872 this.dialog_title = "OpenERP " + _.capitalize(error.type);
873 this.template = 'DialogWarning';
879 this.dialog_title = "OpenERP Error";
880 this.template = 'DialogTraceback';
889 openerp.base.Loading = openerp.base.Controller.extend({
890 controller_manifest: {
891 register: ["Loading"]
893 init: function(session, element_id) {
894 this._super(session, element_id);
896 this.session.on_rpc_request.add_first(this.on_rpc_event, 1);
897 this.session.on_rpc_response.add_last(this.on_rpc_event, -1);
899 on_rpc_event : function(increment) {
900 this.count += increment;
902 //this.$element.html(QWeb.render("Loading", {}));
903 this.$element.html("Loading ("+this.count+")");
904 this.$element.show();
906 this.$element.fadeOut();
911 openerp.base.Database = openerp.base.Controller.extend({
914 openerp.base.Login = openerp.base.Controller.extend({
915 init: function(session, element_id) {
916 this._super(session, element_id);
917 this.has_local_storage = typeof(localStorage) != 'undefined';
918 this.selected_db = null;
919 this.selected_login = null;
920 this.selected_password = null;
921 this.remember = false;
922 if (this.has_local_storage && localStorage.getItem('remember_creditentials') === 'true') {
923 this.remember = true;
924 this.selected_db = localStorage.getItem('last_db_login_success');
925 this.selected_login = localStorage.getItem('last_login_login_success');
926 this.selected_password = localStorage.getItem('last_password_login_success');
931 this.rpc("/base/session/get_databases_list", {}, function(result) {
932 self.db_list = result.db_list;
938 display: function() {
939 this.$element.html(QWeb.render("Login", this));
940 this.$element.find("form").submit(this.on_submit);
942 on_login_invalid: function() {
943 this.$element.closest(".openerp").addClass("login-mode");
945 on_login_valid: function() {
946 this.$element.closest(".openerp").removeClass("login-mode");
948 on_submit: function(ev) {
951 var $e = this.$element;
952 var db = $e.find("form [name=db]").val();
953 var login = $e.find("form input[name=login]").val();
954 var password = $e.find("form input[name=password]").val();
955 var remember = $e.find("form input[name=remember]").attr('checked');
957 // Should hide then call callback
958 this.session.session_login(db, login, password, function() {
959 if(self.session.session_is_valid()) {
960 if (self.has_local_storage) {
962 localStorage.setItem('remember_creditentials', 'true');
963 localStorage.setItem('last_db_login_success', db);
964 localStorage.setItem('last_login_login_success', login);
965 localStorage.setItem('last_password_login_success', password);
967 localStorage.setItem('remember_creditentials', '');
968 localStorage.setItem('last_db_login_success', '');
969 localStorage.setItem('last_login_login_success', '');
970 localStorage.setItem('last_password_login_success', '');
973 self.on_login_valid();
975 self.$element.addClass("login_invalid");
976 self.on_login_invalid();
980 do_ask_login: function(continuation) {
981 this.on_login_invalid();
983 .removeClass("login_invalid");
984 this.on_login_valid.add({
987 callback: continuation
990 on_logout: function() {
991 this.session.logout();
995 openerp.base.Header = openerp.base.Controller.extend({
996 init: function(session, element_id) {
997 this._super(session, element_id);
1002 do_update: function() {
1003 this.$element.html(QWeb.render("Header", this));
1004 this.$element.find(".logout").click(this.on_logout);
1006 on_logout: function() {}
1009 openerp.base.Menu = openerp.base.Controller.extend({
1010 init: function(session, element_id, secondary_menu_id) {
1011 this._super(session, element_id);
1012 this.secondary_menu_id = secondary_menu_id;
1013 this.$secondary_menu = $("#" + secondary_menu_id);
1017 this.rpc("/base/menu/load", {}, this.on_loaded);
1019 on_loaded: function(data) {
1021 this.$element.html(QWeb.render("Menu", this.data));
1022 for (var i = 0; i < this.data.data.children.length; i++) {
1023 var v = { menu : this.data.data.children[i] };
1024 this.$secondary_menu.append(QWeb.render("Menu.secondary", v));
1026 this.$secondary_menu.find("div.menu_accordion").accordion({
1031 this.$secondary_menu.find("div.submenu_accordion").accordion({
1039 this.$element.add(this.$secondary_menu).find("a").click(this.on_menu_click);
1041 on_menu_click: function(ev, id) {
1043 var $menu, $parent, $secondary;
1046 // We can manually activate a menu with it's id (for hash url mapping)
1047 $menu = this.$element.find('a[data-menu=' + id + ']');
1048 if (!$menu.length) {
1049 $menu = this.$secondary_menu.find('a[data-menu=' + id + ']');
1052 $menu = $(ev.currentTarget);
1053 id = $menu.data('menu');
1055 if (this.$secondary_menu.has($menu).length) {
1056 $secondary = $menu.parents('.menu_accordion');
1057 $parent = this.$element.find('a[data-menu=' + $secondary.data('menu-parent') + ']');
1060 $secondary = this.$secondary_menu.find('.menu_accordion[data-menu-parent=' + $menu.attr('data-menu') + ']');
1063 this.$secondary_menu.find('.menu_accordion').hide();
1064 // TODO: ui-accordion : collapse submenus and expand the good one
1068 this.rpc('/base/menu/action', {'menu_id': id},
1069 this.on_menu_action_loaded);
1072 $('.active', this.$element.add(this.$secondary_menu)).removeClass('active');
1073 $parent.addClass('active');
1074 $menu.addClass('active');
1075 $menu.parent('h4').addClass('active');
1077 return !$menu.is(".leaf");
1079 on_menu_action_loaded: function(data) {
1081 if (data.action.length) {
1082 var action = data.action[0][2];
1083 self.on_action(action);
1086 on_action: function(action) {
1090 openerp.base.Homepage = openerp.base.Controller.extend({
1093 openerp.base.Preferences = openerp.base.Controller.extend({
1096 openerp.base.ImportExport = openerp.base.Controller.extend({
1099 openerp.base.WebClient = openerp.base.Controller.extend({
1100 init: function(element_id) {
1102 this._super(null, element_id);
1104 QWeb.add_template("xml/base.xml");
1106 if(jQuery.param != undefined &&
1107 jQuery.deparam(jQuery.param.querystring()).kitten != undefined) {
1108 this.$element.addClass("kitten-mode-activated");
1110 this.$element.html(QWeb.render("Interface", params));
1112 this.session = new openerp.base.Session("oe_errors");
1113 this.loading = new openerp.base.Loading(this.session, "oe_loading");
1114 this.crashmanager = new openerp.base.CrashManager(this.session);
1115 this.crashmanager.start(false);
1117 // Do you autorize this ?
1118 openerp.base.Controller.prototype.notification = new openerp.base.Notification("oe_notification");
1120 this.header = new openerp.base.Header(this.session, "oe_header");
1121 this.login = new openerp.base.Login(this.session, "oe_login");
1122 this.header.on_logout.add(this.login.on_logout);
1124 this.session.on_session_invalid.add(this.login.do_ask_login);
1125 this.session.on_session_valid.add_last(this.header.do_update);
1126 this.session.on_session_valid.add_last(this.on_logged);
1128 this.menu = new openerp.base.Menu(this.session, "oe_menu", "oe_secondary_menu");
1129 this.menu.on_action.add(this.on_menu_action);
1132 this.session.start();
1133 this.header.start();
1136 this.notification.notify("OpenERP Client", "The openerp client has been initialized.");
1138 on_logged: function() {
1139 this.action_manager = new openerp.base.ActionManager(this.session, "oe_app");
1140 this.action_manager.start();
1142 // if using saved actions, load the action and give it to action manager
1143 var parameters = jQuery.deparam(jQuery.param.querystring());
1144 if(parameters["s_action"] != undefined) {
1145 var key = parseInt(parameters["s_action"]);
1147 this.rpc("/base/session/get_session_action", {key:key}, function(action) {
1148 self.action_manager.do_action(action);
1152 on_menu_action: function(action) {
1153 this.action_manager.do_action(action);
1155 do_about: function() {
1159 openerp.base.webclient = function(element_id) {
1160 // TODO Helper to start webclient rename it openerp.base.webclient
1161 var client = new openerp.base.WebClient(element_id);
1168 // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: