2011-08-18 13:24:18 +00:00
|
|
|
/*---------------------------------------------------------
|
|
|
|
* OpenERP Web Mobile chrome
|
|
|
|
*---------------------------------------------------------*/
|
|
|
|
|
2011-07-08 12:26:49 +00:00
|
|
|
openerp.web_mobile.chrome_mobile = function(openerp) {
|
2011-08-18 13:24:18 +00:00
|
|
|
|
|
|
|
openerp.web_mobile.mobilewebclient = function(element_id) {
|
2011-09-05 12:28:15 +00:00
|
|
|
// TODO Helper to start mobile webclient rename it openerp.web.webclient
|
2011-08-18 13:24:18 +00:00
|
|
|
var client = new openerp.web_mobile.MobileWebClient(element_id);
|
|
|
|
client.start();
|
|
|
|
return client;
|
|
|
|
};
|
|
|
|
|
2011-09-05 12:28:15 +00:00
|
|
|
openerp.web_mobile.MobileWebClient = openerp.web.Widget.extend({
|
2011-08-18 13:24:18 +00:00
|
|
|
init: function(element_id) {
|
|
|
|
var self = this;
|
|
|
|
this._super(null, element_id);
|
|
|
|
QWeb.add_template("xml/web_mobile.xml");
|
|
|
|
var params = {};
|
|
|
|
this.$element.html(QWeb.render("WebClient", {}));
|
2011-09-05 12:28:15 +00:00
|
|
|
this.session = new openerp.web.Session("oe_errors");
|
|
|
|
this.crashmanager = new openerp.web.CrashManager(this);
|
2011-08-18 13:24:18 +00:00
|
|
|
this.login = new openerp.web_mobile.Login(this, "oe_app");
|
2011-08-24 06:20:10 +00:00
|
|
|
// this.session.on_session_invalid.add(this.login.do_ask_login);
|
2011-08-18 13:24:18 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
this.session.start();
|
|
|
|
this.login.start();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-09-05 12:28:15 +00:00
|
|
|
openerp.web_mobile.Login = openerp.web.Widget.extend({
|
2011-08-18 13:24:18 +00:00
|
|
|
init: function(session, element_id) {
|
|
|
|
this._super(session, element_id);
|
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
var self = this;
|
|
|
|
jQuery("#oe_header").children().remove();
|
2011-09-05 13:44:57 +00:00
|
|
|
this.rpc("/web/database/get_list", {}, function(result) {
|
2011-08-18 13:24:18 +00:00
|
|
|
var selection = new openerp.web_mobile.Selection();
|
|
|
|
self.db_list = result.db_list;
|
|
|
|
self.$element.html(QWeb.render("Login", self));
|
2011-08-29 05:39:45 +00:00
|
|
|
self.$element.find("#login_btn").click(self.on_login);
|
2011-08-18 13:24:18 +00:00
|
|
|
$.mobile.initializePage();
|
|
|
|
});
|
|
|
|
this.$element
|
|
|
|
.removeClass("login_invalid");
|
|
|
|
},
|
|
|
|
on_login: function(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
var self = this;
|
|
|
|
var $e = this.$element;
|
2011-09-05 13:44:57 +00:00
|
|
|
var db = $e.find("div select[name=database]").val();
|
2011-08-18 13:24:18 +00:00
|
|
|
var login = $e.find("div input[name=login]").val();
|
|
|
|
var password = $e.find("div input[name=password]").val();
|
|
|
|
//$e.hide();
|
|
|
|
// Should hide then call callback
|
|
|
|
this.session.session_login(db, login, password, function() {
|
|
|
|
if(self.session.session_is_valid()) {
|
|
|
|
self.on_login_valid();
|
|
|
|
} else {
|
|
|
|
self.on_login_invalid();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
on_login_invalid: function() {
|
|
|
|
this.$element
|
|
|
|
.removeClass("login_valid")
|
|
|
|
.addClass("login_invalid")
|
|
|
|
.show();
|
|
|
|
},
|
|
|
|
on_login_valid: function() {
|
|
|
|
this.$element
|
|
|
|
.removeClass("login_invalid")
|
|
|
|
.addClass("login_valid");
|
|
|
|
//.hide();
|
|
|
|
this.homepage = new openerp.web_mobile.HomePage(this, "oe_app");
|
|
|
|
this.homepage.start();
|
|
|
|
},
|
|
|
|
do_ask_login: function(continuation) {
|
|
|
|
this.on_login_invalid();
|
|
|
|
this.on_login_valid.add({
|
|
|
|
position: "last",
|
|
|
|
unique: true,
|
|
|
|
callback: continuation
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-09-05 12:28:15 +00:00
|
|
|
openerp.web_mobile.HomePage = openerp.web.Widget.extend({
|
2011-08-18 13:24:18 +00:00
|
|
|
init: function(session, element_id) {
|
|
|
|
this._super(session, element_id);
|
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
this.$element.html(QWeb.render("HomePage", {}));
|
2011-08-19 13:02:32 +00:00
|
|
|
this.header = new openerp.web_mobile.Header(this, "oe_header");
|
2011-08-18 13:24:18 +00:00
|
|
|
this.shortcuts = new openerp.web_mobile.Shortcuts(this, "oe_shortcuts");
|
|
|
|
this.menu = new openerp.web_mobile.Menu(this, "oe_menu", "oe_secondary_menu");
|
|
|
|
this.options = new openerp.web_mobile.Options(this, "oe_options");
|
2011-08-19 13:02:32 +00:00
|
|
|
this.header.start();
|
2011-08-18 13:24:18 +00:00
|
|
|
this.shortcuts.start();
|
|
|
|
this.menu.start();
|
|
|
|
this.options.start();
|
|
|
|
jQuery("#oe_header").find("h1").html('Home');
|
|
|
|
this.$element.find("a").click(this.on_clicked);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-09-05 12:28:15 +00:00
|
|
|
openerp.web_mobile.Header = openerp.web.Widget.extend({
|
2011-08-18 13:24:18 +00:00
|
|
|
init: function(session, element_id) {
|
|
|
|
this._super(session, element_id);
|
|
|
|
},
|
|
|
|
start: function() {
|
2011-08-19 13:02:32 +00:00
|
|
|
var self = this;
|
|
|
|
self.$element.html(QWeb.render("Header", this));
|
|
|
|
self.$element.find("a").click(this.on_clicked);
|
2011-08-18 13:24:18 +00:00
|
|
|
},
|
|
|
|
on_clicked: function(ev) {
|
|
|
|
$opt = $(ev.currentTarget);
|
|
|
|
current_id = $opt.attr('id');
|
|
|
|
if (current_id == 'home') {
|
|
|
|
this.homepage = new openerp.web_mobile.HomePage(this, "oe_app");
|
|
|
|
this.homepage.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-09-05 12:28:15 +00:00
|
|
|
openerp.web_mobile.Shortcuts = openerp.web.Widget.extend({
|
2011-07-08 12:26:49 +00:00
|
|
|
init: function(session, element_id) {
|
|
|
|
this._super(session, element_id);
|
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
var self = this;
|
2011-09-05 12:28:15 +00:00
|
|
|
this.rpc('/web/session/sc_list',{} ,function(res){
|
2011-09-06 08:58:53 +00:00
|
|
|
self.$element.html(QWeb.render("Shortcuts", {'sc' : res}));
|
2011-07-08 12:26:49 +00:00
|
|
|
self.$element.find("a").click(self.on_clicked);
|
|
|
|
})
|
|
|
|
},
|
|
|
|
on_clicked: function(ev) {
|
|
|
|
$shortcut = $(ev.currentTarget);
|
|
|
|
id = $shortcut.data('menu');
|
|
|
|
res_id = $shortcut.data('res');
|
|
|
|
jQuery("#oe_header").find("h1").html($shortcut.data('name'));
|
2011-08-12 10:57:38 +00:00
|
|
|
this.listview = new openerp.web_mobile.ListView(this, "oe_app", res_id);
|
2011-07-08 12:26:49 +00:00
|
|
|
this.listview.start();
|
|
|
|
}
|
|
|
|
});
|
2011-08-18 13:24:18 +00:00
|
|
|
|
2011-09-05 12:28:15 +00:00
|
|
|
openerp.web_mobile.Menu = openerp.web.Widget.extend({
|
2011-08-18 13:24:18 +00:00
|
|
|
init: function(session, element_id, secondary_menu_id) {
|
2011-07-08 12:26:49 +00:00
|
|
|
this._super(session, element_id);
|
2011-08-18 13:24:18 +00:00
|
|
|
this.secondary_menu_id = secondary_menu_id;
|
|
|
|
this.$secondary_menu = $("#" + secondary_menu_id);
|
|
|
|
this.menu = false;
|
2011-07-08 12:26:49 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
2011-09-05 12:28:15 +00:00
|
|
|
this.rpc("/web/menu/load", {}, this.on_loaded);
|
2011-07-08 12:26:49 +00:00
|
|
|
},
|
2011-08-18 13:24:18 +00:00
|
|
|
on_loaded: function(data) {
|
|
|
|
this.data = data;
|
|
|
|
this.$element.html(QWeb.render("Menu", this.data));
|
|
|
|
this.$element.add(this.$secondary_menu).find("a").click(this.on_menu_click);
|
|
|
|
},
|
|
|
|
on_menu_click: function(ev, id) {
|
|
|
|
$menu = $(ev.currentTarget);
|
|
|
|
id = $menu.data('menu');
|
|
|
|
for (var i = 0; i < this.data.data.children.length; i++) {
|
|
|
|
if (this.data.data.children[i].id == id) {
|
|
|
|
this.children = this.data.data.children[i];
|
|
|
|
}
|
2011-07-08 12:26:49 +00:00
|
|
|
}
|
2011-08-18 13:24:18 +00:00
|
|
|
jQuery("#oe_header").find("h1").html($menu.data('name'));
|
|
|
|
this.$element
|
|
|
|
.removeClass("login_valid")
|
|
|
|
.addClass("secondary_menu");
|
|
|
|
//.hide();
|
|
|
|
this.secondary = new openerp.web_mobile.Secondary(this, "oe_app", this.children);
|
|
|
|
this.secondary.start();
|
2011-07-08 12:26:49 +00:00
|
|
|
}
|
|
|
|
});
|
2011-08-18 13:24:18 +00:00
|
|
|
|
2011-09-05 12:28:15 +00:00
|
|
|
openerp.web_mobile.Secondary = openerp.web.Widget.extend({
|
2011-07-08 12:26:49 +00:00
|
|
|
init: function(session, element_id, secondary_menu_id) {
|
|
|
|
this._super(session, element_id);
|
|
|
|
this.data = secondary_menu_id;
|
|
|
|
},
|
|
|
|
start: function(ev, id) {
|
|
|
|
var v = { menu : this.data };
|
|
|
|
this.$element.html(QWeb.render("Menu.secondary", v));
|
|
|
|
this.$element.add(this.$secondary_menu).find("a").click(this.on_menu_click);
|
|
|
|
},
|
|
|
|
on_menu_click: function(ev, id) {
|
|
|
|
$menu = $(ev.currentTarget);
|
|
|
|
id = $menu.data('menu');
|
|
|
|
for (var i = 0; i < this.data.children.length; i++) {
|
|
|
|
if (this.data.children[i].id == id) {
|
|
|
|
this.children = this.data.children[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
jQuery("#oe_header").find("h1").html($menu.data('name'));
|
|
|
|
var child_len = this.children.children.length;
|
|
|
|
if (child_len > 0) {
|
|
|
|
this.$element
|
|
|
|
.removeClass("secondary_menu")
|
|
|
|
.addClass("content_menu");
|
|
|
|
//.hide();
|
2011-08-12 10:57:38 +00:00
|
|
|
this.secondary = new openerp.web_mobile.Secondary(this, "oe_app", this.children);
|
2011-07-08 12:26:49 +00:00
|
|
|
this.secondary.start();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (id) {
|
2011-08-12 10:57:38 +00:00
|
|
|
this.listview = new openerp.web_mobile.ListView(this, "oe_app", id);
|
2011-07-08 12:26:49 +00:00
|
|
|
this.listview.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-09-05 12:28:15 +00:00
|
|
|
openerp.web_mobile.Options = openerp.web.Widget.extend({
|
2011-07-08 12:26:49 +00:00
|
|
|
init: function(session, element_id) {
|
|
|
|
this._super(session, element_id);
|
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
var self = this;
|
|
|
|
this.$element.html(QWeb.render("Options", this));
|
|
|
|
self.$element.find("#logout").click(self.on_logout);
|
|
|
|
},
|
|
|
|
on_logout: function(ev) {
|
|
|
|
this.session.logout();
|
2011-08-19 13:02:32 +00:00
|
|
|
// this.login = new openerp.web_mobile.Login(this, "oe_app");
|
|
|
|
// this.login.start();
|
2011-07-08 12:26:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-09-05 12:28:15 +00:00
|
|
|
openerp.web_mobile.Selection = openerp.web.Widget.extend({
|
2011-07-19 06:23:35 +00:00
|
|
|
init: function (){
|
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
start: function(){
|
|
|
|
this._super();
|
|
|
|
var self = this;
|
|
|
|
},
|
|
|
|
on_select_option: function(ev){
|
|
|
|
ev.preventDefault();
|
|
|
|
var $this = ev.currentTarget;
|
|
|
|
$($this).prev().find(".ui-btn-text").html($($this).find("option:selected").text());
|
|
|
|
}
|
|
|
|
});
|
2011-09-06 08:58:53 +00:00
|
|
|
};
|