From f506d9e92559663551db645425a6430f7a63d76b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Severin=20M=C3=BCnger?= Date: Thu, 5 Sep 2013 17:16:56 +0200 Subject: [PATCH] Implemented WSF_CHECKBOX_CONTROL, added id attribute to rendering of WSF_CONTROL --- .../wsf_html/webcontrol/wsf_button_control.e | 2 +- .../webcontrol/wsf_checkbox_control.e | 83 +++++++++++++++++++ .../server/wsf_html/webcontrol/wsf_control.e | 2 +- .../webcontrol/wsf_form_element_control.e | 9 +- .../wsf_html/webcontrol/wsf_text_control.e | 4 +- .../webcontrol/wsf_textarea_control.e | 5 +- 6 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 library/server/wsf_html/webcontrol/wsf_checkbox_control.e diff --git a/library/server/wsf_html/webcontrol/wsf_button_control.e b/library/server/wsf_html/webcontrol/wsf_button_control.e index a1f4958a..2e9a901d 100644 --- a/library/server/wsf_html/webcontrol/wsf_button_control.e +++ b/library/server/wsf_html/webcontrol/wsf_button_control.e @@ -59,7 +59,7 @@ feature render: STRING do - Result := render_tag ( text, "") + Result := render_tag (text, "") end set_text (t: STRING) diff --git a/library/server/wsf_html/webcontrol/wsf_checkbox_control.e b/library/server/wsf_html/webcontrol/wsf_checkbox_control.e new file mode 100644 index 00000000..91c67778 --- /dev/null +++ b/library/server/wsf_html/webcontrol/wsf_checkbox_control.e @@ -0,0 +1,83 @@ +note + description: "Summary description for {WSF_CHECKBOX_CONTROL}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + WSF_CHECKBOX_CONTROL +inherit + WSF_VALUE_CONTROL[BOOLEAN] +create + make_checkbox + +feature {NONE} + + make_checkbox (n: STRING; l: STRING) + do + make (n, "input") + label := l + end + +feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT + + set_state (new_state: JSON_OBJECT) + -- Restore text from json + do + if attached {JSON_BOOLEAN} new_state.item (create {JSON_STRING}.make_json ("checked")) as new_checked then + checked := new_checked.item + end + end + + state: JSON_OBJECT + -- Return state which contains the current text and if there is an event handle attached + do + create Result.make + Result.put (create {JSON_BOOLEAN}.make_boolean (checked), create {JSON_STRING}.make_json ("checked")) + Result.put (create {JSON_BOOLEAN}.make_boolean (attached change_event), create {JSON_STRING}.make_json ("callback_change")) + end + +feature --EVENT HANDLING + + set_change_event (e: attached like change_event) + -- Set text change event handle + do + change_event := e + end + + handle_callback (cname: STRING; event: STRING) + do + if Current.control_name.is_equal (cname) and attached change_event as cevent then + if event.is_equal ("change") then + cevent.call ([]) + end + end + end + +feature -- Implementation + + render: STRING + local + attributes: STRING + do + attributes := "type=%"checkbox%"" + if checked then + attributes := attributes + " checked" + end + Result := render_tag ("", attributes) + end + + value: BOOLEAN + do + Result := checked + end + +feature + + label: STRING + + checked: BOOLEAN + + change_event: detachable PROCEDURE [ANY, TUPLE []] + +end diff --git a/library/server/wsf_html/webcontrol/wsf_control.e b/library/server/wsf_html/webcontrol/wsf_control.e index d9afa4cb..253fc87c 100644 --- a/library/server/wsf_html/webcontrol/wsf_control.e +++ b/library/server/wsf_html/webcontrol/wsf_control.e @@ -91,7 +91,7 @@ feature if not css_classes_string.is_empty then css_classes_string := " class=%"" + css_classes_string + "%"" end - Result := "<" + tag_name + " data-name=%"" + control_name + "%" data-type=%"" + generator + "%" " + attributes + css_classes_string + Result := "<" + tag_name + " id=%"" + control_name + "%" data-name=%"" + control_name + "%" data-type=%"" + generator + "%" " + attributes + css_classes_string if body.is_empty then Result := Result + " />" else diff --git a/library/server/wsf_html/webcontrol/wsf_form_element_control.e b/library/server/wsf_html/webcontrol/wsf_form_element_control.e index f18f4678..ea1bc5a9 100644 --- a/library/server/wsf_html/webcontrol/wsf_form_element_control.e +++ b/library/server/wsf_html/webcontrol/wsf_form_element_control.e @@ -12,22 +12,21 @@ inherit WSF_CONTROL create - make_form_element, - make_form_element_with_validators + make_form_element, make_form_element_with_validators feature {NONE} - make_form_element (a_label:STRING; c: WSF_VALUE_CONTROL [G]) + make_form_element (a_label: STRING; c: WSF_VALUE_CONTROL [G]) local a_validators: LINKED_LIST [WSF_VALIDATOR [G]] do create a_validators.make - make_form_element_with_validators(a_label,c,a_validators) + make_form_element_with_validators (a_label, c, a_validators) end make_form_element_with_validators (a_label: STRING; c: WSF_VALUE_CONTROL [G]; v: LINKED_LIST [WSF_VALIDATOR [G]]) do - make (c.control_name+"_container", "div") + make (c.control_name + "_container", "div") add_class ("form-group") c.add_class ("form-control") value_control := c diff --git a/library/server/wsf_html/webcontrol/wsf_text_control.e b/library/server/wsf_html/webcontrol/wsf_text_control.e index 63dc34a3..3a03340f 100644 --- a/library/server/wsf_html/webcontrol/wsf_text_control.e +++ b/library/server/wsf_html/webcontrol/wsf_text_control.e @@ -9,8 +9,6 @@ class inherit - WSF_CONTROL - WSF_VALUE_CONTROL [STRING] create @@ -63,7 +61,7 @@ feature -- Implementation render: STRING do - Result := render_tag ("", "value=%"" + text + "%"") + Result := render_tag ("", "type=%"text%" value=%"" + text + "%"") end set_text (t: STRING) diff --git a/library/server/wsf_html/webcontrol/wsf_textarea_control.e b/library/server/wsf_html/webcontrol/wsf_textarea_control.e index 1ee25a96..c447e73b 100644 --- a/library/server/wsf_html/webcontrol/wsf_textarea_control.e +++ b/library/server/wsf_html/webcontrol/wsf_textarea_control.e @@ -22,13 +22,14 @@ feature {NONE} make_textarea (n, t: STRING) do make_text (n, t) - tag_name := "textarea" + tag_name := "textarea" end + feature render: STRING do - Result :=render_tag(text,"") + Result := render_tag (text, "") end end