Commit c0e3a41035b5feeaf9909333483e4c236ce0ec34

Authored by Cédric RICARD
1 parent 49b8cd88

State name is now provided to the 'compute_page' function.

Improving Dojo API
calexium_lib/web/CXM_dojo.anubis
... ... @@ -6,20 +6,21 @@
6 6 *
7 7 */
8 8  
9   -read calexium_lib/web/CXM_making_a_web_site.anubis
  9 +read tools/basis.anubis
10 10 read tools/base64.anubis
11   -read tools/basis.anubis // required for 'make_directory'
12 11 read locale/L3LanguageInfo.anubis
  12 +read system/string.anubis
13 13  
14   -read mailfountain_constants.anubis
15   -read mailfountain_types.anubis
16 14 read calexium_lib/web/CXM_common.anubis
17 15 read calexium_lib/web/CXM_making_a_web_site.anubis
18 16 read calexium_lib/web/CXM_multihost_http_server.anubis
  17 +read calexium_lib/net_services_protocols/logger_service.anubis
  18 +
  19 +read mailfountain_constants.anubis
  20 +read mailfountain_types.anubis
19 21 read common/language_management.anubis
20 22  
21 23 read tools/mf_loggers.anubis
22   -read calexium_lib/net_services_protocols/logger_service.anubis
23 24 read system/logger.anubis
24 25  
25 26 public type Dojo_Grid_Data :
... ... @@ -72,26 +73,132 @@ public define HTML_Off_Form
72 73 // </div><br />")
73 74 ]
74 75 .
  76 +public type DojoGridEditor:
  77 + inputEditor,
  78 + boolEditor,
  79 + selectEditor(List(String) options),
  80 + alwaysOnEditor.
  81 +
  82 +public type DojoGridDefaultColumn:
  83 + dojo_grid_default_column(
  84 + String styles,
  85 + Maybe(String) width,
  86 + Maybe(DojoGridEditor) editor).
  87 +
  88 +public type DojoGridColumn:
  89 + dojo_grid_column( String label,
  90 + String field_name,
  91 + Maybe(String) width,
  92 + Maybe(DojoGridEditor) editor).
  93 +
  94 +public type DojoGridView:
  95 + dojo_grid_view(
  96 + Maybe(DojoGridDefaultColumn) default_column,
  97 + List(DojoGridColumn) columns).
  98 +
  99 +public type DojoGridLayout:
  100 + dojo_grid_layout(
  101 + Maybe(String) selectable_row_header_width,
  102 + List(DojoGridView) views).
  103 +
  104 +define String to_String(DojoGridEditor editor) =
  105 + "editor: " +
  106 + if editor is
  107 + {
  108 + inputEditor then "dojox.grid.editors.Input",
  109 + boolEditor then "dojox.grid.editors.Bool",
  110 + selectEditor(options) then "dojox.grid.editors.Select, options: [" + join(",", map((String o) |-> "\"" + o + "\"", options)) + "]",
  111 + alwaysOnEditor then "dojox.grid.editors.AlwaysOn"
  112 + }.
  113 +
  114 +define String to_String(DojoGridView view) =
  115 + "{ " + (if view.default_column is success(col) then
  116 + (if col is dojo_grid_default_column(styles, mb_width, mb_editor) then
  117 + "defaultCell: {"
  118 + + "styles: \"" + styles + "\""
  119 + + (if mb_width is success(w) then ", width=\"" + w + "\"" else "")
  120 + + (if mb_editor is success(e) then ", " + to_String(e) else "")
  121 + + "}, ")
  122 + else "")
  123 + + "cells: [[" + join(",", map((DojoGridColumn col) |->
  124 + if col is dojo_grid_column(label, field, mb_width, mb_editor) then
  125 + "{"
  126 + + "name: \"" + label + "\""
  127 + + "field: \"" + field + "\""
  128 + + (if mb_width is success(w) then ", width=\"" + w + "\"" else "")
  129 + + (if mb_editor is success(e) then ", " + to_String(e) else "")
  130 + + "}",
  131 + view.columns)) + "]]"
  132 + +"}".
  133 +
  134 +
  135 +public define String
  136 + dojo_make_grid_script
  137 + (
  138 + HtmlId html_id,
  139 + DojoGridLayout layout,
  140 + String layout_name,
  141 + String store_name,
  142 + Bool can_edit
  143 + )
  144 + =
  145 +"<script type=\"text/javascript\">
  146 + " + layout_name + " = ["
  147 + + (if layout.selectable_row_header_width is success(w) then "{ type: 'dojox.GridRowView', width: '" + w + "'}, " else "")
  148 + + join(", ", map(to_String, layout.views))
  149 + + "];
  150 +</script>".
  151 +
  152 +public define HTML_Off_Form
  153 + dojo_make_grid_script
  154 + (
  155 + HtmlId html_id,
  156 + List(String) columns,
  157 + Bool can_edit
  158 + )
  159 + =
  160 + literal(
  161 +"<script type=\"text/javascript\">
  162 + var cols = ["+join(",", map((String col) |-> "\"" + col + "\"", columns)) + "];
  163 + dojo.addOnLoad(function(){
  164 + init_dojo_grid(\""+html_id.id+"\", cols, "+ (if can_edit then "1" else "0")+");
  165 + });
  166 +</script>").
75 167  
76 168 public define HTML_Off_Form
77 169 dojo_grid
78 170 (
79   - String id,
  171 + HtmlId html_id,
  172 + List(CoreAttrs) attributes,
  173 + )
  174 + =
  175 + div_empty([id(html_id.id), attr("dojoType", "dojox.Grid") . attributes ]).
  176 +
  177 +
  178 +public define HTML_Off_Form
  179 + dojo_grid
  180 + (
  181 + HtmlId html_id,
  182 + List(CoreAttrs) attributes,
  183 +// List(GridColumn) columns,
80 184 String colum1,
81 185 String colum2,
82 186 String colum3,
83 187 String colum4,
84   - Bool can_edit
  188 + Bool can_edit
85 189 )
86 190 =
87   - literal("<script type=\"text/javascript\">
88   - dojo.addOnLoad(function(){
89   - init_dojo_grid(\""+colum1+"\",\""+colum2+"\", \""+colum3+"\", \""+colum4+"\", "+ (if can_edit then "1" else "0")+");
90   - }
91   - );
92   - </script>
93   -<div id=\"gridContainer\"></div>")
94   -.
  191 + sequence([
  192 + literal(
  193 +
  194 +"<script type=\"text/javascript\">
  195 + dojo.addOnLoad(function(){
  196 + init_dojo_grid(\""+html_id.id+"\", \""+colum1+"\",\""+colum2+"\", \""+colum3+"\", \""+colum4+"\", "+ (if can_edit then "1" else "0")+");
  197 + });
  198 +</script>"),
  199 + div_empty([id(html_id.id) . attributes /*attr("dojoType", "dojox.Grid"), */]),
  200 + ]).
  201 +//<div id=\"gridContainer\"></div>").
95 202  
96 203  
97 204 public define HTML_Off_Form
... ... @@ -123,83 +230,118 @@ public define HTML_Off_Form
123 230 //actioner(same, same, push_button([id("dojo_tip_" + keyword), class("in"), event(onclick,"new_search(this)")], keyword), "", [], []).
124 231  
125 232  
  233 +public type BorderContainerRegion:
  234 + center,
  235 + top,
  236 + bottom,
  237 + leading,
  238 + trailing,
  239 + left,
  240 + right.
  241 +
  242 +define String
  243 + to_String
  244 + (
  245 + BorderContainerRegion region
  246 + )=
  247 + if region is
  248 + {
  249 + center then "center",
  250 + top then "top",
  251 + bottom then "bottom",
  252 + leading then "leading",
  253 + trailing then "trailing",
  254 + left then "left",
  255 + right then "right"
  256 + }.
  257 +
  258 +
126 259 public define HTML_Off_Form
127 260 dojo_ContentPane
128 261 (
129   - String id,
130   - String region,
131   - Bool splitter,
132   - HTML_Off_Form content
  262 + List(CoreAttrs) attributes,
  263 + BorderContainerRegion region,
  264 + Bool splitter,
  265 + HTML_Off_Form content
133 266 ) =
134   - sequence([
135   - literal("<div id=\"" + id + "\" dojoType=\"dijit.layout.ContentPane\" region=\"" + region + "\" splitter=\""
136   - +(
137   - if splitter then "true"
138   - else "false"
139   - )+
140   - // "\" style=\"overflow: auto;\""+
141   - // "\" minSize=\"20em\""+
142   - "\">"),
143   - content,
144   - literal("</div>")
145   - ]).
  267 + div([ attr("dojoType", "dijit.layout.ContentPane"),
  268 + attr("region", to_String(region)),
  269 + attr("splitter", if splitter then "true" else "false") . attributes ],
  270 + content).
  271 +// sequence([
  272 +// literal("<div id=\"" + id + "\" dojoType=\"dijit.layout.ContentPane\" region=\"" + to_String(region) + "\" splitter=\""
  273 +// +(
  274 +// if splitter then "true"
  275 +// else "false"
  276 +// )+
  277 +// // "\" style=\"overflow: auto;\""+
  278 +// // "\" minSize=\"20em\""+
  279 +// "\">"),
  280 +// content,
  281 +// literal("</div>")
  282 +// ]).
146 283  
147 284 public define HTML_Off_Form
148 285 dojo_TabContainer
149 286 (
150   - String id,
151   - HTML_Off_Form content
  287 + List(CoreAttrs) attributes,
  288 + HTML_Off_Form content
152 289 ) =
153   - sequence([
154   - literal("<div id=\"" + id + "\" dojoType=\"dijit.layout.TabContainer\" style=\"width:70em;height:50em\">"),
155   - content,
156   - literal("</div>")
157   - ]).
  290 + div([attr("dojoType", "dijit.layout.TabContainer") . attributes ],
  291 + content).
  292 +// sequence([
  293 +// literal("<div id=\"" + id + "\" dojoType=\"dijit.layout.TabContainer\" style=\"width:70em;height:50em\">"),
  294 +// content,
  295 +// literal("</div>")
  296 +// ]).
158 297  
159 298 public define HTML_Off_Form
160 299 dojo_BorderContainer
161 300 (
162   - String id,
163   - String title,
164   - HTML_Off_Form content
  301 + List(CoreAttrs) attributes,
  302 + String the_title,
  303 + Bool live_splitter,
  304 + Bool persist,
  305 + HTML_Off_Form content
165 306 ) =
166   - sequence([
167   - literal("<div id=\"" + id + "\" dojoType=\"dijit.layout.BorderContainer\" title=\"" + title + "\" design=\"sidebar\">"),
168   - content,
169   - literal("</div>")
170   - ]).
  307 + div([attr("dojoType", "dijit.layout.BorderContainer"), title(the_title),
  308 + attr("design", "sidebar"), attr("liveSplitters", live_splitter), attr("persist", persist) . attributes ],
  309 + content).
171 310  
172 311  
173 312 public define HTML_Off_Form
174 313 dojo_tree
175 314 (
176   - String id,
  315 + List(CoreAttrs) attributes,
177 316 )=
178   - literal("<div id=\"" + id + "\"</div>").
  317 + div_empty(attributes).
  318 +// literal("<div id=\"" + id + "\"</div>").
179 319  
180 320  
181 321 public define HTML_Off_Form
182 322 dojo_Toolbar
183 323 (
184   - String id,
  324 + List(CoreAttrs) attributes,
185 325 HTML_Off_Form content
186 326 )=
187   - sequence([
188   - literal("<div dojoType=\"dijit.Toolbar\" region=\"top\" id =\"" + id + "\">"),
189   - content,
190   - literal("</div>")
191   - ]).
  327 + div([attr("dojoType", "dijit.Toolbar") . attributes ],
  328 + content).
  329 +// sequence([
  330 +// literal("<div dojoType=\"dijit.Toolbar\" region=\"top\" id =\"" + id + "\">"),
  331 +// content,
  332 +// literal("</div>")
  333 +// ]).
192 334  
193 335  
194 336 public define HTML_Off_Form
195 337 dojo_button
196 338 (
197   - String id,
  339 + HtmlId html_id,
198 340 String name,
199 341 String iconclass,
200 342 String tip_msg,
201 343 )
202 344 =
203 345 literal("
204   - <button dojoType=\"dijit.form.Button\" id=\"" + id + "\" iconClass=\"" + iconclass + "\">" + name + "</button>
205   - <span dojoType=\"dijit.Tooltip\" connectId=\"" + id + "\">" + tip_msg + "</span>").
  346 + <button dojoType=\"dijit.form.Button\" id=\"" + html_id.id + "\" iconClass=\"" + iconclass + "\">" + name + "</button>
  347 + <span dojoType=\"dijit.Tooltip\" connectId=\"" + html_id.id + "\">" + tip_msg + "</span>").
... ...
calexium_lib/web/CXM_making_a_web_site.anubis
... ... @@ -439,7 +439,7 @@ public define Web_Site
439 439 List(Web_arg),
440 440 Bool is_https) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) ticket_lost_state,
441 441 List(Web_Action($SessionTicket, $State)) actions,
442   - (Maybe($SessionTicket), Maybe($State), List(Web_arg) lwa) -> HTTP_Answer compute_page,
  442 + (Maybe($SessionTicket), Maybe($State), String state_name, List(Web_arg) lwa) -> HTTP_Answer compute_page,
443 443 Int timeout, // seconds (todo: minutes)
444 444 List(Redirection) redirections,
445 445 String charset,
... ... @@ -734,6 +734,8 @@ public type CoreAttrs:
734 734 attr (String, String),
735 735 event (HtmlEvents, String).
736 736  
  737 +public define CoreAttrs attr(String name, Bool value) = attr(name, if value then "true" else "false").
  738 +
737 739 public type InputAttrs:
738 740 class (String),
739 741 style (String),
... ... @@ -745,6 +747,8 @@ public type InputAttrs:
745 747 attr (String, String),
746 748 event (HtmlEvents, String).
747 749  
  750 +public define InputAttrs attr(String name, Bool value) = attr(name, if value then "true" else "false").
  751 +
748 752 public define CoreAttrs
749 753 tooltip(String s) = title(s).
750 754 public define InputAttrs
... ... @@ -2219,7 +2223,7 @@ public define Web_Site
2219 2223 List(Web_arg),
2220 2224 Bool is_https) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) ticket_lost_state,
2221 2225 List(Web_Action($SessionTicket, $State)) actions,
2222   - (Maybe($SessionTicket), Maybe($State), List(Web_arg) lwa) -> HTTP_Answer compute_page,
  2226 + (Maybe($SessionTicket), Maybe($State), String state_name, List(Web_arg) lwa) -> HTTP_Answer compute_page,
2223 2227 Int timeout,
2224 2228 Redirections redirections,
2225 2229 String charset,
... ... @@ -2295,7 +2299,7 @@ public define Web_Site
2295 2299 format(info(host_name, http_port, https_port, site_directory, secret),
2296 2300 state_name,
2297 2301 headers,
2298   - compute_page(session_ticket, mb_new_state, operands),
  2302 + compute_page(session_ticket, mb_new_state, state_name, operands),
2299 2303 is_https,
2300 2304 charset)
2301 2305 }),
... ...