[IMP] Create Dynamic pages with hashurl and fields in formview.

bzr revid: bth@tinyerp.com-20110921093312-c3s33i6ascpapvzl
This commit is contained in:
Bhumi Thakkar (Open ERP) 2011-09-21 15:03:12 +05:30
parent b096f09505
commit 9da6ad1040
4 changed files with 82 additions and 78 deletions

View File

@ -135,18 +135,21 @@ openerp.web_mobile.Shortcuts = openerp.web.Widget.extend({
});
},
on_clicked: function(ev) {
var self = this;
ev.preventDefault();
ev.stopPropagation();
$shortcut = $(ev.currentTarget);
id = $shortcut.data('menu');
res_id = $shortcut.data('res');
if(!$('#oe_list').html().length){
this.listview = new openerp.web_mobile.ListView(this, "oe_list", res_id);
this.listview.start();
if(!$('[id^="oe_list_'+res_id+'"]').html()){
$('<div id="oe_list_'+res_id+'" data-role="page" data-url="oe_list_'+res_id+'"> </div>').appendTo('#moe');
this.listview = new openerp.web_mobile.ListView(self, "oe_list_"+res_id, res_id);
this.listview.start();
}else{
$('#oe_list').remove();
$('<div id="oe_list" data-role="page"> </div>').appendTo('#moe');
this.listview = new openerp.web_mobile.ListView(this, "oe_list", res_id);
this.listview.start();
$.mobile.changePage($('#oe_list_'+res_id), "slide", true, true);
}
ev.preventDefault();
ev.stopPropagation();
jQuery("#oe_header").find("h1").html($shortcut.data('name'));
}
});
@ -195,6 +198,8 @@ openerp.web_mobile.Menu = openerp.web.Widget.extend({
on_menu_click: function(ev, id) {
var $menu = $(ev.currentTarget);
id = $menu.data('menu');
ev.preventDefault();
ev.stopPropagation();
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];
@ -204,14 +209,12 @@ openerp.web_mobile.Menu = openerp.web.Widget.extend({
.removeClass("login_valid")
.addClass("secondary_menu");
if(!$('#oe_sec_menu').html().length){
this.secondary = new openerp.web_mobile.Secondary(this, "oe_sec_menu", this.children);
this.secondary.start();
}else{
$('#oe_sec_menu').remove();
$('<div id="oe_sec_menu" data-role="page"> </div>').appendTo('#moe');
this.secondary = new openerp.web_mobile.Secondary(this, "oe_sec_menu", this.children);
if(!$('[id^="oe_sec_menu_'+id+'"]').html()){
$('<div id="oe_sec_menu_'+id+'" data-role="page" data-url="oe_sec_menu_'+id+'"> </div>').appendTo('#moe');
this.secondary = new openerp.web_mobile.Secondary(this, "oe_sec_menu_"+id, this.children);
this.secondary.start();
}else{
$.mobile.changePage('#oe_sec_menu_'+id, "slide", true, true);
}
}
});
@ -250,21 +253,19 @@ openerp.web_mobile.Secondary = openerp.web.Widget.extend({
$.mobile.changePage("#oe_menu", "slide", true, true);
});
$.mobile.changePage("#oe_sec_menu", "slide", true, true);
$.mobile.changePage("#"+this.element_id, "slide", true, true);
},
on_menu_click: function(ev, id) {
var $menu = $(ev.currentTarget);
id = $menu.data('menu');
if (id) {
if(!$('#oe_list').html().length){
this.listview = new openerp.web_mobile.ListView(this, "oe_list", id);
this.listview.start();
}else{
$('#oe_list').remove();
$('<div id="oe_list" data-role="page"> </div>').appendTo('#moe');
this.listview = new openerp.web_mobile.ListView(this, "oe_list", id);
this.listview.start();
}
ev.preventDefault();
ev.stopPropagation();
if(!$('[id^="oe_list_'+id+'"]').html()){
$('<div id="oe_list_'+id+'" data-role="page" data-url="oe_list_'+id+'"> </div>').appendTo('#moe');
this.listview = new openerp.web_mobile.ListView(this, "oe_list_"+id, id);
this.listview.start();
}else{
$.mobile.changePage('#oe_list_'+id, "slide", true, true);
}
jQuery("#oe_header").find("h1").html($menu.data('name'));
}

View File

@ -10,12 +10,6 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
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";
this.collapsed_class = "ui-collapsible-content-collapsed";
this.plus_class = "ui-icon-plus";
this.minus_class = "ui-icon-minus";
},
start: function() {
var self = this;
@ -93,7 +87,9 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
}
});
self.$element.find('[data-role=collapsible-set]').find('[data-role=collapsible]').find('p').find('[data-role=content]').find('ul').find('li').click(function(){
self.$element.find('[data-role=collapsible-set]').find('[data-role=collapsible]').find('p').find('[data-role=content]').find('ul').find('li').click(function(ev){
ev.preventDefault();
ev.stopPropagation();
var latid,lastid;
$(this).parents().each(function(){
latid = $(this).attr('id');
@ -113,17 +109,14 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
var splited_data = res[i][1].split(',');
res[i][1] = splited_data[0];
}
if($('#oe_list').html().length){
$('#oe_list').remove();
$('<div id="oe_list" data-role="page"> </div>').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(){
if(!$('[id^="oe_list_'+relational+'_'+self.element_id+'"]').html()){
$('<div id="oe_list_'+relational+'_'+self.element_id+'" data-role="page" data-url="oe_list_'+relational+'_'+self.element_id+'"> </div>').appendTo('#moe');
$('#oe_list_'+relational+'_'+self.element_id).html(QWeb.render("ListView", {'records' : res}));
$('#oe_list_'+relational+'_'+self.element_id).find("[data-role=header]").find('h1').html(head);
$('#oe_list_'+relational+'_'+self.element_id).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(){
$('#oe_list_'+relational+'_'+self.element_id).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();
@ -132,7 +125,7 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
$.mobile.changePage("#oe_shortcuts", "slide", true, true);
}
});
$('#oe_list').find("[data-role=footer]").find('#preference').click(function(){
$('#oe_list_'+relational+'_'+self.element_id).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();
@ -141,18 +134,20 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
$.mobile.changePage("#oe_options", "slide", true, true);
}
});
$('#oe_list').find("a#list-id").click(function(ev){
$('#oe_list_'+relational+'_'+self.element_id).find("a#list-id").click(function(ev){
ev.preventDefault();
ev.stopPropagation();
var head_title = $(this).text();
var listid = $(ev.currentTarget).data('id');
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')) {
if (result_relational[i].id == listid) {
var data_relational = result_relational[i];
}
}
if($('#oe_form').html().length){
$('#oe_form').remove();
$('<div id="oe_form" data-role="page"> </div>').appendTo('#moe');
if(!$('[id^="oe_listform_'+listid+'"]').html()){
$('<div id="oe_listform_'+listid+'" data-role="page" data-url="oe_listform_'+listid+'"> </div>').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);
@ -168,15 +163,16 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
}
}
}
$('#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){
$('#oe_listform_'+listid).html(QWeb.render("FormView", {'get_fields': get_fields_test, 'notebooks': false, 'fields' : fields_test, 'values' : data_relational, 'temp_flag':'1' }));
$('#oe_listform_'+listid).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(){
$('#oe_listform_'+listid).find("[data-role=header]").find('h1').html(head_title);
$('#oe_listform_'+listid).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(){
$('#oe_listform_'+listid).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();
@ -185,7 +181,7 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
$.mobile.changePage("#oe_shortcuts", "slide", true, true);
}
});
$('#oe_form').find("[data-role=footer]").find('#preference').click(function(){
$('#oe_listform_'+listid).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();
@ -194,16 +190,20 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
$.mobile.changePage("#oe_options", "slide", true, true);
}
});
$.mobile.changePage("#oe_form", "slide", true, true);
$.mobile.changePage('#oe_listform_'+listid, "slide", true, true);
}else{
$.mobile.changePage('#oe_listform_'+listid, "slide", true, true);
}
});
});
$.mobile.changePage("#oe_list", "slide", true, true);
$.mobile.changePage("#oe_list_"+relational+"_"+self.element_id, "slide", true, true);
}else{
$.mobile.changePage("#oe_list_"+relational+"_"+self.element_id, "slide", true, true);
}
});
}
});
$.mobile.changePage("#oe_form", "slide", true, true);
$.mobile.changePage("#"+self.element_id, "slide", true, true);
});
});
},

View File

@ -48,23 +48,23 @@ openerp.web_mobile.ListView = openerp.web.Widget.extend({
}
});
self.$element.find("a#list-id").click(self.on_list_click);
$.mobile.changePage("#oe_list", "slide", true, true);
$.mobile.changePage("#"+self.element_id, "slide", true, true);
});
},
on_list_click: function(ev) {
var $record = $(ev.currentTarget);
var self = this;
ev.preventDefault();
ev.stopPropagation();
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, head_title);
if(!$('[id^="oe_form_'+id+'"]').html()){
$('<div id="oe_form_'+id+'" data-role="page" data-url="oe_form_'+id+'"> </div>').appendTo('#moe');
this.formview = new openerp.web_mobile.FormView(this, "oe_form_"+id, id, this.action, head_title);
this.formview.start();
}else{
$('#oe_form').remove();
$('<div id="oe_form" data-role="page"> </div>').appendTo('#moe');
this.formview = new openerp.web_mobile.FormView(this, "oe_form", id, this.action, head_title);
this.formview.start();
$.mobile.changePage('#oe_form_'+id, "slide", true, true);
}
}
});

View File

@ -7,10 +7,6 @@
<div data-role="page" id="oe_login"></div>
<div id="oe_header" />
<div id="oe_footer" />
<div data-role="page" id="oe_sec_menu"></div>
<div data-role="page" id="oe_sec_menu_new"></div>
<div data-role="page" id="oe_list"></div>
<div data-role="page" id="oe_form"></div>
<div data-role="page" id="oe_shortcuts"></div>
<div data-role="page" id="oe_menu"></div>
<div data-role="page" id="oe_options"></div>
@ -157,7 +153,10 @@
</t>
<t t-if="!(values[field.attrs.name])">
<input type="text" value="" id=""/>
</t>
</t>
<t t-if="(field.attrs.name == 'email' or field.attrs.name == 'email_from') and values[field.attrs.name]">
<a t-att-href="'mailto:'+values[field.attrs.name]"><img src="/web/static/src/img/icons/terp-mail-message-new.png" /></a>
</t>
</t>
<t t-if="fields[field.attrs.name].type == 'text'">
<label for="">
@ -203,15 +202,19 @@
</t>
</t>
<t t-if="fields[field.attrs.name].type == 'boolean'">
<fieldset data-role="controlgroup">
<t t-if="values[field.attrs.name]">
<input type="checkbox" name="checkbox-1" id="checkbox-1" checked="yes" class="custom"/>
</t>
<t t-if="!(values[field.attrs.name])">
<input type="checkbox" name="checkbox-1" id="checkbox-1" class="custom" />
</t>
<label for="checkbox-1"><t t-esc="fields[field.attrs.name].string" /></label>
</fieldset>
<div data-role="fieldcontain">
<label for="slider"><t t-esc="fields[field.attrs.name].string" /> :</label>
<select name="slider" id="slider" data-role="slider">
<t t-if="values[field.attrs.name]">
<option value="on" selected="true">On</option>
<option value="off">Off</option>
</t>
<t t-if="!values[field.attrs.name]">
<option value="on">On</option>
<option value="off" selected="true">Off</option>
</t>
</select>
</div>
</t>
<t t-if="fields[field.attrs.name].type == 'selection'">
<label for="" class="select">