Moved more components from CMS to wsf_html.

This includes WSF_PAGER, and feature in WSF_THEME .. including WSF_API_OPTIONS
used to compute url and link.
This commit is contained in:
Jocelyn Fiat
2013-03-26 14:17:10 +01:00
parent 2eb9abeb37
commit a23871ff5b
18 changed files with 593 additions and 438 deletions

View File

@@ -0,0 +1,167 @@
note
description: "Summary description for {WSF_WIDGET_PAGER}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_WIDGET_PAGER
inherit
WSF_WIDGET
create
make
feature {NONE} -- Initialization
make (tpl: READABLE_STRING_8; a_lower, a_upper: NATURAL_64; a_step: NATURAL_64)
do
create template.make (tpl)
lower := a_lower
upper := a_upper
step := a_step
end
feature -- Change
set_active_range (a_lower, a_upper: NATURAL_64)
do
if a_upper = 0 then
active_range := [{NATURAL_64} 1, {NATURAL_64} 0]
elseif a_lower > 0 and a_lower <= a_upper then
active_range := [a_lower, a_upper]
else
active_range := Void
end
ensure
valid_range: attached active_range as rg implies (rg.upper = 0 or else rg.lower <= rg.upper)
end
feature -- Access
template: URI_TEMPLATE
lower: NATURAL_64
upper: NATURAL_64
step: NATURAL_64
active_range: detachable TUPLE [lower_index, upper_index: NATURAL_64]
feature -- Conversion
to_html (a_theme: WSF_THEME): STRING_8
do
create Result.make (1024)
append_to_html (a_theme, Result)
end
append_to_html (a_theme: WSF_THEME; a_html: STRING_8)
local
l_step: INTEGER
nb: INTEGER
curr: INTEGER
n, i: INTEGER
tb: HASH_TABLE [detachable ANY, STRING_8]
do
a_html.append ("<div")
a_html.append_character ('>')
nb := ((upper - lower) // step).to_integer_32 + 1
if nb > 1 then
if attached active_range as rg then
if rg.upper_index = 0 then
-- all
else
curr := ((rg.lower_index - lower) // step).to_integer_32
if step * curr.to_natural_64 < rg.lower_index then
curr := curr + 1
end
end
end
l_step := step.to_integer_32
create tb.make (2)
tb.force (1, "lower")
tb.force (step, "upper")
if curr > 1 then
if curr > 2 then
tb.force (1, "lower")
tb.force (l_step, "upper")
a_html.append_character (' ')
append_link_to_html (a_theme, "<<", template.expanded_string (tb), a_html)
a_html.append_character (' ')
end
tb.force ((curr - 1) * l_step + 1, "lower")
tb.force ((curr ) * l_step , "upper")
a_html.append_character (' ')
append_link_to_html (a_theme, "<", template.expanded_string (tb), a_html)
a_html.append_character (' ')
end
from
i := (curr - 1).max (1)
n := 5
until
n = 0 or i > nb
loop
a_html.append_character (' ')
tb.force ((i - 1) * l_step + 1, "lower")
tb.force ((i ) * l_step , "upper")
if i = curr then
a_html.append ("<strong>")
end
append_link_to_html (a_theme, i.out, template.expanded_string (tb), a_html)
if i = curr then
a_html.append ("</strong>")
end
a_html.append_character (' ')
i := i + 1
n := n - 1
end
if curr < nb then
a_html.append_character (' ')
tb.force ((curr ) * l_step + 1, "lower")
tb.force ((curr + 1) * l_step , "upper")
append_link_to_html (a_theme, ">", template.expanded_string (tb), a_html)
a_html.append_character (' ')
if curr + 1 < nb then
tb.force ((nb - 1) * l_step + 1, "lower")
tb.force ( upper , "upper")
a_html.append_character (' ')
append_link_to_html (a_theme, ">>", template.expanded_string (tb), a_html)
a_html.append_character (' ')
end
end
a_html.append_character (' ')
tb.force (1, "lower")
tb.force (upper , "upper")
append_link_to_html (a_theme, "all", template.expanded_string (tb), a_html)
a_html.append_character (' ')
end
a_html.append ("</div>")
debug
a_html.append ("curr=" + curr.out +" step=" + step.out + " nb=" + nb.out)
end
end
feature -- Factory
append_link_to_html (a_theme: WSF_THEME; a_text: detachable READABLE_STRING_GENERAL; a_path: STRING; a_html: STRING_8)
do
a_theme.append_link_to_html (a_text, a_path, Void, a_html)
end
end

View File

@@ -0,0 +1,109 @@
note
description: "Summary description for {WSF_WITH_CSS_CLASS}."
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_WITH_CSS_CLASS
feature -- Status report
css_classes: detachable LIST [READABLE_STRING_8]
feature -- Change
reset_css_classes
do
css_classes := Void
end
add_css_classes (a_classes: detachable ITERABLE [READABLE_STRING_8])
do
if a_classes /= Void then
across
a_classes as c
loop
add_css_class (c.item)
end
end
end
add_css_class (a_class: READABLE_STRING_8)
require
is_valid_css_class: is_valid_css_class (a_class)
local
lst: like css_classes
do
lst := css_classes
if lst = Void then
create {ARRAYED_LIST [READABLE_STRING_8]} lst.make (1)
lst.compare_objects
css_classes := lst
end
lst.force (a_class)
end
remove_css_class (a_class: READABLE_STRING_8)
require
is_valid_css_class: is_valid_css_class (a_class)
local
lst: like css_classes
do
lst := css_classes
if lst /= Void then
lst.prune_all (a_class)
end
end
feature -- Query
is_valid_css_class (s: detachable READABLE_STRING_8): BOOLEAN
do
Result := s /= Void implies (not s.is_empty)
-- To complete
end
feature -- Conversion
append_css_class_to (a_target: STRING; a_additional_classes: detachable ITERABLE [READABLE_STRING_8])
local
f: BOOLEAN
cl: READABLE_STRING_8
do
if css_classes /= Void or a_additional_classes /= Void then
a_target.append (" class=%"")
f := True -- is first
if attached css_classes as l_classes then
across
l_classes as c
loop
cl := c.item
if not cl.is_empty then
if f then
f := False
else
a_target.append_character (' ')
end
a_target.append (cl)
end
end
end
if attached a_additional_classes as l_classes then
across
l_classes as c
loop
cl := c.item
if not cl.is_empty then
if not f then
a_target.append_character (' ')
end
a_target.append (cl)
end
end
end
a_target.append_character ('%"')
end
end
end

View File

@@ -0,0 +1,41 @@
note
description: "Summary description for {WSF_WITH_CSS_ID}."
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_WITH_CSS_ID
feature -- Status report
css_id: detachable READABLE_STRING_8
feature -- Change
set_css_id (a_id: like css_id)
require
is_valid_css_id: is_valid_css_id (a_id)
do
css_id := a_id
end
feature -- Query
is_valid_css_id (s: detachable READABLE_STRING_8): BOOLEAN
do
Result := s /= Void implies (not s.is_empty)
-- To complete
end
feature -- Conversion
append_css_id_to (a_target: STRING)
do
if attached css_id as l_id then
a_target.append (" id=%"")
a_target.append (l_id)
a_target.append_character ('%"')
end
end
end

View File

@@ -0,0 +1,43 @@
note
description: "Summary description for {WSF_WITH_CSS_STYLE}."
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_WITH_CSS_STYLE
feature -- Status report
css_style: detachable CSS_STYLE
feature -- Change
reset_css_style
do
css_style := Void
end
add_css_style (a_style: like css_style)
local
s: like css_style
do
s := css_style
if s = Void then
css_style := a_style
elseif a_style /= Void then
css_style := s + a_style
end
end
feature -- Conversion
append_css_style_to (a_target: STRING)
do
if attached css_style as l_css_style then
a_target.append (" style=%"")
l_css_style.append_inline_to (a_target)
a_target.append_character ('%"')
end
end
end

View File

@@ -0,0 +1,81 @@
note
description: "Summary description for {WSF_WITH_HTML_ATTRIBUTE}."
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_WITH_HTML_ATTRIBUTE
feature -- Status report
html_attributes: detachable HASH_TABLE [detachable READABLE_STRING_8, STRING_8]
feature -- Change
reset_html_attributes
do
html_attributes := Void
end
add_html_attribute (a_name: READABLE_STRING_8; a_value: detachable READABLE_STRING_8)
require
is_valid_attribute_name: is_valid_attribute_name (a_name)
is_valid_attribute_value: is_valid_attribute_value (a_value)
local
lst: like html_attributes
do
lst := html_attributes
if lst = Void then
create lst.make (1)
lst.compare_objects
html_attributes := lst
end
lst.force (a_value, a_name)
end
remove_html_attribute (a_name: READABLE_STRING_8)
require
is_valid_attribute_name: is_valid_attribute_name (a_name)
local
lst: like html_attributes
do
lst := html_attributes
if lst /= Void then
lst.remove (a_name)
end
end
feature -- Query
is_valid_attribute_name (s: detachable READABLE_STRING_8): BOOLEAN
do
Result := s /= Void implies (not s.is_empty)
-- To complete
end
is_valid_attribute_value (s: detachable READABLE_STRING_8): BOOLEAN
do
Result := s /= Void implies (not s.has ('%"'))
-- To complete
end
feature -- Conversion
append_html_attributes_to (a_target: STRING)
do
if attached html_attributes as attribs then
across
attribs as c
loop
a_target.append (" " + c.key)
if attached c.item as v then
a_target.append_character ('=')
a_target.append_character ('%"')
a_target.append (v)
a_target.append_character ('%"')
end
end
end
end
end