/* * Created by PyramIDE. * User: Jeremy * Date: 07/09/2012 * Time: 15:10 * */ transmit calexium_lib/web/CXM_making_a_web_site.anubis transmit calexium_lib/web/CXM_jquery.anubis transmit calexium_lib/web/jQuery/CXM_jquery_icons.anubis transmit calexium_lib/web/js_tools.anubis transmit tools/basis.anubis transmit system/string.anubis transmit tools/random.anubis public type JQuery_button_type: button, reset, submit. //button with confirmation dialog public define String to_String ( JQuery_button_type bt_type )= if bt_type is { button then "button", reset then "reset", submit then "submit" }. public type JQuery_button: jQuery_button( JQuery_button_type bt_type, String button_id, String button_name, String button_label, JQuery_Actioner actioner, JQuery_icon primary, JQuery_icon secondary // primary icon is for left icon, secondary icon is for right icon and button_id must set with an unique ID in order to have icons working ) . public define JQuery_button jQuery_button ( JQuery_button_type bt_type, String button_id, String button_name, String button_label, JQuery_Actioner actioner ) = jQuery_button(bt_type, button_id, button_name, button_label, actioner, jq_icon_none, jq_icon_none). define String jquery_button_get_onclick_action_window_options ( List(Other_Window_Option) options, String formated_options ) = //if there is already formated_options add a comma + space between the options with comma = if formated_options="" then "" else ", ", if options is { [ ] then formated_options, [ h . t ] then if h is { resizable then jquery_button_get_onclick_action_window_options( t, formated_options+ comma+ "resizable=yes" ), scrollbars then jquery_button_get_onclick_action_window_options( t, formated_options+ comma + "scrollbars=yes"), width(w) then jquery_button_get_onclick_action_window_options( t, formated_options+ comma + "width="+w), height(h) then jquery_button_get_onclick_action_window_options( t, formated_options+ comma + "height="+h) } } . define HTML_Head_Tag jquery_button_get_onclick_action ( String button_id, JQuery_Actioner actioner ) = if actioner is jQuery_actioner(target, act_type, str) then if target is { same then if act_type is { jqform then js_inline(jquery_ready("$('#"+button_id+"').click(function(){$('#"+str+"').submit();});")), jqlink then js_inline(jquery_ready("$('#"+button_id+"').click(function(){document.location='/?a="+str+"';});")), jqscript then js_inline(jquery_ready("$('#"+button_id+"').click(function(){"+str+"});")) }, same(label) then if act_type is { jqform then js_inline(jquery_ready("$('#"+button_id+"').click(function(){$('#"+str+"').submit();});")), jqlink then js_inline(jquery_ready("$('#"+button_id+"').click(function(){document.location='/?a="+str+"';});")), jqscript then js_inline(jquery_ready("$('#"+button_id+"').click(function(){"+str+"});")) }, other(window_name, window_options) then if act_type is { jqform then js_inline(jquery_ready("$('#"+button_id+"').click(function(){$('#"+str+"').submit();});")), //il s'agit d'une soumision d'un formulaire => cela se fait uniquement dans la même fenêtre ! jqlink then js_inline(jquery_ready("$('#"+button_id+"').click(function(){window.open('"+str+"', '"+window_name+"', '"+jquery_button_get_onclick_action_window_options(window_options, "")+"');});")), jqscript then js_inline(jquery_ready("$('#"+button_id+"').click(function(){"+str+"});")) } } . define HTML_Partial_Content _jquery_buttons ( List(JQuery_button) buttons, List(HTML_Head_Tag) html_tags, List(HTML_Off_Form) html_buttons ) = if buttons is { [ ] then partial_content( reverse(html_tags), sequence(reverse(html_buttons)) ), [ h . t ] then if h is jQuery_button(bt_type, id, name, label, actioner, primary, secondary) then with onclick_action=jquery_button_get_onclick_action(id, actioner), if id = "" then // if the ID is not set => we can't use icons in the buttonset. _jquery_buttons( t, [ onclick_action . html_tags ], [ literal("") . html_buttons ] ) else if jquery_icon_to_string(primary) = "" then if jquery_icon_to_string(secondary) = "" then _jquery_buttons( t, [ js_inline(jquery_ready("$('#"+id+"').button();")), onclick_action ] +html_tags, [ literal("") . html_buttons ] ) else _jquery_buttons( t, [ js_inline(jquery_ready("$('#"+id+"').button({icons:{secondary:'"+jquery_icon_to_string(secondary)+"'}});")), onclick_action ] +html_tags, [ literal("") . html_buttons ] ) else if jquery_icon_to_string(secondary) = "" then _jquery_buttons( t, [ js_inline(jquery_ready("$('#"+id+"').button({icons:{primary:'"+jquery_icon_to_string(primary)+"'}});")), onclick_action ] +html_tags, [ literal("") . html_buttons ] ) else _jquery_buttons( t, [ js_inline(jquery_ready("$('#"+id+"').button({icons:{primary:'"+jquery_icon_to_string(primary)+"',secondary:'"+jquery_icon_to_string(secondary)+"'}});")), onclick_action ] +html_tags, [ literal("") . html_buttons ] ) } . public define HTML_Partial_Content jquery_buttons ( String buttons_container_id, List(JQuery_button) buttons ) = partial_content( [ js_inline(jquery_ready("$('#"+buttons_container_id+"').buttonset();")) ], sequence([ literal("
"), partial(_jquery_buttons(buttons, [], [])), literal("
") ]) ) . public define HTML_Partial_Content jquery_button ( JQuery_button button ) = if button is jQuery_button(bt_type, id, name, label, actioner, primary, secondary) then with onclick_action=jquery_button_get_onclick_action(id, actioner), if jquery_icon_to_string(primary) = "" then if jquery_icon_to_string(secondary) = "" then partial_content( [ js_inline(jquery_ready("$('#"+id+"').button();")), onclick_action ], literal("") ) else partial_content( [ js_inline(jquery_ready("$('#"+id+"').button({icons:{secondary:'"+jquery_icon_to_string(secondary)+"'}});")), onclick_action ], literal("") ) else if jquery_icon_to_string(secondary) = "" then partial_content( [ js_inline(jquery_ready("$('#"+id+"').button({icons:{primary:'"+jquery_icon_to_string(primary)+"'}});")), onclick_action ], literal("") ) else partial_content( [ js_inline(jquery_ready("$('#"+id+"').button({icons:{primary:'"+jquery_icon_to_string(primary)+"',secondary:'"+jquery_icon_to_string(secondary)+"'}});")), onclick_action ], literal("") ) . public type Icon_orientation: top, bottom, left, right. public type JQuery_img_button: jquery_img_button(String img_url, String label_text, String id, JQuery_Actioner jq_action, Icon_orientation orientation). public define HTML_Off_Form jquery_button_html ( JQuery_img_button button, String button_id ) = if button is jquery_img_button(img_url, label_text, _, actioner, orientation) then div([id(button_id), class("jq_img_btn")], if orientation is { top then table([class("jq_img_btn_table")],[ row( cell(image(img_url))), row( cell(text(label_text))) ]), bottom then table([class("jq_img_btn_table")],[ row( cell(text(label_text))), row( cell(image(img_url))) ]), left then table([class("jq_img_btn_table")],[ row( [cell(image(img_url)), cell(text(label_text)) ]) ]), right then table([class("jq_img_btn_table")],[ row( [cell(text(label_text)), cell(image(img_url)) ]) ]), }). public define HTML_Partial_Content jquery_button ( JQuery_img_button button )= if button is jquery_img_button(_, _, button_id, actioner, _) then with button_id_str = if length(button_id) = 0 then generate_random_string(10) else button_id, partial_content( [ jquery_button_get_onclick_action(button_id_str, actioner), css(css_file("css/cxm/cxm_button.css")), js_inline(jquery_ready("$('.jq_img_btn').button();")) ], jquery_button_html(button, button_id_str)) . public define HTML_Partial_Content jq_button_confirm ( String button_label, String dlg_title, String dlg_text, String dlg_ok, String dlg_cancel, String url, List((String, String)) extra_ops )= with uid = generate_random_string(20), js_confirm_dialog_data_obj = "CalexiumToolBox.data.confirm_dialog[" + to_js_string(uid) + "]", js_data = js_confirm_dialog_data_obj + " = { title: " + to_js_string(dlg_title) + ", text: " + to_js_string(dlg_text) + ", ok : " + to_js_string(dlg_ok) + ", cancel: " + to_js_string(dlg_cancel) + "};", button_name = uid, actioner = jQuery_actioner(same, jqscript, "CalexiumToolBox.make_confirm_dialog(this, " + to_js_string("/?a=" + url + format_extra_operands(extra_ops))+");"), partial_content([js(js_file("js/cxm/cxm.js")), js_inline(jquery_ready(js_data))],sequence([ partial(jquery_button(jQuery_button(button, uid, button_name, button_label, actioner, jq_icon_none, jq_icon_none))) ])). public define HTML_Partial_Content jq_button_confirm ( String button_label, String dlg_title, String dlg_text, String dlg_ok, String dlg_cancel, String url )= jq_button_confirm(button_label, dlg_title, dlg_text, dlg_ok, dlg_cancel, url, []).