From fbd835894f666db781f4f29392df82a519b2963c Mon Sep 17 00:00:00 2001 From: "Bhumi Thakkar (Open ERP)" Date: Mon, 12 Sep 2011 16:34:28 +0530 Subject: [IMP] Dynamically Set Header & Footer, Change page on click of header-footer. bzr revid: bth@tinyerp.com-20110912110428-xyxc70zql0r01mty --- addons/web_mobile/static/src/js/chrome_mobile.js | 93 ++++++++++++++++-------- addons/web_mobile/static/src/js/list_mobile.js | 45 ++++++------ addons/web_mobile/static/src/xml/web_mobile.xml | 56 ++++---------- 3 files changed, 102 insertions(+), 92 deletions(-) (limited to 'addons/web_mobile/static/src') diff --git a/addons/web_mobile/static/src/js/chrome_mobile.js b/addons/web_mobile/static/src/js/chrome_mobile.js index 2b9d8600fef..9bdc004a7ca 100644 --- a/addons/web_mobile/static/src/js/chrome_mobile.js +++ b/addons/web_mobile/static/src/js/chrome_mobile.js @@ -90,8 +90,7 @@ openerp.web_mobile.Header = openerp.web.Widget.extend({ this._super(session, element_id); }, start: function() { - var self = this; - self.$element.html(QWeb.render("Header", this)); + this.$element.html(QWeb.render("Header", this)); } }); @@ -100,8 +99,7 @@ openerp.web_mobile.Footer = openerp.web.Widget.extend({ this._super(session, element_id); }, start: function() { - var self = this; - self.$element.html(QWeb.render("Footer", this)); + this.$element.html(QWeb.render("Footer", this)); } }); @@ -113,14 +111,19 @@ openerp.web_mobile.Shortcuts = openerp.web.Widget.extend({ var self = this; this.rpc('/web/session/sc_list',{} ,function(res){ self.$element.html(QWeb.render("Shortcuts", {'sc' : res})) + + self.$element.find("[data-role=header]").find('h1').html('Favourite'); + self.$element.find("[data-role=header]").find('#home').click(function(){ + $.mobile.changePage($("#oe_menu"), "slide", true, true); + }); self.$element.find('#content').find("a").click(self.on_clicked); - self.$element.find("#footer").find('#preference').click(function(){ + self.$element.find("[data-role=footer]").find('#preference').click(function(){ if(!$('#oe_options').html().length){ this.options = new openerp.web_mobile.Options(self, "oe_options"); this.options.start(); } else{ - self.$element.find("#footer").find('#preference').attr('href','#oe_options'); + $.mobile.changePage($("#oe_options"), "slide", true, true); } }); $.mobile.changePage($("#oe_shortcuts"), "slide", true, true); @@ -130,9 +133,7 @@ openerp.web_mobile.Shortcuts = openerp.web.Widget.extend({ $shortcut = $(ev.currentTarget); id = $shortcut.data('menu'); res_id = $shortcut.data('res'); -// this.header = new openerp.web_mobile.Header(this, "oe_header"); this.listview = new openerp.web_mobile.ListView(this, "oe_list", res_id); -// this.header.start(); this.listview.start(); jQuery("#oe_header").find("h1").html($shortcut.data('name')); } @@ -151,24 +152,30 @@ openerp.web_mobile.Menu = openerp.web.Widget.extend({ on_loaded: function(data) { var self = this; this.data = data; - this.$element.html(QWeb.render("Menu", this.data)); - this.$element.find("#footer").find('#shrotcuts').click(function(){ + this.header = new openerp.web_mobile.Header(this, "oe_header"); + this.header.start(); + this.footer = new openerp.web_mobile.Footer(this, "oe_footer"); + this.footer.start(); + + this.$element.html(QWeb.render("Menu", this.data)); + this.$element.find("[data-role=header]").find('h1').html('Application'); + this.$element.find("[data-role=footer]").find('#shrotcuts').click(function(){ if(!$('#oe_shortcuts').html().length){ this.shortcuts = new openerp.web_mobile.Shortcuts(self, "oe_shortcuts"); this.shortcuts.start(); } else{ - self.$element.find("#footer").find('#shrotcuts').attr('href','#oe_shortcuts'); + $.mobile.changePage($("#oe_shortcuts"), "slide", true, true); } }); - this.$element.find("#footer").find('#preference').click(function(){ + this.$element.find("[data-role=footer]").find('#preference').click(function(){ if(!$('#oe_options').html().length){ this.options = new openerp.web_mobile.Options(self, "oe_options"); this.options.start(); } else{ - self.$element.find("#footer").find('#preference').attr('href','#oe_options'); + $.mobile.changePage($("#oe_options"), "slide", true, true); } }); this.$element.add(this.$secondary_menu).find("#content").find('a').click(this.on_menu_click); @@ -186,20 +193,37 @@ openerp.web_mobile.Menu = openerp.web.Widget.extend({ .removeClass("login_valid") .addClass("secondary_menu"); //.hide(); - if(!$('#oe_sec_menu').html().length){ + /*if(!$('#oe_sec_menu').html().length){ this.secondary = new openerp.web_mobile.Secondary(this, "oe_sec_menu", this.children); this.secondary.start(); }else{ - this.$element.find("#content").find('a').attr('href','#oe_sec_menu'); - } - /*if(!$('#oe_sec_menu').html().length){ + //console.log('heree>>>>>>>>>>>>>>>>>>',$('#'+$('.ui-page-active').attr('id'))); + var id=$('.ui-page-active').attr('id'); + //console.log('heree>>>>>>>>>>>>>>>>>>',$('#'+id).removeClass('ui-page-active')); + this.secondary = new openerp.web_mobile.Secondary(this, "oe_sec_menu", this.children); this.secondary.start(); - }else{ - // self.$element.find("#content").find('a').attr('href','#oe_sec_menu'); - this.$element.add(this.$secondary_menu).find("#content").find('a').attr('href','#oe_sec_menu'); - }*/ + $('#'+id).removeClass('ui-page-active'); + $('#oe_sec_menu').addClass('ui-page-active'); + //console.log(); + $.mobile.changePage($("#oe_menu"), "slide", true, true); + + //if($('.ui-page-active').attr('id').live()) + //$.mobile.changePage($("#oe_sec_menu"), "slide", true, true); + // this.secondary = new openerp.web_mobile.Secondary(this, "oe_sec_menu", this.children); + // this.secondary.start(); + + //$.mobile.loadPage(); + //$.mobile.changePage($("#oe_sec_menu"), "slide", true, true); + //this.$element.find("#content").find('a').attr('href','#oe_sec_menu'); + }*/ + if(!$('#oe_sec_menu').html().length){ + this.secondary = new openerp.web_mobile.Secondary(this, "oe_sec_menu", this.children); + this.secondary.start(); + }else{ + $.mobile.changePage($("#oe_sec_menu"), "slide", true, true); + } } }); openerp.web_mobile.Secondary = openerp.web.Widget.extend({ @@ -209,7 +233,6 @@ openerp.web_mobile.Secondary = openerp.web.Widget.extend({ }, start: function(ev, id) { var self = this; - // console.log(this.data,this.$element.html().length); /* if(this.$element.html().length){ self.$element.find('[data-role="listview"]').remove(); @@ -225,27 +248,33 @@ openerp.web_mobile.Secondary = openerp.web.Widget.extend({ }else{*/ var v = { menu : this.data }; + this.$element.html(QWeb.render("Menu.secondary", v)); - this.$element.find("#header").find("h1").html(this.data.name); + + this.$element.find("[data-role=header]").find("h1").html(this.data.name); this.$element.add(this.$secondary_menu).find('#content').find("a").click(this.on_menu_click); - this.$element.find("#footer").find('#shrotcuts').click(function(){ + this.$element.find("[data-role=footer]").find('#shrotcuts').click(function(){ if(!$('#oe_shortcuts').html().length){ this.shortcuts = new openerp.web_mobile.Shortcuts(self, "oe_shortcuts"); this.shortcuts.start(); } else{ - self.$element.find("#footer").find('#shrotcuts').attr('href','#oe_shortcuts'); + $.mobile.changePage($("#oe_shortcuts"), "slide", true, true); } }); - this.$element.find("#footer").find('#preference').click(function(){ + this.$element.find("[data-role=footer]").find('#preference').click(function(){ if(!$('#oe_options').html().length){ this.options = new openerp.web_mobile.Options(self, "oe_options"); this.options.start(); } else{ - self.$element.find("#footer").find('#preference').attr('href','#oe_options'); + $.mobile.changePage($("#oe_options"), "slide", true, true); } }); + this.$element.find("[data-role=header]").find('#home').click(function(){ + $.mobile.changePage($("#oe_menu"), "slide", true, true); + }); + $.mobile.changePage($("#oe_sec_menu"), "slide", true, true); }, on_menu_click: function(ev, id) { @@ -262,16 +291,22 @@ openerp.web_mobile.Secondary = openerp.web.Widget.extend({ openerp.web_mobile.Options = openerp.web.Widget.extend({ start: function() { var self = this; + this.$element.html(QWeb.render("Options", this)); - this.$element.find("#footer").find('#shrotcuts').click(function(){ + this.$element.find("[data-role=header]").find('h1').html('Preference'); + this.$element.find("[data-role=footer]").find('#shrotcuts').click(function(){ if(!$('#oe_shortcuts').html().length){ this.shortcuts = new openerp.web_mobile.Shortcuts(self, "oe_shortcuts"); this.shortcuts.start(); } else{ - self.$element.find("#footer").find('#shrotcuts').attr('href','#oe_shortcuts'); + $.mobile.changePage($("#oe_shortcuts"), "slide", true, true); + //self.$element.find("#footer").find('#shrotcuts').attr('href','#oe_shortcuts'); } }); + this.$element.find("[data-role=header]").find('#home').click(function(){ + $.mobile.changePage($("#oe_menu"), "slide", true, true); + }); $.mobile.changePage($("#oe_options"), "slide", true, true); } }); diff --git a/addons/web_mobile/static/src/js/list_mobile.js b/addons/web_mobile/static/src/js/list_mobile.js index 1d4e0d72ca2..8d276a6bc65 100644 --- a/addons/web_mobile/static/src/js/list_mobile.js +++ b/addons/web_mobile/static/src/js/list_mobile.js @@ -32,26 +32,29 @@ openerp.web_mobile.ListView = openerp.web.Widget.extend({ } self.$element.find('[data-role="listview"]').listview('refresh'); }else{ - self.$element.html(QWeb.render("ListView", {'records' : result})); - self.$element.find("#header").find('h1').html(self.action.name); - self.$element.find("#footer").find('#shortcuts').click(function(){ - if(!$('#oe_shortcuts').html().length){ - this.shortcut = new openerp.web_mobile.Options(self, "oe_shortcuts"); - this.options.start(); - } - else{ - self.$element.find("#footer").find('#shrotcuts').attr('href','#oe_shortcuts'); - } - }); - self.$element.find("#footer").find('#preference').click(function(){ - if(!$('#oe_options').html().length){ - this.options = new openerp.web_mobile.Options(self, "oe_options"); - this.options.start(); - } - else{ - self.$element.find("#footer").find('#preference').attr('href','#oe_options'); - } - }); + self.$element.html(QWeb.render("ListView", {'records' : result})); + self.$element.find("[data-role=header]").find('h1').html(self.action.name); + self.$element.find("[data-role=header]").find('#home').click(function(){ + $.mobile.changePage($("#oe_menu"), "slide", true, true); + }); + self.$element.find("[data-role=footer]").find('#shortcuts').click(function(){ + if(!$('#oe_shortcuts').html().length){ + this.shortcut = new openerp.web_mobile.Shortcuts(self, "oe_shortcuts"); + this.shortcut.start(); + } + else{ + $.mobile.changePage($("#oe_shortcuts"), "slide", true, true); + } + }); + self.$element.find("[data-role=footer]").find('#preference').click(function(){ + if(!$('#oe_options').html().length){ + this.options = new openerp.web_mobile.Options(self, "oe_options"); + this.options.start(); + } + else{ + $.mobile.changePage($("#oe_options"), "slide", true, true); + } + }); } self.$element.find("a#list-id").click(self.on_list_click); $.mobile.changePage($("#oe_list"), "slide", true, true); @@ -61,9 +64,7 @@ openerp.web_mobile.ListView = openerp.web.Widget.extend({ var $record = $(ev.currentTarget); var self = this; id = $record.data('id'); -// this.header = new openerp.web_mobile.Header(this, "oe_header"); this.formview = new openerp.web_mobile.FormView(this, "oe_form", id, this.action); -// this.header.start(); this.formview.start(); } }); diff --git a/addons/web_mobile/static/src/xml/web_mobile.xml b/addons/web_mobile/static/src/xml/web_mobile.xml index 75d30af55b1..29a325a61ce 100644 --- a/addons/web_mobile/static/src/xml/web_mobile.xml +++ b/addons/web_mobile/static/src/xml/web_mobile.xml @@ -5,6 +5,8 @@
+
+