From bc3e455cbd32d678e217552e54f2c879392955c3 Mon Sep 17 00:00:00 2001 From: Cedric RICARD Date: Sat, 21 Jul 2007 22:20:49 +0000 Subject: [PATCH] Big refactoring to avoid confusion in form element arguments order. --- calexium_lib/web/CXM_generic_form.anubis | 7 ++++--- calexium_lib/web/CXM_making_a_web_site.anubis | 383 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------ 2 files changed, 285 insertions(+), 105 deletions(-) diff --git a/calexium_lib/web/CXM_generic_form.anubis b/calexium_lib/web/CXM_generic_form.anubis index 549bfc3..7563973 100644 --- a/calexium_lib/web/CXM_generic_form.anubis +++ b/calexium_lib/web/CXM_generic_form.anubis @@ -199,8 +199,8 @@ public define HTML_Off_Form --- That's all for the public part ! -------------------------------------------------- - -define HTML_Row(HTML_In_Form) +// TO DO update code of CXM generic form + define HTML_Row(HTML_In_Form) format_form_field ( FormField ff @@ -453,7 +453,8 @@ define HTML_Row(HTML_In_Form) -public define HTML_Off_Form +// TO DO update code of CXM generic form + public define HTML_Off_Form generic_form ( String form_name, diff --git a/calexium_lib/web/CXM_making_a_web_site.anubis b/calexium_lib/web/CXM_making_a_web_site.anubis index c5693cc..3501521 100644 --- a/calexium_lib/web/CXM_making_a_web_site.anubis +++ b/calexium_lib/web/CXM_making_a_web_site.anubis @@ -655,29 +655,132 @@ public type Reading_Way: rtl. //the text is readable from "Right To Left" like arabic +// Following types are define to prohib any arguments order error + +/** + * String value for 'id' attribut + */ +public type HtmlId: + htmlId(String id). + +/** + * String value for 'class' attribut + */ +public type HtmlClass: + htmlClass(String class). + +/** + * Name used in arguments list when form is submitted. + */ +public type WebArgName: + wan(String name). + +/** + * Value passed to arguments list when form is submitted (for RadioButton and CheckBox). + */ +public type WebArgValue: + wav(String value). + +/** + * Initial value of an input field. + */ +public type InitialValue: + init(String value). + +public define Printable_tree [HtmlId x . Printable_tree y] = str_pt(x.id, y). +public define Printable_tree [HtmlClass x . Printable_tree y] = str_pt(x.class, y). +public define Printable_tree [WebArgName x . Printable_tree y] = str_pt(x.name, y). +public define Printable_tree [WebArgValue x . Printable_tree y] = str_pt(x.value, y). +public define Printable_tree [InitialValue x . Printable_tree y] = str_pt(x.value, y). + + +public type HtmlEvents: + // Form element events + onchange, + onsubmit, + onreset, + onselect, + onblur, + onfocus, + // Keyboard events (Not valid in base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, and title elements.) + onkeydown, + onkeypress, + onkeyup, + // Mouse events (Not valid in base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, and title elements.) + onclick, + ondblclick, + onmousedown, + onmousemove, + onmouseout, + onmouseover, + onmouseup. public type CoreAttrs: - id (String), - class (String), - style (String), - title (String). + id (String), + class (String), + style (String), + tooltip (String), + lang (String), + dir (Reading_Way), + accesskey (Word8), + tabindex (Int32), + attr (String, String), + event (HtmlEvents, String). + +public type InputAttrs: + class (String), + style (String), + tooltip (String), + lang (String), + dir (Reading_Way), + accesskey (Word8), + tabindex (Int32), + attr (String, String), + event (HtmlEvents, String). public type I18n: lang (String), dir (Reading_Way). -public type DIV_Option: - id (String), - class (String), - style (String), - title (String), - lang (String), - dir (Reading_Way), - attr (String, String). - +//public type DIV_Option: +// id (String), +// class (String), +// style (String), +// tooltip (String), +// lang (String), +// dir (Reading_Way), +// attr (String, String), +// event (HtmlEvents, String). +// A list of 'DIV_Option' must be given with each DIV you want to put in your page. +define String event_name + ( + HtmlEvents e + ) = + if e is + { + // Form element events + onchange then "onchange", + onsubmit then "onsubmit", + onreset then "onreset", + onselect then "onselect", + onblur then "onblur", + onfocus then "onfocus", + // Keyboard events + onkeydown then "onkeydown", + onkeypress then "onkeypress", + onkeyup then "onkeyup", + // Mouse events + onclick then "onclick", + ondblclick then "ondblclick", + onmousedown then "onmousedown", + onmousemove then "onmousemove", + onmouseout then "onmouseout", + onmouseover then "onmouseover", + onmouseup then "onmouseup" + }. public type Table_Option: background_color(RGB), // applied to all cells in the table @@ -880,9 +983,9 @@ public type HTML_In_Form: foreign_link (List(Text_Option), String url, String name), private_download (String abs_path, String name, String extra_ext, Maybe((String,List((String,String)))) action), - text_input (String label_text, String label, String name, String init, Int32 width), - text_input_ro (String label_text, String label, String name, String init, Int32 width), - password_input (String label_text, String label, String name, Int32 width), + text_input (List(InputAttrs), String label_text, HtmlId id, WebArgName name, InitialValue init, Int32 width), + text_input_ro (List(InputAttrs), String label_text, HtmlId id, WebArgName name, InitialValue init, Int32 width), + password_input (List(InputAttrs), String label_text, HtmlId id, WebArgName name, InitialValue init, Int32 width), text_area (List(TextAreaOption), String name, String init, Int32 width, Int32 height), file_upload (String name, Int32 width), selector (String name, Int32 size, List(String) choices), @@ -892,12 +995,12 @@ public type HTML_In_Form: // code is the web-arg value selector_c (String name, Int32 size, List((String,String)) choices), selector_c (String name, Int32 size, List((String,String)) choices, String selected), - radio_button (String label_text, String label, String name, String value, Bool checked), - radio_button_r (String label_text, String label, String name, String value, Bool checked), - check_box (String label_text, String label, String name, Bool checked), - check_box_r (String label_text, String label, String name, Bool checked), - div (List(DIV_Option), HTML_In_Form content), - div_empty (List(DIV_Option)), + radio_button (List(InputAttrs), String label_text, HtmlId id, WebArgName name, WebArgValue value, Bool checked), + radio_button_r (List(InputAttrs), String label_text, HtmlId id, WebArgName name, WebArgValue value, Bool checked), + check_box (List(InputAttrs), String label_text, HtmlId id, WebArgName name, WebArgValue value, Bool checked), + check_box_r (List(InputAttrs), String label_text, HtmlId id, WebArgName name, WebArgValue value, Bool checked), + div (List(CoreAttrs), HTML_In_Form content), + div_empty (List(CoreAttrs)), hidden (String name, String value). @@ -988,7 +1091,22 @@ public define HTML_In_Form ) = text([],s). - +public define HTML_In_Form + radio_button (List(InputAttrs) options, String label_text, WebArgName n, WebArgValue value, Bool checked) + = radio_button (options, label_text, htmlId(n.name), n, value, checked). + +public define HTML_In_Form + radio_button_r (List(InputAttrs) options, String label_text, WebArgName n, WebArgValue value, Bool checked) + = radio_button_r (options, label_text, htmlId(n.name), n, value, checked). + +public define HTML_In_Form + check_box (List(InputAttrs) options, String label_text, WebArgName n, WebArgValue value, Bool checked) + = check_box (options, label_text, htmlId(n.name), n, value, checked). + +public define HTML_In_Form + check_box_r (List(InputAttrs) options, String label_text, WebArgName n, WebArgValue value, Bool checked) + = check_box_r (options, label_text, htmlId(n.name), n, value, checked). + public type HTML_Off_Form: @@ -1020,8 +1138,8 @@ public type HTML_Off_Form: Maybe((String,List((String,String)))) action), label (String name), form (String form_name, List(CoreAttrs), HTML_In_Form content), - div (List(DIV_Option), HTML_Off_Form content), - div_empty (List(DIV_Option)). + div (List(CoreAttrs), HTML_Off_Form content), + div_empty (List(CoreAttrs)). 'HTML_Off_Form' defines all the elements you may put outside any form. @@ -2241,8 +2359,8 @@ type HTML_Any($T): any_foreign_link (List(Text_Option), String url, String name), any_private_download (String abs_path, String name, String extra_ext, Maybe((String,List((String,String))))), - any_div (List(DIV_Option), $T element), - any_div_empty (List(DIV_Option)), + any_div (List(CoreAttrs), $T element), + any_div_empty (List(CoreAttrs)), any_coreattrs (List(CoreAttrs)). @@ -2761,7 +2879,7 @@ define Printable_tree }. define String - format_coreattrs + format_attrs ( List(CoreAttrs) attributs )= @@ -2771,60 +2889,124 @@ define String [h .t] then with current = if h is { - id(id_name) then - " id=\"" + id_name + "\"", - class(class_name) then - " class=\"" + class_name + "\"", - style(style_string) then - " style=\"" + style_string + "\"", - - title(title_string) then - " title=\"" + title_string + "\"", + id(id_name) then + " id=\"" + id_name + "\"", + class(class_name) then + " class=\"" + class_name + "\"", + style(style_string) then + " style=\"" + style_string + "\"", + + tooltip(title_string) then + " title=\"" + title_string + "\"", + + lang(lang) then + " xml:lang=" + lang, + dir(reading_Way) then + if reading_Way is + { + ltr then " dir=ltr", + rtl then " dir=rtl" + }, + + accesskey(key) then + " accesskey=\"" + key + "\"", + tabindex(index) then + " tabindex=\"" + index + "\"", + + attr(name, value) then + " " + name + "=\"" + value + "\"", + + event(e, value) then + " " + event_name(e) + "=\"" + value + "\"", }, - current + format_coreattrs(t) + current + format_attrs(t) }. define String - _format + format_attrs ( - List(DIV_Option) opt + List(InputAttrs) attributs )= - if opt is + if attributs is { [] then "", [h .t] then with current = if h is { - id(id_name) then - " id=\"" + id_name + "\"", - class(class_name) then - " class=\"" + class_name + "\"", - style(style_string) then - " style=\"" + style_string + "\"", - - title(title_string) then - " title=\"" + title_string + "\"", - lang(lang) then - " xml:lang=" + lang, - dir(reading_Way) then - if reading_Way is - { - ltr then " dir=ltr", - rtl then " dir=rtl" - }, - attr(name, value) then - " " + name + "=\"" + value + "\"" + class(class_name) then + " class=\"" + class_name + "\"", + style(style_string) then + " style=\"" + style_string + "\"", + + tooltip(title_string) then + " title=\"" + title_string + "\"", + + lang(lang) then + " xml:lang=" + lang, + dir(reading_Way) then + if reading_Way is + { + ltr then " dir=ltr", + rtl then " dir=rtl" + }, + + accesskey(key) then + " accesskey=\"" + key + "\"", + tabindex(index) then + " tabindex=\"" + index + "\"", + + attr(name, value) then + " " + name + "=\"" + value + "\"", + + event(e, value) then + " " + event_name(e) + "=\"" + value + "\"", }, - current + _format(t) - } - . + current + format_attrs(t) + }. + +//define String +// _format +// ( +// List(CoreAttrs) opt +// )= +// if opt is +// { +// [] then "", +// [h .t] then +// with current = if h is +// { +// id(id_name) then +// " id=\"" + id_name + "\"", +// class(class_name) then +// " class=\"" + class_name + "\"", +// style(style_string) then +// " style=\"" + style_string + "\"", +// +// title(title_string) then +// " title=\"" + title_string + "\"", +// lang(lang) then +// " xml:lang=" + lang, +// dir(reading_Way) then +// if reading_Way is +// { +// ltr then " dir=ltr", +// rtl then " dir=rtl" +// }, +// attr(name, value) then +// " " + name + "=\"" + value + "\"", +// event(e, value) then +// " " + event_name(e) + "=\"" + value + "\"" +// }, +// current + _format(t) +// } +// . define Printable_tree format_div_option ( - List(DIV_Option) options + List(CoreAttrs) options )= - [""] . + [""] . define Printable_tree @@ -2865,22 +3047,22 @@ define Printable_tree [ if action is { - url(u) then ["", + url(u) then ["", text, "" ], javascript(s,h) then - [s,""] + [s,""] } ], submit(options, text) then [ if action is { - url(u) then ["", + url(u) then ["", text, "" ], javascript(s,h) then - [s,""] + [s,""] } ], @@ -3054,7 +3236,7 @@ define String [h . t] then if h is { - core_attrs(core_attr_list) then format_coreattrs(core_attr_list), + core_attrs(core_attr_list) then format_attrs(core_attr_list), left then " align=left", h_center then " align=center", right then " align=right", @@ -3448,7 +3630,7 @@ define Printable_tree any_div_empty(options) then [format_div_option(options), "\n"], any_coreattrs(attributs) then - [format_coreattrs(attributs)] + [format_attrs(attributs)] }. @@ -3503,18 +3685,15 @@ define Printable_tree format(cinfo,sn,ic_v,any_foreign_link(options,url,name),format_element,is_https), private_download(url,name,extra,action) then format(cinfo,sn,ic_v,any_private_download(url,name,extra,action),format_element,is_https), - text_input(label_text, label, name,i,w) then - [ "", - ""], - //["  "], - text_input_ro(label_text, label, name,i,w) then - [ "", - ""], - //["  "], - password_input(label_text, label, name,w) then - [ "", - ""], - //["  "], + text_input(options, label_text, id, name, i, w) then + [ "", + ""], + text_input_ro(options, label_text, id, name,i,w) then + [ "", + ""], + password_input(options, label_text, id, name,i,w) then + [ "", + ""], text_area(opts,n,i,w,h) then [""], file_upload(n,w) then @@ -3528,18 +3707,18 @@ define Printable_tree selector_c(n,s,cs,sd) then [""], - radio_button(label_text,label,n,v,c) then - [ "", - ""], - radio_button_r(label_text,label,n,v,c) then - [ "", - ""], - check_box(label_text, label,n,c) then - [ if length(label_text) > 0 then "" else "", - ""] - check_box_r(label_text, label,n,c) then - [ "", - if length(label_text) > 0 then "" else "" ] + radio_button(options, label_text, id, n, v, c) then + [ "", + ""], + radio_button_r(options, label_text, id, n, v, c) then + [ "", + ""], + check_box(options, label_text, id, n, v, c) then + [ if length(label_text) > 0 then [""] else [""], + ""] + check_box_r(options, label_text, id, n, v, c) then + [ "", + if length(label_text) > 0 then [""] else [""] ] div(options, e) then format(cinfo,sn,ic_v,any_div(options, e),format_element,is_https), div_empty(options) then @@ -3597,19 +3776,19 @@ define Bool foreign_link(o,u) then false, foreign_link(o,u,n) then false, private_download(p,n,e,a) then false, - text_input(lt,l,n,i,w) then false, - text_input_ro(lt,l,n,i,w) then false, - password_input(lt,l,n,w) then false, + text_input(o,lt,l,n,i,w) then false, + text_input_ro(o,lt,l,n,i,w) then false, + password_input(o,lt,l,n,i,w) then false, text_area(o,n,i,w,h) then false, file_upload(n,w) then true, selector(n,s,c) then false, selector(n,s,c,p) then false, selector_c(n,s,c) then false, selector_c(n,s,c,p) then false, - radio_button(_,_,n,v,c) then false, - radio_button_r(_,_,n,v,c) then false, - check_box(_,_,n,c) then false, - check_box_r(_,_,n,c) then false, + radio_button(o,_,_,n,v,c) then false, + radio_button_r(o,_,_,n,v,c) then false, + check_box(o,_,_,n,v,c) then false, + check_box_r(o,_,_,n,v,c) then false, div(o,c) then false, div_empty(o) then false, hidden(_,_) then false -- libgit2 0.21.4