[merge] improvements to the mobile client

bzr revid: nicolas.vanhoren@openerp.com-20111205132959-ydnph7z6ohru6jfc
This commit is contained in:
niv-openerp
2011-12-05 14:29:59 +01:00
5 changed files with 80 additions and 286 deletions
+1 -1
View File
@@ -406,7 +406,7 @@ class Root(object):
params = urllib.urlencode(request.args)
return werkzeug.utils.redirect(self.root + '?' + params, 301)(
environ, start_response)
elif request.path == '/mobile':
elif request.path == '/mobile' or ('#' in request.path):
return werkzeug.utils.redirect(
'/web_mobile/static/src/web_mobile.html', 301)(environ, start_response)
@@ -151,14 +151,6 @@ openerp.web_mobile.Shortcuts = openerp.web.Widget.extend({
$.mobile.changePage("#oe_menu", "slide", false, true);
});
self.$element.find('#content').find("a").click(self.on_clicked);
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", false, true);
}
});
$.mobile.changePage("#oe_shortcuts", "slide", false, true);
});
},
@@ -261,22 +253,6 @@ openerp.web_mobile.Secondary = openerp.web.Widget.extend({
this.$element.html(this.render(v));
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("[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", false, true);
}
});
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{
$.mobile.changePage("#oe_options", "slide", false, true);
}
});
this.$element.find("[data-role=header]").find('#home').click(function(){
$.mobile.changePage("#oe_menu", "slide", false, true);
});
@@ -328,14 +304,6 @@ openerp.web_mobile.Options = openerp.web.Widget.extend({
var self = this;
this.$element.html(this.render(this));
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{
$.mobile.changePage("#oe_shortcuts", "slide", false, true);
}
});
this.$element.find("[data-role=header]").find('#home').click(function(){
$.mobile.changePage("#oe_menu", "slide", false, true);
});
+58 -198
View File
@@ -41,221 +41,91 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
var fields = result.fields;
var view_fields = result.arch.children;
var get_fields = this.get_fields(view_fields);
var values = self.datarecord;
for (var j = 0; j < view_fields.length; j++) {
if (view_fields[j].tag == 'notebook') {
var notebooks = view_fields[j];
}
}
self.$element.html(self.render({'get_fields': get_fields, 'notebooks': notebooks || false, 'fields' : fields, 'values' : self.datarecord ,'temp_flag':'1'}));
self.formatdata(get_fields, fields, result, self.datarecord,self.element_id,'element');
self.$element.html(self.render({'get_fields': get_fields, 'notebooks': notebooks || false, 'fields' : fields, 'values' : values ,'temp_flag':'1'}));
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", false, true);
});
self.$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{
$.mobile.changePage("#oe_shortcuts", "slide", false, 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", false, true);
}
});
self.$element.find('#formbutton').click(function(){
var head = $(this).prev().find('select').find("option:selected").text();
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", false, true);
}
}
});
self.$element.find('[data-role=collapsible-set]').find('[data-role=collapsible]').each(function(i){
for (var k = 0; k < notebooks.children.length; k++) {
if (notebooks.children[k].attrs.string == $(this).attr('id')) {
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;
}
}
}
$(this).find('div#page_content').html(self.render({'get_fields': get_fields,'fields' : result.fields, 'values' : self.datarecord}));
get_fields_notebook = self.get_fields(notebooks.children[k].children);
$(this).find('div#page_content').html(self.render({'get_fields': get_fields_notebook,'fields' : fields, 'values' : values}));
}
self.formatdata(get_fields, fields, result, self.datarecord,'page_content','element');
$(this).find('div#page_content').find('#formbutton').click(function(){
var head = $(this).prev().find('select').find("option:selected").text();
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", false, true);
}
}
});
}
});
self.$element.find('[data-role=collapsible-set]').find('[data-role=collapsible]').find('div#page_content').find('[data-role=content]').find('ul').find('li').click(function(ev){
self.$element.find('#o2m_m2m').click(function(ev) {
ev.preventDefault();
ev.stopPropagation();
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.DataSetSearch(self, result.fields[relational].relation, result.fields[relational].context);
dataset.domain=[['id', 'in', self.datarecord[relational]]];
dataset.read_slice([], {}, function(result1,ids){
_.extend(self.action.context,{"html_name_get" : true});
var dataset1 = new openerp.web.DataSet(self, result.fields[relational].relation,result.fields[relational].context);
dataset1.name_get(dataset.ids,function(res){
var additional = "";
if(res['html_name_get']){
additional = res['display'];
}
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');
$('[id^="oe_list_'+relational+'_'+self.element_id+'"]').html(openerp.web.qweb.render("ListView", {'records' : res,'data': additional}));
$('[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", false, true);
});
$('[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();
}else{
$.mobile.changePage("#oe_shortcuts", "slide", false, true);
}
});
$('[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();
}else{
$.mobile.changePage("#oe_options", "slide", false, true);
}
});
$('[id^="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 == listid) {
var data_relational = result_relational[i];
}
}
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);
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;
}
}
}
}
}
if(notebook){
$('[id^="oe_form_'+listid+result.fields[relational].relation+'"]').html(self.render({'get_fields': get_fields_test, 'notebooks': false, 'fields' : fields_test, 'values' : data_relational, 'temp_flag':'1' }));
}else{
$('[id^="oe_form_'+listid+result.fields[relational].relation+'"]').html(self.render({'get_fields': get_fields_test, 'notebooks': false, 'fields' : fields, 'values' : data_relational, 'temp_flag':'1' }));
}
$('[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", false, true);
});
$('[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();
}else{
$.mobile.changePage("#oe_shortcuts", "slide", false, true);
}
});
$('[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();
}else{
$.mobile.changePage("#oe_options", "slide", false, true);
}
});
$('[id^="oe_form_'+listid+result.fields[relational].relation+'"]').find('#formbutton').click(function(){
var head = $(this).prev().find('select').find("option:selected").text();
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", false, true);
}
}
});
if(notebook){
self.formatdata(get_fields_test, fields_test, result, data_relational,'oe_form_'+listid+result.fields[relational].relation,'element');
}else{
self.formatdata(get_fields_test, fields, result, data_relational,'oe_form_'+listid+result.fields[relational].relation,'element');
}
$.mobile.changePage('#oe_form_'+listid+result.fields[relational].relation, "slide", false, true);
self.formatdata('', '', '', '','oe_form_'+listid+result.fields[relational].relation,'slider');
var rel_field = fields[relational];
var rel_ids = values[relational];
var head = rel_field.string;
if (rel_ids) {
var datasearch = new openerp.web.DataSetSearch(self, rel_field.relation, rel_field.context);
datasearch.domain=[['id', 'in', rel_ids]];
datasearch.read_slice(['name'], {context:rel_field.context, domain: datasearch.domain, limit:80}, function(listrec){
_.extend(rel_field.context,{"html_name_get" : true});
var dataset = new openerp.web.DataSet(self, rel_field.relation,rel_field.context);
dataset.name_get(listrec,function(res){
var additional = "";
if(res['html_name_get']){
additional = res['display'];
}
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');
$('[id^="oe_list_'+relational+'_'+self.element_id+'"]').html(openerp.web.qweb.render("ListView", {'records' : res,'data': additional}));
$('[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", false, true);
});
$('[id^="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');
if(!$('[id^="oe_form_'+listid+rel_field.relation+'"]').html()){
$('<div id="oe_form_'+listid+rel_field.relation+'" data-role="page" data-url="oe_form_'+listid+rel_field.relation+'"> </div>').appendTo('#moe');
this.formview = new openerp.web_mobile.FormView(self, "oe_form_"+listid+rel_field.relation, listid, '', head, rel_field.relation, false);
this.formview.start();
}else{
$.mobile.changePage('#oe_form_'+listid+result.fields[relational].relation, "slide", false, true);
$.mobile.changePage('#oe_form_'+listid+rel_field.relation, "slide", false, true);
}
});
});
$.mobile.changePage("#oe_list_"+relational+"_"+self.element_id, "slide", false, true);
}else{
$.mobile.changePage("#oe_list_"+relational+"_"+self.element_id, "slide", false, true);
}
$.mobile.changePage("#oe_list_"+relational+"_"+self.element_id, "slide", false, true);
}else{
$.mobile.changePage("#oe_list_"+relational+"_"+self.element_id, "slide", false, true);
}
});
});
});
}
});
self.$element.find('#m2o_btn').click(this.open_m2o_form);
$.mobile.changePage("#"+self.element_id, "slide", false, true);
self.formatdata('', '', '', '',self.element_id,'slider');
},
open_m2o_form : function(ev) {
ev.preventDefault();
ev.stopPropagation();
var head = $(this).find('a').attr('name');
var selected_id = $(this).find('a').attr('value');
var select_model = $(this).attr('for');
if(selected_id){
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", false, true);
}
}
},
get_fields: function(view_fields, fields) {
this.fields = fields || [];
for (var i=0; i < view_fields.length; i++){
@@ -324,16 +194,6 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
$(this).css('left', '-9999px');
});
});
// image displayed with m2o field
$('[id^="'+id+'"]').find('div[class=ui-select]').each(function(){
$(this).next().each(function(){
if($(this).attr('id')=="formbutton"){
$(this).prev().css('display','inline-table');
$(this).prev().find('a').find('.ui-btn-inner').removeClass('ui-btn-inner');
$(this).prev().find('a').find('span:first').css('padding-right','150px');
}
});
});
}
}
});
+5 -22
View File
@@ -30,13 +30,12 @@ openerp.web_mobile.ListView = openerp.web.Widget.extend({
},
on_search_data: function(ev){
var self = this;
var dataset = new openerp.web.DataSetSearch(this, this.action.res_model,this.action.context);
dataset.domain = self.action.domain;
dataset.read_slice([], {}, function(result,ids){
var datasearch = new openerp.web.DataSetSearch(self, self.action.res_model,self.action.context);
datasearch.domain = self.action.domain;
datasearch.read_slice(['name'], {context:datasearch.context, domain: datasearch.domain, limit:80}, function(listresult){
_.extend(self.action.context,{"html_name_get" : true});
var dataset1 = new openerp.web.DataSet(self, self.action.res_model,self.action.context);
dataset1.name_get(dataset.ids,function(res){
var dataset = new openerp.web.DataSet(self, datasearch.model,datasearch.context);
dataset.name_get(listresult,function(res){
var additional = "";
if(res['html_name_get']){
additional = res['display'];
@@ -46,22 +45,6 @@ openerp.web_mobile.ListView = openerp.web.Widget.extend({
self.$element.find("[data-role=header]").find('#home').click(function(){
$.mobile.changePage("#oe_menu", "slide", false, true);
});
self.$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{
$.mobile.changePage("#oe_shortcuts", "slide", false, 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", false, true);
}
});
self.$element.find("a#list-id").click(self.on_list_click);
$.mobile.changePage("#"+self.element_id, "slide", false, true);
});
+16 -33
View File
@@ -72,7 +72,6 @@
</li>
</ul>
</div>
<t t-call="Footer" />
</t>
<t t-name="Menu">
@@ -114,7 +113,6 @@
</ul>
</t>
</div>
<t t-call="Footer" />
</t>
<t t-name="Options">
@@ -126,7 +124,6 @@
</li>
</ul>
</div>
<t t-call="Footer" />
</t>
<t t-name="ListView">
@@ -159,7 +156,6 @@
</ul>
</t>
</div>
<t t-call="Footer" />
</t>
<t t-name="FormView">
@@ -283,7 +279,9 @@
</label>
<select t-att-id="field.attrs.name" data-native-menu="false">
<t t-foreach="fields[field.attrs.name].selection" t-as="opt">
<option t-att-value="opt[0]"><t t-esc="opt[1]"/></option>
<t t-if="opt[0] == values[field.attrs.name]">
<option t-att-value="opt[0]"><t t-esc="opt[1]"/></option>
</t>
</t>
</select>
</t>
@@ -292,35 +290,23 @@
<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" 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] and values[field.attrs.name]==opt[0]">
<option t-att-value="opt[0]" selected="true" ><t t-esc="opt[1]"/></option>
</t>
<t t-if="values[field.attrs.name] and values[field.attrs.name]!=opt[0]">
<option t-att-value="opt[0]" ><t t-esc="opt[1]"/></option>
</t>
</t>
</t>
<t t-if="values[field.attrs.name] and !fields[field.attrs.name].selection">
<option t-att-value="values[field.attrs.name][0]" ><t t-esc="values[field.attrs.name][1]"/></option>
</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">
<li data-theme="c" t-att-for="field.attrs.name" >
<a href="">
<t t-esc="fields[field.attrs.name].string"/>
<li id="m2o_btn" data-theme="c" t-att-for="fields[field.attrs.name].relation">
<a id="formbutton" href="#" title="Form View" t-att-value="values[field.attrs.name][0]" t-att-name="values[field.attrs.name][1]">
<t t-esc="values[field.attrs.name][1]"/>
</a>
</li>
</ul>
</t>
</t>
<t t-if="fields[field.attrs.name].type == 'one2many' or fields[field.attrs.name].type == 'many2many' ">
<ul data-role="listview" data-inset="true" data-theme="d">
<li id="o2m_m2m" data-theme="c" t-att-for="field.attrs.name">
<a href="#">
<t t-esc="fields[field.attrs.name].string"/>
</a>
</li>
</ul>
</t>
</div>
</t>
<t t-if="notebooks">
@@ -343,8 +329,5 @@
</t>
</form>
</div>
<t t-if="temp_flag">
<t t-call="Footer" />
</t>
</t>
</templates>