2011-03-16 23:56:34 +00:00
|
|
|
/*---------------------------------------------------------
|
|
|
|
* OpenERP base library
|
|
|
|
*---------------------------------------------------------*/
|
|
|
|
|
2011-03-30 14:35:56 +00:00
|
|
|
openerp.base.chrome = function(openerp) {
|
2011-03-16 23:56:34 +00:00
|
|
|
|
2011-03-31 10:20:23 +00:00
|
|
|
/**
|
|
|
|
* Base error for lookup failure
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
*/
|
2011-07-15 14:16:00 +00:00
|
|
|
openerp.base.NotFound = openerp.base.Class.extend( /** @lends openerp.base.NotFound# */ {
|
2011-03-31 10:20:23 +00:00
|
|
|
});
|
2011-04-04 19:52:16 +00:00
|
|
|
openerp.base.KeyNotFound = openerp.base.NotFound.extend( /** @lends openerp.base.KeyNotFound# */ {
|
2011-03-31 10:20:23 +00:00
|
|
|
/**
|
|
|
|
* Thrown when a key could not be found in a mapping
|
|
|
|
*
|
|
|
|
* @constructs
|
|
|
|
* @extends openerp.base.NotFound
|
|
|
|
* @param {String} key the key which could not be found
|
|
|
|
*/
|
|
|
|
init: function (key) {
|
2011-03-31 12:20:18 +00:00
|
|
|
this.key = key;
|
|
|
|
},
|
|
|
|
toString: function () {
|
|
|
|
return "The key " + this.key + " was not found";
|
2011-03-31 10:20:23 +00:00
|
|
|
}
|
|
|
|
});
|
2011-04-04 19:52:16 +00:00
|
|
|
openerp.base.ObjectNotFound = openerp.base.NotFound.extend( /** @lends openerp.base.ObjectNotFound# */ {
|
2011-03-31 10:20:23 +00:00
|
|
|
/**
|
|
|
|
* Thrown when an object path does not designate a valid class or object
|
|
|
|
* in the openerp hierarchy.
|
|
|
|
*
|
|
|
|
* @constructs
|
|
|
|
* @extends openerp.base.NotFound
|
|
|
|
* @param {String} path the invalid object path
|
|
|
|
*/
|
|
|
|
init: function (path) {
|
2011-03-31 12:20:18 +00:00
|
|
|
this.path = path;
|
|
|
|
},
|
|
|
|
toString: function () {
|
|
|
|
return "Could not find any object of path " + this.path;
|
2011-03-31 10:20:23 +00:00
|
|
|
}
|
|
|
|
});
|
2011-07-15 14:16:00 +00:00
|
|
|
openerp.base.Registry = openerp.base.Class.extend( /** @lends openerp.base.Registry# */ {
|
2011-03-31 10:20:23 +00:00
|
|
|
/**
|
|
|
|
* Stores a mapping of arbitrary key (strings) to object paths (as strings
|
|
|
|
* as well).
|
|
|
|
*
|
|
|
|
* Resolves those paths at query time in order to always fetch the correct
|
|
|
|
* 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.base.Session"`` for an OpenERP
|
|
|
|
* session object).
|
|
|
|
*
|
|
|
|
* @constructs
|
|
|
|
* @param {Object} mapping a mapping of keys to object-paths
|
|
|
|
*/
|
|
|
|
init: function (mapping) {
|
|
|
|
this.map = mapping || {};
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Retrieves the object matching the provided key string.
|
|
|
|
*
|
|
|
|
* @param {String} key the key to fetch the object for
|
|
|
|
* @returns {Class} the stored class, to initialize
|
|
|
|
*
|
|
|
|
* @throws {openerp.base.KeyNotFound} if the object was not in the mapping
|
|
|
|
* @throws {openerp.base.ObjectNotFound} if the object path was invalid
|
|
|
|
*/
|
|
|
|
get_object: function (key) {
|
|
|
|
var path_string = this.map[key];
|
|
|
|
if (path_string === undefined) {
|
|
|
|
throw new openerp.base.KeyNotFound(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
var object_match = openerp;
|
|
|
|
var path = path_string.split('.');
|
|
|
|
// ignore first section
|
|
|
|
for(var i=1; i<path.length; ++i) {
|
|
|
|
object_match = object_match[path[i]];
|
|
|
|
|
|
|
|
if (object_match === undefined) {
|
|
|
|
throw new openerp.base.ObjectNotFound(path_string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return object_match;
|
|
|
|
},
|
2011-06-27 14:14:38 +00:00
|
|
|
/**
|
|
|
|
* Tries a number of keys, and returns the first object matching one of
|
|
|
|
* the keys.
|
|
|
|
*
|
|
|
|
* @param {Array} keys a sequence of keys to fetch the object for
|
|
|
|
* @returns {Class} the first class found matching an object
|
|
|
|
*
|
|
|
|
* @throws {openerp.base.KeyNotFound} if none of the keys was in the mapping
|
|
|
|
* @trows {openerp.base.ObjectNotFound} if a found object path was invalid
|
|
|
|
*/
|
|
|
|
get_any: function (keys) {
|
|
|
|
for (var i=0; i<keys.length; ++i) {
|
|
|
|
try {
|
|
|
|
return this.get_object(keys[i]);
|
|
|
|
} catch (e) {
|
|
|
|
if (e instanceof openerp.base.KeyNotFound) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new openerp.base.KeyNotFound(keys.join(','));
|
|
|
|
},
|
2011-03-31 10:20:23 +00:00
|
|
|
/**
|
|
|
|
* Adds a new key and value to the registry.
|
|
|
|
*
|
|
|
|
* This method can be chained.
|
|
|
|
*
|
|
|
|
* @param {String} key
|
|
|
|
* @param {String} object_path fully qualified dotted object path
|
|
|
|
* @returns {openerp.base.Registry} itself
|
|
|
|
*/
|
|
|
|
add: function (key, object_path) {
|
|
|
|
this.map[key] = object_path;
|
|
|
|
return this;
|
2011-06-03 09:38:17 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Creates and returns a copy of the current mapping, with the provided
|
|
|
|
* mapping argument added in (replacing existing keys if needed)
|
|
|
|
*
|
|
|
|
* @param {Object} [mapping={}] a mapping of keys to object-paths
|
|
|
|
*/
|
|
|
|
clone: function (mapping) {
|
|
|
|
return new openerp.base.Registry(
|
|
|
|
_.extend({}, this.map, mapping || {}));
|
2011-03-31 10:20:23 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-05-24 16:34:20 +00:00
|
|
|
/**
|
2011-07-22 11:21:08 +00:00
|
|
|
* OpenERP session aware controller
|
|
|
|
* a controller takes an already existing dom element and manage it
|
2011-05-24 16:34:20 +00:00
|
|
|
*/
|
2011-07-22 11:21:08 +00:00
|
|
|
openerp.base.Controller = openerp.base.Controller.extend( /** @lends openerp.base.Controller# */{
|
2011-07-18 12:54:22 +00:00
|
|
|
init: function(parent, element_id) {
|
|
|
|
this._super(parent, element_id);
|
2011-07-22 11:21:08 +00:00
|
|
|
if(this.controller_parent && this.controller_parent.session) {
|
|
|
|
this.session = this.controller_parent.session;
|
|
|
|
}
|
2011-04-09 23:07:27 +00:00
|
|
|
},
|
2011-07-22 11:21:08 +00:00
|
|
|
/**
|
|
|
|
* Performs a JSON-RPC call
|
|
|
|
*
|
|
|
|
* @param {String} url endpoint url
|
|
|
|
* @param {Object} data RPC parameters
|
|
|
|
* @param {Function} success RPC call success callback
|
|
|
|
* @param {Function} error RPC call error callback
|
|
|
|
* @returns {jQuery.Deferred} deferred object for the RPC call
|
|
|
|
*/
|
|
|
|
rpc: function(url, data, success, error) {
|
|
|
|
return this.session.rpc(url, data, success, error);
|
2011-04-09 23:07:27 +00:00
|
|
|
},
|
2011-07-22 11:21:08 +00:00
|
|
|
do_action: function(action, on_finished) {
|
|
|
|
return this.parent.do_action(action, on_finished);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* OpenERP session aware widget
|
|
|
|
* A widget is a controller that doesnt take an element_id
|
|
|
|
* it render its own html render() that you should insert into the dom
|
|
|
|
* and bind it at start()
|
|
|
|
*/
|
|
|
|
openerp.base.BaseWidget = openerp.base.Controller.extend({
|
|
|
|
/**
|
|
|
|
* The name of the QWeb template that will be used for rendering. Must be
|
|
|
|
* redefined in subclasses or the render() method can not be used.
|
|
|
|
*
|
|
|
|
* @type string
|
|
|
|
*/
|
|
|
|
template: null,
|
|
|
|
/**
|
|
|
|
* The prefix used to generate an id automatically. Should be redefined in
|
|
|
|
* subclasses. If it is not defined, a default identifier will be used.
|
|
|
|
*
|
|
|
|
* @type string
|
|
|
|
*/
|
|
|
|
identifier_prefix: 'generic-identifier',
|
|
|
|
/**
|
|
|
|
* Base class for widgets. Handle rendering (based on a QWeb template),
|
|
|
|
* identifier generation, parenting and destruction of the widget.
|
|
|
|
* Also initialize the identifier.
|
|
|
|
*
|
|
|
|
* @constructs
|
|
|
|
* @params {openerp.base.search.BaseWidget} parent The parent widget.
|
|
|
|
*/
|
|
|
|
init: function (parent) {
|
|
|
|
this._super(parent);
|
|
|
|
this.make_id(this.identifier_prefix);
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Sets and returns a globally unique identifier for the widget.
|
|
|
|
*
|
|
|
|
* If a prefix is appended, the identifier will be appended to it.
|
|
|
|
*
|
|
|
|
* @params sections prefix sections, empty/falsy sections will be removed
|
|
|
|
*/
|
|
|
|
make_id: function () {
|
|
|
|
this.element_id = _.uniqueId(_.toArray(arguments).join('_'));
|
|
|
|
return this.element_id;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Render the widget. This.template must be defined.
|
|
|
|
* The content of the current object is passed as context to the template.
|
|
|
|
*
|
|
|
|
* @param {object} additional Additional context arguments to pass to the template.
|
|
|
|
*/
|
|
|
|
render: function (additional) {
|
|
|
|
return QWeb.render(this.template, _.extend({}, this, additional != null ? additional : {}));
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* "Starts" the widgets. Called at the end of the rendering, this allows
|
|
|
|
* to get a jQuery object referring to the DOM ($element attribute).
|
|
|
|
*/
|
|
|
|
start: function () {
|
|
|
|
this._super();
|
|
|
|
var tmp = document.getElementById(this.element_id);
|
|
|
|
this.$element = tmp ? $(tmp) : null;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* "Stops" the widgets. Called when the view destroys itself, this
|
|
|
|
* lets the widgets clean up after themselves.
|
|
|
|
*/
|
|
|
|
stop: function () {
|
|
|
|
if(this.$element != null) {
|
|
|
|
this.$element.remove();
|
|
|
|
}
|
2011-07-22 16:27:01 +00:00
|
|
|
this._super();
|
2011-04-09 23:07:27 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-07-22 11:21:08 +00:00
|
|
|
openerp.base.Session = openerp.base.Controller.extend( /** @lends openerp.base.Session# */{
|
2011-03-27 12:05:15 +00:00
|
|
|
/**
|
|
|
|
* @constructs
|
2011-04-04 19:52:16 +00:00
|
|
|
* @param element_id to use for exception reporting
|
2011-03-27 12:05:15 +00:00
|
|
|
* @param server
|
|
|
|
* @param port
|
|
|
|
*/
|
2011-07-18 12:54:22 +00:00
|
|
|
init: function(parent, element_id, server, port) {
|
2011-07-25 14:06:56 +00:00
|
|
|
this._super(parent, element_id);
|
2011-03-16 23:56:34 +00:00
|
|
|
this.server = (server == undefined) ? location.hostname : server;
|
|
|
|
this.port = (port == undefined) ? location.port : port;
|
|
|
|
this.rpc_mode = (server == location.hostname) ? "ajax" : "jsonp";
|
|
|
|
this.debug = true;
|
|
|
|
this.db = "";
|
|
|
|
this.login = "";
|
|
|
|
this.password = "";
|
|
|
|
this.uid = false;
|
|
|
|
this.session_id = false;
|
|
|
|
this.module_list = [];
|
|
|
|
this.module_loaded = {"base": true};
|
2011-05-17 17:43:26 +00:00
|
|
|
this.context = {};
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
2011-03-20 20:01:17 +00:00
|
|
|
start: function() {
|
|
|
|
this.session_restore();
|
|
|
|
},
|
2011-04-01 11:50:05 +00:00
|
|
|
/**
|
|
|
|
* Executes an RPC call, registering the provided callbacks.
|
|
|
|
*
|
|
|
|
* Registers a default error callback if none is provided, and handles
|
|
|
|
* setting the correct session id and session context in the parameter
|
|
|
|
* objects
|
|
|
|
*
|
|
|
|
* @param {String} url RPC endpoint
|
|
|
|
* @param {Object} params call parameters
|
|
|
|
* @param {Function} success_callback function to execute on RPC call success
|
|
|
|
* @param {Function} error_callback function to execute on RPC call failure
|
|
|
|
* @returns {jQuery.Deferred} jquery-provided ajax deferred
|
|
|
|
*/
|
2011-03-16 23:56:34 +00:00
|
|
|
rpc: function(url, params, success_callback, error_callback) {
|
2011-06-29 10:28:58 +00:00
|
|
|
var self = this;
|
2011-03-16 23:56:34 +00:00
|
|
|
// Construct a JSON-RPC2 request, method is currently unused
|
|
|
|
params.session_id = this.session_id;
|
|
|
|
|
|
|
|
// Call using the rpc_mode
|
2011-06-29 10:01:09 +00:00
|
|
|
var deferred = $.Deferred();
|
|
|
|
this.rpc_ajax(url, {
|
2011-03-17 13:09:46 +00:00
|
|
|
jsonrpc: "2.0",
|
|
|
|
method: "call",
|
|
|
|
params: params,
|
|
|
|
id:null
|
2011-06-29 10:01:09 +00:00
|
|
|
}).then(function () {deferred.resolve.apply(deferred, arguments);},
|
2011-07-14 09:57:31 +00:00
|
|
|
function(error) {deferred.reject(error, $.Event());});
|
2011-06-29 10:28:58 +00:00
|
|
|
return deferred.fail(function() {
|
|
|
|
deferred.fail(function(error, event) {
|
2011-06-29 10:01:09 +00:00
|
|
|
if (!event.isDefaultPrevented()) {
|
2011-06-29 10:28:58 +00:00
|
|
|
self.on_rpc_error(error, event);
|
2011-06-29 10:01:09 +00:00
|
|
|
}
|
|
|
|
});
|
2011-06-29 10:28:58 +00:00
|
|
|
}).then(success_callback, error_callback).promise();
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
2011-04-01 11:50:05 +00:00
|
|
|
/**
|
|
|
|
* Raw JSON-RPC call
|
|
|
|
*
|
|
|
|
* @returns {jQuery.Deferred} ajax-based deferred object
|
|
|
|
*/
|
2011-06-29 10:28:58 +00:00
|
|
|
rpc_ajax: function(url, payload) {
|
2011-03-16 23:56:34 +00:00
|
|
|
var self = this;
|
|
|
|
this.on_rpc_request();
|
2011-04-07 13:50:42 +00:00
|
|
|
// url can be an $.ajax option object
|
|
|
|
if (_.isString(url)) {
|
|
|
|
url = {
|
|
|
|
url: url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var ajax = _.extend({
|
2011-03-16 23:56:34 +00:00
|
|
|
type: "POST",
|
|
|
|
url: url,
|
|
|
|
dataType: 'json',
|
2011-03-17 13:09:46 +00:00
|
|
|
contentType: 'application/json',
|
|
|
|
data: JSON.stringify(payload),
|
2011-06-29 10:01:09 +00:00
|
|
|
processData: false
|
|
|
|
}, url);
|
|
|
|
var deferred = $.Deferred();
|
|
|
|
$.ajax(ajax).done(function(response, textStatus, jqXHR) {
|
2011-07-14 09:57:31 +00:00
|
|
|
self.on_rpc_response();
|
|
|
|
if (!response.error) {
|
|
|
|
deferred.resolve(response["result"], textStatus, jqXHR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (response.error.data.type !== "session_invalid") {
|
|
|
|
deferred.reject(response.error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
self.uid = false;
|
|
|
|
self.on_session_invalid(function() {
|
|
|
|
self.rpc(url, payload.params,
|
|
|
|
function() {
|
|
|
|
deferred.resolve.apply(deferred, arguments);
|
|
|
|
},
|
|
|
|
function(error, event) {
|
|
|
|
event.preventDefault();
|
|
|
|
deferred.reject.apply(deferred, arguments);
|
|
|
|
});
|
2011-06-29 10:01:09 +00:00
|
|
|
});
|
2011-07-14 09:57:31 +00:00
|
|
|
}).fail(function(jqXHR, textStatus, errorThrown) {
|
|
|
|
self.on_rpc_response();
|
|
|
|
var error = {
|
|
|
|
code: -32098,
|
|
|
|
message: "XmlHttpRequestError " + errorThrown,
|
|
|
|
data: {type: "xhr"+textStatus, debug: jqXHR.responseText, objects: [jqXHR, errorThrown] }
|
|
|
|
};
|
|
|
|
deferred.reject(error);
|
|
|
|
});
|
2011-06-29 10:28:58 +00:00
|
|
|
return deferred.promise();
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
|
|
|
on_rpc_request: function() {
|
|
|
|
},
|
|
|
|
on_rpc_response: function() {
|
|
|
|
},
|
|
|
|
on_rpc_error: function(error) {
|
|
|
|
},
|
2011-03-20 20:01:17 +00:00
|
|
|
/**
|
|
|
|
* The session is validated either by login or by restoration of a previous session
|
|
|
|
*/
|
|
|
|
on_session_valid: function() {
|
|
|
|
if(!openerp._modules_loaded)
|
|
|
|
this.load_modules();
|
|
|
|
},
|
2011-03-16 23:56:34 +00:00
|
|
|
on_session_invalid: function(contination) {
|
|
|
|
},
|
2011-03-20 20:01:17 +00:00
|
|
|
session_is_valid: function() {
|
2011-03-16 23:56:34 +00:00
|
|
|
return this.uid;
|
|
|
|
},
|
|
|
|
session_login: function(db, login, password, success_callback) {
|
|
|
|
var self = this;
|
|
|
|
this.db = db;
|
|
|
|
this.login = login;
|
|
|
|
this.password = password;
|
|
|
|
var params = { db: this.db, login: this.login, password: this.password };
|
|
|
|
this.rpc("/base/session/login", params, function(result) {
|
|
|
|
self.session_id = result.session_id;
|
|
|
|
self.uid = result.uid;
|
2011-03-20 20:01:17 +00:00
|
|
|
self.session_save();
|
|
|
|
self.on_session_valid();
|
2011-03-16 23:56:34 +00:00
|
|
|
if (success_callback)
|
|
|
|
success_callback();
|
|
|
|
});
|
|
|
|
},
|
2011-03-20 20:01:17 +00:00
|
|
|
session_logout: function() {
|
|
|
|
this.uid = false;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Reloads uid and session_id from local storage, if they exist
|
|
|
|
*/
|
|
|
|
session_restore: function () {
|
|
|
|
this.uid = this.get_cookie('uid');
|
|
|
|
this.session_id = this.get_cookie('session_id');
|
|
|
|
// we should do an rpc to confirm that this session_id is valid and if it is retrieve the information about db and login
|
|
|
|
// then call on_session_valid
|
|
|
|
this.on_session_valid();
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Saves the session id and uid locally
|
|
|
|
*/
|
|
|
|
session_save: function () {
|
|
|
|
this.set_cookie('uid', this.uid);
|
|
|
|
this.set_cookie('session_id', this.session_id);
|
|
|
|
},
|
2011-06-06 09:04:54 +00:00
|
|
|
logout: function() {
|
|
|
|
this.uid = this.get_cookie('uid');
|
|
|
|
this.session_id = this.get_cookie('session_id');
|
2011-06-06 09:49:55 +00:00
|
|
|
this.set_cookie('uid', '');
|
|
|
|
this.set_cookie('session_id', '');
|
2011-06-06 09:04:54 +00:00
|
|
|
this.on_session_invalid(function() {});
|
|
|
|
},
|
2011-03-20 20:01:17 +00:00
|
|
|
/**
|
|
|
|
* Fetches a cookie stored by an openerp session
|
|
|
|
*
|
2011-03-27 12:05:15 +00:00
|
|
|
* @private
|
2011-03-20 20:01:17 +00:00
|
|
|
* @param name the cookie's name
|
|
|
|
*/
|
|
|
|
get_cookie: function (name) {
|
|
|
|
var nameEQ = this.element_id + '|' + name + '=';
|
|
|
|
var cookies = document.cookie.split(';');
|
|
|
|
for(var i=0; i<cookies.length; ++i) {
|
|
|
|
var cookie = cookies[i].replace(/^\s*/, '');
|
|
|
|
if(cookie.indexOf(nameEQ) === 0) {
|
2011-07-25 12:09:40 +00:00
|
|
|
return JSON.parse(decodeURIComponent(cookie.substring(nameEQ.length)));
|
2011-03-20 20:01:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
/**
|
2011-03-27 12:05:15 +00:00
|
|
|
* Create a new cookie with the provided name and value
|
2011-03-20 20:01:17 +00:00
|
|
|
*
|
2011-03-27 12:05:15 +00:00
|
|
|
* @private
|
2011-03-20 20:01:17 +00:00
|
|
|
* @param name the cookie's name
|
|
|
|
* @param value the cookie's value
|
|
|
|
* @param ttl the cookie's time to live, 1 year by default, set to -1 to delete
|
|
|
|
*/
|
|
|
|
set_cookie: function (name, value, ttl) {
|
|
|
|
ttl = ttl || 24*60*60*365;
|
|
|
|
document.cookie = [
|
2011-07-25 12:09:40 +00:00
|
|
|
this.element_id + '|' + name + '=' + encodeURIComponent(JSON.stringify(value)),
|
2011-03-20 20:01:17 +00:00
|
|
|
'max-age=' + ttl,
|
|
|
|
'expires=' + new Date(new Date().getTime() + ttl*1000).toGMTString()
|
|
|
|
].join(';');
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
2011-03-20 20:01:17 +00:00
|
|
|
/**
|
|
|
|
* Load additional web addons of that instance and init them
|
|
|
|
*/
|
|
|
|
load_modules: function() {
|
2011-03-16 23:56:34 +00:00
|
|
|
var self = this;
|
|
|
|
this.rpc('/base/session/modules', {}, function(result) {
|
2011-07-23 13:53:44 +00:00
|
|
|
self.module_list = result;
|
2011-04-13 12:50:42 +00:00
|
|
|
var modules = self.module_list.join(',');
|
2011-07-23 13:35:43 +00:00
|
|
|
if(self.debug || true) {
|
|
|
|
self.rpc('/base/webclient/csslist', {"mods": modules}, self.do_load_css);
|
|
|
|
self.rpc('/base/webclient/jslist', {"mods": modules}, self.do_load_js);
|
|
|
|
} else {
|
|
|
|
self.do_load_css(["/base/webclient/css?mods="+modules]);
|
|
|
|
self.do_load_js(["/base/webclient/js?mods="+modules]);
|
|
|
|
}
|
2011-03-16 23:56:34 +00:00
|
|
|
openerp._modules_loaded = true;
|
|
|
|
});
|
|
|
|
},
|
2011-07-23 13:35:43 +00:00
|
|
|
do_load_css: function (files) {
|
|
|
|
_.each(files, function (file) {
|
2011-04-13 12:50:42 +00:00
|
|
|
$('head').append($('<link>', {
|
|
|
|
'href': file,
|
|
|
|
'rel': 'stylesheet',
|
|
|
|
'type': 'text/css'
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
},
|
2011-07-23 13:35:43 +00:00
|
|
|
do_load_js: function(files) {
|
|
|
|
var self = this;
|
|
|
|
if(files.length != 0) {
|
|
|
|
var file = files.shift();
|
|
|
|
var tag = document.createElement('script');
|
|
|
|
tag.type = 'text/javascript';
|
|
|
|
tag.src = file;
|
|
|
|
tag.onload = tag.onreadystatechange = function() {
|
|
|
|
if ( (tag.readyState && tag.readyState != "loaded" && tag.readyState != "complete") || tag.onload_done )
|
|
|
|
return;
|
|
|
|
tag.onload_done = true;
|
|
|
|
self.do_load_js(files);
|
|
|
|
};
|
|
|
|
document.head.appendChild(tag);
|
|
|
|
} else {
|
|
|
|
this.on_modules_loaded();
|
|
|
|
}
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
2011-03-20 20:01:17 +00:00
|
|
|
on_modules_loaded: function() {
|
2011-04-13 12:50:42 +00:00
|
|
|
for(var j=0; j<this.module_list.length; j++) {
|
|
|
|
var mod = this.module_list[j];
|
|
|
|
if(this.module_loaded[mod])
|
2011-03-16 23:56:34 +00:00
|
|
|
continue;
|
|
|
|
openerp[mod] = {};
|
|
|
|
// init module mod
|
2011-04-11 11:59:33 +00:00
|
|
|
if(openerp._openerp[mod] != undefined) {
|
|
|
|
openerp._openerp[mod](openerp);
|
2011-04-13 12:50:42 +00:00
|
|
|
this.module_loaded[mod] = true;
|
2011-04-11 11:59:33 +00:00
|
|
|
}
|
2011-03-16 23:56:34 +00:00
|
|
|
}
|
2011-03-24 20:35:38 +00:00
|
|
|
}
|
2011-03-20 20:01:17 +00:00
|
|
|
});
|
|
|
|
|
2011-07-22 11:21:08 +00:00
|
|
|
openerp.base.Notification = openerp.base.Controller.extend({
|
2011-07-18 12:54:22 +00:00
|
|
|
init: function(parent, element_id) {
|
|
|
|
this._super(parent, element_id);
|
2011-07-22 11:21:08 +00:00
|
|
|
this.$element.notify({
|
|
|
|
speed: 500,
|
|
|
|
expires: 1500
|
|
|
|
});
|
2011-04-10 00:12:22 +00:00
|
|
|
},
|
2011-07-22 11:21:08 +00:00
|
|
|
notify: function(title, text) {
|
|
|
|
this.$element.notify('create', {
|
|
|
|
title: title,
|
|
|
|
text: text
|
|
|
|
});
|
2011-04-10 00:12:22 +00:00
|
|
|
},
|
2011-07-22 11:21:08 +00:00
|
|
|
warn: function(title, text) {
|
|
|
|
this.$element.notify('create', 'oe_notification_alert', {
|
|
|
|
title: title,
|
|
|
|
text: text
|
|
|
|
});
|
2011-04-10 00:12:22 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-06-16 14:37:11 +00:00
|
|
|
openerp.base.Dialog = openerp.base.BaseWidget.extend({
|
|
|
|
dialog_title: "",
|
|
|
|
identifier_prefix: 'dialog',
|
2011-07-18 12:54:22 +00:00
|
|
|
init: function (parent, options) {
|
2011-07-26 10:01:36 +00:00
|
|
|
var self = this;
|
2011-07-18 12:54:22 +00:00
|
|
|
this._super(parent);
|
2011-06-21 12:07:50 +00:00
|
|
|
this.options = {
|
2011-06-16 14:37:11 +00:00
|
|
|
modal: true,
|
2011-06-21 12:07:50 +00:00
|
|
|
width: 'auto',
|
2011-06-16 14:37:11 +00:00
|
|
|
min_width: 0,
|
|
|
|
max_width: '100%',
|
2011-06-21 12:07:50 +00:00
|
|
|
height: 'auto',
|
2011-06-16 14:37:11 +00:00
|
|
|
min_height: 0,
|
|
|
|
max_height: '100%',
|
2011-06-21 12:07:50 +00:00
|
|
|
autoOpen: false,
|
2011-07-26 10:01:36 +00:00
|
|
|
buttons: {},
|
|
|
|
close: function () {
|
|
|
|
self.stop();
|
|
|
|
}
|
2011-06-21 12:07:50 +00:00
|
|
|
};
|
2011-06-16 14:37:11 +00:00
|
|
|
for (var f in this) {
|
|
|
|
if (f.substr(0, 10) == 'on_button_') {
|
2011-06-21 12:07:50 +00:00
|
|
|
this.options.buttons[f.substr(10)] = this[f];
|
2011-06-16 14:37:11 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-21 12:07:50 +00:00
|
|
|
if (options) {
|
|
|
|
this.set_options(options);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
set_options: function(options) {
|
|
|
|
options = options || {};
|
|
|
|
options.width = this.get_width(options.width || this.options.width);
|
|
|
|
options.min_width = this.get_width(options.min_width || this.options.min_width);
|
|
|
|
options.max_width = this.get_width(options.max_width || this.options.max_width);
|
|
|
|
options.height = this.get_height(options.height || this.options.height);
|
|
|
|
options.min_height = this.get_height(options.min_height || this.options.min_height);
|
|
|
|
options.max_height = this.get_height(options.max_height || this.options.max_width);
|
|
|
|
|
|
|
|
if (options.width !== 'auto') {
|
|
|
|
if (options.width > options.max_width) options.width = options.max_width;
|
|
|
|
if (options.width < options.min_width) options.width = options.min_width;
|
|
|
|
}
|
|
|
|
if (options.height !== 'auto') {
|
|
|
|
if (options.height > options.max_height) options.height = options.max_height;
|
|
|
|
if (options.height < options.min_height) options.height = options.min_height;
|
|
|
|
}
|
|
|
|
if (!options.title && this.dialog_title) {
|
|
|
|
options.title = this.dialog_title;
|
|
|
|
}
|
|
|
|
_.extend(this.options, options);
|
2011-06-16 14:37:11 +00:00
|
|
|
},
|
|
|
|
get_width: function(val) {
|
|
|
|
return this.get_size(val.toString(), $(window.top).width());
|
|
|
|
},
|
|
|
|
get_height: function(val) {
|
|
|
|
return this.get_size(val.toString(), $(window.top).height());
|
|
|
|
},
|
|
|
|
get_size: function(val, available_size) {
|
2011-06-21 12:07:50 +00:00
|
|
|
if (val === 'auto') {
|
2011-06-16 14:37:11 +00:00
|
|
|
return val;
|
|
|
|
} else if (val.slice(-1) == "%") {
|
|
|
|
return Math.round(available_size / 100 * parseInt(val.slice(0, -1), 10));
|
|
|
|
} else {
|
|
|
|
return parseInt(val, 10);
|
|
|
|
}
|
|
|
|
},
|
2011-06-21 12:07:50 +00:00
|
|
|
start: function (auto_open) {
|
2011-06-16 14:37:11 +00:00
|
|
|
this.$dialog = $('<div id="' + this.element_id + '"></div>').dialog(this.options);
|
2011-06-21 12:07:50 +00:00
|
|
|
if (auto_open !== false) {
|
|
|
|
this.open();
|
|
|
|
}
|
2011-06-16 14:37:11 +00:00
|
|
|
this._super();
|
|
|
|
},
|
2011-06-21 12:07:50 +00:00
|
|
|
open: function(options) {
|
|
|
|
// TODO fme: bind window on resize
|
|
|
|
if (this.template) {
|
|
|
|
this.$element.html(this.render());
|
|
|
|
}
|
|
|
|
this.set_options(options);
|
|
|
|
this.$dialog.dialog(this.options).dialog('open');
|
|
|
|
},
|
2011-06-16 14:37:11 +00:00
|
|
|
stop: function () {
|
2011-06-21 12:07:50 +00:00
|
|
|
this.$dialog.dialog('destroy');
|
2011-06-16 14:37:11 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-06-21 12:10:02 +00:00
|
|
|
openerp.base.CrashManager = openerp.base.Dialog.extend({
|
|
|
|
identifier_prefix: 'dialog_crash',
|
2011-07-18 12:54:22 +00:00
|
|
|
init: function(parent) {
|
|
|
|
this._super(parent);
|
2011-04-06 21:10:37 +00:00
|
|
|
this.session.on_rpc_error.add(this.on_rpc_error);
|
|
|
|
},
|
2011-06-21 12:10:02 +00:00
|
|
|
on_button_Ok: function() {
|
|
|
|
this.close();
|
2011-04-06 21:10:37 +00:00
|
|
|
},
|
2011-06-21 12:10:02 +00:00
|
|
|
on_rpc_error: function(error) {
|
|
|
|
this.error = error;
|
2011-06-22 14:57:57 +00:00
|
|
|
if (error.data.fault_code) {
|
|
|
|
var split = error.data.fault_code.split('\n')[0].split(' -- ');
|
|
|
|
if (split.length > 1) {
|
|
|
|
error.type = split.shift();
|
|
|
|
error.data.fault_code = error.data.fault_code.substr(error.type.length + 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (error.code === 200 && error.type) {
|
|
|
|
this.dialog_title = "OpenERP " + _.capitalize(error.type);
|
2011-06-21 12:10:02 +00:00
|
|
|
this.template = 'DialogWarning';
|
|
|
|
this.open({
|
|
|
|
width: 'auto',
|
|
|
|
height: 'auto'
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.dialog_title = "OpenERP Error";
|
|
|
|
this.template = 'DialogTraceback';
|
|
|
|
this.open({
|
2011-07-04 13:18:38 +00:00
|
|
|
width: 'auto',
|
|
|
|
height: 'auto'
|
2011-06-21 12:10:02 +00:00
|
|
|
});
|
|
|
|
}
|
2011-04-06 21:10:37 +00:00
|
|
|
}
|
2011-04-04 19:52:16 +00:00
|
|
|
});
|
|
|
|
|
2011-03-16 23:56:34 +00:00
|
|
|
openerp.base.Loading = openerp.base.Controller.extend({
|
2011-07-18 12:54:22 +00:00
|
|
|
init: function(parent, element_id) {
|
|
|
|
this._super(parent, element_id);
|
2011-03-16 23:56:34 +00:00
|
|
|
this.count = 0;
|
|
|
|
this.session.on_rpc_request.add_first(this.on_rpc_event, 1);
|
|
|
|
this.session.on_rpc_response.add_last(this.on_rpc_event, -1);
|
|
|
|
},
|
|
|
|
on_rpc_event : function(increment) {
|
|
|
|
this.count += increment;
|
|
|
|
if (this.count) {
|
|
|
|
//this.$element.html(QWeb.render("Loading", {}));
|
|
|
|
this.$element.html("Loading ("+this.count+")");
|
|
|
|
this.$element.show();
|
|
|
|
} else {
|
|
|
|
this.$element.fadeOut();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-04-09 23:07:27 +00:00
|
|
|
openerp.base.Database = openerp.base.Controller.extend({
|
2011-07-26 08:03:18 +00:00
|
|
|
init: function(parent, element_id, option_id) {
|
|
|
|
this._super(parent, element_id);
|
|
|
|
this.$option_id = $('#' + option_id);
|
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
this.$element.html(QWeb.render("Database", this));
|
2011-08-01 09:16:36 +00:00
|
|
|
this.$element.closest(".openerp")
|
|
|
|
.removeClass("login-mode")
|
|
|
|
.addClass("database_block");
|
2011-06-29 06:17:55 +00:00
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
2011-08-01 09:31:30 +00:00
|
|
|
var fetch_db = this.rpc("/base/database/get_databases_list", {}, function(result) {
|
2011-06-29 18:15:57 +00:00
|
|
|
self.db_list = result.db_list;
|
|
|
|
});
|
2011-08-01 09:31:30 +00:00
|
|
|
var fetch_langs = this.rpc("/base/session/get_lang_list", {}, function(result) {
|
2011-07-26 08:20:02 +00:00
|
|
|
if (!result.error) {
|
|
|
|
self.lang_list = result.lang_list;
|
|
|
|
} else {
|
2011-08-01 09:28:29 +00:00
|
|
|
$('<div>').dialog({
|
|
|
|
modal: true,
|
|
|
|
title: result.title,
|
|
|
|
buttons: {
|
|
|
|
Ok: function() {
|
|
|
|
$(this).dialog("close");
|
2011-07-26 08:20:02 +00:00
|
|
|
}
|
2011-08-01 09:28:29 +00:00
|
|
|
}
|
|
|
|
}).html(result.error);
|
2011-07-26 08:20:02 +00:00
|
|
|
}
|
2011-07-01 06:58:42 +00:00
|
|
|
});
|
2011-08-01 09:31:30 +00:00
|
|
|
$.when(fetch_db, fetch_langs).then(function () {self.do_db_create();});
|
2011-07-01 06:58:42 +00:00
|
|
|
|
2011-07-13 07:07:12 +00:00
|
|
|
this.$element.find('#db-create').click(this.do_db_create);
|
|
|
|
this.$element.find('#db-drop').click(this.do_db_drop);
|
|
|
|
this.$element.find('#db-backup').click(this.do_db_backup);
|
|
|
|
this.$element.find('#db-restore').click(this.do_db_restore);
|
|
|
|
this.$element.find('#db-change-password').click(this.do_change_password);
|
|
|
|
this.$element.find('#back-to-login').click(function() {
|
2011-08-02 08:10:22 +00:00
|
|
|
self.stop();
|
2011-07-26 08:03:18 +00:00
|
|
|
});
|
|
|
|
},
|
2011-08-02 08:10:22 +00:00
|
|
|
stop: function () {
|
|
|
|
this.$option_id.empty();
|
|
|
|
|
|
|
|
this.$element
|
|
|
|
.find('#db-create, #db-drop, #db-backup, #db-restore, #db-change-password, #back-to-login')
|
|
|
|
.unbind('click')
|
|
|
|
.end()
|
|
|
|
.closest(".openerp")
|
|
|
|
.addClass("login-mode")
|
|
|
|
.removeClass("database_block")
|
|
|
|
.end()
|
|
|
|
.empty();
|
|
|
|
|
|
|
|
},
|
2011-08-01 09:56:49 +00:00
|
|
|
/**
|
|
|
|
* Converts a .serializeArray() result into a dict. Does not bother folding
|
|
|
|
* multiple identical keys into an array, last key wins.
|
|
|
|
*
|
|
|
|
* @param {Array} array
|
|
|
|
*/
|
|
|
|
to_object: function (array) {
|
|
|
|
var result = {};
|
|
|
|
_(array).each(function (record) {
|
|
|
|
result[record.name] = record.value;
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
},
|
2011-08-02 07:25:51 +00:00
|
|
|
/**
|
|
|
|
* Waits until the new database is done creating, then unblocks the UI and
|
|
|
|
* logs the user in as admin
|
|
|
|
*
|
|
|
|
* @param {Number} db_creation_id identifier for the db-creation operation, used to fetch the current installation progress
|
|
|
|
* @param {Object} info info fields for this database creation
|
|
|
|
* @param {String} info.db name of the database being created
|
|
|
|
* @param {String} info.password super-admin password for the database
|
|
|
|
*/
|
|
|
|
wait_for_newdb: function (db_creation_id, info) {
|
2011-08-02 07:00:07 +00:00
|
|
|
var self = this;
|
|
|
|
self.rpc('/base/database/progress', {
|
|
|
|
id: db_creation_id,
|
2011-08-02 07:25:51 +00:00
|
|
|
password: info.password
|
2011-08-02 07:00:07 +00:00
|
|
|
}, function (result) {
|
|
|
|
var progress = result[0];
|
|
|
|
// I'd display a progress bar, but turns out the progress status
|
|
|
|
// the server report kind-of blows goats: it's at 0 for ~75% of
|
|
|
|
// the installation, then jumps to 75%, then jumps down to either
|
|
|
|
// 0 or ~40%, then back up to 75%, then terminates. Let's keep that
|
|
|
|
// mess hidden behind a not-very-useful but not overly weird
|
|
|
|
// message instead.
|
|
|
|
if (progress < 1) {
|
|
|
|
setTimeout(function () {
|
2011-08-02 07:25:51 +00:00
|
|
|
self.wait_for_newdb(db_creation_id, info);
|
2011-08-02 07:00:07 +00:00
|
|
|
}, 500);
|
|
|
|
return;
|
|
|
|
}
|
2011-08-02 07:25:51 +00:00
|
|
|
|
|
|
|
var admin = result[1][0];
|
2011-08-02 08:28:03 +00:00
|
|
|
setTimeout(function () {
|
|
|
|
self.stop();
|
|
|
|
self.controller_parent.do_login(
|
|
|
|
info.db, admin.login, admin.password);
|
|
|
|
$.unblockUI();
|
|
|
|
});
|
2011-08-02 07:00:07 +00:00
|
|
|
});
|
|
|
|
},
|
2011-07-26 08:03:18 +00:00
|
|
|
do_db_create: function() {
|
|
|
|
var self = this;
|
2011-07-13 07:07:12 +00:00
|
|
|
self.$option_id.html(QWeb.render("CreateDB", self));
|
2011-08-01 10:44:53 +00:00
|
|
|
|
|
|
|
self.$option_id.find("form[name=create_db_form]").validate({
|
|
|
|
submitHandler: function (form) {
|
|
|
|
var fields = $(form).serializeArray();
|
2011-08-02 07:00:07 +00:00
|
|
|
$.blockUI();
|
2011-08-01 10:44:53 +00:00
|
|
|
self.rpc("/base/database/create_db", {'fields': fields}, function(result) {
|
|
|
|
if (!result.error) {
|
|
|
|
self.db_list.push(self.to_object(fields)['db_name']);
|
|
|
|
self.db_list.sort();
|
2011-08-02 07:25:51 +00:00
|
|
|
var form_obj = self.to_object(fields);
|
2011-08-02 07:00:07 +00:00
|
|
|
self.wait_for_newdb(
|
2011-08-02 07:25:51 +00:00
|
|
|
result, {
|
|
|
|
password: form_obj['super_admin_pwd'],
|
|
|
|
db: form_obj['db_name']
|
|
|
|
});
|
2011-08-01 10:44:53 +00:00
|
|
|
} else {
|
2011-08-02 07:00:07 +00:00
|
|
|
$.unblockUI();
|
2011-08-01 10:44:53 +00:00
|
|
|
$('<div>').dialog({
|
|
|
|
modal: true,
|
|
|
|
title: result.title,
|
|
|
|
buttons: {
|
|
|
|
Ok: function() {
|
|
|
|
$(this).dialog("close");
|
|
|
|
}
|
2011-07-26 08:03:18 +00:00
|
|
|
}
|
2011-08-01 10:44:53 +00:00
|
|
|
}).html(result.error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-07-26 08:03:18 +00:00
|
|
|
});
|
2011-07-13 07:07:12 +00:00
|
|
|
},
|
|
|
|
|
2011-07-26 08:03:18 +00:00
|
|
|
do_db_drop: function() {
|
|
|
|
var self = this;
|
2011-07-13 07:07:12 +00:00
|
|
|
self.$option_id.html(QWeb.render("DropDB", self));
|
|
|
|
|
2011-08-01 10:44:53 +00:00
|
|
|
self.$option_id.find("form[name=drop_db_form]").validate({
|
|
|
|
submitHandler: function (form) {
|
|
|
|
var $form = $(form),
|
|
|
|
fields = $form.serializeArray(),
|
|
|
|
$db_list = $form.find('select[name=drop_db]'),
|
|
|
|
db = $db_list.val();
|
|
|
|
|
|
|
|
if (!confirm("Do you really want to delete the database: " + db + " ?")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
self.rpc("/base/database/drop_db", {'fields': fields}, function(result) {
|
|
|
|
if (! result.error) {
|
|
|
|
$db_list.find(':selected').remove();
|
2011-08-01 09:56:49 +00:00
|
|
|
self.db_list.splice(
|
|
|
|
_.indexOf(self.db_list, db, true), 1);
|
2011-08-01 09:17:33 +00:00
|
|
|
self.notification.notify("Dropping database", "The database '" + db + "' has been dropped");
|
2011-08-01 10:44:53 +00:00
|
|
|
} else {
|
2011-08-01 09:17:33 +00:00
|
|
|
$('<div>').dialog({
|
|
|
|
modal: true,
|
|
|
|
title: result.title,
|
|
|
|
buttons: {
|
|
|
|
Ok: function() {
|
|
|
|
$(this).dialog("close");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).html(result.error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-06-29 18:15:57 +00:00
|
|
|
});
|
2011-07-13 07:07:12 +00:00
|
|
|
},
|
2011-08-01 13:12:54 +00:00
|
|
|
|
|
|
|
wait_for_file: function (token, cleanup) {
|
|
|
|
var cookie_name = 'fileToken',
|
|
|
|
cookie_length = cookie_name.length;
|
|
|
|
var timer = setInterval(function () {
|
|
|
|
var cookies = document.cookie.split(';');
|
|
|
|
for(var i=0; i<cookies.length; ++i) {
|
|
|
|
var cookie = cookies[i].replace(/^\s*/, '');
|
|
|
|
if(!cookie.indexOf(cookie_name) === 0) { continue; }
|
|
|
|
var cookie_val = cookie.substring(cookie_length + 1);
|
|
|
|
if(parseInt(cookie_val, 10) !== token) { continue; }
|
|
|
|
|
|
|
|
// clear waiter
|
|
|
|
clearInterval(timer);
|
|
|
|
// clear cookie
|
|
|
|
document.cookie = _.sprintf("%s=;expires=%s;path=/",
|
|
|
|
cookie_name, new Date().toGMTString());
|
|
|
|
|
|
|
|
if (cleanup) { cleanup(); }
|
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
},
|
2011-07-13 07:07:12 +00:00
|
|
|
do_db_backup: function() {
|
2011-07-26 08:03:18 +00:00
|
|
|
var self = this;
|
2011-07-13 07:07:12 +00:00
|
|
|
self.$option_id.html(QWeb.render("BackupDB", self));
|
2011-08-01 10:44:53 +00:00
|
|
|
|
|
|
|
self.$option_id.find("form[name=backup_db_form]").validate({
|
|
|
|
submitHandler: function (form) {
|
2011-08-02 08:43:12 +00:00
|
|
|
$.blockUI();
|
2011-08-01 13:12:54 +00:00
|
|
|
// need to detect when the file is done downloading (not used
|
|
|
|
// yet, but we'll need it to fix the UI e.g. with a throbber
|
|
|
|
// while dump is being generated), iframe load event only fires
|
|
|
|
// when the iframe content loads, so we need to go smarter:
|
|
|
|
// http://geekswithblogs.net/GruffCode/archive/2010/10/28/detecting-the-file-download-dialog-in-the-browser.aspx
|
|
|
|
var $target = $('#backup-target'),
|
|
|
|
token = new Date().getTime();
|
|
|
|
if (!$target.length) {
|
|
|
|
$target = $('<iframe id="backup-target" style="display: none;">')
|
|
|
|
.appendTo(document.body);
|
|
|
|
}
|
|
|
|
$(form).find('input[name=token]').val(token);
|
|
|
|
form.submit();
|
2011-08-01 10:44:53 +00:00
|
|
|
|
2011-08-02 08:43:12 +00:00
|
|
|
self.wait_for_file(token, function () {
|
|
|
|
$.unblockUI();
|
|
|
|
});
|
2011-08-01 10:44:53 +00:00
|
|
|
}
|
|
|
|
});
|
2011-07-13 07:07:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
do_db_restore: function() {
|
2011-07-26 08:03:18 +00:00
|
|
|
var self = this;
|
2011-07-13 07:07:12 +00:00
|
|
|
self.$option_id.html(QWeb.render("RestoreDB", self));
|
|
|
|
|
2011-08-01 10:44:53 +00:00
|
|
|
self.$option_id.find("form[name=restore_db_form]").validate({
|
|
|
|
submitHandler: function (form) {
|
2011-08-02 08:43:12 +00:00
|
|
|
$.blockUI();
|
2011-08-01 14:47:28 +00:00
|
|
|
$(form).ajaxSubmit({
|
|
|
|
url: '/base/database/restore_db',
|
|
|
|
type: 'POST',
|
|
|
|
dataType: 'json',
|
|
|
|
resetForm: true,
|
|
|
|
success: function () {
|
|
|
|
// TODO: ui manipulations
|
|
|
|
// note: response objects don't work
|
2011-08-02 08:43:12 +00:00
|
|
|
$.unblockUI();
|
2011-08-01 10:44:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2011-07-26 08:03:18 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
do_change_password: function() {
|
|
|
|
var self = this;
|
2011-07-13 07:07:12 +00:00
|
|
|
self.$option_id.html(QWeb.render("Change_DB_Pwd", self));
|
2011-07-26 08:03:18 +00:00
|
|
|
|
2011-08-01 10:44:53 +00:00
|
|
|
self.$option_id.find("form[name=change_pwd_form]").validate({
|
|
|
|
messages: {
|
|
|
|
old_pwd: "Please enter your previous password",
|
|
|
|
new_pwd: "Please enter your new password",
|
|
|
|
confirm_pwd: {
|
|
|
|
required: "Please confirm your new password",
|
|
|
|
equalTo: "The confirmation does not match the password"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
submitHandler: function (form) {
|
|
|
|
var fields = $(form).serializeArray();
|
2011-07-26 08:03:18 +00:00
|
|
|
|
2011-08-01 10:44:53 +00:00
|
|
|
self.rpc("/base/database/change_password_db", {'fields': fields}, function(result) {
|
|
|
|
if (!result.error) {
|
|
|
|
self.notification.notify("Changed Password", "Password has been changed successfully");
|
|
|
|
} else {
|
2011-08-01 09:17:33 +00:00
|
|
|
$('<div>').dialog({
|
2011-07-26 08:03:18 +00:00
|
|
|
modal: true,
|
|
|
|
title: result.title,
|
|
|
|
buttons: {
|
|
|
|
Ok: function() {
|
|
|
|
$(this).dialog("close");
|
|
|
|
}
|
|
|
|
}
|
2011-07-26 12:55:08 +00:00
|
|
|
}).html(result.error);
|
2011-08-01 10:44:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2011-07-26 08:03:18 +00:00
|
|
|
}
|
2011-04-05 15:53:48 +00:00
|
|
|
});
|
|
|
|
|
2011-03-16 23:56:34 +00:00
|
|
|
openerp.base.Login = openerp.base.Controller.extend({
|
2011-07-04 15:32:59 +00:00
|
|
|
remember_creditentials: true,
|
2011-07-05 04:38:11 +00:00
|
|
|
|
2011-07-18 12:54:22 +00:00
|
|
|
init: function(parent, element_id) {
|
|
|
|
this._super(parent, element_id);
|
2011-06-08 09:44:26 +00:00
|
|
|
this.has_local_storage = typeof(localStorage) != 'undefined';
|
|
|
|
this.selected_db = null;
|
|
|
|
this.selected_login = null;
|
2011-07-05 04:38:11 +00:00
|
|
|
|
2011-07-04 15:32:59 +00:00
|
|
|
if (this.has_local_storage && this.remember_creditentials) {
|
2011-06-08 09:44:26 +00:00
|
|
|
this.selected_db = localStorage.getItem('last_db_login_success');
|
|
|
|
this.selected_login = localStorage.getItem('last_login_login_success');
|
|
|
|
}
|
2011-07-12 09:11:31 +00:00
|
|
|
if (jQuery.deparam(jQuery.param.querystring()).debug != undefined) {
|
2011-07-12 09:14:31 +00:00
|
|
|
this.selected_db = this.selected_db || "trunk";
|
|
|
|
this.selected_login = this.selected_login || "admin";
|
|
|
|
this.selected_password = this.selected_password || "a";
|
2011-07-12 09:11:31 +00:00
|
|
|
}
|
2011-07-26 07:11:07 +00:00
|
|
|
if(this.parent && this.parent.session) {
|
|
|
|
this.session = this.parent.session;
|
|
|
|
}
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
2011-06-06 11:43:06 +00:00
|
|
|
var self = this;
|
2011-07-13 10:26:12 +00:00
|
|
|
this.rpc("/base/database/get_databases_list", {}, function(result) {
|
2011-06-06 11:43:06 +00:00
|
|
|
self.db_list = result.db_list;
|
|
|
|
self.display();
|
|
|
|
}, function() {
|
|
|
|
self.display();
|
|
|
|
});
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
2011-06-08 08:54:07 +00:00
|
|
|
display: function() {
|
2011-06-29 06:17:55 +00:00
|
|
|
var self = this;
|
2011-08-02 08:10:22 +00:00
|
|
|
|
2011-06-06 11:43:06 +00:00
|
|
|
this.$element.html(QWeb.render("Login", this));
|
2011-08-02 08:10:22 +00:00
|
|
|
this.database = new openerp.base.Database(
|
|
|
|
this, "oe_database", "oe_db_options");
|
|
|
|
|
2011-06-29 06:17:55 +00:00
|
|
|
this.$element.find('#oe-db-config').click(function() {
|
2011-07-26 08:03:18 +00:00
|
|
|
self.database.start();
|
2011-06-29 06:17:55 +00:00
|
|
|
});
|
2011-08-02 08:10:22 +00:00
|
|
|
|
|
|
|
this.$element.find("form").submit(this.on_submit);
|
2011-06-08 08:54:07 +00:00
|
|
|
},
|
2011-03-16 23:56:34 +00:00
|
|
|
on_login_invalid: function() {
|
2011-06-06 09:04:54 +00:00
|
|
|
this.$element.closest(".openerp").addClass("login-mode");
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
|
|
|
on_login_valid: function() {
|
2011-06-06 09:04:54 +00:00
|
|
|
this.$element.closest(".openerp").removeClass("login-mode");
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
|
|
|
on_submit: function(ev) {
|
2011-03-17 17:11:51 +00:00
|
|
|
ev.preventDefault();
|
2011-03-16 23:56:34 +00:00
|
|
|
var $e = this.$element;
|
2011-06-06 11:43:06 +00:00
|
|
|
var db = $e.find("form [name=db]").val();
|
2011-03-16 23:56:34 +00:00
|
|
|
var login = $e.find("form input[name=login]").val();
|
|
|
|
var password = $e.find("form input[name=password]").val();
|
2011-08-02 08:28:03 +00:00
|
|
|
|
|
|
|
this.do_login(db, login, password);
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Performs actual login operation, and UI-related stuff
|
|
|
|
*
|
|
|
|
* @param {String} db database to log in
|
|
|
|
* @param {String} login user login
|
|
|
|
* @param {String} password user password
|
|
|
|
*/
|
|
|
|
do_login: function (db, login, password) {
|
|
|
|
var self = this;
|
2011-03-17 15:01:53 +00:00
|
|
|
this.session.session_login(db, login, password, function() {
|
2011-03-20 20:01:17 +00:00
|
|
|
if(self.session.session_is_valid()) {
|
2011-06-08 09:44:26 +00:00
|
|
|
if (self.has_local_storage) {
|
2011-07-04 15:32:59 +00:00
|
|
|
if(self.remember_creditentials) {
|
2011-06-08 09:44:26 +00:00
|
|
|
localStorage.setItem('last_db_login_success', db);
|
|
|
|
localStorage.setItem('last_login_login_success', login);
|
|
|
|
} else {
|
|
|
|
localStorage.setItem('last_db_login_success', '');
|
|
|
|
localStorage.setItem('last_login_login_success', '');
|
|
|
|
}
|
|
|
|
}
|
2011-03-16 23:56:34 +00:00
|
|
|
self.on_login_valid();
|
|
|
|
} else {
|
2011-06-06 11:43:06 +00:00
|
|
|
self.$element.addClass("login_invalid");
|
2011-03-16 23:56:34 +00:00
|
|
|
self.on_login_invalid();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
do_ask_login: function(continuation) {
|
|
|
|
this.on_login_invalid();
|
2011-06-06 11:43:06 +00:00
|
|
|
this.$element
|
|
|
|
.removeClass("login_invalid");
|
2011-03-18 12:19:44 +00:00
|
|
|
this.on_login_valid.add({
|
2011-03-16 23:56:34 +00:00
|
|
|
position: "last",
|
|
|
|
unique: true,
|
2011-03-18 12:19:44 +00:00
|
|
|
callback: continuation
|
|
|
|
});
|
2011-06-06 09:04:54 +00:00
|
|
|
},
|
|
|
|
on_logout: function() {
|
|
|
|
this.session.logout();
|
2011-03-16 23:56:34 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-03-20 20:01:17 +00:00
|
|
|
openerp.base.Header = openerp.base.Controller.extend({
|
2011-07-18 12:54:22 +00:00
|
|
|
init: function(parent, element_id) {
|
|
|
|
this._super(parent, element_id);
|
2011-07-26 07:11:07 +00:00
|
|
|
if(parent)
|
|
|
|
this.session = parent.session;
|
2011-03-20 20:01:17 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
this.do_update();
|
|
|
|
},
|
|
|
|
do_update: function() {
|
|
|
|
this.$element.html(QWeb.render("Header", this));
|
2011-06-06 09:04:54 +00:00
|
|
|
this.$element.find(".logout").click(this.on_logout);
|
|
|
|
},
|
2011-07-26 07:11:07 +00:00
|
|
|
on_logout: function() {}
|
2011-03-20 20:01:17 +00:00
|
|
|
});
|
|
|
|
|
2011-03-16 23:56:34 +00:00
|
|
|
openerp.base.Menu = openerp.base.Controller.extend({
|
2011-07-18 12:54:22 +00:00
|
|
|
init: function(parent, element_id, secondary_menu_id) {
|
|
|
|
this._super(parent, element_id);
|
2011-03-22 11:49:19 +00:00
|
|
|
this.secondary_menu_id = secondary_menu_id;
|
|
|
|
this.$secondary_menu = $("#" + secondary_menu_id);
|
2011-03-16 23:56:34 +00:00
|
|
|
this.menu = false;
|
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
this.rpc("/base/menu/load", {}, this.on_loaded);
|
|
|
|
},
|
|
|
|
on_loaded: function(data) {
|
|
|
|
this.data = data;
|
2011-03-22 11:49:19 +00:00
|
|
|
this.$element.html(QWeb.render("Menu", this.data));
|
|
|
|
for (var i = 0; i < this.data.data.children.length; i++) {
|
|
|
|
var v = { menu : this.data.data.children[i] };
|
|
|
|
this.$secondary_menu.append(QWeb.render("Menu.secondary", v));
|
|
|
|
}
|
|
|
|
this.$secondary_menu.find("div.menu_accordion").accordion({
|
|
|
|
animated : false,
|
|
|
|
autoHeight : false,
|
|
|
|
icons : false
|
|
|
|
});
|
|
|
|
this.$secondary_menu.find("div.submenu_accordion").accordion({
|
|
|
|
animated : false,
|
|
|
|
autoHeight : false,
|
|
|
|
active: false,
|
|
|
|
collapsible: true,
|
|
|
|
header: 'h4'
|
2011-03-16 23:56:34 +00:00
|
|
|
});
|
2011-03-22 11:49:19 +00:00
|
|
|
|
|
|
|
this.$element.add(this.$secondary_menu).find("a").click(this.on_menu_click);
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
2011-03-22 11:49:19 +00:00
|
|
|
on_menu_click: function(ev, id) {
|
2011-03-25 13:21:15 +00:00
|
|
|
id = id || 0;
|
|
|
|
var $menu, $parent, $secondary;
|
|
|
|
|
2011-03-22 11:49:19 +00:00
|
|
|
if (id) {
|
|
|
|
// We can manually activate a menu with it's id (for hash url mapping)
|
2011-03-25 13:21:15 +00:00
|
|
|
$menu = this.$element.find('a[data-menu=' + id + ']');
|
2011-03-22 11:49:19 +00:00
|
|
|
if (!$menu.length) {
|
2011-03-25 13:21:15 +00:00
|
|
|
$menu = this.$secondary_menu.find('a[data-menu=' + id + ']');
|
2011-03-22 11:49:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$menu = $(ev.currentTarget);
|
2011-03-25 13:21:15 +00:00
|
|
|
id = $menu.data('menu');
|
2011-03-22 11:49:19 +00:00
|
|
|
}
|
|
|
|
if (this.$secondary_menu.has($menu).length) {
|
|
|
|
$secondary = $menu.parents('.menu_accordion');
|
2011-03-25 13:21:15 +00:00
|
|
|
$parent = this.$element.find('a[data-menu=' + $secondary.data('menu-parent') + ']');
|
2011-03-22 11:49:19 +00:00
|
|
|
} else {
|
|
|
|
$parent = $menu;
|
|
|
|
$secondary = this.$secondary_menu.find('.menu_accordion[data-menu-parent=' + $menu.attr('data-menu') + ']');
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$secondary_menu.find('.menu_accordion').hide();
|
|
|
|
// TODO: ui-accordion : collapse submenus and expand the good one
|
|
|
|
$secondary.show();
|
2011-03-25 13:23:51 +00:00
|
|
|
|
|
|
|
if (id) {
|
|
|
|
this.rpc('/base/menu/action', {'menu_id': id},
|
|
|
|
this.on_menu_action_loaded);
|
|
|
|
}
|
2011-03-22 11:49:19 +00:00
|
|
|
|
|
|
|
$('.active', this.$element.add(this.$secondary_menu)).removeClass('active');
|
|
|
|
$parent.addClass('active');
|
|
|
|
$menu.addClass('active');
|
|
|
|
$menu.parent('h4').addClass('active');
|
|
|
|
|
|
|
|
return !$menu.is(".leaf");
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
|
|
|
on_menu_action_loaded: function(data) {
|
|
|
|
var self = this;
|
2011-03-22 11:49:19 +00:00
|
|
|
if (data.action.length) {
|
2011-03-16 23:56:34 +00:00
|
|
|
var action = data.action[0][2];
|
|
|
|
self.on_action(action);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
on_action: function(action) {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
openerp.base.Homepage = openerp.base.Controller.extend({
|
|
|
|
});
|
|
|
|
|
|
|
|
openerp.base.Preferences = openerp.base.Controller.extend({
|
|
|
|
});
|
|
|
|
|
|
|
|
openerp.base.ImportExport = openerp.base.Controller.extend({
|
|
|
|
});
|
|
|
|
|
|
|
|
openerp.base.WebClient = openerp.base.Controller.extend({
|
|
|
|
init: function(element_id) {
|
|
|
|
this._super(null, element_id);
|
|
|
|
|
2011-07-22 14:28:24 +00:00
|
|
|
QWeb.add_template("/base/static/src/xml/base.xml");
|
2011-04-12 13:19:48 +00:00
|
|
|
var params = {};
|
2011-07-18 12:54:22 +00:00
|
|
|
if(jQuery.param != undefined && jQuery.deparam(jQuery.param.querystring()).kitten != undefined) {
|
2011-05-12 07:16:04 +00:00
|
|
|
this.$element.addClass("kitten-mode-activated");
|
2011-04-12 13:19:48 +00:00
|
|
|
}
|
|
|
|
this.$element.html(QWeb.render("Interface", params));
|
2011-03-16 23:56:34 +00:00
|
|
|
|
2011-07-18 12:54:22 +00:00
|
|
|
this.session = new openerp.base.Session(this,"oe_errors");
|
|
|
|
this.loading = new openerp.base.Loading(this,"oe_loading");
|
|
|
|
this.crashmanager = new openerp.base.CrashManager(this);
|
2011-06-21 12:10:02 +00:00
|
|
|
this.crashmanager.start(false);
|
2011-04-05 15:53:48 +00:00
|
|
|
|
2011-07-22 11:21:08 +00:00
|
|
|
// Do you autorize this ? will be replaced by notify() in controller
|
2011-07-18 12:54:22 +00:00
|
|
|
openerp.base.Controller.prototype.notification = new openerp.base.Notification(this, "oe_notification");
|
2011-04-05 15:53:48 +00:00
|
|
|
|
2011-07-18 12:54:22 +00:00
|
|
|
this.header = new openerp.base.Header(this, "oe_header");
|
|
|
|
this.login = new openerp.base.Login(this, "oe_login");
|
2011-06-06 09:04:54 +00:00
|
|
|
this.header.on_logout.add(this.login.on_logout);
|
2011-03-16 23:56:34 +00:00
|
|
|
|
|
|
|
this.session.on_session_invalid.add(this.login.do_ask_login);
|
2011-03-20 20:01:17 +00:00
|
|
|
this.session.on_session_valid.add_last(this.header.do_update);
|
2011-03-25 08:16:13 +00:00
|
|
|
this.session.on_session_valid.add_last(this.on_logged);
|
2011-03-16 23:56:34 +00:00
|
|
|
|
2011-07-18 12:54:22 +00:00
|
|
|
this.menu = new openerp.base.Menu(this, "oe_menu", "oe_secondary_menu");
|
2011-03-16 23:56:34 +00:00
|
|
|
this.menu.on_action.add(this.on_menu_action);
|
2011-06-29 06:17:55 +00:00
|
|
|
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
2011-03-20 20:01:17 +00:00
|
|
|
this.session.start();
|
2011-03-16 23:56:34 +00:00
|
|
|
this.header.start();
|
2011-03-20 20:01:17 +00:00
|
|
|
this.login.start();
|
2011-03-16 23:56:34 +00:00
|
|
|
this.menu.start();
|
2011-04-11 08:30:32 +00:00
|
|
|
this.notification.notify("OpenERP Client", "The openerp client has been initialized.");
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
2011-03-25 08:16:13 +00:00
|
|
|
on_logged: function() {
|
2011-07-18 12:54:22 +00:00
|
|
|
this.action_manager = new openerp.base.ActionManager(this, "oe_app");
|
2011-04-12 14:07:01 +00:00
|
|
|
this.action_manager.start();
|
2011-07-18 12:54:22 +00:00
|
|
|
|
2011-04-11 11:59:33 +00:00
|
|
|
// if using saved actions, load the action and give it to action manager
|
|
|
|
var parameters = jQuery.deparam(jQuery.param.querystring());
|
|
|
|
if(parameters["s_action"] != undefined) {
|
|
|
|
var key = parseInt(parameters["s_action"]);
|
|
|
|
var self = this;
|
|
|
|
this.rpc("/base/session/get_session_action", {key:key}, function(action) {
|
2011-04-12 14:07:01 +00:00
|
|
|
self.action_manager.do_action(action);
|
2011-04-11 11:59:33 +00:00
|
|
|
});
|
|
|
|
}
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
|
|
|
on_menu_action: function(action) {
|
2011-04-12 14:07:01 +00:00
|
|
|
this.action_manager.do_action(action);
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
|
|
|
do_about: function() {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
openerp.base.webclient = function(element_id) {
|
|
|
|
// TODO Helper to start webclient rename it openerp.base.webclient
|
|
|
|
var client = new openerp.base.WebClient(element_id);
|
|
|
|
client.start();
|
|
|
|
return client;
|
|
|
|
};
|
2011-04-09 23:07:27 +00:00
|
|
|
|
2011-03-16 23:56:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|