Author: jmorliaguet Date: Tue Dec 20 23:27:15 2005 New Revision: 2071 Modified: cpsskins/branches/jmo-perspectives/ui/default/filters/style/style_editor.js Log:
- fixed the conflict errors problem. This was due to 'setSelectorStyle' being called several times in a row, since the same 'onchange' event was registered at each creation of a form. Now we destroy the form before creating a new one. Also the observer is declared using an indirection, otherwise stopObserving() will not work: this.onChange = this.changeField.bindAsEventListener(this); Event.observe(form_area, 'change', this.onChange); // Event.stopObserve(form_area, 'change', this.onChange); changeField: function() { ... } Modified: cpsskins/branches/jmo-perspectives/ui/default/filters/style/style_editor.js ============================================================================== --- cpsskins/branches/jmo-perspectives/ui/default/filters/style/style_editor.js (original) +++ cpsskins/branches/jmo-perspectives/ui/default/filters/style/style_editor.js Tue Dec 20 23:27:15 2005 @@ -71,7 +71,7 @@ // Now we can open the edit form for this style if (this.form) this.form.destroy(); this.form = new EditForm(this); - this.form.create(); + this.form.createForm(); }, getWidgetStyle: function() { @@ -134,15 +134,24 @@ } + /* Edit form */ EditForm = Class.create(); EditForm.prototype = { initialize: function(preview) { this.preview = preview; this.form_data = {}; + // Register the event + this.onChange = this.changeField.bindAsEventListener(this); + Event.observe(form_area, 'change', this.onChange); + }, + + destroy: function() { + // Unregister the event + Event.stopObserving(form_area, 'change', this.onChange); }, - create: function() { + createForm: function() { var preview = this.preview; new Ajax.Request('getFieldRange', { parameters: $H({'widget_type': preview.widget_type, @@ -153,23 +162,28 @@ onComplete: this.onComplete.bind(this), }); - // Register the event - Event.observe(form_area, 'change', - this.onChange.bindAsEventListener(this)); }, - destroy: function() { - // Unregister the event - Event.stopObserving(form_area, 'change', this.onChange); + changeField: function(e) { + var preview = this.preview; + + // Update the model on the client + var field = Event.element(e); + var attrs = {}; + attrs[field.name] = field.value; + preview.updateStyle(attrs); + + // Update the model on the server + preview.setSelectorStyle(); }, onComplete: function(request) { this.form_data = JSON.parse(request.responseText); - this.render(); + this.renderForm(); clear_message(); }, - render: function() { + renderForm: function() { var preview = this.preview; var sel = preview.selector; var form = document.createElement('form'); @@ -217,19 +231,6 @@ }, - onChange: function(e) { - var preview = this.preview; - - // Update the model on the client - var field = Event.element(e); - var attrs = new Object(); - attrs[field.name] = field.value; - preview.updateStyle(attrs); - - - // Update the model on the server - preview.setSelectorStyle(); - } } /* Setup */ @@ -242,7 +243,7 @@ Element.hide(tooltip_box); - preview = new Preview(widget_type); + new Preview(widget_type); } -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins