diff options
| author | Vidhin Mehta (OpenERP) <vme@tinyerp.com> | 2011-09-14 11:07:46 +0530 |
|---|---|---|
| committer | Vidhin Mehta (OpenERP) <vme@tinyerp.com> | 2011-09-14 11:07:46 +0530 |
| commit | b6076c3cc3ca5141349b99821268b8fd5e148b77 (patch) | |
| tree | bb875d3ef5127cf5b8c35de6475de14e5477dbbd /addons/web_mobile/static/src/js/chrome_mobile.js | |
| parent | 243e1bdb0079ea9f214696ead8228d464ecb2cfc (diff) | |
| parent | c7c2b5846d3775780bbaa9a84a93ad755bdb8756 (diff) | |
[Merge] upto revno 1024.
bzr revid: vme@tinyerp.com-20110914053746-ri6d5s341mm6tc7n
Diffstat (limited to 'addons/web_mobile/static/src/js/chrome_mobile.js')
| -rw-r--r-- | addons/web_mobile/static/src/js/chrome_mobile.js | 219 |
1 files changed, 128 insertions, 91 deletions
diff --git a/addons/web_mobile/static/src/js/chrome_mobile.js b/addons/web_mobile/static/src/js/chrome_mobile.js index 551856e01fb..2b9d8600fef 100644 --- a/addons/web_mobile/static/src/js/chrome_mobile.js +++ b/addons/web_mobile/static/src/js/chrome_mobile.js @@ -5,22 +5,21 @@ openerp.web_mobile.chrome_mobile = function(openerp) { openerp.web_mobile.mobilewebclient = function(element_id) { - // TODO Helper to start mobile webclient rename it openerp.base.webclient + // TODO Helper to start mobile webclient rename it openerp.web.webclient var client = new openerp.web_mobile.MobileWebClient(element_id); client.start(); return client; }; -openerp.web_mobile.MobileWebClient = openerp.base.Widget.extend({ +openerp.web_mobile.MobileWebClient = openerp.web.Widget.extend({ 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", {})); - this.session = new openerp.base.Session("oe_errors"); - this.crashmanager = new openerp.base.CrashManager(this); - this.login = new openerp.web_mobile.Login(this, "oe_app"); + this.session = new openerp.web.Session("oe_errors"); + this.crashmanager = new openerp.web.CrashManager(this); + this.login = new openerp.web_mobile.Login(this, "oe_login"); // this.session.on_session_invalid.add(this.login.do_ask_login); }, start: function() { @@ -29,14 +28,11 @@ openerp.web_mobile.MobileWebClient = openerp.base.Widget.extend({ } }); -openerp.web_mobile.Login = openerp.base.Widget.extend({ - init: function(session, element_id) { - this._super(session, element_id); - }, +openerp.web_mobile.Login = openerp.web.Widget.extend({ start: function() { var self = this; jQuery("#oe_header").children().remove(); - this.rpc("/base/database/get_list", {}, function(result) { + this.rpc("/web/database/get_list", {}, function(result) { var selection = new openerp.web_mobile.Selection(); self.db_list = result.db_list; self.$element.html(QWeb.render("Login", self)); @@ -53,6 +49,7 @@ openerp.web_mobile.Login = openerp.base.Widget.extend({ var db = $e.find("div select[name=database]").val(); 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() { @@ -74,8 +71,9 @@ openerp.web_mobile.Login = openerp.base.Widget.extend({ .removeClass("login_invalid") .addClass("login_valid"); //.hide(); - this.homepage = new openerp.web_mobile.HomePage(this, "oe_app"); - this.homepage.start(); + + this.menu = new openerp.web_mobile.Menu(this, "oe_menu", "oe_secondary_menu"); + this.menu.start(); }, do_ask_login: function(continuation) { this.on_login_invalid(); @@ -87,66 +85,60 @@ openerp.web_mobile.Login = openerp.base.Widget.extend({ } }); -openerp.web_mobile.HomePage = openerp.base.Widget.extend({ +openerp.web_mobile.Header = openerp.web.Widget.extend({ init: function(session, element_id) { this._super(session, element_id); }, start: function() { - this.$element.html(QWeb.render("HomePage", {})); - this.header = new openerp.web_mobile.Header(this, "oe_header"); - 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"); - this.header.start(); - this.shortcuts.start(); - this.menu.start(); - this.options.start(); - jQuery("#oe_header").find("h1").html('Home'); - this.$element.find("a").click(this.on_clicked); + var self = this; + self.$element.html(QWeb.render("Header", this)); } }); -openerp.web_mobile.Header = openerp.base.Widget.extend({ +openerp.web_mobile.Footer = openerp.web.Widget.extend({ init: function(session, element_id) { this._super(session, element_id); }, start: function() { var self = this; - self.$element.html(QWeb.render("Header", this)); - self.$element.find("a").click(this.on_clicked); - }, - 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(); - } + self.$element.html(QWeb.render("Footer", this)); } }); -openerp.web_mobile.Shortcuts = openerp.base.Widget.extend({ +openerp.web_mobile.Shortcuts = openerp.web.Widget.extend({ init: function(session, element_id) { this._super(session, element_id); }, start: function() { var self = this; - this.rpc('/base/session/sc_list',{} ,function(res){ + this.rpc('/web/session/sc_list',{} ,function(res){ self.$element.html(QWeb.render("Shortcuts", {'sc' : res})) - self.$element.find("a").click(self.on_clicked); - }) + self.$element.find('#content').find("a").click(self.on_clicked); + 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'); + } + }); + $.mobile.changePage($("#oe_shortcuts"), "slide", true, true); + }); }, 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')); - this.listview = new openerp.web_mobile.ListView(this, "oe_app", res_id); +// 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')); } }); -openerp.web_mobile.Menu = openerp.base.Widget.extend({ +openerp.web_mobile.Menu = openerp.web.Widget.extend({ init: function(session, element_id, secondary_menu_id) { this._super(session, element_id); this.secondary_menu_id = secondary_menu_id; @@ -154,96 +146,141 @@ openerp.web_mobile.Menu = openerp.base.Widget.extend({ this.menu = false; }, start: function() { - this.rpc("/base/menu/load", {}, this.on_loaded); + this.rpc("/web/menu/load", {}, this.on_loaded); }, on_loaded: function(data) { + var self = this; this.data = data; this.$element.html(QWeb.render("Menu", this.data)); - this.$element.add(this.$secondary_menu).find("a").click(this.on_menu_click); + + this.$element.find("#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'); + } + }); + this.$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'); + } + }); + this.$element.add(this.$secondary_menu).find("#content").find('a').click(this.on_menu_click); + $.mobile.changePage($("#oe_menu"), "slide", true, true); }, on_menu_click: function(ev, id) { - $menu = $(ev.currentTarget); + var $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]; } } - 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(); + 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){ + 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'); + }*/ + } }); - -openerp.web_mobile.Secondary = openerp.base.Widget.extend({ +openerp.web_mobile.Secondary = openerp.web.Widget.extend({ init: function(session, element_id, secondary_menu_id) { this._super(session, element_id); this.data = secondary_menu_id; }, 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(); + + _.each(self.data.children,function(i){ + var newul = '<ul data-dividertheme="b" class="ui-listview ui-listview-inset ui-corner-all ui-shadow" data-theme="c" data-inset="true" data-role="listview"><li data-role="list-divider">'+ + i.name+'</li></ul>'; // Create New List Item + self.$element.find('#content').append(newul); + //console.log('in for loop',i.children); + }); + console.log('saaasasaaa',self.$element.find('#content'),self.data); + //self.$element.find('[data-role="listview"]').listview('refresh'); + }else{*/ + 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); + this.$element.find("#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(){ + 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'); + } + }); + this.$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'); + } + }); + $.mobile.changePage($("#oe_sec_menu"), "slide", true, true); }, on_menu_click: function(ev, id) { - $menu = $(ev.currentTarget); + var $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]; - } + if (id) { + this.listview = new openerp.web_mobile.ListView(this, "oe_list", id); + this.listview.start(); } 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(); - this.secondary = new openerp.web_mobile.Secondary(this, "oe_app", this.children); - this.secondary.start(); - } - else { - if (id) { - this.listview = new openerp.web_mobile.ListView(this, "oe_app", id); - this.listview.start(); - } - } } }); -openerp.web_mobile.Options = openerp.base.Widget.extend({ - init: function(session, element_id) { - this._super(session, element_id); - }, +openerp.web_mobile.Options = openerp.web.Widget.extend({ 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(); -// this.login = new openerp.web_mobile.Login(this, "oe_app"); -// this.login.start(); + this.$element.find("#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_options"), "slide", true, true); } }); -openerp.web_mobile.Selection = openerp.base.Widget.extend({ - init: function (){ - this._super(); - }, - start: function(){ - this._super(); - var self = this; - }, +openerp.web_mobile.Selection = openerp.web.Widget.extend({ on_select_option: function(ev){ ev.preventDefault(); var $this = ev.currentTarget; $($this).prev().find(".ui-btn-text").html($($this).find("option:selected").text()); } }); -} +}; |
