1 /*---------------------------------------------------------
2 * OpenERP Web Mobile chrome
3 *---------------------------------------------------------*/
5 openerp.web_mobile.chrome_mobile = function(openerp) {
7 openerp.web_mobile.mobilewebclient = function(element_id) {
8 // TODO Helper to start mobile webclient rename it openerp.web.webclient
9 var client = new openerp.web_mobile.MobileWebClient(element_id);
14 openerp.web_mobile.MobileWebClient = openerp.web.Widget.extend({
15 init: function(element_id) {
16 this._super(null, element_id);
17 QWeb.add_template("xml/web_mobile.xml");
19 this.$element.html(QWeb.render("WebClient", {}));
20 this.session = new openerp.web.Session("oe_errors");
21 this.crashmanager = new openerp.web.CrashManager(this);
22 this.login = new openerp.web_mobile.Login(this, "oe_login");
23 // this.session.on_session_invalid.add(this.login.do_ask_login);
31 openerp.web_mobile.Login = openerp.web.Widget.extend({
34 jQuery("#oe_header").children().remove();
35 this.rpc("/web/database/get_list", {}, function(result) {
36 var selection = new openerp.web_mobile.Selection();
37 self.db_list = result.db_list;
38 self.$element.html(QWeb.render("Login", self));
39 self.$element.find("#login_btn").click(self.on_login);
40 $.mobile.initializePage();
43 .removeClass("login_invalid");
45 on_login: function(ev) {
48 var $e = this.$element;
49 var db = $e.find("div select[name=database]").val();
50 var login = $e.find("div input[name=login]").val();
51 var password = $e.find("div input[name=password]").val();
54 // Should hide then call callback
55 this.session.session_login(db, login, password, function() {
56 if(self.session.session_is_valid()) {
57 self.on_login_valid();
59 self.on_login_invalid();
63 on_login_invalid: function() {
65 .removeClass("login_valid")
66 .addClass("login_invalid")
69 on_login_valid: function() {
71 .removeClass("login_invalid")
72 .addClass("login_valid");
75 this.menu = new openerp.web_mobile.Menu(this, "oe_menu", "oe_secondary_menu");
78 do_ask_login: function(continuation) {
79 this.on_login_invalid();
80 this.on_login_valid.add({
83 callback: continuation
87 openerp.web_mobile.Header = openerp.web.Widget.extend({
88 init: function(session, element_id) {
89 this._super(session, element_id);
92 this.$element.html(QWeb.render("Header", this));
96 openerp.web_mobile.Footer = openerp.web.Widget.extend({
97 init: function(session, element_id) {
98 this._super(session, element_id);
101 this.$element.html(QWeb.render("Footer", this));
105 openerp.web_mobile.Shortcuts = openerp.web.Widget.extend({
106 init: function(session, element_id) {
107 this._super(session, element_id);
111 this.rpc('/web/session/sc_list',{} ,function(res){
112 self.$element.html(QWeb.render("Shortcuts", {'sc' : res}))
114 self.$element.find("[data-role=header]").find('h1').html('Favourite');
115 self.$element.find("[data-role=header]").find('#home').click(function(){
116 $.mobile.changePage($("#oe_menu"), "slide", true, true);
118 self.$element.find('#content').find("a").click(self.on_clicked);
119 self.$element.find("[data-role=footer]").find('#preference').click(function(){
120 if(!$('#oe_options').html().length){
121 this.options = new openerp.web_mobile.Options(self, "oe_options");
122 this.options.start();
125 $.mobile.changePage($("#oe_options"), "slide", true, true);
128 $.mobile.changePage($("#oe_shortcuts"), "slide", true, true);
131 on_clicked: function(ev) {
132 $shortcut = $(ev.currentTarget);
133 id = $shortcut.data('menu');
134 res_id = $shortcut.data('res');
136 if(!$('#oe_list').html().length){
137 this.listview = new openerp.web_mobile.ListView(this, "oe_list", res_id);
138 this.listview.start();
140 $('#oe_list').remove();
141 $('<div id="oe_list" data-role="page"> </div>').appendTo('#moe');
142 this.listview = new openerp.web_mobile.ListView(this, "oe_list", res_id);
143 this.listview.start();
145 jQuery("#oe_header").find("h1").html($shortcut.data('name'));
149 openerp.web_mobile.Menu = openerp.web.Widget.extend({
150 init: function(session, element_id, secondary_menu_id) {
151 this._super(session, element_id);
152 this.secondary_menu_id = secondary_menu_id;
153 this.$secondary_menu = $("#" + secondary_menu_id);
157 this.rpc("/web/menu/load", {}, this.on_loaded);
159 on_loaded: function(data) {
163 this.header = new openerp.web_mobile.Header(this, "oe_header");
165 this.footer = new openerp.web_mobile.Footer(this, "oe_footer");
168 this.$element.html(QWeb.render("Menu", this.data));
169 this.$element.find("[data-role=header]").find('h1').html('Application');
170 this.$element.find("[data-role=footer]").find('#shrotcuts').click(function(){
171 if(!$('#oe_shortcuts').html().length){
172 this.shortcuts = new openerp.web_mobile.Shortcuts(self, "oe_shortcuts");
173 this.shortcuts.start();
176 $.mobile.changePage($("#oe_shortcuts"), "slide", true, true);
179 this.$element.find("[data-role=footer]").find('#preference').click(function(){
180 if(!$('#oe_options').html().length){
181 this.options = new openerp.web_mobile.Options(self, "oe_options");
182 this.options.start();
185 $.mobile.changePage($("#oe_options"), "slide", true, true);
188 this.$element.add(this.$secondary_menu).find("#content").find('a').click(this.on_menu_click);
189 $.mobile.changePage($("#oe_menu"), "slide", true, true);
191 on_menu_click: function(ev, id) {
192 var $menu = $(ev.currentTarget);
193 id = $menu.data('menu');
194 for (var i = 0; i < this.data.data.children.length; i++) {
195 if (this.data.data.children[i].id == id) {
196 this.children = this.data.data.children[i];
200 .removeClass("login_valid")
201 .addClass("secondary_menu");
203 if(!$('#oe_sec_menu').html().length){
204 this.secondary = new openerp.web_mobile.Secondary(this, "oe_sec_menu", this.children);
205 this.secondary.start();
207 $('#oe_sec_menu').remove();
208 $('<div id="oe_sec_menu" data-role="page"> </div>').appendTo('#moe');
209 this.secondary = new openerp.web_mobile.Secondary(this, "oe_sec_menu", this.children);
210 this.secondary.start();
214 openerp.web_mobile.Secondary = openerp.web.Widget.extend({
215 init: function(session, element_id, secondary_menu_id) {
216 this._super(session, element_id);
217 this.data = secondary_menu_id;
219 start: function(ev, id) {
221 var v = { menu : this.data };
223 this.$element.html(QWeb.render("Menu.secondary", v));
225 this.$element.find("[data-role=header]").find("h1").html(this.data.name);
226 this.$element.add(this.$secondary_menu).find('#content').find("a").click(this.on_menu_click);
227 this.$element.find("[data-role=footer]").find('#shrotcuts').click(function(){
228 if(!$('#oe_shortcuts').html().length){
229 this.shortcuts = new openerp.web_mobile.Shortcuts(self, "oe_shortcuts");
230 this.shortcuts.start();
233 $.mobile.changePage($("#oe_shortcuts"), "slide", true, true);
236 this.$element.find("[data-role=footer]").find('#preference').click(function(){
237 if(!$('#oe_options').html().length){
238 this.options = new openerp.web_mobile.Options(self, "oe_options");
239 this.options.start();
242 $.mobile.changePage($("#oe_options"), "slide", true, true);
245 this.$element.find("[data-role=header]").find('#home').click(function(){
246 $.mobile.changePage($("#oe_menu"), "slide", true, true);
249 $.mobile.changePage($("#oe_sec_menu"), "slide", true, true);
251 on_menu_click: function(ev, id) {
252 var $menu = $(ev.currentTarget);
253 id = $menu.data('menu');
255 if(!$('#oe_list').html().length){
256 this.listview = new openerp.web_mobile.ListView(this, "oe_list", id);
257 this.listview.start();
259 $('#oe_list').remove();
260 $('<div id="oe_list" data-role="page"> </div>').appendTo('#moe');
261 this.listview = new openerp.web_mobile.ListView(this, "oe_list", id);
262 this.listview.start();
265 jQuery("#oe_header").find("h1").html($menu.data('name'));
269 openerp.web_mobile.Options = openerp.web.Widget.extend({
273 this.$element.html(QWeb.render("Options", this));
274 this.$element.find("[data-role=header]").find('h1').html('Preference');
275 this.$element.find("[data-role=footer]").find('#shrotcuts').click(function(){
276 if(!$('#oe_shortcuts').html().length){
277 this.shortcuts = new openerp.web_mobile.Shortcuts(self, "oe_shortcuts");
278 this.shortcuts.start();
281 $.mobile.changePage($("#oe_shortcuts"), "slide", true, true);
284 this.$element.find("[data-role=header]").find('#home').click(function(){
285 $.mobile.changePage($("#oe_menu"), "slide", true, true);
287 this.$element.find("[data-role=content]").find('a').click(function(){
288 $('#oe_login').empty();
289 window.location.replace('/mobile');
291 $.mobile.changePage($("#oe_options"), "slide", true, true);
295 openerp.web_mobile.Selection = openerp.web.Widget.extend({
296 on_select_option: function(ev){
298 var $this = ev.currentTarget;
299 $($this).prev().find(".ui-btn-text").html($($this).find("option:selected").text());