Merge branch 'widget' of github.com:souvarin/EWF into widget

This commit is contained in:
YNH Webdev
2013-09-24 15:20:43 +02:00
48 changed files with 204 additions and 123 deletions

View File

@@ -0,0 +1,20 @@
note
description: "Summary description for {WSF_AUTOCOMPLETION}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_AUTOCOMPLETION
feature -- Access
autocompletion (input: STRING): JSON_ARRAY
-- JSON array of suggestions that fit the specific input
deferred
end
template: detachable STRING
-- Customizable template
end

View File

@@ -0,0 +1,47 @@
note
description: "Summary description for {WSF_SIMPLE_AUTOCOMPLETION}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_SIMPLE_AUTOCOMPLETION
inherit
WSF_AUTOCOMPLETION
create
make
feature {NONE} -- Initialization
make (l: ITERABLE [STRING])
-- Initialize
do
list := l
end
feature -- Implementation
autocompletion (input: STRING): JSON_ARRAY
-- Implementation
local
o: JSON_OBJECT
do
create Result.make_array
across
list as c
loop
if c.item.as_lower.has_substring (input.as_lower) then
create o.make
o.put (create {JSON_STRING}.make_json (c.item), "value")
Result.add (o)
end
end
end
list: ITERABLE [STRING]
-- List containing suggestions
end

View File

@@ -0,0 +1,79 @@
note
description: "Summary description for {WSF_DATASOURCE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_DATASOURCE [G -> WSF_ENTITY]
feature --Event handling
set_on_update_agent (f: PROCEDURE [ANY, TUPLE])
--Set update listener
do
on_update_agent := f
end
update
--Trigger update listener
do
if attached on_update_agent as a then
a.call (Void)
end
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
state: JSON_OBJECT
-- Return state which contains the current sort_column and sort_direction
do
create Result.make
if attached sort_column as a_sort_column then
Result.put (create {JSON_STRING}.make_json (a_sort_column), "sort_column")
else
Result.put (create {JSON_NULL}, "sort_column")
end
Result.put (create {JSON_BOOLEAN}.make_boolean (sort_direction), "sort_direction")
end
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
sort_column := new_sort_column.unescaped_string_32 -- Implicit Conversion !
elseif attached {JSON_NULL} new_state.item ("sort_column") as new_sort_column then
sort_column := Void
end
if attached {JSON_BOOLEAN} new_state.item ("sort_direction") as new_sort_direction then
sort_direction := new_sort_direction.item
end
end
feature -- Change
set_sort_column (a_sort_column: like sort_column)
-- Set the column by which the data should be sorted
do
sort_column := a_sort_column
end
set_sort_direction (a_sort_direction: like sort_direction)
-- Set the sorting direction
do
sort_direction := a_sort_direction
end
feature -- Properties
sort_column: detachable STRING
sort_direction: BOOLEAN
data: ITERABLE [G]
deferred
end
on_update_agent: detachable PROCEDURE [ANY, TUPLE]
end

View File

@@ -0,0 +1,16 @@
note
description: "Summary description for {WSF_ENTITY}."
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_ENTITY
feature -- Access
item (a_field: READABLE_STRING_GENERAL): detachable ANY
-- Value for field item `a_field'.
deferred
end
end

View File

@@ -0,0 +1,44 @@
note
description: "Summary description for {WSF_GRID_COLUMN}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_GRID_COLUMN
create
make
feature {NONE} -- Initialization
make (a_header, a_field: STRING)
do
header := a_header
field_name := a_field
sorting_name := a_field
end
feature -- Render
render_column (e: WSF_ENTITY): STRING
-- Return the rendered column cell for a specific entity (row)
do
if attached e.item (field_name) as data then
Result := data.out
else
Result := "[VOID]"
end
end
feature -- Properties
header: STRING
sortable: BOOLEAN
sorting_name: STRING
field_name: STRING
end

View File

@@ -0,0 +1,73 @@
note
description: "Summary description for {WSF_GRID_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_GRID_CONTROL [G -> WSF_ENTITY]
inherit
WSF_REPEATER_CONTROL [G]
redefine
render
end
create
make_grid
feature {NONE} -- Initialization
make_grid (n: STRING; a_columns: ITERABLE [WSF_GRID_COLUMN]; a_datasource: WSF_DATASOURCE [G])
do
make_repeater (n, a_datasource)
columns := a_columns
end
feature -- Render
render_item (item: G): STRING
-- Render table row
do
Result := ""
across
columns as c
loop
Result.append (render_tag_with_tagname ("td", c.item.render_column (item), "", ""))
end
Result := render_tag_with_tagname ("tr", Result, "", "")
end
render_header: STRING
-- Render table header
do
Result := ""
across
columns as c
loop
Result.append (render_tag_with_tagname ("th", c.item.header, "", ""))
end
Result := render_tag_with_tagname ("thead", render_tag_with_tagname ("tr", Result, "", ""), "", "")
end
render: STRING
-- Render entre table and subcontrols
local
table: STRING
do
table := render_tag_with_tagname ("table", render_header + render_tag_with_tagname ("tbody", render_body, "", ""), "", "table table-striped")
Result := ""
across
controls as c
loop
Result.append (c.item.render)
end
Result := render_tag (table + Result, "")
end
feature -- Properties
columns: ITERABLE [WSF_GRID_COLUMN]
end

View File

@@ -0,0 +1,41 @@
note
description: "Summary description for {WSF_GRID_IMAGE_COLUMN}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_GRID_IMAGE_COLUMN
inherit
WSF_GRID_COLUMN
rename
make as make_column
redefine
render_column
end
create
make
feature {NONE} -- Initialization
make (a_header, a_field: STRING)
do
make_column (a_header, a_field)
end
feature -- Render
render_column (e: WSF_ENTITY): STRING
-- Return the rendered column image cell for a specific entity (row)
do
if attached e.item (field_name) as data then
Result := "<img src=%"" + data.out + "%" />"
else
Result := "[VOID]"
end
end
end

View File

@@ -0,0 +1,84 @@
note
description: "Summary description for {WSF_PAGABLE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_PAGABLE_DATASOURCE [G -> WSF_ENTITY]
inherit
WSF_DATASOURCE [G]
redefine
state,
set_state,
update
end
feature --Event handling
set_on_update_page_agent (f: PROCEDURE [ANY, TUPLE])
--Set paging update listener
do
on_update_page_agent := f
end
update
--Trigger update listeners
do
Precursor
if attached on_update_page_agent as a then
a.call (Void)
end
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
state: JSON_OBJECT
-- Return state which contains the current page, page_size and row_count
do
Result := Precursor
Result.put (create {JSON_NUMBER}.make_integer (page), "page")
Result.put (create {JSON_NUMBER}.make_integer (page_size), "page_size")
Result.put (create {JSON_NUMBER}.make_integer (row_count), "row_count")
end
set_state (new_state: JSON_OBJECT)
-- Restore page, page_size and row_count from json
do
Precursor (new_state)
if attached {JSON_NUMBER} new_state.item ("page") as new_page then
page := new_page.item.to_integer
end
if attached {JSON_NUMBER} new_state.item ("page_size") as new_page_size then
page_size := new_page_size.item.to_integer
end
if attached {JSON_NUMBER} new_state.item ("row_count") as new_row_count then
row_count := new_row_count.item.to_integer
end
end
feature -- Change
set_page (p: INTEGER)
do
page := p.min (page_count).max (1)
end
feature -- Properties
page: INTEGER
page_size: INTEGER
row_count: INTEGER
page_count: INTEGER
do
Result := (row_count / page_size).ceiling
end
on_update_page_agent: detachable PROCEDURE [ANY, TUPLE]
end

View File

@@ -0,0 +1,96 @@
note
description: "Summary description for {WSF_PAGINATION}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_PAGINATION_CONTROL [G -> WSF_ENTITY]
inherit
WSF_CONTROL
create
make_paging
feature {NONE}
make_paging (n: STRING; ds: WSF_PAGABLE_DATASOURCE [G])
do
make_control (n, "ul")
add_class ("pagination")
datasource := ds
datasource.set_on_update_page_agent (agent update)
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
state: JSON_OBJECT
-- Return empty
do
create Result.make
end
set_state (new_state: JSON_OBJECT)
-- There is no state to restore states
do
end
update
-- Send new renederd control to client on update
do
state_changes.replace (create {JSON_STRING}.make_json (render), "_html")
end
feature --Event handling
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
-- Handle goto/next/prev events
do
if Current.control_name.same_string (cname) then
if event.same_string ("next") then
datasource.set_page (datasource.page + 1)
elseif event.same_string ("prev") then
datasource.set_page (datasource.page - 1)
elseif event.same_string ("goto") then
if attached event_parameter as p and then attached p.to_integer as i then
datasource.set_page (i)
end
end
datasource.update
end
end
feature -- Render
render: STRING
-- Render paging control
local
paging_start: INTEGER
paging_end: INTEGER
cssclass: STRING
do
Result := render_tag_with_tagname ("li", render_tag_with_tagname ("a", "&laquo;", "href=%"#%" data-nr=%"prev%"", ""), "", "")
paging_start := (datasource.page - 4).max (1)
paging_end := (paging_start + 8).min (datasource.page_count)
paging_start := (paging_end - 8).max (1)
across
paging_start |..| paging_end as n
loop
if n.item = datasource.page then
cssclass := "active"
else
cssclass := ""
end
Result.append (render_tag_with_tagname ("li", render_tag_with_tagname ("a", n.item.out, "href=%"#%" data-nr=%"" + n.item.out + "%"", ""), "", cssclass))
end
Result.append (render_tag_with_tagname ("li", render_tag_with_tagname ("a", "&raquo;", "href=%"#%" data-nr=%"next%"", ""), "", ""))
Result := render_tag (Result, "")
end
feature -- Properties
datasource: WSF_PAGABLE_DATASOURCE [G]
end

View File

@@ -0,0 +1,97 @@
note
description: "Summary description for {WSF_REPEATER_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_REPEATER_CONTROL [G -> WSF_ENTITY]
inherit
WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
redefine
set_state,
state,
render
end
feature {NONE} -- Initialization
make_repeater (n: STRING; a_datasource: WSF_DATASOURCE [G])
do
make_multi_control (n)
datasource := a_datasource
datasource.set_on_update_agent (agent update)
if attached {WSF_PAGABLE_DATASOURCE [G]} a_datasource as ds then
create pagination_control.make_paging (n + "_paging", ds)
add_control (pagination_control)
end
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
update
-- Send new renederd control to client on update
do
state_changes.replace (create {JSON_STRING}.make_json (render_body), "_body")
state_changes.replace (datasource.state, "datasource")
end
set_state (new_state: JSON_OBJECT)
-- Restore datasource state from json
do
if attached {JSON_OBJECT} new_state.item ("datasource") as datasource_state then
datasource.set_state (datasource_state)
end
end
state: JSON_OBJECT
-- Return state which contains the current datasource state
do
create Result.make
Result.put (datasource.state, "datasource")
end
feature -- Rendering
render_item (item: G): STRING
--Render item
deferred
end
render_body: STRING
--Render Body
do
Result := ""
across
datasource.data as entity
loop
Result.append (render_item (entity.item))
end
end
render: STRING
--Render repeater inclusive paging if paging is available
local
content: STRING
do
content := render_tag_with_tagname ("div", render_body, "", "repeater_content")
Result := ""
across
controls as c
loop
Result := c.item.render + Result
end
-- Fix generator name since the user will extend this class to define item_render
Result := render_tag_with_generator_name ("WSF_REPEATER_CONTROL", content + Result, "")
end
feature -- Properties
datasource: WSF_DATASOURCE [G]
pagination_control: detachable WSF_PAGINATION_CONTROL [G]
end

View File

@@ -0,0 +1,64 @@
note
description: "Summary description for {WSF_AUTOCOMPLETE_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_AUTOCOMPLETE_CONTROL
inherit
WSF_INPUT_CONTROL
redefine
handle_callback,
state
end
create
make_autocomplete, make_autocomplete_with_agent
feature {NONE} -- Initialization
make_autocomplete (n: STRING; c: WSF_AUTOCOMPLETION)
-- Initialize with specified name and autocompletion
do
make_autocomplete_with_agent (n, agent c.autocompletion)
if attached c.template as t then
template := t
end
end
make_autocomplete_with_agent (n: STRING; c: FUNCTION [ANY, TUPLE [STRING], JSON_ARRAY])
-- Initialize with specified name and autocompletion function
do
make_input (n, "")
create_json_list := c
template := "{{=value}}"
end
feature -- State
state: JSON_OBJECT
do
Result := Precursor {WSF_INPUT_CONTROL}
Result.put (create {JSON_STRING}.make_json (template), "template")
end
feature -- Callback
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
do
Precursor {WSF_INPUT_CONTROL} (cname, event, event_parameter)
if cname.same_string (control_name) and event.same_string ("autocomplete") then
state_changes.put (create_json_list.item ([text]), "suggestions")
end
end
feature -- Properties
create_json_list: FUNCTION [ANY, TUPLE [STRING], JSON_ARRAY]
template: STRING
end

View File

@@ -0,0 +1,95 @@
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} -- Initialization
make_checkbox (n, l, c: STRING)
-- Initialize with specified control name,
do
make_control (n, "input")
label := l
checked_value := c
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 ("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), "checked")
Result.put (create {JSON_STRING}.make_json (checked_value), "checked_value")
Result.put (create {JSON_BOOLEAN}.make_boolean (attached change_event), "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; event_parameter: detachable STRING)
do
if Current.control_name.same_string (cname) and attached change_event as cevent then
if event.same_string ("change") then
cevent.call (Void)
end
end
end
feature -- Implementation
render: STRING
local
attrs: STRING
do
attrs := "type=%"checkbox%""
if checked then
attrs := attrs + " checked"
end
Result := render_tag_with_tagname ("div", render_tag_with_tagname ("label", render_tag ("", attrs) + " " + label, "", ""), "", "checkbox")
end
value: BOOLEAN
do
Result := checked
end
feature -- Properties
label: STRING
-- The label of the checkbox control
checked: BOOLEAN
-- The checked value of the checkbox control
checked_value: STRING
-- String checked value
change_event: detachable PROCEDURE [ANY, TUPLE]
-- Function to be executed on change
end

View File

@@ -0,0 +1,46 @@
note
description: "Summary description for {WSF_CHECKBOX_LIST_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_CHECKBOX_LIST_CONTROL
inherit
WSF_VALUE_CONTROL [LIST [STRING]]
undefine
load_state,
full_state,
read_state_changes
end
WSF_MULTI_CONTROL [WSF_CHECKBOX_CONTROL]
create
make_checkbox_list_control
feature {NONE} -- Initializaton
make_checkbox_list_control (n: STRING)
-- Initialize with specified control name
do
make_multi_control (n)
end
feature -- Implementation
value: LIST [STRING]
do
create {ARRAYED_LIST [STRING]} Result.make (0)
across
controls as c
loop
if c.item.value then
Result.extend (c.item.checked_value)
end
end
end
end

View File

@@ -0,0 +1,98 @@
note
description: "Summary description for {WSF_TEXT_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_INPUT_CONTROL
inherit
WSF_VALUE_CONTROL [STRING]
create
make_input
feature {NONE} -- Initialization
make_input (n, v: STRING)
-- Initialize with specified name and value
do
make_control (n, "input")
type := "text"
text := v
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
set_state (new_state: JSON_OBJECT)
-- Restore text from json
do
if attached {JSON_STRING} new_state.item ("text") as new_text then
text := new_text.unescaped_string_32
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_STRING}.make_json (text), "text")
Result.put (create {JSON_BOOLEAN}.make_boolean (attached change_event), "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; event_parameter: detachable STRING)
do
if Current.control_name.same_string (cname) and attached change_event as cevent then
if event.same_string ("change") then
cevent.call (Void)
end
end
end
feature -- Rendering
render: STRING
do
Result := render_tag ("", "type=%"" + type + "%" value=%"" + text + "%"")
end
feature -- Change
set_text (t: STRING)
-- Set text to be displayed
do
if not t.same_string (text) then
text := t
state_changes.replace (create {JSON_STRING}.make_json (text), "text")
end
end
feature -- Implementation
value: STRING
do
Result := text
end
feature -- Properties
text: STRING
-- Text to be displayed
type: STRING
-- Type of this input control
change_event: detachable PROCEDURE [ANY, TUPLE]
-- Procedure to be execued on change
end

View File

@@ -0,0 +1,26 @@
note
description: "Summary description for {WSF_PASSWORD_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_PASSWORD_CONTROL
inherit
WSF_INPUT_CONTROL
create
make_password
feature {NONE} -- Initialization
make_password (n, v: STRING)
-- Initialize with specified control name and text
do
make_input (n, v)
type := "password"
end
end

View File

@@ -0,0 +1,36 @@
note
description: "Summary description for {WSF_TEXT_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_TEXTAREA_CONTROL
inherit
WSF_INPUT_CONTROL
redefine
render
end
create
make_textarea
feature {NONE} -- Initialization
make_textarea (n, t: STRING)
-- Initialize with specified control name and text to be displayed in this textarea
do
make_input (n, t)
tag_name := "textarea"
end
feature -- Rendering
render: STRING
do
Result := render_tag (text, "")
end
end

View File

@@ -0,0 +1,123 @@
note
description: "Summary description for {WSF_NAVBAR_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_NAVBAR_CONTROL
inherit
WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
redefine
render
end
create
make_navbar, make_navbar_with_brand
feature {NONE} -- Initialization
make_navbar (n: STRING)
--Initialize
do
make_multi_control (n)
add_class ("navbar navbar-inverse navbar-fixed-top")
create nav.make_with_tag_name (control_name + "_nav", "ul")
nav.add_class ("nav navbar-nav")
end
make_navbar_with_brand (n, b: STRING)
-- Initialize with specified brand string
do
make_navbar (n)
brand := b
end
feature -- Rendering
render: STRING
local
temp: STRING
nav_string: STRING
do
temp := render_tag_with_tagname ("span", "", "", "icon-bar")
temp.append (render_tag_with_tagname ("span", "", "", "icon-bar"))
temp.append (render_tag_with_tagname ("span", "", "", "icon-bar"))
temp := render_tag_with_tagname ("button", temp, "", "navbar-toggle")
if attached brand as b then
temp.append (render_tag_with_tagname ("a", b, "href=%"#%"", "navbar-brand"))
end
temp := render_tag_with_tagname ("div", temp, "", "navbar-header")
nav_string := nav.render
if attached nav_right as n then
nav_string.append (n.render)
end
temp.append (render_tag_with_tagname ("div", nav_string, "", "navbar-collapse"))
Result := render_tag_with_tagname ("div", temp, "", "container")
Result := render_tag (Result, "")
end
feature -- Change
add_list_element_right (c: WSF_STATELESS_CONTROL)
-- Add element in li tag to right aligned part of navbar
local
name: STRING
li: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
do
name := control_name + "_rightlink";
if attached nav_right as right then
name := name + right.controls.count.out
else
name := name + "0"
end
create li.make_with_tag_name (name, "li")
li.add_control (c)
add_element_right (li)
end
add_list_element (c: WSF_STATELESS_CONTROL)
-- Add element in li tag to main nav
local
li: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
do
create li.make_with_tag_name (control_name + "_link" + nav.controls.count.out, "li")
li.add_control (c)
add_element (li)
end
add_element_right (c: WSF_STATELESS_CONTROL)
-- Add element to right aligned part of navbar
local
right: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
do
if attached nav_right as r then
right := r
else
create right.make_with_tag_name (control_name + "_rightnav", "ul")
right.add_class ("nav navbar-nav navbar-right")
nav_right := right
end
right.add_control (c)
end
add_element (c: WSF_STATELESS_CONTROL)
-- Add element to main nav
do
nav.add_control (c)
end
feature -- Properties
brand: detachable STRING
-- Optional brand of the navbar
nav: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
-- Middle nav
nav_right: detachable WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
-- Right nav
end

View File

@@ -0,0 +1,97 @@
note
description: "Summary description for {WSF_PROGRESS_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_PROGRESS_CONTROL
inherit
WSF_CONTROL
create
make_progress, make_progress_with_source
feature {NONE} -- Initialization
make_progress (n: STRING)
-- Initialize with specified control name
do
make_control (n, "div")
add_class ("progress")
progress := 0
end
make_progress_with_source (n: STRING; p: WSF_PROGRESSSOURCE)
-- Initialize with specified control name and progresssource
do
make_progress (n)
progress_source := p
end
feature -- State handling
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
end
end
state: JSON_OBJECT
do
create Result.make
Result.put (create {JSON_NUMBER}.make_integer (progress_value), "progress")
end
feature -- Event handling
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
do
if cname.same_string (control_name) and event.same_string ("progress_fetch") then
state_changes.put (create {JSON_NUMBER}.make_integer (progress_value), "progress")
end
end
feature -- Rendering
render: STRING
local
p: STRING
do
p := progress_value.out
Result := render_tag_with_tagname ("div", "", "role=%"progressbar%" aria-valuenow=%"" + p + "%" aria-valuemin=%"0%" aria-valuemax=%"100%" style=%"width: " + p + "%%;%"", "progress-bar")
Result := render_tag (Result, "")
end
feature -- Change
set_progress (p: INTEGER)
-- Set current progress value to specified value. Must be between 0 and 100. Must only be called when no progresssource has been set to this progress control
require
no_progress_source: not (attached progress_source)
valid_input_value: p >= 0 and p <= 100
do
progress := p
state_changes.put (create {JSON_NUMBER}.make_integer (progress), "progress")
end
feature -- Implementation
progress_value: INTEGER
do
Result := progress
if attached progress_source as ps then
Result := ps.progress
end
end
feature -- Properties
progress_source: detachable WSF_PROGRESSSOURCE
progress: INTEGER
end

View File

@@ -0,0 +1,17 @@
note
description: "Summary description for {WSF_PROGRESSSOURCE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_PROGRESSSOURCE
feature -- Specification
progress: INTEGER
-- Current value of progress between 0 and 100 of this progresssource
deferred
end
end

View File

@@ -0,0 +1,97 @@
note
description: "Summary description for {WSF_IMAGE_SLIDER_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_SLIDER_CONTROL
inherit
WSF_CONTROL
create
make_slider
feature {NONE} -- Initialization
make_slider (n: STRING)
-- Initialize with specified name
do
make_control (n, "div")
add_class ("carousel slide")
create list.make_with_tag_name (control_name+"_links", "ol")
list.add_class ("carousel-indicators")
create slide_wrapper.make_multi_control (control_name+"_wrapper")
slide_wrapper.add_class ("carousel-inner")
end
feature -- State handling
set_state (new_state: JSON_OBJECT)
do
end
state: JSON_OBJECT
do
create Result.make
end
feature -- Callback
handle_callback (cname, event: STRING; event_parameter: detachable STRING)
do
-- Do nothing here
end
feature -- Rendering
render: STRING
local
temp: STRING
do
temp := list.render
temp.append (slide_wrapper.render)
temp.append (render_tag_with_tagname ("a", "<span class=%"icon-prev%"></span>", "href=%"#" + control_name + "%" data-slide=%"next%"", "left carousel-control"))
temp.append (render_tag_with_tagname ("a", "<span class=%"icon-next%"></span>", "href=%"#" + control_name + "%" data-slide=%"prev%"", "right carousel-control"))
Result := render_tag (temp, "")
end
feature -- Change
add_image_with_caption (src, alt: STRING; caption: detachable WSF_STATELESS_CONTROL)
-- Add a new image to the slider, with specified url, alternative text and caption element
local
item: WSF_MULTI_CONTROL[WSF_STATELESS_CONTROL]
do
list.add_control (create {WSF_BASIC_CONTROL}.make_with_body ("li", "data-target=%"#" + control_name + "%" data-slide-to=%"" + list.controls.count.out + "%"", ""));
create item.make_multi_control (control_name+"_item"+slide_wrapper.controls.count.out)
item.add_class ("item")
item.add_control (create {WSF_BASIC_CONTROL}.make_with_body ("img", "src=%"" + src + "%" alt=%"" + alt + "%"", ""))
if attached caption as c then
item.add_control (c)
end
slide_wrapper.add_control (item)
end
add_image (src, alt: STRING)
-- Add a new image to the slider, with specified url and alternative text
do
add_image_with_caption (src, alt, Void)
end
add_control(c:WSF_STATELESS_CONTROL)
do
end
feature -- Properties
list: WSF_MULTI_CONTROL[WSF_STATELESS_CONTROL]
-- List of slider links
slide_wrapper: WSF_MULTI_CONTROL[WSF_STATELESS_CONTROL]
-- List of the single slides
end

View File

@@ -0,0 +1,25 @@
note
description: "Summary description for {WSF_DECIMAL_VALIDATOR}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_DECIMAL_VALIDATOR
inherit
WSF_REGEXP_VALIDATOR
create
make_decimal_validator
feature {NONE} -- Initialization
make_decimal_validator (e: STRING)
-- Initialize with specified error message which will be displayed on validation failure
do
make_regexp_validator ("^[0-9]+(\.[0-9]*)?$|^\.[0-9]+$", e)
end
end

View File

@@ -0,0 +1,25 @@
note
description: "Summary description for {WSF_EMAIL_VALIDATOR}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_EMAIL_VALIDATOR
inherit
WSF_REGEXP_VALIDATOR
create
make_email_validator
feature {NONE} -- Initialization
make_email_validator (e: STRING)
-- Initialize with specified error message which will be displayed on validation failure
do
make_regexp_validator ("^[a-zA-Z0-9._%%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$", e)
end
end

View File

@@ -0,0 +1,49 @@
note
description: "Summary description for {WSF_MAX_VALIDATOR}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_max_VALIDATOR [G]
inherit
WSF_VALIDATOR [LIST [G]]
redefine
state
end
create
make_max_validator
feature {NONE} -- Initialization
make_max_validator (m: INTEGER; e: STRING)
-- Initialize with specified maximum and error message which will be displayed on validation failure
do
make (e)
max := m
end
feature -- Implementation
is_valid (input: LIST [G]): BOOLEAN
do
Result := input.count < max or input.count = max
end
feature -- State
state: JSON_OBJECT
do
Result := Precursor
Result.put (create {JSON_NUMBER}.make_integer (max), "max")
end
feature -- Properties
max: INTEGER
-- The maximal allowed value
end

View File

@@ -0,0 +1,49 @@
note
description: "Summary description for {WSF_MIN_VALIDATOR}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_MIN_VALIDATOR [G]
inherit
WSF_VALIDATOR [LIST [G]]
redefine
state
end
create
make_min_validator
feature {NONE} -- Initialization
make_min_validator (m: INTEGER; e: STRING)
-- Initialize with specified minimum and error message which will be displayed on validation failure
do
make (e)
min := m
end
feature -- Implementation
is_valid (input: LIST [G]): BOOLEAN
do
Result := input.count > min or input.count = min
end
feature -- State
state: JSON_OBJECT
do
Result := Precursor
Result.put (create {JSON_NUMBER}.make_integer (min), "min")
end
feature -- Properties
min: INTEGER
-- The minimal allowed value
end

View File

@@ -0,0 +1,25 @@
note
description: "Summary description for {WSF_PHONE_NUMBER_VALIDATOR}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_PHONE_NUMBER_VALIDATOR
inherit
WSF_REGEXP_VALIDATOR
create
make_with_message
feature {NONE} -- Initialization
make_with_message (e: STRING)
-- Initialize with specified error message which will be displayed on validation failure
do
make_regexp_validator ("", e)
end
end

View File

@@ -0,0 +1,57 @@
note
description: "Summary description for {WSF_REGEXP_VALIDATOR}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_REGEXP_VALIDATOR
inherit
WSF_VALIDATOR [STRING]
redefine
state
end
create
make_regexp_validator
feature {NONE} -- Initialization
make_regexp_validator (r, e: STRING)
-- Initialize with specified regular expression and error message which will be displayed on validation failure
do
make (e)
regexp_string := r
create regexp
end
feature -- Implementation
is_valid (input: STRING): BOOLEAN
do
--Only compile when used
if not regexp.is_compiled then
regexp.compile (regexp_string)
end
Result := regexp.matches (input)
end
feature -- State
state: JSON_OBJECT
do
create Result.make
Result.put (create {JSON_STRING}.make_json ("WSF_REGEXP_VALIDATOR"), "name")
Result.put (create {JSON_STRING}.make_json (regexp_string), "expression")
Result.put (create {JSON_STRING}.make_json (error), "error")
end
feature -- Properties
regexp_string: STRING
regexp: REGULAR_EXPRESSION
end

View File

@@ -0,0 +1,22 @@
note
description: "Summary description for {WSF_VALIDATABLE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_VALIDATABLE
feature -- Specification
validate
-- Perform validation
deferred
end
is_valid: BOOLEAN
-- Result of last validation
deferred
end
end

View File

@@ -0,0 +1,37 @@
note
description: "Summary description for {WSF_VALIDATOR}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_VALIDATOR [G]
feature {NONE} -- Initialization
make (e: STRING)
-- Initialize with specified error message to be displayed on validation failure
do
error := e
end
feature -- Access
state: JSON_OBJECT
-- JSON state of this validator
do
create Result.make
Result.put (create {JSON_STRING}.make_json (generator), "name")
Result.put (create {JSON_STRING}.make_json (error), "error")
end
is_valid (input: G): BOOLEAN
-- Perform validation on given input and tell whether validation was successful or not
deferred
end
feature -- Properties
error: STRING
end

View File

@@ -0,0 +1,66 @@
note
description: "Summary description for {WSF_BASIC_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_BASIC_CONTROL
inherit
WSF_STATELESS_CONTROL
redefine
attributes
end
create
make_control, make_with_body
feature {NONE} -- Initialization
make_control (t: STRING)
-- Initialize
do
make_with_body (t, "", "")
end
make_with_body (t, attr, b: STRING)
-- Initialize with specific attributes and body
do
make (t)
attributes := attr
body := b
end
feature -- Rendering
render: STRING
-- HTML representation of this control
do
Result := render_tag (body, attributes)
end
feature -- Change
set_attributes (a: STRING)
-- Set the attributes string of this control
do
attributes := a
end
set_body (b: STRING)
-- Set the body of this control
do
body := b
end
feature -- Access
attributes: STRING
-- Attributes of this control
body: STRING
-- Body of this control
end

View File

@@ -0,0 +1,88 @@
note
description: "Summary description for {WSF_BUTTON_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_BUTTON_CONTROL
inherit
WSF_CONTROL
create
make_button
feature {NONE} -- Initialization
make_button (n: STRING; t: STRING)
-- Initialize with specified control name and text
do
make_control (n, "button")
add_class ("btn")
add_class ("btn-default")
text := t
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
set_state (new_state: JSON_OBJECT)
-- Restore text from json
do
if attached {JSON_STRING} new_state.item ("text") as new_text then
text := new_text.unescaped_string_32
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_STRING}.make_json (text), "text")
Result.put (create {JSON_BOOLEAN}.make_boolean (attached click_event), "callback_click")
end
feature --Event handling
set_click_event (e: attached like click_event)
-- Set button click event handle
do
click_event := e
end
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
do
if Current.control_name.same_string (cname) and attached click_event as cevent then
cevent.call (Void)
end
end
feature -- Rendering
render: STRING
-- HTML representation of this control
do
Result := render_tag (text, "")
end
feature -- Change
set_text (t: STRING)
-- Set text of that button
do
if not t.same_string (text) then
text := t
state_changes.replace (create {JSON_STRING}.make_json (text), "text")
end
end
feature -- Properties
text: STRING
-- The text currently displayed on this button
click_event: detachable PROCEDURE [ANY, TUPLE]
-- Event that is executed when button is clicked
end

View File

@@ -0,0 +1,159 @@
note
description: "Summary description for {WSF_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_CONTROL
inherit
WSF_STATELESS_CONTROL
redefine
render_tag
end
feature
control_name: STRING
feature {NONE} -- Initialization
make_control (n, a_tag_name: STRING)
-- Initialize with specified control name and tag
require
not n.is_empty
not a_tag_name.is_empty
do
make (a_tag_name)
control_name := n
create state_changes.make
create actions.make_array
ensure
attached state_changes
end
feature -- Actions
start_modal(url:STRING; title:STRING)
--Start a modal window containg an other or the same page
local
modal:JSON_OBJECT
do
create modal.make
modal.put (create {JSON_STRING}.make_json("start_modal"), "type")
modal.put (create {JSON_STRING}.make_json(url), "url")
modal.put (create {JSON_STRING}.make_json(title), "title")
actions.add (modal)
end
show_alert(mesage:STRING)
--Start a modal window containg an other or the same page
local
modal:JSON_OBJECT
do
create modal.make
modal.put (create {JSON_STRING}.make_json("show_alert"), "type")
modal.put (create {JSON_STRING}.make_json(mesage), "message")
actions.add (modal)
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
load_state (new_states: JSON_OBJECT)
-- Select state stored with `control_name` as key
do
if attached {JSON_OBJECT} new_states.item ("state") as new_state_obj then
set_state (new_state_obj)
end
end
set_state (new_state: JSON_OBJECT)
-- Before we process the callback. We restore the state of control.
deferred
end
full_state: JSON_OBJECT
-- Return state of object
do
create Result.make
Result.put (state, "state")
end
read_state_changes (states: JSON_OBJECT)
-- Add a new entry in the `states_changes` JSON object with the `control_name` as key and the `state` as value
do
if state_changes.count > 0 then
states.put (state_changes, control_name)
end
if actions.count > 0 then
if not attached states.item ("actions") then
states.put (create {JSON_ARRAY}.make_array,"actions")
end
if attached {JSON_ARRAY}states.item ("actions") as action_list then
across
actions.array_representation as action
loop
action_list.add (action.item)
end
end
end
end
state: JSON_OBJECT
-- Returns the current state of the Control as JSON. This state will be transfered to the client.
deferred
ensure
controls_not_defined: not (attached Result.item ("controls"))
end
state_changes: JSON_OBJECT
feature -- Rendering
render_tag (body, attrs: STRING): STRING
-- Render this control with the specified body and attributes
do
Result := render_tag_with_generator_name (generator, body, attrs)
end
render_tag_with_generator_name (a_generator, body, attrs: STRING): STRING
-- Render this control with the specified generator name, body and attributes
local
css_classes_string: STRING
l_attributes: STRING
do
css_classes_string := ""
across
css_classes as c
loop
css_classes_string := css_classes_string + " " + c.item
end
l_attributes := "id=%"" + control_name + "%" data-name=%"" + control_name + "%" data-type=%"" + a_generator + "%" " + attrs
if isolate then
l_attributes.append (" data-isolation=%"1%"")
end
Result := render_tag_with_tagname (tag_name, body, l_attributes, css_classes_string)
end
feature -- EVENT HANDLING
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
-- Method called if any callback received. In this method you can route the callback to the event handler
deferred
end
feature -- Change
set_isolation (p: BOOLEAN)
do
isolate := true
end
feature -- Properties
isolate: BOOLEAN
actions: JSON_ARRAY
end

View File

@@ -0,0 +1,51 @@
note
description: "Summary description for {WSF_FORM_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_FORM_CONTROL
inherit
WSF_MULTI_CONTROL [WSF_CONTROL]
WSF_VALIDATABLE
create
make_form_control
feature {NONE} -- Initialization
make_form_control (n: STRING)
-- Initialize
do
make_multi_control (n)
tag_name := "form"
end
feature -- Validation
validate
-- Perform form validation
do
is_valid := True
across
controls as c
until
is_valid = False
loop
if attached {WSF_VALIDATABLE} c.item as elem then
elem.validate
if not elem.is_valid then
is_valid := False
end
end
end
end
is_valid: BOOLEAN
-- Tells whether the last validation was valid
end

View File

@@ -0,0 +1,184 @@
note
description: "Summary description for {WSF_FORM_ELEMENT_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_FORM_ELEMENT_CONTROL [G]
inherit
WSF_CONTROL
redefine
read_state_changes,
load_state,
full_state
end
WSF_VALIDATABLE
create
make_form_element, make_form_element_with_validators
feature {NONE} -- Initialization
make_form_element (a_label: STRING; c: WSF_VALUE_CONTROL [G])
-- Initialize form element control with a specific label and value control
do
make_form_element_with_validators (a_label, c, create {ARRAYED_LIST [WSF_VALIDATOR [G]]}.make (0))
end
make_form_element_with_validators (a_label: STRING; c: WSF_VALUE_CONTROL [G]; v: LIST [WSF_VALIDATOR [G]])
-- Initialize form element control with a specific label, value control and list of validators
do
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")
end
if attached {WSF_HTML_CONTROL} c then
c.add_class ("form-control-static")
end
value_control := c
validators := v
label := a_label
error := ""
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
load_state (new_states: JSON_OBJECT)
-- Pass new_states to subcontrols
do
Precursor (new_states)
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: JSON_OBJECT)
-- Set new state
do
value_control.set_state (new_state)
end
full_state: JSON_OBJECT
local
controls_state: JSON_OBJECT
do
Result := Precursor
create controls_state.make
controls_state.put (value_control.full_state, value_control.control_name)
Result.put (controls_state, "controls")
end
read_state_changes (states: JSON_OBJECT)
-- Read states_changes in subcontrols
do
Precursor (states)
value_control.read_state_changes (states)
end
state: JSON_OBJECT
-- Read state
local
validator_description: JSON_ARRAY
do
create Result.make
create validator_description.make_array
across
validators as v
loop
validator_description.add (v.item.state)
end
Result.put (create {JSON_STRING}.make_json (value_control.control_name), "value_control")
Result.put (validator_description, "validators")
end
feature -- Event handling
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
-- Pass callback to subcontrols
do
if cname.same_string (control_name) then
if event.same_string ("validate") then
validate
end
else
value_control.handle_callback (cname, event, event_parameter)
end
end
feature -- Implementation
render: STRING
-- HTML Respresentation of this form element control
local
body: STRING
do
body := ""
if not label.is_empty then
body.append ("<label class=%"col-lg-2 control-label%" for=%"" + value_control.control_name + "%">" + label + "</label>")
end
body.append ("<div class=%"col-lg-10%">")
body.append (value_control.render)
body.append ("</div>")
Result := render_tag (body, "")
end
feature -- Validation
add_validator (v: WSF_VALIDATOR [G])
-- Add an additional validator that will check the input of the value control of this form element control on validation
do
validators.extend (v)
end
set_error (e: STRING)
-- Set the error message that will be displayed upon failure of client side validation
do
error := e
state_changes.replace (create {JSON_STRING}.make_json (e), "error")
end
validate
-- Perform validation
local
current_value: G
do
current_value := value_control.value
is_valid := True
across
validators as c
until
not is_valid
loop
if not c.item.is_valid (current_value) then
is_valid := False
set_error (c.item.error)
end
end
if is_valid then
set_error ("")
end
end
is_valid: BOOLEAN
-- Tells whether the last validation was successful or not
feature -- Properties
value_control: WSF_VALUE_CONTROL [G]
-- The value control associated with this form element control
validators: LIST [WSF_VALIDATOR [G]]
-- The validators which check the input when validaton is performed
label: STRING
-- The label of this form element control
error: STRING
-- The error message that is displayed when client side validation fails
end

View File

@@ -0,0 +1,74 @@
note
description: "Summary description for {WSF_html_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_HTML_CONTROL
inherit
WSF_VALUE_CONTROL [STRING]
create
make_html
feature {NONE} -- Initialization
make_html (n, t, v: STRING)
-- Initialize
do
make_control (n, t)
html := v
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
set_state (new_state: JSON_OBJECT)
-- Restore html from json
do
if attached {JSON_STRING} new_state.item ("html") as new_html then
html := new_html.unescaped_string_32
end
end
state: JSON_OBJECT
-- Return state which contains the current html and if there is an event handle attached
do
create Result.make
Result.put (create {JSON_STRING}.make_json (html), "html")
end
feature --Event handling
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
do
end
feature -- Implementation
render: STRING
-- HTML representation of this html control
do
Result := render_tag (html, "")
end
set_html (t: STRING)
do
if not t.same_string (html) then
html := t
state_changes.replace (create {JSON_STRING}.make_json (html), "html")
end
end
value: STRING
do
Result := html
end
feature -- Properties
html: STRING
end

View File

@@ -0,0 +1,143 @@
note
description: "Summary description for {WSF_MULTI_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_MULTI_CONTROL [G -> WSF_STATELESS_CONTROL]
inherit
WSF_CONTROL
redefine
full_state,
read_state_changes,
load_state
end
create
make_multi_control, make_with_tag_name
feature {NONE} -- Initialization
make_multi_control (n: STRING)
-- Initialize with specified control name and default tag "div"
do
make_with_tag_name (n, "div")
end
make_with_tag_name (n, t: STRING)
-- Initialize with specified control name and tag
do
make_control (n, t)
controls := create {ARRAYED_LIST [G]}.make (5);
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
load_state (new_states: JSON_OBJECT)
-- Pass new_states to subcontrols
do
Precursor (new_states)
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 {JSON_OBJECT} ct.item (cont.control_name) as value_state then
cont.load_state (value_state)
end
end
end
end
end
set_state (new_state: JSON_OBJECT)
-- Before we process the callback. We restore the state of control.
do
end
full_state: JSON_OBJECT
-- Read states in subcontrols
local
controls_state: JSON_OBJECT
do
Result := Precursor
create controls_state.make
across
controls as c
loop
if attached {WSF_CONTROL} c.item as cont then
controls_state.put (cont.full_state, cont.control_name)
end
end
Result.put (controls_state, "controls")
end
read_state_changes (states: JSON_OBJECT)
-- Read states_changes in subcontrols
do
Precursor (states)
across
controls as c
loop
if attached {WSF_CONTROL} c.item as cont then
cont.read_state_changes (states)
end
end
end
state: JSON_OBJECT
--Read state
do
create Result.make
end
feature -- Event handling
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
-- Pass callback to subcontrols
do
if equal (cname, control_name) then
else
across
controls as c
loop
if attached {WSF_CONTROL} c.item as cont then
cont.handle_callback (cname, event, event_parameter)
end
end
end
end
feature -- Rendering
render: STRING
-- HTML representation of this multi control
do
Result := ""
across
controls as c
loop
Result := c.item.render + Result
end
Result := render_tag (Result, "")
end
feature -- Change
add_control (c: detachable G)
-- Add a control to this multi control
do
if attached c as d then
controls.put_front (d)
end
end
feature -- Properties
controls: ARRAYED_LIST [G]
-- List of current controls in this multi control
end

View File

@@ -0,0 +1,189 @@
note
description: "Summary description for {WSF_PAGE_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_PAGE_CONTROL
inherit
WSF_CONTROL
rename
make as make_wsf_control
redefine
full_state,
read_state_changes
end
feature {NONE} -- Initialization
make (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Initialize
do
make_control (req.request_time_stamp.out, "body")
request := req
response := res
initialize_controls
end
feature -- Access
request: WSF_REQUEST
-- The http request
response: WSF_RESPONSE
-- The http response
feature -- Specific implementation
initialize_controls
-- Initalize all the controls, all the event handles must be set in this function.
deferred
ensure
attached control
end
process
-- Function called on page load (not on callback)
deferred
end
feature -- Implementation
execute
-- Entry Point: If request is a callback, restore control states and execute handle then return new state json.
-- If request is not a callback. Run process and render the html page
local
event: detachable STRING
event_parameter: detachable STRING
event_control_name: detachable STRING
states: STRING
states_changes: JSON_OBJECT
json_parser: JSON_PARSER
do
event_control_name := get_parameter ("control_name")
event := get_parameter ("event")
event_parameter := get_parameter ("event_parameter")
if attached event and attached event_control_name and attached control then
create states.make_empty
request.read_input_data_into (states)
create json_parser.make_parser (states)
if attached {JSON_OBJECT} json_parser.parse_json as sp then
set_state (sp)
end
handle_callback (event_control_name, event, event_parameter)
create states_changes.make
read_state_changes (states_changes)
response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "application/json; charset=ISO-8859-1"]>>)
response.put_string (states_changes.representation)
else
process
render_page
end
end
render_page
-- Render and send the HTML Page
local
page: WSF_PAGE_RESPONSE
do
create page.make
page.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/html; charset=ISO-8859-1"]>>)
page.set_body (render)
response.send (page)
end
render: STRING
local
ajax: BOOLEAN
do
ajax := attached get_parameter ("ajax")
create Result.make_empty
if not ajax then
Result.append ("<html><head>")
Result.append ("<link href=%"/bootstrap.min.css%" rel=%"stylesheet%">")
Result.append ("<link href=%"/widget.css%" rel=%"stylesheet%">")
Result.append ("</head><body data-name=%"" + control_name + "%" data-type=%"WSF_PAGE_CONTROL%">")
Result.append (control.render)
Result.append ("<script src=%"/jquery.min.js%"></script>")
Result.append ("<script src=%"/typeahead.min.js%"></script>")
Result.append ("<script src=%"/bootstrap.min.js%"></script>")
Result.append ("<script src=%"/widget.js%"></script>")
Result.append ("<script type=%"text/javascript%">$(function() {var page= new WSF_PAGE_CONTROL(")
Result.append (full_state.representation)
Result.append (");page.attach_events();});</script>")
Result.append ("</body></html>")
else
Result.append ("<div data-name=%"" + control_name + "%" data-type=%"WSF_PAGE_CONTROL%">")
Result.append (control.render)
Result.append ("<script type=%"text/javascript%">$(function() {var page= new WSF_PAGE_CONTROL(")
Result.append (full_state.representation)
Result.append (");page.attach_events();});</script>")
Result.append ("</div>")
end
end
read_state_changes (states: JSON_OBJECT)
-- Add a new entry in the `states_changes` JSON object with the `control_name` as key and the `state` as value
do
Precursor (states)
control.read_state_changes (states)
end
get_parameter (key: STRING): detachable STRING
-- Read query parameter as string
local
value: detachable WSF_VALUE
do
Result := VOID
value := request.query_parameter (key)
if attached value and then value.is_string then
Result := value.as_string.value
end
end
feature -- Event handling
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
-- Forward callback to control
do
control.handle_callback (cname, event, event_parameter)
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
state: JSON_OBJECT
do
create Result.make
Result.put (create {JSON_STRING}.make_json (control_name), "id")
Result.put (create {JSON_STRING}.make_json (request.path_info), "url")
Result.put (create {JSON_STRING}.make_json (request.query_string), "url_params")
end
set_state (sp: JSON_OBJECT)
do
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
full_state: JSON_OBJECT
local
controls_state: JSON_OBJECT
do
create Result.make
create controls_state.make
controls_state.put (control.full_state, control.control_name)
Result.put (controls_state, "controls")
Result.put (state, "state")
end
feature {NONE} -- Root control
control: WSF_CONTROL
-- The root control of this page
end

View File

@@ -0,0 +1,90 @@
note
description: "Summary description for {WSF_STATELESS_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_STATELESS_CONTROL
feature {NONE} -- Initialization
make (a_tag_name: STRING)
-- Initialize with specified tag
require
not a_tag_name.is_empty
do
tag_name := a_tag_name
create css_classes.make (0)
end
feature -- Access
tag_name: STRING
-- The tag name
css_classes: ARRAYED_LIST [STRING]
-- List of classes (appear in the "class" attribute)
attributes: detachable STRING
-- Attributes string
feature -- Change
add_class (c: STRING)
-- Add a css class to this control
do
css_classes.force (c)
end
feature -- Rendering
render_tag (body, attrs: STRING): STRING
-- Generate HTML of this control with the specified body and attributes
local
css_classes_string: STRING
do
create css_classes_string.make_empty
across
css_classes as c
loop
css_classes_string.append (" " + c.item)
end
Result := render_tag_with_tagname (tag_name, body, attrs, css_classes_string)
end
render_tag_with_tagname (tag, body, attrs, css_classes_string: STRING): STRING
-- Generate HTML of the specified tag with specified body, attributes and css classes
local
l_attributes: STRING
do
create l_attributes.make_from_string (attrs)
if not css_classes_string.is_empty then
l_attributes.append (" class=%"")
l_attributes.append (css_classes_string)
l_attributes.append_character ('%"')
end
Result := "<" + tag + " " + l_attributes
if body.is_empty and not tag.same_string ("textarea") and not tag.same_string ("span") and not tag.same_string ("button") and not tag.same_string ("ul") then
Result.append (" />")
else
Result.append (" >" + body + "</" + tag + ">")
end
end
render_tag_with_body (body: STRING): STRING
-- Generate HTML of this control with the specified body
do
if attached attributes as attrs then
Result := render_tag (body, attrs)
else
Result := render_tag (body, "")
end
end
render: STRING
-- Return html representation of control
deferred
end
end

View File

@@ -0,0 +1,21 @@
note
description: "Summary description for {WSF_VALUE_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_VALUE_CONTROL [G]
inherit
WSF_CONTROL
feature -- Access
value: G
-- The current value of this control
deferred
end
end