Add stateless widgets

This commit is contained in:
YNH Webdev
2013-11-06 15:44:31 +01:00
parent 6838089570
commit c9102af0aa
8 changed files with 78 additions and 29 deletions

View File

@@ -9,7 +9,7 @@ class
inherit inherit
WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL] WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
rename rename
make as make_multi_control, make as make_multi_control,
make_with_tag_name as make_multi_control_with_tag_name make_with_tag_name as make_multi_control_with_tag_name
@@ -20,19 +20,19 @@ create
feature {NONE} -- Initialization feature {NONE} -- Initialization
make (n, title: STRING) make ( title: STRING)
-- Make a dropdown control with div tag name and specified menu title -- Make a dropdown control with div tag name and specified menu title
do do
make_with_tag_name (n, title, "div") make_with_tag_name ( title, "div")
end end
make_with_tag_name (n, title, t: STRING) make_with_tag_name ( title, t: STRING)
-- Make a dropdown control with specified tag name and menu title (such as li) -- Make a dropdown control with specified tag name and menu title (such as li)
do do
make_multi_control_with_tag_name (n, t) make_multi_control_with_tag_name ( t)
add_class ("dropdown") add_class ("dropdown")
create {WSF_BASIC_CONTROL} dropdown_toggle.make_with_body_class ("a", "data-toggle=%"dropdown%" href=%"#%"", "dropdown-toggle", title + " <strong class=%"caret%"></strong>") create {WSF_BASIC_CONTROL} dropdown_toggle.make_with_body_class ("a", "data-toggle=%"dropdown%" href=%"#%"", "dropdown-toggle", title + " <strong class=%"caret%"></strong>")
create dropdown_menu.make_with_tag_name (n + "_menu", "ul") create dropdown_menu.make_with_tag_name ( "ul")
dropdown_menu.add_class ("dropdown-menu") dropdown_menu.add_class ("dropdown-menu")
add_control (dropdown_toggle) add_control (dropdown_toggle)
add_control (dropdown_menu) add_control (dropdown_menu)
@@ -66,6 +66,6 @@ feature -- Properties
dropdown_toggle: WSF_STATELESS_CONTROL dropdown_toggle: WSF_STATELESS_CONTROL
dropdown_menu: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL] dropdown_menu: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
end end

View File

@@ -27,8 +27,8 @@ feature {NONE} -- Initialization
make_multi_control (n) make_multi_control (n)
active_set := false active_set := false
add_class ("navbar navbar-inverse navbar-fixed-top") add_class ("navbar navbar-inverse navbar-fixed-top")
create nav.make_with_tag_name (control_name + "_nav", "ul") create nav.make_with_tag_name ("ul")
create nav_right.make_with_tag_name (control_name + "_nav_right", "ul") create nav_right.make_with_tag_name ( "ul")
controls.extend (nav) controls.extend (nav)
controls.extend (nav_right) controls.extend (nav_right)
nav.add_class ("nav navbar-nav") nav.add_class ("nav navbar-nav")
@@ -155,10 +155,10 @@ feature -- Properties
brand: detachable STRING brand: detachable STRING
-- Optional brand of the navbar -- Optional brand of the navbar
nav: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL] nav: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
-- Middle nav -- Middle nav
nav_right: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL] nav_right: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
-- Right nav -- Right nav
end end

View File

@@ -24,9 +24,9 @@ feature {NONE} -- Initialization
do do
make_control (n, "div") make_control (n, "div")
add_class ("carousel slide") add_class ("carousel slide")
create list.make_with_tag_name (control_name + "_links", "ol") create list.make_with_tag_name ( "ol")
list.add_class ("carousel-indicators") list.add_class ("carousel-indicators")
create slide_wrapper.make (control_name + "_wrapper") create slide_wrapper.make_with_tag_name ("div")
slide_wrapper.add_class ("carousel-inner") slide_wrapper.add_class ("carousel-inner")
end end
@@ -108,10 +108,10 @@ feature -- Change
feature -- Properties feature -- Properties
list: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL] list: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
-- List of slider links -- List of slider links
slide_wrapper: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL] slide_wrapper: WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
-- List of the single slides -- List of the single slides
end end

View File

@@ -9,7 +9,7 @@ class
inherit inherit
WSF_MULTI_CONTROL [WSF_CONTROL] WSF_STATELESS_MULTI_CONTROL [WSF_CONTROL]
rename rename
make as make_multi_control make as make_multi_control
end end

View File

@@ -9,7 +9,7 @@ class
inherit inherit
WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL] WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
rename rename
make as make_multi_control, make as make_multi_control,
add_control as add_control_raw add_control as add_control_raw
@@ -22,7 +22,7 @@ feature {NONE} -- Initialization
make (n: STRING) make (n: STRING)
do do
make_with_tag_name (n, "div") make_with_tag_name ("div")
add_class ("row") add_class ("row")
end end

View File

@@ -43,17 +43,24 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
do do
Precursor (new_states) Precursor (new_states)
if attached {JSON_OBJECT} new_states.item ("controls") as ct then if attached {JSON_OBJECT} new_states.item ("controls") as ct then
load_subcontrol_state (ct)
end
end
load_subcontrol_state (newstate: JSON_OBJECT)
do
across across
controls as c controls as c
loop loop
if attached {WSF_CONTROL} c.item as cont then if attached {WSF_STATELESS_MULTI_CONTROL[WSF_STATELESS_CONTROL]} c.item as cont then
if attached {JSON_OBJECT} ct.item (cont.control_name) as value_state then cont.load_subcontrol_state (newstate)
elseif attached {WSF_CONTROL} c.item as cont then
if attached {JSON_OBJECT} newstate.item (cont.control_name) as value_state then
cont.load_state (value_state) cont.load_state (value_state)
end end
end end
end end
end end
end
set_state (new_state: JSON_OBJECT) set_state (new_state: JSON_OBJECT)
-- Before we process the callback. We restore the state of control. -- Before we process the callback. We restore the state of control.
@@ -67,14 +74,21 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
do do
Result := Precursor Result := Precursor
create controls_state.make create controls_state.make
read_subcontrol_state (controls_state)
Result.put (controls_state, "controls")
end
read_subcontrol_state (controls_state: JSON_OBJECT)
do
across across
controls as c controls as c
loop loop
if attached {WSF_CONTROL} c.item as cont then if attached {WSF_STATELESS_MULTI_CONTROL[WSF_STATELESS_CONTROL]} c.item as mcont then
mcont.read_subcontrol_state (controls_state)
elseif attached {WSF_CONTROL} c.item as cont then
controls_state.put (cont.full_state, cont.control_name) controls_state.put (cont.full_state, cont.control_name)
end end
end end
Result.put (controls_state, "controls")
end end
read_state_changes (states: WSF_JSON_OBJECT) read_state_changes (states: WSF_JSON_OBJECT)
@@ -124,8 +138,10 @@ feature -- Rendering
loop loop
Result := Result + c.item.render Result := Result + c.item.render
end end
if not tag_name.is_empty then
Result := render_tag (Result, "") Result := render_tag (Result, "")
end end
end
feature -- Change feature -- Change
@@ -137,6 +153,8 @@ feature -- Change
feature -- Properties feature -- Properties
stateless: BOOLEAN
controls: ARRAYED_LIST [G] controls: ARRAYED_LIST [G]
-- List of current controls in this multi control -- List of current controls in this multi control

View File

@@ -0,0 +1,31 @@
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_MULTI_CONTROL [G]
rename
make_with_tag_name as make_with_tag_name_and_name
end
create
make_with_tag_name, make_tag_less
feature {NONE} -- Initialization
make_with_tag_name(t:STRING)
do
make_with_tag_name_and_name("",t)
end
make_tag_less
do
make_with_tag_name_and_name ("", "")
stateless := True
end
end

View File

@@ -23,7 +23,7 @@ feature
do do
create control.make ("container") create control.make ("container")
control.add_class ("container") control.add_class ("container")
create dropdown.make_with_tag_name ("mydropdown", "Dropdown", "li") create dropdown.make_with_tag_name ( "Dropdown", "li")
dropdown.add_link_item ("Example link 1", "#") dropdown.add_link_item ("Example link 1", "#")
dropdown.add_divider dropdown.add_divider
dropdown.add_link_item ("Example link 2", "#") dropdown.add_link_item ("Example link 2", "#")