Move wsf_js_widget library under draft/library/server/wsf_js_widget

This commit is contained in:
2014-07-07 10:26:10 +02:00
parent 3c8dc0a9e1
commit fe4c283336
106 changed files with 16 additions and 16 deletions

View File

@@ -0,0 +1,89 @@
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: WSF_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_string (a_sort_column, "sort_column")
else
Result.put (create {JSON_NULL}, "sort_column")
end
Result.put_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]
;note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,26 @@
note
description: "Summary description for {WSF_ENTITY}."
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_ENTITY
feature -- Access
item alias "[]" (a_field: READABLE_STRING_GENERAL): detachable ANY
-- Value for field item `a_field'.
deferred
end
note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,55 @@
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_32)
do
header := a_header
field_name := a_field
sorting_name := a_field
end
feature -- Render
render_column (e: WSF_ENTITY): STRING_32
-- Return the rendered column cell for a specific entity (row)
do
if attached e.item (field_name) as data then
--| FIXME: .out may not be the best rendering for objects...
Result := data.out
else
Result := "[VOID]"
end
end
feature -- Access
header: STRING_32
sortable: BOOLEAN
sorting_name: STRING_32
field_name: STRING_32
;note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,75 @@
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]
rename
make as make_repeater
redefine
render
end
create
make
feature {NONE} -- Initialization
make (a_columns: ITERABLE [WSF_GRID_COLUMN]; a_datasource: WSF_DATASOURCE [G])
do
make_repeater (a_datasource)
columns := a_columns
end
feature -- Render
render_item (item: G): STRING_32
-- 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_32
-- 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_32
-- Render entre table and subcontrols
local
table: STRING_32
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_32)
do
make_column (a_header, a_field)
end
feature -- Render
render_column (e: WSF_ENTITY): STRING_32
-- 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,92 @@
note
description: "Summary description for {WSF_PAGABLE_DATASOURCE}."
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: WSF_JSON_OBJECT
-- Return state which contains the current page, page_size and row_count
do
Result := Precursor
Result.put_integer (page, "page")
Result.put_integer (page_size, "page_size")
Result.put_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]
;note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,112 @@
note
description: "Summary description for {WSF_PAGINATION}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_PAGINATION_CONTROL [G -> WSF_ENTITY]
inherit
WSF_CONTROL
rename
make as make_control
end
create
make
feature {NONE}
make (ds: WSF_PAGABLE_DATASOURCE [G])
do
make_control ( "ul")
add_class ("pagination")
datasource := ds
datasource.set_on_update_page_agent (agent update)
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
state: WSF_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_from_string_32 (render), "_html")
end
feature --Event handling
handle_callback (cname: LIST [READABLE_STRING_GENERAL]; event: READABLE_STRING_GENERAL; event_parameter: detachable ANY)
-- Handle goto/next/prev events
do
if control_name.same_string_general (cname.first) 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 {READABLE_STRING_GENERAL} 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_32
-- Render paging control
local
paging_start: INTEGER
paging_end: INTEGER
cssclass: STRING_32
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]
;note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,112 @@
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]
rename
make as make_multi_control
redefine
set_state,
state,
render
end
feature {NONE} -- Initialization
make (a_datasource: WSF_DATASOURCE [G])
local
p: WSF_PAGINATION_CONTROL [G]
do
make_multi_control
datasource := a_datasource
datasource.set_on_update_agent (agent update)
if attached {WSF_PAGABLE_DATASOURCE [G]} a_datasource as ds then
create p.make (ds)
add_control (p)
pagination_control := p
end
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
update
-- Send new rendered control to client on update
do
state_changes.replace (create {JSON_STRING}.make_json_from_string_32 (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: WSF_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_32
-- Render item
deferred
end
render_body: STRING_32
-- Render Body
do
create Result.make_empty
across
datasource.data as ic
loop
Result.append (render_item (ic.item))
end
end
render: STRING_32
-- Render repeater inclusive paging if paging is available
local
content: STRING_32
do
content := render_tag_with_tagname ("div", render_body, "", "repeater_content")
create Result.make_empty
across
controls as ic
loop
-- CHECK: Prepend ? or Append?
Result.prepend (ic.item.render)
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 -- Access
datasource: WSF_DATASOURCE [G]
pagination_control: detachable WSF_PAGINATION_CONTROL [G]
;note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end