bzr revid: nicolas.vanhoren@openerp.com-20110718152954-1osrwsxmyij4wkun
This commit is contained in:
niv-openerp
2011-07-18 17:29:54 +02:00
11 changed files with 344 additions and 446 deletions
+1
View File
@@ -23,6 +23,7 @@
<script type="text/javascript" src="/base/static/lib/datejs/date-en-US.js"></script>
<script type="text/javascript" src="/base/static/lib/json/json2.js"></script>
<script type="text/javascript" src="/base/static/src/js/base.js"></script>
<script type="text/javascript" src="/base/static/src/js/controller.js"></script>
<script type="text/javascript" src="/base/static/src/js/dates.js"></script>
<script type="text/javascript" src="/base/static/src/js/chrome.js"></script>
<script type="text/javascript" src="/base/static/src/js/data.js"></script>
+1 -66
View File
@@ -1,69 +1,3 @@
/*---------------------------------------------------------
* John Resig Class, to be moved to openerp.base.Class
*---------------------------------------------------------*/
(function() {
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
// The base Class implementation (does nothing)
this.Class = function(){};
// Create a new Class that inherits from this class
Class.extend = function(prop) {
var _super = this.prototype;
// Instantiate a base class (but only create the instance,
// don't run the init constructor)
initializing = true;
var prototype = new this();
initializing = false;
// Copy the properties over onto the new prototype
for (var name in prop) {
// Check if we're overwriting an existing function
prototype[name] = typeof prop[name] == "function" &&
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
(function(name, fn){
return function() {
var tmp = this._super;
// Add a new ._super() method that is the same method
// but on the super-class
this._super = _super[name];
// The method only need to be bound temporarily, so we
// remove it when we're done executing
var ret = fn.apply(this, arguments);
this._super = tmp;
return ret;
};
})(name, prop[name]) :
prop[name];
}
// The dummy class constructor
function Class() {
// All construction is actually done in the init method
if ( !initializing && this.init ) {
var ret = this.init.apply(this, arguments);
if (ret) { return ret; }
}
return this;
}
// Populate our constructed prototype object
Class.prototype = prototype;
// Enforce the constructor to be what we expect
Class.constructor = Class;
// And make this class extendable
Class.extend = arguments.callee;
return Class;
};
})();
//---------------------------------------------------------
// OpenERP initialisation and black magic about the pool
//---------------------------------------------------------
@@ -125,6 +59,7 @@
/** @namespace */
openerp.base = function(instance) {
openerp.base.controller(instance);
openerp.base.dates(instance);
openerp.base.chrome(instance);
openerp.base.data(instance);
+44 -274
View File
@@ -4,61 +4,12 @@
openerp.base.chrome = function(openerp) {
openerp.base.callback = function(obj, method) {
var callback = function() {
var args = Array.prototype.slice.call(arguments);
var r;
for(var i = 0; i < callback.callback_chain.length; i++) {
var c = callback.callback_chain[i];
if(c.unique) {
callback.callback_chain.splice(i, 1);
i -= 1;
}
r = c.callback.apply(c.self, c.args.concat(args));
// TODO special value to stop the chain
// openerp.base.callback_stop
}
return r;
};
callback.callback_chain = [];
callback.add = function(f) {
if(typeof(f) == 'function') {
f = { callback: f, args: Array.prototype.slice.call(arguments, 1) };
}
f.self = f.self || null;
f.args = f.args || [];
f.unique = !!f.unique;
if(f.position == 'last') {
callback.callback_chain.push(f);
} else {
callback.callback_chain.unshift(f);
}
return callback;
};
callback.add_first = function(f) {
return callback.add.apply(null,arguments);
};
callback.add_last = function(f) {
return callback.add({
callback: f,
args: Array.prototype.slice.call(arguments, 1),
position: "last"
});
};
return callback.add({
callback: method,
self:obj,
args:Array.prototype.slice.call(arguments, 2)
});
};
/**
* Base error for lookup failure
*
* @class
*/
openerp.base.NotFound = Class.extend( /** @lends openerp.base.NotFound# */ {
openerp.base.NotFound = openerp.base.Class.extend( /** @lends openerp.base.NotFound# */ {
});
openerp.base.KeyNotFound = openerp.base.NotFound.extend( /** @lends openerp.base.KeyNotFound# */ {
/**
@@ -91,7 +42,7 @@ openerp.base.ObjectNotFound = openerp.base.NotFound.extend( /** @lends openerp.b
return "Could not find any object of path " + this.path;
}
});
openerp.base.Registry = Class.extend( /** @lends openerp.base.Registry# */ {
openerp.base.Registry = openerp.base.Class.extend( /** @lends openerp.base.Registry# */ {
/**
* Stores a mapping of arbitrary key (strings) to object paths (as strings
* as well).
@@ -185,87 +136,6 @@ openerp.base.Registry = Class.extend( /** @lends openerp.base.Registry# */ {
}
});
openerp.base.BasicController = Class.extend( /** @lends openerp.base.BasicController# */{
/**
* rpc operations, event binding and callback calling should be done in
* start() instead of init so that event can be hooked in between.
*
* @constructs
*/
init: function(element_id) {
this.element_id = element_id;
this.$element = $('#' + element_id);
if (element_id) {
openerp.screen[element_id] = this;
}
// Transform on_* method into openerp.base.callbacks
for (var name in this) {
if(typeof(this[name]) == "function") {
this[name].debug_name = name;
// bind ALL function to this not only on_and _do ?
if((/^on_|^do_/).test(name)) {
this[name] = openerp.base.callback(this, this[name]);
}
}
}
},
/**
* Controller start
* event binding, rpc and callback calling required to initialize the
* object can happen here
*
* Returns a promise object letting callers (subclasses and direct callers)
* know when this component is done starting
*
* @returns {jQuery.Deferred}
*/
start: function() {
// returns an already fulfilled promise. Maybe we could return nothing?
// $.when can take non-deferred and in that case it simply considers
// them all as fulfilled promises.
// But in thise case we *have* to ensure callers use $.when and don't
// try to call deferred methods on this return value.
return $.Deferred().done().promise();
},
stop: function() {
},
log: function() {
var args = Array.prototype.slice.call(arguments);
var caller = arguments.callee.caller;
// TODO add support for line number using
// https://github.com/emwendelin/javascript-stacktrace/blob/master/stacktrace.js
// args.unshift("" + caller.debug_name);
this.on_log.apply(this,args);
},
on_log: function() {
if(window.openerp.debug || (window.location.search.indexOf('?debug') !== -1)) {
var notify = false;
var body = false;
if(window.console) {
console.log(arguments);
} else {
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) {
$('<pre></pre>').text(v).appendTo($('body'));
}
if(notify && this.notification) {
this.notification.notify("Logging:",v);
}
}
}
}
});
/**
* Generates an inherited class that replaces all the methods by null methods (methods
* that does nothing and always return undefined).
@@ -292,8 +162,8 @@ openerp.base.generate_null_object_class = function(claz, add) {
};
openerp.base.Notification = openerp.base.BasicController.extend({
init: function(element_id) {
this._super(element_id);
init: function(parent, element_id) {
this._super(parent, element_id);
this.$element.notify({
speed: 500,
expires: 1500
@@ -313,6 +183,7 @@ openerp.base.Notification = openerp.base.BasicController.extend({
}
});
// Session should be a Class not Controller
openerp.base.Session = openerp.base.BasicController.extend( /** @lends openerp.base.Session# */{
/**
* @constructs
@@ -321,7 +192,7 @@ openerp.base.Session = openerp.base.BasicController.extend( /** @lends openerp.b
* @param server
* @param port
*/
init: function(element_id, server, port) {
init: function(parent, element_id, server, port) {
this._super(element_id);
this.server = (server == undefined) ? location.hostname : server;
this.port = (port == undefined) ? location.port : port;
@@ -570,88 +441,19 @@ openerp.base.Session = openerp.base.BasicController.extend( /** @lends openerp.b
}
});
// A controller takes an already existing element
// new()
// start()
/**
* OpenERP session aware controller
* a controller takes an already existing dom element and manage it
*/
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 build 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(parent_or_session, element_id) {
this._super(element_id);
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<register.length; i++) {
this.controller_registry[register[i]] = this;
}
}
// TODO if post prefix
//this.element_id = _.uniqueId(_.toArray(arguments).join('_'));
init: function(parent, element_id) {
this._super(parent, element_id);
if(this.parent && this.parent.session) {
this.session = this.parent.session;
}
},
/**
@@ -664,18 +466,16 @@ openerp.base.Controller = openerp.base.BasicController.extend( /** @lends opener
* @returns {jQuery.Deferred} deferred object for the RPC call
*/
rpc: function(url, data, success, error) {
// TODO: support additional arguments ?
return this.session.rpc(url, data, success, error);
}
});
// A widget is a controller that doesnt take an element_id
// it render its own html that you should insert into the dom
// and bind it a start()
//
// new()
// render() and insert it place it where you want
// start()
/**
* OpenERP session aware widget
* A widget is a controller that doesnt take an element_id
* it render its own html render() that you should insert into the dom
* and bind it a start()
*/
openerp.base.BaseWidget = openerp.base.Controller.extend({
/**
* The name of the QWeb template that will be used for rendering. Must be
@@ -699,11 +499,8 @@ openerp.base.BaseWidget = openerp.base.Controller.extend({
* @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);
init: function (parent) {
this._super(parent);
this.make_id(this.identifier_prefix);
},
/**
@@ -731,31 +528,9 @@ openerp.base.BaseWidget = openerp.base.Controller.extend({
* 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.
@@ -771,8 +546,8 @@ openerp.base.BaseWidget = openerp.base.Controller.extend({
openerp.base.Dialog = openerp.base.BaseWidget.extend({
dialog_title: "",
identifier_prefix: 'dialog',
init: function (session, options) {
this._super(null, session);
init: function (parent, options) {
this._super(parent);
this.options = {
modal: true,
width: 'auto',
@@ -856,8 +631,8 @@ openerp.base.Dialog = openerp.base.BaseWidget.extend({
openerp.base.CrashManager = openerp.base.Dialog.extend({
identifier_prefix: 'dialog_crash',
init: function(session) {
this._super(session);
init: function(parent) {
this._super(parent);
this.session.on_rpc_error.add(this.on_rpc_error);
},
on_button_Ok: function() {
@@ -891,11 +666,8 @@ openerp.base.CrashManager = openerp.base.Dialog.extend({
});
openerp.base.Loading = openerp.base.Controller.extend({
controller_manifest: {
register: ["Loading"]
},
init: function(session, element_id) {
this._super(session, element_id);
init: function(parent, element_id) {
this._super(parent, element_id);
this.count = 0;
this.session.on_rpc_request.add_first(this.on_rpc_event, 1);
this.session.on_rpc_response.add_last(this.on_rpc_event, -1);
@@ -917,8 +689,8 @@ openerp.base.Database = openerp.base.Controller.extend({
openerp.base.Login = openerp.base.Controller.extend({
remember_creditentials: true,
init: function(session, element_id) {
this._super(session, element_id);
init: function(parent, element_id) {
this._super(parent, element_id);
this.has_local_storage = typeof(localStorage) != 'undefined';
this.selected_db = null;
this.selected_login = null;
@@ -994,8 +766,8 @@ openerp.base.Login = openerp.base.Controller.extend({
});
openerp.base.Header = openerp.base.Controller.extend({
init: function(session, element_id) {
this._super(session, element_id);
init: function(parent, element_id) {
this._super(parent, element_id);
},
start: function() {
this.do_update();
@@ -1008,8 +780,8 @@ openerp.base.Header = openerp.base.Controller.extend({
});
openerp.base.Menu = openerp.base.Controller.extend({
init: function(session, element_id, secondary_menu_id) {
this._super(session, element_id);
init: function(parent, element_id, secondary_menu_id) {
this._super(parent, element_id);
this.secondary_menu_id = secondary_menu_id;
this.$secondary_menu = $("#" + secondary_menu_id);
this.menu = false;
@@ -1099,34 +871,32 @@ openerp.base.ImportExport = openerp.base.Controller.extend({
openerp.base.WebClient = openerp.base.Controller.extend({
init: function(element_id) {
var self = this;
this._super(null, element_id);
QWeb.add_template("xml/base.xml");
var params = {};
if(jQuery.param != undefined &&
jQuery.deparam(jQuery.param.querystring()).kitten != undefined) {
if(jQuery.param != undefined && jQuery.deparam(jQuery.param.querystring()).kitten != undefined) {
this.$element.addClass("kitten-mode-activated");
}
this.$element.html(QWeb.render("Interface", params));
this.session = new openerp.base.Session("oe_errors");
this.loading = new openerp.base.Loading(this.session, "oe_loading");
this.crashmanager = new openerp.base.CrashManager(this.session);
this.session = new openerp.base.Session(this,"oe_errors");
this.loading = new openerp.base.Loading(this,"oe_loading");
this.crashmanager = new openerp.base.CrashManager(this);
this.crashmanager.start(false);
// Do you autorize this ?
openerp.base.Controller.prototype.notification = new openerp.base.Notification("oe_notification");
openerp.base.Controller.prototype.notification = new openerp.base.Notification(this, "oe_notification");
this.header = new openerp.base.Header(this.session, "oe_header");
this.login = new openerp.base.Login(this.session, "oe_login");
this.header = new openerp.base.Header(this, "oe_header");
this.login = new openerp.base.Login(this, "oe_login");
this.header.on_logout.add(this.login.on_logout);
this.session.on_session_invalid.add(this.login.do_ask_login);
this.session.on_session_valid.add_last(this.header.do_update);
this.session.on_session_valid.add_last(this.on_logged);
this.menu = new openerp.base.Menu(this.session, "oe_menu", "oe_secondary_menu");
this.menu = new openerp.base.Menu(this, "oe_menu", "oe_secondary_menu");
this.menu.on_action.add(this.on_menu_action);
},
start: function() {
@@ -1137,9 +907,9 @@ openerp.base.WebClient = openerp.base.Controller.extend({
this.notification.notify("OpenERP Client", "The openerp client has been initialized.");
},
on_logged: function() {
this.action_manager = new openerp.base.ActionManager(this.session, "oe_app");
this.action_manager = new openerp.base.ActionManager(this, "oe_app");
this.action_manager.start();
// if using saved actions, load the action and give it to action manager
var parameters = jQuery.deparam(jQuery.param.querystring());
if(parameters["s_action"] != undefined) {
+216
View File
@@ -0,0 +1,216 @@
/*---------------------------------------------------------
* OpenERP controller framework
*--------------------------------------------------------*/
openerp.base.controller = function(instance) {
/**
* John Resig Class with factory improvement
*/
(function() {
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
// The base Class implementation (does nothing)
this.Class = function(){};
// Create a new Class that inherits from this class
Class.extend = function(prop) {
var _super = this.prototype;
// Instantiate a base class (but only create the instance,
// don't run the init constructor)
initializing = true;
var prototype = new this();
initializing = false;
// Copy the properties over onto the new prototype
for (var name in prop) {
// Check if we're overwriting an existing function
prototype[name] = typeof prop[name] == "function" &&
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
(function(name, fn){
return function() {
var tmp = this._super;
// Add a new ._super() method that is the same method
// but on the super-class
this._super = _super[name];
// The method only need to be bound temporarily, so we
// remove it when we're done executing
var ret = fn.apply(this, arguments);
this._super = tmp;
return ret;
};
})(name, prop[name]) :
prop[name];
}
// The dummy class constructor
function Class() {
// All construction is actually done in the init method
if ( !initializing && this.init ) {
var ret = this.init.apply(this, arguments);
if (ret) { return ret; }
}
return this;
}
// Populate our constructed prototype object
Class.prototype = prototype;
// Enforce the constructor to be what we expect
Class.constructor = Class;
// And make this class extendable
Class.extend = arguments.callee;
return Class;
};
})(instance.base);
// todo change john resig class to keep window clean
instance.base.Class = window.Class
instance.base.callback = function(obj, method) {
var callback = function() {
var args = Array.prototype.slice.call(arguments);
var r;
for(var i = 0; i < callback.callback_chain.length; i++) {
var c = callback.callback_chain[i];
if(c.unique) {
callback.callback_chain.splice(i, 1);
i -= 1;
}
r = c.callback.apply(c.self, c.args.concat(args));
// TODO special value to stop the chain
// openerp.base.callback_stop
}
return r;
};
callback.callback_chain = [];
callback.add = function(f) {
if(typeof(f) == 'function') {
f = { callback: f, args: Array.prototype.slice.call(arguments, 1) };
}
f.self = f.self || null;
f.args = f.args || [];
f.unique = !!f.unique;
if(f.position == 'last') {
callback.callback_chain.push(f);
} else {
callback.callback_chain.unshift(f);
}
return callback;
};
callback.add_first = function(f) {
return callback.add.apply(null,arguments);
};
callback.add_last = function(f) {
return callback.add({
callback: f,
args: Array.prototype.slice.call(arguments, 1),
position: "last"
});
};
return callback.add({
callback: method,
self:obj,
args:Array.prototype.slice.call(arguments, 2)
});
};
/**
* OpenERP Controller
*/
instance.base.BasicController = instance.base.Class.extend( /** @lends instance.base.BasicController# */{
/**
* rpc operations, event binding and callback calling should be done in
* start() instead of init so that event can be hooked in between.
*
* @constructs
*/
init: function(parent, element_id) {
this.element_id = element_id;
this.$element = $('#' + element_id);
if (element_id) {
instance.screen[element_id] = this;
}
// save the parent children relationship
this.controller_parent = null;
this.controller_children = [];
this.parent = parent;
if(this.parent && this.parent.children) {
this.parent.children.push(this);
}
// Transform on_* method into openerp.base.callbacks
for (var name in this) {
if(typeof(this[name]) == "function") {
this[name].debug_name = name;
// bind ALL function to this not only on_and _do ?
if((/^on_|^do_/).test(name)) {
this[name] = instance.base.callback(this, this[name]);
}
}
}
},
/**
* Controller start
* event binding, rpc and callback calling required to initialize the
* object can happen here
*
* Returns a promise object letting callers (subclasses and direct callers)
* know when this component is done starting
*
* @returns {jQuery.Deferred}
*/
start: function() {
// returns an already fulfilled promise. Maybe we could return nothing?
// $.when can take non-deferred and in that case it simply considers
// them all as fulfilled promises.
// But in thise case we *have* to ensure callers use $.when and don't
// try to call deferred methods on this return value.
return $.Deferred().done().promise();
},
stop: function() {
},
log: function() {
var args = Array.prototype.slice.call(arguments);
var caller = arguments.callee.caller;
// TODO add support for line number using
// https://github.com/emwendelin/javascript-stacktrace/blob/master/stacktrace.js
// args.unshift("" + caller.debug_name);
this.on_log.apply(this,args);
},
on_log: function() {
if(window.openerp.debug || (window.location.search.indexOf('?debug') !== -1)) {
var notify = false;
var body = false;
if(window.console) {
console.log(arguments);
} else {
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) {
$('<pre></pre>').text(v).appendTo($('body'));
}
if(notify && this.notification) {
this.notification.notify("Logging:",v);
}
}
}
}
});
};
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
+18 -28
View File
@@ -39,18 +39,16 @@ openerp.base.DataGroup = openerp.base.Controller.extend( /** @lends openerp.bas
* @param {Array} group_by sequence of fields by which to group
* @param {Number} [level=0] nesting level of the group
*/
init: function(session, model, domain, context, group_by, level) {
init: function(parent, model, domain, context, group_by, level) {
this._super(parent, null);
if (group_by) {
if (group_by.length || context['group_by_no_leaf']) {
return new openerp.base.ContainerDataGroup(
session, model, domain, context, group_by, level);
return new openerp.base.ContainerDataGroup( this, model, domain, context, group_by, level);
} else {
return new openerp.base.GrouplessDataGroup(
session, model, domain, context, level);
return new openerp.base.GrouplessDataGroup( this, model, domain, context, level);
}
}
this._super(session, null);
this.model = model;
this.context = context;
this.domain = domain;
@@ -59,8 +57,7 @@ openerp.base.DataGroup = openerp.base.Controller.extend( /** @lends openerp.bas
},
cls: 'DataGroup'
});
openerp.base.ContainerDataGroup = openerp.base.DataGroup.extend(
/** @lends openerp.base.ContainerDataGroup# */ {
openerp.base.ContainerDataGroup = openerp.base.DataGroup.extend( /** @lends openerp.base.ContainerDataGroup# */ {
/**
*
* @constructs
@@ -73,8 +70,8 @@ openerp.base.ContainerDataGroup = openerp.base.DataGroup.extend(
* @param group_by
* @param level
*/
init: function (session, model, domain, context, group_by, level) {
this._super(session, model, domain, context, null, level);
init: function (parent, model, domain, context, group_by, level) {
this._super(parent, model, domain, context, null, level);
this.group_by = group_by;
},
@@ -197,8 +194,7 @@ openerp.base.ContainerDataGroup = openerp.base.DataGroup.extend(
});
}
});
openerp.base.GrouplessDataGroup = openerp.base.DataGroup.extend(
/** @lends openerp.base.GrouplessDataGroup# */ {
openerp.base.GrouplessDataGroup = openerp.base.DataGroup.extend( /** @lends openerp.base.GrouplessDataGroup# */ {
/**
*
* @constructs
@@ -210,18 +206,16 @@ openerp.base.GrouplessDataGroup = openerp.base.DataGroup.extend(
* @param context
* @param level
*/
init: function (session, model, domain, context, level) {
this._super(session, model, domain, context, null, level);
init: function (parent, model, domain, context, level) {
this._super(parent, model, domain, context, null, level);
},
list: function (fields, ifGroups, ifRecords) {
ifRecords(_.extend(
new openerp.base.DataSetSearch(this.session, this.model),
new openerp.base.DataSetSearch(this, this.model),
{domain: this.domain, context: this.context, _sort: this.sort}));
}
});
openerp.base.StaticDataGroup = openerp.base.GrouplessDataGroup.extend(
/** @lends openerp.base.StaticDataGroup# */ {
openerp.base.StaticDataGroup = openerp.base.GrouplessDataGroup.extend( /** @lends openerp.base.StaticDataGroup# */ {
/**
* A specialization of groupless data groups, relying on a single static
* dataset as its records provider.
@@ -249,8 +243,8 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base.
* @param {openerp.base.Session} session current OpenERP session
* @param {String} model the OpenERP model this dataset will manage
*/
init: function(session, model, context) {
this._super(session);
init: function(parent, model, context) {
this._super(parent);
this.model = model;
this.context = context || {};
this.index = null;
@@ -382,10 +376,9 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base.
return this.context;
}
});
openerp.base.DataSetStatic = openerp.base.DataSet.extend({
init: function(session, model, context, ids) {
this._super(session, model, context);
init: function(parent, model, context, ids) {
this._super(parent, model, context);
// all local records
this.ids = ids || [];
},
@@ -410,10 +403,9 @@ openerp.base.DataSetStatic = openerp.base.DataSet.extend({
this.set_ids(_.without.apply(null, [this.ids].concat(ids)));
}
});
openerp.base.DataSetSearch = openerp.base.DataSet.extend({
init: function(session, model, context, domain) {
this._super(session, model, context);
init: function(parent, model, context, domain) {
this._super(parent, model, context);
this.domain = domain || [];
this._sort = [];
this.offset = 0;
@@ -486,7 +478,6 @@ openerp.base.DataSetSearch = openerp.base.DataSet.extend({
}, error_callback);
}
});
openerp.base.BufferedDataSet = openerp.base.DataSetStatic.extend({
virtual_id_prefix: "one2many_v_id_",
virtual_id_regex: /one2many_v_id_.*/,
@@ -591,7 +582,6 @@ openerp.base.BufferedDataSet = openerp.base.DataSetStatic.extend({
return completion.promise();
}
});
openerp.base.ReadOnlyDataSetSearch = openerp.base.DataSetSearch.extend({
create: function(data, callback, error_callback) {
this.on_create(data);
+20 -24
View File
@@ -17,9 +17,9 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV
*
* @property {openerp.base.Registry} registry=openerp.base.form.widgets widgets registry for this form view instance
*/
init: function(view_manager, session, element_id, dataset, view_id, options) {
this._super(session, element_id);
this.view_manager = view_manager || new openerp.base.NullViewManager();
init: function(parent, element_id, dataset, view_id, options) {
this._super(parent, element_id);
this.view_manager = parent || new openerp.base.NullViewManager();
this.dataset = dataset;
this.model = dataset.model;
this.view_id = view_id;
@@ -413,7 +413,7 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV
} else {
// TODO fme: modify this so it doesn't try to load attachments when there is not sidebar
/*(new openerp.base.DataSetSearch(
this.session, 'ir.attachment', this.dataset.get_context(),
this, 'ir.attachment', this.dataset.get_context(),
[['res_model', '=', this.dataset.model],
['res_id', '=', this.datarecord.id],
['type', 'in', ['binary', 'url']]])).read_slice(
@@ -539,7 +539,7 @@ openerp.base.form.Widget = openerp.base.Controller.extend({
this.element_name = this.element_name || this.type;
this.element_id = [this.view.element_id, this.element_name, this.view.widgets_counter++].join("_");
this._super(this.view.session, this.element_id);
this._super(view, this.element_id);
this.view.widgets[this.element_id] = this;
this.children = node.children;
@@ -1387,7 +1387,7 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
var search_val = request.term;
var self = this;
var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, self.build_context());
var dataset = new openerp.base.DataSetStatic(this, this.field.relation, self.build_context());
dataset.name_search(search_val, self.build_domain(), 'ilike',
this.limit + 1, function(data) {
@@ -1429,7 +1429,7 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
},
_quick_create: function(name) {
var self = this;
var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, self.build_context());
var dataset = new openerp.base.DataSetStatic(this, this.field.relation, self.build_context());
dataset.name_create(name, function(data) {
self._change_int_ext_value(data);
}).fail(function(error, event) {
@@ -1441,7 +1441,7 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
// all search/create popup handling
_search_create_popup: function(view, ids, context) {
var self = this;
var pop = new openerp.base.form.SelectCreatePopup(null, self.view.session);
var pop = new openerp.base.form.SelectCreatePopup(this);
pop.select_element(self.field.relation,{
initial_ids: ids ? _.map(ids, function(x) {return x[0]}) : undefined,
initial_view: view,
@@ -1449,7 +1449,7 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
}, self.build_domain(),
new openerp.base.CompoundContext(self.build_context(), context || {}));
pop.on_select_elements.add(function(element_ids) {
var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, self.build_context());
var dataset = new openerp.base.DataSetStatic(this, this.field.relation, self.build_context());
dataset.name_get([element_ids[0]], function(data) {
self._change_int_ext_value(data[0]);
pop.stop();
@@ -1487,7 +1487,7 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
self._change_int_ext_value(rval);
};
if(typeof(value) === "number") {
var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, self.build_context());
var dataset = new openerp.base.DataSetStatic(this, this.field.relation, self.build_context());
dataset.name_get([value], function(data) {
real_set_value(data[0]);
}).fail(function() {self.tmp_value = undefined;});
@@ -1572,7 +1572,7 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
var self = this;
this.dataset = new openerp.base.form.One2ManyDataSet(this.session, this.field.relation);
this.dataset = new openerp.base.form.One2ManyDataSet(this, this.field.relation);
this.dataset.o2m = this;
this.dataset.parent_view = this.view;
this.dataset.on_change.add_last(function() {
@@ -1596,8 +1596,7 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
});
this.views = views;
this.viewmanager = new openerp.base.ViewManager(this.view.session,
this.element_id, this.dataset, views);
this.viewmanager = new openerp.base.ViewManager(this, this.element_id, this.dataset, views);
this.viewmanager.registry = openerp.base.views.clone({
list: 'openerp.base.form.One2ManyListView',
form: 'openerp.base.form.One2ManyFormView'
@@ -1731,7 +1730,7 @@ openerp.base.form.One2ManyListView = openerp.base.ListView.extend({
this._super.apply(this, arguments);
} else {
var self = this;
var pop = new openerp.base.form.SelectCreatePopup(null, self.o2m.view.session);
var pop = new openerp.base.form.SelectCreatePopup(this);
pop.select_element(self.o2m.field.relation,{
initial_view: "form",
alternative_form_view: self.o2m.field.views ? self.o2m.field.views["form"] : undefined,
@@ -1777,15 +1776,13 @@ openerp.base.form.FieldMany2Many = openerp.base.form.Field.extend({
var self = this;
this.dataset = new openerp.base.form.Many2ManyDataSet(
this.session, this.field.relation);
this.dataset = new openerp.base.form.Many2ManyDataSet( this, this.field.relation);
this.dataset.m2m = this;
this.dataset.on_unlink.add_last(function(ids) {
self.on_ui_change();
});
this.list_view = new openerp.base.form.Many2ManyListView(
null, this.view.session, this.list_id, this.dataset, false, {
this.list_view = new openerp.base.form.Many2ManyListView(this.view.view_manager, this.list_id, this.dataset, false, {
'addable': 'Add',
'selectable': self.multi_selection
});
@@ -1828,8 +1825,7 @@ openerp.base.form.Many2ManyDataSet = openerp.base.DataSetStatic.extend({
openerp.base.form.Many2ManyListView = openerp.base.ListView.extend({
do_add_record: function () {
var pop = new openerp.base.form.SelectCreatePopup(
null, this.m2m_field.view.session);
var pop = new openerp.base.form.SelectCreatePopup(this);
pop.select_element(this.model, {},
new openerp.base.CompoundDomain(this.m2m_field.build_domain(), ["!", ["id", "in", this.m2m_field.dataset.ids]]),
this.m2m_field.build_context());
@@ -1847,7 +1843,7 @@ openerp.base.form.Many2ManyListView = openerp.base.ListView.extend({
},
do_activate_record: function(index, id) {
var self = this;
var pop = new openerp.base.form.FormOpenPopup(null, this.m2m_field.view.session);
var pop = new openerp.base.form.FormOpenPopup(this);
pop.show_element(this.dataset.model, id, this.m2m_field.build_context(), {});
pop.on_write_completed.add_last(function() {
self.reload_content();
@@ -1920,7 +1916,7 @@ openerp.base.form.SelectCreatePopup = openerp.base.BaseWidget.extend({
$sbutton.click(function() {
self.on_select_elements(self.selected_ids);
});
self.view_list = new openerp.base.form.SelectCreateListView( null, self.session,
self.view_list = new openerp.base.form.SelectCreateListView(this,
self.element_id + "_view_list", self.dataset, false,
{'deletable': false});
self.view_list.popup = self;
@@ -1935,7 +1931,7 @@ openerp.base.form.SelectCreatePopup = openerp.base.BaseWidget.extend({
if (!this.options.auto_create)
return;
var self = this;
var wdataset = new openerp.base.DataSetSearch(this.session, this.model, this.context, this.domain);
var wdataset = new openerp.base.DataSetSearch(this, this.model, this.context, this.domain);
wdataset.parent_view = this.options.parent_view;
wdataset.create(data, function(r) {
self.on_select_elements([r.result]);
@@ -2030,7 +2026,7 @@ openerp.base.form.FormOpenPopup = openerp.base.BaseWidget.extend({
if (!this.options.auto_write)
return;
var self = this;
var wdataset = new openerp.base.DataSetSearch(this.session, this.model, this.context, this.domain);
var wdataset = new openerp.base.DataSetSearch(this, this.model, this.context, this.domain);
wdataset.parent_view = this.options.parent_view;
wdataset.write(id, data, function(r) {
self.on_write_completed();
+10 -8
View File
@@ -87,9 +87,9 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
*
* @borrows openerp.base.ActionExecutor#execute_action as #execute_action
*/
init: function(view_manager, session, element_id, dataset, view_id, options) {
this._super(session, element_id);
this.view_manager = view_manager || new openerp.base.NullViewManager();
init: function(parent, element_id, dataset, view_id, options) {
this._super(parent, element_id);
this.view_manager = parent || new openerp.base.NullViewManager();
this.dataset = dataset;
this.model = dataset.model;
this.view_id = view_id;
@@ -100,7 +100,7 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
this.flags = this.view_manager.flags || {};
this.set_groups(new openerp.base.ListView.Groups(this));
if (this.dataset instanceof openerp.base.DataSetStatic) {
this.groups.datagroup = new openerp.base.StaticDataGroup(this.dataset);
}
@@ -254,8 +254,10 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
})
.val(self._limit || 'NaN');
});
if(this.view_manager.sidebar == undefined)
debugger;
this.view_manager.sidebar.set_toolbar(data.fields_view.toolbar);
},
/**
* Configures the ListView pager based on the provided dataset's information
@@ -451,7 +453,7 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
this.dataset.context = results.context;
this.dataset.domain = results.domain;
this.groups.datagroup = new openerp.base.DataGroup(
this.session, this.model,
this, this.model,
results.domain, results.context,
results.group_by);
this.groups.datagroup.sort = this.dataset._sort;
@@ -606,7 +608,7 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
}
// TODO: implement reorder (drag and drop rows)
});
openerp.base.ListView.List = Class.extend( /** @lends openerp.base.ListView.List# */{
openerp.base.ListView.List = openerp.base.Class.extend( /** @lends openerp.base.ListView.List# */{
/**
* List display for the ListView, handles basic DOM events and transforms
* them in the relevant higher-level events, to which the list view (or
@@ -842,7 +844,7 @@ openerp.base.ListView.List = Class.extend( /** @lends openerp.base.ListView.List
}
// drag and drop
});
openerp.base.ListView.Groups = Class.extend( /** @lends openerp.base.ListView.Groups# */{
openerp.base.ListView.Groups = openerp.base.Class.extend( /** @lends openerp.base.ListView.Groups# */{
passtrough_events: 'action deleted row_link',
/**
* Grouped display for the ListView. Handles basic DOM events and interacts
+14 -23
View File
@@ -1,9 +1,9 @@
openerp.base.search = function(openerp) {
openerp.base.SearchView = openerp.base.Controller.extend({
init: function(view_manager, session, element_id, dataset, view_id, defaults) {
this._super(session, element_id);
this.view_manager = view_manager || new openerp.base.NullViewManager();
init: function(parent, element_id, dataset, view_id, defaults) {
this._super(parent, element_id);
this.view_manager = parent || new openerp.base.NullViewManager();
this.dataset = dataset;
this.model = dataset.model;
this.view_id = view_id;
@@ -115,7 +115,7 @@ openerp.base.SearchView = openerp.base.Controller.extend({
data.fields_view.fields);
// for extended search view
var ext = new openerp.base.search.ExtendedSearch(null, this.session, this.model);
var ext = new openerp.base.search.ExtendedSearch(this, this.model);
lines.push([ext]);
this.inputs.push(ext);
@@ -124,6 +124,7 @@ openerp.base.SearchView = openerp.base.Controller.extend({
'lines': lines,
'defaults': this.defaults
});
// We don't understand why the following commented line does not work in Chrome but
// the non-commented line does. As far as we investigated, only God knows.
//this.$element.html(render);
@@ -301,8 +302,7 @@ openerp.base.search.fields = new openerp.base.Registry({
'many2one': 'openerp.base.search.ManyToOneField',
'many2many': 'openerp.base.search.ManyToManyField'
});
openerp.base.search.Invalid = Class.extend(
/** @lends openerp.base.search.Invalid# */{
openerp.base.search.Invalid = openerp.base.Class.extend( /** @lends openerp.base.search.Invalid# */{
/**
* Exception thrown by search widgets when they hold invalid values,
* which they can not return when asked.
@@ -322,8 +322,7 @@ openerp.base.search.Invalid = Class.extend(
': [' + this.value + '] is ' + this.message);
}
});
openerp.base.search.Widget = openerp.base.Controller.extend(
/** @lends openerp.base.search.Widget# */{
openerp.base.search.Widget = openerp.base.Controller.extend( /** @lends openerp.base.search.Widget# */{
template: null,
/**
* Root class of all search widgets
@@ -420,8 +419,7 @@ openerp.base.search.Group = openerp.base.search.Widget.extend({
}
});
openerp.base.search.Input = openerp.base.search.Widget.extend(
/** @lends openerp.base.search.Input# */{
openerp.base.search.Input = openerp.base.search.Widget.extend( /** @lends openerp.base.search.Input# */{
/**
* @constructs
* @extends openerp.base.search.Widget
@@ -491,8 +489,7 @@ openerp.base.search.Filter = openerp.base.search.Input.extend({
return this.attrs.domain;
}
});
openerp.base.search.Field = openerp.base.search.Input.extend(
/** @lends openerp.base.search.Field# */ {
openerp.base.search.Field = openerp.base.search.Input.extend( /** @lends openerp.base.search.Field# */ {
template: 'SearchView.field',
default_operator: '=',
/**
@@ -557,8 +554,7 @@ openerp.base.search.Field = openerp.base.search.Input.extend(
* @class
* @extends openerp.base.search.Field
*/
openerp.base.search.CharField = openerp.base.search.Field.extend(
/** @lends openerp.base.search.CharField# */ {
openerp.base.search.CharField = openerp.base.search.Field.extend( /** @lends openerp.base.search.CharField# */ {
default_operator: 'ilike',
get_value: function () {
return this.$element.val();
@@ -631,12 +627,7 @@ openerp.base.search.SelectionField = openerp.base.search.Field.extend({
return this.$element.val();
}
});
/**
* @class
* @extends openerp.base.search.Field
*/
openerp.base.search.DateField = openerp.base.search.Field.extend(
/** @lends openerp.base.search.DateField# */{
openerp.base.search.DateField = openerp.base.search.Field.extend( /** @lends openerp.base.search.DateField# */{
template: 'SearchView.fields.date',
/**
* enables date picker on the HTML widgets
@@ -724,7 +715,7 @@ openerp.base.search.ManyToOneField = openerp.base.search.CharField.extend({
self.$element.val(self.name);
});
this.dataset = new openerp.base.DataSet(
this.view.session, this.attrs['relation']);
this.view, this.attrs['relation']);
},
start: function () {
this._super();
@@ -791,8 +782,8 @@ openerp.base.search.ManyToManyField = openerp.base.search.CharField.extend({
openerp.base.search.ExtendedSearch = openerp.base.BaseWidget.extend({
template: 'SearchView.extended_search',
identifier_prefix: 'extended-search',
init: function (parent, session, model) {
this._super(parent, session);
init: function (parent, model) {
this._super(parent);
this.model = model;
},
add_group: function() {
+15 -18
View File
@@ -6,13 +6,13 @@ openerp.base.views = function(openerp) {
openerp.base.ActionManager = openerp.base.Controller.extend({
// process all kind of actions
init: function(session, element_id) {
this._super(session, element_id);
init: function(parent, element_id) {
this._super(parent, element_id);
this.viewmanager = null;
this.current_dialog = null;
// Temporary linking view_manager to session.
// Will use controller_parent to find it when implementation will be done.
session.action_manager = this;
this.session.action_manager = this;
},
/**
* Process an action
@@ -35,15 +35,12 @@ openerp.base.ActionManager = openerp.base.Controller.extend({
action.flags.new_window = true;
}
if (action.target == 'new') {
var dialog = this.current_dialog = new openerp.base.ActionDialog(this.session, {
title: action.name,
width: '50%'
});
var dialog = this.current_dialog = new openerp.base.ActionDialog(this, { title: action.name, width: '90%' });
if (on_closed) {
dialog.close_callback = on_closed;
}
dialog.start(false);
var viewmanager = dialog.viewmanager = new openerp.base.ViewManagerAction(this.session, dialog.element_id, action);
var viewmanager = dialog.viewmanager = new openerp.base.ViewManagerAction(this, dialog.element_id, action);
viewmanager.start();
dialog.open();
} else if (action.flags.new_window) {
@@ -57,7 +54,7 @@ openerp.base.ActionManager = openerp.base.Controller.extend({
if (this.viewmanager) {
this.viewmanager.stop();
}
this.viewmanager = new openerp.base.ViewManagerAction(this.session, this.element_id, action);
this.viewmanager = new openerp.base.ViewManagerAction(this, this.element_id, action);
this.viewmanager.start();
}
break;
@@ -85,8 +82,8 @@ openerp.base.ActionManager = openerp.base.Controller.extend({
});
openerp.base.ViewManager = openerp.base.Controller.extend({
init: function(session, element_id, dataset, views) {
this._super(session, element_id);
init: function(parent, element_id, dataset, views) {
this._super(parent, element_id);
this.model = dataset.model;
this.dataset = dataset;
this.searchview = null;
@@ -133,7 +130,7 @@ openerp.base.ViewManager = openerp.base.Controller.extend({
if (!view.controller) {
// Lazy loading of views
var controllerclass = this.registry.get_object(view_type);
var controller = new controllerclass( this, this.session, this.element_id + "_view_" + view_type,
var controller = new controllerclass( this, this.element_id + "_view_" + view_type,
this.dataset, view.view_id, view.options);
if (view.embedded_view) {
controller.set_embedded_view(view.embedded_view);
@@ -203,7 +200,7 @@ openerp.base.ViewManager = openerp.base.Controller.extend({
if (this.searchview) {
this.searchview.stop();
}
this.searchview = new openerp.base.SearchView(this, this.session, this.element_id + "_search", this.dataset, view_id, search_defaults);
this.searchview = new openerp.base.SearchView(this, this.element_id + "_search", this.dataset, view_id, search_defaults);
if (this.flags.search_view === false) {
this.searchview.hide();
}
@@ -253,18 +250,19 @@ openerp.base.NullViewManager = openerp.base.generate_null_object_class(openerp.b
});
openerp.base.ViewManagerAction = openerp.base.ViewManager.extend({
init: function(session, element_id, action) {
init: function(parent, element_id, action) {
this.session = parent.session;
var dataset;
if (!action.res_id) {
dataset = new openerp.base.DataSetSearch(session, action.res_model, action.context || null);
dataset = new openerp.base.DataSetSearch(this, action.res_model, action.context || null);
} else {
dataset = new openerp.base.DataSetStatic(session, action.res_model, {}, [action.res_id]);
dataset = new openerp.base.DataSetStatic(this, action.res_model, {}, [action.res_id]);
if (action.context) {
// TODO fme: should normalize all DataSets constructors to (session, model, context, ...)
dataset.context = action.context;
}
}
this._super(session, element_id, dataset, action.views);
this._super(parent, element_id, dataset, action.views);
this.action = action;
this.flags = this.action.flags || {};
if (action.res_model == 'board.board' && action.views.length == 1 && action.views) {
@@ -402,7 +400,6 @@ openerp.base.Sidebar = openerp.base.BaseWidget.extend({
}
});
openerp.base.NullSidebar = openerp.base.generate_null_object_class(openerp.base.Sidebar);
openerp.base.Export = openerp.base.Dialog.extend({
@@ -89,7 +89,7 @@ openerp.base.form.DashBoard = openerp.base.form.Widget.extend({
}
}
});
new openerp.base.ViewManagerAction(this.session, dialog_id, action).start();
new openerp.base.ViewManagerAction(this, dialog_id, action).start();
// TODO: should bind ListView#select_record in order to catch record clicking
},
do_add_widget : function(action_manager) {
@@ -227,7 +227,7 @@ openerp.base.form.DashBoard = openerp.base.form.Widget.extend({
action_buttons : false,
pager: false
};
new openerp.base.ViewManagerAction(this.session,
new openerp.base.ViewManagerAction(this,
this.view.element_id + '_action_' + action.id, action).start();
},
render: function() {
+3 -3
View File
@@ -16,9 +16,9 @@ QWeb.add_template('/base_graph/static/src/xml/base_graph.xml');
openerp.base.views.add('graph', 'openerp.base_graph.GraphView');
openerp.base_graph.GraphView = openerp.base.View.extend({
init: function(view_manager, session, element_id, dataset, view_id) {
this._super(session, element_id);
this.view_manager = view_manager;
init: function(parent, element_id, dataset, view_id) {
this._super(parent, element_id);
this.view_manager = parent;
this.dataset = dataset;
this.dataset_index = 0;
this.model = this.dataset.model;