Commit 9faa9e1e authored by Yohan Boniface's avatar Yohan Boniface
Browse files

Always forward event from helper to builder, and to obj if possible

parent f45dd4d2
...@@ -40,6 +40,8 @@ L.FormBuilder = L.Class.extend({ ...@@ -40,6 +40,8 @@ L.FormBuilder = L.Class.extend({
}, },
buildField: function (field) { buildField: function (field) {
// field can be either a string like "option.name" or a full definition array,
// like ['options.tilelayer.tms', {handler: 'CheckBox', helpText: 'TMS format'}]
var type, helper, options; var type, helper, options;
if (field instanceof Array) { if (field instanceof Array) {
options = field[1] || {}; options = field[1] || {};
...@@ -54,24 +56,7 @@ L.FormBuilder = L.Class.extend({ ...@@ -54,24 +56,7 @@ L.FormBuilder = L.Class.extend({
helper = new type(this, field, options); helper = new type(this, field, options);
} }
this.helpers[field] = helper; this.helpers[field] = helper;
helper.on('synced', function () { this.on('postsync', this.onPostSync);
if (helper.options.callback) {
helper.options.callback.call(helper.options.callbackContext || this.obj);
}
if (this.options.callback) {
this.options.callback.call(this.options.callbackContext || this.obj, field);
}
this.fire('synced', {field: field});
if (this.obj.fire) this.obj.fire('synced', {field: field});
}, this);
// L.DomEvent.on(input, 'keydown', function (e) {
// var key = e.keyCode,
// ESC = 27;
// if (key === ESC) {
// this.resetField(field);
// L.DomEvent.stop(e);
// }
// }, this);
return helper; return helper;
}, },
...@@ -130,8 +115,13 @@ L.FormBuilder = L.Class.extend({ ...@@ -130,8 +115,13 @@ L.FormBuilder = L.Class.extend({
} }
}, },
finish: function () { onPostSync: function (e) {
this.fire('finish'); if (e.helper.options.callback) {
e.helper.options.callback.call(e.helper.options.callbackContext || this.obj, e);
}
if (this.options.callback) {
this.options.callback.call(this.options.callbackContext || this.obj, e);
}
} }
}); });
...@@ -150,7 +140,15 @@ L.FormBuilder.Element = L.Class.extend({ ...@@ -150,7 +140,15 @@ L.FormBuilder.Element = L.Class.extend({
this.buildLabel(); this.buildLabel();
this.build(); this.build();
this.buildHelpText(); this.buildHelpText();
this.builder.fire('element:init', {element: this}); this.fireAndForward('helper:init');
},
fireAndForward: function (type, e) {
e = e || {};
e.helper = this;
this.fire(type, e);
this.builder.fire(type, e);
if (this.obj.fire) this.obj.fire(type, e);
}, },
get: function () { get: function () {
...@@ -166,8 +164,9 @@ L.FormBuilder.Element = L.Class.extend({ ...@@ -166,8 +164,9 @@ L.FormBuilder.Element = L.Class.extend({
}, },
sync: function () { sync: function () {
this.fireAndForward('presync');
this.set(); this.set();
this.fire('synced'); this.fireAndForward('postsync');
}, },
set: function () { set: function () {
...@@ -191,7 +190,7 @@ L.FormBuilder.Element = L.Class.extend({ ...@@ -191,7 +190,7 @@ L.FormBuilder.Element = L.Class.extend({
fetch: function () {}, fetch: function () {},
finish: function () { finish: function () {
this.builder.finish(); this.fireAndForward('finish');
} }
}); });
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment