[WIP] Form v2
bzr revid: fme@openerp.com-20120312153452-x6zhyeheu4579ak3
This commit is contained in:
parent
2cb9261f0b
commit
e125dd5f63
|
@ -1113,6 +1113,7 @@ class View(openerpweb.Controller):
|
|||
arch = fvg['arch'].encode('utf-8')
|
||||
else:
|
||||
arch = fvg['arch']
|
||||
fvg['arch_string'] = arch
|
||||
|
||||
if transform:
|
||||
evaluation_context = session.evaluation_context(context or {})
|
||||
|
|
|
@ -12,7 +12,7 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
|
|||
*/
|
||||
searchable: false,
|
||||
readonly : false,
|
||||
form_template: "FormView",
|
||||
template: "FormView",
|
||||
display_name: _lt('Form'),
|
||||
/**
|
||||
* @constructs openerp.web.FormView
|
||||
|
@ -91,22 +91,24 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
|
|||
on_loaded: function(data) {
|
||||
var self = this;
|
||||
if (!data) {
|
||||
throw "No data provided.";
|
||||
throw new Error("No data provided.");
|
||||
}
|
||||
if (this.root_frame) {
|
||||
throw "Form view does not support multiple calls to on_loaded";
|
||||
if (this.arch) {
|
||||
throw "Form view does not support multiple calls to on_loaded";
|
||||
}
|
||||
this.fields_order = [];
|
||||
this.fields_view = data;
|
||||
this.arch = this.preprocess_arch(data);
|
||||
|
||||
debugger
|
||||
var html_view = openerp.web.xml_to_str(this.arch);
|
||||
this.$element.find('.oe_form_content').append(html_view);
|
||||
|
||||
//this.root_frame = instanciate_widget(this.registry.get_object('frame'), this, this.fields_view.arch);
|
||||
//var to_append = $(".oe_form_header", this.$element);
|
||||
//this.root_frame.appendTo(to_append.length > 0 ? to_append : this.$element);
|
||||
//this.root_frame.$element.children().unwrap();
|
||||
|
||||
this.rendered = QWeb.render(this.form_template, {'widget': this});
|
||||
this.$element.html(this.rendered);
|
||||
|
||||
this.root_frame = instanciate_widget(this.registry.get_object('frame'), this, this.fields_view.arch);
|
||||
var to_append = $(".oe_form_header", this.$element);
|
||||
this.root_frame.appendTo(to_append.length > 0 ? to_append : this.$element);
|
||||
this.root_frame.$element.children().unwrap();
|
||||
|
||||
this.$form_header = this.$element.find('.oe_form_header:first');
|
||||
this.$form_header.find('div.oe_form_pager button[data-pager-action]').click(function() {
|
||||
var action = $(this).data('pager-action');
|
||||
|
@ -135,6 +137,63 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
|
|||
}
|
||||
this.has_been_loaded.resolve();
|
||||
},
|
||||
preprocess_arch: function(data) {
|
||||
// TODO: extract embeded views before preprocessing
|
||||
// Cut down this function into rendering API amongst form, page and kanban
|
||||
//
|
||||
// OpenERP views spec :
|
||||
// - @width is obsolete ?
|
||||
var self = this,
|
||||
baseclass = 'oe_layout_',
|
||||
fields = data.fields,
|
||||
arch = $($.parseXML('<?xml version="1.0" encoding="UTF-8"?>' + data.arch_string));
|
||||
|
||||
// First pass:
|
||||
// - If field has no @string, fetch it from fvg.fields.
|
||||
// - If field has no label, create one.
|
||||
// - Unless @nolabel, create unique @id and @for pair
|
||||
$(arch).find('field').each(function() {
|
||||
var $field = $(this),
|
||||
name = $field.attr('name'),
|
||||
field_orm = fields[name],
|
||||
field_id = _.uniqueId([self.dataset.model, name, '#'].join('.'));
|
||||
if (!field_orm) {
|
||||
throw new Error("Field '" + name + "' specified in view could not be found.");
|
||||
}
|
||||
var $label = $(arch).find('label[for="' + name + '"]'),
|
||||
label_string = $field.attr('string') || field_orm.string || '';
|
||||
if ($label.length) {
|
||||
label_string = $label.attr('string') || $label.text();
|
||||
} else {
|
||||
// TODO: find a way to prevent @xmlns.
|
||||
$label = $('<label/>').insertBefore($field);
|
||||
}
|
||||
$field.attr('id', field_id);
|
||||
$label.attr('for', field_id).text(label_string);
|
||||
});
|
||||
|
||||
// Second pass:
|
||||
// - Convert groups to table
|
||||
while (true) {
|
||||
var $group = $(arch).find('group:first');
|
||||
if (!$group.length) {
|
||||
break;
|
||||
}
|
||||
|
||||
var $table = $('<table/>').addClass(baseclass + 'group');
|
||||
$group.find('*').each(function() {
|
||||
var $tr, $td, colspan, $child = $(this);
|
||||
if (!$tr) {
|
||||
$tr = $('<tr/>').addClass(baseclass + 'group_row').appendTo($table);
|
||||
}
|
||||
|
||||
$td = $('<td/>').addClass(baseclass + 'group_cell');
|
||||
$tr.append($td.append(child));
|
||||
});
|
||||
$group.replaceWith($table);
|
||||
}
|
||||
return arch;
|
||||
},
|
||||
|
||||
do_load_state: function(state, warm) {
|
||||
if (state.id && this.datarecord.id != state.id) {
|
||||
|
|
|
@ -1282,6 +1282,13 @@ session.web.json_node_to_xml = function(node, human_readable, indent) {
|
|||
return r + '/>';
|
||||
}
|
||||
}
|
||||
session.web.xml_to_str = function(node) {
|
||||
if (window.ActiveXObject) {
|
||||
return node.xml;
|
||||
} else {
|
||||
return (new XMLSerializer()).serializeToString(node);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -714,16 +714,19 @@
|
|||
</t>
|
||||
|
||||
<t t-name="FormView">
|
||||
<div class="oe_form_header">
|
||||
<div class="oe_form_buttons" t-if="widget.options.action_buttons !== false">
|
||||
<button type="button" class="oe_button oe_form_button_save">Save</button>
|
||||
<button type="button" class="oe_button oe_form_button_cancel">Cancel</button>
|
||||
</div>
|
||||
<div class="oe_form_pager" t-if="widget.options.pager !== false">
|
||||
<t t-call="ViewPager">
|
||||
<span class="oe_pager_index">0</span><span class="oe_pager_separator"> / </span><span class="oe_pager_count">0</span>
|
||||
</t>
|
||||
<div class="oe_formview">
|
||||
<div class="oe_form_header">
|
||||
<div class="oe_form_buttons" t-if="widget.options.action_buttons !== false">
|
||||
<button type="button" class="oe_button oe_form_button_save">Save</button>
|
||||
<button type="button" class="oe_button oe_form_button_cancel">Cancel</button>
|
||||
</div>
|
||||
<div class="oe_form_pager" t-if="widget.options.pager !== false">
|
||||
<t t-call="ViewPager">
|
||||
<span class="oe_pager_index">0</span><span class="oe_pager_separator"> / </span><span class="oe_pager_count">0</span>
|
||||
</t>
|
||||
</div>
|
||||
</div>
|
||||
<div class="oe_form_content"/>
|
||||
</div>
|
||||
</t>
|
||||
<t t-name="One2Many.formview" t-extend="FormView">
|
||||
|
|
Loading…
Reference in New Issue