[IMP] Dynamic pages for relational fields & on many2one open formview.
bzr revid: bth@tinyerp.com-20110922073303-kpewefsb6k6sncp7
This commit is contained in:
@@ -141,12 +141,13 @@ openerp.web_mobile.Shortcuts = openerp.web.Widget.extend({
|
||||
$shortcut = $(ev.currentTarget);
|
||||
id = $shortcut.data('menu');
|
||||
res_id = $shortcut.data('res');
|
||||
|
||||
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{
|
||||
$.mobile.changePage($('#oe_list_'+res_id), "slide", true, true);
|
||||
$.mobile.changePage('#oe_list_'+res_id, "slide", true, true);
|
||||
}
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
@@ -260,6 +261,7 @@ openerp.web_mobile.Secondary = openerp.web.Widget.extend({
|
||||
id = $menu.data('menu');
|
||||
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);
|
||||
|
||||
@@ -5,20 +5,30 @@
|
||||
openerp.web_mobile.form_mobile = function (openerp) {
|
||||
|
||||
openerp.web_mobile.FormView = openerp.web.Widget.extend({
|
||||
init: function(session, element_id, list_id, action, head_title) {
|
||||
init: function(session, element_id, list_id, action, head_title, resmodel, viewid) {
|
||||
this._super(session, element_id);
|
||||
this.list_id = list_id;
|
||||
this.action = action;
|
||||
this.head_title = head_title;
|
||||
this.resmodel = resmodel;
|
||||
this.viewid = viewid;
|
||||
|
||||
},
|
||||
start: function() {
|
||||
var self = this;
|
||||
var id = this.list_id;
|
||||
var model = this.action.res_model;
|
||||
var view_id = this.action.views[1][0];
|
||||
this.dataset = new openerp.web.DataSetSearch(this, this.action.res_model, null, null);
|
||||
|
||||
var model = this.action.res_model || this.resmodel;
|
||||
if(this.action){
|
||||
var view_id = this.action.views[1][0];
|
||||
}else{
|
||||
var view_id = this.viewid;
|
||||
}
|
||||
|
||||
this.dataset = new openerp.web.DataSetSearch(this, model, null, null);
|
||||
var context = new openerp.web.CompoundContext(this.dataset.get_context());
|
||||
this.dataset.read_slice([],{}, function (result) {
|
||||
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
if (result[i].id == id) {
|
||||
var data = result[i];
|
||||
@@ -29,6 +39,7 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
|
||||
var view_fields = result.arch.children;
|
||||
var get_fields = self.get_fields(view_fields);
|
||||
var selection = new openerp.web_mobile.Selection();
|
||||
|
||||
for (var j = 0; j < view_fields.length; j++) {
|
||||
if (view_fields[j].tag == 'notebook') {
|
||||
var notebooks = view_fields[j];
|
||||
@@ -58,10 +69,19 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
|
||||
$.mobile.changePage("#oe_options", "slide", true, true);
|
||||
}
|
||||
});
|
||||
self.$element.find('select').change(function(ev){
|
||||
selection.on_select_option(ev);
|
||||
self.$element.find('#formbutton').click(function(){
|
||||
var selected_id = $(this).prev().find('select').val();
|
||||
var select_model = $(this).prev().find('select').attr('for');
|
||||
if(selected_id!="false"){
|
||||
if(!$('[id^="oe_form_'+selected_id+select_model+'"]').html()){
|
||||
$('<div id="oe_form_'+selected_id+select_model+'" data-role="page" data-url="oe_form_'+selected_id+select_model+'"> </div>').appendTo('#moe');
|
||||
this.formview = new openerp.web_mobile.FormView(self, "oe_form_"+selected_id+select_model, selected_id, '', 'head',select_model,false);
|
||||
this.formview.start();
|
||||
}else{
|
||||
$.mobile.changePage('#oe_form_'+selected_id+select_model, "slide", true, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
self.$element.find('[data-role=collapsible-set]').find('[data-role=collapsible]').each(function(i){
|
||||
|
||||
for (var k = 0; k < notebooks.children.length; k++) {
|
||||
@@ -84,6 +104,19 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
|
||||
}else{
|
||||
$(this).find('p').html(QWeb.render("FormView", {'get_fields': get_fields,'fields' : result.fields, 'values' : data }));
|
||||
}
|
||||
$(this).find('p').find('#formbutton').click(function(){
|
||||
var selected_id = $(this).prev().find('select').val();
|
||||
var select_model = $(this).prev().find('select').attr('for');
|
||||
if(selected_id!="false"){
|
||||
if(!$('[id^="oe_form_'+selected_id+select_model+'"]').html()){
|
||||
$('<div id="oe_form_'+selected_id+select_model+'" data-role="page" data-url="oe_form_'+selected_id+select_model+'"> </div>').appendTo('#moe');
|
||||
this.formview = new openerp.web_mobile.FormView(self, "oe_form_"+selected_id+select_model, selected_id, '', 'head',select_model,false);
|
||||
this.formview.start();
|
||||
}else{
|
||||
$.mobile.changePage('#oe_form_'+selected_id+select_model, "slide", true, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
@@ -101,6 +134,7 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
|
||||
});
|
||||
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]]];
|
||||
@@ -111,12 +145,12 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
|
||||
}
|
||||
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(){
|
||||
$('[id^="oe_list_'+relational+'_'+self.element_id+'"]').html(QWeb.render("ListView", {'records' : res}));
|
||||
$('[id^="oe_list_'+relational+'_'+self.element_id+'"]').find("[data-role=header]").find('h1').html(head);
|
||||
$('[id^="oe_list_'+relational+'_'+self.element_id+'"]').find("[data-role=header]").find('#home').click(function(){
|
||||
$.mobile.changePage("#oe_menu", "slide", true, true);
|
||||
});
|
||||
$('#oe_list_'+relational+'_'+self.element_id).find("[data-role=footer]").find('#shrotcuts').click(function(){
|
||||
$('[id^="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();
|
||||
@@ -125,7 +159,7 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
|
||||
$.mobile.changePage("#oe_shortcuts", "slide", true, true);
|
||||
}
|
||||
});
|
||||
$('#oe_list_'+relational+'_'+self.element_id).find("[data-role=footer]").find('#preference').click(function(){
|
||||
$('[id^="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();
|
||||
@@ -134,7 +168,7 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
|
||||
$.mobile.changePage("#oe_options", "slide", true, true);
|
||||
}
|
||||
});
|
||||
$('#oe_list_'+relational+'_'+self.element_id).find("a#list-id").click(function(ev){
|
||||
$('[id^="oe_list_'+relational+'_'+self.element_id+'"]').find("a#list-id").click(function(ev){
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
var head_title = $(this).text();
|
||||
@@ -146,8 +180,8 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
|
||||
var data_relational = result_relational[i];
|
||||
}
|
||||
}
|
||||
if(!$('[id^="oe_listform_'+listid+'"]').html()){
|
||||
$('<div id="oe_listform_'+listid+'" data-role="page" data-url="oe_listform_'+listid+'"> </div>').appendTo('#moe');
|
||||
if(!$('[id^="oe_form_'+listid+result.fields[relational].relation+'"]').html()){
|
||||
$('<div id="oe_form_'+listid+result.fields[relational].relation+'" data-role="page" data-url="oe_form_'+listid+result.fields[relational].relation+'"> </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);
|
||||
@@ -163,16 +197,13 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
|
||||
}
|
||||
}
|
||||
}
|
||||
$('#oe_listform_'+listid).html(QWeb.render("FormView", {'get_fields': get_fields_test, 'notebooks': false, 'fields' : fields_test, 'values' : data_relational, 'temp_flag':'1' }));
|
||||
$('[id^="oe_form_'+listid+result.fields[relational].relation+'"]').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_listform_'+listid).find("[data-role=header]").find('h1').html(head_title);
|
||||
$('#oe_listform_'+listid).find("[data-role=header]").find('#home').click(function(){
|
||||
$('[id^="oe_form_'+listid+result.fields[relational].relation+'"]').find("[data-role=header]").find('h1').html(head_title);
|
||||
$('[id^="oe_form_'+listid+result.fields[relational].relation+'"]').find("[data-role=header]").find('#home').click(function(){
|
||||
$.mobile.changePage("#oe_menu", "slide", true, true);
|
||||
});
|
||||
$('#oe_listform_'+listid).find("[data-role=footer]").find('#shrotcuts').click(function(){
|
||||
$('[id^="oe_form_'+listid+result.fields[relational].relation+'"]').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();
|
||||
@@ -181,7 +212,7 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
|
||||
$.mobile.changePage("#oe_shortcuts", "slide", true, true);
|
||||
}
|
||||
});
|
||||
$('#oe_listform_'+listid).find("[data-role=footer]").find('#preference').click(function(){
|
||||
$('[id^="oe_form_'+listid+result.fields[relational].relation+'"]').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();
|
||||
@@ -190,9 +221,22 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
|
||||
$.mobile.changePage("#oe_options", "slide", true, true);
|
||||
}
|
||||
});
|
||||
$.mobile.changePage('#oe_listform_'+listid, "slide", true, true);
|
||||
$('[id^="oe_form_'+listid+result.fields[relational].relation+'"]').find('#formbutton').click(function(){
|
||||
var selected_id = $(this).prev().find('select').val();
|
||||
var select_model = $(this).prev().find('select').attr('for');
|
||||
if(selected_id!="false"){
|
||||
if(!$('[id^="oe_form_'+selected_id+select_model+'"]').html()){
|
||||
$('<div id="oe_form_'+selected_id+select_model+'" data-role="page" data-url="oe_form_'+selected_id+select_model+'"> </div>').appendTo('#moe');
|
||||
this.formview = new openerp.web_mobile.FormView(self, "oe_form_"+selected_id+select_model, selected_id, '', 'head',select_model,false);
|
||||
this.formview.start();
|
||||
}else{
|
||||
$.mobile.changePage('#oe_form_'+selected_id+select_model, "slide", true, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
$.mobile.changePage('#oe_form_'+listid+result.fields[relational].relation, "slide", true, true);
|
||||
}else{
|
||||
$.mobile.changePage('#oe_listform_'+listid, "slide", true, true);
|
||||
$.mobile.changePage('#oe_form_'+listid+result.fields[relational].relation, "slide", true, true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -59,12 +59,12 @@ openerp.web_mobile.ListView = openerp.web.Widget.extend({
|
||||
id = $record.data('id');
|
||||
head_title = $.trim($record.text());
|
||||
|
||||
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);
|
||||
if(!$('[id^="oe_form_'+id+this.action.res_model+'"]').html()){
|
||||
$('<div id="oe_form_'+id+this.action.res_model+'" data-role="page" data-url="oe_form_'+id+this.action.res_model+'"> </div>').appendTo('#moe');
|
||||
this.formview = new openerp.web_mobile.FormView(this, "oe_form_"+id+this.action.res_model, id, this.action, head_title, '' ,'');
|
||||
this.formview.start();
|
||||
}else{
|
||||
$.mobile.changePage('#oe_form_'+id, "slide", true, true);
|
||||
$.mobile.changePage('#oe_form_'+id+this.action.res_model, "slide", true, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -232,7 +232,7 @@
|
||||
<t t-if="!(field.attrs.string)" t-esc="fields[field.attrs.name].string"></t>
|
||||
<t t-if="field.attrs.string" t-esc="field.attrs.string"></t>:
|
||||
</label>
|
||||
<select id="" data-native-menu="false">
|
||||
<select id="" data-native-menu="false" t-att-for="fields[field.attrs.name].relation">
|
||||
<t t-if="fields[field.attrs.name].selection">
|
||||
<t t-foreach="fields[field.attrs.name].selection" t-as="opt">
|
||||
<t t-if="values[field.attrs.name]==opt[0]">
|
||||
@@ -244,6 +244,9 @@
|
||||
</t>
|
||||
</t>
|
||||
</select>
|
||||
<t t-if="fields[field.attrs.name].selection">
|
||||
<a id="formbutton" href="#" title="Form View"><img src="/web/static/src/img/icons/gtk-index.png" /></a>
|
||||
</t>
|
||||
</t>
|
||||
<t t-if="fields[field.attrs.name].type == 'one2many'">
|
||||
<ul data-role="listview" data-inset="true" data-theme="d">
|
||||
@@ -281,7 +284,7 @@
|
||||
</form>
|
||||
</div>
|
||||
<t t-if="temp_flag">
|
||||
<t t-call="Footer" />
|
||||
<t t-call="Footer" />
|
||||
</t>
|
||||
</t>
|
||||
</templates>
|
||||
|
||||
Reference in New Issue
Block a user