Commit 2ddb91a557f6d655bb4761a67ae09d59bc10ae85
1 parent
96b5f856
add img submit button with new parameters like img, WEB_Action_Name
fix Asterisk AMI receive
Showing
4 changed files
with
120 additions
and
27 deletions
Show diff stats
asterisk/ami.anubis
| @@ -14,29 +14,41 @@ transmit calexium_lib/asterisk/ami_types.anubis | @@ -14,29 +14,41 @@ transmit calexium_lib/asterisk/ami_types.anubis | ||
| 14 | transmit calexium_lib/asterisk/ami_commands.anubis | 14 | transmit calexium_lib/asterisk/ami_commands.anubis |
| 15 | transmit calexium_lib/web/CXM_http_get_common.anubis | 15 | transmit calexium_lib/web/CXM_http_get_common.anubis |
| 16 | 16 | ||
| 17 | -define Maybe(One) | 17 | +define Maybe(List(String)) |
| 18 | receive | 18 | receive |
| 19 | ( | 19 | ( |
| 20 | - Bool print_dump, | ||
| 21 | - Connection conn | 20 | + Bool print_dump, |
| 21 | + Connection conn, | ||
| 22 | + List(String) response | ||
| 22 | )= | 23 | )= |
| 23 | //TODO find the header and content-lenght to get full length of answer | 24 | //TODO find the header and content-lenght to get full length of answer |
| 24 | 25 | ||
| 25 | - if read(conn, 16384, 5) is | 26 | + //if read(conn, 16384, 5) is |
| 27 | + if read_line(conn, 80, 10) is | ||
| 26 | { | 28 | { |
| 27 | - error then println("Read error");failure, | ||
| 28 | - timeout then println("Read timeout");failure, | ||
| 29 | - ok(ba) then | ||
| 30 | - with ami_response = to_string(ba), | ||
| 31 | - // typed_response = xml_rpc_get_response(xml_response), | ||
| 32 | - if print_dump then | ||
| 33 | - println("=== ASTERISK SERVER answer ==="+crlf +"["+ ami_response + "]" ); | ||
| 34 | - receive(print_dump, conn) | ||
| 35 | - | ||
| 36 | - else | ||
| 37 | - receive(print_dump, conn) | 29 | + error then println("Read error");failure, |
| 30 | + timeout then println("Read timeout");failure, | ||
| 31 | + eof then println("Read timeout");failure, | ||
| 32 | + ok(str) then | ||
| 33 | + if str = crlf then | ||
| 34 | + (if print_dump then | ||
| 35 | + println("=== ASTERISK SERVER answer ==="+crlf +"["+ join("",(reverse(response))) + "]" ) | ||
| 36 | + else | ||
| 37 | + unique); | ||
| 38 | + success(reverse(response)) | ||
| 39 | + else | ||
| 40 | + receive(print_dump, conn, [str . response]) | ||
| 38 | } | 41 | } |
| 39 | - . | 42 | +. |
| 43 | + | ||
| 44 | +public define Maybe(List(String)) | ||
| 45 | + ami_receive | ||
| 46 | + ( | ||
| 47 | + Bool print_dump, | ||
| 48 | + Connection conn | ||
| 49 | + )= | ||
| 50 | + receive(print_dump, conn, []) | ||
| 51 | +. | ||
| 40 | 52 | ||
| 41 | define Maybe(String) | 53 | define Maybe(String) |
| 42 | _format_action | 54 | _format_action |
| @@ -46,7 +58,9 @@ define Maybe(String) | @@ -46,7 +58,9 @@ define Maybe(String) | ||
| 46 | )= | 58 | )= |
| 47 | if values is | 59 | if values is |
| 48 | { | 60 | { |
| 49 | - [] then success(so_far+crlf), | 61 | + [] then |
| 62 | + println("AMI _format_action\n"+so_far+crlf); | ||
| 63 | + success(so_far+crlf), | ||
| 50 | [h . t] then | 64 | [h . t] then |
| 51 | if h is key_value(key, value) then | 65 | if h is key_value(key, value) then |
| 52 | _format_action(so_far+key+": "+value+crlf, t) | 66 | _format_action(so_far+key+": "+value+crlf, t) |
| @@ -69,7 +83,7 @@ define Maybe(String) | @@ -69,7 +83,7 @@ define Maybe(String) | ||
| 69 | 83 | ||
| 70 | 84 | ||
| 71 | 85 | ||
| 72 | -public define Maybe(One) | 86 | +public define Maybe(List(String)) |
| 73 | send_action | 87 | send_action |
| 74 | ( | 88 | ( |
| 75 | Asterisk_client client, | 89 | Asterisk_client client, |
| @@ -90,7 +104,7 @@ public define Maybe(One) | @@ -90,7 +104,7 @@ public define Maybe(One) | ||
| 90 | if write(conn, to_byte_array(action_str)) is | 104 | if write(conn, to_byte_array(action_str)) is |
| 91 | { | 105 | { |
| 92 | failure then failure, | 106 | failure then failure, |
| 93 | - success(_) then receive(true, conn) | 107 | + success(_) then ami_receive(true, conn) |
| 94 | } | 108 | } |
| 95 | }. | 109 | }. |
| 96 | 110 | ||
| @@ -98,7 +112,8 @@ public define Maybe(Asterisk_client) | @@ -98,7 +112,8 @@ public define Maybe(Asterisk_client) | ||
| 98 | asterisk_new_client | 112 | asterisk_new_client |
| 99 | ( | 113 | ( |
| 100 | String server_name, | 114 | String server_name, |
| 101 | - AMI_Auth auth | 115 | + AMI_Auth auth, |
| 116 | + Bool subscribe_events | ||
| 102 | )= | 117 | )= |
| 103 | //println("asterisk_new_client "+server_name); | 118 | //println("asterisk_new_client "+server_name); |
| 104 | if separate_name_port(server_name, 5038) is (name, server_port) then | 119 | if separate_name_port(server_name, 5038) is (name, server_port) then |
| @@ -112,6 +127,7 @@ public define Maybe(Asterisk_client) | @@ -112,6 +127,7 @@ public define Maybe(Asterisk_client) | ||
| 112 | { | 127 | { |
| 113 | error(e) then failure, | 128 | error(e) then failure, |
| 114 | ok(conn) then | 129 | ok(conn) then |
| 130 | + //read line of 80 bytes and timeout for 10 seconds | ||
| 115 | if read_line(tcp(conn), 80, 10) is | 131 | if read_line(tcp(conn), 80, 10) is |
| 116 | { | 132 | { |
| 117 | error then failure, | 133 | error then failure, |
| @@ -123,7 +139,7 @@ public define Maybe(Asterisk_client) | @@ -123,7 +139,7 @@ public define Maybe(Asterisk_client) | ||
| 123 | if start_with(to_lower(str), "asterisk call manager") then | 139 | if start_with(to_lower(str), "asterisk call manager") then |
| 124 | 140 | ||
| 125 | with client = asterisk_client(tcp(conn), var(0), auth), | 141 | with client = asterisk_client(tcp(conn), var(0), auth), |
| 126 | - if send_action(client, ami_login(auth)) is | 142 | + if send_action(client, ami_login(auth, subscribe_events)) is |
| 127 | { | 143 | { |
| 128 | failure then failure, | 144 | failure then failure, |
| 129 | success(_) then success(client) | 145 | success(_) then success(client) |
| @@ -137,6 +153,15 @@ public define Maybe(Asterisk_client) | @@ -137,6 +153,15 @@ public define Maybe(Asterisk_client) | ||
| 137 | else | 153 | else |
| 138 | failure. | 154 | failure. |
| 139 | 155 | ||
| 156 | +public define Maybe(Asterisk_client) | ||
| 157 | + asterisk_new_client | ||
| 158 | + ( | ||
| 159 | + String server_name, | ||
| 160 | + AMI_Auth auth, | ||
| 161 | + )= | ||
| 162 | + asterisk_new_client(server_name, auth, false) | ||
| 163 | +. | ||
| 164 | + | ||
| 140 | 165 | ||
| 141 | global define One | 166 | global define One |
| 142 | ami_test | 167 | ami_test |
asterisk/ami_commands.anubis
| @@ -17,10 +17,14 @@ public define AMI_Action ami_login(String user, String password, Bool events) = | @@ -17,10 +17,14 @@ public define AMI_Action ami_login(String user, String password, Bool events) = | ||
| 17 | 17 | ||
| 18 | public define AMI_Action ami_login(String user, String password)= | 18 | public define AMI_Action ami_login(String user, String password)= |
| 19 | ami_login(user, password, true). | 19 | ami_login(user, password, true). |
| 20 | - | 20 | + |
| 21 | public define AMI_Action ami_login(AMI_Auth ami_auth) = | 21 | public define AMI_Action ami_login(AMI_Auth ami_auth) = |
| 22 | if ami_auth is auth(user, password) then | 22 | if ami_auth is auth(user, password) then |
| 23 | ami_login(user, password, true). | 23 | ami_login(user, password, true). |
| 24 | + | ||
| 25 | +public define AMI_Action ami_login(AMI_Auth ami_auth, Bool event) = | ||
| 26 | + if ami_auth is auth(user, password) then | ||
| 27 | + ami_login(user, password, event). | ||
| 24 | 28 | ||
| 25 | public define AMI_Action ami_originate_call(String extension, String out_number) = | 29 | public define AMI_Action ami_originate_call(String extension, String out_number) = |
| 26 | action("Originate", [ | 30 | action("Originate", [ |
web/CXM_jquery.anubis
| @@ -12,7 +12,7 @@ read tools/basis.anubis | @@ -12,7 +12,7 @@ read tools/basis.anubis | ||
| 12 | 12 | ||
| 13 | /* jQuery Actioner type */ | 13 | /* jQuery Actioner type */ |
| 14 | public type JQuery_Actioner_type: | 14 | public type JQuery_Actioner_type: |
| 15 | - jqform ( String form), | 15 | + jqform ( String form, WEB_Action_Name name, List((String,String)) extra_ops), |
| 16 | jqlink ( WEB_Action_Name name, List((String,String)) extra_ops), | 16 | jqlink ( WEB_Action_Name name, List((String,String)) extra_ops), |
| 17 | jqflink ( String link), | 17 | jqflink ( String link), |
| 18 | jqscript( String script) | 18 | jqscript( String script) |
| @@ -74,7 +74,19 @@ public define String | @@ -74,7 +74,19 @@ public define String | ||
| 74 | same then | 74 | same then |
| 75 | if act_type is | 75 | if act_type is |
| 76 | { | 76 | { |
| 77 | - jqform(form) then "$('#"+form+"').submit();", | 77 | + jqform(form, control_action, extra_ops) then |
| 78 | + | ||
| 79 | + if control_action is | ||
| 80 | + { | ||
| 81 | + no_action then "", //will use the default action defined in form | ||
| 82 | + controller_action(ctrl, action) then | ||
| 83 | + "$('#"+form+"').get(0).setAttribute('action','/?aws_controller="+ctrl+"&aws_action="+action+format_extra_operands(extra_ops)+"');\n" | ||
| 84 | + action_name(action) then | ||
| 85 | + "$('#"+form+"').get(0).setAttribute('action','/?aws_action="+action+"');", | ||
| 86 | + url(url) then | ||
| 87 | + "$('#"+form+"').get(0).setAttribute('action','"+url+"');", | ||
| 88 | + }+ | ||
| 89 | + "$('#"+form+"').submit();\n", | ||
| 78 | jqlink(control_action, extra_ops) then | 90 | jqlink(control_action, extra_ops) then |
| 79 | if control_action is | 91 | if control_action is |
| 80 | { | 92 | { |
| @@ -89,7 +101,18 @@ public define String | @@ -89,7 +101,18 @@ public define String | ||
| 89 | same(label) then | 101 | same(label) then |
| 90 | if act_type is | 102 | if act_type is |
| 91 | { | 103 | { |
| 92 | - jqform(form) then "$('#"+form+"').submit();", | 104 | + jqform(form, control_action, extra_ops) then |
| 105 | + if control_action is | ||
| 106 | + { | ||
| 107 | + no_action then "", //will use the default action defined in form | ||
| 108 | + controller_action(ctrl, action) then | ||
| 109 | + "$('#"+form+"').get(0).setAttribute('action','/?aws_controller="+ctrl+"&aws_action="+action+format_extra_operands(extra_ops)+"');\n" | ||
| 110 | + action_name(action) then | ||
| 111 | + "$('#"+form+"').get(0).setAttribute('action','/?aws_action="+action+"');", | ||
| 112 | + url(url) then | ||
| 113 | + "$('#"+form+"').get(0).setAttribute('action','"+url+"');", | ||
| 114 | + }+ | ||
| 115 | + "$('#"+form+"').submit();\n", | ||
| 93 | jqlink(control_action, extra_ops) then | 116 | jqlink(control_action, extra_ops) then |
| 94 | if control_action is | 117 | if control_action is |
| 95 | { | 118 | { |
| @@ -104,7 +127,18 @@ public define String | @@ -104,7 +127,18 @@ public define String | ||
| 104 | other(window_name, window_options) then | 127 | other(window_name, window_options) then |
| 105 | if act_type is | 128 | if act_type is |
| 106 | { | 129 | { |
| 107 | - jqform(form) then "$('#"+form+"').submit();",//il s'agit d'une soumision d'un formulaire => cela se fait uniquement dans la même fenêtre ! | 130 | + jqform(form, control_action, extra_ops) then //il s'agit d'une soumision d'un formulaire => cela se fait uniquement dans la même fenêtre ! |
| 131 | + if control_action is | ||
| 132 | + { | ||
| 133 | + no_action then "", //will use the default action defined in form | ||
| 134 | + controller_action(ctrl, action) then | ||
| 135 | + "$('#"+form+"').get(0).setAttribute('action','/?aws_controller="+ctrl+"&aws_action="+action+format_extra_operands(extra_ops)+"');\n" | ||
| 136 | + action_name(action) then | ||
| 137 | + "$('#"+form+"').get(0).setAttribute('action','/?aws_action="+action+"');", | ||
| 138 | + url(url) then | ||
| 139 | + "$('#"+form+"').get(0).setAttribute('action','"+url+"');", | ||
| 140 | + }+ | ||
| 141 | + "$('#"+form+"').submit();\n", | ||
| 108 | jqlink(control_action, extra_ops) then | 142 | jqlink(control_action, extra_ops) then |
| 109 | if control_action is | 143 | if control_action is |
| 110 | { | 144 | { |
web/jQuery/CXM_jquery_button.anubis
| @@ -338,10 +338,40 @@ public define HTML_Partial_Content | @@ -338,10 +338,40 @@ public define HTML_Partial_Content | ||
| 338 | public define HTML_Partial_Content | 338 | public define HTML_Partial_Content |
| 339 | img_submit_button | 339 | img_submit_button |
| 340 | ( | 340 | ( |
| 341 | + String img, //path to image | ||
| 342 | + String label, //translated label of the button | ||
| 343 | + String form_id, //form id to submit | ||
| 344 | + WEB_Action_Name action, // | ||
| 345 | + List((String,String)) extra_ops | ||
| 346 | + )= | ||
| 347 | + jquery_button(jquery_img_button(img, label, "", jQuery_actioner(same, jqform(form_id, action, extra_ops)), left)). | ||
| 348 | + | ||
| 349 | +public define HTML_Partial_Content | ||
| 350 | + img_submit_button | ||
| 351 | + ( | ||
| 352 | + String img, //path to image | ||
| 353 | + String label, //translated label of the button | ||
| 354 | + String form_id, //form id to submit | ||
| 355 | + WEB_Action_Name action | ||
| 356 | + )= | ||
| 357 | + jquery_button(jquery_img_button(img, label, "", jQuery_actioner(same, jqform(form_id, action, [])), left)). | ||
| 358 | + | ||
| 359 | +public define HTML_Partial_Content | ||
| 360 | + img_submit_button | ||
| 361 | + ( | ||
| 362 | + String label, //translated label of the button | ||
| 363 | + String form_id, //form id to submit | ||
| 364 | + WEB_Action_Name action | ||
| 365 | + )= | ||
| 366 | + jquery_button(jquery_img_button(icn16_check, label, "", jQuery_actioner(same, jqform(form_id, action, [])), left)). | ||
| 367 | + | ||
| 368 | +public define HTML_Partial_Content | ||
| 369 | + img_submit_button | ||
| 370 | + ( | ||
| 341 | String label, //translated label of the button | 371 | String label, //translated label of the button |
| 342 | String form_id // | 372 | String form_id // |
| 343 | )= | 373 | )= |
| 344 | - jquery_button(jquery_img_button(icn16_check, label, "", jQuery_actioner(same, jqform(form_id)), left)). | 374 | + jquery_button(jquery_img_button(icn16_check, label, "", jQuery_actioner(same, jqform(form_id, no_action, [])), left)). |
| 345 | 375 | ||
| 346 | public define HTML_Partial_Content | 376 | public define HTML_Partial_Content |
| 347 | img_button | 377 | img_button |