/* * Created by PyramIDE. * User: Steve Marechal * Date: 11/06/2008 * Time: 09:54 * */ read tools/basis.anubis read tools/base64.anubis read locale/L3LanguageInfo.anubis read system/string.anubis read system/logger.anubis read calexium_lib/web/CXM_common.anubis read calexium_lib/web/CXM_making_a_web_site.anubis read calexium_lib/web/CXM_multihost_http_server.anubis read calexium_lib/net_services_protocols/logger_service.anubis public type Dojo_Grid_Data : grid_data(String). public type Position_Direction: brup, brleft, blup, blright, trdown, trleft, tldown, tlright. define String pos_dir_to_str ( Position_Direction pos )= if pos is { brup then "br-up", brleft then "br-left", blup then "bl-up", blright then "bl-right", trdown then "tr-down", trleft then "tr-left", tldown then "tl-down", tlright then "tl-right" }. public define HTML_Off_Form dojo_button ( String name, String execute, String id, ) = literal(" ") . public type Input_Type: file, text, password. public type InputDial: input_dial(HtmlId id, Input_Type input_type, String label, Maybe(String) class), input_date(HtmlId id, String label), input_combo(HtmlId id, String label, List((List(CoreAttrs), WebArgValue, String)) list_data), input_check(HtmlId id, String label, Bool checked), input_hidden(HtmlId id, WebArgValue value). define List(HTML_Off_Form) format_list_data ( List((List(CoreAttrs), WebArgValue, String)) list_data, List(HTML_Off_Form) result_list )= if list_data is { [] then result_list, [h . t] then if h is (_, wa, label) then format_list_data(t, [literal("") . result_list]) }. public define HTML_Off_Form dojo_combobox ( WebArgName the_name, HtmlId the_id, String label, List((List(CoreAttrs), WebArgValue, String)) list_data, )= sequence([ literal(" ") ]). define HTML_Off_Form _maybe_label ( String label_text, HtmlId html_id ) = if length(label_text) > 0 then literal("") else literal(""). public define HTML_Off_Form dojo_checkbox ( WebArgName the_name, HtmlId the_id, String label, WebArgValue val, Bool checked, )= sequence([ _maybe_label(label, the_id), literal(""), ]). define HTML_Off_Form input_in_dialog ( InputDial input_data )= if input_data is { input_dial(html_id, input, label, class) then sequence([ literal("
"), literal("
") ]), input_date(html_id, label) then sequence([ literal("
"), literal("
" ) ]), input_combo(the_id, label, list_data) then sequence([ literal("
"), dojo_combobox(wan(the_id.id), the_id, label, list_data), literal("
") ]), input_check(the_id, label, checked) then sequence([ literal("
"), dojo_checkbox(wan(the_id.id), the_id, label, wav("1"), checked), literal("
"), ]), input_hidden(the_id, val) then literal(""), } . define List(HTML_Off_Form) inputs_in_dialog ( List(InputDial) inputs_data )= if inputs_data is { [] then [], [h . t] then [input_in_dialog(h) . inputs_in_dialog(t)] }. public define HTML_Off_Form dijit_dialog ( String name, String dialog_id, String execute, String ok_label, Maybe(String) cancel, List(InputDial) inputs_data, Maybe(String) do_cancel ) = sequence([ div([attr("dojoType", "dijit.Dialog"), id(dialog_id), title(name), attr("execute", execute)], sequence([ sequence(inputs_in_dialog(inputs_data)), literal("" + if cancel is { failure then "", success(cancel_label) then "" }), literal("
") ]) ) ]) . public define HTML_Off_Form dojo_dialog ( String name, String dialog_id, String execute, String ok_label, Maybe(String) cancel, List(InputDial) inputs_data, Maybe(String) do_cancel ) = sequence[ dojo_button(name,"dijit.byId('"+dialog_id+"').show()", dialog_id + "_button"), dijit_dialog(name, dialog_id, execute, ok_label, cancel, inputs_data, do_cancel) ] . public type DojoGridEditor: inputEditor, boolEditor, selectEditor(List(String) options), alwaysOnEditor. public type DojoGridDefaultColumn: dojo_grid_default_column( String styles, Maybe(String) width, Maybe(DojoGridEditor) editor). public type DojoGridColumn: dojo_grid_column( String label, String field_name, Maybe(String) width, Maybe(DojoGridEditor) editor). public type DojoGridView: dojo_grid_view( Maybe(DojoGridDefaultColumn) default_column, List(DojoGridColumn) columns). public type DojoGridLayout: dojo_grid_layout( Maybe(String) selectable_row_header_width, List(DojoGridView) views). define String to_String(DojoGridEditor editor) = "editor: " + if editor is { inputEditor then "dojox.grid.editors.Input", boolEditor then "dojox.grid.editors.Bool", selectEditor(options) then "dojox.grid.editors.Select, options: [" + join(",", map((String o) |-> "\"" + o + "\"", options)) + "]", alwaysOnEditor then "dojox.grid.editors.AlwaysOn" }. define String to_String(DojoGridView view) = "{ " + (if view.default_column is success(col) then (if col is dojo_grid_default_column(styles, mb_width, mb_editor) then "defaultCell: {" + "styles: \"" + styles + "\"" + (if mb_width is success(w) then ", width=\"" + w + "\"" else "") + (if mb_editor is success(e) then ", " + to_String(e) else "") + "}, ") else "") + "cells: [[" + join(",", map((DojoGridColumn col) |-> if col is dojo_grid_column(label, field, mb_width, mb_editor) then "{" + "name: \"" + label + "\"" + "field: \"" + field + "\"" + (if mb_width is success(w) then ", width=\"" + w + "\"" else "") + (if mb_editor is success(e) then ", " + to_String(e) else "") + "}", view.columns)) + "]]" +"}". public define String dojo_make_grid_script ( HtmlId html_id, DojoGridLayout layout, String layout_name, String store_name, Bool can_edit ) = "". public define HTML_Off_Form dojo_make_grid_script ( HtmlId html_id, List(String) columns, Bool can_edit ) = literal( ""). public define HTML_Off_Form dojo_grid ( HtmlId html_id, Int rowsPerPage, List(Table_Option) attributes, )= table([attr("dojoType", "dojox.grid.DataGrid"), attr("id", html_id.id), attr("jsId", html_id.id), class("soria"), attr("singleClickEdit", "true"), attr("rowsPerPage", to_decimal(rowsPerPage)) . attributes], empty, [], empty). public define HTML_Off_Form dojo_grid ( HtmlId html_id, List(CoreAttrs) attributes, // List(GridColumn) columns, String colum1, String colum2, String colum3, String colum4, Bool can_edit ) = sequence([ literal( ""), div_empty([id(html_id.id) . attributes /*attr("dojoType", "dojox.Grid"), */]), ]). //
"). public define HTML_Off_Form dojo_message_box ( HTML_Off_Form name1, HTML_Off_Form name2, ) = sequence([ literal("
"), div([class("message_box")], sequence([ div([id("node3"), class("box nopad hidden")], name1), div([id("node4"), class("box two nopad")], name2), ])), literal("
"), ]). public define HTML_Off_Form dojo_tooltip ( String title, String keyword, ) = actioner(same,same, link([id("dojo_tip_" + keyword),class("dojoToolTip")],title, success(title)), "show_address_mailing", [("address_mailing", keyword)], []). //actioner(same, same, push_button([id("dojo_tip_" + keyword), class("in"), event(onclick,"new_search(this)")], keyword), "", [], []). public type BorderContainerRegion: center, top, bottom, leading, trailing, left, right. define String to_String ( BorderContainerRegion region )= if region is { center then "center", top then "top", bottom then "bottom", leading then "leading", trailing then "trailing", left then "left", right then "right" }. public type BorderContainerDesign: headline, sidebar. define String to_String ( BorderContainerDesign design )= if design is { headline then "headline", sidebar then "sidebar" }. public define HTML_Off_Form dojo_ContentPane ( List(CoreAttrs) attributes, BorderContainerRegion region, Bool splitter, HTML_Off_Form content ) = div([ attr("dojoType", "dijit.layout.ContentPane"), attr("region", to_String(region)), attr("splitter", if splitter then "true" else "false") . attributes ], content). public define HTML_In_Form dojo_ContentPane ( List(CoreAttrs) attributes, BorderContainerRegion region, Bool splitter, HTML_In_Form content ) = div([ attr("dojoType", "dijit.layout.ContentPane"), attr("region", to_String(region)), attr("splitter", if splitter then "true" else "false") . attributes ], content). public define HTML_Off_Form dojo_TabContainer ( List(CoreAttrs) attributes, HTML_Off_Form content ) = div([attr("dojoType", "dijit.layout.TabContainer") . attributes ], content). public define HTML_Off_Form dojo_BorderContainer ( List(CoreAttrs) attributes, Maybe(String) the_title, BorderContainerDesign design, Bool live_splitter, Bool persist, Bool closable, String container, HTML_Off_Form content ) = with the_attributes = (List(CoreAttrs)) [attr("dojoType", "dijit.layout.BorderContainer"), attr("dojoAttachPoint", container), attr("design", to_String(design)), attr("liveSplitters", live_splitter), attr("persist", persist), attr("closable",closable) . attributes ], total_attributes = if the_title is { failure then the_attributes, success(t) then [title(t) . the_attributes] }, div(total_attributes, content). public define HTML_In_Form dojo_BorderContainer ( List(CoreAttrs) attributes, Maybe(String) the_title, BorderContainerDesign design, Bool live_splitter, Bool persist, Bool closable, String container, HTML_In_Form content ) = with the_attributes = (List(CoreAttrs)) [attr("dojoType", "dijit.layout.BorderContainer"), attr("dojoAttachPoint", container), attr("design", to_String(design)), attr("liveSplitters", live_splitter), attr("persist", persist), attr("closable",closable) . attributes ], total_attributes = if the_title is { failure then the_attributes, success(t) then [title(t) . the_attributes] }, div(total_attributes, content). public define HTML_Off_Form dojo_tree ( List(CoreAttrs) attributes, )= div_empty(attributes). public define HTML_Off_Form dojo_Toolbar ( List(CoreAttrs) attributes, HTML_Off_Form content )= div([attr("dojoType", "dijit.Toolbar") . attributes ], content). public define HTML_Off_Form dojo_tooltip ( List(CoreAttrs) attributes, List(Text_Option) txt_attr, HtmlId html_id, String label, HTML_Off_Form tooltip_content, )= sequence([ text([id(html_id.id) . txt_attr], label), div([id(html_id.id + "_tt"), attr("connectId", html_id.id), attr("dojoType", "dijit.Tooltip") . attributes], tooltip_content) ]). public define HTML_Off_Form dojo_button ( HtmlId html_id, // Maybe(String) class, String name, String iconclass, Maybe(String) tip_msg, String execute, )= literal(" " + if tip_msg is { failure then "", success(tip) then "" + tip + "" }). public define HTML_In_Form dojo_button ( HtmlId html_id, // Maybe(String) class, String name, String iconclass, Maybe(String) tip_msg, String execute, )= literal(" " + if tip_msg is { failure then "", success(tip) then "" + tip + "" }). public define HTML_Off_Form dojo_declaration ( String name, List(CoreAttrs) attributes, HTML_Off_Form content )= div([attr("dojoType", "dijit.Declaration"), attr("widgetClass", name) . attributes ], content). public define HTML_In_Form dojo_declaration ( String name, List(CoreAttrs) attributes, HTML_In_Form content )= div([attr("dojoType", "dijit.Declaration"), attr("widgetClass", name) . attributes ], content). public define HTML_Off_Form dojo_editor ( List(CoreAttrs) attributes, HtmlId html_id, WebArgName input_name, HTML_Off_Form text, )= div([id(html_id.id), attr("name", input_name.name), attr("dojoType", "dijit.Editor") ,attr("extraPlugins", "['|', 'foreColor','hiliteColor',{name:'dojox.editor.plugins.FontChoice', command:'fontName', generic:true},'fontSize','formatBlock','|','createLink','insertImage']") . attributes], text). public define HTML_In_Form dojo_button ( HtmlId html_id, String name, String iconclass, Maybe(String) tip_msg, String execute, )= literal(" " + if tip_msg is { failure then "", success(tip) then "" + tip + "" }). public define HTML_In_Form dojo_checkbox ( List(InputAttrs) attributes, WebArgName name, HtmlId id, String label, WebArgValue val, Bool checked, )= check_box_r([attr("dojoType", "dijit.form.CheckBox") . attributes] , label, id, name, val, checked). public define HTML_In_Form dojo_combobox ( List(InputAttrs) attributes, WebArgName name, HtmlId id, String label, List((List(CoreAttrs),WebArgValue,String)) list_data, InitialValue selected, )= // selector_c([attr("dojoType", "dijit.form.ComboBox") . attributes], label, id, name, 1, list_data, selected, non_mandatory). selector_c(attributes, label, id, name, 1, list_data, selected). public define HTML_Off_Form dojo_toaster ( List(CoreAttrs) attributes, HtmlId html_id, String message_topic, Position_Direction position_direction, Bool separator, Maybe(Int) duration )= div(append(append(if separator then [attr("separator","<hr>")] else [], if duration is { failure then [], success(dur) then [attr("duration", abs_to_decimal(dur))] }), [attr("dojoType", "dojox.widget.Toaster"), attr("messageTopic", message_topic), attr("positionDirection", pos_dir_to_str(position_direction)), id(html_id.id) . attributes ]), literal("")). public define HTML_Off_Form dojo_progressBar ( List(CoreAttrs) attributes, List(Text_Option) attributes_text, HtmlId html_id, String label )= sequence([ text([id("text_" + html_id.id), class("progress_bar") . attributes_text], label), div([id(html_id.id), class("progress_bar"), attr("indeterminate", "true"), attr("dojoType", "dijit.ProgressBar") . attributes], literal("")) ]). public define HTML_Off_Form dojo_progressBar ( List(CoreAttrs) attributes, List(Text_Option) attributes_text, HtmlId html_id, String label, Int progress, Int maximum )= sequence([ text([id("text_" + html_id.id), class("progress_bar") . attributes_text], label), div([id(html_id.id), class("progress_bar"), attr("maximum", abs_to_decimal(maximum)), attr("progress", abs_to_decimal(progress)), attr("dojoType", "dijit.ProgressBar") . attributes], literal("")) ]). define Maybe(Int) string_to_month ( String month_s )= with month = to_lower(month_s), if month = "jan" then success(1) else if month = "feb" then success(2) else if month = "mar" then success(3) else if month = "apr" then success(4) else if month = "may" then success(5) else if month = "jun" then success(6) else if month = "jul" then success(7) else if month = "aug" then success(8) else if month = "sep" then success(9) else if month = "oct" then success(10) else if month = "nov" then success(11) else if month = "dec" then success(12) else failure . // 'Thu Jan 14 2010 00:00:00 GMT+0100' must be replaced by '2010-01-14 00:00:00' public define Maybe(String) dojo_date_to_db_datetime ( String data )= with list_data = split_by_token(data, ' '), if nth(2, list_data) is { failure then failure, success(day) then if nth(1, list_data) is { failure then failure, success(month) then if nth(3, list_data) is { failure then failure, success(year) then if nth(4, list_data) is { failure then failure, success(hour) then if string_to_month(month) is { failure then failure, success(month_int) then success(year+"-"+month_int+"-"+day+" "+hour) } } } } }. public define List(HTML_Head_Tag) dojo_defaults = [ // js(js_file("js/dojo/dojo.js", [attr("djConfig", "parseOnLoad: true, isDebug: " + (if debug_mode then "true" else "false") + ", usePlainJson: true")])), js(js_file("js/dojo/dojo/dojo.js", [attr("djConfig", "parseOnLoad: true, isDebug: false, usePlainJson: true")])), js(js_file("js/dojo/dijit/dijit.js")), //css(css_file("js/dojo/dojo/resources/dojo.css")) ]. public define List(HTML_Head_Tag) dojo_init ( String web_dir, String theme_name ) = with theme_name = if file_exists(web_dir+"/public/js/dojo/dijit/themes/"+theme_name+"/"+theme_name+".css")then theme_name else "claro", [ css(css_file("js/dojo/dijit/themes/"+theme_name+"/"+theme_name+".css")) . [ css(css_file("js/dojo/dijit/themes/"+theme_name+"/"+theme_name+"_rtl.css")) . dojo_defaults ] ] .