2011-03-16 23:56:34 +00:00
|
|
|
/*---------------------------------------------------------
|
2011-08-11 03:10:00 +00:00
|
|
|
* OpenERP Web chrome
|
2011-03-16 23:56:34 +00:00
|
|
|
*---------------------------------------------------------*/
|
2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.chrome = function(openerp) {
|
2011-12-15 10:40:31 +00:00
|
|
|
var QWeb = openerp.web.qweb,
|
|
|
|
_t = openerp.web._t;
|
2011-03-16 23:56:34 +00:00
|
|
|
|
2012-01-24 14:58:10 +00:00
|
|
|
openerp.web.Notification = openerp.web.OldWidget.extend(/** @lends openerp.web.Notification# */{
|
2011-10-13 10:26:53 +00:00
|
|
|
template: 'Notification',
|
|
|
|
|
2011-10-13 15:03:17 +00:00
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
openerp.notification = this;
|
|
|
|
},
|
|
|
|
|
2011-10-13 10:26:53 +00:00
|
|
|
start: function() {
|
|
|
|
this._super.apply(this, arguments);
|
2011-07-22 11:21:08 +00:00
|
|
|
this.$element.notify({
|
|
|
|
speed: 500,
|
2012-01-25 09:24:23 +00:00
|
|
|
expires: 2500
|
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,
|
2011-10-28 08:52:12 +00:00
|
|
|
text: text
|
2011-07-22 11:21:08 +00:00
|
|
|
});
|
2011-10-28 08:52:12 +00:00
|
|
|
}
|
2011-10-13 10:26:53 +00:00
|
|
|
|
2011-04-10 00:12:22 +00:00
|
|
|
});
|
|
|
|
|
2012-01-24 14:58:10 +00:00
|
|
|
openerp.web.Dialog = openerp.web.OldWidget.extend(/** @lends openerp.web.Dialog# */{
|
2011-06-16 14:37:11 +00:00
|
|
|
dialog_title: "",
|
2011-09-12 11:34:37 +00:00
|
|
|
/**
|
|
|
|
* @constructs openerp.web.Dialog
|
2012-01-24 14:58:10 +00:00
|
|
|
* @extends openerp.web.OldWidget
|
2011-09-12 11:34:37 +00:00
|
|
|
*
|
|
|
|
* @param parent
|
2012-01-10 10:03:49 +00:00
|
|
|
* @param options
|
2011-09-12 11:34:37 +00:00
|
|
|
*/
|
2012-01-11 11:06:48 +00:00
|
|
|
init: function (parent, options, content) {
|
2011-07-26 10:01:36 +00:00
|
|
|
var self = this;
|
2011-07-18 12:54:22 +00:00
|
|
|
this._super(parent);
|
2012-01-11 11:06:48 +00:00
|
|
|
if (content) {
|
|
|
|
this.$element = content instanceof $ ? content : $(content);
|
|
|
|
}
|
2011-08-08 17:14:07 +00:00
|
|
|
this.dialog_options = {
|
2011-06-16 14:37:11 +00:00
|
|
|
modal: true,
|
2011-12-21 13:43:06 +00:00
|
|
|
destroy_on_close: true,
|
|
|
|
width: $(window).width() * (($(window).width() > 1024) ? 0.5 : 0.75),
|
2011-06-16 14:37:11 +00:00
|
|
|
min_width: 0,
|
2011-12-21 13:43:06 +00:00
|
|
|
max_width: '95%',
|
2011-06-21 12:07:50 +00:00
|
|
|
height: 'auto',
|
2011-06-16 14:37:11 +00:00
|
|
|
min_height: 0,
|
2012-01-10 10:03:49 +00:00
|
|
|
max_height: this.get_height('100%') - 140,
|
2011-06-21 12:07:50 +00:00
|
|
|
autoOpen: false,
|
2011-12-21 13:43:06 +00:00
|
|
|
position: [false, 50],
|
2011-07-26 10:01:36 +00:00
|
|
|
buttons: {},
|
2011-12-21 13:43:06 +00:00
|
|
|
beforeClose: function () { self.on_close(); },
|
|
|
|
resizeStop: this.on_resized
|
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-08-08 17:14:07 +00:00
|
|
|
this.dialog_options.buttons[f.substr(10)] = this[f];
|
2011-06-16 14:37:11 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-10 10:03:49 +00:00
|
|
|
if (options) {
|
|
|
|
_.extend(this.dialog_options, options);
|
2011-06-21 12:07:50 +00:00
|
|
|
}
|
2012-01-11 11:06:48 +00:00
|
|
|
if (this.dialog_options.autoOpen) {
|
|
|
|
this.open();
|
|
|
|
} else {
|
|
|
|
this.$element.dialog(this.get_options());
|
|
|
|
}
|
2011-06-21 12:07:50 +00:00
|
|
|
},
|
2012-01-10 10:03:49 +00:00
|
|
|
get_options: function(options) {
|
|
|
|
var self = this,
|
|
|
|
o = _.extend({}, this.dialog_options, options || {});
|
|
|
|
_.each(['width', 'height'], function(unit) {
|
|
|
|
o[unit] = self['get_' + unit](o[unit]);
|
|
|
|
o['min_' + unit] = self['get_' + unit](o['min_' + unit] || 0);
|
|
|
|
o['max_' + unit] = self['get_' + unit](o['max_' + unit] || 0);
|
|
|
|
if (o[unit] !== 'auto' && o['min_' + unit] && o[unit] < o['min_' + unit]) o[unit] = o['min_' + unit];
|
|
|
|
if (o[unit] !== 'auto' && o['max_' + unit] && o[unit] > o['max_' + unit]) o[unit] = o['max_' + unit];
|
|
|
|
});
|
|
|
|
if (!o.title && this.dialog_title) {
|
|
|
|
o.title = this.dialog_title;
|
2011-06-21 12:07:50 +00:00
|
|
|
}
|
2012-01-10 10:03:49 +00:00
|
|
|
return o;
|
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);
|
|
|
|
}
|
|
|
|
},
|
2012-01-10 10:03:49 +00:00
|
|
|
open: function(options) {
|
2011-06-21 12:07:50 +00:00
|
|
|
// TODO fme: bind window on resize
|
|
|
|
if (this.template) {
|
|
|
|
this.$element.html(this.render());
|
|
|
|
}
|
2012-01-10 10:03:49 +00:00
|
|
|
var o = this.get_options(options);
|
|
|
|
this.$element.dialog(o).dialog('open');
|
|
|
|
if (o.height === 'auto' && o.max_height) {
|
|
|
|
this.$element.css({ 'max-height': o.max_height, 'overflow-y': 'auto' });
|
|
|
|
}
|
2011-08-22 10:19:34 +00:00
|
|
|
return this;
|
2011-06-21 12:07:50 +00:00
|
|
|
},
|
2011-07-27 15:05:42 +00:00
|
|
|
close: function() {
|
2011-12-21 13:43:06 +00:00
|
|
|
this.$element.dialog('close');
|
2011-07-27 15:05:42 +00:00
|
|
|
},
|
|
|
|
on_close: function() {
|
2011-12-21 13:43:06 +00:00
|
|
|
if (this.dialog_options.destroy_on_close) {
|
|
|
|
this.$element.dialog('destroy');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
on_resized: function() {
|
2012-01-12 12:44:56 +00:00
|
|
|
//openerp.log("Dialog resized to %d x %d", this.$element.width(), this.$element.height());
|
2011-07-27 15:05:42 +00:00
|
|
|
},
|
2011-06-16 14:37:11 +00:00
|
|
|
stop: function () {
|
2011-07-27 15:05:42 +00:00
|
|
|
// Destroy widget
|
|
|
|
this.close();
|
2011-12-21 13:43:06 +00:00
|
|
|
this.$element.dialog('destroy');
|
2011-09-28 15:16:13 +00:00
|
|
|
this._super();
|
2011-06-16 14:37:11 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-10-27 15:31:32 +00:00
|
|
|
openerp.web.CrashManager = openerp.web.CallbackEnabled.extend({
|
|
|
|
init: function() {
|
2011-11-02 10:05:11 +00:00
|
|
|
this._super();
|
2011-11-08 15:27:23 +00:00
|
|
|
openerp.connection.on_rpc_error.add(this.on_rpc_error);
|
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) {
|
2011-09-12 16:03:26 +00:00
|
|
|
var split = ("" + error.data.fault_code).split('\n')[0].split(' -- ');
|
2011-06-22 14:57:57 +00:00
|
|
|
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) {
|
2011-10-17 15:24:00 +00:00
|
|
|
this.on_managed_error(error);
|
2011-06-21 12:10:02 +00:00
|
|
|
} else {
|
2011-10-17 15:24:00 +00:00
|
|
|
this.on_traceback(error);
|
2011-06-21 12:10:02 +00:00
|
|
|
}
|
2011-10-17 15:24:00 +00:00
|
|
|
},
|
|
|
|
on_managed_error: function(error) {
|
2011-12-27 15:59:15 +00:00
|
|
|
$('<div>' + QWeb.render('CrashManagerWarning', {error: error}) + '</div>').dialog({
|
2011-11-15 12:30:59 +00:00
|
|
|
title: "OpenERP " + _.str.capitalize(error.type),
|
2011-12-15 10:40:31 +00:00
|
|
|
buttons: [
|
|
|
|
{text: _t("Ok"), click: function() { $(this).dialog("close"); }}
|
|
|
|
]
|
2011-10-17 15:24:00 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
on_traceback: function(error) {
|
2011-12-07 11:00:57 +00:00
|
|
|
var self = this;
|
2011-12-27 15:59:15 +00:00
|
|
|
var buttons = {};
|
|
|
|
if (openerp.connection.openerp_entreprise) {
|
|
|
|
buttons[_t("Send OpenERP Enterprise Report")] = function() {
|
2012-01-11 14:43:27 +00:00
|
|
|
var $this = $(this);
|
2011-12-27 15:59:15 +00:00
|
|
|
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){
|
|
|
|
if (result === false) {
|
|
|
|
alert('There was a communication error.')
|
|
|
|
} else {
|
|
|
|
$this.dialog('close');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
buttons[_t("Dont send")] = function() {
|
|
|
|
$(this).dialog("close");
|
|
|
|
};
|
2011-12-23 12:06:34 +00:00
|
|
|
} else {
|
2011-12-27 15:59:15 +00:00
|
|
|
buttons[_t("Ok")] = function() {
|
|
|
|
$(this).dialog("close");
|
|
|
|
};
|
2011-12-23 12:06:34 +00:00
|
|
|
}
|
2011-10-17 15:24:00 +00:00
|
|
|
var dialog = new openerp.web.Dialog(this, {
|
2011-12-07 11:00:57 +00:00
|
|
|
title: "OpenERP " + _.str.capitalize(this.error.type),
|
|
|
|
width: '80%',
|
|
|
|
height: '50%',
|
2011-10-17 15:24:00 +00:00
|
|
|
min_width: '800px',
|
|
|
|
min_height: '600px',
|
2011-12-23 12:06:34 +00:00
|
|
|
buttons: buttons
|
2012-01-11 11:06:48 +00:00
|
|
|
}).open();
|
2011-12-27 15:59:15 +00:00
|
|
|
dialog.$element.html(QWeb.render('CrashManagerError', {session: openerp.connection, error: error}));
|
2012-01-17 13:28:43 +00:00
|
|
|
}
|
2011-04-04 19:52:16 +00:00
|
|
|
});
|
|
|
|
|
2012-01-24 14:58:10 +00:00
|
|
|
openerp.web.Loading = openerp.web.OldWidget.extend(/** @lends openerp.web.Loading# */{
|
2011-11-15 16:55:30 +00:00
|
|
|
template: 'Loading',
|
2011-09-12 11:34:37 +00:00
|
|
|
/**
|
|
|
|
* @constructs openerp.web.Loading
|
2012-01-24 14:58:10 +00:00
|
|
|
* @extends openerp.web.OldWidget
|
2011-09-12 11:34:37 +00:00
|
|
|
*
|
|
|
|
* @param parent
|
|
|
|
* @param element_id
|
|
|
|
*/
|
2011-11-15 16:55:30 +00:00
|
|
|
init: function(parent) {
|
|
|
|
this._super(parent);
|
2011-03-16 23:56:34 +00:00
|
|
|
this.count = 0;
|
2011-10-27 13:58:28 +00:00
|
|
|
this.blocked_ui = false;
|
2012-01-04 18:11:50 +00:00
|
|
|
var self = this;
|
|
|
|
this.request_call = function() {
|
|
|
|
self.on_rpc_event(1);
|
|
|
|
};
|
|
|
|
this.response_call = function() {
|
|
|
|
self.on_rpc_event(-1);
|
|
|
|
};
|
|
|
|
this.session.on_rpc_request.add_first(this.request_call);
|
|
|
|
this.session.on_rpc_response.add_last(this.response_call);
|
|
|
|
},
|
|
|
|
stop: function() {
|
|
|
|
this.session.on_rpc_request.remove(this.request_call);
|
|
|
|
this.session.on_rpc_response.remove(this.response_call);
|
2012-01-04 18:21:12 +00:00
|
|
|
this.on_rpc_event(-this.count);
|
2012-01-04 18:11:50 +00:00
|
|
|
this._super();
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
|
|
|
on_rpc_event : function(increment) {
|
2011-10-27 13:58:28 +00:00
|
|
|
var self = this;
|
|
|
|
if (!this.count && increment === 1) {
|
|
|
|
// Block UI after 3s
|
|
|
|
this.long_running_timer = setTimeout(function () {
|
|
|
|
self.blocked_ui = true;
|
|
|
|
$.blockUI();
|
|
|
|
}, 3000);
|
|
|
|
}
|
|
|
|
|
2011-03-16 23:56:34 +00:00
|
|
|
this.count += increment;
|
2011-11-15 16:55:30 +00:00
|
|
|
if (this.count > 0) {
|
2011-03-16 23:56:34 +00:00
|
|
|
//this.$element.html(QWeb.render("Loading", {}));
|
2012-01-04 09:55:49 +00:00
|
|
|
$(".loading",this.$element).html("Loading ("+this.count+")");
|
|
|
|
$(".loading",this.$element).show();
|
2011-10-13 09:17:38 +00:00
|
|
|
this.widget_parent.$element.addClass('loading');
|
2011-03-16 23:56:34 +00:00
|
|
|
} else {
|
2011-11-15 16:55:30 +00:00
|
|
|
this.count = 0;
|
2011-10-27 13:58:28 +00:00
|
|
|
clearTimeout(this.long_running_timer);
|
|
|
|
// Don't unblock if blocked by somebody else
|
|
|
|
if (self.blocked_ui) {
|
|
|
|
this.blocked_ui = false;
|
|
|
|
$.unblockUI();
|
|
|
|
}
|
2012-01-04 09:55:49 +00:00
|
|
|
$(".loading",this.$element).fadeOut();
|
2011-10-13 09:17:38 +00:00
|
|
|
this.widget_parent.$element.removeClass('loading');
|
2011-03-16 23:56:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-01-24 14:58:10 +00:00
|
|
|
openerp.web.Database = openerp.web.OldWidget.extend(/** @lends openerp.web.Database# */{
|
2012-01-04 10:20:31 +00:00
|
|
|
template: "DatabaseManager",
|
2011-09-12 11:34:37 +00:00
|
|
|
/**
|
|
|
|
* @constructs openerp.web.Database
|
2012-01-24 14:58:10 +00:00
|
|
|
* @extends openerp.web.OldWidget
|
2011-09-12 11:34:37 +00:00
|
|
|
*
|
|
|
|
* @param parent
|
|
|
|
* @param element_id
|
|
|
|
* @param option_id
|
|
|
|
*/
|
2011-07-26 08:03:18 +00:00
|
|
|
init: function(parent, element_id, option_id) {
|
|
|
|
this._super(parent, element_id);
|
2011-12-05 13:24:25 +00:00
|
|
|
this.unblockUIFunction = $.unblockUI;
|
2012-01-17 12:00:35 +00:00
|
|
|
$.validator.addMethod('matches', function (s, _, re) {
|
|
|
|
return new RegExp(re).test(s);
|
|
|
|
}, _t("Invalid database name"));
|
2011-07-26 08:03:18 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
2012-01-04 10:20:31 +00:00
|
|
|
this.$option_id = $("#oe_db_options");
|
2011-08-09 06:44:41 +00:00
|
|
|
|
2011-06-29 06:17:55 +00:00
|
|
|
var self = this;
|
2011-09-05 11:03:09 +00:00
|
|
|
var fetch_db = this.rpc("/web/database/get_list", {}, function(result) {
|
2011-06-29 18:15:57 +00:00
|
|
|
self.db_list = result.db_list;
|
|
|
|
});
|
2011-09-05 11:03:09 +00:00
|
|
|
var fetch_langs = this.rpc("/web/session/get_lang_list", {}, function(result) {
|
2011-08-02 09:20:16 +00:00
|
|
|
if (result.error) {
|
|
|
|
self.display_error(result);
|
|
|
|
return;
|
2011-07-26 08:20:02 +00:00
|
|
|
}
|
2011-08-02 09:20:16 +00:00
|
|
|
self.lang_list = result.lang_list;
|
2011-07-01 06:58:42 +00:00
|
|
|
});
|
2011-08-02 09:18:49 +00:00
|
|
|
$.when(fetch_db, fetch_langs).then(function () {self.do_create();});
|
2011-08-09 06:44:41 +00:00
|
|
|
|
2011-08-02 09:18:49 +00:00
|
|
|
this.$element.find('#db-create').click(this.do_create);
|
|
|
|
this.$element.find('#db-drop').click(this.do_drop);
|
|
|
|
this.$element.find('#db-backup').click(this.do_backup);
|
|
|
|
this.$element.find('#db-restore').click(this.do_restore);
|
2011-07-13 07:07:12 +00:00
|
|
|
this.$element.find('#db-change-password').click(this.do_change_password);
|
|
|
|
this.$element.find('#back-to-login').click(function() {
|
2011-11-15 13:29:14 +00:00
|
|
|
self.hide();
|
2011-07-26 08:03:18 +00:00
|
|
|
});
|
|
|
|
},
|
2011-08-02 08:10:22 +00:00
|
|
|
stop: function () {
|
2011-11-15 13:29:14 +00:00
|
|
|
this.hide();
|
2011-08-02 08:10:22 +00:00
|
|
|
this.$option_id.empty();
|
|
|
|
|
|
|
|
this.$element
|
|
|
|
.find('#db-create, #db-drop, #db-backup, #db-restore, #db-change-password, #back-to-login')
|
|
|
|
.unbind('click')
|
|
|
|
.end()
|
2011-11-15 12:30:59 +00:00
|
|
|
.empty();
|
|
|
|
this._super();
|
2011-11-15 09:34:48 +00:00
|
|
|
},
|
2011-11-15 13:29:14 +00:00
|
|
|
show: function () {
|
2012-01-04 10:11:19 +00:00
|
|
|
this.$element.closest(".login")
|
2011-11-15 13:29:14 +00:00
|
|
|
.addClass("database_block");
|
|
|
|
},
|
|
|
|
hide: function () {
|
2012-01-04 10:11:19 +00:00
|
|
|
this.$element.closest(".login")
|
2011-11-15 13:29:14 +00:00
|
|
|
.removeClass("database_block")
|
|
|
|
},
|
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;
|
2011-09-05 11:03:09 +00:00
|
|
|
self.rpc('/web/database/progress', {
|
2011-08-02 07:00:07 +00:00
|
|
|
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 () {
|
2011-08-02 09:53:31 +00:00
|
|
|
self.widget_parent.do_login(
|
2011-08-02 08:28:03 +00:00
|
|
|
info.db, admin.login, admin.password);
|
2011-09-29 14:57:51 +00:00
|
|
|
self.stop();
|
2011-12-05 13:24:25 +00:00
|
|
|
self.unblockUI();
|
2011-08-02 08:28:03 +00:00
|
|
|
});
|
2011-08-02 07:00:07 +00:00
|
|
|
});
|
|
|
|
},
|
2011-12-05 13:24:25 +00:00
|
|
|
/**
|
|
|
|
* Blocks UI and replaces $.unblockUI by a noop to prevent third parties
|
|
|
|
* from unblocking the UI
|
|
|
|
*/
|
|
|
|
blockUI: function () {
|
|
|
|
$.blockUI();
|
|
|
|
$.unblockUI = function () {};
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Reinstates $.unblockUI so third parties can play with blockUI, and
|
|
|
|
* unblocks the UI
|
|
|
|
*/
|
|
|
|
unblockUI: function () {
|
|
|
|
$.unblockUI = this.unblockUIFunction;
|
|
|
|
$.unblockUI();
|
|
|
|
},
|
2011-08-02 09:13:44 +00:00
|
|
|
/**
|
|
|
|
* Displays an error dialog resulting from the various RPC communications
|
|
|
|
* failing over themselves
|
|
|
|
*
|
|
|
|
* @param {Object} error error description
|
|
|
|
* @param {String} error.title title of the error dialog
|
|
|
|
* @param {String} error.error message of the error dialog
|
|
|
|
*/
|
|
|
|
display_error: function (error) {
|
|
|
|
return $('<div>').dialog({
|
|
|
|
modal: true,
|
|
|
|
title: error.title,
|
2011-12-15 10:40:31 +00:00
|
|
|
buttons: [
|
|
|
|
{text: _t("Ok"), click: function() { $(this).dialog("close"); }}
|
|
|
|
]
|
2011-08-02 09:13:44 +00:00
|
|
|
}).html(error.error);
|
|
|
|
},
|
2011-08-02 09:18:49 +00:00
|
|
|
do_create: function() {
|
2011-07-26 08:03:18 +00:00
|
|
|
var self = this;
|
2011-08-19 02:01:56 +00:00
|
|
|
self.$option_id.html(QWeb.render("Database.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-12-05 13:24:25 +00:00
|
|
|
self.blockUI();
|
2011-09-05 11:03:09 +00:00
|
|
|
self.rpc("/web/database/create", {'fields': fields}, function(result) {
|
2011-08-02 09:13:44 +00:00
|
|
|
if (result.error) {
|
2011-12-05 13:24:25 +00:00
|
|
|
self.unblockUI();
|
2011-08-02 09:13:44 +00:00
|
|
|
self.display_error(result);
|
|
|
|
return;
|
2011-08-01 10:44:53 +00:00
|
|
|
}
|
2011-08-02 09:13:44 +00:00
|
|
|
self.db_list.push(self.to_object(fields)['db_name']);
|
|
|
|
self.db_list.sort();
|
2011-11-15 13:29:14 +00:00
|
|
|
self.widget_parent.set_db_list(self.db_list);
|
2011-08-02 09:13:44 +00:00
|
|
|
var form_obj = self.to_object(fields);
|
|
|
|
self.wait_for_newdb(result, {
|
|
|
|
password: form_obj['super_admin_pwd'],
|
|
|
|
db: form_obj['db_name']
|
|
|
|
});
|
2011-08-01 10:44:53 +00:00
|
|
|
});
|
|
|
|
}
|
2011-07-26 08:03:18 +00:00
|
|
|
});
|
2011-07-13 07:07:12 +00:00
|
|
|
},
|
2011-08-02 09:18:49 +00:00
|
|
|
do_drop: 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("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;
|
|
|
|
}
|
2011-09-05 11:03:09 +00:00
|
|
|
self.rpc("/web/database/drop", {'fields': fields}, function(result) {
|
2011-08-02 09:13:44 +00:00
|
|
|
if (result.error) {
|
|
|
|
self.display_error(result);
|
|
|
|
return;
|
2011-08-01 09:17:33 +00:00
|
|
|
}
|
2011-08-02 09:13:44 +00:00
|
|
|
$db_list.find(':selected').remove();
|
|
|
|
self.db_list.splice(_.indexOf(self.db_list, db, true), 1);
|
2011-11-15 13:29:14 +00:00
|
|
|
self.widget_parent.set_db_list(self.db_list);
|
2011-10-13 10:26:53 +00:00
|
|
|
self.do_notify("Dropping database", "The database '" + db + "' has been dropped");
|
2011-08-01 09:17:33 +00:00
|
|
|
});
|
|
|
|
}
|
2011-06-29 18:15:57 +00:00
|
|
|
});
|
2011-07-13 07:07:12 +00:00
|
|
|
},
|
2011-08-02 09:18:49 +00:00
|
|
|
do_backup: function() {
|
2011-07-26 08:03:18 +00:00
|
|
|
var self = this;
|
2011-08-30 08:53:51 +00:00
|
|
|
self.$option_id
|
|
|
|
.html(QWeb.render("BackupDB", self))
|
|
|
|
.find("form[name=backup_db_form]").validate({
|
2011-08-01 10:44:53 +00:00
|
|
|
submitHandler: function (form) {
|
2011-12-05 13:24:25 +00:00
|
|
|
self.blockUI();
|
2011-08-30 09:06:09 +00:00
|
|
|
self.session.get_file({
|
2011-08-30 08:53:51 +00:00
|
|
|
form: form,
|
2012-01-19 14:48:37 +00:00
|
|
|
success: function () {
|
|
|
|
self.do_notify(_t("Backed"),
|
|
|
|
_t("Database backed up successfully"));
|
2011-08-30 09:05:14 +00:00
|
|
|
},
|
2012-01-19 14:48:37 +00:00
|
|
|
error: openerp.webclient.crashmanager.on_rpc_error,
|
2012-01-09 08:14:41 +00:00
|
|
|
complete: function() {
|
|
|
|
self.unblockUI();
|
|
|
|
}
|
2011-08-02 08:43:12 +00:00
|
|
|
});
|
2011-08-01 10:44:53 +00:00
|
|
|
}
|
|
|
|
});
|
2011-07-13 07:07:12 +00:00
|
|
|
},
|
2011-08-02 09:18:49 +00:00
|
|
|
do_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-09 06:44:41 +00:00
|
|
|
|
2011-08-01 10:44:53 +00:00
|
|
|
self.$option_id.find("form[name=restore_db_form]").validate({
|
|
|
|
submitHandler: function (form) {
|
2011-12-05 13:24:25 +00:00
|
|
|
self.blockUI();
|
2011-08-01 14:47:28 +00:00
|
|
|
$(form).ajaxSubmit({
|
2011-09-05 11:03:09 +00:00
|
|
|
url: '/web/database/restore',
|
2011-08-01 14:47:28 +00:00
|
|
|
type: 'POST',
|
|
|
|
resetForm: true,
|
2011-08-02 09:13:44 +00:00
|
|
|
success: function (body) {
|
2011-08-01 14:47:28 +00:00
|
|
|
// TODO: ui manipulations
|
2011-08-02 09:13:44 +00:00
|
|
|
// note: response objects don't work, but we have the
|
|
|
|
// HTTP body of the response~~
|
|
|
|
|
|
|
|
// If empty body, everything went fine
|
|
|
|
if (!body) { return; }
|
|
|
|
|
|
|
|
if (body.indexOf('403 Forbidden') !== -1) {
|
|
|
|
self.display_error({
|
|
|
|
title: 'Access Denied',
|
|
|
|
error: 'Incorrect super-administrator password'
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
self.display_error({
|
|
|
|
title: 'Restore Database',
|
|
|
|
error: 'Could not restore the database'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2012-01-09 08:14:41 +00:00
|
|
|
complete: function() {
|
|
|
|
self.unblockUI();
|
2012-01-10 13:38:26 +00:00
|
|
|
self.do_notify(_t("Restored"), _t("Database restored successfully"));
|
2012-01-09 08:14:41 +00:00
|
|
|
}
|
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) {
|
2011-09-05 11:03:09 +00:00
|
|
|
self.rpc("/web/database/change_password", {
|
2011-08-02 09:13:44 +00:00
|
|
|
'fields': $(form).serializeArray()
|
|
|
|
}, function(result) {
|
|
|
|
if (result.error) {
|
|
|
|
self.display_error(result);
|
|
|
|
return;
|
2011-08-01 10:44:53 +00:00
|
|
|
}
|
2011-10-13 10:26:53 +00:00
|
|
|
self.do_notify("Changed Password", "Password has been changed successfully");
|
2011-08-01 10:44:53 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2011-07-26 08:03:18 +00:00
|
|
|
}
|
2011-04-05 15:53:48 +00:00
|
|
|
});
|
|
|
|
|
2012-01-24 14:58:10 +00:00
|
|
|
openerp.web.Login = openerp.web.OldWidget.extend(/** @lends openerp.web.Login# */{
|
2011-10-14 15:49:50 +00:00
|
|
|
remember_credentials: true,
|
2011-09-27 09:32:32 +00:00
|
|
|
|
|
|
|
template: "Login",
|
2011-09-12 11:34:37 +00:00
|
|
|
/**
|
|
|
|
* @constructs openerp.web.Login
|
2012-01-24 14:58:10 +00:00
|
|
|
* @extends openerp.web.OldWidget
|
2011-09-13 05:44:06 +00:00
|
|
|
*
|
2011-09-12 11:34:37 +00:00
|
|
|
* @param parent
|
|
|
|
* @param element_id
|
|
|
|
*/
|
2011-08-09 06:44:41 +00:00
|
|
|
|
2011-09-27 09:32:32 +00:00
|
|
|
init: function(parent) {
|
|
|
|
this._super(parent);
|
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-10-14 15:49:50 +00:00
|
|
|
if (this.has_local_storage && this.remember_credentials) {
|
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-09-02 09:46:26 +00:00
|
|
|
if (jQuery.deparam(jQuery.param.querystring()).debug != undefined) {
|
|
|
|
this.selected_password = localStorage.getItem('last_password_login_success');
|
|
|
|
}
|
2011-07-12 09:11:31 +00:00
|
|
|
}
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
2011-06-06 11:43:06 +00:00
|
|
|
var self = this;
|
2012-01-04 10:20:31 +00:00
|
|
|
this.database = new openerp.web.Database(this);
|
|
|
|
this.database.appendTo(this.$element);
|
2011-08-02 08:10:22 +00:00
|
|
|
|
2011-06-29 06:17:55 +00:00
|
|
|
this.$element.find('#oe-db-config').click(function() {
|
2011-11-15 13:29:14 +00:00
|
|
|
self.database.show();
|
2011-06-29 06:17:55 +00:00
|
|
|
});
|
2011-08-02 08:10:22 +00:00
|
|
|
|
2011-06-06 11:43:06 +00:00
|
|
|
this.$element.find("form").submit(this.on_submit);
|
2011-09-27 09:32:32 +00:00
|
|
|
|
|
|
|
this.rpc("/web/database/get_list", {}, function(result) {
|
2011-11-15 13:29:14 +00:00
|
|
|
self.set_db_list(result.db_list);
|
2011-09-27 15:53:47 +00:00
|
|
|
},
|
|
|
|
function(error, event) {
|
|
|
|
if (error.data.fault_code === 'AccessDenied') {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
2011-09-27 09:32:32 +00:00
|
|
|
});
|
2011-09-27 15:53:47 +00:00
|
|
|
|
2011-06-08 08:54:07 +00:00
|
|
|
},
|
2011-11-15 13:29:14 +00:00
|
|
|
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}))
|
|
|
|
},
|
2011-03-16 23:56:34 +00:00
|
|
|
on_submit: function(ev) {
|
2011-12-20 15:05:56 +00:00
|
|
|
if(ev) {
|
|
|
|
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;
|
2012-01-30 11:52:55 +00:00
|
|
|
this.$element.removeClass('login_invalid');
|
2011-12-22 11:46:35 +00:00
|
|
|
this.session.on_session_invalid.add({
|
|
|
|
callback: function () {
|
|
|
|
self.$element.addClass("login_invalid");
|
|
|
|
},
|
|
|
|
unique: true
|
|
|
|
});
|
2011-12-16 14:17:07 +00:00
|
|
|
this.session.session_authenticate(db, login, password).then(function() {
|
2011-12-22 11:46:35 +00:00
|
|
|
self.$element.removeClass("login_invalid");
|
|
|
|
if (self.has_local_storage) {
|
|
|
|
if(self.remember_credentials) {
|
|
|
|
localStorage.setItem('last_db_login_success', db);
|
|
|
|
localStorage.setItem('last_login_login_success', login);
|
|
|
|
if (jQuery.deparam(jQuery.param.querystring()).debug != undefined) {
|
|
|
|
localStorage.setItem('last_password_login_success', password);
|
2011-06-08 09:44:26 +00:00
|
|
|
}
|
2011-12-22 11:46:35 +00:00
|
|
|
} else {
|
|
|
|
localStorage.setItem('last_db_login_success', '');
|
|
|
|
localStorage.setItem('last_login_login_success', '');
|
|
|
|
localStorage.setItem('last_password_login_success', '');
|
2011-06-08 09:44:26 +00:00
|
|
|
}
|
2011-03-16 23:56:34 +00:00
|
|
|
}
|
|
|
|
});
|
2012-01-17 13:28:43 +00:00
|
|
|
}
|
2011-03-16 23:56:34 +00:00
|
|
|
});
|
|
|
|
|
2012-01-24 14:58:10 +00:00
|
|
|
openerp.web.Header = openerp.web.OldWidget.extend(/** @lends openerp.web.Header# */{
|
2011-08-30 08:53:28 +00:00
|
|
|
template: "Header",
|
2011-09-12 11:34:37 +00:00
|
|
|
/**
|
|
|
|
* @constructs openerp.web.Header
|
2012-01-24 14:58:10 +00:00
|
|
|
* @extends openerp.web.OldWidget
|
2011-09-13 05:44:06 +00:00
|
|
|
*
|
2011-09-12 11:34:37 +00:00
|
|
|
* @param parent
|
|
|
|
*/
|
2011-08-30 08:53:28 +00:00
|
|
|
init: function(parent) {
|
|
|
|
this._super(parent);
|
|
|
|
this.qs = "?" + jQuery.param.querystring();
|
|
|
|
this.$content = $();
|
2011-09-13 08:27:55 +00:00
|
|
|
this.update_promise = $.Deferred().resolve();
|
2011-03-20 20:01:17 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
2011-08-30 08:53:28 +00:00
|
|
|
this._super();
|
2011-03-20 20:01:17 +00:00
|
|
|
},
|
2011-08-16 10:26:20 +00:00
|
|
|
do_update: function () {
|
2011-09-05 09:23:15 +00:00
|
|
|
var self = this;
|
2011-09-13 08:27:55 +00:00
|
|
|
var fct = function() {
|
|
|
|
self.$content.remove();
|
|
|
|
if (!self.session.uid)
|
|
|
|
return;
|
2011-12-14 17:03:56 +00:00
|
|
|
var func = new openerp.web.Model("res.users").get_func("read");
|
2011-09-13 08:27:55 +00:00
|
|
|
return func(self.session.uid, ["name", "company_id"]).pipe(function(res) {
|
|
|
|
self.$content = $(QWeb.render("Header-content", {widget: self, user: res}));
|
|
|
|
self.$content.appendTo(self.$element);
|
|
|
|
self.$element.find(".logout").click(self.on_logout);
|
|
|
|
self.$element.find("a.preferences").click(self.on_preferences);
|
|
|
|
self.$element.find(".about").click(self.on_about);
|
|
|
|
return self.shortcut_load();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
this.update_promise = this.update_promise.pipe(fct, fct);
|
2011-08-08 11:16:16 +00:00
|
|
|
},
|
2011-09-05 15:14:20 +00:00
|
|
|
on_about: function() {
|
|
|
|
var self = this;
|
|
|
|
self.rpc("/web/webclient/version_info", {}).then(function(res) {
|
|
|
|
var $help = $(QWeb.render("About-Page", {version_info: res}));
|
2012-01-13 16:28:49 +00:00
|
|
|
$help.find('a.oe_activate_debug_mode').click(function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
window.location = $.param.querystring(
|
|
|
|
window.location.href, 'debug');
|
|
|
|
});
|
2011-09-05 15:56:42 +00:00
|
|
|
$help.dialog({autoOpen: true,
|
2011-12-15 10:40:31 +00:00
|
|
|
modal: true, width: 960, title: _t("About")});
|
2011-09-05 15:14:20 +00:00
|
|
|
});
|
|
|
|
},
|
2011-08-08 11:16:16 +00:00
|
|
|
shortcut_load :function(){
|
2011-08-16 14:04:25 +00:00
|
|
|
var self = this,
|
|
|
|
sc = self.session.shortcuts,
|
2011-09-05 11:03:09 +00:00
|
|
|
shortcuts_ds = new openerp.web.DataSet(this, 'ir.ui.view_sc');
|
2011-08-16 14:04:25 +00:00
|
|
|
// TODO: better way to communicate between sections.
|
|
|
|
// sc.bindings, because jquery does not bind/trigger on arrays...
|
|
|
|
if (!sc.binding) {
|
|
|
|
sc.binding = {};
|
|
|
|
$(sc.binding).bind({
|
|
|
|
'add': function (e, attrs) {
|
2011-08-19 10:33:22 +00:00
|
|
|
shortcuts_ds.create(attrs, function (out) {
|
2011-08-23 09:01:21 +00:00
|
|
|
$('<li>', {
|
|
|
|
'data-shortcut-id':out.result,
|
2011-08-16 14:04:25 +00:00
|
|
|
'data-id': attrs.res_id
|
|
|
|
}).text(attrs.name)
|
2011-08-26 08:47:58 +00:00
|
|
|
.appendTo(self.$element.find('.oe-shortcuts ul'));
|
2011-08-19 10:33:22 +00:00
|
|
|
attrs.id = out.result;
|
2011-08-23 09:01:21 +00:00
|
|
|
sc.push(attrs);
|
2011-08-16 14:04:25 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
'remove-current': function () {
|
|
|
|
var menu_id = self.session.active_id;
|
|
|
|
var $shortcut = self.$element
|
2011-08-23 09:01:21 +00:00
|
|
|
.find('.oe-shortcuts li[data-id=' + menu_id + ']');
|
2011-08-16 14:04:25 +00:00
|
|
|
var shortcut_id = $shortcut.data('shortcut-id');
|
|
|
|
$shortcut.remove();
|
|
|
|
shortcuts_ds.unlink([shortcut_id]);
|
2011-08-23 09:01:21 +00:00
|
|
|
var sc_new = _.reject(sc, function(shortcut){ return shortcut_id === shortcut.id});
|
2011-08-19 10:33:22 +00:00
|
|
|
sc.splice(0, sc.length);
|
2011-08-26 08:47:58 +00:00
|
|
|
sc.push.apply(sc, sc_new);
|
2011-08-23 09:01:21 +00:00
|
|
|
}
|
2011-08-16 14:04:25 +00:00
|
|
|
});
|
|
|
|
}
|
2011-09-05 11:03:09 +00:00
|
|
|
return this.rpc('/web/session/sc_list', {}, function(shortcuts) {
|
2011-08-16 14:04:25 +00:00
|
|
|
sc.splice(0, sc.length);
|
|
|
|
sc.push.apply(sc, shortcuts);
|
|
|
|
|
2011-08-16 10:26:20 +00:00
|
|
|
self.$element.find('.oe-shortcuts')
|
|
|
|
.html(QWeb.render('Shortcuts', {'shortcuts': shortcuts}))
|
2011-08-16 11:17:46 +00:00
|
|
|
.undelegate('li', 'click')
|
2011-08-19 10:33:22 +00:00
|
|
|
|
2011-08-16 11:17:46 +00:00
|
|
|
.delegate('li', 'click', function(e) {
|
|
|
|
e.stopPropagation();
|
2011-08-16 12:37:24 +00:00
|
|
|
var id = $(this).data('id');
|
|
|
|
self.session.active_id = id;
|
2011-09-05 11:03:09 +00:00
|
|
|
self.rpc('/web/menu/action', {'menu_id':id}, function(ir_menu_data) {
|
2011-08-16 10:26:20 +00:00
|
|
|
if (ir_menu_data.action.length){
|
|
|
|
self.on_action(ir_menu_data.action[0][2]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2011-08-08 11:16:16 +00:00
|
|
|
});
|
|
|
|
},
|
2011-09-06 12:54:40 +00:00
|
|
|
|
2011-08-12 07:12:48 +00:00
|
|
|
on_action: function(action) {
|
2011-06-06 09:04:54 +00:00
|
|
|
},
|
2011-08-19 13:10:07 +00:00
|
|
|
on_preferences: function(){
|
|
|
|
var self = this;
|
2011-09-05 11:03:09 +00:00
|
|
|
var action_manager = new openerp.web.ActionManager(this);
|
|
|
|
var dataset = new openerp.web.DataSet (this,'res.users',this.context);
|
2011-09-01 13:33:55 +00:00
|
|
|
dataset.call ('action_get','',function (result){
|
2011-09-05 11:03:09 +00:00
|
|
|
self.rpc('/web/action/load', {action_id:result}, function(result){
|
2011-09-01 13:33:55 +00:00
|
|
|
action_manager.do_action(_.extend(result['result'], {
|
|
|
|
res_id: self.session.uid,
|
|
|
|
res_model: 'res.users',
|
|
|
|
flags: {
|
|
|
|
action_buttons: false,
|
|
|
|
search_view: false,
|
|
|
|
sidebar: false,
|
|
|
|
views_switcher: false,
|
|
|
|
pager: false
|
|
|
|
}
|
|
|
|
}));
|
2011-08-19 13:10:07 +00:00
|
|
|
});
|
2011-08-23 09:17:21 +00:00
|
|
|
});
|
2011-09-05 11:03:09 +00:00
|
|
|
this.dialog = new openerp.web.Dialog(this,{
|
2011-12-15 10:40:31 +00:00
|
|
|
title: _t("Preferences"),
|
2011-12-21 13:43:06 +00:00
|
|
|
width: '700px',
|
2011-12-15 10:40:31 +00:00
|
|
|
buttons: [
|
|
|
|
{text: _t("Cancel"), click: function(){ $(this).dialog('destroy'); }},
|
2012-01-11 14:43:45 +00:00
|
|
|
{text: _t("Change password"), click: function(){ self.change_password(); }},
|
2011-12-15 10:40:31 +00:00
|
|
|
{text: _t("Save"), click: function(){
|
|
|
|
var inner_viewmanager = action_manager.inner_viewmanager;
|
|
|
|
inner_viewmanager.views[inner_viewmanager.active_view].controller.do_save()
|
|
|
|
.then(function() {
|
|
|
|
self.dialog.stop();
|
2012-01-11 14:44:43 +00:00
|
|
|
// needs to refresh interface in case language changed
|
2011-12-15 10:40:31 +00:00
|
|
|
window.location.reload();
|
|
|
|
});
|
|
|
|
}
|
2011-08-30 11:16:49 +00:00
|
|
|
}
|
2011-12-15 10:40:31 +00:00
|
|
|
]
|
2012-01-11 11:06:48 +00:00
|
|
|
}).open();
|
2011-08-19 13:10:07 +00:00
|
|
|
action_manager.appendTo(this.dialog);
|
|
|
|
action_manager.render(this.dialog);
|
|
|
|
},
|
2011-09-06 12:54:40 +00:00
|
|
|
|
2011-08-19 13:10:07 +00:00
|
|
|
change_password :function() {
|
|
|
|
var self = this;
|
2011-12-21 13:43:06 +00:00
|
|
|
this.dialog = new openerp.web.Dialog(this, {
|
2011-12-15 10:40:31 +00:00
|
|
|
title: _t("Change Password"),
|
2011-12-21 13:43:06 +00:00
|
|
|
width : 'auto'
|
2012-01-11 11:06:48 +00:00
|
|
|
}).open();
|
2011-08-19 13:10:07 +00:00
|
|
|
this.dialog.$element.html(QWeb.render("Change_Pwd", self));
|
|
|
|
this.dialog.$element.find("form[name=change_password_form]").validate({
|
|
|
|
submitHandler: function (form) {
|
2011-09-05 11:03:09 +00:00
|
|
|
self.rpc("/web/session/change_password",{
|
2011-08-23 12:58:02 +00:00
|
|
|
'fields': $(form).serializeArray()
|
2011-09-21 13:22:32 +00:00
|
|
|
}, function(result) {
|
|
|
|
if (result.error) {
|
|
|
|
self.display_error(result);
|
2011-08-19 13:10:07 +00:00
|
|
|
return;
|
2011-09-21 13:22:32 +00:00
|
|
|
} else {
|
2012-01-06 16:32:20 +00:00
|
|
|
openerp.webclient.on_logout();
|
2011-09-21 13:22:32 +00:00
|
|
|
}
|
2011-08-19 13:10:07 +00:00
|
|
|
});
|
2011-09-01 13:38:12 +00:00
|
|
|
}
|
2011-08-19 13:10:07 +00:00
|
|
|
});
|
2011-09-02 14:25:06 +00:00
|
|
|
},
|
2011-08-19 13:10:07 +00:00
|
|
|
display_error: function (error) {
|
|
|
|
return $('<div>').dialog({
|
|
|
|
modal: true,
|
|
|
|
title: error.title,
|
2011-12-15 10:40:31 +00:00
|
|
|
buttons: [
|
|
|
|
{text: _("Ok"), click: function() { $(this).dialog("close"); }}
|
|
|
|
]
|
2011-08-19 13:10:07 +00:00
|
|
|
}).html(error.error);
|
|
|
|
},
|
2011-08-12 07:12:48 +00:00
|
|
|
on_logout: function() {
|
|
|
|
}
|
2011-03-20 20:01:17 +00:00
|
|
|
});
|
|
|
|
|
2012-01-24 14:58:10 +00:00
|
|
|
openerp.web.Menu = openerp.web.OldWidget.extend(/** @lends openerp.web.Menu# */{
|
2011-09-12 11:34:37 +00:00
|
|
|
/**
|
|
|
|
* @constructs openerp.web.Menu
|
2012-01-24 14:58:10 +00:00
|
|
|
* @extends openerp.web.OldWidget
|
2011-09-13 05:44:06 +00:00
|
|
|
*
|
2011-09-12 11:34:37 +00:00
|
|
|
* @param parent
|
|
|
|
* @param element_id
|
|
|
|
* @param secondary_menu_id
|
|
|
|
*/
|
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;
|
2011-12-07 11:22:14 +00:00
|
|
|
this.$secondary_menu = $("#" + secondary_menu_id);
|
2011-03-16 23:56:34 +00:00
|
|
|
this.menu = false;
|
2011-09-19 14:46:31 +00:00
|
|
|
this.folded = false;
|
2011-09-19 19:59:06 +00:00
|
|
|
if (window.localStorage) {
|
|
|
|
this.folded = localStorage.getItem('oe_menu_folded') === 'true';
|
|
|
|
}
|
2011-09-20 11:18:30 +00:00
|
|
|
this.float_timeout = 700;
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
2011-09-19 15:59:43 +00:00
|
|
|
this.$secondary_menu.addClass(this.folded ? 'oe_folded' : 'oe_unfolded');
|
2011-09-20 08:10:08 +00:00
|
|
|
},
|
2011-10-13 08:14:45 +00:00
|
|
|
do_reload: function() {
|
2011-12-22 15:34:49 +00:00
|
|
|
var self = this;
|
|
|
|
return this.rpc("/web/menu/load", {}, this.on_loaded).then(function () {
|
|
|
|
if (self.current_menu) {
|
|
|
|
self.open_menu(self.current_menu);
|
|
|
|
}
|
|
|
|
});
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
|
|
|
on_loaded: function(data) {
|
|
|
|
this.data = data;
|
2011-09-19 14:46:31 +00:00
|
|
|
this.$element.html(QWeb.render("Menu", { widget : this }));
|
|
|
|
this.$secondary_menu.html(QWeb.render("Menu.secondary", { widget : this }));
|
2011-03-22 11:49:19 +00:00
|
|
|
this.$element.add(this.$secondary_menu).find("a").click(this.on_menu_click);
|
2011-09-19 14:46:31 +00:00
|
|
|
this.$secondary_menu.find('.oe_toggle_secondary_menu').click(this.on_toggle_fold);
|
|
|
|
},
|
|
|
|
on_toggle_fold: function() {
|
2011-09-19 15:59:43 +00:00
|
|
|
this.$secondary_menu.toggleClass('oe_folded').toggleClass('oe_unfolded');
|
2011-09-19 14:46:31 +00:00
|
|
|
if (this.folded) {
|
|
|
|
this.$secondary_menu.find('.oe_secondary_menu.active').show();
|
|
|
|
} else {
|
|
|
|
this.$secondary_menu.find('.oe_secondary_menu').hide();
|
|
|
|
}
|
|
|
|
this.folded = !this.folded;
|
2011-09-19 19:59:06 +00:00
|
|
|
if (window.localStorage) {
|
|
|
|
localStorage.setItem('oe_menu_folded', this.folded.toString());
|
|
|
|
}
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
2011-12-22 15:34:49 +00:00
|
|
|
/**
|
|
|
|
* Opens a given menu by id, as if a user had browsed to that menu by hand
|
|
|
|
* except does not trigger any event on the way
|
|
|
|
*
|
|
|
|
* @param {Number} menu_id database id of the terminal menu to select
|
|
|
|
*/
|
|
|
|
open_menu: function (menu_id) {
|
|
|
|
this.$element.add(this.$secondary_menu).find('.active')
|
|
|
|
.removeClass('active');
|
|
|
|
this.$secondary_menu.find('> .oe_secondary_menu').hide();
|
|
|
|
|
|
|
|
var $primary_menu;
|
|
|
|
var $secondary_submenu = this.$secondary_menu.find(
|
|
|
|
'a[data-menu=' + menu_id +']');
|
|
|
|
if ($secondary_submenu.length) {
|
|
|
|
for(;;) {
|
|
|
|
if ($secondary_submenu.hasClass('leaf')) {
|
|
|
|
$secondary_submenu.addClass('active');
|
|
|
|
} else if ($secondary_submenu.hasClass('submenu')) {
|
|
|
|
$secondary_submenu.addClass('opened')
|
|
|
|
}
|
|
|
|
var $parent = $secondary_submenu.parent().show();
|
|
|
|
if ($parent.hasClass('oe_secondary_menu')) {
|
|
|
|
var primary_id = $parent.data('menu-parent');
|
|
|
|
$primary_menu = this.$element.find(
|
|
|
|
'a[data-menu=' + primary_id + ']');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$secondary_submenu = $parent.prev();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$primary_menu = this.$element.find('a[data-menu=' + menu_id + ']');
|
|
|
|
}
|
|
|
|
if (!$primary_menu.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$primary_menu.addClass('active');
|
|
|
|
this.$secondary_menu.find(
|
|
|
|
'div[data-menu-parent=' + $primary_menu.data('menu') + ']').show();
|
|
|
|
},
|
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;
|
2011-09-20 10:23:50 +00:00
|
|
|
var $clicked_menu, manual = false;
|
2011-03-25 13:21:15 +00:00
|
|
|
|
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-09-20 13:41:42 +00:00
|
|
|
manual = true;
|
2011-09-19 19:23:07 +00:00
|
|
|
$clicked_menu = this.$element.find('a[data-menu=' + id + ']');
|
|
|
|
if (!$clicked_menu.length) {
|
|
|
|
$clicked_menu = this.$secondary_menu.find('a[data-menu=' + id + ']');
|
2011-03-22 11:49:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
2011-09-19 19:23:07 +00:00
|
|
|
$clicked_menu = $(ev.currentTarget);
|
|
|
|
id = $clicked_menu.data('menu');
|
2011-03-22 11:49:19 +00:00
|
|
|
}
|
2011-09-20 10:23:50 +00:00
|
|
|
|
2011-09-20 13:41:42 +00:00
|
|
|
if (this.do_menu_click($clicked_menu, manual) && id) {
|
2011-12-22 15:34:49 +00:00
|
|
|
this.current_menu = id;
|
2011-09-20 10:23:50 +00:00
|
|
|
this.session.active_id = id;
|
|
|
|
this.rpc('/web/menu/action', {'menu_id': id}, this.on_menu_action_loaded);
|
|
|
|
}
|
2011-10-12 09:30:31 +00:00
|
|
|
if (ev) {
|
|
|
|
ev.stopPropagation();
|
|
|
|
}
|
2011-09-20 13:41:42 +00:00
|
|
|
return false;
|
2011-09-20 10:23:50 +00:00
|
|
|
},
|
|
|
|
do_menu_click: function($clicked_menu, manual) {
|
|
|
|
var $sub_menu, $main_menu,
|
|
|
|
active = $clicked_menu.is('.active'),
|
|
|
|
sub_menu_visible = false;
|
2011-09-19 19:23:07 +00:00
|
|
|
|
|
|
|
if (this.$secondary_menu.has($clicked_menu).length) {
|
|
|
|
$sub_menu = $clicked_menu.parents('.oe_secondary_menu');
|
|
|
|
$main_menu = this.$element.find('a[data-menu=' + $sub_menu.data('menu-parent') + ']');
|
2011-03-22 11:49:19 +00:00
|
|
|
} else {
|
2011-09-19 19:23:07 +00:00
|
|
|
$sub_menu = this.$secondary_menu.find('.oe_secondary_menu[data-menu-parent=' + $clicked_menu.attr('data-menu') + ']');
|
|
|
|
$main_menu = $clicked_menu;
|
2011-03-22 11:49:19 +00:00
|
|
|
}
|
|
|
|
|
2011-09-20 10:23:50 +00:00
|
|
|
sub_menu_visible = $sub_menu.is(':visible');
|
|
|
|
this.$secondary_menu.find('.oe_secondary_menu').hide();
|
2011-03-22 11:49:19 +00:00
|
|
|
|
2011-12-07 11:22:14 +00:00
|
|
|
$('.active', this.$element.add(this.$secondary_menu)).removeClass('active');
|
2011-09-20 10:23:50 +00:00
|
|
|
$main_menu.add($clicked_menu).add($sub_menu).addClass('active');
|
2011-03-22 11:49:19 +00:00
|
|
|
|
2011-09-19 15:59:43 +00:00
|
|
|
if (!(this.folded && manual)) {
|
2011-09-20 10:23:50 +00:00
|
|
|
this.do_show_secondary($sub_menu, $main_menu);
|
2011-12-14 10:43:01 +00:00
|
|
|
} else {
|
|
|
|
this.do_show_secondary();
|
2011-09-19 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2011-09-20 10:23:50 +00:00
|
|
|
if ($main_menu != $clicked_menu) {
|
2011-09-19 19:23:07 +00:00
|
|
|
if ($clicked_menu.is('.submenu')) {
|
2011-09-20 10:23:50 +00:00
|
|
|
$sub_menu.find('.submenu.opened').each(function() {
|
2011-09-20 13:41:42 +00:00
|
|
|
if (!$(this).next().has($clicked_menu).length && !$(this).is($clicked_menu)) {
|
2011-09-20 10:23:50 +00:00
|
|
|
$(this).removeClass('opened').next().hide();
|
|
|
|
}
|
|
|
|
});
|
2011-09-19 19:23:07 +00:00
|
|
|
$clicked_menu.toggleClass('opened').next().toggle();
|
2011-09-20 10:23:50 +00:00
|
|
|
} else if ($clicked_menu.is('.leaf')) {
|
|
|
|
$sub_menu.toggle(!this.folded);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (this.folded) {
|
|
|
|
if (active && sub_menu_visible) {
|
|
|
|
$sub_menu.hide();
|
|
|
|
return true;
|
2011-09-15 20:22:09 +00:00
|
|
|
}
|
2011-10-12 09:30:31 +00:00
|
|
|
return manual;
|
2011-09-14 13:03:08 +00:00
|
|
|
} else {
|
2011-09-20 10:23:50 +00:00
|
|
|
return true;
|
2011-09-14 13:03:08 +00:00
|
|
|
}
|
2011-09-20 10:23:50 +00:00
|
|
|
return false;
|
|
|
|
},
|
2011-12-14 10:43:01 +00:00
|
|
|
do_hide_secondary: function() {
|
|
|
|
this.$secondary_menu.hide();
|
|
|
|
},
|
2011-09-20 10:23:50 +00:00
|
|
|
do_show_secondary: function($sub_menu, $main_menu) {
|
2011-09-20 11:18:30 +00:00
|
|
|
var self = this;
|
2011-12-14 10:43:01 +00:00
|
|
|
this.$secondary_menu.show();
|
|
|
|
if (!arguments.length) {
|
|
|
|
return;
|
|
|
|
}
|
2011-09-20 10:23:50 +00:00
|
|
|
if (this.folded) {
|
|
|
|
var css = $main_menu.position(),
|
|
|
|
fold_width = this.$secondary_menu.width() + 2,
|
|
|
|
window_width = $(window).width();
|
|
|
|
css.top += 33;
|
|
|
|
css.left -= Math.round(($sub_menu.width() - $main_menu.width()) / 2);
|
|
|
|
css.left = css.left < fold_width ? fold_width : css.left;
|
|
|
|
if ((css.left + $sub_menu.width()) > window_width) {
|
|
|
|
delete(css.left);
|
|
|
|
css.right = 1;
|
|
|
|
}
|
|
|
|
$sub_menu.css(css);
|
2011-09-20 11:18:30 +00:00
|
|
|
$sub_menu.mouseenter(function() {
|
|
|
|
clearTimeout($sub_menu.data('timeoutId'));
|
2011-12-15 16:37:24 +00:00
|
|
|
$sub_menu.data('timeoutId', null);
|
|
|
|
return false;
|
2011-09-20 11:18:30 +00:00
|
|
|
}).mouseleave(function(evt) {
|
2011-09-20 13:41:42 +00:00
|
|
|
var timeoutId = setTimeout(function() {
|
2011-12-15 16:37:24 +00:00
|
|
|
if (self.folded && $sub_menu.data('timeoutId')) {
|
|
|
|
$sub_menu.hide().unbind('mouseenter').unbind('mouseleave');
|
2011-09-20 13:41:42 +00:00
|
|
|
}
|
|
|
|
}, self.float_timeout);
|
2011-09-20 11:18:30 +00:00
|
|
|
$sub_menu.data('timeoutId', timeoutId);
|
2011-12-15 16:37:24 +00:00
|
|
|
return false;
|
2011-09-20 11:18:30 +00:00
|
|
|
});
|
2011-09-20 10:23:50 +00:00
|
|
|
}
|
|
|
|
$sub_menu.show();
|
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];
|
2011-12-20 16:49:03 +00:00
|
|
|
action.from_menu = true;
|
2011-03-16 23:56:34 +00:00
|
|
|
self.on_action(action);
|
2011-12-07 10:50:08 +00:00
|
|
|
} else {
|
|
|
|
self.on_action({type: 'null_action'});
|
2011-03-16 23:56:34 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
on_action: function(action) {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-01-24 14:58:10 +00:00
|
|
|
openerp.web.WebClient = openerp.web.OldWidget.extend(/** @lends openerp.web.WebClient */{
|
2011-09-12 11:34:37 +00:00
|
|
|
/**
|
|
|
|
* @constructs openerp.web.WebClient
|
2012-01-24 14:58:10 +00:00
|
|
|
* @extends openerp.web.OldWidget
|
2011-09-13 05:44:06 +00:00
|
|
|
*
|
2011-09-12 11:34:37 +00:00
|
|
|
* @param element_id
|
|
|
|
*/
|
2012-01-04 09:12:22 +00:00
|
|
|
init: function(parent) {
|
2011-12-15 13:38:00 +00:00
|
|
|
var self = this;
|
2012-01-04 09:12:22 +00:00
|
|
|
this._super(parent);
|
2011-08-11 02:42:46 +00:00
|
|
|
openerp.webclient = this;
|
2011-03-16 23:56:34 +00:00
|
|
|
|
2011-12-13 10:32:32 +00:00
|
|
|
this._current_state = null;
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
2011-11-15 17:04:08 +00:00
|
|
|
var self = this;
|
2012-01-22 23:32:02 +00:00
|
|
|
this.$element = $(document.body);
|
2012-01-04 18:21:12 +00:00
|
|
|
if (jQuery.param != undefined && jQuery.deparam(jQuery.param.querystring()).kitten != undefined) {
|
|
|
|
this.$element.addClass("kitten-mode-activated");
|
|
|
|
this.$element.delegate('img.oe-record-edit-link-img', 'hover', function(e) {
|
|
|
|
self.$element.toggleClass('clark-gable');
|
|
|
|
});
|
|
|
|
}
|
2011-12-16 00:44:02 +00:00
|
|
|
this.session.bind().then(function() {
|
2012-01-04 12:44:56 +00:00
|
|
|
if (!self.session.session_is_valid()) {
|
2012-01-04 18:11:50 +00:00
|
|
|
self.show_login();
|
2011-12-20 17:43:32 +00:00
|
|
|
}
|
2011-12-16 00:44:02 +00:00
|
|
|
});
|
2012-01-04 18:21:12 +00:00
|
|
|
this.session.on_session_valid.add(function() {
|
2012-01-04 18:11:50 +00:00
|
|
|
self.show_application();
|
2012-01-04 11:01:37 +00:00
|
|
|
|
2011-12-16 00:44:02 +00:00
|
|
|
self.header.do_update();
|
|
|
|
self.menu.do_reload();
|
|
|
|
if(self.action_manager)
|
|
|
|
self.action_manager.stop();
|
2011-12-16 14:43:12 +00:00
|
|
|
self.action_manager = new openerp.web.ActionManager(self);
|
2011-12-16 00:44:02 +00:00
|
|
|
self.action_manager.appendTo($("#oe_app"));
|
|
|
|
self.bind_hashchange();
|
2011-12-27 15:59:15 +00:00
|
|
|
if (!self.session.openerp_entreprise) {
|
2011-12-21 17:11:37 +00:00
|
|
|
self.$element.find('.oe_footer_powered').append('<span> - <a href="http://www.openerp.com/support-or-publisher-warranty-contract" target="_blank">Unsupported/Community Version</a></span>');
|
2012-01-17 13:58:17 +00:00
|
|
|
document.title = _t("OpenERP - Unsupported/Community Version");
|
2011-12-21 17:11:37 +00:00
|
|
|
}
|
2011-11-15 17:04:08 +00:00
|
|
|
});
|
2011-03-16 23:56:34 +00:00
|
|
|
},
|
2012-01-04 18:11:50 +00:00
|
|
|
show_login: function() {
|
|
|
|
var self = this;
|
|
|
|
this.destroy_content();
|
|
|
|
this.show_common();
|
|
|
|
self.login = new openerp.web.Login(self);
|
|
|
|
self.login.appendTo(self.$element);
|
|
|
|
},
|
|
|
|
show_application: function() {
|
|
|
|
var self = this;
|
|
|
|
this.destroy_content();
|
|
|
|
this.show_common();
|
|
|
|
self.$table = $(QWeb.render("Interface", {}));
|
|
|
|
self.$element.append(self.$table);
|
|
|
|
self.header = new openerp.web.Header(self);
|
2012-01-12 08:49:10 +00:00
|
|
|
self.header.on_logout.add(this.proxy('on_logout'));
|
|
|
|
self.header.on_action.add(this.proxy('on_menu_action'));
|
2012-01-04 18:11:50 +00:00
|
|
|
self.header.appendTo($("#oe_header"));
|
|
|
|
self.menu = new openerp.web.Menu(self, "oe_menu", "oe_secondary_menu");
|
2012-01-12 08:49:10 +00:00
|
|
|
self.menu.on_action.add(this.proxy('on_menu_action'));
|
2012-01-04 18:11:50 +00:00
|
|
|
self.menu.start();
|
|
|
|
},
|
|
|
|
show_common: function() {
|
2012-01-27 16:43:32 +00:00
|
|
|
if (!this.crashmanager) {
|
|
|
|
this.crashmanager = new openerp.web.CrashManager();
|
|
|
|
}
|
2012-01-27 16:34:46 +00:00
|
|
|
this.notification = new openerp.web.Notification(this);
|
|
|
|
this.notification.appendTo(this.$element);
|
|
|
|
this.loading = new openerp.web.Loading(this);
|
|
|
|
this.loading.appendTo(this.$element);
|
2012-01-04 18:11:50 +00:00
|
|
|
},
|
|
|
|
destroy_content: function() {
|
|
|
|
_.each(_.clone(this.widget_children), function(el) {
|
|
|
|
el.stop();
|
|
|
|
});
|
2012-01-04 18:21:12 +00:00
|
|
|
this.$element.children().remove();
|
2012-01-04 18:11:50 +00:00
|
|
|
},
|
2011-10-13 23:20:54 +00:00
|
|
|
do_reload: function() {
|
2012-01-13 15:08:29 +00:00
|
|
|
var self = this;
|
|
|
|
return this.session.session_reload().pipe(function () {
|
|
|
|
openerp.connection.load_modules(true).pipe(
|
|
|
|
self.menu.proxy('do_reload')); });
|
|
|
|
|
2011-10-13 23:20:54 +00:00
|
|
|
},
|
2011-10-13 15:30:23 +00:00
|
|
|
do_notify: function() {
|
|
|
|
var n = this.notification;
|
|
|
|
n.notify.apply(n, arguments);
|
|
|
|
},
|
|
|
|
do_warn: function() {
|
|
|
|
var n = this.notification;
|
|
|
|
n.warn.apply(n, arguments);
|
|
|
|
},
|
2011-12-16 01:25:42 +00:00
|
|
|
on_logout: function() {
|
|
|
|
this.session.session_logout();
|
2011-12-13 15:35:50 +00:00
|
|
|
$(window).unbind('hashchange', this.on_hashchange);
|
2011-12-14 16:09:58 +00:00
|
|
|
this.do_push_state({});
|
2012-01-05 09:43:51 +00:00
|
|
|
//would be cool to be able to do this, but I think it will make addons do strange things
|
|
|
|
//this.show_login();
|
|
|
|
window.location.reload();
|
2011-08-10 00:38:57 +00:00
|
|
|
},
|
2011-12-12 16:44:55 +00:00
|
|
|
bind_hashchange: function() {
|
|
|
|
$(window).bind('hashchange', this.on_hashchange);
|
2011-12-09 16:31:14 +00:00
|
|
|
|
2011-12-12 14:20:12 +00:00
|
|
|
var state = $.bbq.getState(true);
|
|
|
|
if (! _.isEmpty(state)) {
|
2011-12-12 16:44:55 +00:00
|
|
|
$(window).trigger('hashchange');
|
2011-12-12 14:20:12 +00:00
|
|
|
} else {
|
|
|
|
this.action_manager.do_action({type: 'ir.actions.client', tag: 'default_home'});
|
2011-12-09 16:31:14 +00:00
|
|
|
}
|
2011-07-19 12:32:46 +00:00
|
|
|
},
|
2011-12-12 16:44:55 +00:00
|
|
|
on_hashchange: function(event) {
|
|
|
|
var state = event.getState(true);
|
2011-12-13 10:32:32 +00:00
|
|
|
if (!_.isEqual(this._current_state, state)) {
|
|
|
|
this.action_manager.do_load_state(state);
|
2011-09-14 13:03:08 +00:00
|
|
|
}
|
2011-12-13 10:32:32 +00:00
|
|
|
this._current_state = state;
|
2011-09-14 13:03:08 +00:00
|
|
|
},
|
2011-12-14 16:09:58 +00:00
|
|
|
do_push_state: function(state) {
|
2011-12-09 16:31:14 +00:00
|
|
|
var url = '#' + $.param(state);
|
2011-12-13 10:32:32 +00:00
|
|
|
this._current_state = _.clone(state);
|
2011-12-12 16:44:55 +00:00
|
|
|
$.bbq.pushState(url);
|
2011-09-14 13:03:08 +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
|
|
|
},
|
2011-12-12 10:39:05 +00:00
|
|
|
do_action: function(action) {
|
2011-12-13 15:13:49 +00:00
|
|
|
var self = this;
|
2011-12-13 15:35:50 +00:00
|
|
|
// TODO replace by client action menuclick
|
2011-12-21 11:49:04 +00:00
|
|
|
if(action.menu_id) {
|
2011-12-13 13:55:14 +00:00
|
|
|
this.do_reload().then(function () {
|
2011-12-13 15:13:49 +00:00
|
|
|
self.menu.on_menu_click(null, action.menu_id);
|
2011-12-13 13:55:14 +00:00
|
|
|
});
|
2011-12-12 10:39:05 +00:00
|
|
|
}
|
2012-01-11 14:31:44 +00:00
|
|
|
}
|
2011-03-16 23:56:34 +00:00
|
|
|
});
|
|
|
|
|
2012-01-24 14:58:10 +00:00
|
|
|
openerp.web.EmbeddedClient = openerp.web.OldWidget.extend({
|
2011-12-14 12:56:58 +00:00
|
|
|
template: 'EmptyComponent',
|
|
|
|
init: function(action_id, options) {
|
|
|
|
this._super();
|
|
|
|
// 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);
|
|
|
|
},
|
|
|
|
|
|
|
|
start: function() {
|
|
|
|
var self = this;
|
|
|
|
this.am.appendTo(this.$element.addClass('openerp'));
|
|
|
|
return this.rpc("/web/action/load", { action_id: this.action_id }, function(result) {
|
|
|
|
var action = result.result;
|
|
|
|
action.flags = _.extend({
|
|
|
|
//views_switcher : false,
|
|
|
|
search_view : false,
|
|
|
|
action_buttons : false,
|
|
|
|
sidebar : false
|
|
|
|
//pager : false
|
|
|
|
}, self.options, action.flags || {});
|
|
|
|
|
|
|
|
self.am.do_action(action);
|
|
|
|
});
|
2012-01-17 13:28:43 +00:00
|
|
|
}
|
2011-12-14 12:56:58 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2011-12-16 15:37:36 +00:00
|
|
|
openerp.web.embed = function (origin, dbname, login, key, action, options) {
|
2011-12-16 16:51:46 +00:00
|
|
|
$('head').append($('<link>', {
|
|
|
|
'rel': 'stylesheet',
|
|
|
|
'type': 'text/css',
|
|
|
|
'href': origin +'/web/webclient/css'
|
|
|
|
}));
|
2011-12-16 15:37:36 +00:00
|
|
|
var currentScript = document.currentScript;
|
|
|
|
if (!currentScript) {
|
|
|
|
var sc = document.getElementsByTagName('script');
|
|
|
|
currentScript = sc[sc.length-1];
|
|
|
|
}
|
|
|
|
openerp.connection.bind(origin).then(function () {
|
2011-12-21 10:40:31 +00:00
|
|
|
openerp.connection.session_authenticate(dbname, login, key, true).then(function () {
|
2011-12-16 16:47:39 +00:00
|
|
|
var client = new openerp.web.EmbeddedClient(action, options);
|
2011-12-16 15:37:36 +00:00
|
|
|
client.insertAfter(currentScript);
|
|
|
|
});
|
|
|
|
});
|
2011-12-16 16:47:39 +00:00
|
|
|
|
2011-12-16 15:37:36 +00:00
|
|
|
}
|
2011-12-14 12:56:58 +00:00
|
|
|
|
2011-03-16 23:56:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|