From 72e74938423427bea35f554f54a10c344e79566f Mon Sep 17 00:00:00 2001 From: YNH Webdev Date: Sun, 10 Nov 2013 16:39:04 +0100 Subject: [PATCH] Fix event handler --- .../kernel/validator/wsf_agent_validator.e | 32 +++++++++++++++++++ .../webcontrol/wsf_form_element_control.e | 17 ++++++---- .../kernel/webcontrol/wsf_multi_control.e | 18 +++++++---- .../webcontrol/wsf_stateless_multi_control.e | 3 ++ examples/widgetapp/assets/widget.coffee | 2 ++ examples/widgetapp/assets/widget.js | 14 +++++++- 6 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 draft/library/wsf_js_widget/kernel/validator/wsf_agent_validator.e diff --git a/draft/library/wsf_js_widget/kernel/validator/wsf_agent_validator.e b/draft/library/wsf_js_widget/kernel/validator/wsf_agent_validator.e new file mode 100644 index 00000000..8aa58fda --- /dev/null +++ b/draft/library/wsf_js_widget/kernel/validator/wsf_agent_validator.e @@ -0,0 +1,32 @@ +note + description: "Summary description for {WSF_AGENT_VALIDATOR}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + WSF_AGENT_VALIDATOR [G] +inherit + WSF_VALIDATOR [G] +create + make_with_agent + +feature {NONE} -- Initialization + + make_with_agent (h:like handler; e: STRING) + do + make (e) + handler := h + end + +feature + + is_valid (input: G): BOOLEAN + do + + Result := handler.item ( [input]) + end + + + handler: FUNCTION[ANY,TUPLE[G],BOOLEAN] +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 d99333d6..ee76d77a 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 @@ -84,8 +84,8 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management Precursor (states) create sub_states.make value_control.read_state_changes (sub_states) - if sub_states.count>0 then - if attached {JSON_OBJECT}states.item (control_name) as changes then + if sub_states.count > 0 then + if attached {JSON_OBJECT} states.item (control_name) as changes then changes.put (sub_states, "controls") else create control_state.make @@ -113,16 +113,19 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management feature -- Event handling - handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable STRING) + handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable STRING) -- Pass callback to subcontrols do - if cname[1].same_string (control_name) then + if cname [1].same_string (control_name) then cname.go_i_th (1) cname.remove - if event.same_string ("validate") then - validate + if cname.is_empty then + if event.same_string ("validate") then + validate + end + else + value_control.handle_callback (cname, event, event_parameter) end - value_control.handle_callback (cname, event, event_parameter) end end 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 33aec384..bf5ad890 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 @@ -100,8 +100,8 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management Precursor (states) create sub_states.make read_subcontrol_state_changes (sub_states) - if sub_states.count>0 then - if attached {JSON_OBJECT}states.item (control_name) as changes then + if sub_states.count > 0 then + if attached {JSON_OBJECT} states.item (control_name) as changes then changes.put (sub_states, "controls") else create control_state.make @@ -138,11 +138,15 @@ feature -- Event handling if equal (cname [1], control_name) then cname.go_i_th (1) cname.remove - across - controls as c - loop - if attached {WSF_CONTROL} c.item as cont then - cont.handle_callback (cname, event, event_parameter) + if not cname.is_empty then + across + controls as c + until + cname.is_empty + loop + if attached {WSF_CONTROL} c.item as cont then + cont.handle_callback (cname, event, event_parameter) + end end end end diff --git a/draft/library/wsf_js_widget/kernel/webcontrol/wsf_stateless_multi_control.e b/draft/library/wsf_js_widget/kernel/webcontrol/wsf_stateless_multi_control.e index 8ce9321e..7dba1109 100644 --- a/draft/library/wsf_js_widget/kernel/webcontrol/wsf_stateless_multi_control.e +++ b/draft/library/wsf_js_widget/kernel/webcontrol/wsf_stateless_multi_control.e @@ -1,3 +1,4 @@ + note description: "Summary description for {WSF_STATELESS_MULTI_CONTROL}." author: "" @@ -80,6 +81,8 @@ feature -- Event handling do across controls as c + until + cname.is_empty loop if attached {WSF_CONTROL} c.item as cont then cont.handle_callback (cname, event, event_parameter) diff --git a/examples/widgetapp/assets/widget.coffee b/examples/widgetapp/assets/widget.coffee index 6c362ab0..0c0195dc 100644 --- a/examples/widgetapp/assets/widget.coffee +++ b/examples/widgetapp/assets/widget.coffee @@ -360,6 +360,8 @@ class WSF_INPUT_CONTROL extends WSF_CONTROL @state['text'] = state.text @$el.val(state.text) +class WSF_PASSWORD_CONTROL extends WSF_INPUT_CONTROL + class WSF_NAVLIST_ITEM_CONTROL extends WSF_BUTTON_CONTROL update: (state) -> super diff --git a/examples/widgetapp/assets/widget.js b/examples/widgetapp/assets/widget.js index 3eb2c515..2a1ab483 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_CODEVIEW_CONTROL, WSF_CONTROL, WSF_DROPDOWN_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_PROGRESS_CONTROL, WSF_REGEXP_VALIDATOR, WSF_REPEATER_CONTROL, WSF_SLIDER_CONTROL, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, build_control, cache, controls, lazy_load, loaded, parseSuggestions, 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_DROPDOWN_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, 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; }; @@ -596,6 +596,18 @@ WSF_INPUT_CONTROL = (function(_super) { })(WSF_CONTROL); +WSF_PASSWORD_CONTROL = (function(_super) { + + __extends(WSF_PASSWORD_CONTROL, _super); + + function WSF_PASSWORD_CONTROL() { + return WSF_PASSWORD_CONTROL.__super__.constructor.apply(this, arguments); + } + + return WSF_PASSWORD_CONTROL; + +})(WSF_INPUT_CONTROL); + WSF_NAVLIST_ITEM_CONTROL = (function(_super) { __extends(WSF_NAVLIST_ITEM_CONTROL, _super);