Commit c52d284587dad39927b87e57cc1547a8bf6927e3
1 parent
cd4c85fc
+ Add on_change function on immediate selector.
+ Merge all immediate_selector together and create some immediate_selector function with less argument. These functions call the master function with default value for the arguments which are removed from the call + Add HTML_partial_content to HTTP_answer. This allow to send small part of html without body and header. Need for Ajax call + Change the HTML DOCTYPE from old xhtml to html 5 + Add autoOpen argument on jq_dialog_create
Showing
2 changed files
with
133 additions
and
49 deletions
Show diff stats
web/CXM_making_a_web_site.anubis
| @@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
| 11 | *Authors* Alain Prouté | 11 | *Authors* Alain Prouté |
| 12 | David René | 12 | David René |
| 13 | Jérémy Larrieu | 13 | Jérémy Larrieu |
| 14 | - Julien Vernueil | 14 | + Julien Verneuil |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | *Revised* May 2015 | 17 | *Revised* May 2015 |
| @@ -956,10 +956,35 @@ public type Actioner_Aspect: | @@ -956,10 +956,35 @@ public type Actioner_Aspect: | ||
| 956 | button (String url_off, String url_on), // rollover button | 956 | button (String url_off, String url_on), // rollover button |
| 957 | button (String url_off, String url_on, Int w, Int h), // idem with size | 957 | button (String url_off, String url_on, Int w, Int h), // idem with size |
| 958 | submit (List(CoreAttrs),String text), | 958 | submit (List(CoreAttrs),String text), |
| 959 | - immediate_selector (List(CoreAttrs),WebArgName name, Int size, List((List(CoreAttrs),WebArgValue,String)) choices), | ||
| 960 | - immediate_selector (List(CoreAttrs),WebArgName name, Int size, List((List(CoreAttrs),WebArgValue,String)) choices, InitialValue selected), | 959 | +// immediate_selector (List(CoreAttrs),WebArgName name, Int size, List((List(CoreAttrs),WebArgValue,String)) choices), |
| 960 | +// immediate_selector (List(CoreAttrs),WebArgName name, Int size, List((List(CoreAttrs),WebArgValue,String)) choices, InitialValue selected), | ||
| 961 | + immediate_selector (List(CoreAttrs),WebArgName name, Int size, List((List(CoreAttrs),WebArgValue,String)) choices, Maybe(InitialValue) selected, String onchange_fn), | ||
| 962 | + | ||
| 961 | html (HTML_Off_Form). | 963 | html (HTML_Off_Form). |
| 962 | 964 | ||
| 965 | +public define Actioner_Aspect | ||
| 966 | + immediate_selector | ||
| 967 | + ( | ||
| 968 | + List(CoreAttrs) core_attrs, | ||
| 969 | + WebArgName name, | ||
| 970 | + Int size, | ||
| 971 | + List((List(CoreAttrs),WebArgValue,String)) choices | ||
| 972 | + )= | ||
| 973 | + immediate_selector(core_attrs, name, size, choices, failure, "") | ||
| 974 | + . | ||
| 975 | + | ||
| 976 | +public define Actioner_Aspect | ||
| 977 | + immediate_selector | ||
| 978 | + ( | ||
| 979 | + List(CoreAttrs) core_attrs, | ||
| 980 | + WebArgName name, | ||
| 981 | + Int size, | ||
| 982 | + List((List(CoreAttrs),WebArgValue,String)) choices, | ||
| 983 | + Maybe(InitialValue) selected | ||
| 984 | + )= | ||
| 985 | + immediate_selector(core_attrs, name, size, choices, selected, "") | ||
| 986 | + . | ||
| 987 | + | ||
| 963 | 988 | ||
| 964 | public type Actioner_Local_Action: | 989 | public type Actioner_Local_Action: |
| 965 | close_window. | 990 | close_window. |
| @@ -1652,7 +1677,9 @@ public type HTTP_Answer: | @@ -1652,7 +1677,9 @@ public type HTTP_Answer: | ||
| 1652 | Printable_tree /*content*/), | 1677 | Printable_tree /*content*/), |
| 1653 | http_raw (Printable_tree), | 1678 | http_raw (Printable_tree), |
| 1654 | html_content (HTTP_Status /*http_status*/, | 1679 | html_content (HTTP_Status /*http_status*/, |
| 1655 | - HTML_Off_Form). | 1680 | + HTML_Off_Form), |
| 1681 | + html_partial_content (HTTP_Status /*http_status*/, | ||
| 1682 | + HTML_Partial_Content). | ||
| 1656 | 1683 | ||
| 1657 | 1684 | ||
| 1658 | public define HTTP_Answer | 1685 | public define HTTP_Answer |
| @@ -1882,13 +1909,13 @@ define Printable_tree | @@ -1882,13 +1909,13 @@ define Printable_tree | ||
| 1882 | public define String | 1909 | public define String |
| 1883 | doctype_w3c_header | 1910 | doctype_w3c_header |
| 1884 | = | 1911 | = |
| 1885 | - "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" "+ | ||
| 1886 | - "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n". | 1912 | + "<!DOCTYPE html>\n". //html 5 |
| 1887 | 1913 | ||
| 1888 | -public define String | ||
| 1889 | - html_header | ||
| 1890 | - = | ||
| 1891 | - "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n". | 1914 | +// No longer used in HTML 5 |
| 1915 | +//public define String | ||
| 1916 | +// html_header | ||
| 1917 | +// = | ||
| 1918 | +// "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n". | ||
| 1892 | 1919 | ||
| 1893 | 1920 | ||
| 1894 | *** [1] States. | 1921 | *** [1] States. |
| @@ -3064,10 +3091,10 @@ public define Printable_tree | @@ -3064,10 +3091,10 @@ public define Printable_tree | ||
| 3064 | 3091 | ||
| 3065 | public define Printable_tree | 3092 | public define Printable_tree |
| 3066 | format_choices | 3093 | format_choices |
| 3067 | - ( | ||
| 3068 | - List(String) l, | ||
| 3069 | - InitialValue selected | ||
| 3070 | - ) = | 3094 | + ( |
| 3095 | + List(String) l, | ||
| 3096 | + InitialValue selected | ||
| 3097 | + ) = | ||
| 3071 | if l is | 3098 | if l is |
| 3072 | { | 3099 | { |
| 3073 | [ ] then [ ], | 3100 | [ ] then [ ], |
| @@ -3483,8 +3510,8 @@ define Maybe(String) | @@ -3483,8 +3510,8 @@ define Maybe(String) | ||
| 3483 | button(_,_) then failure, | 3510 | button(_,_) then failure, |
| 3484 | button(_,_,_,_) then failure, | 3511 | button(_,_,_,_) then failure, |
| 3485 | submit(opts,_) then extract_id(opts), | 3512 | submit(opts,_) then extract_id(opts), |
| 3486 | - immediate_selector(_,_,_,_) then failure, | ||
| 3487 | - immediate_selector(_,_,_,_,_) then failure, | 3513 | + //immediate_selector(_,_,_,_) then failure, |
| 3514 | + immediate_selector(_,_,_,_,_,_) then failure, | ||
| 3488 | html(_) then failure, | 3515 | html(_) then failure, |
| 3489 | }. | 3516 | }. |
| 3490 | 3517 | ||
| @@ -3541,9 +3568,9 @@ define Printable_tree | @@ -3541,9 +3568,9 @@ define Printable_tree | ||
| 3541 | submit(options, text) then | 3568 | submit(options, text) then |
| 3542 | [ ], | 3569 | [ ], |
| 3543 | 3570 | ||
| 3544 | - immediate_selector(opt,name,size,choices) then | ||
| 3545 | - [ ], | ||
| 3546 | - immediate_selector(opt,name,size,choices,selected) then | 3571 | + //immediate_selector(opt,name,size,choices) then |
| 3572 | + // [ ], | ||
| 3573 | + immediate_selector(opt,name,size,choices,selected,function) then | ||
| 3547 | [ ], | 3574 | [ ], |
| 3548 | html(html_off_form) then | 3575 | html(html_off_form) then |
| 3549 | [ | 3576 | [ |
| @@ -3647,23 +3674,29 @@ define Printable_tree | @@ -3647,23 +3674,29 @@ define Printable_tree | ||
| 3647 | } | 3674 | } |
| 3648 | ], | 3675 | ], |
| 3649 | 3676 | ||
| 3650 | - immediate_selector(options,name,size,choices) then | ||
| 3651 | - [ if action is | ||
| 3652 | - { | ||
| 3653 | - url(u) then ["<select href=\"",u] | ||
| 3654 | - javascript(s,h) then [s,"<select onchange=\"",h] | ||
| 3655 | - }, | ||
| 3656 | - "\" name=\"",name,"\" size=\"",size,"\"", format_attrs(options), ">", | ||
| 3657 | - format_choices(choices),"</select>" | ||
| 3658 | - ], | ||
| 3659 | - immediate_selector(options,name,size,choices,selected) then | ||
| 3660 | - [ if action is | 3677 | +// immediate_selector(options,name,size,choices) then |
| 3678 | +// [ if action is | ||
| 3679 | +// { | ||
| 3680 | +// url(u) then ["<select href=\"",u] | ||
| 3681 | +// javascript(s,h) then [s,"<select onchange=\"",h] | ||
| 3682 | +// }, | ||
| 3683 | +// "\" name=\"",name,"\" size=\"",size,"\"", format_attrs(options), ">", | ||
| 3684 | +// format_choices(choices),"</select>" | ||
| 3685 | +// ], | ||
| 3686 | + immediate_selector(options, name, size, choices, mb_selected, custom_function_name) then | ||
| 3687 | + [ | ||
| 3688 | + //if custom function name is provided, that name is used instead of autogenerated js function | ||
| 3689 | + if custom_function_name = "" then | ||
| 3690 | + if action is | ||
| 3661 | { | 3691 | { |
| 3662 | url(u) then ["<select href=\"",u] | 3692 | url(u) then ["<select href=\"",u] |
| 3663 | javascript(s,h) then [s,"<select onchange=\"",h] | 3693 | javascript(s,h) then [s,"<select onchange=\"",h] |
| 3664 | - }, | 3694 | + } |
| 3695 | + else | ||
| 3696 | + ["<select onchange=\"",custom_function_name], | ||
| 3697 | + | ||
| 3665 | "\" name=\"",name,"\" size=\"",size,"\"", format_attrs(options), ">", | 3698 | "\" name=\"",name,"\" size=\"",size,"\"", format_attrs(options), ">", |
| 3666 | - format_choices(choices, selected),"</select>" | 3699 | + if mb_selected is success(selected) then format_choices(choices, selected) else format_choices(choices),"</select>" |
| 3667 | ], | 3700 | ], |
| 3668 | html(html_off_form) then | 3701 | html(html_off_form) then |
| 3669 | [ | 3702 | [ |
| @@ -4663,8 +4696,8 @@ define Printable_tree | @@ -4663,8 +4696,8 @@ define Printable_tree | ||
| 4663 | = | 4696 | = |
| 4664 | if lwf is | 4697 | if lwf is |
| 4665 | { | 4698 | { |
| 4666 | - [] then reverse(so_far), | ||
| 4667 | - [ h . t] then | 4699 | + [] then reverse(so_far), |
| 4700 | + [ h . t] then | ||
| 4668 | if h is | 4701 | if h is |
| 4669 | { | 4702 | { |
| 4670 | meta(meta) then | 4703 | meta(meta) then |
| @@ -4693,15 +4726,16 @@ public define Printable_tree | @@ -4693,15 +4726,16 @@ public define Printable_tree | ||
| 4693 | String charset | 4726 | String charset |
| 4694 | ) | 4727 | ) |
| 4695 | = | 4728 | = |
| 4696 | - with lwf = (List(HTML_Head_Tag))[ meta(http_equiv("content-type", "text/html; charset="+charset)) . lwf], | ||
| 4697 | - if lwf is | ||
| 4698 | - { | ||
| 4699 | - [] then | ||
| 4700 | - [], | ||
| 4701 | - [ h . t] then | ||
| 4702 | - _format_html_head(lwf, []) | ||
| 4703 | - } | ||
| 4704 | - . | 4729 | + _format_html_head((List(HTML_Head_Tag))[ meta(http_equiv("content-type", "text/html; charset="+charset)) . lwf], []). |
| 4730 | + | ||
| 4731 | +public define Printable_tree | ||
| 4732 | + format_html_head | ||
| 4733 | + ( | ||
| 4734 | + List(HTML_Head_Tag) lwf | ||
| 4735 | + ) | ||
| 4736 | + = | ||
| 4737 | + _format_html_head(lwf, []). | ||
| 4738 | + | ||
| 4705 | 4739 | ||
| 4706 | public type HTML_ajax_content: | 4740 | public type HTML_ajax_content: |
| 4707 | html_ajax_content( String html_body, String script, List(String) js_file, List(String) css_file). | 4741 | html_ajax_content( String html_body, String script, List(String) js_file, List(String) css_file). |
| @@ -4748,6 +4782,12 @@ public define HTML_ajax_content | @@ -4748,6 +4782,12 @@ public define HTML_ajax_content | ||
| 4748 | CommonInfo cinfo | 4782 | CommonInfo cinfo |
| 4749 | )= to_html_ajax_content(content_HTML, cinfo, ""). | 4783 | )= to_html_ajax_content(content_HTML, cinfo, ""). |
| 4750 | 4784 | ||
| 4785 | +public define HTML_ajax_content | ||
| 4786 | + to_html_ajax_content | ||
| 4787 | + ( | ||
| 4788 | + HTML_Partial_Content content_HTML, | ||
| 4789 | + CommonInfo cinfo | ||
| 4790 | + )= to_html_ajax_content(partial(content_HTML), cinfo, ""). | ||
| 4751 | 4791 | ||
| 4752 | public define Printable_tree | 4792 | public define Printable_tree |
| 4753 | format | 4793 | format |
| @@ -4776,7 +4816,7 @@ public define Printable_tree | @@ -4776,7 +4816,7 @@ public define Printable_tree | ||
| 4776 | "</html>"], | 4816 | "</html>"], |
| 4777 | answer_body_header = | 4817 | answer_body_header = |
| 4778 | [doctype_w3c_header, | 4818 | [doctype_w3c_header, |
| 4779 | - html_header, | 4819 | + // html_header, |
| 4780 | 4820 | ||
| 4781 | "<head>\n", format_html_head(head_tags + *p_content_head_tags, charset),"</head>\n", | 4821 | "<head>\n", format_html_head(head_tags + *p_content_head_tags, charset),"</head>\n", |
| 4782 | ], | 4822 | ], |
| @@ -4795,7 +4835,7 @@ public define Printable_tree | @@ -4795,7 +4835,7 @@ public define Printable_tree | ||
| 4795 | if format(status) is (status_string, status_headers) then | 4835 | if format(status) is (status_string, status_headers) then |
| 4796 | with answer_body = | 4836 | with answer_body = |
| 4797 | [ doctype_w3c_header, | 4837 | [ doctype_w3c_header, |
| 4798 | - html_header, | 4838 | + //html_header, |
| 4799 | "<head>\n", | 4839 | "<head>\n", |
| 4800 | add_css_styles(css_styles), | 4840 | add_css_styles(css_styles), |
| 4801 | add_css_files(css_files), | 4841 | add_css_files(css_files), |
| @@ -4889,5 +4929,29 @@ public define Printable_tree | @@ -4889,5 +4929,29 @@ public define Printable_tree | ||
| 4889 | crlf . | 4929 | crlf . |
| 4890 | content | 4930 | content |
| 4891 | ], | 4931 | ], |
| 4932 | + //HMTL content with some header | ||
| 4933 | + html_partial_content(HTTP_Status status, HTML_Partial_Content p_content) then | ||
| 4934 | + | ||
| 4935 | + since p_content is partial_content(head_tags, html_content), | ||
| 4936 | + since format(status) is (status_string, status_headers), | ||
| 4937 | + with | ||
| 4938 | + answer_body = (Printable_tree) | ||
| 4939 | + [ | ||
| 4940 | + format(cinfo, state_name, ic_v, html_content, is_https, var(0), p_content_head_tags), | ||
| 4941 | + ], | ||
| 4942 | + answer_header = (Printable_tree) | ||
| 4943 | + [ | ||
| 4944 | + // html_header, | ||
| 4945 | + format_html_head(head_tags + *p_content_head_tags), | ||
| 4946 | + ], | ||
| 4947 | + [ "HTTP/1.1 " + status_string, crlf, | ||
| 4948 | + format_headers(standard_headers), | ||
| 4949 | + format_headers(standard_headers_for("text/html", length(answer_header) + length(answer_body), success(charset))), | ||
| 4950 | + format_headers(status_headers), | ||
| 4951 | + format_headers(additional_headers), | ||
| 4952 | + crlf, | ||
| 4953 | + answer_header . | ||
| 4954 | + answer_body | ||
| 4955 | + ], | ||
| 4892 | }. | 4956 | }. |
| 4893 | 4957 |
web/jQuery/CXM_jquery_dialog.anubis
| @@ -6,6 +6,7 @@ | @@ -6,6 +6,7 @@ | ||
| 6 | * © Calexium | 6 | * © Calexium |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | +read system/convert.anubis | ||
| 9 | read calexium_lib/web/CXM_making_a_web_site.anubis | 10 | read calexium_lib/web/CXM_making_a_web_site.anubis |
| 10 | read calexium_lib/web/CXM_jquery.anubis | 11 | read calexium_lib/web/CXM_jquery.anubis |
| 11 | 12 | ||
| @@ -23,16 +24,17 @@ public define HTML_Partial_Content | @@ -23,16 +24,17 @@ public define HTML_Partial_Content | ||
| 23 | ( | 24 | ( |
| 24 | JQuery_dialog_id dial_id, | 25 | JQuery_dialog_id dial_id, |
| 25 | JQuery_dialog content, | 26 | JQuery_dialog content, |
| 26 | - String extra_parm | 27 | + Bool autoOpen, |
| 28 | + String extra_param | ||
| 27 | )= | 29 | )= |
| 28 | with dlg_id = id(dial_id), | 30 | with dlg_id = id(dial_id), |
| 29 | js = js_inline(jquery_ready(" | 31 | js = js_inline(jquery_ready(" |
| 30 | $( \"#"+dlg_id+"\" ).dialog({ | 32 | $( \"#"+dlg_id+"\" ).dialog({ |
| 31 | - autoOpen: false, | 33 | + autoOpen: "+to_String(autoOpen)+", |
| 32 | modal: true, | 34 | modal: true, |
| 33 | height: 'auto', | 35 | height: 'auto', |
| 34 | width: 'auto', | 36 | width: 'auto', |
| 35 | - "+extra_parm+" | 37 | + "+extra_param+" |
| 36 | Cancel: function() { | 38 | Cancel: function() { |
| 37 | $( this ).dialog( 'close' ); | 39 | $( this ).dialog( 'close' ); |
| 38 | } | 40 | } |
| @@ -49,6 +51,15 @@ public define HTML_Partial_Content | @@ -49,6 +51,15 @@ public define HTML_Partial_Content | ||
| 49 | ajax(url) then | 51 | ajax(url) then |
| 50 | partial_content( [js], div_empty([id(dlg_id), attr("ajax_url",url)])) | 52 | partial_content( [js], div_empty([id(dlg_id), attr("ajax_url",url)])) |
| 51 | }. | 53 | }. |
| 54 | + | ||
| 55 | +public define HTML_Partial_Content | ||
| 56 | + jq_dialog_create | ||
| 57 | + ( | ||
| 58 | + JQuery_dialog_id dial_id, | ||
| 59 | + JQuery_dialog content, | ||
| 60 | + String extra_param | ||
| 61 | + )= | ||
| 62 | + jq_dialog_create(dial_id, content, false, extra_param). | ||
| 52 | 63 | ||
| 53 | public define HTML_Partial_Content | 64 | public define HTML_Partial_Content |
| 54 | jq_dialog_create | 65 | jq_dialog_create |
| @@ -56,8 +67,17 @@ public define HTML_Partial_Content | @@ -56,8 +67,17 @@ public define HTML_Partial_Content | ||
| 56 | JQuery_dialog_id dial_id, | 67 | JQuery_dialog_id dial_id, |
| 57 | JQuery_dialog content | 68 | JQuery_dialog content |
| 58 | )= | 69 | )= |
| 59 | - jq_dialog_create(dial_id, content, ""). | 70 | + jq_dialog_create(dial_id, content, false, ""). |
| 60 | 71 | ||
| 72 | +public define HTML_Partial_Content | ||
| 73 | + jq_dialog_create | ||
| 74 | + ( | ||
| 75 | + JQuery_dialog_id dial_id, | ||
| 76 | + JQuery_dialog content, | ||
| 77 | + Bool autoOpen | ||
| 78 | + )= | ||
| 79 | + jq_dialog_create(dial_id, content, autoOpen, ""). | ||
| 80 | + | ||
| 61 | define String | 81 | define String |
| 62 | _jq_dialog_open | 82 | _jq_dialog_open |
| 63 | ( | 83 | ( |