diff --git a/addons/base/static/src/js/base.js b/addons/base/static/src/js/base.js
index 8f9921ceeae..675476879cf 100644
--- a/addons/base/static/src/js/base.js
+++ b/addons/base/static/src/js/base.js
@@ -76,6 +76,10 @@
/** @lends openerp */
var openerp = this.openerp = {
+ /**
+ * Debug flag turns on logging
+ */
+ debug: true,
// element_ids registry linked to all controllers on the page
// TODO rename to elements, or keep gtk naming?
screen: {},
diff --git a/addons/base/static/src/js/chrome.js b/addons/base/static/src/js/chrome.js
index cdfa1f4d192..920973e640a 100644
--- a/addons/base/static/src/js/chrome.js
+++ b/addons/base/static/src/js/chrome.js
@@ -193,8 +193,6 @@ openerp.base.BasicController = Class.extend( /** @lends openerp.base.BasicContro
// try to call deferred methods on this return value.
return $.Deferred().done().promise();
},
- on_ready: function() {
- },
stop: function() {
},
log: function() {
@@ -206,20 +204,55 @@ openerp.base.BasicController = Class.extend( /** @lends openerp.base.BasicContro
this.on_log.apply(this,args);
},
on_log: function() {
- if(true || window.openerp.debug || (window.location.search.indexOf('?debug') !== -1)) {
+ if(window.openerp.debug || (window.location.search.indexOf('?debug') !== -1)) {
+ var notify = false;
+ var body = false;
if(window.console) {
console.log(arguments);
} else {
- $.each(arguments, function(i,v) {
- v = v==null ? "null" : v;
- $('
').text(v.toString()).appendTo($('body'));
- });
+ body = true;
+ }
+ var a = Array.prototype.slice.call(arguments, 0);
+ for(var i = 0; i < a.length; i++) {
+ var v = a[i]==null ? "null" : a[i].toString();
+ if(i==0) {
+ notify = v.match(/^not/);
+ body = v.match(/^bod/);
+ }
+ if(body) {
+ $('').text(v).appendTo($('body'));
+ }
+ if(notify && this.notification) {
+ this.notification.notify("Logging:",v);
+ }
}
}
}
});
+openerp.base.Notification = openerp.base.BasicController.extend({
+ init: function(element_id) {
+ this._super(element_id);
+ this.$element.notify({
+ speed: 500,
+ expires: 1500
+ });
+ },
+ notify: function(title, text) {
+ this.$element.notify('create', {
+ title: title,
+ text: text
+ });
+ },
+ warn: function(title, text) {
+ this.$element.notify('create', 'oe_notification_alert', {
+ title: title,
+ text: text
+ });
+ }
+});
+
openerp.base.Session = openerp.base.BasicController.extend( /** @lends openerp.base.Session# */{
/**
* @constructs
@@ -446,18 +479,89 @@ openerp.base.Session = openerp.base.BasicController.extend( /** @lends openerp.b
}
});
+// A controller takes an already existing element
+// new()
+// start()
openerp.base.Controller = openerp.base.BasicController.extend( /** @lends openerp.base.Controller# */{
+ /**
+ * Controller manifest used to declare standard controller attributes
+ */
+ controller_manifest: {
+ register: null,
+ template: "",
+ element_post_prefix: false,
+ },
+ /**
+ * Controller registry,
+ */
+ controller_registry: {
+ },
+ /**
+ * Add a new child controller
+ */
+ controller_get: function(key) {
+ return this.controller_registry[key];
+ // OR should contrustct it ? setting parent correctly ?
+ // function construct(constructor, args) {
+ // function F() {
+ // return constructor.apply(this, args);
+ // }
+ // F.prototype = constructor.prototype;
+ // return new F();
+ // }
+ // var obj = this.controller_registry[key];
+ // if(obj) {
+ // return construct(obj, Array.prototype.slice.call(arguments, 1));
+ // }
+ },
+ controller_new: function(key) {
+ var self;
+ // OR should contrustct it ? setting parent correctly ?
+ function construct(constructor, args) {
+ function F() {
+ return constructor.apply(this, args);
+ }
+ F.prototype = constructor.prototype;
+ return new F();
+ }
+ var obj = this.controller_registry[key];
+ if(obj) {
+ // TODO Prepend parent
+ return construct(obj, Array.prototype.slice.call(arguments, 1));
+ }
+ },
/**
* @constructs
* @extends openerp.base.BasicController
*/
- init: function(session, element_id) {
+ init: function(parent_or_session, element_id) {
this._super(element_id);
- this.session = session;
- },
- on_log: function() {
- if(this.session)
- this.session.log.apply(this.session,arguments);
+ this.controller_parent = null;
+ this.controller_children = [];
+ if(parent_or_session) {
+ if(parent_or_session.session) {
+ this.parent = parent_or_session;
+ this.session = this.parent.session;
+ if(this.parent.children) {
+ this.parent.children.push(this);
+ }
+ } else {
+ // TODO remove Backward compatilbility
+ this.session = parent_or_session;
+ }
+ }
+ // Apply manifest options
+ if(this.controller_manifest) {
+ var register = this.controller_manifest.register;
+ // TODO accept a simple string
+ if(register) {
+ for(var i=0; i";
- this.notification.alert("The following fields are invalid :", msg);
+ this.notification.warn("The following fields are invalid :", msg);
},
on_saved: function(r) {
if (!r.result) {
this.log("Record was not saved");
} else {
// Check response for exceptions, display error
- this.notification['default']("Record saved", "The record #" + this.datarecord.id + " has been saved.");
+ this.notification.notify("Record saved", "The record #" + this.datarecord.id + " has been saved.");
}
},
do_search: function (domains, contexts, groupbys) {
- this.notification['default']("Searching form");
+ this.notification.notify("Searching form");
},
on_action: function (action) {
- this.notification['default']('Executing action ' + action);
+ this.notification.notify('Executing action ' + action);
},
do_cancel: function () {
- this.notification['default']("Cancelling form");
+ this.notification.notify("Cancelling form");
}
});
@@ -720,7 +720,7 @@ openerp.base.form.FieldOne2ManyDatasSet = openerp.base.DataSetStatic.extend({
this._super(id, data, callback);
},
unlink: function() {
- this.notification['default']('Unlinking o2m ' + this.ids);
+ this.notification.notify('Unlinking o2m ' + this.ids);
}
});
diff --git a/addons/base/static/src/js/search.js b/addons/base/static/src/js/search.js
index ef10992d75f..21d1408f087 100644
--- a/addons/base/static/src/js/search.js
+++ b/addons/base/static/src/js/search.js
@@ -215,7 +215,7 @@ openerp.base.SearchView = openerp.base.Controller.extend({
* @param {Array} errors a never-empty array of error objects
*/
on_invalid: function (errors) {
- this.notification['default']("Invalid Search", "triggered from search view");
+ this.notification.notify("Invalid Search", "triggered from search view");
},
do_clear: function (e) {
if (e && e.preventDefault) { e.preventDefault(); }
diff --git a/addons/base/static/src/js/views.js b/addons/base/static/src/js/views.js
index 109ce4d3404..1e3851c218f 100644
--- a/addons/base/static/src/js/views.js
+++ b/addons/base/static/src/js/views.js
@@ -178,98 +178,6 @@ openerp.base.ViewManagerAction = openerp.base.ViewManager.extend({
}
});
-openerp.base.BaseWidget = openerp.base.Controller.extend({
- /**
- * The name of the QWeb template that will be used for rendering. Must be
- * redefined in subclasses or the render() method can not be used.
- *
- * @type string
- */
- template: null,
- /**
- * The prefix used to generate an id automatically. Should be redefined in
- * subclasses. If it is not defined, a default identifier will be used.
- *
- * @type string
- */
- identifier_prefix: 'generic-identifier',
- /**
- * Base class for widgets. Handle rendering (based on a QWeb template),
- * identifier generation, parenting and destruction of the widget.
- * Also initialize the identifier.
- *
- * @constructs
- * @params {openerp.base.search.BaseWidget} parent The parent widget.
- */
- init: function (parent, session) {
- this._super(session);
- this.children = [];
- this.parent = null;
- this.set_parent(parent);
- this.make_id(this.identifier_prefix);
- },
- /**
- * Sets and returns a globally unique identifier for the widget.
- *
- * If a prefix is appended, the identifier will be appended to it.
- *
- * @params sections prefix sections, empty/falsy sections will be removed
- */
- make_id: function () {
- this.element_id = _.uniqueId(_.toArray(arguments).join('_'));
- return this.element_id;
- },
- /**
- * "Starts" the widgets. Called at the end of the rendering, this allows
- * to get a jQuery object referring to the DOM ($element attribute).
- */
- start: function () {
- this._super();
- var tmp = document.getElementById(this.element_id);
- this.$element = tmp ? $(tmp) : null;
- },
- /**
- * "Stops" the widgets. Called when the view destroys itself, this
- * lets the widgets clean up after themselves.
- */
- stop: function () {
- var tmp_children = this.children;
- this.children = [];
- _.each(tmp_children, function(x) {
- x.stop();
- });
- if(this.$element != null) {
- this.$element.remove();
- }
- this.set_parent(null);
- this._super();
- },
- /**
- * Set the parent of this component, also un-register the previous parent
- * if there was one.
- *
- * @param {openerp.base.BaseWidget} parent The new parent.
- */
- set_parent: function(parent) {
- if(this.parent) {
- this.parent.children = _.without(this.parent.children, this);
- }
- this.parent = parent;
- if(this.parent) {
- parent.children.push(this);
- }
- },
- /**
- * Render the widget. This.template must be defined.
- * The content of the current object is passed as context to the template.
- *
- * @param {object} additional Additional context arguments to pass to the template.
- */
- render: function (additional) {
- return QWeb.render(this.template, _.extend({}, this, additional != null ? additional : {}));
- }
-});
-
openerp.base.Sidebar = openerp.base.BaseWidget.extend({
template: "ViewManager.sidebar",
init: function(parent, view_manager) {
@@ -296,8 +204,7 @@ openerp.base.Sidebar = openerp.base.BaseWidget.extend({
var i = $this.attr("data-i");
var j = $this.attr("data-j");
var action = self.sections[i].elements[j];
- (new openerp.base.ExternalActionManager(self.view_manager.session, null))
- .handle_action(action);
+ (new openerp.base.ExternalActionManager(self.view_manager.session, null)) .handle_action(action);
e.stopPropagation();
e.preventDefault();
});
@@ -317,12 +224,10 @@ openerp.base.ExternalActionManager = openerp.base.Controller.extend({
dialog.dialog({
title: action.name
});
- var viewmanager = new openerp.base.ViewManagerAction(this.session
- ,element_id, action, false);
+ var viewmanager = new openerp.base.ViewManagerAction(this.session ,element_id, action, false);
viewmanager.start();
} else if (action.target == "current") {
this.rpc("/base/session/save_session_action", {the_action:action}, function(key) {
- debugger;
var url = window.location.href;
//window.open();
});