From 930babc88ec6f5fa24b955afb337f05b435378ec Mon Sep 17 00:00:00 2001 From: "Bhumi Thakkar (Open ERP)" Date: Fri, 16 Sep 2011 16:19:38 +0530 Subject: [PATCH] [IMP]Implement Relational Fields in listview and formview with theme. bzr revid: bth@tinyerp.com-20110916104938-kskhg7c41iwyt465 --- .../web_mobile/static/src/js/chrome_mobile.js | 13 -- .../web_mobile/static/src/js/form_mobile.js | 116 ++++++++++++++- .../web_mobile/static/src/js/list_mobile.js | 6 +- .../web_mobile/static/src/xml/web_mobile.xml | 139 +----------------- 4 files changed, 118 insertions(+), 156 deletions(-) diff --git a/addons/web_mobile/static/src/js/chrome_mobile.js b/addons/web_mobile/static/src/js/chrome_mobile.js index 1a71236e6f4..8cbe19a105c 100644 --- a/addons/web_mobile/static/src/js/chrome_mobile.js +++ b/addons/web_mobile/static/src/js/chrome_mobile.js @@ -84,19 +84,6 @@ openerp.web_mobile.Login = openerp.web.Widget.extend({ }); } }); -openerp.web_mobile.Notepage = openerp.web.Widget.extend({ - init: function(session, element_id) { - this._super(session, element_id); - this.get_fields = this.widget_parent.get_fields; - this.page_fields = this.widget_parent.page_fields; - this.values = this.widget_parent.values; - this.til = this.widget_parent.til; - }, - start: function() { - console.log(this.get_fields,this.page_fields,this.values,this.til,this.$element); - this.$element.html(QWeb.render("NotePage", {'get_fields1': this.get_fields,'fields1' : this.page_fields, 'values1' : this.values,'til1': this.til })); - } -}); openerp.web_mobile.Header = openerp.web.Widget.extend({ init: function(session, element_id) { this._super(session, element_id); diff --git a/addons/web_mobile/static/src/js/form_mobile.js b/addons/web_mobile/static/src/js/form_mobile.js index 1699824ce77..f31742d9760 100644 --- a/addons/web_mobile/static/src/js/form_mobile.js +++ b/addons/web_mobile/static/src/js/form_mobile.js @@ -5,10 +5,11 @@ openerp.web_mobile.form_mobile = function (openerp) { openerp.web_mobile.FormView = openerp.web.Widget.extend({ - init: function(session, element_id, list_id, action) { + init: function(session, element_id, list_id, action, head_title) { this._super(session, element_id); this.list_id = list_id; this.action = action; + this.head_title = head_title; this.content_expanded_class = "ui-collapsible-content ui-collapsible-content-expanded"; this.content_collapsed_class = "ui-collapsible-content ui-collapsible-content-collapsed"; this.expanded_class = "ui-collapsible-content-expanded"; @@ -41,7 +42,7 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({ } self.$element.html(QWeb.render("FormView", {'get_fields': get_fields, 'notebooks': notebooks || false, 'fields' : fields, 'values' : data ,'temp_flag':'1'})); - self.$element.find("[data-role=header]").find('h1').html(self.action.name); + self.$element.find("[data-role=header]").find('h1').html(self.head_title); self.$element.find("[data-role=header]").find('#home').click(function(){ $.mobile.changePage($("#oe_menu"), "slide", true, true); }); @@ -74,6 +75,7 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({ get_fields = self.get_fields(notebooks.children[k].children); for (var i = 0; i < get_fields.length; i++) { if (fields[get_fields[i].attrs.name].type == 'one2many'){ + self.relational_fields = get_fields[i].attrs.name; if(fields[get_fields[i].attrs.name].views.form){ var get_fields_test = self.get_fields(fields[get_fields[i].attrs.name].views.form.arch.children); var fields_test = fields[get_fields[i].attrs.name]['views'].form.fields; @@ -82,16 +84,124 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({ } } } + if(notebook){ $(this).find('p').html(QWeb.render("FormView", {'get_fields': get_fields,'fields' : result.fields, 'values' : data,'til': notebook.attrs.string })); }else{ $(this).find('p').html(QWeb.render("FormView", {'get_fields': get_fields,'fields' : result.fields, 'values' : data })); } + } }); - self.$element.find('[data-role=collapsible-set]').find('[data-role=collapsible]').find('p').find('[data-role=content]').find('ul').find('li').click(function(){ + var latid,lastid; + $(this).parents().each(function(){ + latid = $(this).attr('id'); + self.$element.find('[data-role=collapsible-set]').find('[data-role=collapsible]').each(function(){ + if(latid==$(this).attr('id')){ + lastid = $(this).attr('id'); + } + }); + }); + var relational = $(this).attr('for'); + if(result.fields[relational]){ + var head = $.trim($(this).text()); + var dataset = new openerp.web.DataSetStatic(self, result.fields[relational].relation, result.fields[relational].context); + dataset.domain=[['id', 'in', data[relational]]]; + dataset.name_search('', dataset.domain, 'in',false ,function(res){ + for(var i=0;i ').appendTo('#moe'); + + $('#oe_list').html(QWeb.render("ListView", {'records' : res})); + $('#oe_list').find("[data-role=header]").find('h1').html(head); + $('#oe_list').find("[data-role=header]").find('#home').click(function(){ + $.mobile.changePage($("#oe_menu"), "slide", true, true); + }); + $('#oe_list').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{ + $.mobile.changePage($("#oe_shortcuts"), "slide", true, true); + } + }); + $('#oe_list').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); + } + }); + $('#oe_list').find("a#list-id").click(function(ev){ + var head_title = $(this).text(); + dataset = new openerp.web.DataSetSearch(self, dataset.model, null, null); + dataset.read_slice([],{}, function (result_relational) { + for (var i = 0; i < result_relational.length; i++) { + if (result_relational[i].id == $(ev.currentTarget).data('id')) { + var data_relational = result_relational[i]; + } + } + if($('#oe_form').html().length){ + $('#oe_form').remove(); + $('
').appendTo('#moe'); + for (var k = 0; k < notebooks.children.length; k++) { + if (notebooks.children[k].attrs.string == lastid) { + get_fields = self.get_fields(notebooks.children[k].children); + for (var i = 0; i < get_fields.length; i++) { + if (fields[get_fields[i].attrs.name].type == 'one2many'){ + self.relational_fields = get_fields[i].attrs.name; + if(fields[get_fields[i].attrs.name].views.form){ + var get_fields_test = self.get_fields(fields[get_fields[i].attrs.name].views.form.arch.children); + var fields_test = fields[get_fields[i].attrs.name]['views'].form.fields; + var notebook=fields[get_fields[i].attrs.name].views.form.arch; + } + } + } + } + } + $('#oe_form').html(QWeb.render("FormView", {'get_fields': get_fields_test, 'notebooks': false, 'fields' : fields_test, 'values' : data_relational, 'temp_flag':'1' })); + $('#oe_form').find('select').change(function(ev){ + selection.on_select_option(ev); + }); + $('#oe_form').find("[data-role=header]").find('h1').html(head_title); + $('#oe_form').find("[data-role=header]").find('#home').click(function(){ + $.mobile.changePage($("#oe_menu"), "slide", true, true); + }); + $('#oe_form').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{ + $.mobile.changePage($("#oe_shortcuts"), "slide", true, true); + } + }); + $('#oe_form').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); + } + }); + $.mobile.changePage($("#oe_form"), "slide", true, true); + } + }); + }); + $.mobile.changePage($("#oe_list"), "slide", true, true); + } + }); + } }); $.mobile.changePage($("#oe_form"), "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 3c872496577..d7e7918afbe 100644 --- a/addons/web_mobile/static/src/js/list_mobile.js +++ b/addons/web_mobile/static/src/js/list_mobile.js @@ -55,13 +55,15 @@ openerp.web_mobile.ListView = openerp.web.Widget.extend({ var $record = $(ev.currentTarget); var self = this; id = $record.data('id'); + + head_title = $.trim($record.text()); if(!$('#oe_form').html().length){ - this.formview = new openerp.web_mobile.FormView(this, "oe_form", id, this.action); + this.formview = new openerp.web_mobile.FormView(this, "oe_form", id, this.action, head_title); this.formview.start(); }else{ $('#oe_form').remove(); $('
').appendTo('#moe'); - this.formview = new openerp.web_mobile.FormView(this, "oe_form", id, this.action); + this.formview = new openerp.web_mobile.FormView(this, "oe_form", id, this.action, head_title); 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 208fba1dc77..a6242858069 100644 --- a/addons/web_mobile/static/src/xml/web_mobile.xml +++ b/addons/web_mobile/static/src/xml/web_mobile.xml @@ -7,7 +7,6 @@