/* * Created by PyramIDE. * User: Jeremy * Date: 07/09/2012 * Time: 15:10 * * To change this template use Tools | Options | Coding | Edit Standard Headers. */ read calexium_lib/web/CXM_making_a_web_site.anubis read calexium_lib/web/CXM_jquery.anubis read calexium_lib/web/jQuery/CXM_jquery_icons.anubis read tools/basis.anubis read system/string.anubis read 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 options is { [ ] then formated_options, [ h . t ] then if h is { resizable then if formated_options="" then // si c'est vide on ne prefixe pas avec une virgule jquery_button_get_onclick_action_window_options( t, formated_options+"resizable='yes'" ) else jquery_button_get_onclick_action_window_options( t, formated_options+", resizable='yes'" ), scrollbars then if formated_options="" then // si c'est vide on ne prefixe pas avec une virgule jquery_button_get_onclick_action_window_options( t, formated_options+"scrollbars='yes'" ) else jquery_button_get_onclick_action_window_options( t, formated_options+", scrollbars='yes'" ), width(w) then if formated_options="" then // si c'est vide on ne prefixe pas avec une virgule jquery_button_get_onclick_action_window_options( t, formated_options+"width="+w ) else jquery_button_get_onclick_action_window_options( t, formated_options+", width="+w ), height(h) then if formated_options="" then // si c'est vide on ne prefixe pas avec une virgule jquery_button_get_onclick_action_window_options( t, formated_options+"height="+h ) else jquery_button_get_onclick_action_window_options( t, formated_options+", 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 button_id = generate_random_string(10), button_name = button_id, actioner = jQuery_actioner(same, jqscript, " $( '#" + button_id + "_dlg' ).dialog({ title: '" + dlg_title + "', resizable: false, modal: true, buttons: { '" + dlg_ok + "': function() { document.location='/?a=" + url + format_extra_operands(extra_ops)+"'; }, '" + dlg_cancel + "': function() { $( this ).dialog( 'close' ); } } });"), partial_content(sequence([ div([id(button_id+"_dlg"),style("display: none;")], text(dlg_text)), partial(jquery_button(jQuery_button(button, button_id, 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, []).