left_menu.anubis 5.57 KB
/*
 * Created by PyramIDE.
 * User: フランスのトトロ 
 * Date: 10/01/2016
 * Time: 12:24
 * © David RENÉ
 */

transmit tools/basis.anubis
 read calexium_lib/web/CXM_web_action.anubis
read calexium_lib/web/CXM_web_action.anubis
read system/string.anubis

public type Left_Menu_Entry:
  left_menu_entry(          //MENU entry hence no selectable
    String          entry_id,       //it's also use as icon prefix
    List(String)    classes,        //additional classes if need (for disabling entry, change background color, etc.)
    WEB_Action_Name action,         //action (url to apply when click
    String          text,           //text to show
    List((String, String)) extra,   //extra web arguments to send when click
    Maybe(String)   target_id       //target_id use during load_content
  ),
  title(                    //TITLE entry hence no selectable
    String        title_id,       //it's also use as icon prefix
    List(String)  classes,        //additional classes if need (change background color, font size, etc.)
    String        text            //text to show
  )
.

public type Left_Menu:
  no_left_menu,
  left_menu(
    List(Left_Menu_Entry) entries,
    String  selected
  )
.

public type Plugin_Left_Menu:
  plugin_left_menu(
    String    app,    //application name
    String    space,  //space name
    Left_Menu left_menu
  )
.

public type Space_Left_Menu:
  space_menu(
    String    name,
    Left_Menu menu
  )
.

public type App_Left_Menu:
  app_menu(
    String name,
    List(Space_Left_Menu) space_menu_list
  )
.

public type World_Left_Menu:
  world_menu(
    List(App_Left_Menu) app_menu_list
  )
.

public define List(Space_Left_Menu)
  add_to_space
  (
    List(Space_Left_Menu) space_list,
    List(Space_Left_Menu) so_far,
    String                space_name,
    Left_Menu             left_menu
  )=
  if space_list is
  {
    []      then [space_menu(space_name, left_menu)],
    [h . t] then
      if h.name = space_name then // if we found the same name we replace it into the list
        [space_menu(space_name, left_menu) . so_far]+t
      else
        add_to_space(t, [h . so_far], space_name, left_menu)
  }
.

public define World_Left_Menu
  add_to_app
  (
    List(App_Left_Menu) app_list,
    List(App_Left_Menu) so_far,
    String              app_name,
    String              space_name,
    Left_Menu           left_menu
  )=
  if app_list is
  {
    []      then world_menu([app_menu(app_name, [space_menu(space_name, left_menu)]) . so_far]),
    [h . t] then
      if h.name = app_name then
        world_menu([app_menu(app_name, add_to_space(h.space_menu_list, [], space_name, left_menu)) . so_far]+t)
      else
        add_to_app(t, [h . so_far], app_name, space_name, left_menu)
  }
.

public define World_Left_Menu
  add_to_World_Left_Menu
  (
    World_Left_Menu   w_left_menu,
    Plugin_Left_Menu  p_left_menu
  )=
  since p_left_menu is plugin_left_menu(app, space, l_menu),
  
  add_to_app(w_left_menu.app_menu_list, [], app, space, l_menu)
.

public define World_Left_Menu
  add_to_World_Left_Menu
  (
    World_Left_Menu         current_world,
    List(Plugin_Left_Menu)  p_left_menu
  )=
  if p_left_menu is 
  {
    []      then current_world,
    [h . t] then add_to_World_Left_Menu(add_to_World_Left_Menu(current_world, h), t)
  }
.

public define World_Left_Menu
  add_to_World_Left_Menu
  (
    List(Plugin_Left_Menu)  p_left_menu
  )=
  add_to_World_Left_Menu(world_menu([]), p_left_menu)
.
  
public define Left_Menu_Entry
  left_menu_entry
  (
    String           entry_id,
    WEB_Action_Name  action,
    String           text
  )=
  left_menu_entry(entry_id, [], action, text, [], failure)
.
  
public define Left_Menu_Entry
  left_menu_entry
  (
    String  entry_id,
    String  action,
    String  text
  )=
  left_menu_entry(entry_id, [], action_name(action), text, [], failure)
.
  
public define Left_Menu_Entry
  left_menu_entry
  (
    String          entry_id,       //it's also use as icon prefix
    WEB_Action_Name action,         //action (url to apply when click
    String          text,           //text to show
    List((String, String)) extra    //extra web arguments to send when click
  )=
  left_menu_entry(entry_id, [], action, text, extra, failure)
.

public define Left_Menu_Entry
  left_menu_entry
  (
    String          entry_id,       //it's also use as icon prefix
    WEB_Action_Name action,         //action (url to apply when click
    String          text,           //text to show
    List((String, String)) extra,   //extra web arguments to send when click
    String          target_id
  )=
  left_menu_entry(entry_id, [], action, text, extra, success(target_id))
.
  
public define Left_Menu_Entry
  left_menu_entry
  (
    String  entry_id,       //it's also use as icon prefix
    String  action,         //action (url to apply when click
    String  text,           //text to show
    List((String, String)) extra  //extra web arguments to send when click
  )=
  left_menu_entry(entry_id, [], action_name(action), text, extra, failure)
.

public define Left_Menu_Entry
  left_menu_entry
  (
    String  entry_id,       //it's also use as icon prefix
    String  action,         //action (url to apply when click
    String  text,           //text to show
    List((String, String)) extra,  //extra web arguments to send when click
    String  target_id
  )=
  left_menu_entry(entry_id, [], action_name(action), text, extra, success(target_id))
.
  
public define Left_Menu_Entry
  title
  (
    String  text
  )=
  title("", [], text). 
  
public define Left_Menu_Entry
  title
  (  
    String title_id,
    String text
  )=
  title(title_id, [], text).