From b1cf6304439a4aa64976f62605ec184d8d8b4afb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Severin=20M=C3=BCnger?= Date: Fri, 13 Sep 2013 00:28:37 +0200 Subject: [PATCH] New Control structure --- .../webcontrol/grid/wsf_grid_control.e | 4 +- .../webcontrol/input/wsf_checkbox_control.e | 2 +- .../input/wsf_checkbox_list_control.e | 7 +- .../webcontrol/input/wsf_input_control.e | 2 +- .../wsf_html/webcontrol/wsf_button_control.e | 2 +- .../server/wsf_html/webcontrol/wsf_control.e | 55 +-------- .../webcontrol/wsf_form_element_control.e | 2 +- .../wsf_html/webcontrol/wsf_html_control.e | 2 +- .../wsf_html/webcontrol/wsf_multi_control.e | 15 ++- .../wsf_html/webcontrol/wsf_navbar_control.e | 112 ++++++++++++++++++ .../wsf_html/webcontrol/wsf_page_control.e | 2 +- .../webcontrol/wsf_stateless_control.e | 67 +++++++++++ .../webcontrol/wsf_stateless_multi_control.e | 50 ++++++++ 13 files changed, 255 insertions(+), 67 deletions(-) create mode 100644 library/server/wsf_html/webcontrol/wsf_navbar_control.e create mode 100644 library/server/wsf_html/webcontrol/wsf_stateless_control.e create mode 100644 library/server/wsf_html/webcontrol/wsf_stateless_multi_control.e diff --git a/library/server/wsf_html/webcontrol/grid/wsf_grid_control.e b/library/server/wsf_html/webcontrol/grid/wsf_grid_control.e index 253cbaca..6492cb6d 100644 --- a/library/server/wsf_html/webcontrol/grid/wsf_grid_control.e +++ b/library/server/wsf_html/webcontrol/grid/wsf_grid_control.e @@ -18,7 +18,7 @@ feature {NONE} make_grid (n: STRING; a_columns: ITERABLE [WSF_GRID_COLUMN]; a_datasource: WSF_DATASOURCE [G]) do - make (n, "div") + make_control (n, "div") columns := a_columns datasource := a_datasource end @@ -79,7 +79,7 @@ feature -- Implementation end Result.append (render_tag_with_tagname ("tr", row, "", "")) end - Result :=render_tag_with_tagname ("tbody", Result, "", "") + Result := render_tag_with_tagname ("tbody", Result, "", "") end render: STRING diff --git a/library/server/wsf_html/webcontrol/input/wsf_checkbox_control.e b/library/server/wsf_html/webcontrol/input/wsf_checkbox_control.e index cf8957c9..d5fd307f 100644 --- a/library/server/wsf_html/webcontrol/input/wsf_checkbox_control.e +++ b/library/server/wsf_html/webcontrol/input/wsf_checkbox_control.e @@ -18,7 +18,7 @@ feature {NONE} make_checkbox (n: STRING; l: STRING; c: STRING) do - make (n, "input") + make_control (n, "input") label := l checked_value := c end diff --git a/library/server/wsf_html/webcontrol/input/wsf_checkbox_list_control.e b/library/server/wsf_html/webcontrol/input/wsf_checkbox_list_control.e index 2c6cadd2..34b7d36e 100644 --- a/library/server/wsf_html/webcontrol/input/wsf_checkbox_list_control.e +++ b/library/server/wsf_html/webcontrol/input/wsf_checkbox_list_control.e @@ -31,18 +31,15 @@ feature {NONE} feature value: LIST [STRING] - local - l: LINKED_LIST [STRING] do - create l.make + create {LINKED_LIST [STRING]} Result.make across controls as c loop if c.item.value then - l.extend (c.item.checked_value) + Result.extend (c.item.checked_value) end end - Result := l end end diff --git a/library/server/wsf_html/webcontrol/input/wsf_input_control.e b/library/server/wsf_html/webcontrol/input/wsf_input_control.e index 0499a1d9..731d55e6 100644 --- a/library/server/wsf_html/webcontrol/input/wsf_input_control.e +++ b/library/server/wsf_html/webcontrol/input/wsf_input_control.e @@ -18,7 +18,7 @@ feature {NONE} make_input (n: STRING; v: STRING) do - make (n, "input") + make_control (n, "input") type := "text" text := v end diff --git a/library/server/wsf_html/webcontrol/wsf_button_control.e b/library/server/wsf_html/webcontrol/wsf_button_control.e index cfd5ec05..b4aab2ed 100644 --- a/library/server/wsf_html/webcontrol/wsf_button_control.e +++ b/library/server/wsf_html/webcontrol/wsf_button_control.e @@ -18,7 +18,7 @@ feature {NONE} make_button (n: STRING; t: STRING) do - make (n, "button") + make_control (n, "button") add_class ("btn") add_class ("btn-default") text := t diff --git a/library/server/wsf_html/webcontrol/wsf_control.e b/library/server/wsf_html/webcontrol/wsf_control.e index b4b8f454..c4a4b80e 100644 --- a/library/server/wsf_html/webcontrol/wsf_control.e +++ b/library/server/wsf_html/webcontrol/wsf_control.e @@ -7,25 +7,23 @@ note deferred class WSF_CONTROL +inherit + + WSF_STATELESS_CONTROL + feature control_name: STRING - tag_name: STRING - - css_classes: LINKED_LIST [STRING] - feature {NONE} - make (n, a_tag_name: STRING) + make_control (n, a_tag_name: STRING) do + make (a_tag_name) control_name := n - tag_name := a_tag_name - create css_classes.make create state_changes.make ensure attached state_changes - attached css_classes end feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT @@ -71,45 +69,4 @@ feature --EVENT HANDLING deferred end -feature - - add_class (c: STRING) - do - css_classes.extend (c) - end - - render_tag (body, attributes: STRING): STRING - local - css_classes_string: STRING - do - css_classes_string := "" - across - css_classes as c - loop - css_classes_string := css_classes_string + " " + c.item - end - Result := render_tag_with_tagname (tag_name, body, attributes, css_classes_string) - end - - render_tag_with_tagname (tag, body, attributes, css_classes_string: STRING): STRING - local - l_attributes: STRING - do - l_attributes := attributes - if not css_classes_string.is_empty then - l_attributes := l_attributes + " class=%"" + css_classes_string + "%"" - end - Result := "<" + tag + " id=%"" + control_name + "%" data-name=%"" + control_name + "%" data-type=%"" + generator + "%" " + l_attributes - if body.is_empty and not tag.is_equal ("textarea") then - Result := Result + " />" - else - Result := Result + " >" + body + "" - end - end - - render: STRING - -- Return html representaion of control - deferred - end - end 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 3fbf7d98..a57f6403 100644 --- a/library/server/wsf_html/webcontrol/wsf_form_element_control.e +++ b/library/server/wsf_html/webcontrol/wsf_form_element_control.e @@ -33,7 +33,7 @@ feature {NONE} 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_control (c.control_name + "_container", "div") add_class ("form-group") if attached {WSF_INPUT_CONTROL} c or attached {WSF_TEXTAREA_CONTROL} c then c.add_class ("form-control") diff --git a/library/server/wsf_html/webcontrol/wsf_html_control.e b/library/server/wsf_html/webcontrol/wsf_html_control.e index 0df4ebf6..c8a1ec88 100644 --- a/library/server/wsf_html/webcontrol/wsf_html_control.e +++ b/library/server/wsf_html/webcontrol/wsf_html_control.e @@ -18,7 +18,7 @@ feature {NONE} make_html (n,t,v: STRING) do - make (n, t) + make_control (n, t) html := v end diff --git a/library/server/wsf_html/webcontrol/wsf_multi_control.e b/library/server/wsf_html/webcontrol/wsf_multi_control.e index be5c952c..3f11a0d4 100644 --- a/library/server/wsf_html/webcontrol/wsf_multi_control.e +++ b/library/server/wsf_html/webcontrol/wsf_multi_control.e @@ -17,15 +17,18 @@ inherit end create - make_multi_control + make_multi_control, make_with_tag_name -feature {NONE} - - controls: LINKED_LIST [G] +feature {NONE} -- Initialization make_multi_control (n: STRING) do - make (n, "div") + make_with_tag_name(n, "div") + end + + make_with_tag_name (n, t: STRING) + do + make_control (n, t) controls := create {LINKED_LIST [G]}.make; end @@ -112,4 +115,6 @@ feature controls.put_front (c) end + controls: LINKED_LIST [G] + end diff --git a/library/server/wsf_html/webcontrol/wsf_navbar_control.e b/library/server/wsf_html/webcontrol/wsf_navbar_control.e new file mode 100644 index 00000000..9e78df94 --- /dev/null +++ b/library/server/wsf_html/webcontrol/wsf_navbar_control.e @@ -0,0 +1,112 @@ +note + description: "Summary description for {WSF_NAVBAR_CONTROL}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + WSF_NAVBAR_CONTROL + +inherit + + WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL] + +create + make_navbar + +feature + + collapse: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL] + nav: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL] + + + +feature {NONE} -- Initialization + + make_navbar(brand:STRING) + local + container: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL] + header: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL] + do + make_multi_control + add_class ("navbar navbar-inverse navbar-fixed-top") + create header.make_multi_control + create nav.make_multi_control + create collapse.make_multi_control + add_control (header) + header.add_class ("navbar-header") + -- + end + +end diff --git a/library/server/wsf_html/webcontrol/wsf_page_control.e b/library/server/wsf_html/webcontrol/wsf_page_control.e index 846069b7..89ae201c 100644 --- a/library/server/wsf_html/webcontrol/wsf_page_control.e +++ b/library/server/wsf_html/webcontrol/wsf_page_control.e @@ -76,7 +76,7 @@ feature do create states.make control.read_state (states) - data := "" + data := "" data.append ("") data.append ("") data.append ("") diff --git a/library/server/wsf_html/webcontrol/wsf_stateless_control.e b/library/server/wsf_html/webcontrol/wsf_stateless_control.e new file mode 100644 index 00000000..29a89d59 --- /dev/null +++ b/library/server/wsf_html/webcontrol/wsf_stateless_control.e @@ -0,0 +1,67 @@ +note + description: "Summary description for {WSF_STATELESS_CONTROL}." + author: "" + date: "$Date$" + revision: "$Revision$" + +deferred class + WSF_STATELESS_CONTROL + +feature + + tag_name: STRING + + css_classes: LINKED_LIST [STRING] + +feature {NONE} + + make (a_tag_name: STRING) + do + tag_name := a_tag_name + create css_classes.make + ensure + attached css_classes + end + +feature + + add_class (c: STRING) + do + css_classes.extend (c) + end + + render_tag (body, attributes: STRING): STRING + local + css_classes_string: STRING + do + css_classes_string := "" + across + css_classes as c + loop + css_classes_string := css_classes_string + " " + c.item + end + Result := render_tag_with_tagname (tag_name, body, attributes, css_classes_string) + end + + render_tag_with_tagname (tag, body, attributes, css_classes_string: STRING): STRING + local + l_attributes: STRING + do + l_attributes := attributes + if not css_classes_string.is_empty then + l_attributes := l_attributes + " class=%"" + css_classes_string + "%"" + end + Result := "<" + tag + l_attributes + if body.is_empty and not tag.is_equal ("textarea") then + Result := Result + " />" + else + Result := Result + " >" + body + "" + end + end + + render: STRING + -- Return html representaion of control + deferred + end + +end diff --git a/library/server/wsf_html/webcontrol/wsf_stateless_multi_control.e b/library/server/wsf_html/webcontrol/wsf_stateless_multi_control.e new file mode 100644 index 00000000..6f8c6ea1 --- /dev/null +++ b/library/server/wsf_html/webcontrol/wsf_stateless_multi_control.e @@ -0,0 +1,50 @@ +note + description: "Summary description for {WSF_STATELESS_MULTI_CONTROL}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + WSF_STATELESS_MULTI_CONTROL [G -> WSF_STATELESS_CONTROL] + +inherit + + WSF_STATELESS_CONTROL + +create + make_multi_control, make_with_tag_name + +feature {NONE} -- Initialization + + make_multi_control + do + make_with_tag_name ("div") + end + + make_with_tag_name (t: STRING) + do + make (t) + controls := create {LINKED_LIST [G]}.make; + end + +feature + + render: STRING + do + Result := "" + across + controls as c + loop + Result := c.item.render + Result + end + Result := render_tag (Result, "") + end + + add_control (c: G) + do + controls.put_front (c) + end + + controls: LINKED_LIST [G] + +end