/* * 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/widgets/button.anubis transmit calexium_lib/web/js_tools.anubis transmit calexium_lib/web/CXM_json.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 HTML_Head_Tag jquery_button_get_onclick_action ( String button_id, JQuery_Actioner actioner ) = with js_action = jquery_button_get_onclick_action(actioner), js_inline(jquery_ready("$('#"+button_id+"').click(function(e){" + js_action + "});")) . 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, html_id, name, label, actioner, primary, secondary) then with onclick_action=jquery_button_get_onclick_action(html_id, actioner), if html_id = "" then // if the ID is not set => we can't use icons in the buttonset. _jquery_buttons( t, [ onclick_action . html_tags ], [ button([attr("type",to_String(bt_type)), attr("name",name)], text(label)) . html_buttons ] ) else if jquery_icon_to_string(primary) = "" then if jquery_icon_to_string(secondary) = "" then _jquery_buttons( t, [ js_inline(jquery_ready("$('#"+html_id+"').button();")), onclick_action ] +html_tags, [ button([attr("type",to_String(bt_type)), id(html_id), attr("name",name)], text(label)) . html_buttons ] ) else _jquery_buttons( t, [ js_inline(jquery_ready("$('#"+html_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("$('#"+html_id+"').button({icons:{primary:'"+jquery_icon_to_string(primary)+"'}});")), onclick_action ] +html_tags, [ literal("") . html_buttons ] ) else _jquery_buttons( t, [ js_inline(jquery_ready("$('#"+html_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();")) ], div(id(buttons_container_id), _jquery_buttons(buttons, [], [])) // 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), // btn_seq = (HTML_Off_Form)sequence([literal("")]), btn_seq = (HTML_Off_Form)sequence([literal("")]), if jquery_icon_to_string(primary) = "" then if jquery_icon_to_string(secondary) = "" then partial_content( [ js_inline(jquery_ready("$('#"+id+"').button();")), onclick_action ], btn_seq //sequence([literal("")]) //literal("") ) else partial_content( [ js_inline(jquery_ready("$('#"+id+"').button({icons:{secondary:'"+jquery_icon_to_string(secondary)+"'}});")), onclick_action ], btn_seq //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 ], btn_seq //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 ], btn_seq //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 jq_img_button, String button_id ) = since jq_img_button is jquery_img_button(img_url, label_text, _, actioner, orientation), button([id(button_id), class("jq_img_btn")], if orientation is { top then table([class("jq_img_btn_table")],[ row( cell(img(img_url))), row( cell(text(label_text))) ]), bottom then table([class("jq_img_btn_table")],[ row( cell(text(label_text))), row( cell(img(img_url))) ]), left then table([class("jq_img_btn_table")],[ row( [cell(img(img_url)), cell(text(label_text)) ]) ]), right then table([class("jq_img_btn_table")],[ row( [cell(text(label_text)), cell(img(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, JQuery_Actioner actioner )= with uid = generate_random_string(10), js_confirm_dialog_data_obj = "CalexiumToolBox.data.confirm_dialog['" + 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))+*/ + to_JS_String(jquery_button_get_onclick_action(actioner)) + ");")), partial_content([ js(js_file("js/cxm/cxm.js")), css(css_file("css/cxm/cxm_button.css")), 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 ( JQuery_img_button button, String dlg_title, String dlg_text, String dlg_ok, String dlg_cancel //JQuery_Actioner actioner //String url, //List((String, String)) extra_ops )= since button is jquery_img_button(img_url, button_label, button_name, actioner, orientation), with uid = generate_random_string(10), js_confirm_dialog_data_obj = "CalexiumToolBox.data.confirm_dialog['" + 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(jquery_button_get_onclick_action(actioner)) +");")), partial_content([ js(js_file("js/cxm/cxm.js")), js_inline(jquery_ready(js_data)) ], sequence([ partial(jquery_button(jquery_img_button(img_url, button_label, _button_name, _actioner, orientation))) ]) ) . public define HTML_Partial_Content img_submit_button ( String img, //path to image String label, //translated label of the button String form_id, //form id to submit WEB_Action_Name action, // List((String,String)) extra_ops )= jquery_button(jquery_img_button(img, label, "", jQuery_actioner(same, jqform(form_id, action, extra_ops)), left)). public define HTML_Partial_Content img_submit_button ( String img, //path to image String label, //translated label of the button String form_id, //form id to submit WEB_Action_Name action )= jquery_button(jquery_img_button(img, label, "", jQuery_actioner(same, jqform(form_id, action, [])), left)). public define HTML_Partial_Content img_submit_button ( String label, //translated label of the button String form_id, //form id to submit WEB_Action_Name action )= jquery_button(jquery_img_button(icn16_check, label, "", jQuery_actioner(same, jqform(form_id, action, [])), left)). public define HTML_Partial_Content img_submit_button_load ( String label, //translated label of the button String form_id, //form id to submit String target_id, WEB_Action_Name action )= jquery_button(jquery_img_button(icn16_check, label, "", jQuery_actioner(same, jqformload(form_id, target_id, action, [])), left)). public define HTML_Partial_Content img_submit_button ( String label, //translated label of the button String form_id // )= jquery_button(jquery_img_button(icn16_check, label, "", jQuery_actioner(same, jqform(form_id, no_action, [])), left)) . public define HTML_Partial_Content img_button ( String icon, //URL of String label, //translated label of the button WEB_Action_Name action, List((String,String)) extra_ops )= jquery_button(jquery_img_button(icon, label, "", jQuery_actioner(same, jqlink(action, extra_ops)), left)) . public define HTML_Partial_Content img_button ( String icon, //URL of String label, //translated label of the button WEB_Action_Name action, List((String,String)) extra_ops, String target )= jquery_button(jquery_img_button(icon, label, "", jQuery_actioner(same, jqload(target, action, extra_ops)), left)) . public define HTML_Partial_Content img_button ( String icon, String label, //translated label of the button WEB_Action_Name action )= jquery_button(jquery_img_button(icon, label, "", jQuery_actioner(same, jqlink(action)), left)) .