Finalize WSF_DYNAMIC_MULTI_CONTROL

This commit is contained in:
YNH Webdev
2014-01-26 22:07:15 +01:00
parent 8f148f2a5e
commit 45ddc47b0e
4 changed files with 179 additions and 27 deletions

View File

@@ -1,5 +1,5 @@
// Generated by CoffeeScript 1.6.1
var Mini, WSF_AUTOCOMPLETE_CONTROL, WSF_BUTTON_CONTROL, WSF_CHECKBOX_CONTROL, WSF_CHECKBOX_LIST_CONTROL, WSF_CODEVIEW_CONTROL, WSF_CONTROL, WSF_DATE_PICKER_CONTROL, WSF_DROPDOWN_CONTROL, WSF_DYNAMIC_MULTI_CONTROL, WSF_FILE_CONTROL, WSF_FORM_ELEMENT_CONTROL, WSF_GRID_CONTROL, WSF_HTML_CONTROL, WSF_INPUT_CONTROL, WSF_MAX_VALIDATOR, WSF_MIN_VALIDATOR, WSF_NAVLIST_ITEM_CONTROL, WSF_PAGE_CONTROL, WSF_PAGINATION_CONTROL, WSF_PASSWORD_CONTROL, WSF_PROGRESS_CONTROL, WSF_REGEXP_VALIDATOR, WSF_REPEATER_CONTROL, WSF_SLIDER_CONTROL, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, build_control, cache, controls, lazy_load, loaded, parseSuggestions, redirect, show_alert, start_modal, start_modal_big, template, tmpl,
var Mini, WSF_AUTOCOMPLETE_CONTROL, WSF_BUTTON_CONTROL, WSF_CHECKBOX_CONTROL, WSF_CHECKBOX_LIST_CONTROL, WSF_CODEVIEW_CONTROL, WSF_CONTROL, WSF_DATE_PICKER_CONTROL, WSF_DROPDOWN_CONTROL, WSF_DYNAMIC_MULTI_CONTROL, WSF_FILE_CONTROL, WSF_FORM_ELEMENT_CONTROL, WSF_GRID_CONTROL, WSF_HTML_CONTROL, WSF_INPUT_CONTROL, WSF_MAX_VALIDATOR, WSF_MIN_VALIDATOR, WSF_NAVLIST_ITEM_CONTROL, WSF_PAGE_CONTROL, WSF_PAGINATION_CONTROL, WSF_PASSWORD_CONTROL, WSF_PROGRESS_CONTROL, WSF_REGEXP_VALIDATOR, WSF_REPEATER_CONTROL, WSF_SLIDER_CONTROL, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, build_control, cache, controls, find_control, lazy_load, loaded, once, parseSuggestions, redirect, show_alert, start_modal, start_modal_big, template, tmpl,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
@@ -118,6 +118,17 @@ parseSuggestions = function(data) {
loaded = {};
once = function(f) {
var executed;
executed = false;
return function() {
if (!executed) {
executed = true;
return f.apply(this, arguments);
}
};
};
lazy_load = function(requirements, fn, that) {
if (requirements.length === 0) {
return function() {
@@ -154,9 +165,30 @@ lazy_load = function(requirements, fn, that) {
};
};
find_control = function(root, name) {
var children, matching;
children = root.children();
if (children.length) {
matching = children.filter('[data-name=' + name + ']');
if (matching.length) {
return matching.first();
} else {
return find_control(children.filter(':not([data-name])'), name);
}
} else {
return null;
}
};
build_control = function(control_name, state, control) {
var $el, type, typeclass;
$el = control.$el.find('[data-name=' + control_name + ']').first();
$el = find_control(control.$el, control_name);
if ($el === null) {
return null;
}
if ($el.data('control') != null) {
return $el.data('control');
}
type = $el.data('type');
typeclass = null;
try {
@@ -257,6 +289,7 @@ WSF_CONTROL = (function() {
this.isolation = "" + this.$el.data('isolation') === "1";
this.$el.data('control', this);
this.initialize = lazy_load(this.requirements, this.attach_events, this);
this.initialize = once(this.initialize);
return;
}
@@ -314,10 +347,10 @@ WSF_CONTROL = (function() {
WSF_CONTROL.prototype.process_update = function(new_states) {
var control, _i, _len, _ref;
try {
if (new_states.actions != null) {
if ((new_states != null ? new_states.actions : void 0) != null) {
this.process_actions(new_states.actions);
}
if (new_states[this.control_name] != null) {
if ((new_states != null ? new_states[this.control_name] : void 0) != null) {
this.update(new_states[this.control_name]);
_ref = this.controls;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@@ -328,6 +361,7 @@ WSF_CONTROL = (function() {
}
}
} catch (e) {
console.error(e);
return;
}
};
@@ -437,7 +471,9 @@ WSF_CONTROL = (function() {
_ref = this.controls;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
control = _ref[_i];
control.remove();
if (control != null) {
control.remove();
}
}
console.log("Removed " + this.control_name);
return this.$el.remove();
@@ -461,6 +497,7 @@ WSF_PAGE_CONTROL = (function(_super) {
this.url_params = jQuery.unparam(this.state['url_params']);
this.$el.data('control', this);
this.initialize = lazy_load(this.requirements, this.attach_events, this);
this.initialize = once(this.initialize);
this.load_subcontrols();
}
@@ -488,7 +525,9 @@ WSF_PAGE_CONTROL = (function(_super) {
_ref = this.controls;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
control = _ref[_i];
control.remove();
if (control != null) {
control.remove();
}
}
console.log("Removed " + this.control_name);
return this.$el.remove();
@@ -803,22 +842,40 @@ WSF_DYNAMIC_MULTI_CONTROL = (function(_super) {
}
WSF_DYNAMIC_MULTI_CONTROL.prototype.update = function(state) {
var control, _i, _j, _len, _len1, _ref, _ref1;
var control, el, k, v, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3;
console.log(state);
if ((state.items != null) && (state.render != null) && (state.newstate != null)) {
this.state['items'] = state.items;
_ref = this.controls;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
control = _ref[_i];
control.remove();
if (!((control != null ? control.control_name : void 0) in state.newstate)) {
if (control != null) {
control.remove();
}
}
}
this.$el.html($(state.render).html());
this.fullstate.controls = state.newstate;
this.load_subcontrols();
_ref1 = this.controls;
_ref1 = $(state.render).children();
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
control = _ref1[_j];
control.initialize();
el = _ref1[_j];
if (this.$el.children('[data-name=' + $(el).data('name') + ']').length === 0) {
this.$el.append(el);
}
}
_ref2 = state.newstate;
for (k in _ref2) {
v = _ref2[k];
if (!(k in this.fullstate.controls)) {
this.fullstate.controls[k] = v;
}
}
this.load_subcontrols();
_ref3 = this.controls;
for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) {
control = _ref3[_k];
if (control != null) {
control.initialize();
}
}
}
};