diff options
| author | Fabien Meghazi <fme@openerp.com> | 2012-05-09 10:41:39 +0200 |
|---|---|---|
| committer | Fabien Meghazi <fme@openerp.com> | 2012-05-09 10:41:39 +0200 |
| commit | 104615333c062e96896f3783edea1bb1b441d36c (patch) | |
| tree | f7ba96cc95d0ba1ac1d383db548c4f6266f2e6cc /addons/web/static/src/js | |
| parent | dd47079a116a8f535dd0ca3c27b1357aff033508 (diff) | |
| parent | e4fdf1b061b7cc859e3d257dcab504caf8e8ebf2 (diff) | |
[MERGE] Merge trunk
bzr revid: fme@openerp.com-20120509084139-q0jae332yok87ae1
Diffstat (limited to 'addons/web/static/src/js')
| -rw-r--r-- | addons/web/static/src/js/boot.js | 2 | ||||
| -rw-r--r-- | addons/web/static/src/js/corelib.js | 4 | ||||
| -rw-r--r-- | addons/web/static/src/js/coresetup.js | 2 | ||||
| -rw-r--r-- | addons/web/static/src/js/view_form.js | 110 | ||||
| -rw-r--r-- | addons/web/static/src/js/view_list_editable.js | 2 |
5 files changed, 69 insertions, 51 deletions
diff --git a/addons/web/static/src/js/boot.js b/addons/web/static/src/js/boot.js index 29d953aadd8..f83dbc97095 100644 --- a/addons/web/static/src/js/boot.js +++ b/addons/web/static/src/js/boot.js @@ -37,7 +37,7 @@ }; openerp.instances[new_instance._session_id] = new_instance; for(var i=0; i < modules.length; i++) { - openerp[modules[i]](new_instance); + openerp[modules[i]](new_instance,new_instance[modules[i]]); } return new_instance; } diff --git a/addons/web/static/src/js/corelib.js b/addons/web/static/src/js/corelib.js index 465ad2c921b..b30350a9502 100644 --- a/addons/web/static/src/js/corelib.js +++ b/addons/web/static/src/js/corelib.js @@ -1046,7 +1046,9 @@ instance.web.JsonRPC = instance.web.CallbackEnabled.extend({ '<li>Source: %(source)s</li>' + '</ul>'; try { - var ctx = this.test_eval_contexts(source.contexts); + // see Session.eval_context in Python + var ctx = this.test_eval_contexts( + ([this.context] || []).concat(source.contexts)); if (!_.isEqual(ctx, expected.context)) { instance.webclient.notification.warn('Context mismatch, report to xmo', _.str.sprintf(match_template, { diff --git a/addons/web/static/src/js/coresetup.js b/addons/web/static/src/js/coresetup.js index 00fdb9aec98..8e7b5d4f75d 100644 --- a/addons/web/static/src/js/coresetup.js +++ b/addons/web/static/src/js/coresetup.js @@ -279,7 +279,7 @@ instance.web.Session = instance.web.JsonRPC.extend( /** @lends instance.web.Sess instance[mod] = {}; // init module mod if(instance._openerp[mod] != undefined) { - instance._openerp[mod](instance); + instance._openerp[mod](instance,instance[mod]); this.module_loaded[mod] = true; } } diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 607e92f0802..03889a91757 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -6,8 +6,34 @@ var QWeb = instance.web.qweb; /** @namespace */ instance.web.form = {}; +/** + * Interface implemented by the form view or any other object + * able to provide the features necessary for the fields to work. + * + * Properties: + * - display_invalid_fields : if true, all fields where is_valid() return true should + * be displayed as invalid. + * Events: + * - view_content_has_changed : when the values of the fields have changed. When + * this event is triggered all fields should reprocess their modifiers. + */ +instance.web.form.FieldManagerMixin = { + /** + * Must return the asked field as in fields_get. + */ + get_field: function(field_name) {}, + /** + * Called by the field when the translate button is clicked. + */ + open_translate_dialog: function(field) {}, + /** + * Returns true when the view is in create mode. + */ + is_create_mode: function() {}, +}; + instance.web.views.add('form', 'instance.web.FormView'); -instance.web.FormView = instance.web.View.extend({ +instance.web.FormView = instance.web.View.extend(_.extend({}, instance.web.form.FieldManagerMixin, { /** * Indicates that this view is not searchable, and thus that no search * view should be displayed (if there is one active). @@ -859,6 +885,15 @@ instance.web.FormView = instance.web.View.extend({ is_create_mode: function() { return !this.datarecord.id; }, +})); + +/** + * Interface to be implemented by rendering engines for the form view. + */ +instance.web.form.FormRenderingEngineInterface = instance.web.Class.extend({ + set_fields_view: function(fields_view) {}, + set_fields_registry: function(fields_registry) {}, + render_to: function($element) {}, }); /** @@ -866,7 +901,7 @@ instance.web.FormView = instance.web.View.extend({ * * It is necessary to set the view using set_view() before usage. */ -instance.web.form.FormRenderingEngine = instance.web.Class.extend({ +instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInterface.extend({ init: function(view) { this.view = view; }, @@ -1381,10 +1416,6 @@ instance.web.form.FormWidget = instance.web.Widget.extend(_.extend({}, instance. this._super(); this.$element.addClass(this.node.attrs["class"] || ""); }, - start: function() { - this._super(); - instance.web.form.InvisibilityChangerMixin.start.call(this); - }, destroy: function() { $.fn.tipsy.clear(); this._super.apply(this, arguments); @@ -1558,32 +1589,6 @@ instance.web.form.WidgetButton = instance.web.form.FormWidget.extend({ }); /** - * Interface implemented by the form view or any other object - * able to provide the features necessary for the fields to work. - * - * Properties: - * - display_invalid_fields : if true, all fields where is_valid() return true should - * be displayed as invalid. - * Events: - * - view_content_has_changed : when the values of the fields have changed. When - * this event is triggered all fields should reprocess their modifiers. - */ -instance.web.form.FieldManagerInterface = { - /** - * Must return the asked field as in fields_get. - */ - get_field: function(field_name) {}, - /** - * Called by the field when the translate button is clicked. - */ - open_translate_dialog: function(field) {}, - /** - * Returns true when the view is in create mode. - */ - is_create_mode: function() {}, -}; - -/** * Interface to be implemented by fields. * * Properties: @@ -1594,10 +1599,10 @@ instance.web.form.FieldManagerInterface = { * - changed_value: triggered to inform the view to check on_changes * */ -instance.web.form.FieldInterface = { +instance.web.form.FieldMixin = { /** * Constructor takes 2 arguments: - * - field_manager: Implements FieldManagerInterface + * - field_manager: Implements FieldManagerMixin * - node: the "<field>" node in json form */ init: function(field_manager, node) {}, @@ -1658,7 +1663,7 @@ instance.web.form.FieldInterface = { }; /** - * Abstract class for classes implementing FieldInterface. + * Abstract class for classes implementing FieldMixin. * * Properties: * - effective_readonly: when it is true, the widget is displayed as readonly. Vary depending @@ -1668,7 +1673,7 @@ instance.web.form.FieldInterface = { * a 'changed_value' event that inform the view to trigger on_changes. * */ -instance.web.form.AbstractField = instance.web.form.FormWidget.extend(/** @lends instance.web.form.AbstractField# */{ +instance.web.form.AbstractField = instance.web.form.FormWidget.extend(_.extend({}, instance.web.form.FieldMixin, { /** * @constructs instance.web.form.AbstractField * @extends instance.web.form.FormWidget @@ -1677,7 +1682,6 @@ instance.web.form.AbstractField = instance.web.form.FormWidget.extend(/** @lends * @param node */ init: function(field_manager, node) { - this._super(field_manager, node); this.field_manager = field_manager; this.name = this.node.attrs.name; @@ -1701,9 +1705,8 @@ instance.web.form.AbstractField = instance.web.form.FormWidget.extend(/** @lends this._check_css_flags(); }); }, - start: function() { - var self = this; - this._super.apply(this, arguments); + renderElement: function() { + this._super(); if (this.field.translate) { this.$element.addClass('oe_form_field_translatable'); this.$element.find('.oe_field_translate').click(_.bind(function() { @@ -1714,13 +1717,17 @@ instance.web.form.AbstractField = instance.web.form.FormWidget.extend(/** @lends this.do_attach_tooltip(this, this.view.$element.find('label[for=' + this.id_for_label + ']')[0] || this.$element); } if (!this.disable_utility_classes) { - var set_required = function() { - self.$element.toggleClass('oe_form_required', self.get("required")); - }; - this.on("change:required", this, set_required); - set_required(); + this.off("change:required", this, this._set_required); + this.on("change:required", this, this._set_required); + this._set_required(); } }, + /** + * Private. Do not use. + */ + _set_required: function() { + this.$element.toggleClass('oe_form_required', this.get("required")); + }, set_value: function(value_) { this._inhibit_on_change = true; this.set({'value': value_}); @@ -1775,7 +1782,7 @@ instance.web.form.AbstractField = instance.web.form.FormWidget.extend(/** @lends set_input_id: function(id) { this.id_for_label = id; }, -}); +})); /** * A mixin to apply on any field that has to completely re-render when its readonly state @@ -3797,7 +3804,10 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ }); /** - * Registry of form widgets, called by :js:`instance.web.FormView` + * Registry of form fields, called by :js:`instance.web.FormView`. + * + * All referenced classes must implement FieldMixin. Those represent the classes whose instances + * will substitute to the <field> tags as defined in OpenERP's views. */ instance.web.form.widgets = new instance.web.Registry({ 'char' : 'instance.web.form.FieldChar', @@ -3823,6 +3833,12 @@ instance.web.form.widgets = new instance.web.Registry({ 'statusbar': 'instance.web.form.FieldStatus' }); +/** + * Registry of widgets usable in the form view that can substitute to any possible + * tags defined in OpenERP's form views. + * + * Every referenced class should extend FormWidget. + */ instance.web.form.tags = new instance.web.Registry({ 'button' : 'instance.web.form.WidgetButton', }); diff --git a/addons/web/static/src/js/view_list_editable.js b/addons/web/static/src/js/view_list_editable.js index e539d17e63f..83b219a211a 100644 --- a/addons/web/static/src/js/view_list_editable.js +++ b/addons/web/static/src/js/view_list_editable.js @@ -377,7 +377,7 @@ openerp.web.list_editable = function (instance) { renderElement: function() {} }); - instance.web.ListEditableRenderingEngine = instance.web.Class.extend({ + instance.web.ListEditableRenderingEngine = instance.web.form.FormRenderingEngineInterface.extend({ init: function(view) { this.view = view; }, |
