[merge] refactoring of 'openerp' to 'instance'

bzr revid: nicolas.vanhoren@openerp.com-20120417121627-c2264x40jgikdpd8
This commit is contained in:
niv-openerp 2012-04-17 14:16:27 +02:00
commit 53c0d46e79
15 changed files with 692 additions and 692 deletions

View File

@ -1,16 +1,16 @@
/*---------------------------------------------------------
* OpenERP Web chrome
*---------------------------------------------------------*/
openerp.web.chrome = function(openerp) {
var QWeb = openerp.web.qweb,
_t = openerp.web._t;
openerp.web.chrome = function(instance) {
var QWeb = instance.web.qweb,
_t = instance.web._t;
openerp.web.Notification = openerp.web.Widget.extend({
instance.web.Notification = instance.web.Widget.extend({
template: 'Notification',
init: function() {
this._super.apply(this, arguments);
// move to openerp.web.notification
openerp.notification = this;
// move to instance.web.notification
instance.notification = this;
},
start: function() {
this._super.apply(this, arguments);
@ -43,13 +43,13 @@ openerp.web.Notification = openerp.web.Widget.extend({
}
});
openerp.web.dialog = function(element) {
instance.web.dialog = function(element) {
var result = element.dialog.apply(element, _.rest(_.toArray(arguments)));
result.dialog("widget").addClass("openerp");
return result;
}
openerp.web.Dialog = openerp.web.Widget.extend({
instance.web.Dialog = instance.web.Widget.extend({
dialog_title: "",
init: function (parent, options, content) {
var self = this;
@ -83,7 +83,7 @@ openerp.web.Dialog = openerp.web.Widget.extend({
if (this.dialog_options.autoOpen) {
this.open();
} else {
openerp.web.dialog(this.$element, this.get_options());
instance.web.dialog(this.$element, this.get_options());
}
},
get_options: function(options) {
@ -122,7 +122,7 @@ openerp.web.Dialog = openerp.web.Widget.extend({
this.$element.html(this.renderElement());
}
var o = this.get_options(options);
openerp.web.dialog(this.$element, o).dialog('open');
instance.web.dialog(this.$element, o).dialog('open');
if (o.height === 'auto' && o.max_height) {
this.$element.css({ 'max-height': o.max_height, 'overflow-y': 'auto' });
}
@ -146,7 +146,7 @@ openerp.web.Dialog = openerp.web.Widget.extend({
}
});
openerp.web.CrashManager = openerp.web.CallbackEnabled.extend({
instance.web.CrashManager = instance.web.CallbackEnabled.extend({
on_rpc_error: function(error) {
if (error.data.fault_code) {
var split = ("" + error.data.fault_code).split('\n')[0].split(' -- ');
@ -162,7 +162,7 @@ openerp.web.CrashManager = openerp.web.CallbackEnabled.extend({
}
},
on_managed_error: function(error) {
openerp.web.dialog($('<div>' + QWeb.render('CrashManager.warning', {error: error}) + '</div>'), {
instance.web.dialog($('<div>' + QWeb.render('CrashManager.warning', {error: error}) + '</div>'), {
title: "OpenERP " + _.str.capitalize(error.type),
buttons: [
{text: _t("Ok"), click: function() { $(this).dialog("close"); }}
@ -172,14 +172,14 @@ openerp.web.CrashManager = openerp.web.CallbackEnabled.extend({
on_traceback: function(error) {
var self = this;
var buttons = {};
if (openerp.connection.openerp_entreprise) {
if (instance.connection.openerp_entreprise) {
buttons[_t("Send OpenERP Enterprise Report")] = function() {
var $this = $(this);
var issuename = $('#issuename').val();
var explanation = $('#explanation').val();
var remark = $('#remark').val();
// Call the send method from server to send mail with details
new openerp.web.DataSet(self, 'publisher_warranty.contract').call_and_eval('send', [error.data,explanation,remark,issuename]).then(function(result){
new instance.web.DataSet(self, 'publisher_warranty.contract').call_and_eval('send', [error.data,explanation,remark,issuename]).then(function(result){
if (result === false) {
alert('There was a communication error.')
} else {
@ -195,7 +195,7 @@ openerp.web.CrashManager = openerp.web.CallbackEnabled.extend({
$(this).dialog("close");
};
}
var dialog = new openerp.web.Dialog(this, {
var dialog = new instance.web.Dialog(this, {
title: "OpenERP " + _.str.capitalize(error.type),
width: '80%',
height: '50%',
@ -203,11 +203,11 @@ openerp.web.CrashManager = openerp.web.CallbackEnabled.extend({
min_height: '600px',
buttons: buttons
}).open();
dialog.$element.html(QWeb.render('CrashManager.error', {session: openerp.connection, error: error}));
dialog.$element.html(QWeb.render('CrashManager.error', {session: instance.connection, error: error}));
}
});
openerp.web.Loading = openerp.web.Widget.extend({
instance.web.Loading = instance.web.Widget.extend({
template: 'Loading',
init: function(parent) {
this._super(parent);
@ -258,7 +258,7 @@ openerp.web.Loading = openerp.web.Widget.extend({
}
});
openerp.web.DatabaseManager = openerp.web.Widget.extend({
instance.web.DatabaseManager = instance.web.Widget.extend({
init: function(parent) {
this._super(parent);
this.unblockUIFunction = $.unblockUI;
@ -344,7 +344,7 @@ openerp.web.DatabaseManager = openerp.web.Widget.extend({
* @param {String} error.error message of the error dialog
*/
display_error: function (error) {
return openerp.web.dialog($('<div>'), {
return instance.web.dialog($('<div>'), {
modal: true,
title: error.title,
buttons: [
@ -388,7 +388,7 @@ openerp.web.DatabaseManager = openerp.web.Widget.extend({
success: function () {
self.do_notify(_t("Backed"), _t("Database backed up successfully"));
},
error: openerp.webclient.crashmanager.on_rpc_error,
error: instance.webclient.crashmanager.on_rpc_error,
complete: function() {
self.unblockUI();
}
@ -439,7 +439,7 @@ openerp.web.DatabaseManager = openerp.web.Widget.extend({
}
});
openerp.web.Login = openerp.web.Widget.extend({
instance.web.Login = instance.web.Widget.extend({
template: "Login",
remember_credentials: true,
init: function(parent) {
@ -464,7 +464,7 @@ openerp.web.Login = openerp.web.Widget.extend({
self.$element.find('.oe_login_manage_db').click(function() {
self.$element.find('.oe_login_bottom').hide();
self.$element.find('.oe_login_pane').hide();
self.databasemanager = new openerp.web.DatabaseManager(self);
self.databasemanager = new instance.web.DatabaseManager(self);
self.databasemanager.appendTo(self.$element);
self.databasemanager.do_exit.add_last(function() {
self.databasemanager.destroy();
@ -486,7 +486,7 @@ openerp.web.Login = openerp.web.Widget.extend({
});
},
set_db_list: function (list) {
this.$element.find("[name=db]").replaceWith(openerp.web.qweb.render('Login.dblist', { db_list: list, selected_db: this.selected_db}))
this.$element.find("[name=db]").replaceWith(instance.web.qweb.render('Login.dblist', { db_list: list, selected_db: this.selected_db}))
},
on_submit: function(ev) {
if(ev) {
@ -538,7 +538,7 @@ openerp.web.Login = openerp.web.Widget.extend({
}
});
openerp.web.Menu = openerp.web.Widget.extend({
instance.web.Menu = instance.web.Widget.extend({
template: 'Menu',
init: function() {
this._super.apply(this, arguments);
@ -682,7 +682,7 @@ openerp.web.Menu = openerp.web.Widget.extend({
}
});
openerp.web.UserMenu = openerp.web.Widget.extend({
instance.web.UserMenu = instance.web.Widget.extend({
template: "UserMenu",
init: function(parent) {
this._super(parent);
@ -707,7 +707,7 @@ openerp.web.UserMenu = openerp.web.Widget.extend({
},
change_password :function() {
var self = this;
this.dialog = new openerp.web.Dialog(this, {
this.dialog = new instance.web.Dialog(this, {
title: _t("Change Password"),
width : 'auto'
}).open();
@ -721,14 +721,14 @@ openerp.web.UserMenu = openerp.web.Widget.extend({
self.display_error(result);
return;
} else {
openerp.webclient.on_logout();
instance.webclient.on_logout();
}
});
}
});
},
display_error: function (error) {
return openerp.web.dialog($('<div>'), {
return instance.web.dialog($('<div>'), {
modal: true,
title: error.title,
buttons: [
@ -743,10 +743,10 @@ openerp.web.UserMenu = openerp.web.Widget.extend({
$avatar.attr('src', $avatar.data('default-src'));
if (!self.session.uid)
return;
var func = new openerp.web.Model("res.users").get_func("read");
var func = new instance.web.Model("res.users").get_func("read");
return func(self.session.uid, ["name", "company_id"]).pipe(function(res) {
// TODO: Show company if multicompany is in use
var topbar_name = _.str.sprintf("%s (%s)", res.name, openerp.connection.db, res.company_id[1]);
var topbar_name = _.str.sprintf("%s (%s)", res.name, instance.connection.db, res.company_id[1]);
self.$element.find('.oe_topbar_name').text(topbar_name);
var avatar_src = _.str.sprintf('%s/web/binary/image?session_id=%s&model=res.users&field=avatar&id=%s', self.session.prefix, self.session.session_id, self.session.uid);
$avatar.attr('src', avatar_src);
@ -760,7 +760,7 @@ openerp.web.UserMenu = openerp.web.Widget.extend({
shortcut_load :function(){
var self = this,
sc = self.session.shortcuts,
shortcuts_ds = new openerp.web.DataSet(this, 'ir.ui.view_sc');
shortcuts_ds = new instance.web.DataSet(this, 'ir.ui.view_sc');
self.$element.find('.oe_dropdown_options a[data-menu=shortcut]').each(function() {
$(this).parent().remove();
});
@ -807,8 +807,8 @@ openerp.web.UserMenu = openerp.web.Widget.extend({
},
on_menu_settings: function() {
var self = this;
var action_manager = new openerp.web.ActionManager(this);
var dataset = new openerp.web.DataSet (this,'res.users',this.context);
var action_manager = new instance.web.ActionManager(this);
var dataset = new instance.web.DataSet (this,'res.users',this.context);
dataset.call ('action_get','',function (result){
self.rpc('/web/action/load', {action_id:result}, function(result){
action_manager.do_action(_.extend(result['result'], {
@ -825,7 +825,7 @@ openerp.web.UserMenu = openerp.web.Widget.extend({
}));
});
});
this.dialog = new openerp.web.Dialog(this,{
this.dialog = new instance.web.Dialog(this,{
title: _t("Preferences"),
width: '700px',
buttons: [
@ -855,7 +855,7 @@ openerp.web.UserMenu = openerp.web.Widget.extend({
window.location = $.param.querystring(
window.location.href, 'debug');
});
openerp.web.dialog($help, {autoOpen: true,
instance.web.dialog($help, {autoOpen: true,
modal: true, width: 960, title: _t("About")});
});
},
@ -871,11 +871,11 @@ openerp.web.UserMenu = openerp.web.Widget.extend({
}
});
openerp.web.WebClient = openerp.web.Widget.extend({
instance.web.WebClient = instance.web.Widget.extend({
init: function(parent) {
var self = this;
this._super(parent);
openerp.webclient = this;
instance.webclient = this;
this.querystring = '?' + jQuery.param.querystring();
this._current_state = null;
},
@ -900,7 +900,7 @@ openerp.web.WebClient = openerp.web.Widget.extend({
self.menu.do_reload();
if(self.action_manager)
self.action_manager.destroy();
self.action_manager = new openerp.web.ActionManager(self);
self.action_manager = new instance.web.ActionManager(self);
self.action_manager.appendTo(self.$element.find('.oe_application'));
self.bind_hashchange();
var version_label = _t("OpenERP - Unsupported/Community Version");
@ -917,7 +917,7 @@ openerp.web.WebClient = openerp.web.Widget.extend({
var self = this;
this.destroy_content();
this.show_common();
self.login = new openerp.web.Login(self);
self.login = new instance.web.Login(self);
self.login.appendTo(self.$element);
},
show_application: function() {
@ -926,10 +926,10 @@ openerp.web.WebClient = openerp.web.Widget.extend({
this.show_common();
self.$table = $(QWeb.render("WebClient", {}));
self.$element.append(self.$table);
self.menu = new openerp.web.Menu(self);
self.menu = new instance.web.Menu(self);
self.menu.replace(this.$element.find('.oe_menu_placeholder'));
self.menu.on_action.add(this.proxy('on_menu_action'));
self.user_menu = new openerp.web.UserMenu(self);
self.user_menu = new instance.web.UserMenu(self);
self.user_menu.replace(this.$element.find('.oe_user_menu_placeholder'));
self.user_menu.on_menu_logout.add(this.proxy('on_logout'));
self.user_menu.on_action.add(this.proxy('on_menu_action'));
@ -937,8 +937,8 @@ openerp.web.WebClient = openerp.web.Widget.extend({
show_common: function() {
var self = this;
if (!this.crashmanager) {
this.crashmanager = new openerp.web.CrashManager();
openerp.connection.on_rpc_error.add(this.crashmanager.on_rpc_error);
this.crashmanager = new instance.web.CrashManager();
instance.connection.on_rpc_error.add(this.crashmanager.on_rpc_error);
window.onerror = function (message, file, line) {
self.crashmanager.on_traceback({
type: _t("Client Error"),
@ -947,9 +947,9 @@ openerp.web.WebClient = openerp.web.Widget.extend({
});
}
}
this.notification = new openerp.web.Notification(this);
this.notification = new instance.web.Notification(this);
this.notification.appendTo(this.$element);
this.loading = new openerp.web.Loading(this);
this.loading = new instance.web.Loading(this);
this.loading.appendTo(this.$element);
},
destroy_content: function() {
@ -961,7 +961,7 @@ openerp.web.WebClient = openerp.web.Widget.extend({
do_reload: function() {
var self = this;
return this.session.session_reload().pipe(function () {
openerp.connection.load_modules(true).pipe(
instance.connection.load_modules(true).pipe(
self.menu.proxy('do_reload')); });
},
@ -1025,14 +1025,14 @@ openerp.web.WebClient = openerp.web.Widget.extend({
}
});
openerp.web.EmbeddedClient = openerp.web.Widget.extend({
instance.web.EmbeddedClient = instance.web.Widget.extend({
template: 'EmptyComponent',
init: function(parent, action_id, options) {
this._super(parent);
// TODO take the xmlid of a action instead of its id
this.action_id = action_id;
this.options = options || {};
this.am = new openerp.web.ActionManager(this);
this.am = new instance.web.ActionManager(this);
},
start: function() {
var self = this;
@ -1052,7 +1052,7 @@ openerp.web.EmbeddedClient = openerp.web.Widget.extend({
}
});
openerp.web.embed = function (origin, dbname, login, key, action, options) {
instance.web.embed = function (origin, dbname, login, key, action, options) {
$('head').append($('<link>', {
'rel': 'stylesheet',
'type': 'text/css',
@ -1063,9 +1063,9 @@ openerp.web.embed = function (origin, dbname, login, key, action, options) {
var sc = document.getElementsByTagName('script');
currentScript = sc[sc.length-1];
}
openerp.connection.session_bind(origin).then(function () {
openerp.connection.session_authenticate(dbname, login, key, true).then(function () {
var client = new openerp.web.EmbeddedClient(null, action, options);
instance.connection.session_bind(origin).then(function () {
instance.connection.session_authenticate(dbname, login, key, true).then(function () {
var client = new instance.web.EmbeddedClient(null, action, options);
client.insertAfter(currentScript);
});
});

View File

@ -23,7 +23,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
openerp.web.corelib = function(openerp) {
openerp.web.corelib = function(instance) {
/**
* Improved John Resig's inheritance, based on:
@ -39,7 +39,7 @@ openerp.web.corelib = function(openerp) {
*
* Example:
*
* var Person = openerp.web.Class.extend({
* var Person = instance.web.Class.extend({
* init: function(isDancing){
* this.dancing = isDancing;
* },
@ -75,14 +75,14 @@ openerp.web.corelib = function(openerp) {
var initializing = false,
fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
// The web Class implementation (does nothing)
openerp.web.Class = function(){};
instance.web.Class = function(){};
/**
* Subclass an existing class
*
* @param {Object} prop class-level properties (class attributes and instance methods) to set on the new class
*/
openerp.web.Class.extend = function() {
instance.web.Class.extend = function() {
var _super = this.prototype;
// Support mixins arguments
var args = _.toArray(arguments);
@ -180,7 +180,7 @@ openerp.web.corelib = function(openerp) {
* When an object is destroyed, all its children are destroyed too releasing
* any resource they could have reserved before.
*/
openerp.web.ParentedMixin = {
instance.web.ParentedMixin = {
__parentedMixin : true,
init: function() {
this.__parentedDestroyed = false;
@ -253,7 +253,7 @@ openerp.web.ParentedMixin = {
* events is done in EventDispatcherMixin.
*
*/
openerp.web.Events = openerp.web.Class.extend({
instance.web.Events = instance.web.Class.extend({
on : function(events, callback, context) {
var ev;
@ -324,11 +324,11 @@ openerp.web.Events = openerp.web.Class.extend({
}
});
openerp.web.EventDispatcherMixin = _.extend({}, openerp.web.ParentedMixin, {
instance.web.EventDispatcherMixin = _.extend({}, instance.web.ParentedMixin, {
__eventDispatcherMixin: true,
init: function() {
openerp.web.ParentedMixin.init.call(this);
this.__edispatcherEvents = new openerp.web.Events();
instance.web.ParentedMixin.init.call(this);
this.__edispatcherEvents = new instance.web.Events();
this.__edispatcherRegisteredEvents = [];
},
on: function(events, dest, func) {
@ -369,13 +369,13 @@ openerp.web.EventDispatcherMixin = _.extend({}, openerp.web.ParentedMixin, {
debugger;
}
this.__edispatcherEvents.off();
openerp.web.ParentedMixin.destroy.call(this);
instance.web.ParentedMixin.destroy.call(this);
}
});
openerp.web.GetterSetterMixin = _.extend({}, openerp.web.EventDispatcherMixin, {
instance.web.GetterSetterMixin = _.extend({}, instance.web.EventDispatcherMixin, {
init: function() {
openerp.web.EventDispatcherMixin.init.call(this);
instance.web.EventDispatcherMixin.init.call(this);
this.__getterSetterInternalMap = {};
},
set: function(map) {
@ -400,9 +400,9 @@ openerp.web.GetterSetterMixin = _.extend({}, openerp.web.EventDispatcherMixin, {
}
});
openerp.web.CallbackEnabledMixin = _.extend({}, openerp.web.GetterSetterMixin, {
instance.web.CallbackEnabledMixin = _.extend({}, instance.web.GetterSetterMixin, {
init: function() {
openerp.web.GetterSetterMixin.init.call(this);
instance.web.GetterSetterMixin.init.call(this);
var self = this;
var callback_maker = function(obj, name, method) {
var callback = function() {
@ -421,7 +421,7 @@ openerp.web.CallbackEnabledMixin = _.extend({}, openerp.web.GetterSetterMixin, {
r = result;
}
// TODO special value to stop the chain
// openerp.web.callback_stop
// instance.web.callback_stop
}
return r;
};
@ -500,7 +500,7 @@ openerp.web.CallbackEnabledMixin = _.extend({}, openerp.web.GetterSetterMixin, {
}
});
openerp.web.WidgetMixin = _.extend({},openerp.web.CallbackEnabledMixin, {
instance.web.WidgetMixin = _.extend({},instance.web.CallbackEnabledMixin, {
/**
* Tag name when creating a default $element.
* @type string
@ -509,10 +509,10 @@ openerp.web.WidgetMixin = _.extend({},openerp.web.CallbackEnabledMixin, {
/**
* Constructs the widget and sets its parent if a parent is given.
*
* @constructs openerp.web.Widget
* @extends openerp.web.CallbackEnabled
* @constructs instance.web.Widget
* @extends instance.web.CallbackEnabled
*
* @param {openerp.web.Widget} parent Binds the current instance to the given Widget instance.
* @param {instance.web.Widget} parent Binds the current instance to the given Widget instance.
* When that widget is destroyed by calling destroy(), the current instance will be
* destroyed too. Can be null.
* @param {String} element_id Deprecated. Sets the element_id. Only useful when you want
@ -521,7 +521,7 @@ openerp.web.WidgetMixin = _.extend({},openerp.web.CallbackEnabledMixin, {
* for new components this argument should not be provided any more.
*/
init: function(parent) {
openerp.web.CallbackEnabledMixin.init.call(this);
instance.web.CallbackEnabledMixin.init.call(this);
this.$element = $(document.createElement(this.tagName));
this.setParent(parent);
},
@ -535,7 +535,7 @@ openerp.web.WidgetMixin = _.extend({},openerp.web.CallbackEnabledMixin, {
if(this.$element != null) {
this.$element.remove();
}
openerp.web.GetterSetterMixin.destroy.call(this);
instance.web.GetterSetterMixin.destroy.call(this);
},
/**
* Renders the current widget and appends it to the given jQuery object or Widget.
@ -616,9 +616,9 @@ openerp.web.WidgetMixin = _.extend({},openerp.web.CallbackEnabledMixin, {
// Classes
openerp.web.CallbackEnabled = openerp.web.Class.extend(openerp.web.CallbackEnabledMixin, {
instance.web.CallbackEnabled = instance.web.Class.extend(instance.web.CallbackEnabledMixin, {
init: function() {
openerp.web.CallbackEnabledMixin.init.call(this);
instance.web.CallbackEnabledMixin.init.call(this);
}
});
@ -637,7 +637,7 @@ openerp.web.CallbackEnabled = openerp.web.Class.extend(openerp.web.CallbackEnabl
*
* Here is a sample child class:
*
* MyWidget = openerp.base.Widget.extend({
* MyWidget = instance.base.Widget.extend({
* // the name of the QWeb template to use for rendering
* template: "MyQWebTemplate",
*
@ -670,7 +670,7 @@ openerp.web.CallbackEnabled = openerp.web.Class.extend(openerp.web.CallbackEnabl
*
* That will kill the widget in a clean way and erase its content from the dom.
*/
openerp.web.Widget = openerp.web.Class.extend(openerp.web.WidgetMixin, {
instance.web.Widget = instance.web.Class.extend(instance.web.WidgetMixin, {
/**
* The name of the QWeb template that will be used for rendering. Must be
* redefined in subclasses or the default render() method can not be used.
@ -681,10 +681,10 @@ openerp.web.Widget = openerp.web.Class.extend(openerp.web.WidgetMixin, {
/**
* Constructs the widget and sets its parent if a parent is given.
*
* @constructs openerp.web.Widget
* @extends openerp.web.CallbackEnabled
* @constructs instance.web.Widget
* @extends instance.web.CallbackEnabled
*
* @param {openerp.web.Widget} parent Binds the current instance to the given Widget instance.
* @param {instance.web.Widget} parent Binds the current instance to the given Widget instance.
* When that widget is destroyed by calling destroy(), the current instance will be
* destroyed too. Can be null.
* @param {String} element_id Deprecated. Sets the element_id. Only useful when you want
@ -693,8 +693,8 @@ openerp.web.Widget = openerp.web.Class.extend(openerp.web.WidgetMixin, {
* for new components this argument should not be provided any more.
*/
init: function(parent) {
openerp.web.WidgetMixin.init.call(this,parent);
this.session = openerp.connection;
instance.web.WidgetMixin.init.call(this,parent);
this.session = instance.connection;
},
/**
* Renders the element. The default implementation renders the widget using QWeb,
@ -704,7 +704,7 @@ openerp.web.Widget = openerp.web.Class.extend(openerp.web.WidgetMixin, {
renderElement: function() {
var rendered = null;
if (this.template)
rendered = openerp.web.qweb.render(this.template, {widget: this});
rendered = instance.web.qweb.render(this.template, {widget: this});
if (_.str.trim(rendered)) {
var elem = $(rendered);
this.$element.replaceWith(elem);
@ -737,7 +737,7 @@ openerp.web.Widget = openerp.web.Class.extend(openerp.web.WidgetMixin, {
rpc: function(url, data, success, error) {
var def = $.Deferred().then(success, error);
var self = this;
openerp.connection.rpc(url, data). then(function() {
instance.connection.rpc(url, data). then(function() {
if (!self.isDestroyed())
def.resolve.apply(def, arguments);
}, function() {
@ -748,7 +748,7 @@ openerp.web.Widget = openerp.web.Class.extend(openerp.web.WidgetMixin, {
}
});
openerp.web.Registry = openerp.web.Class.extend({
instance.web.Registry = instance.web.Class.extend({
/**
* Stores a mapping of arbitrary key (strings) to object paths (as strings
* as well).
@ -757,11 +757,11 @@ openerp.web.Registry = openerp.web.Class.extend({
* object, even if those objects have been overloaded/replaced after the
* registry was created.
*
* An object path is simply a dotted name from the openerp root to the
* object pointed to (e.g. ``"openerp.web.Connection"`` for an OpenERP
* An object path is simply a dotted name from the instance root to the
* object pointed to (e.g. ``"instance.web.Connection"`` for an OpenERP
* connection object).
*
* @constructs openerp.web.Registry
* @constructs instance.web.Registry
* @param {Object} mapping a mapping of keys to object-paths
*/
init: function (mapping) {
@ -785,7 +785,7 @@ openerp.web.Registry = openerp.web.Class.extend({
return null;
}
var object_match = openerp;
var object_match = instance;
var path = path_string.split('.');
// ignore first section
for(var i=1; i<path.length; ++i) {
@ -838,7 +838,7 @@ openerp.web.Registry = openerp.web.Class.extend({
*
* @param {String} key
* @param {String} object_path fully qualified dotted object path
* @returns {openerp.web.Registry} itself
* @returns {instance.web.Registry} itself
*/
add: function (key, object_path) {
this.map[key] = object_path;
@ -854,7 +854,7 @@ openerp.web.Registry = openerp.web.Class.extend({
* @param {Object} [mapping={}] a mapping of keys to object-paths
*/
extend: function (mapping) {
var child = new openerp.web.Registry(mapping);
var child = new instance.web.Registry(mapping);
child.parent = this;
return child;
},
@ -867,10 +867,10 @@ openerp.web.Registry = openerp.web.Class.extend({
}
});
openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.web.Connection# */{
instance.web.Connection = instance.web.CallbackEnabled.extend( /** @lends instance.web.Connection# */{
/**
* @constructs openerp.web.Connection
* @extends openerp.web.CallbackEnabled
* @constructs instance.web.Connection
* @extends instance.web.CallbackEnabled
*
* @param {String} [server] JSON-RPC endpoint hostname
* @param {String} [port] JSON-RPC endpoint port
@ -880,7 +880,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
this.server = null;
this.debug = ($.deparam($.param.querystring()).debug != undefined);
// TODO: session store in cookie should be optional
this.name = openerp._session_id;
this.name = instance._session_id;
this.qweb_mutex = new $.Mutex();
},
session_bind: function(origin) {
@ -888,7 +888,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
this.origin = origin ? _.str.rtrim(origin,'/') : window_origin;
this.prefix = this.origin;
this.server = this.origin; // keep chs happy
openerp.web.qweb.default_dict['_s'] = this.origin;
instance.web.qweb.default_dict['_s'] = this.origin;
this.rpc_function = (this.origin == window_origin) ? this.rpc_json : this.rpc_jsonp;
this.session_id = false;
this.uid = false;
@ -896,7 +896,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
this.user_context= {};
this.db = false;
this.openerp_entreprise = false;
this.module_list = openerp._modules.slice();
this.module_list = instance._modules.slice();
this.module_loaded = {};
_(this.module_list).each(function (mod) {
self.module_loaded[mod] = true;
@ -1069,7 +1069,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
try {
var ctx = this.test_eval_contexts(source.contexts);
if (!_.isEqual(ctx, expected.context)) {
openerp.webclient.notification.warn('Context mismatch, report to xmo',
instance.webclient.notification.warn('Context mismatch, report to xmo',
_.str.sprintf(match_template, {
source: JSON.stringify(source.contexts),
local: JSON.stringify(ctx),
@ -1077,7 +1077,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
}), true);
}
} catch (e) {
openerp.webclient.notification.warn('Context fail, report to xmo',
instance.webclient.notification.warn('Context fail, report to xmo',
_.str.sprintf(fail_template, {
error: e.message,
source: JSON.stringify(source.contexts)
@ -1087,7 +1087,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
try {
var dom = this.test_eval_domains(source.domains, this.test_eval_get_context());
if (!_.isEqual(dom, expected.domain)) {
openerp.webclient.notification.warn('Domains mismatch, report to xmo',
instance.webclient.notification.warn('Domains mismatch, report to xmo',
_.str.sprintf(match_template, {
source: JSON.stringify(source.domains),
local: JSON.stringify(dom),
@ -1095,7 +1095,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
}), true);
}
} catch (e) {
openerp.webclient.notification.warn('Domain fail, report to xmo',
instance.webclient.notification.warn('Domain fail, report to xmo',
_.str.sprintf(fail_template, {
error: e.message,
source: JSON.stringify(source.domains)
@ -1105,7 +1105,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
try {
var groups = this.test_eval_groupby(source.group_by_seq);
if (!_.isEqual(groups, expected.group_by)) {
openerp.webclient.notification.warn('GroupBy mismatch, report to xmo',
instance.webclient.notification.warn('GroupBy mismatch, report to xmo',
_.str.sprintf(match_template, {
source: JSON.stringify(source.group_by_seq),
local: JSON.stringify(groups),
@ -1113,7 +1113,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
}), true);
}
} catch (e) {
openerp.webclient.notification.warn('GroupBy fail, report to xmo',
instance.webclient.notification.warn('GroupBy fail, report to xmo',
_.str.sprintf(fail_template, {
error: e.message,
source: JSON.stringify(source.group_by_seq)
@ -1369,7 +1369,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
// TODO: session store in cookie should be optional
this.session_id = this.get_cookie('session_id');
return this.session_reload().pipe(function(result) {
var modules = openerp._modules.join(',');
var modules = instance._modules.join(',');
var deferred = self.rpc('/web/webclient/qweblist', {mods: modules}).pipe(self.do_load_qweb);
if(self.session_is_valid()) {
return deferred.pipe(function() { return self.load_modules(); });
@ -1491,7 +1491,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
self.rpc('/web/webclient/csslist', {mods: to_load}, self.do_load_css),
self.rpc('/web/webclient/qweblist', {mods: to_load}).pipe(self.do_load_qweb),
self.rpc('/web/webclient/translations', params).pipe(function(trans) {
openerp.web._t.database.set_bundle(trans);
instance.web._t.database.set_bundle(trans);
var file_list = ["/web/static/lib/datejs/globalization/" + lang.replace("_", "-") + ".js"];
return self.rpc('/web/webclient/jslist', {mods: to_load}).pipe(function(files) {
return self.do_load_js(file_list.concat(files));
@ -1553,7 +1553,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
self.qweb_mutex.exec(function() {
return self.rpc('/web/proxy/load', {path: file}).pipe(function(xml) {
if (!xml) { return; }
openerp.web.qweb.add_template(_.str.trim(xml));
instance.web.qweb.add_template(_.str.trim(xml));
});
});
});
@ -1564,10 +1564,10 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
var mod = this.module_list[j];
if(this.module_loaded[mod])
continue;
openerp[mod] = {};
instance[mod] = {};
// init module mod
if(openerp._openerp[mod] != undefined) {
openerp._openerp[mod](openerp);
if(instance._openerp[mod] != undefined) {
instance._openerp[mod](instance);
this.module_loaded[mod] = true;
}
}
@ -1687,10 +1687,10 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
}
});
openerp.web.TranslationDataBase = openerp.web.Class.extend(/** @lends openerp.web.TranslationDataBase# */{
instance.web.TranslationDataBase = instance.web.Class.extend(/** @lends instance.web.TranslationDataBase# */{
/**
* @constructs openerp.web.TranslationDataBase
* @extends openerp.web.Class
* @constructs instance.web.TranslationDataBase
* @extends instance.web.Class
*/
init: function() {
this.db = {};
@ -1741,9 +1741,9 @@ openerp.web.TranslationDataBase = openerp.web.Class.extend(/** @lends openerp.we
});
/**
* @deprecated use :class:`openerp.web.Widget`
* @deprecated use :class:`instance.web.Widget`
*/
openerp.web.OldWidget = openerp.web.Widget.extend({
instance.web.OldWidget = instance.web.Widget.extend({
init: function(parent, element_id) {
this._super(parent);
this.element_id = element_id;
@ -1762,7 +1762,7 @@ openerp.web.OldWidget = openerp.web.Widget.extend({
},
render: function (additional) {
if (this.template)
return openerp.web.qweb.render(this.template, _.extend({widget: this}, additional || {}));
return instance.web.qweb.render(this.template, _.extend({widget: this}, additional || {}));
return null;
}
});

View File

@ -9,10 +9,10 @@ if (!console.debug) {
console.debug = console.log;
}
openerp.web.coresetup = function(openerp) {
openerp.web.coresetup = function(instance) {
/** Configure default qweb */
openerp.web._t = new openerp.web.TranslationDataBase().build_translation_function();
instance.web._t = new instance.web.TranslationDataBase().build_translation_function();
/**
* Lazy translation function, only performs the translation when actually
* printed (e.g. inserted into a template)
@ -24,16 +24,16 @@ openerp.web._t = new openerp.web.TranslationDataBase().build_translation_functio
* @param {String} s string to translate
* @returns {Object} lazy translation object
*/
openerp.web._lt = function (s) {
return {toString: function () { return openerp.web._t(s); }}
instance.web._lt = function (s) {
return {toString: function () { return instance.web._t(s); }}
};
openerp.web.qweb = new QWeb2.Engine();
openerp.web.qweb.debug = ($.deparam($.param.querystring()).debug != undefined);
openerp.web.qweb.default_dict = {
instance.web.qweb = new QWeb2.Engine();
instance.web.qweb.debug = ($.deparam($.param.querystring()).debug != undefined);
instance.web.qweb.default_dict = {
'_' : _,
'_t' : openerp.web._t
'_t' : instance.web._t
};
openerp.web.qweb.preprocess_node = function() {
instance.web.qweb.preprocess_node = function() {
// Note that 'this' is the Qweb Node
switch (this.node.nodeType) {
case 3:
@ -47,7 +47,7 @@ openerp.web.qweb.preprocess_node = function() {
if (ts.length === 0) {
return;
}
var tr = openerp.web._t(ts);
var tr = instance.web._t(ts);
if (tr !== ts) {
this.node.data = tr;
}
@ -57,7 +57,7 @@ openerp.web.qweb.preprocess_node = function() {
var attr, attrs = ['label', 'title', 'alt'];
while (attr = attrs.pop()) {
if (this.attributes[attr]) {
this.attributes[attr] = openerp.web._t(this.attributes[attr]);
this.attributes[attr] = instance.web._t(this.attributes[attr]);
}
}
}
@ -99,8 +99,8 @@ $.Mutex = (function() {
})();
/** Setup default connection */
openerp.connection = new openerp.web.Connection();
openerp.web.qweb.default_dict['__debug__'] = openerp.connection.debug;
instance.connection = new instance.web.Connection();
instance.web.qweb.default_dict['__debug__'] = instance.connection.debug;
$.async_when = function() {
var async = false;
@ -131,7 +131,7 @@ $.async_when = function() {
// special tweak for the web client
var old_async_when = $.async_when;
$.async_when = function() {
if (openerp.connection.synch)
if (instance.connection.synch)
return $.when.apply(this, arguments);
else
return old_async_when.apply(this, arguments);

View File

@ -1,5 +1,5 @@
openerp.web.data = function(openerp) {
openerp.web.data = function(instance) {
/**
* Serializes the sort criterion array of a dataset into a form which can be
@ -8,7 +8,7 @@ openerp.web.data = function(openerp) {
* @param {Array} criterion array of fields, from first to last criteria, prefixed with '-' for reverse sorting
* @returns {String} SQL-like sorting string (``ORDER BY``) clause
*/
openerp.web.serialize_sort = function (criterion) {
instance.web.serialize_sort = function (criterion) {
return _.map(criterion,
function (criteria) {
if (criteria[0] === '-') {
@ -18,7 +18,7 @@ openerp.web.serialize_sort = function (criterion) {
}).join(', ');
};
openerp.web.DataGroup = openerp.web.OldWidget.extend( /** @lends openerp.web.DataGroup# */{
instance.web.DataGroup = instance.web.OldWidget.extend( /** @lends instance.web.DataGroup# */{
/**
* Management interface between views and grouped collections of OpenERP
* records.
@ -26,13 +26,13 @@ openerp.web.DataGroup = openerp.web.OldWidget.extend( /** @lends openerp.web.Da
* The root DataGroup is instantiated with the relevant information
* (a session, a model, a domain, a context and a group_by sequence), the
* domain and context may be empty. It is then interacted with via
* :js:func:`~openerp.web.DataGroup.list`, which is used to read the
* :js:func:`~instance.web.DataGroup.list`, which is used to read the
* content of the current grouping level.
*
* @constructs openerp.web.DataGroup
* @extends openerp.web.OldWidget
* @constructs instance.web.DataGroup
* @extends instance.web.OldWidget
*
* @param {openerp.web.OldWidget} parent widget
* @param {instance.web.OldWidget} parent widget
* @param {String} model name of the model managed by this DataGroup
* @param {Array} domain search domain for this DataGroup
* @param {Object} context context of the DataGroup's searches
@ -43,9 +43,9 @@ openerp.web.DataGroup = openerp.web.OldWidget.extend( /** @lends openerp.web.Da
this._super(parent, null);
if (group_by) {
if (group_by.length || context['group_by_no_leaf']) {
return new openerp.web.ContainerDataGroup( this, model, domain, context, group_by, level);
return new instance.web.ContainerDataGroup( this, model, domain, context, group_by, level);
} else {
return new openerp.web.GrouplessDataGroup( this, model, domain, context, level);
return new instance.web.GrouplessDataGroup( this, model, domain, context, level);
}
}
@ -57,11 +57,11 @@ openerp.web.DataGroup = openerp.web.OldWidget.extend( /** @lends openerp.web.Da
},
cls: 'DataGroup'
});
openerp.web.ContainerDataGroup = openerp.web.DataGroup.extend( /** @lends openerp.web.ContainerDataGroup# */ {
instance.web.ContainerDataGroup = instance.web.DataGroup.extend( /** @lends instance.web.ContainerDataGroup# */ {
/**
*
* @constructs openerp.web.ContainerDataGroup
* @extends openerp.web.DataGroup
* @constructs instance.web.ContainerDataGroup
* @extends instance.web.DataGroup
*
* @param session
* @param model
@ -146,7 +146,7 @@ openerp.web.ContainerDataGroup = openerp.web.DataGroup.extend( /** @lends opener
domain: this.domain,
fields: _.uniq(this.group_by.concat(fields)),
group_by_fields: this.group_by,
sort: openerp.web.serialize_sort(this.sort)
sort: instance.web.serialize_sort(this.sort)
}, function () { }).then(function (response) {
var data_groups = _(response).map(
_.bind(self.transform_group, self));
@ -186,7 +186,7 @@ openerp.web.ContainerDataGroup = openerp.web.DataGroup.extend( /** @lends opener
ifGroups(_(group_records).map(function (group) {
var child_context = _.extend({}, self.context, group.__context);
return _.extend(
new openerp.web.DataGroup(
new instance.web.DataGroup(
self, self.model, group.__domain,
child_context, child_context.group_by,
self.level + 1),
@ -195,11 +195,11 @@ openerp.web.ContainerDataGroup = openerp.web.DataGroup.extend( /** @lends opener
});
}
});
openerp.web.GrouplessDataGroup = openerp.web.DataGroup.extend( /** @lends openerp.web.GrouplessDataGroup# */ {
instance.web.GrouplessDataGroup = instance.web.DataGroup.extend( /** @lends instance.web.GrouplessDataGroup# */ {
/**
*
* @constructs openerp.web.GrouplessDataGroup
* @extends openerp.web.DataGroup
* @constructs instance.web.GrouplessDataGroup
* @extends instance.web.DataGroup
*
* @param session
* @param model
@ -212,17 +212,17 @@ openerp.web.GrouplessDataGroup = openerp.web.DataGroup.extend( /** @lends opener
},
list: function (fields, ifGroups, ifRecords) {
ifRecords(_.extend(
new openerp.web.DataSetSearch(this, this.model),
new instance.web.DataSetSearch(this, this.model),
{domain: this.domain, context: this.context, _sort: this.sort}));
}
});
openerp.web.StaticDataGroup = openerp.web.GrouplessDataGroup.extend( /** @lends openerp.web.StaticDataGroup# */ {
instance.web.StaticDataGroup = instance.web.GrouplessDataGroup.extend( /** @lends instance.web.StaticDataGroup# */ {
/**
* A specialization of groupless data groups, relying on a single static
* dataset as its records provider.
*
* @constructs openerp.web.StaticDataGroup
* @extends openerp.web.GrouplessDataGroup
* @constructs instance.web.StaticDataGroup
* @extends instance.web.GrouplessDataGroup
* @param {openep.web.DataSetStatic} dataset a static dataset backing the groups
*/
init: function (dataset) {
@ -233,13 +233,13 @@ openerp.web.StaticDataGroup = openerp.web.GrouplessDataGroup.extend( /** @lends
}
});
openerp.web.DataSet = openerp.web.OldWidget.extend( /** @lends openerp.web.DataSet# */{
instance.web.DataSet = instance.web.OldWidget.extend( /** @lends instance.web.DataSet# */{
/**
* DateaManagement interface between views and the collection of selected
* OpenERP records (represents the view's state?)
*
* @constructs openerp.web.DataSet
* @extends openerp.web.OldWidget
* @constructs instance.web.DataSet
* @extends instance.web.OldWidget
*
* @param {String} model the OpenERP model this dataset will manage
*/
@ -494,7 +494,7 @@ openerp.web.DataSet = openerp.web.OldWidget.extend( /** @lends openerp.web.Data
},
get_context: function(request_context) {
if (request_context) {
return new openerp.web.CompoundContext(this.context, request_context);
return new instance.web.CompoundContext(this.context, request_context);
}
return this.context;
},
@ -513,7 +513,7 @@ openerp.web.DataSet = openerp.web.OldWidget.extend( /** @lends openerp.web.Data
*/
sort: function (field, force_reverse) {
if (!field) {
return openerp.web.serialize_sort(this._sort);
return instance.web.serialize_sort(this._sort);
}
var reverse = force_reverse || (this._sort[0] === field);
this._sort.splice.apply(
@ -530,7 +530,7 @@ openerp.web.DataSet = openerp.web.OldWidget.extend( /** @lends openerp.web.Data
this.ids = n_ids;
},
});
openerp.web.DataSetStatic = openerp.web.DataSet.extend({
instance.web.DataSetStatic = instance.web.DataSet.extend({
init: function(parent, model, context, ids) {
this._super(parent, model, context);
// all local records
@ -560,10 +560,10 @@ openerp.web.DataSetStatic = openerp.web.DataSet.extend({
this.set_ids(_.without.apply(null, [this.ids].concat(ids)));
}
});
openerp.web.DataSetSearch = openerp.web.DataSet.extend(/** @lends openerp.web.DataSetSearch */{
instance.web.DataSetSearch = instance.web.DataSet.extend(/** @lends instance.web.DataSetSearch */{
/**
* @constructs openerp.web.DataSetSearch
* @extends openerp.web.DataSet
* @constructs instance.web.DataSetSearch
* @extends instance.web.DataSet
*
* @param {Object} parent
* @param {String} model
@ -612,7 +612,7 @@ openerp.web.DataSetSearch = openerp.web.DataSet.extend(/** @lends openerp.web.D
},
get_domain: function (other_domain) {
if (other_domain) {
return new openerp.web.CompoundDomain(this.domain, other_domain);
return new instance.web.CompoundDomain(this.domain, other_domain);
}
return this.domain;
},
@ -635,7 +635,7 @@ openerp.web.DataSetSearch = openerp.web.DataSet.extend(/** @lends openerp.web.D
return this._super();
}
});
openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({
instance.web.BufferedDataSet = instance.web.DataSetStatic.extend({
virtual_id_prefix: "one2many_v_id_",
debug_mode: true,
init: function() {
@ -800,9 +800,9 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({
this.on_change();
},
});
openerp.web.BufferedDataSet.virtual_id_regex = /^one2many_v_id_.*$/;
instance.web.BufferedDataSet.virtual_id_regex = /^one2many_v_id_.*$/;
openerp.web.ProxyDataSet = openerp.web.DataSetSearch.extend({
instance.web.ProxyDataSet = instance.web.DataSetSearch.extend({
init: function() {
this._super.apply(this, arguments);
this.create_function = null;
@ -848,13 +848,13 @@ openerp.web.ProxyDataSet = openerp.web.DataSetSearch.extend({
on_unlink: function(ids) {}
});
openerp.web.Model = openerp.web.CallbackEnabled.extend({
instance.web.Model = instance.web.CallbackEnabled.extend({
init: function(model_name) {
this._super();
this.model_name = model_name;
},
rpc: function() {
var c = openerp.connection;
var c = instance.connection;
return c.rpc.apply(c, arguments);
},
/*
@ -876,7 +876,7 @@ openerp.web.Model = openerp.web.CallbackEnabled.extend({
}
});
openerp.web.CompoundContext = openerp.web.Class.extend({
instance.web.CompoundContext = instance.web.Class.extend({
init: function () {
this.__ref = "compound_context";
this.__contexts = [];
@ -899,7 +899,7 @@ openerp.web.CompoundContext = openerp.web.Class.extend({
}
});
openerp.web.CompoundDomain = openerp.web.Class.extend({
instance.web.CompoundDomain = instance.web.Class.extend({
init: function () {
this.__ref = "compound_domain";
this.__domains = [];

View File

@ -1,14 +1,14 @@
openerp.web.data_export = function(openerp) {
var QWeb = openerp.web.qweb,
_t = openerp.web._t;
openerp.web.DataExport = openerp.web.Dialog.extend({
openerp.web.data_export = function(instance) {
var QWeb = instance.web.qweb,
_t = instance.web._t;
instance.web.DataExport = instance.web.Dialog.extend({
template: 'ExportTreeView',
dialog_title: {toString: function () { return _t("Export Data"); }},
init: function(parent, dataset) {
this._super(parent);
this.records = {};
this.dataset = dataset;
this.exports = new openerp.web.DataSetSearch(
this.exports = new instance.web.DataSetSearch(
this, 'ir.exports', this.dataset.get_context());
},
start: function() {

View File

@ -1,6 +1,6 @@
openerp.web.data_import = function(openerp) {
var QWeb = openerp.web.qweb,
_t = openerp.web._t;
openerp.web.data_import = function(instance) {
var QWeb = instance.web.qweb,
_t = instance.web._t;
/**
* Safari does not deal well at all with raw JSON data being returned. As a
* result, we're going to cheat by using a pseudo-jsonp: instead of getting
@ -29,7 +29,7 @@ function jsonp(form, attributes, callback) {
$(form).ajaxSubmit(attributes);
}
openerp.web.DataImport = openerp.web.Dialog.extend({
instance.web.DataImport = instance.web.Dialog.extend({
template: 'ImportDataView',
dialog_title: {toString: function () { return _t("Import Data"); }},
init: function(parent, dataset){
@ -79,10 +79,10 @@ openerp.web.DataImport = openerp.web.Dialog.extend({
this.$element.delegate('fieldset legend', 'click', function() {
$(this).parent().toggleClass('oe-closed');
});
this.ready.push(new openerp.web.DataSet(this, this.model).call(
this.ready.push(new instance.web.DataSet(this, this.model).call(
'fields_get', [], function (fields) {
self.graft_fields(fields);
self.ready.push(new openerp.web.DataSet(self, self.model)
self.ready.push(new instance.web.DataSet(self, self.model)
.default_get(_.pluck(self.fields, 'id')).then(function (fields) {
_.each(fields, function(val, key) {
if (val) {
@ -140,7 +140,7 @@ openerp.web.DataImport = openerp.web.Dialog.extend({
f.fields = [];
// only fetch sub-fields to a depth of 2 levels
if (level < 2) {
self.ready.push(new openerp.web.DataSet(self, field.relation).call(
self.ready.push(new instance.web.DataSet(self, field.relation).call(
'fields_get', [], function (fields) {
self.graft_fields(fields, f, level+1);
}));
@ -151,7 +151,7 @@ openerp.web.DataImport = openerp.web.Dialog.extend({
});
},
toggle_import_button: function (newstate) {
openerp.web.dialog(this.$element, 'widget')
instance.web.dialog(this.$element, 'widget')
.find('.oe-dialog-import-button')
.button('option', 'disabled', !newstate);
},

View File

@ -1,5 +1,5 @@
openerp.web.dates = function(openerp) {
openerp.web.dates = function(instance) {
/**
* Converts a string to a Date javascript object using OpenERP's
@ -11,7 +11,7 @@ openerp.web.dates = function(openerp) {
* @param {String} str A string representing a datetime.
* @returns {Date}
*/
openerp.web.str_to_datetime = function(str) {
instance.web.str_to_datetime = function(str) {
if(!str) {
return str;
}
@ -38,7 +38,7 @@ openerp.web.str_to_datetime = function(str) {
* @param {String} str A string representing a date.
* @returns {Date}
*/
openerp.web.str_to_date = function(str) {
instance.web.str_to_date = function(str) {
if(!str) {
return str;
}
@ -65,7 +65,7 @@ openerp.web.str_to_date = function(str) {
* @param {String} str A string representing a time.
* @returns {Date}
*/
openerp.web.str_to_time = function(str) {
instance.web.str_to_time = function(str) {
if(!str) {
return str;
}
@ -104,7 +104,7 @@ var zpad = function(str, size) {
* @param {Date} obj
* @returns {String} A string representing a datetime.
*/
openerp.web.datetime_to_str = function(obj) {
instance.web.datetime_to_str = function(obj) {
if (!obj) {
return false;
}
@ -124,7 +124,7 @@ openerp.web.datetime_to_str = function(obj) {
* @param {Date} obj
* @returns {String} A string representing a date.
*/
openerp.web.date_to_str = function(obj) {
instance.web.date_to_str = function(obj) {
if (!obj) {
return false;
}
@ -143,7 +143,7 @@ openerp.web.date_to_str = function(obj) {
* @param {Date} obj
* @returns {String} A string representing a time.
*/
openerp.web.time_to_str = function(obj) {
instance.web.time_to_str = function(obj) {
if (!obj) {
return false;
}

View File

@ -1,6 +1,6 @@
openerp.web.formats = function(openerp) {
var _t = openerp.web._t;
openerp.web.formats = function(instance) {
var _t = instance.web._t;
/**
* Intersperses ``separator`` in ``str`` at the positions indicated by
@ -23,7 +23,7 @@ var _t = openerp.web._t;
* @param {String} separator
* @returns {String}
*/
openerp.web.intersperse = function (str, indices, separator) {
instance.web.intersperse = function (str, indices, separator) {
separator = separator || '';
var result = [], last = str.length;
@ -55,10 +55,10 @@ openerp.web.intersperse = function (str, indices, separator) {
* @param {String} num
* @returns {String}
*/
openerp.web.insert_thousand_seps = function (num) {
instance.web.insert_thousand_seps = function (num) {
var negative = num[0] === '-';
num = (negative ? num.slice(1) : num);
return (negative ? '-' : '') + openerp.web.intersperse(
return (negative ? '-' : '') + instance.web.intersperse(
num, _t.database.parameters.grouping, _t.database.parameters.thousands_sep);
};
@ -69,7 +69,7 @@ openerp.web.insert_thousand_seps = function (num) {
*
* @param {String} value original format
*/
openerp.web.strip_raw_chars = function (value) {
instance.web.strip_raw_chars = function (value) {
var isletter = /[a-zA-Z]/, output = [];
for(var index=0; index < value.length; ++index) {
var character = value[index];
@ -81,7 +81,7 @@ openerp.web.strip_raw_chars = function (value) {
return output.join('');
};
var normalize_format = function (format) {
return Date.normalizeFormat(openerp.web.strip_raw_chars(format));
return Date.normalizeFormat(instance.web.strip_raw_chars(format));
};
/**
* Formats a single atomic value based on a field descriptor
@ -93,7 +93,7 @@ var normalize_format = function (format) {
* @param {Object} [descriptor.digits] used for the formatting of floats
* @param {String} [value_if_empty=''] returned if the ``value`` argument is considered empty
*/
openerp.web.format_value = function (value, descriptor, value_if_empty) {
instance.web.format_value = function (value, descriptor, value_if_empty) {
// If NaN value, display as with a `false` (empty cell)
if (typeof value === 'number' && isNaN(value)) {
value = false;
@ -115,12 +115,12 @@ openerp.web.format_value = function (value, descriptor, value_if_empty) {
case 'id':
return value.toString();
case 'integer':
return openerp.web.insert_thousand_seps(
return instance.web.insert_thousand_seps(
_.str.sprintf('%d', value));
case 'float':
var precision = descriptor.digits ? descriptor.digits[1] : 2;
var formatted = _.str.sprintf('%.' + precision + 'f', value).split('.');
formatted[0] = openerp.web.insert_thousand_seps(formatted[0]);
formatted[0] = instance.web.insert_thousand_seps(formatted[0]);
return formatted.join(l10n.decimal_point);
case 'float_time':
var pattern = '%02d:%02d';
@ -136,17 +136,17 @@ openerp.web.format_value = function (value, descriptor, value_if_empty) {
return value[1];
case 'datetime':
if (typeof(value) == "string")
value = openerp.web.auto_str_to_date(value);
value = instance.web.auto_str_to_date(value);
return value.toString(normalize_format(l10n.date_format)
+ ' ' + normalize_format(l10n.time_format));
case 'date':
if (typeof(value) == "string")
value = openerp.web.auto_str_to_date(value);
value = instance.web.auto_str_to_date(value);
return value.toString(normalize_format(l10n.date_format));
case 'time':
if (typeof(value) == "string")
value = openerp.web.auto_str_to_date(value);
value = instance.web.auto_str_to_date(value);
return value.toString(normalize_format(l10n.time_format));
case 'selection': case 'statusbar':
// Each choice is [value, label]
@ -163,7 +163,7 @@ openerp.web.format_value = function (value, descriptor, value_if_empty) {
}
};
openerp.web.parse_value = function (value, descriptor, value_if_empty) {
instance.web.parse_value = function (value, descriptor, value_if_empty) {
var date_pattern = normalize_format(_t.database.parameters.date_format),
time_pattern = normalize_format(_t.database.parameters.time_format);
switch (value) {
@ -176,7 +176,7 @@ openerp.web.parse_value = function (value, descriptor, value_if_empty) {
var tmp;
do {
tmp = value;
value = value.replace(openerp.web._t.database.parameters.thousands_sep, "");
value = value.replace(instance.web._t.database.parameters.thousands_sep, "");
} while(tmp !== value);
tmp = Number(value);
if (isNaN(tmp))
@ -190,9 +190,9 @@ openerp.web.parse_value = function (value, descriptor, value_if_empty) {
var tmp2 = value;
do {
tmp = tmp2;
tmp2 = tmp.replace(openerp.web._t.database.parameters.thousands_sep, "");
tmp2 = tmp.replace(instance.web._t.database.parameters.thousands_sep, "");
} while(tmp !== tmp2);
var reformatted_value = tmp.replace(openerp.web._t.database.parameters.decimal_point, ".");
var reformatted_value = tmp.replace(instance.web._t.database.parameters.decimal_point, ".");
var parsed = Number(reformatted_value);
if (isNaN(parsed))
throw new Error(value + " is not a correct float");
@ -205,62 +205,62 @@ openerp.web.parse_value = function (value, descriptor, value_if_empty) {
}
var float_time_pair = value.split(":");
if (float_time_pair.length != 2)
return factor * openerp.web.parse_value(value, {type: "float"});
var hours = openerp.web.parse_value(float_time_pair[0], {type: "integer"});
var minutes = openerp.web.parse_value(float_time_pair[1], {type: "integer"});
return factor * instance.web.parse_value(value, {type: "float"});
var hours = instance.web.parse_value(float_time_pair[0], {type: "integer"});
var minutes = instance.web.parse_value(float_time_pair[1], {type: "integer"});
return factor * (hours + (minutes / 60));
case 'progressbar':
return openerp.web.parse_value(value, {type: "float"});
return instance.web.parse_value(value, {type: "float"});
case 'datetime':
var datetime = Date.parseExact(
value, (date_pattern + ' ' + time_pattern));
if (datetime !== null)
return openerp.web.datetime_to_str(datetime);
return instance.web.datetime_to_str(datetime);
datetime = Date.parse(value);
if (datetime !== null)
return openerp.web.datetime_to_str(datetime);
return instance.web.datetime_to_str(datetime);
throw new Error(value + " is not a valid datetime");
case 'date':
var date = Date.parseExact(value, date_pattern);
if (date !== null)
return openerp.web.date_to_str(date);
return instance.web.date_to_str(date);
date = Date.parse(value);
if (date !== null)
return openerp.web.date_to_str(date);
return instance.web.date_to_str(date);
throw new Error(value + " is not a valid date");
case 'time':
var time = Date.parseExact(value, time_pattern);
if (time !== null)
return openerp.web.time_to_str(time);
return instance.web.time_to_str(time);
time = Date.parse(value);
if (time !== null)
return openerp.web.time_to_str(time);
return instance.web.time_to_str(time);
throw new Error(value + " is not a valid time");
}
return value;
};
openerp.web.auto_str_to_date = function(value, type) {
instance.web.auto_str_to_date = function(value, type) {
try {
return openerp.web.str_to_datetime(value);
return instance.web.str_to_datetime(value);
} catch(e) {}
try {
return openerp.web.str_to_date(value);
return instance.web.str_to_date(value);
} catch(e) {}
try {
return openerp.web.str_to_time(value);
return instance.web.str_to_time(value);
} catch(e) {}
throw new Error("'" + value + "' is not a valid date, datetime nor time");
};
openerp.web.auto_date_to_str = function(value, type) {
instance.web.auto_date_to_str = function(value, type) {
switch(type) {
case 'datetime':
return openerp.web.datetime_to_str(value);
return instance.web.datetime_to_str(value);
case 'date':
return openerp.web.date_to_str(value);
return instance.web.date_to_str(value);
case 'time':
return openerp.web.time_to_str(value);
return instance.web.time_to_str(value);
default:
throw new Error(type + " is not convertible to date, datetime nor time");
}
@ -290,7 +290,7 @@ openerp.web.auto_date_to_str = function(value, type) {
* @param {Number} [options.id] current record's id
*
*/
openerp.web.format_cell = function (row_data, column, options) {
instance.web.format_cell = function (row_data, column, options) {
options = options || {};
var attrs = {};
if (options.process_modifiers !== false) {
@ -303,9 +303,9 @@ openerp.web.format_cell = function (row_data, column, options) {
'<img src="<%-prefix%>/web/static/src/img/icons/<%-icon%>.png" alt="<%-alt%>"/>' +
'</button>', {
title: column.string || '',
additional_attributes: isNaN(row_data["id"].value) && openerp.web.BufferedDataSet.virtual_id_regex.test(row_data["id"].value) ?
additional_attributes: isNaN(row_data["id"].value) && instance.web.BufferedDataSet.virtual_id_regex.test(row_data["id"].value) ?
'disabled="disabled" class="oe-listview-button-disabled"' : '',
prefix: openerp.connection.prefix,
prefix: instance.connection.prefix,
icon: column.icon,
alt: column.string || ''
});
@ -320,11 +320,11 @@ openerp.web.format_cell = function (row_data, column, options) {
row_data[column.id].value ? 'checked="checked"' : '');
case "binary":
var text = _t("Download"),
download_url = _.str.sprintf('/web/binary/saveas?session_id=%s&model=%s&field=%s&id=%d', openerp.connection.session_id, options.model, column.id, options.id);
download_url = _.str.sprintf('/web/binary/saveas?session_id=%s&model=%s&field=%s&id=%d', instance.connection.session_id, options.model, column.id, options.id);
if (column.filename) {
download_url += '&filename_field=' + column.filename;
if (row_data[column.filename]) {
text = _.str.sprintf(_t("Download \"%s\""), openerp.web.format_value(
text = _.str.sprintf(_t("Download \"%s\""), instance.web.format_value(
row_data[column.filename].value, {type: 'char'}));
}
}
@ -340,7 +340,7 @@ openerp.web.format_cell = function (row_data, column, options) {
});
}
return _.escape(openerp.web.format_value(
return _.escape(instance.web.format_value(
row_data[column.id].value, column, options.value_if_empty));
}

View File

@ -1,7 +1,7 @@
openerp.web.search = function(openerp) {
var QWeb = openerp.web.qweb,
_t = openerp.web._t,
_lt = openerp.web._lt;
openerp.web.search = function(instance) {
var QWeb = instance.web.qweb,
_t = instance.web._t,
_lt = instance.web._lt;
_.mixin({
sum: function (obj) { return _.reduce(obj, function (a, b) { return a + b; }, 0); }
});
@ -70,11 +70,11 @@ _.extend(VS.model.SearchFacet.prototype, {
}
});
openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.SearchView# */{
instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.SearchView# */{
template: "SearchView",
/**
* @constructs openerp.web.SearchView
* @extends openerp.web.OldWidget
* @constructs instance.web.SearchView
* @extends instance.web.OldWidget
*
* @param parent
* @param element_id
@ -178,7 +178,7 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
var running_count = 0;
// get total filters count
var is_group = function (i) { return i instanceof openerp.web.search.FilterGroup; };
var is_group = function (i) { return i instanceof instance.web.search.FilterGroup; };
var filters_count = _(this.controls).chain()
.flatten()
.filter(is_group)
@ -212,12 +212,12 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
name: _t("Custom Filters"),
filters: _.map(this.custom_filters, function (filter) {
// FIXME: handling of ``disabled`` being set
var f = new openerp.web.search.Filter({attrs: {
var f = new instance.web.search.Filter({attrs: {
string: filter.name,
context: filter.context,
domain: filter.domain
}}, self);
return new openerp.web.search.FilterGroup([f], self);
return new instance.web.search.FilterGroup([f], self);
}),
length: 3
});
@ -225,7 +225,7 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
return $.when(
this.render_column(col1, $('<div>').appendTo($filters)),
this.render_column(col2, $('<div>').appendTo($filters)),
(new openerp.web.search.Advanced(this).appendTo($drawer)));
(new instance.web.search.Advanced(this).appendTo($drawer)));
},
render_column: function (column, $el) {
return $.when.apply(null, _(column).map(function (group) {
@ -314,10 +314,10 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
* @param {VS.model.SearchFacet} options.model facet object to render
*/
make_visualsearch_facet: function (options) {
return new openerp.web.search.FilterGroupFacet(options);
return new instance.web.search.FilterGroupFacet(options);
// if (options.model.get('field') instanceof openerp.web.search.FilterGroup) {
// return new openerp.web.search.FilterGroupFacet(options);
// if (options.model.get('field') instanceof instance.web.search.FilterGroup) {
// return new instance.web.search.FilterGroupFacet(options);
// }
// return new VS.ui.SearchFacet(options);
},
@ -363,7 +363,7 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
var filters = [];
_.each(items, function (item) {
if (filters.length && item.tag !== 'filter') {
group.push(new openerp.web.search.FilterGroup(filters, this));
group.push(new instance.web.search.FilterGroup(filters, this));
filters = [];
}
@ -371,7 +371,7 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
case 'separator': case 'newline':
break;
case 'filter':
filters.push(new openerp.web.search.Filter(item, this));
filters.push(new instance.web.search.Filter(item, this));
break;
case 'group':
self.make_widgets(item.children, fields, item.attrs.string);
@ -385,7 +385,7 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
}, this);
if (filters.length) {
group.push(new openerp.web.search.FilterGroup(filters, this));
group.push(new instance.web.search.FilterGroup(filters, this));
}
},
/**
@ -394,10 +394,10 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
*
* @param {Object} item fields_view_get node for the field
* @param {Object} field fields_get result for the field
* @returns openerp.web.search.Field
* @returns instance.web.search.Field
*/
make_field: function (item, field) {
var obj = openerp.web.search.fields.get_any( [item.attrs.widget, field.type]);
var obj = instance.web.search.fields.get_any( [item.attrs.widget, field.type]);
if(obj) {
return new (obj) (item, field, this);
} else {
@ -460,11 +460,11 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
break;
case 'save_filter':
var data = this.build_search_data();
var context = new openerp.web.CompoundContext();
var context = new instance.web.CompoundContext();
_.each(data.contexts, function(x) {
context.add(x);
});
var domain = new openerp.web.CompoundDomain();
var domain = new instance.web.CompoundDomain();
_.each(data.domains, function(x) {
domain.add(x);
});
@ -472,7 +472,7 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
context.add({"group_by": groupbys});
var dial_html = QWeb.render("SearchView.managed-filters.add");
var $dial = $(dial_html);
openerp.web.dialog($dial, {
instance.web.dialog($dial, {
modal: true,
title: _t("Filter Entry"),
buttons: [
@ -525,13 +525,13 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
on_add_to_dashboard: function() {
this.$element.find(".oe_search-view-filters-management")[0].selectedIndex = 0;
var self = this,
menu = openerp.webclient.menu,
menu = instance.webclient.menu,
$dialog = $(QWeb.render("SearchView.add_to_dashboard", {
dashboards : menu.data.data.children,
selected_menu_id : menu.$element.find('a.active').data('menu')
}));
$dialog.find('input').val(this.fields_view.name);
openerp.web.dialog($dialog, {
instance.web.dialog($dialog, {
modal: true,
title: _t("Add to Dashboard"),
buttons: [
@ -543,8 +543,8 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
var menu_id = $(this).find("select").val(),
title = $(this).find("input").val(),
data = self.build_search_data(),
context = new openerp.web.CompoundContext(),
domain = new openerp.web.CompoundDomain();
context = new instance.web.CompoundContext(),
domain = new instance.web.CompoundDomain();
_.each(data.contexts, function(x) {
context.add(x);
});
@ -573,10 +573,10 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
* Performs the search view collection of widget data.
*
* If the collection went well (all fields are valid), then triggers
* :js:func:`openerp.web.SearchView.on_search`.
* :js:func:`instance.web.SearchView.on_search`.
*
* If at least one field failed its validation, triggers
* :js:func:`openerp.web.SearchView.on_invalid` instead.
* :js:func:`instance.web.SearchView.on_invalid` instead.
*
* @param e jQuery event object coming from the "Search" button
*/
@ -599,7 +599,7 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
groupbys.push.apply(groupbys, group_by);
}
} catch (e) {
if (e instanceof openerp.web.search.Invalid) {
if (e instanceof instance.web.search.Invalid) {
errors.push(e);
} else {
throw e;
@ -648,9 +648,9 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
});
/** @namespace */
openerp.web.search = {};
instance.web.search = {};
openerp.web.search.FilterGroupFacet = VS.ui.SearchFacet.extend({
instance.web.search.FilterGroupFacet = VS.ui.SearchFacet.extend({
events: _.extend({
'click': 'selectFacet'
}, VS.ui.SearchFacet.prototype.events),
@ -682,30 +682,30 @@ openerp.web.search.FilterGroupFacet = VS.ui.SearchFacet.extend({
}
});
/**
* Registry of search fields, called by :js:class:`openerp.web.SearchView` to
* Registry of search fields, called by :js:class:`instance.web.SearchView` to
* find and instantiate its field widgets.
*/
openerp.web.search.fields = new openerp.web.Registry({
'char': 'openerp.web.search.CharField',
'text': 'openerp.web.search.CharField',
'boolean': 'openerp.web.search.BooleanField',
'integer': 'openerp.web.search.IntegerField',
'id': 'openerp.web.search.IntegerField',
'float': 'openerp.web.search.FloatField',
'selection': 'openerp.web.search.SelectionField',
'datetime': 'openerp.web.search.DateTimeField',
'date': 'openerp.web.search.DateField',
'many2one': 'openerp.web.search.ManyToOneField',
'many2many': 'openerp.web.search.CharField',
'one2many': 'openerp.web.search.CharField'
instance.web.search.fields = new instance.web.Registry({
'char': 'instance.web.search.CharField',
'text': 'instance.web.search.CharField',
'boolean': 'instance.web.search.BooleanField',
'integer': 'instance.web.search.IntegerField',
'id': 'instance.web.search.IntegerField',
'float': 'instance.web.search.FloatField',
'selection': 'instance.web.search.SelectionField',
'datetime': 'instance.web.search.DateTimeField',
'date': 'instance.web.search.DateField',
'many2one': 'instance.web.search.ManyToOneField',
'many2many': 'instance.web.search.CharField',
'one2many': 'instance.web.search.CharField'
});
openerp.web.search.Invalid = openerp.web.Class.extend( /** @lends openerp.web.search.Invalid# */{
instance.web.search.Invalid = instance.web.Class.extend( /** @lends instance.web.search.Invalid# */{
/**
* Exception thrown by search widgets when they hold invalid values,
* which they can not return when asked.
*
* @constructs openerp.web.search.Invalid
* @extends openerp.web.Class
* @constructs instance.web.search.Invalid
* @extends instance.web.Class
*
* @param field the name of the field holding an invalid value
* @param value the invalid value
@ -723,13 +723,13 @@ openerp.web.search.Invalid = openerp.web.Class.extend( /** @lends openerp.web.se
);
}
});
openerp.web.search.Widget = openerp.web.OldWidget.extend( /** @lends openerp.web.search.Widget# */{
instance.web.search.Widget = instance.web.OldWidget.extend( /** @lends instance.web.search.Widget# */{
template: null,
/**
* Root class of all search widgets
*
* @constructs openerp.web.search.Widget
* @extends openerp.web.OldWidget
* @constructs instance.web.search.Widget
* @extends instance.web.OldWidget
*
* @param view the ancestor view of this widget
*/
@ -738,14 +738,14 @@ openerp.web.search.Widget = openerp.web.OldWidget.extend( /** @lends openerp.web
this.view = view;
}
});
openerp.web.search.add_expand_listener = function($root) {
instance.web.search.add_expand_listener = function($root) {
$root.find('a.searchview_group_string').click(function (e) {
$root.toggleClass('folded expanded');
e.stopPropagation();
e.preventDefault();
});
};
openerp.web.search.Group = openerp.web.search.Widget.extend({
instance.web.search.Group = instance.web.search.Widget.extend({
template: 'SearchView.group',
init: function (view_section, view, fields) {
this._super(view);
@ -755,10 +755,10 @@ openerp.web.search.Group = openerp.web.search.Widget.extend({
}
});
openerp.web.search.Input = openerp.web.search.Widget.extend( /** @lends openerp.web.search.Input# */{
instance.web.search.Input = instance.web.search.Widget.extend( /** @lends instance.web.search.Input# */{
/**
* @constructs openerp.web.search.Input
* @extends openerp.web.search.Widget
* @constructs instance.web.search.Input
* @extends instance.web.search.Widget
*
* @param view
*/
@ -784,7 +784,7 @@ openerp.web.search.Input = openerp.web.search.Widget.extend( /** @lends openerp.
* they apply to this widget, or null if they don't.
*
* This default implementation will try calling
* :js:func:`openerp.web.search.Input#facet_for` if the widget's name
* :js:func:`instance.web.search.Input#facet_for` if the widget's name
* matches the input key
*
* @param {Object} defaults
@ -820,17 +820,17 @@ openerp.web.search.Input = openerp.web.search.Widget.extend( /** @lends openerp.
this.attrs = attrs;
}
});
openerp.web.search.FilterGroup = openerp.web.search.Input.extend(/** @lends openerp.web.search.FilterGroup# */{
instance.web.search.FilterGroup = instance.web.search.Input.extend(/** @lends instance.web.search.FilterGroup# */{
template: 'SearchView.filters',
/**
* Inclusive group of filters, creates a continuous "button" with clickable
* sections (the normal display for filters is to be a self-contained button)
*
* @constructs openerp.web.search.FilterGroup
* @extends openerp.web.search.Input
* @constructs instance.web.search.FilterGroup
* @extends instance.web.search.Input
*
* @param {Array<openerp.web.search.Filter>} filters elements of the group
* @param {openerp.web.SearchView} view view in which the filters are contained
* @param {Array<instance.web.search.Filter>} filters elements of the group
* @param {instance.web.SearchView} view view in which the filters are contained
*/
init: function (filters, view) {
this._super(view);
@ -868,7 +868,7 @@ openerp.web.search.FilterGroup = openerp.web.search.Input.extend(/** @lends open
if (!contexts.length) { return; }
if (contexts.length === 1) { return contexts[0]; }
return _.extend(new openerp.web.CompoundContext, {
return _.extend(new instance.web.CompoundContext, {
__contexts: contexts
});
},
@ -901,7 +901,7 @@ openerp.web.search.FilterGroup = openerp.web.search.Input.extend(/** @lends open
for (var i=domains.length; --i;) {
domains.unshift(['|']);
}
return _.extend(new openerp.web.CompoundDomain(), {
return _.extend(new instance.web.CompoundDomain(), {
__domains: domains
});
},
@ -945,7 +945,7 @@ openerp.web.search.FilterGroup = openerp.web.search.Input.extend(/** @lends open
});
}
});
openerp.web.search.Filter = openerp.web.search.Input.extend(/** @lends openerp.web.search.Filter# */{
instance.web.search.Filter = instance.web.search.Input.extend(/** @lends instance.web.search.Filter# */{
template: 'SearchView.filter',
/**
* Implementation of the OpenERP filters (button with a context and/or
@ -955,8 +955,8 @@ openerp.web.search.Filter = openerp.web.search.Input.extend(/** @lends openerp.w
* domains and contexts, converting between facets and filters) is
* performed by the filter group.
*
* @constructs openerp.web.search.Filter
* @extends openerp.web.search.Input
* @constructs instance.web.search.Filter
* @extends instance.web.search.Input
*
* @param node
* @param view
@ -969,12 +969,12 @@ openerp.web.search.Filter = openerp.web.search.Input.extend(/** @lends openerp.w
get_context: function () { },
get_domain: function () { },
});
openerp.web.search.Field = openerp.web.search.Input.extend( /** @lends openerp.web.search.Field# */ {
instance.web.search.Field = instance.web.search.Input.extend( /** @lends instance.web.search.Field# */ {
template: 'SearchView.field',
default_operator: '=',
/**
* @constructs openerp.web.search.Field
* @extends openerp.web.search.Input
* @constructs instance.web.search.Field
* @extends instance.web.search.Input
*
* @param view_section
* @param field
@ -1005,7 +1005,7 @@ openerp.web.search.Field = openerp.web.search.Input.extend( /** @lends openerp.w
if (!(has_value && context)) {
return;
}
return new openerp.web.CompoundContext(context)
return new instance.web.CompoundContext(context)
.set_eval_context({self: val});
},
get_groupby: function () { },
@ -1036,7 +1036,7 @@ openerp.web.search.Field = openerp.web.search.Input.extend( /** @lends openerp.w
this.attrs.operator || this.default_operator,
facet);
}
return new openerp.web.CompoundDomain(domain)
return new instance.web.CompoundDomain(domain)
.set_eval_context({self: val});
}
});
@ -1048,9 +1048,9 @@ openerp.web.search.Field = openerp.web.search.Input.extend( /** @lends openerp.w
* * The Javascript and the HTML values are identical (strings)
*
* @class
* @extends openerp.web.search.Field
* @extends instance.web.search.Field
*/
openerp.web.search.CharField = openerp.web.search.Field.extend( /** @lends openerp.web.search.CharField# */ {
instance.web.search.CharField = instance.web.search.Field.extend( /** @lends instance.web.search.CharField# */ {
default_operator: 'ilike',
complete: function (value) {
if (_.isEmpty(value)) { return $.when(null); }
@ -1066,7 +1066,7 @@ openerp.web.search.CharField = openerp.web.search.Field.extend( /** @lends opene
}]);
}
});
openerp.web.search.NumberField = openerp.web.search.Field.extend(/** @lends openerp.web.search.NumberField# */{
instance.web.search.NumberField = instance.web.search.Field.extend(/** @lends instance.web.search.NumberField# */{
get_value: function () {
if (!this.$element.val()) {
return null;
@ -1075,7 +1075,7 @@ openerp.web.search.NumberField = openerp.web.search.Field.extend(/** @lends open
check = Number(this.$element.val());
if (isNaN(val) || val !== check) {
this.$element.addClass('error');
throw new openerp.web.search.Invalid(
throw new instance.web.search.Invalid(
this.attrs.name, this.$element.val(), this.error_message);
}
this.$element.removeClass('error');
@ -1084,13 +1084,13 @@ openerp.web.search.NumberField = openerp.web.search.Field.extend(/** @lends open
});
/**
* @class
* @extends openerp.web.search.NumberField
* @extends instance.web.search.NumberField
*/
openerp.web.search.IntegerField = openerp.web.search.NumberField.extend(/** @lends openerp.web.search.IntegerField# */{
instance.web.search.IntegerField = instance.web.search.NumberField.extend(/** @lends instance.web.search.IntegerField# */{
error_message: _t("not a valid integer"),
parse: function (value) {
try {
return openerp.web.parse_value(value, {'widget': 'integer'});
return instance.web.parse_value(value, {'widget': 'integer'});
} catch (e) {
return NaN;
}
@ -1098,13 +1098,13 @@ openerp.web.search.IntegerField = openerp.web.search.NumberField.extend(/** @len
});
/**
* @class
* @extends openerp.web.search.NumberField
* @extends instance.web.search.NumberField
*/
openerp.web.search.FloatField = openerp.web.search.NumberField.extend(/** @lends openerp.web.search.FloatField# */{
instance.web.search.FloatField = instance.web.search.NumberField.extend(/** @lends instance.web.search.FloatField# */{
error_message: _t("not a valid number"),
parse: function (value) {
try {
return openerp.web.parse_value(value, {'widget': 'float'});
return instance.web.parse_value(value, {'widget': 'float'});
} catch (e) {
return NaN;
}
@ -1112,9 +1112,9 @@ openerp.web.search.FloatField = openerp.web.search.NumberField.extend(/** @lends
});
/**
* @class
* @extends openerp.web.search.Field
* @extends instance.web.search.Field
*/
openerp.web.search.SelectionField = openerp.web.search.Field.extend(/** @lends openerp.web.search.SelectionField# */{
instance.web.search.SelectionField = instance.web.search.Field.extend(/** @lends instance.web.search.SelectionField# */{
// This implementation is a basic <select> field, but it may have to be
// altered to be more in line with the GTK client, which uses a combo box
// (~ jquery.autocomplete):
@ -1171,10 +1171,10 @@ openerp.web.search.SelectionField = openerp.web.search.Field.extend(/** @lends o
return facet.get('json');
}
});
openerp.web.search.BooleanField = openerp.web.search.SelectionField.extend(/** @lends openerp.web.search.BooleanField# */{
instance.web.search.BooleanField = instance.web.search.SelectionField.extend(/** @lends instance.web.search.BooleanField# */{
/**
* @constructs openerp.web.search.BooleanField
* @extends openerp.web.search.BooleanField
* @constructs instance.web.search.BooleanField
* @extends instance.web.search.BooleanField
*/
init: function () {
this._super.apply(this, arguments);
@ -1193,16 +1193,16 @@ openerp.web.search.BooleanField = openerp.web.search.SelectionField.extend(/** @
});
/**
* @class
* @extends openerp.web.search.DateField
* @extends instance.web.search.DateField
*/
openerp.web.search.DateField = openerp.web.search.Field.extend(/** @lends openerp.web.search.DateField# */{
instance.web.search.DateField = instance.web.search.Field.extend(/** @lends instance.web.search.DateField# */{
get_value: function (facet) {
return openerp.web.date_to_str(facet.get('json'));
return instance.web.date_to_str(facet.get('json'));
},
complete: function (needle) {
var d = Date.parse(needle);
if (!d) { return $.when(null); }
var value = openerp.web.format_value(d, this.attrs);
var value = instance.web.format_value(d, this.attrs);
var label = _.str.sprintf(_.str.escapeHTML(
_t("Search %(field)s at: %(value)s")), {
field: '<em>' + this.attrs.string + '</em>',
@ -1225,17 +1225,17 @@ openerp.web.search.DateField = openerp.web.search.Field.extend(/** @lends opener
* spanning the whole day selected by the date widget
*
* @class
* @extends openerp.web.DateField
* @extends instance.web.DateField
*/
openerp.web.search.DateTimeField = openerp.web.search.DateField.extend(/** @lends openerp.web.search.DateTimeField# */{
instance.web.search.DateTimeField = instance.web.search.DateField.extend(/** @lends instance.web.search.DateTimeField# */{
get_value: function (facet) {
return openerp.web.datetime_to_str(facet.get('json'));
return instance.web.datetime_to_str(facet.get('json'));
}
});
openerp.web.search.ManyToOneField = openerp.web.search.CharField.extend({
instance.web.search.ManyToOneField = instance.web.search.CharField.extend({
init: function (view_section, field, view) {
this._super(view_section, field, view);
this.model = new openerp.web.Model(this.attrs.relation);
this.model = new instance.web.Model(this.attrs.relation);
},
complete: function (needle) {
var self = this;
@ -1289,7 +1289,7 @@ openerp.web.search.ManyToOneField = openerp.web.search.CharField.extend({
}
});
openerp.web.search.Advanced = openerp.web.search.Input.extend({
instance.web.search.Advanced = instance.web.search.Input.extend({
template: 'SearchView.advanced',
start: function () {
var self = this;
@ -1314,7 +1314,7 @@ openerp.web.search.Advanced = openerp.web.search.Input.extend({
});
},
append_proposition: function () {
return (new openerp.web.search.ExtendedSearchProposition(this, this.fields))
return (new instance.web.search.ExtendedSearchProposition(this, this.fields))
.appendTo(this.$element.find('ul'));
},
commit_search: function () {
@ -1323,14 +1323,14 @@ openerp.web.search.Advanced = openerp.web.search.Input.extend({
var children = this.getChildren(),
domain = _.invoke(children, 'get_proposition');
var filters = _(domain).map(function (section) {
return new openerp.web.search.Filter({attrs: {
return new instance.web.search.Filter({attrs: {
string: _.str.sprintf('%s(%s)%s',
section[0], section[1], section[2]),
domain: [section]
}}, self.view);
});
// Create Filter (& FilterGroup around it) with that domain
var f = new openerp.web.search.FilterGroup(filters, this.view);
var f = new instance.web.search.FilterGroup(filters, this.view);
// add group to query
this.view.vs.searchQuery.add({
category: _t("Advanced"),
@ -1349,11 +1349,11 @@ openerp.web.search.Advanced = openerp.web.search.Input.extend({
}
});
openerp.web.search.ExtendedSearchProposition = openerp.web.OldWidget.extend(/** @lends openerp.web.search.ExtendedSearchProposition# */{
instance.web.search.ExtendedSearchProposition = instance.web.OldWidget.extend(/** @lends instance.web.search.ExtendedSearchProposition# */{
template: 'SearchView.extended_search.proposition',
/**
* @constructs openerp.web.search.ExtendedSearchProposition
* @extends openerp.web.OldWidget
* @constructs instance.web.search.ExtendedSearchProposition
* @extends instance.web.OldWidget
*
* @param parent
* @param fields
@ -1401,10 +1401,10 @@ openerp.web.search.ExtendedSearchProposition = openerp.web.OldWidget.extend(/**
}
var type = field.type;
var obj = openerp.web.search.custom_filters.get_object(type);
var obj = instance.web.search.custom_filters.get_object(type);
if(obj === null) {
console.log('Unknow field type ' + e.key);
obj = openerp.web.search.custom_filters.get_object("char");
obj = instance.web.search.custom_filters.get_object("char");
}
this.value = new (obj) (this);
if(this.value.set_field) {
@ -1430,12 +1430,12 @@ openerp.web.search.ExtendedSearchProposition = openerp.web.OldWidget.extend(/**
}
});
openerp.web.search.ExtendedSearchProposition.Field = openerp.web.OldWidget.extend({
instance.web.search.ExtendedSearchProposition.Field = instance.web.OldWidget.extend({
start: function () {
this.$element = $("#" + this.element_id);
}
});
openerp.web.search.ExtendedSearchProposition.Char = openerp.web.search.ExtendedSearchProposition.Field.extend({
instance.web.search.ExtendedSearchProposition.Char = instance.web.search.ExtendedSearchProposition.Field.extend({
template: 'SearchView.extended_search.proposition.char',
operators: [
{value: "ilike", text: _lt("contains")},
@ -1447,7 +1447,7 @@ openerp.web.search.ExtendedSearchProposition.Char = openerp.web.search.ExtendedS
return this.$element.val();
}
});
openerp.web.search.ExtendedSearchProposition.DateTime = openerp.web.search.ExtendedSearchProposition.Field.extend({
instance.web.search.ExtendedSearchProposition.DateTime = instance.web.search.ExtendedSearchProposition.Field.extend({
template: 'SearchView.extended_search.proposition.empty',
operators: [
{value: "=", text: _lt("is equal to")},
@ -1462,11 +1462,11 @@ openerp.web.search.ExtendedSearchProposition.DateTime = openerp.web.search.Exten
},
start: function() {
this._super();
this.datewidget = new openerp.web.DateTimeWidget(this);
this.datewidget = new instance.web.DateTimeWidget(this);
this.datewidget.prependTo(this.$element);
}
});
openerp.web.search.ExtendedSearchProposition.Date = openerp.web.search.ExtendedSearchProposition.Field.extend({
instance.web.search.ExtendedSearchProposition.Date = instance.web.search.ExtendedSearchProposition.Field.extend({
template: 'SearchView.extended_search.proposition.empty',
operators: [
{value: "=", text: _lt("is equal to")},
@ -1481,11 +1481,11 @@ openerp.web.search.ExtendedSearchProposition.Date = openerp.web.search.ExtendedS
},
start: function() {
this._super();
this.datewidget = new openerp.web.DateWidget(this);
this.datewidget = new instance.web.DateWidget(this);
this.datewidget.prependTo(this.$element);
}
});
openerp.web.search.ExtendedSearchProposition.Integer = openerp.web.search.ExtendedSearchProposition.Field.extend({
instance.web.search.ExtendedSearchProposition.Integer = instance.web.search.ExtendedSearchProposition.Field.extend({
template: 'SearchView.extended_search.proposition.integer',
operators: [
{value: "=", text: _lt("is equal to")},
@ -1497,16 +1497,16 @@ openerp.web.search.ExtendedSearchProposition.Integer = openerp.web.search.Extend
],
get_value: function() {
try {
return openerp.web.parse_value(this.$element.val(), {'widget': 'integer'});
return instance.web.parse_value(this.$element.val(), {'widget': 'integer'});
} catch (e) {
return "";
}
}
});
openerp.web.search.ExtendedSearchProposition.Id = openerp.web.search.ExtendedSearchProposition.Integer.extend({
instance.web.search.ExtendedSearchProposition.Id = instance.web.search.ExtendedSearchProposition.Integer.extend({
operators: [{value: "=", text: _lt("is")}]
});
openerp.web.search.ExtendedSearchProposition.Float = openerp.web.search.ExtendedSearchProposition.Field.extend({
instance.web.search.ExtendedSearchProposition.Float = instance.web.search.ExtendedSearchProposition.Field.extend({
template: 'SearchView.extended_search.proposition.float',
operators: [
{value: "=", text: _lt("is equal to")},
@ -1518,13 +1518,13 @@ openerp.web.search.ExtendedSearchProposition.Float = openerp.web.search.Extended
],
get_value: function() {
try {
return openerp.web.parse_value(this.$element.val(), {'widget': 'float'});
return instance.web.parse_value(this.$element.val(), {'widget': 'float'});
} catch (e) {
return "";
}
}
});
openerp.web.search.ExtendedSearchProposition.Selection = openerp.web.search.ExtendedSearchProposition.Field.extend({
instance.web.search.ExtendedSearchProposition.Selection = instance.web.search.ExtendedSearchProposition.Field.extend({
template: 'SearchView.extended_search.proposition.selection',
operators: [
{value: "=", text: _lt("is")},
@ -1537,7 +1537,7 @@ openerp.web.search.ExtendedSearchProposition.Selection = openerp.web.search.Exte
return this.$element.val();
}
});
openerp.web.search.ExtendedSearchProposition.Boolean = openerp.web.search.ExtendedSearchProposition.Field.extend({
instance.web.search.ExtendedSearchProposition.Boolean = instance.web.search.ExtendedSearchProposition.Field.extend({
template: 'SearchView.extended_search.proposition.boolean',
operators: [
{value: "=", text: _lt("is true")},
@ -1548,21 +1548,21 @@ openerp.web.search.ExtendedSearchProposition.Boolean = openerp.web.search.Extend
}
});
openerp.web.search.custom_filters = new openerp.web.Registry({
'char': 'openerp.web.search.ExtendedSearchProposition.Char',
'text': 'openerp.web.search.ExtendedSearchProposition.Char',
'one2many': 'openerp.web.search.ExtendedSearchProposition.Char',
'many2one': 'openerp.web.search.ExtendedSearchProposition.Char',
'many2many': 'openerp.web.search.ExtendedSearchProposition.Char',
instance.web.search.custom_filters = new instance.web.Registry({
'char': 'instance.web.search.ExtendedSearchProposition.Char',
'text': 'instance.web.search.ExtendedSearchProposition.Char',
'one2many': 'instance.web.search.ExtendedSearchProposition.Char',
'many2one': 'instance.web.search.ExtendedSearchProposition.Char',
'many2many': 'instance.web.search.ExtendedSearchProposition.Char',
'datetime': 'openerp.web.search.ExtendedSearchProposition.DateTime',
'date': 'openerp.web.search.ExtendedSearchProposition.Date',
'integer': 'openerp.web.search.ExtendedSearchProposition.Integer',
'float': 'openerp.web.search.ExtendedSearchProposition.Float',
'boolean': 'openerp.web.search.ExtendedSearchProposition.Boolean',
'selection': 'openerp.web.search.ExtendedSearchProposition.Selection',
'datetime': 'instance.web.search.ExtendedSearchProposition.DateTime',
'date': 'instance.web.search.ExtendedSearchProposition.Date',
'integer': 'instance.web.search.ExtendedSearchProposition.Integer',
'float': 'instance.web.search.ExtendedSearchProposition.Float',
'boolean': 'instance.web.search.ExtendedSearchProposition.Boolean',
'selection': 'instance.web.search.ExtendedSearchProposition.Selection',
'id': 'openerp.web.search.ExtendedSearchProposition.Id'
'id': 'instance.web.search.ExtendedSearchProposition.Id'
});
};

View File

@ -1,15 +1,15 @@
openerp.web.view_editor = function(openerp) {
var _t = openerp.web._t;
var QWeb = openerp.web.qweb;
openerp.web.ViewEditor = openerp.web.OldWidget.extend({
openerp.web.view_editor = function(instance) {
var _t = instance.web._t;
var QWeb = instance.web.qweb;
instance.web.ViewEditor = instance.web.OldWidget.extend({
init: function(parent, element_id, dataset, view, options) {
this._super(parent);
this.element_id = element_id;
this.parent = parent;
this.dataset = new openerp.web.DataSetSearch(this, 'ir.ui.view', null, null),
this.dataset = new instance.web.DataSetSearch(this, 'ir.ui.view', null, null),
this.model = dataset.model;
this.xml_element_id = 0;
this.property = openerp.web.ViewEditor.property_widget;
this.property = instance.web.ViewEditor.property_widget;
this.one_object = false;
},
start: function() {
@ -39,7 +39,7 @@ openerp.web.ViewEditor = openerp.web.OldWidget.extend({
select_view_id: self.parent.fields_view.view_id
}
};
this.view_edit_dialog = new openerp.web.Dialog(this, {
this.view_edit_dialog = new instance.web.Dialog(this, {
title: action_title,
width: 850,
buttons: [
@ -51,7 +51,7 @@ openerp.web.ViewEditor = openerp.web.OldWidget.extend({
}).open();
this.view_edit_dialog.on_close.add_last(function(){window.location.reload();});
this.main_view_id = this.parent.fields_view.view_id;
this.action_manager = new openerp.web.ActionManager(this);
this.action_manager = new instance.web.ActionManager(this);
this.action_manager.appendTo(this.view_edit_dialog);
$.when(this.action_manager.do_action(action)).then(function() {
var viewmanager = self.action_manager.inner_viewmanager,
@ -67,7 +67,7 @@ openerp.web.ViewEditor = openerp.web.OldWidget.extend({
},
on_create_view: function() {
var self = this;
this.create_view_dialog = new openerp.web.Dialog(this, {
this.create_view_dialog = new instance.web.Dialog(this, {
title: _.str.sprintf(_t("Create a view (%s)"), self.model),
buttons: [
{text: _t("Save"), click: function () {
@ -115,8 +115,8 @@ openerp.web.ViewEditor = openerp.web.OldWidget.extend({
},
do_save_view: function(values) {
def = $.Deferred();
var field_dataset = new openerp.web.DataSetSearch(this, this.model, null, null);
var model_dataset = new openerp.web.DataSetSearch(this, 'ir.model', null, null);
var field_dataset = new instance.web.DataSetSearch(this, this.model, null, null);
var model_dataset = new instance.web.DataSetSearch(this, 'ir.model', null, null);
var view_string = "", field_name = false, self = this;
field_dataset.call( 'fields_get', [], function(fields) {
_.each(['name', 'x_name'], function(value) {
@ -360,7 +360,7 @@ openerp.web.ViewEditor = openerp.web.OldWidget.extend({
edit_view: function(one_object) {
var self = this;
this.one_object = one_object;
this.edit_xml_dialog = new openerp.web.Dialog(this, {
this.edit_xml_dialog = new instance.web.Dialog(this, {
title: _.str.sprintf(_t("View Editor %d - %s"), self.main_view_id, self.model),
height: '90%',
buttons: [
@ -392,7 +392,7 @@ openerp.web.ViewEditor = openerp.web.OldWidget.extend({
action_buttons: false
}
};
var action_manager = new openerp.web.ActionManager(self);
var action_manager = new instance.web.ActionManager(self);
action_manager.do_action(action);
}},
{text: _t("Close"), click: function(){
@ -517,7 +517,7 @@ openerp.web.ViewEditor = openerp.web.OldWidget.extend({
var self = this;
var tr = self.get_object_by_id(this.one_object.clicked_tr_id, this.one_object['main_object'], [])[0].att_list[0];
var parent_tr = ($(side).prevAll("tr[level=" + String(this.one_object.clicked_tr_level - 1) + "]"))[0];
var field_dataset = new openerp.web.DataSetSearch(this, this.model, null, null);
var field_dataset = new instance.web.DataSetSearch(this, this.model, null, null);
parent_tr = $(parent_tr).find('a').text();
field_dataset.call( 'fields_get', [], function(result) {
var fields = _.keys(result);
@ -811,7 +811,7 @@ openerp.web.ViewEditor = openerp.web.OldWidget.extend({
},
on_edit_node: function(properties){
var self = this;
this.edit_node_dialog = new openerp.web.Dialog(this,{
this.edit_node_dialog = new instance.web.Dialog(this,{
title: _t("Properties"),
width: 450,
buttons: [
@ -880,7 +880,7 @@ openerp.web.ViewEditor = openerp.web.OldWidget.extend({
this.edit_widget = [];
self.ready = $.when(self.on_groups(properties)).then(function () {
_PROPERTIES_ATTRIBUTES['groups']['selection'] = self.groups;
var values = _.keys( openerp.web.form.widgets.map);
var values = _.keys( instance.web.form.widgets.map);
values.push('');
values.sort();
_PROPERTIES_ATTRIBUTES['widget']['selection'] = values;
@ -908,8 +908,8 @@ openerp.web.ViewEditor = openerp.web.OldWidget.extend({
def.resolve();
}
var group_ids = [], group_names = {}, groups = [];
var res_groups = new openerp.web.DataSetSearch(this,'res.groups', null, null),
model_data = new openerp.web.DataSetSearch(self,'ir.model.data', null, null);
var res_groups = new instance.web.DataSetSearch(this,'res.groups', null, null),
model_data = new instance.web.DataSetSearch(self,'ir.model.data', null, null);
res_groups.read_slice([], {}).done(function (res_grp) {
_.each(res_grp, function (res) {
var key = res.id;
@ -935,7 +935,7 @@ openerp.web.ViewEditor = openerp.web.OldWidget.extend({
{'name': 'field_value','selection': fields, 'value': false, 'string': '','type': 'selection'},
{'name': 'position','selection': ['After','Before','Inside'], 'value': false, 'string': 'Position','type': 'selection'}];
this.add_widget = [];
this.add_node_dialog = new openerp.web.Dialog(this,{
this.add_node_dialog = new instance.web.Dialog(this,{
title: _t("Properties"),
width: 450,
buttons: [
@ -980,7 +980,7 @@ openerp.web.ViewEditor = openerp.web.OldWidget.extend({
});
table_selector.find("td[id^=]").attr("width","100px");
self.add_node_dialog.$element.find('#new_field').click(function() {
model_data = new openerp.web.DataSetSearch(self,'ir.model', null, null);
model_data = new instance.web.DataSetSearch(self,'ir.model', null, null);
model_data.read_slice([], {domain: [['model','=', self.model]]}).then(function(result) {
self.render_new_field(result[0].id);
});
@ -998,7 +998,7 @@ openerp.web.ViewEditor = openerp.web.OldWidget.extend({
action_buttons: true
}
};
var action_manager = new openerp.web.ActionManager(self);
var action_manager = new instance.web.ActionManager(self);
$.when(action_manager.do_action(action)).then(function() {
var controller = action_manager.dialog_viewmanager.views['form'].controller;
controller.on_button_cancel.add_last(function(){
@ -1015,7 +1015,7 @@ openerp.web.ViewEditor = openerp.web.OldWidget.extend({
});
}
});
openerp.web.ViewEditor.Field = openerp.web.Class.extend({
instance.web.ViewEditor.Field = instance.web.Class.extend({
init: function(view, widget) {
this.$element = view.$element;
this.dirty = false;
@ -1041,7 +1041,7 @@ openerp.web.ViewEditor.Field = openerp.web.Class.extend({
validate: function() {
this.is_invalid = false;
try {
var value = openerp.web.parse_value(this.get_value(), this, '');
var value = instance.web.parse_value(this.get_value(), this, '');
this.is_invalid = this.required && value === '';
} catch(e) {
this.is_invalid = true;
@ -1051,7 +1051,7 @@ openerp.web.ViewEditor.Field = openerp.web.Class.extend({
return _.str.sprintf("<td id = %s>%s</td>", this.name, QWeb.render(this.template, {widget: this}))
}
});
openerp.web.ViewEditor.FieldBoolean = openerp.web.ViewEditor.Field.extend({
instance.web.ViewEditor.FieldBoolean = instance.web.ViewEditor.Field.extend({
template : "vieweditor_boolean",
start: function() {
var self = this;
@ -1069,7 +1069,7 @@ openerp.web.ViewEditor.FieldBoolean = openerp.web.ViewEditor.Field.extend({
return this.$element.find("input[id=" + this.name + "]").is(':checked')? "1" : null;
}
});
openerp.web.ViewEditor.FieldChar = openerp.web.ViewEditor.Field.extend({
instance.web.ViewEditor.FieldChar = instance.web.ViewEditor.Field.extend({
template : "vieweditor_char",
start: function () {
var self = this;
@ -1085,7 +1085,7 @@ openerp.web.ViewEditor.FieldChar = openerp.web.ViewEditor.Field.extend({
return this.$element.find("input[id=" + this.name + "]").val();
}
});
openerp.web.ViewEditor.FieldSelect = openerp.web.ViewEditor.Field.extend({
instance.web.ViewEditor.FieldSelect = instance.web.ViewEditor.Field.extend({
template : "vieweditor_selection",
start: function () {
var self = this;
@ -1115,7 +1115,7 @@ openerp.web.ViewEditor.FieldSelect = openerp.web.ViewEditor.Field.extend({
return this.$element.find("select[id=" + this.name + "]").val();
}
});
openerp.web.ViewEditor.FieldSelectMulti = openerp.web.ViewEditor.FieldSelect.extend({
instance.web.ViewEditor.FieldSelectMulti = instance.web.ViewEditor.FieldSelect.extend({
start: function () {
this._super();
this.$element.find("select[id=" + this.name + "]").css('height', '100px').attr("multiple", true);
@ -1131,7 +1131,7 @@ openerp.web.ViewEditor.FieldSelectMulti = openerp.web.ViewEditor.FieldSelect.ext
});
}
});
openerp.web.ViewEditor.FieldFloat = openerp.web.ViewEditor.FieldChar.extend({
instance.web.ViewEditor.FieldFloat = instance.web.ViewEditor.FieldChar.extend({
});
var _PROPERTIES = {
@ -1196,11 +1196,11 @@ var _ICONS = ['','STOCK_ABOUT', 'STOCK_ADD', 'STOCK_APPLY', 'STOCK_BOLD',
'terp-sale', 'terp-tools', 'terp-administration', 'terp-hr', 'terp-partner',
'terp-project', 'terp-report', 'terp-stock', 'terp-calendar', 'terp-graph'
];
openerp.web.ViewEditor.property_widget = new openerp.web.Registry({
'boolean' : 'openerp.web.ViewEditor.FieldBoolean',
'selection_multi' : 'openerp.web.ViewEditor.FieldSelectMulti',
'selection' : 'openerp.web.ViewEditor.FieldSelect',
'char' : 'openerp.web.ViewEditor.FieldChar',
'float' : 'openerp.web.ViewEditor.FieldFloat'
instance.web.ViewEditor.property_widget = new instance.web.Registry({
'boolean' : 'instance.web.ViewEditor.FieldBoolean',
'selection_multi' : 'instance.web.ViewEditor.FieldSelectMulti',
'selection' : 'instance.web.ViewEditor.FieldSelect',
'char' : 'instance.web.ViewEditor.FieldChar',
'float' : 'instance.web.ViewEditor.FieldFloat'
});
};

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,9 @@
openerp.web.list = function (openerp) {
var _t = openerp.web._t,
_lt = openerp.web._lt;
var QWeb = openerp.web.qweb;
openerp.web.views.add('list', 'openerp.web.ListView');
openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView# */ {
openerp.web.list = function (instance) {
var _t = instance.web._t,
_lt = instance.web._lt;
var QWeb = instance.web.qweb;
instance.web.views.add('list', 'instance.web.ListView');
instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListView# */ {
_template: 'ListView',
display_name: _lt('List'),
defaults: {
@ -33,11 +33,11 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView#
* See constructor parameters and method documentations for information on
* the default behaviors and possible options for the list view.
*
* @constructs openerp.web.ListView
* @extends openerp.web.View
* @constructs instance.web.ListView
* @extends instance.web.View
*
* @param parent parent object
* @param {openerp.web.DataSet} dataset the dataset the view should work with
* @param {instance.web.DataSet} dataset the dataset the view should work with
* @param {String} view_id the listview's identifier, if any
* @param {Object} options A set of options used to configure the view
* @param {Boolean} [options.selectable=true] determines whether view rows are selectable (e.g. via a checkbox)
@ -61,12 +61,12 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView#
this.records = new Collection();
this.set_groups(new openerp.web.ListView.Groups(this));
this.set_groups(new instance.web.ListView.Groups(this));
if (this.dataset instanceof openerp.web.DataSetStatic) {
this.groups.datagroup = new openerp.web.StaticDataGroup(this.dataset);
if (this.dataset instanceof instance.web.DataSetStatic) {
this.groups.datagroup = new instance.web.StaticDataGroup(this.dataset);
} else {
this.groups.datagroup = new openerp.web.DataGroup(
this.groups.datagroup = new instance.web.DataGroup(
this, this.model,
dataset.get_domain(),
dataset.get_context(),
@ -104,7 +104,7 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView#
/**
* Set a custom Group construct as the root of the List View.
*
* @param {openerp.web.ListView.Groups} groups
* @param {instance.web.ListView.Groups} groups
*/
set_groups: function (groups) {
var self = this;
@ -302,7 +302,7 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView#
// Sidebar
if (!this.sidebar && this.options.sidebar && this.options.$sidebar) {
this.sidebar = new openerp.web.Sidebar(this);
this.sidebar = new instance.web.Sidebar(this);
this.sidebar.appendTo(this.options.$sidebar);
this.sidebar.add_toolbar(this.fields_view.toolbar);
}
@ -312,7 +312,7 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView#
*
* Horrifying side-effect: sets the dataset's data on this.dataset?
*
* @param {openerp.web.DataSet} dataset
* @param {instance.web.DataSet} dataset
*/
configure_pager: function (dataset) {
this.dataset.ids = dataset.ids;
@ -336,7 +336,7 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView#
* @param {Boolean} [grouped] Should the grouping columns (group and count) be displayed
*/
setup_columns: function (fields, grouped) {
var domain_computer = openerp.web.form.compute_domain;
var domain_computer = instance.web.form.compute_domain;
var noop = function () { return {}; };
var field_to_column = function (field) {
@ -405,7 +405,7 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView#
*
* The default implementation asks the list view's view manager to switch
* to a different view (by calling
* :js:func:`~openerp.web.ViewManager.on_mode_switch`), using the
* :js:func:`~instance.web.ViewManager.on_mode_switch`), using the
* provided record index (within the current list view's dataset).
*
* If the index is null, ``switch_to_record`` asks for the creation of a
@ -526,7 +526,7 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView#
*/
do_search: function (domain, context, group_by) {
this.page = 0;
this.groups.datagroup = new openerp.web.DataGroup(
this.groups.datagroup = new instance.web.DataGroup(
this, this.model, domain, context, group_by);
this.groups.datagroup.sort = this.dataset._sort;
@ -598,7 +598,7 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView#
return;
}
var c = new openerp.web.CompoundContext();
var c = new instance.web.CompoundContext();
c.set_eval_context(_.extend({
active_id: id,
active_ids: [id],
@ -615,7 +615,7 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView#
*
* @param {Number} index index of the record in the dataset
* @param {Object} id identifier of the activated record
* @param {openerp.web.DataSet} dataset dataset in which the record is available (may not be the listview's dataset in case of nested groups)
* @param {instance.web.DataSet} dataset dataset in which the record is available (may not be the listview's dataset in case of nested groups)
*/
do_activate_record: function (index, id, dataset, view) {
this.dataset.ids = dataset.ids;
@ -639,11 +639,11 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView#
/**
* Computes the aggregates for the current list view, either on the
* records provided or on the records of the internal
* :js:class:`~openerp.web.ListView.Group`, by calling
* :js:func:`~openerp.web.ListView.group.get_records`.
* :js:class:`~instance.web.ListView.Group`, by calling
* :js:func:`~instance.web.ListView.group.get_records`.
*
* Then displays the aggregates in the table through
* :js:method:`~openerp.web.ListView.display_aggregates`.
* :js:method:`~instance.web.ListView.display_aggregates`.
*
* @param {Array} [records]
*/
@ -719,7 +719,7 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView#
}
$footer_cells.filter(_.str.sprintf('[data-field=%s]', column.id))
.html(openerp.web.format_cell(aggregation, column, {
.html(instance.web.format_cell(aggregation, column, {
process_modifiers: false
}));
});
@ -772,7 +772,7 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView#
}
}
});
openerp.web.ListView.List = openerp.web.Class.extend( /** @lends openerp.web.ListView.List# */{
instance.web.ListView.List = instance.web.Class.extend( /** @lends instance.web.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
@ -797,10 +797,10 @@ openerp.web.ListView.List = openerp.web.Class.extend( /** @lends openerp.web.Lis
* Triggered when a row of the table is clicked, provides the index (in
* the rows array) and id of the selected record to the handle function.
*
* @constructs openerp.web.ListView.List
* @extends openerp.web.Class
* @constructs instance.web.ListView.List
* @extends instance.web.Class
*
* @param {Object} opts display options, identical to those of :js:class:`openerp.web.ListView`
* @param {Object} opts display options, identical to those of :js:class:`instance.web.ListView`
*/
init: function (group, opts) {
var self = this;
@ -915,7 +915,7 @@ openerp.web.ListView.List = openerp.web.Class.extend( /** @lends openerp.web.Lis
// to get a correctly displayable value in the field
var model = ref_match[1],
id = parseInt(ref_match[2], 10);
new openerp.web.DataSet(this.view, model).name_get([id], function(names) {
new instance.web.DataSet(this.view, model).name_get([id], function(names) {
if (!names.length) { return; }
record.set(column.id, names[0][1]);
});
@ -930,14 +930,14 @@ openerp.web.ListView.List = openerp.web.Class.extend( /** @lends openerp.web.Lis
// fetch the name, set it on the record (in the right field)
// and let the various registered events handle refreshing the
// row
new openerp.web.DataSet(this.view, column.relation)
new instance.web.DataSet(this.view, column.relation)
.name_get([value], function (names) {
if (!names.length) { return; }
record.set(column.id, names[0]);
});
}
}
return openerp.web.format_cell(record.toForm().data, column, {
return instance.web.format_cell(record.toForm().data, column, {
model: this.dataset.model,
id: record.get('id')
});
@ -1091,19 +1091,19 @@ openerp.web.ListView.List = openerp.web.Class.extend( /** @lends openerp.web.Lis
});
}
});
openerp.web.ListView.Groups = openerp.web.Class.extend( /** @lends openerp.web.ListView.Groups# */{
instance.web.ListView.Groups = instance.web.Class.extend( /** @lends instance.web.ListView.Groups# */{
passtrough_events: 'action deleted row_link',
/**
* Grouped display for the ListView. Handles basic DOM events and interacts
* with the :js:class:`~openerp.web.DataGroup` bound to it.
* with the :js:class:`~instance.web.DataGroup` bound to it.
*
* Provides events similar to those of
* :js:class:`~openerp.web.ListView.List`
* :js:class:`~instance.web.ListView.List`
*
* @constructs openerp.web.ListView.Groups
* @extends openerp.web.Class
* @constructs instance.web.ListView.Groups
* @extends instance.web.Class
*
* @param {openerp.web.ListView} view
* @param {instance.web.ListView} view
* @param {Object} [options]
* @param {Collection} [options.records]
* @param {Object} [options.options]
@ -1214,7 +1214,7 @@ openerp.web.ListView.Groups = openerp.web.Class.extend( /** @lends openerp.web.L
self.records.proxy(group.value).reset();
delete self.children[group.value];
}
var child = self.children[group.value] = new openerp.web.ListView.Groups(self.view, {
var child = self.children[group.value] = new instance.web.ListView.Groups(self.view, {
records: self.records.proxy(group.value),
options: self.options,
columns: self.columns
@ -1250,7 +1250,7 @@ openerp.web.ListView.Groups = openerp.web.Class.extend( /** @lends openerp.web.L
var group_column = _(self.columns).detect(function (column) {
return column.id === group.grouped_on; });
try {
$group_column.html(openerp.web.format_cell(
$group_column.html(instance.web.format_cell(
row_data, group_column, {
value_if_empty: _t("Undefined"),
process_modifiers: false
@ -1287,7 +1287,7 @@ openerp.web.ListView.Groups = openerp.web.Class.extend( /** @lends openerp.web.L
var r = {};
r[column.id] = {value: group.aggregates[column.id]};
$('<td class="oe-number">')
.html(openerp.web.format_cell(
.html(instance.web.format_cell(
r, column, {process_modifiers: false}))
.appendTo($row);
} else {
@ -1320,7 +1320,7 @@ openerp.web.ListView.Groups = openerp.web.Class.extend( /** @lends openerp.web.L
},
render_dataset: function (dataset) {
var self = this,
list = new openerp.web.ListView.List(this, {
list = new instance.web.ListView.List(this, {
options: this.options,
columns: this.columns,
dataset: dataset,
@ -1533,10 +1533,10 @@ var Events = /** @lends Events# */{
return this;
}
};
var Record = openerp.web.Class.extend(/** @lends Record# */{
var Record = instance.web.Class.extend(/** @lends Record# */{
/**
* @constructs Record
* @extends openerp.web.Class
* @extends instance.web.Class
*
* @mixes Events
* @param {Object} [data]
@ -1614,7 +1614,7 @@ var Record = openerp.web.Class.extend(/** @lends Record# */{
}
});
Record.include(Events);
var Collection = openerp.web.Class.extend(/** @lends Collection# */{
var Collection = instance.web.Class.extend(/** @lends Collection# */{
/**
* Smarter collections, with events, very strongly inspired by Backbone's.
*
@ -1622,7 +1622,7 @@ var Collection = openerp.web.Class.extend(/** @lends Collection# */{
* various serious
*
* @constructs Collection
* @extends openerp.web.Class
* @extends instance.web.Class
*
* @mixes Events
* @param {Array} [records] records to initialize the collection with
@ -1797,7 +1797,7 @@ var Collection = openerp.web.Class.extend(/** @lends Collection# */{
}
});
Collection.include(Events);
openerp.web.list = {
instance.web.list = {
Events: Events,
Record: Record,
Collection: Collection

View File

@ -2,16 +2,16 @@
* handles editability case for lists, because it depends on form and forms already depends on lists it had to be split out
* @namespace
*/
openerp.web.list_editable = function (openerp) {
openerp.web.list_editable = function (instance) {
var KEY_RETURN = 13,
KEY_ESCAPE = 27;
var QWeb = openerp.web.qweb;
var QWeb = instance.web.qweb;
// editability status of list rows
openerp.web.ListView.prototype.defaults.editable = null;
instance.web.ListView.prototype.defaults.editable = null;
// TODO: not sure second @lends on existing item is correct, to check
openerp.web.ListView.include(/** @lends openerp.web.ListView# */{
instance.web.ListView.include(/** @lends instance.web.ListView# */{
init: function () {
var self = this;
this._super.apply(this, arguments);
@ -37,7 +37,7 @@ openerp.web.list_editable = function (openerp) {
*
* @param {Number} index index of the record in the dataset
* @param {Object} id identifier of the record being edited
* @param {openerp.web.DataSet} dataset dataset in which the record is available
* @param {instance.web.DataSet} dataset dataset in which the record is available
*/
do_edit: function (index, id, dataset) {
_.extend(this.dataset, dataset);
@ -93,8 +93,8 @@ openerp.web.list_editable = function (openerp) {
}
});
openerp.web.ListView.Groups.include(/** @lends openerp.web.ListView.Groups# */{
passtrough_events: openerp.web.ListView.Groups.prototype.passtrough_events + " edit saved",
instance.web.ListView.Groups.include(/** @lends instance.web.ListView.Groups# */{
passtrough_events: instance.web.ListView.Groups.prototype.passtrough_events + " edit saved",
new_record: function () {
// TODO: handle multiple children
this.children[null].new_record();
@ -113,7 +113,7 @@ openerp.web.list_editable = function (openerp) {
}
});
openerp.web.ListView.List.include(/** @lends openerp.web.ListView.List# */{
instance.web.ListView.List.include(/** @lends instance.web.ListView.List# */{
row_clicked: function (event) {
if (!this.options.editable) {
return this._super.apply(this, arguments);
@ -236,7 +236,7 @@ openerp.web.list_editable = function (openerp) {
self.edition = true;
self.edition_id = record_id;
$new_row.addClass("oe_form_container");
self.edition_form = new openerp.web.ListEditableFormView(self.view, self.dataset, false);
self.edition_form = new instance.web.ListEditableFormView(self.view, self.dataset, false);
self.edition_form.$element = $new_row;
self.edition_form.editable_list = self;
// HO HO
@ -274,7 +274,7 @@ openerp.web.list_editable = function (openerp) {
// insert after the source record
var index = self.records.indexOf(
self.records.get(source_record_id)) + 1;
record = new openerp.web.list.Record({id: id});
record = new instance.web.list.Record({id: id});
self.records.add(record, {at: index});
self.dataset.ids.splice(index, 0, id);
}
@ -368,15 +368,15 @@ openerp.web.list_editable = function (openerp) {
}
});
openerp.web.ListEditableFormView = openerp.web.FormView.extend({
instance.web.ListEditableFormView = instance.web.FormView.extend({
init: function() {
this._super.apply(this, arguments);
this.rendering_engine = new openerp.web.ListEditableRenderingEngine(this);
this.rendering_engine = new instance.web.ListEditableRenderingEngine(this);
},
renderElement: function() {}
});
openerp.web.ListEditableRenderingEngine = openerp.web.Class.extend({
instance.web.ListEditableRenderingEngine = instance.web.Class.extend({
init: function(view) {
this.view = view;
},
@ -392,7 +392,7 @@ openerp.web.list_editable = function (openerp) {
render_to: function($element) {
var self = this;
var xml = openerp.web.json_node_to_xml(this.fvg.arch);
var xml = instance.web.json_node_to_xml(this.fvg.arch);
var $xml = $(xml);
if (this.view.editable_list.options.selectable)
@ -412,7 +412,7 @@ openerp.web.list_editable = function (openerp) {
key = $(el).attr('widget') || self.fvg.fields[name].type;
}
var obj = self.view.fields_registry.get_object(key);
var w = new (obj)(self.view, openerp.web.xml_to_json(el));
var w = new (obj)(self.view, instance.web.xml_to_json(el));
self.view.register_field(w, $(el).attr("name"));
w.appendTo($td);
$td.appendTo($element);

View File

@ -2,12 +2,12 @@
* OpenERP web library
*---------------------------------------------------------*/
openerp.web.view_tree = function(openerp) {
var QWeb = openerp.web.qweb,
_lt = openerp.web._lt;
openerp.web.view_tree = function(instance) {
var QWeb = instance.web.qweb,
_lt = instance.web._lt;
openerp.web.views.add('tree', 'openerp.web.TreeView');
openerp.web.TreeView = openerp.web.View.extend(/** @lends openerp.web.TreeView# */{
instance.web.views.add('tree', 'instance.web.TreeView');
instance.web.TreeView = instance.web.View.extend(/** @lends instance.web.TreeView# */{
display_name: _lt('Tree'),
/**
* Indicates that this view is not searchable, and thus that no search
@ -17,8 +17,8 @@ openerp.web.TreeView = openerp.web.View.extend(/** @lends openerp.web.TreeView#
/**
* Genuine tree view (the one displayed as a tree, not the list)
*
* @constructs openerp.web.TreeView
* @extends openerp.web.View
* @constructs instance.web.TreeView
* @extends instance.web.View
*
* @param parent
* @param dataset
@ -203,7 +203,7 @@ openerp.web.TreeView = openerp.web.View.extend(/** @lends openerp.web.TreeView#
'fields_view': self.fields_view.arch.children,
'fields': self.fields,
'level': $curr_node.data('level') || 0,
'render': openerp.web.format_value,
'render': instance.web.format_value,
'color_for': self.color_for
});
@ -226,12 +226,12 @@ openerp.web.TreeView = openerp.web.View.extend(/** @lends openerp.web.TreeView#
return this.rpc('/web/treeview/action', {
id: id,
model: this.dataset.model,
context: new openerp.web.CompoundContext(
context: new instance.web.CompoundContext(
this.dataset.get_context(), local_context)
}).pipe(function (actions) {
if (!actions.length) { return; }
var action = actions[0][2];
var c = new openerp.web.CompoundContext(local_context);
var c = new instance.web.CompoundContext(local_context);
if (action.context) {
c.add(action.context);
}

View File

@ -2,11 +2,11 @@
* OpenERP web library
*---------------------------------------------------------*/
openerp.web.views = function(session) {
var QWeb = session.web.qweb,
_t = session.web._t;
openerp.web.views = function(instance) {
var QWeb = instance.web.qweb,
_t = instance.web._t;
session.web.ActionManager = session.web.Widget.extend({
instance.web.ActionManager = instance.web.Widget.extend({
init: function(parent) {
this._super(parent);
this.inner_action = null;
@ -52,8 +52,8 @@ session.web.ActionManager = session.web.Widget.extend({
if (run_action) {
this.null_action();
action_loaded = this.do_action(state.action_id);
session.webclient.menu.has_been_loaded.then(function() {
session.webclient.menu.open_action(state.action_id);
instance.webclient.menu.has_been_loaded.then(function() {
instance.webclient.menu.open_action(state.action_id);
});
}
} else if (state.model && state.id) {
@ -124,31 +124,31 @@ session.web.ActionManager = session.web.Widget.extend({
.contains(action.res_model)) {
var old_close = on_close;
on_close = function () {
session.webclient.do_reload().then(old_close);
instance.webclient.do_reload().then(old_close);
};
}
if (action.target === 'new') {
if (this.dialog == null) {
this.dialog = new session.web.Dialog(this, { width: '80%' });
this.dialog = new instance.web.Dialog(this, { width: '80%' });
if(on_close)
this.dialog.on_close.add(on_close);
} else {
this.dialog_viewmanager.destroy();
}
this.dialog.dialog_title = action.name;
this.dialog_viewmanager = new session.web.ViewManagerAction(this, action);
this.dialog_viewmanager = new instance.web.ViewManagerAction(this, action);
this.dialog_viewmanager.appendTo(this.dialog.$element);
this.dialog.open();
} else {
if(action.menu_id) {
return this.getParent().do_action(action, function () {
session.webclient.menu.open_menu(action.menu_id);
instance.webclient.menu.open_menu(action.menu_id);
});
}
this.dialog_stop();
this.content_stop();
this.inner_action = action;
this.inner_viewmanager = new session.web.ViewManagerAction(this, action);
this.inner_viewmanager = new instance.web.ViewManagerAction(this, action);
this.inner_viewmanager.appendTo(this.$element);
}
},
@ -170,7 +170,7 @@ session.web.ActionManager = session.web.Widget.extend({
ir_actions_client: function (action) {
this.content_stop();
this.dialog_stop();
var ClientWidget = session.web.client_actions.get_object(action.tag);
var ClientWidget = instance.web.client_actions.get_object(action.tag);
(this.client_widget = new ClientWidget(this, action.params)).appendTo(this.$element);
},
ir_actions_report_xml: function(action, on_closed) {
@ -192,7 +192,7 @@ session.web.ActionManager = session.web.Widget.extend({
}
self.dialog_stop();
},
error: session.webclient.crashmanager.on_rpc_error
error: instance.webclient.crashmanager.on_rpc_error
})
});
},
@ -204,7 +204,7 @@ session.web.ActionManager = session.web.Widget.extend({
}
});
session.web.ViewManager = session.web.Widget.extend({
instance.web.ViewManager = instance.web.Widget.extend({
template: "ViewManager",
init: function(parent, dataset, views, flags) {
this._super(parent);
@ -214,7 +214,7 @@ session.web.ViewManager = session.web.Widget.extend({
this.active_view = null;
this.views_src = _.map(views, function(x) {
if (x instanceof Array) {
var View = session.web.views.get_object(x[1], true);
var View = instance.web.views.get_object(x[1], true);
return {
view_id: x[0],
view_type: x[1],
@ -226,7 +226,7 @@ session.web.ViewManager = session.web.Widget.extend({
});
this.views = {};
this.flags = flags || {};
this.registry = session.web.views;
this.registry = instance.web.views;
this.views_history = [];
},
/**
@ -376,7 +376,7 @@ session.web.ViewManager = session.web.Widget.extend({
if (this.searchview) {
this.searchview.destroy();
}
this.searchview = new session.web.SearchView(this, this.dataset, view_id, search_defaults, this.flags.search_view === false);
this.searchview = new instance.web.SearchView(this, this.dataset, view_id, search_defaults, this.flags.search_view === false);
this.searchview.on_search.add(this.do_searchview_search);
return this.searchview.appendTo(this.$element.find(".oe_view_manager_view_search"));
@ -435,13 +435,13 @@ session.web.ViewManager = session.web.Widget.extend({
}
});
session.web.ViewManagerAction = session.web.ViewManager.extend({
instance.web.ViewManagerAction = instance.web.ViewManager.extend({
template:"ViewManagerAction",
/**
* @constructs session.web.ViewManagerAction
* @extends session.web.ViewManager
* @constructs instance.web.ViewManagerAction
* @extends instance.web.ViewManager
*
* @param {session.web.ActionManager} parent parent object/widget
* @param {instance.web.ActionManager} parent parent object/widget
* @param {Object} action descriptor for the action this viewmanager needs to manage its views.
*/
init: function(parent, action) {
@ -466,7 +466,7 @@ session.web.ViewManagerAction = session.web.ViewManager.extend({
this._super(parent, null, action.views, flags);
this.session = parent.session;
this.action = action;
var dataset = new session.web.DataSetSearch(this, action.res_model, action.context, action.domain);
var dataset = new instance.web.DataSetSearch(this, action.res_model, action.context, action.domain);
if (action.res_id) {
dataset.ids.push(action.res_id);
dataset.index = 0;
@ -507,7 +507,7 @@ session.web.ViewManagerAction = session.web.ViewManager.extend({
this.$element.find('.oe_debug_view').change(this.on_debug_changed);
if (this.action.help && !this.flags.low_profile) {
var Users = new session.web.DataSet(self, 'res.users'),
var Users = new instance.web.DataSet(self, 'res.users'),
$tips = this.$element.find('.oe_view_manager_menu_tips');
$tips.delegate('blockquote button', 'click', function() {
var $this = $(this);
@ -541,19 +541,19 @@ session.web.ViewManagerAction = session.web.ViewManager.extend({
current_view = this.views[this.active_view].controller;
switch (val) {
case 'fvg':
var dialog = new session.web.Dialog(this, { title: _t("Fields View Get"), width: '95%' }).open();
$('<pre>').text(session.web.json_node_to_xml(current_view.fields_view.arch, true)).appendTo(dialog.$element);
var dialog = new instance.web.Dialog(this, { title: _t("Fields View Get"), width: '95%' }).open();
$('<pre>').text(instance.web.json_node_to_xml(current_view.fields_view.arch, true)).appendTo(dialog.$element);
break;
case 'perm_read':
var ids = current_view.get_selected_ids();
if (ids.length === 1) {
this.dataset.call('perm_read', [ids]).then(function(result) {
var dialog = new session.web.Dialog(this, {
var dialog = new instance.web.Dialog(this, {
title: _.str.sprintf(_t("View Log (%s)"), self.dataset.model),
width: 400
}, QWeb.render('ViewManagerDebugViewLog', {
perm : result[0],
format : session.web.format_value
format : instance.web.format_value
})).open();
});
}
@ -578,7 +578,7 @@ session.web.ViewManagerAction = session.web.ViewManager.extend({
.append($('<dd style="white-space: pre-wrap;">').text(def));
});
});
new session.web.Dialog(self, {
new instance.web.Dialog(self, {
title: _.str.sprintf(_t("Model %s fields"),
self.dataset.model),
width: '95%'}, $root).open();
@ -586,7 +586,7 @@ session.web.ViewManagerAction = session.web.ViewManager.extend({
break;
case 'manage_views':
if (current_view.fields_view && current_view.fields_view.arch) {
var view_editor = new session.web.ViewEditor(current_view, current_view.$element, this.dataset, current_view.fields_view.arch);
var view_editor = new instance.web.ViewEditor(current_view, current_view.$element, this.dataset, current_view.fields_view.arch);
view_editor.start();
} else {
this.do_warn(_t("Manage Views"),
@ -723,7 +723,7 @@ session.web.ViewManagerAction = session.web.ViewManager.extend({
}
});
session.web.Sidebar = session.web.Widget.extend({
instance.web.Sidebar = instance.web.Widget.extend({
init: function(parent) {
this._super(parent);
var view = this.getParent();
@ -832,7 +832,7 @@ session.web.Sidebar = session.web.Widget.extend({
self.getParent().sidebar_context().then(function (context) {
var ids = self.getParent().get_selected_ids();
if (ids.length == 0) {
session.web.dialog($("<div />").text(_t("You must choose at least one record.")), { title: _t("Warning"), modal: true });
instance.web.dialog($("<div />").text(_t("You must choose at least one record.")), { title: _t("Warning"), modal: true });
return false;
}
var additional_context = _.extend({
@ -860,7 +860,7 @@ session.web.Sidebar = session.web.Widget.extend({
this.on_attachments_loaded([]);
} else {
var dom = [ ['res_model', '=', dataset.model], ['res_id', '=', model_id], ['type', 'in', ['binary', 'url']] ];
var ds = new session.web.DataSetSearch(this, 'ir.attachment', dataset.get_context(), dom);
var ds = new instance.web.DataSetSearch(this, 'ir.attachment', dataset.get_context(), dom);
ds.read_slice(['name', 'url', 'type'], {}).then(this.on_attachments_loaded);
}
},
@ -908,7 +908,7 @@ session.web.Sidebar = session.web.Widget.extend({
}
});
session.web.TranslateDialog = session.web.Dialog.extend({
instance.web.TranslateDialog = instance.web.Dialog.extend({
dialog_title: {toString: function () { return _t("Translations"); }},
init: function(view) {
// TODO fme: should add the language to fields_view_get because between the fields view get
@ -928,14 +928,14 @@ session.web.TranslateDialog = session.web.Dialog.extend({
this.translatable_fields_keys = _.map(this.view.translatable_fields || [], function(i) { return i.name });
this.languages = null;
this.languages_loaded = $.Deferred();
(new session.web.DataSetSearch(this, 'res.lang', this.view.dataset.get_context(),
(new instance.web.DataSetSearch(this, 'res.lang', this.view.dataset.get_context(),
[['translatable', '=', '1']])).read_slice(['code', 'name'], { sort: 'id' }).then(this.on_languages_loaded);
},
start: function() {
var self = this;
this._super();
$.when(this.languages_loaded).then(function() {
self.$element.html(session.web.qweb.render('TranslateDialog', { widget: self }));
self.$element.html(instance.web.qweb.render('TranslateDialog', { widget: self }));
self.$fields_form = self.$element.find('.oe_translation_form');
self.$fields_form.find('.oe_trad_field').change(function() {
$(this).toggleClass('touched', ($(this).val() != $(this).attr('data-value')));
@ -1024,7 +1024,7 @@ session.web.TranslateDialog = session.web.Dialog.extend({
}
});
session.web.View = session.web.Widget.extend({
instance.web.View = instance.web.Widget.extend({
template: "EmptyComponent",
// name displayed in view switchers
display_name: '',
@ -1048,7 +1048,7 @@ session.web.View = session.web.Widget.extend({
$.async_when().then(function() {def.resolve(self.embedded_view);});
return def.pipe(this.on_loaded);
} else {
var context = new session.web.CompoundContext(this.dataset.get_context());
var context = new instance.web.CompoundContext(this.dataset.get_context());
if (! this.view_type)
console.warn("view_type is not defined", this);
return this.rpc("/web/view/load", {
@ -1079,7 +1079,7 @@ session.web.View = session.web.Widget.extend({
},
open_translate_dialog: function(field) {
if (!this.translate_dialog) {
this.translate_dialog = new session.web.TranslateDialog(this).start();
this.translate_dialog = new instance.web.TranslateDialog(this).start();
}
this.translate_dialog.open(field);
},
@ -1091,7 +1091,7 @@ session.web.View = session.web.Widget.extend({
* @param {String} [action_data.special=null] special action handlers (currently: only ``'cancel'``)
* @param {String} [action_data.type='workflow'] the action type, if present, one of ``'object'``, ``'action'`` or ``'workflow'``
* @param {Object} [action_data.context=null] additional action context, to add to the current context
* @param {session.web.DataSet} dataset a dataset object used to communicate with the server
* @param {instance.web.DataSet} dataset a dataset object used to communicate with the server
* @param {Object} [record_id] the identifier of the object on which the action is to be applied
* @param {Function} on_closed callback to execute when dialog is closed or when the action does not generate any result (no new action)
*/
@ -1103,12 +1103,12 @@ session.web.View = session.web.Widget.extend({
return self.getParent().on_action_executed.apply(null, arguments);
}
};
var context = new session.web.CompoundContext(dataset.get_context(), action_data.context || {});
var context = new instance.web.CompoundContext(dataset.get_context(), action_data.context || {});
var handler = function (r) {
var action = r.result;
if (action && action.constructor == Object) {
var ncontext = new session.web.CompoundContext(context);
var ncontext = new instance.web.CompoundContext(context);
if (record_id) {
ncontext.add({
active_id: record_id,
@ -1157,7 +1157,7 @@ session.web.View = session.web.Widget.extend({
/**
* Directly set a view to use instead of calling fields_view_get. This method must
* be called before start(). When an embedded view is set, underlying implementations
* of session.web.View must use the provided view instead of any other one.
* of instance.web.View must use the provided view instead of any other one.
*
* @param embedded_view A view.
*/
@ -1197,11 +1197,11 @@ session.web.View = session.web.Widget.extend({
do_search: function(view) {
},
on_sidebar_import: function() {
var import_view = new session.web.DataImport(this, this.dataset);
var import_view = new instance.web.DataImport(this, this.dataset);
import_view.start();
},
on_sidebar_export: function() {
var export_view = new session.web.DataExport(this, this.dataset);
var export_view = new instance.web.DataExport(this, this.dataset);
export_view.start();
},
on_sidebar_translate: function() {
@ -1226,7 +1226,7 @@ session.web.View = session.web.Widget.extend({
}
});
session.web.xml_to_json = function(node) {
instance.web.xml_to_json = function(node) {
switch (node.nodeType) {
case 3:
case 4:
@ -1244,11 +1244,11 @@ session.web.xml_to_json = function(node) {
return {
tag: node.tagName.toLowerCase(),
attrs: attrs,
children: _.map(node.childNodes, session.web.xml_to_json)
children: _.map(node.childNodes, instance.web.xml_to_json)
}
}
}
session.web.json_node_to_xml = function(node, human_readable, indent) {
instance.web.json_node_to_xml = function(node, human_readable, indent) {
// For debugging purpose, this function will convert a json node back to xml
// Maybe useful for xml view editor
indent = indent || 0;
@ -1277,7 +1277,7 @@ session.web.json_node_to_xml = function(node, human_readable, indent) {
r += '>' + cr;
var childs = [];
for (var i = 0, ii = node.children.length; i < ii; i++) {
childs.push(session.web.json_node_to_xml(node.children[i], human_readable, indent + 1));
childs.push(instance.web.json_node_to_xml(node.children[i], human_readable, indent + 1));
}
r += childs.join(cr);
r += cr + sindent + '</' + node.tag + '>';
@ -1286,14 +1286,14 @@ session.web.json_node_to_xml = function(node, human_readable, indent) {
return r + '/>';
}
}
session.web.xml_to_str = function(node) {
instance.web.xml_to_str = function(node) {
if (window.ActiveXObject) {
return node.xml;
} else {
return (new XMLSerializer()).serializeToString(node);
}
}
session.web.str_to_xml = function(s) {
instance.web.str_to_xml = function(s) {
if (window.DOMParser) {
var dp = new DOMParser();
var r = dp.parseFromString(s, "text/xml");
@ -1317,12 +1317,12 @@ session.web.str_to_xml = function(s) {
/**
* Registry for all the client actions key: tag value: widget
*/
session.web.client_actions = new session.web.Registry();
instance.web.client_actions = new instance.web.Registry();
/**
* Registry for all the main views
*/
session.web.views = new session.web.Registry();
instance.web.views = new instance.web.Registry();
};