From 1100328fee91cec8409f5319bb97f7efb102f781 Mon Sep 17 00:00:00 2001 From: YNH Webdev Date: Sat, 28 Sep 2013 09:44:39 +0200 Subject: [PATCH] Fix load state error --- .../wsf_js_widget/kernel/grid/wsf_datasource.e | 2 +- .../kernel/grid/wsf_pagable_datasource.e | 2 +- .../kernel/grid/wsf_pagination_control.e | 2 +- .../kernel/grid/wsf_repeater_control.e | 4 ++-- .../kernel/input/wsf_checkbox_control.e | 2 +- .../kernel/input/wsf_input_control.e | 2 +- .../kernel/progressbar/wsf_progress_control.e | 2 +- .../kernel/slider/wsf_image_slider_control.e | 2 +- .../kernel/webcontrol/wsf_button_control.e | 2 +- .../kernel/webcontrol/wsf_control.e | 6 +++--- .../webcontrol/wsf_form_element_control.e | 6 +++--- .../kernel/webcontrol/wsf_html_control.e | 2 +- .../kernel/webcontrol/wsf_multi_control.e | 8 ++++---- .../kernel/webcontrol/wsf_page_control.e | 6 +++--- examples/widgetapp/assets/widget.coffee | 11 +++++++++-- examples/widgetapp/assets/widget.js | 18 ++++++++++++++---- 16 files changed, 47 insertions(+), 30 deletions(-) diff --git a/draft/library/wsf_js_widget/kernel/grid/wsf_datasource.e b/draft/library/wsf_js_widget/kernel/grid/wsf_datasource.e index 601276a1..00a4d1f3 100644 --- a/draft/library/wsf_js_widget/kernel/grid/wsf_datasource.e +++ b/draft/library/wsf_js_widget/kernel/grid/wsf_datasource.e @@ -37,7 +37,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management Result.put_boolean (sort_direction, "sort_direction") end - set_state (new_state: WSF_JSON_OBJECT) + set_state (new_state: JSON_OBJECT) -- Restore sort_column and sort_direction from json do if attached {JSON_STRING} new_state.item ("sort_column") as new_sort_column then diff --git a/draft/library/wsf_js_widget/kernel/grid/wsf_pagable_datasource.e b/draft/library/wsf_js_widget/kernel/grid/wsf_pagable_datasource.e index 64d2a9fe..8bda1722 100644 --- a/draft/library/wsf_js_widget/kernel/grid/wsf_pagable_datasource.e +++ b/draft/library/wsf_js_widget/kernel/grid/wsf_pagable_datasource.e @@ -44,7 +44,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management Result.put_integer (row_count, "row_count") end - set_state (new_state: WSF_JSON_OBJECT) + set_state (new_state: JSON_OBJECT) -- Restore page, page_size and row_count from json do Precursor (new_state) diff --git a/draft/library/wsf_js_widget/kernel/grid/wsf_pagination_control.e b/draft/library/wsf_js_widget/kernel/grid/wsf_pagination_control.e index 0023bea2..37389ee7 100644 --- a/draft/library/wsf_js_widget/kernel/grid/wsf_pagination_control.e +++ b/draft/library/wsf_js_widget/kernel/grid/wsf_pagination_control.e @@ -32,7 +32,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management create Result.make end - set_state (new_state: WSF_JSON_OBJECT) + set_state (new_state: JSON_OBJECT) -- There is no state to restore states do end diff --git a/draft/library/wsf_js_widget/kernel/grid/wsf_repeater_control.e b/draft/library/wsf_js_widget/kernel/grid/wsf_repeater_control.e index c7fcefb5..79473e6f 100644 --- a/draft/library/wsf_js_widget/kernel/grid/wsf_repeater_control.e +++ b/draft/library/wsf_js_widget/kernel/grid/wsf_repeater_control.e @@ -38,10 +38,10 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management state_changes.replace (datasource.state, "datasource") end - set_state (new_state: WSF_JSON_OBJECT) + set_state (new_state: JSON_OBJECT) -- Restore datasource state from json do - if attached {WSF_JSON_OBJECT} new_state.item ("datasource") as datasource_state then + if attached {JSON_OBJECT} new_state.item ("datasource") as datasource_state then datasource.set_state (datasource_state) end end diff --git a/draft/library/wsf_js_widget/kernel/input/wsf_checkbox_control.e b/draft/library/wsf_js_widget/kernel/input/wsf_checkbox_control.e index 45891b33..5d298e2c 100644 --- a/draft/library/wsf_js_widget/kernel/input/wsf_checkbox_control.e +++ b/draft/library/wsf_js_widget/kernel/input/wsf_checkbox_control.e @@ -26,7 +26,7 @@ feature {NONE} -- Initialization feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management - set_state (new_state: WSF_JSON_OBJECT) + set_state (new_state: JSON_OBJECT) -- Restore text from json do if attached {JSON_BOOLEAN} new_state.item ("checked") as new_checked then diff --git a/draft/library/wsf_js_widget/kernel/input/wsf_input_control.e b/draft/library/wsf_js_widget/kernel/input/wsf_input_control.e index 73243508..53f81eae 100644 --- a/draft/library/wsf_js_widget/kernel/input/wsf_input_control.e +++ b/draft/library/wsf_js_widget/kernel/input/wsf_input_control.e @@ -26,7 +26,7 @@ feature {NONE} -- Initialization feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management - set_state (new_state: WSF_JSON_OBJECT) + set_state (new_state: JSON_OBJECT) -- Restore text from json do if attached {JSON_STRING} new_state.item ("text") as new_text then diff --git a/draft/library/wsf_js_widget/kernel/progressbar/wsf_progress_control.e b/draft/library/wsf_js_widget/kernel/progressbar/wsf_progress_control.e index ff51c6d7..95208ce8 100644 --- a/draft/library/wsf_js_widget/kernel/progressbar/wsf_progress_control.e +++ b/draft/library/wsf_js_widget/kernel/progressbar/wsf_progress_control.e @@ -33,7 +33,7 @@ feature {NONE} -- Initialization feature -- State handling - set_state (new_state: WSF_JSON_OBJECT) + set_state (new_state: JSON_OBJECT) do if attached {JSON_NUMBER} new_state.item ("progress") as new_progress then progress := new_progress.item.to_integer diff --git a/draft/library/wsf_js_widget/kernel/slider/wsf_image_slider_control.e b/draft/library/wsf_js_widget/kernel/slider/wsf_image_slider_control.e index 1f3fcce7..3f2e6724 100644 --- a/draft/library/wsf_js_widget/kernel/slider/wsf_image_slider_control.e +++ b/draft/library/wsf_js_widget/kernel/slider/wsf_image_slider_control.e @@ -29,7 +29,7 @@ feature {NONE} -- Initialization feature -- State handling - set_state (new_state: WSF_JSON_OBJECT) + set_state (new_state: JSON_OBJECT) do end diff --git a/draft/library/wsf_js_widget/kernel/webcontrol/wsf_button_control.e b/draft/library/wsf_js_widget/kernel/webcontrol/wsf_button_control.e index 8dd9ba5d..a6df5542 100644 --- a/draft/library/wsf_js_widget/kernel/webcontrol/wsf_button_control.e +++ b/draft/library/wsf_js_widget/kernel/webcontrol/wsf_button_control.e @@ -27,7 +27,7 @@ feature {NONE} -- Initialization feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management - set_state (new_state: WSF_JSON_OBJECT) + set_state (new_state: JSON_OBJECT) -- Restore text from json do if attached {JSON_STRING} new_state.item ("text") as new_text then diff --git a/draft/library/wsf_js_widget/kernel/webcontrol/wsf_control.e b/draft/library/wsf_js_widget/kernel/webcontrol/wsf_control.e index 11e34cde..2ea043eb 100644 --- a/draft/library/wsf_js_widget/kernel/webcontrol/wsf_control.e +++ b/draft/library/wsf_js_widget/kernel/webcontrol/wsf_control.e @@ -62,15 +62,15 @@ feature -- Actions feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT - load_state (new_states: WSF_JSON_OBJECT) + load_state (new_states: JSON_OBJECT) -- Select state stored with `control_name` as key do - if attached {WSF_JSON_OBJECT} new_states.item ("state") as new_state_obj then + if attached {JSON_OBJECT} new_states.item ("state") as new_state_obj then set_state (new_state_obj) end end - set_state (new_state: WSF_JSON_OBJECT) + set_state (new_state: JSON_OBJECT) -- Before we process the callback. We restore the state of control. deferred end diff --git a/draft/library/wsf_js_widget/kernel/webcontrol/wsf_form_element_control.e b/draft/library/wsf_js_widget/kernel/webcontrol/wsf_form_element_control.e index 43cd1938..e18286c8 100644 --- a/draft/library/wsf_js_widget/kernel/webcontrol/wsf_form_element_control.e +++ b/draft/library/wsf_js_widget/kernel/webcontrol/wsf_form_element_control.e @@ -48,16 +48,16 @@ feature {NONE} -- Initialization feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management - load_state (new_states: WSF_JSON_OBJECT) + load_state (new_states: JSON_OBJECT) -- Pass new_states to subcontrols do Precursor (new_states) - if attached {WSF_JSON_OBJECT} new_states.item ("controls") as ct and then attached {WSF_JSON_OBJECT} ct.item (value_control.control_name) as value_state then + if attached {JSON_OBJECT} new_states.item ("controls") as ct and then attached {JSON_OBJECT} ct.item (value_control.control_name) as value_state then value_control.load_state (value_state) end end - set_state (new_state: WSF_JSON_OBJECT) + set_state (new_state: JSON_OBJECT) -- Set new state do value_control.set_state (new_state) diff --git a/draft/library/wsf_js_widget/kernel/webcontrol/wsf_html_control.e b/draft/library/wsf_js_widget/kernel/webcontrol/wsf_html_control.e index 2637a182..b272861f 100644 --- a/draft/library/wsf_js_widget/kernel/webcontrol/wsf_html_control.e +++ b/draft/library/wsf_js_widget/kernel/webcontrol/wsf_html_control.e @@ -25,7 +25,7 @@ feature {NONE} -- Initialization feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management - set_state (new_state: WSF_JSON_OBJECT) + set_state (new_state: JSON_OBJECT) -- Restore html from json do if attached {JSON_STRING} new_state.item ("html") as new_html then diff --git a/draft/library/wsf_js_widget/kernel/webcontrol/wsf_multi_control.e b/draft/library/wsf_js_widget/kernel/webcontrol/wsf_multi_control.e index a86f65dc..6012a2e9 100644 --- a/draft/library/wsf_js_widget/kernel/webcontrol/wsf_multi_control.e +++ b/draft/library/wsf_js_widget/kernel/webcontrol/wsf_multi_control.e @@ -36,16 +36,16 @@ feature {NONE} -- Initialization feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management - load_state (new_states: WSF_JSON_OBJECT) + load_state (new_states: JSON_OBJECT) -- Pass new_states to subcontrols do Precursor (new_states) - if attached {WSF_JSON_OBJECT} new_states.item ("controls") as ct then + if attached {JSON_OBJECT} new_states.item ("controls") as ct then across controls as c loop if attached {WSF_CONTROL} c.item as cont then - if attached {WSF_JSON_OBJECT} ct.item (cont.control_name) as value_state then + if attached {JSON_OBJECT} ct.item (cont.control_name) as value_state then cont.load_state (value_state) end end @@ -53,7 +53,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management end end - set_state (new_state: WSF_JSON_OBJECT) + set_state (new_state: JSON_OBJECT) -- Before we process the callback. We restore the state of control. do end diff --git a/draft/library/wsf_js_widget/kernel/webcontrol/wsf_page_control.e b/draft/library/wsf_js_widget/kernel/webcontrol/wsf_page_control.e index 1bd2233c..0b98fbb9 100644 --- a/draft/library/wsf_js_widget/kernel/webcontrol/wsf_page_control.e +++ b/draft/library/wsf_js_widget/kernel/webcontrol/wsf_page_control.e @@ -70,7 +70,7 @@ feature -- Implementation create states.make_empty request.read_input_data_into (states) create json_parser.make_parser (states) - if attached {WSF_JSON_OBJECT} json_parser.parse_json as sp then + if attached {JSON_OBJECT} json_parser.parse_json as sp then set_state (sp) end handle_callback (event_control_name, event, event_parameter) @@ -161,9 +161,9 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management Result.put_string (request.query_string, "url_params") end - set_state (sp: WSF_JSON_OBJECT) + set_state (sp: JSON_OBJECT) do - if attached {WSF_JSON_OBJECT} sp.item ("controls") as ct and then attached {WSF_JSON_OBJECT} ct.item (control.control_name) as value_state then + if attached {JSON_OBJECT} sp.item ("controls") as ct and then attached {JSON_OBJECT} ct.item (control.control_name) as value_state then control.load_state (value_state) end end diff --git a/examples/widgetapp/assets/widget.coffee b/examples/widgetapp/assets/widget.coffee index 36ecbc57..489d7814 100644 --- a/examples/widgetapp/assets/widget.coffee +++ b/examples/widgetapp/assets/widget.coffee @@ -31,10 +31,12 @@ Mini = { render:template(t) } +loaded = {} lazy_load = (requirements,fn,that)-> if not that? that = window return ()-> + a = arguments if not args? args = [] counter = requirements.length + 1 @@ -42,10 +44,15 @@ lazy_load = (requirements,fn,that)-> done = ()-> counter = counter - 1 if counter == 0 - fn.apply(that,arguments) + fn.apply(that,a) return for r in requirements - $.cachedScript(r).done(done) + if loaded[r]? + done() + else + $.cachedScript(r).done ()-> + done() + loaded[r] = true done() build_control = (control_name, state, control)-> diff --git a/examples/widgetapp/assets/widget.js b/examples/widgetapp/assets/widget.js index b1e35bb3..c85c23a5 100644 --- a/examples/widgetapp/assets/widget.js +++ b/examples/widgetapp/assets/widget.js @@ -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_CONTROL, WSF_FORM_ELEMENT_CONTROL, WSF_GRID_CONTROL, WSF_HTML_CONTROL, WSF_INPUT_CONTROL, WSF_MAX_VALIDATOR, WSF_MIN_VALIDATOR, WSF_PAGE_CONTROL, WSF_PAGINATION_CONTROL, WSF_PROGRESS_CONTROL, WSF_REGEXP_VALIDATOR, WSF_REPEATER_CONTROL, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, build_control, cache, controls, lazy_load, show_alert, start_modal, template, tmpl, +var Mini, WSF_AUTOCOMPLETE_CONTROL, WSF_BUTTON_CONTROL, WSF_CHECKBOX_CONTROL, WSF_CHECKBOX_LIST_CONTROL, WSF_CONTROL, WSF_FORM_ELEMENT_CONTROL, WSF_GRID_CONTROL, WSF_HTML_CONTROL, WSF_INPUT_CONTROL, WSF_MAX_VALIDATOR, WSF_MIN_VALIDATOR, WSF_PAGE_CONTROL, WSF_PAGINATION_CONTROL, WSF_PROGRESS_CONTROL, WSF_REGEXP_VALIDATOR, WSF_REPEATER_CONTROL, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, build_control, cache, controls, lazy_load, loaded, show_alert, start_modal, 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; }; @@ -49,12 +49,15 @@ Mini = { } }; +loaded = {}; + lazy_load = function(requirements, fn, that) { if (that == null) { that = window; } return function() { - var args, counter, done, r, self, _i, _len; + var a, args, counter, done, r, self, _i, _len; + a = arguments; if (typeof args === "undefined" || args === null) { args = []; } @@ -63,12 +66,19 @@ lazy_load = function(requirements, fn, that) { done = function() { counter = counter - 1; if (counter === 0) { - fn.apply(that, arguments); + fn.apply(that, a); } }; for (_i = 0, _len = requirements.length; _i < _len; _i++) { r = requirements[_i]; - $.cachedScript(r).done(done); + if (loaded[r] != null) { + done(); + } else { + $.cachedScript(r).done(function() { + done(); + return loaded[r] = true; + }); + } } return done(); };