Rename validators, Make forms resizable

This commit is contained in:
YNH Webdev
2013-11-10 17:22:28 +01:00
parent 40bb88a55f
commit f369b26d88
12 changed files with 83 additions and 32 deletions
@@ -6,16 +6,22 @@ note
class class
WSF_AGENT_VALIDATOR [G] WSF_AGENT_VALIDATOR [G]
inherit inherit
WSF_VALIDATOR [G] WSF_VALIDATOR [G]
rename
make as make_validator
end
create create
make_with_agent make
feature {NONE} -- Initialization feature {NONE} -- Initialization
make_with_agent (h:like handler; e: STRING) make (h: like handler; e: STRING)
do do
make (e) make_validator (e)
handler := h handler := h
end end
@@ -23,10 +29,9 @@ feature
is_valid (input: G): BOOLEAN is_valid (input: G): BOOLEAN
do do
Result := handler.item ([input])
Result := handler.item ( [input])
end end
handler: FUNCTION [ANY, TUPLE [G], BOOLEAN]
handler: FUNCTION[ANY,TUPLE[G],BOOLEAN]
end end
@@ -10,13 +10,16 @@ class
inherit inherit
WSF_REGEXP_VALIDATOR WSF_REGEXP_VALIDATOR
rename
make as make_regexp_validator
end
create create
make_decimal_validator make
feature {NONE} -- Initialization feature {NONE} -- Initialization
make_decimal_validator (e: STRING) make (e: STRING)
-- Initialize with specified error message which will be displayed on validation failure -- Initialize with specified error message which will be displayed on validation failure
do do
make_regexp_validator ("^[0-9]+(\.[0-9]*)?$|^\.[0-9]+$", e) make_regexp_validator ("^[0-9]+(\.[0-9]*)?$|^\.[0-9]+$", e)
@@ -10,13 +10,16 @@ class
inherit inherit
WSF_REGEXP_VALIDATOR WSF_REGEXP_VALIDATOR
rename
make as make_regexp_validator
end
create create
make_email_validator make
feature {NONE} -- Initialization feature {NONE} -- Initialization
make_email_validator (e: STRING) make (e: STRING)
-- Initialize with specified error message which will be displayed on validation failure -- Initialize with specified error message which will be displayed on validation failure
do do
make_regexp_validator ("^[a-zA-Z0-9._%%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$", e) make_regexp_validator ("^[a-zA-Z0-9._%%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$", e)
@@ -5,24 +5,26 @@ note
revision: "$Revision$" revision: "$Revision$"
class class
WSF_MAX_VALIDATOR [G->FINITE[ANY]] WSF_MAX_VALIDATOR [G -> FINITE [ANY]]
inherit inherit
WSF_VALIDATOR [G] WSF_VALIDATOR [G]
rename
make as make_validator
redefine redefine
state state
end end
create create
make_max_validator make
feature {NONE} -- Initialization feature {NONE} -- Initialization
make_max_validator (m: INTEGER; e: STRING) make (m: INTEGER; e: STRING)
-- Initialize with specified maximum and error message which will be displayed on validation failure -- Initialize with specified maximum and error message which will be displayed on validation failure
do do
make (e) make_validator (e)
max := m max := m
end end
@@ -5,24 +5,26 @@ note
revision: "$Revision$" revision: "$Revision$"
class class
WSF_MIN_VALIDATOR [G->FINITE[ANY]] WSF_MIN_VALIDATOR [G -> FINITE [ANY]]
inherit inherit
WSF_VALIDATOR [G] WSF_VALIDATOR [G]
rename
make as make_validator
redefine redefine
state state
end end
create create
make_min_validator make
feature {NONE} -- Initialization feature {NONE} -- Initialization
make_min_validator (m: INTEGER; e: STRING) make (m: INTEGER; e: STRING)
-- Initialize with specified minimum and error message which will be displayed on validation failure -- Initialize with specified minimum and error message which will be displayed on validation failure
do do
make (e) make_validator (e)
min := m min := m
end end
@@ -10,6 +10,9 @@ class
inherit inherit
WSF_REGEXP_VALIDATOR WSF_REGEXP_VALIDATOR
rename
make as make_regexp_validator
end
create create
make_with_message make_with_message
@@ -10,19 +10,21 @@ class
inherit inherit
WSF_VALIDATOR [STRING] WSF_VALIDATOR [STRING]
rename
make as make_validator
redefine redefine
state state
end end
create create
make_regexp_validator make
feature {NONE} -- Initialization feature {NONE} -- Initialization
make_regexp_validator (r, e: STRING) make (r, e: STRING)
-- Initialize with specified regular expression and error message which will be displayed on validation failure -- Initialize with specified regular expression and error message which will be displayed on validation failure
do do
make (e) make_validator (e)
regexp_string := r regexp_string := r
create regexp create regexp
end end
@@ -9,23 +9,41 @@ class
inherit inherit
WSF_STATELESS_MULTI_CONTROL [WSF_CONTROL] WSF_STATELESS_MULTI_CONTROL [WSF_STATELESS_CONTROL]
rename rename
make as make_multi_control make as make_multi_control
redefine
add_control
end end
WSF_VALIDATABLE WSF_VALIDATABLE
create create
make make, make_with_label_width
feature {NONE} -- Initialization feature {NONE} -- Initialization
make make
-- Initialize -- Initialize
do
make_with_label_width (2)
end
make_with_label_width (w: INTEGER)
do do
make_multi_control make_multi_control
tag_name := "form" tag_name := "form"
label_width := w
end
feature
add_control (c: WSF_STATELESS_CONTROL)
do
Precursor (c)
if attached {WSF_FORM_ELEMENT_CONTROL[ANY]} c as fec then
fec.set_label_width (label_width)
end
end end
feature -- Validation feature -- Validation
@@ -49,4 +67,8 @@ feature -- Validation
is_valid: BOOLEAN is_valid: BOOLEAN
-- Tells whether the last validation was valid -- Tells whether the last validation was valid
feature
label_width: INTEGER
end end
@@ -48,6 +48,13 @@ feature {NONE} -- Initialization
error := "" error := ""
end end
feature
set_label_width (w: INTEGER)
do
label_width := w
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
load_state (new_states: JSON_OBJECT) load_state (new_states: JSON_OBJECT)
@@ -138,9 +145,9 @@ feature -- Implementation
do do
body := "" body := ""
if not label.is_empty then if not label.is_empty then
body.append ("<label class=%"col-lg-2 control-label%" for=%"" + value_control.control_name + "%">" + label + "</label>") body.append ("<label class=%"col-lg-"+label_width.out+" control-label%" for=%"" + value_control.control_name + "%">" + label + "</label>")
end end
body.append ("<div class=%"col-lg-10%">") body.append ("<div class=%"col-lg-"+(12-label_width).out+"%">")
body.append (value_control.render) body.append (value_control.render)
body.append ("</div>") body.append ("</div>")
Result := render_tag (body, "") Result := render_tag (body, "")
@@ -200,4 +207,6 @@ feature -- Properties
error: STRING error: STRING
-- The error message that is displayed when client side validation fails -- The error message that is displayed when client side validation fails
label_width: INTEGER
end end
+2 -2
View File
@@ -359,7 +359,7 @@ class WSF_INPUT_CONTROL extends WSF_CONTROL
if state.text? if state.text?
@state['text'] = state.text @state['text'] = state.text
@$el.val(state.text) @$el.val(state.text)
class WSF_PASSWORD_CONTROL extends WSF_INPUT_CONTROL class WSF_PASSWORD_CONTROL extends WSF_INPUT_CONTROL
class WSF_NAVLIST_ITEM_CONTROL extends WSF_BUTTON_CONTROL class WSF_NAVLIST_ITEM_CONTROL extends WSF_BUTTON_CONTROL
@@ -489,7 +489,7 @@ class WSF_FORM_ELEMENT_CONTROL extends WSF_CONTROL
if message.length>0 if message.length>0
@$el.addClass("has-error") @$el.addClass("has-error")
errordiv = $("<div />").addClass('help-block').addClass('validation').text(message) errordiv = $("<div />").addClass('help-block').addClass('validation').text(message)
@$el.find(".col-lg-10").append(errordiv) @$el.children("div").append(errordiv)
update: (state) -> update: (state) ->
if state.error? if state.error?
+1 -1
View File
@@ -817,7 +817,7 @@ WSF_FORM_ELEMENT_CONTROL = (function(_super) {
if (message.length > 0) { if (message.length > 0) {
this.$el.addClass("has-error"); this.$el.addClass("has-error");
errordiv = $("<div />").addClass('help-block').addClass('validation').text(message); errordiv = $("<div />").addClass('help-block').addClass('validation').text(message);
return this.$el.find(".col-lg-10").append(errordiv); return this.$el.children("div").append(errordiv);
} }
}; };
+4 -4
View File
@@ -35,13 +35,13 @@ feature
--Number 1 --Number 1
create textbox1.make ("1") create textbox1.make ("1")
create n1_container.make ("Number1", textbox1) create n1_container.make ("Number1", textbox1)
n1_container.add_validator (create {WSF_DECIMAL_VALIDATOR}.make_decimal_validator ("Invalid Number")) n1_container.add_validator (create {WSF_DECIMAL_VALIDATOR}.make ("Invalid Number"))
n1_container.add_validator (create {OWN_VALIDATOR}.make_own) n1_container.add_validator (create {OWN_VALIDATOR}.make_own)
form.add_control (n1_container) form.add_control (n1_container)
--Number 2 --Number 2
create textbox2.make ("2") create textbox2.make ("2")
create n2_container.make ("Number2", textbox2) create n2_container.make ("Number2", textbox2)
n2_container.add_validator (create {WSF_DECIMAL_VALIDATOR}.make_decimal_validator ("Invalid Number")) n2_container.add_validator (create {WSF_DECIMAL_VALIDATOR}.make ("Invalid Number"))
form.add_control (n2_container) form.add_control (n2_container)
--Flag autocomplete --Flag autocomplete
create autocompletion1.make (create {FLAG_AUTOCOMPLETION}.make) create autocompletion1.make (create {FLAG_AUTOCOMPLETION}.make)
@@ -61,8 +61,8 @@ feature
cklist.add_control (create {WSF_CHECKBOX_CONTROL}.make ("Operating Systems", "os")) cklist.add_control (create {WSF_CHECKBOX_CONTROL}.make ("Operating Systems", "os"))
cklist.add_control (create {WSF_CHECKBOX_CONTROL}.make ("Formal Methods and Functional Programming", "fmfp")) cklist.add_control (create {WSF_CHECKBOX_CONTROL}.make ("Formal Methods and Functional Programming", "fmfp"))
create cats_container.make ("Categories", cklist) create cats_container.make ("Categories", cklist)
cats_container.add_validator (create {WSF_MIN_VALIDATOR [LIST[STRING]]}.make_min_validator (1, "Choose at least one category")) cats_container.add_validator (create {WSF_MIN_VALIDATOR [LIST[STRING]]}.make (1, "Choose at least one category"))
cats_container.add_validator (create {WSF_MAX_VALIDATOR [LIST[STRING]]}.make_max_validator (2, "Choose at most two category")) cats_container.add_validator (create {WSF_MAX_VALIDATOR [LIST[STRING]]}.make (2, "Choose at most two category"))
form.add_control (cats_container) form.add_control (cats_container)
--Button 1 --Button 1
create button1.make ("Update") create button1.make ("Update")