CXM_web_action.anubis 2.11 KB
/*
 * Created by PyramIDE.
 * User: フランスのトトロ aka (David RENÉ) 
 * Date: 14/03/2017
 * Time: 04:23
 * © Calexium 
 */

read system/string.anubis

transmit calexium_lib/web/types/web_action_name.anubis
transmit calexium_lib/web/CXM_urllib.anubis
//public type WEB_Action_Name:
//  controller_action(
//    String  controller,
//    String  action_name
//  ),
//  action_name(
//    String  action_name
//  ),
//  //url is raw action, hence we will only copy that url in final link
//  url(
//    String  url_name
//  )
//.

public define String 
  format_extra_operands
  (
    List((String,String)) l_args
  ) =
  if length(l_args) = 0 then 
    ""
  else
    "&"+join("&", map(((String, String) arg) |-> since arg is (name, value), name+"="+url_quote(value), l_args))
.

public define String
  to_Anubis_Source
  (
    WEB_Action_Name wan
  )=
  if wan is 
  {
    no_action                         then "no_action",
    controller_action(cont, ac_name)  then "controller_action(\""+cont+"\", \""+ac_name+"\")",
    action_name(ac_name)              then "action_name(\""+ac_name+"\")",
    url(url_name)                     then "url(\""+url_name+"\")"
  }
.

public define String
  format_web_action_name
  (
    WEB_Action_Name           action
  )=
  
  if action is
  {
    no_action                                   then "",  
    controller_action(controller, action_name)  then "?aws_controller="+controller+"&aws_action="+action_name,
    action_name(action_name)                    then "?aws_action="+action_name,
    url(url)                                    then url
  }  
.

public define String
  format_web_action_name
  (
    WEB_Action_Name           action,
    List((String,String))     extra_ops,
  )=
  format_web_action_name(action)
  +
  format_extra_operands(extra_ops)
.

public define String
  format_web_action_name_to_js
  (
    WEB_Action_Name           action,
    List((String,String))     extra_ops,
  )=
  "'"+format_web_action_name(action, extra_ops)+"'"
.

public define String
  format_web_action_name_to_js
  (
    WEB_Action_Name           action
  )=
  format_web_action_name_to_js(action, [])
.