/* * Created by PyramIDE. * User: Totoro * Date: 07/02/2014 * Time: 21:43 */ transmit tools/basis.anubis transmit xlib/web/CXM_common.anubis transmit xlib/database/db_types.anubis transmit xlib/web/types/web_action_name.anubis public define One add_web_arg ( Var(List(Web_arg)) lwa, String arg_name, String value )= lwa <- [ web_arg(arg_name, value) . *lwa] . public define One add_web_arg ( Var(List(Web_arg)) lwa, Web_arg w_arg )= lwa <- [ w_arg . *lwa] . define List(Web_arg) _remove_web_arg ( List(Web_arg) lwa, String arg_name )= if lwa is { [] then [], [h . t] then if h is web_arg(name, _) then if name = arg_name then t else [h . _remove_web_arg(t, arg_name)] else [h . _remove_web_arg(t, arg_name)] } . public define One remove_web_arg ( Var(List(Web_arg)) lwa, String arg_name )= lwa <- _remove_web_arg(*lwa, arg_name) . define List(Web_arg) _replace_web_arg ( List(Web_arg) lwa, String arg_name, String value )= if lwa is { [] then /*println("arg_name "+arg_name+" not found, add it");*/[web_arg(arg_name, value)], [h . t] then if h is web_arg(name, _) then if name = arg_name then [web_arg(name, value) . t] else [h . _replace_web_arg(t, arg_name, value)] else [h . _replace_web_arg(t, arg_name, value)] } . public define One /* replace the value of given web argument name in the list. Replace the value of the first found * argument. * If the web argument is not found, an entry is created for this WEB argument name with given * value */ replace_web_arg ( Var(List(Web_arg)) lwa, //current list of web argument String arg_name, //web argument name to replace String value //value to replace )= //println("replace web arg name "+arg_name+" value "+value); lwa <- _replace_web_arg(*lwa, arg_name, value) . public define Web_arg web_arg ( String name, Int value )= web_arg(name, to_String(value)) . public define Web_arg web_arg ( String name, DB_id value )= web_arg(name, to_String(value)) . public define Maybe(DB_id) get_mb_DB_id ( List(Web_arg) lwa, String arg_name ) = if web_arg_value(lwa, arg_name) is { not_found then failure, found(value) then //Check if value is none which means no id provided if value="none" then success(none) else //Now try to convert the string into Int to get the id if decimal_scan(value) is { failure then success(none), success(_value) then success(db_id(_value)) } } . public define DB_id get_DB_id ( List(Web_arg) lwa, String arg_name, DB_id defaut_value ) = if get_mb_DB_id(lwa, arg_name) is { failure then defaut_value, success(value) then value } . public define DB_id get_DB_id ( List(Web_arg) lwa, String arg_name ) = if get_mb_DB_id(lwa, arg_name) is { failure then none, success(value) then value } . public define List(DB_id) get_List_DB_id ( List(Web_arg) l, String name ) = if l is { [] then [], [h . t] then if h is web_arg(n, value) then if n = name then //Check if value is none which means no id provided with result = if value="none" then none else //Now try to convert the string into Int to get the id if decimal_scan(value) is { failure then none, success(_value) then db_id(_value) }, [ result . get_List_DB_id(t, name)] else get_List_DB_id(t, name) else get_List_DB_id(t, name) } . public define Maybe(DB_date) get_DB_date ( List(Web_arg) lwa, String arg_name ) = if web_arg_value(lwa, arg_name) is { not_found then failure, found(value) then success(db_date(value)) }. public define DB_date get_DB_date ( List(Web_arg) lwa, String arg_name, DB_date default ) = if web_arg_value(lwa, arg_name) is { not_found then default, found(value) then db_date(value) }. public define Maybe(DB_time) get_DB_time ( List(Web_arg) lwa, String arg_name ) = if web_arg_value(lwa, arg_name) is { not_found then failure, found(value) then success(db_time(value)) }. public define DB_time get_DB_time ( List(Web_arg) lwa, String arg_name, DB_time default ) = if web_arg_value(lwa, arg_name) is { not_found then default, found(value) then db_time(value) }. public define Maybe(DB_datetime) get_DB_datetime ( List(Web_arg) lwa, String arg_name ) = if web_arg_value(lwa, arg_name) is { not_found then failure, found(value) then success(db_datetime(value)) }. public define DB_datetime get_DB_datetime ( List(Web_arg) lwa, String arg_name, DB_datetime default ) = if web_arg_value(lwa, arg_name) is { not_found then default, found(value) then db_datetime(value) }. public define Maybe(String) get_String ( List(Web_arg) lwa, String arg_name ) = if web_arg_value(lwa, arg_name) is { not_found then failure, found(value) then success(value) }. public define String get_String ( List(Web_arg) lwa, String arg_name, String default_value ) = if get_String(lwa, arg_name) is { failure then default_value success(value) then value }. public define List(String) get_List_String ( List(Web_arg) l, String name ) = if l is { [] then [], [h . t] then if h is web_arg(n, v) then if n = name then [ v . get_List_String(t, name)] else get_List_String(t, name) else get_List_String(t, name) } . public define Maybe(String) get_Password ( List(Web_arg) lwa, String pwd_1_name, String pwd_2_name )= if get_String(lwa, pwd_1_name) is { failure then failure, success(password1) then if get_String(lwa, pwd_2_name) is { failure then failure success(password2) then if password1 = password2 then success(password1) else failure } } . public define Maybe(Bool) get_mb_Bool ( List(Web_arg) lwa, String arg_name ) = // println("get_mb_Bool "+arg_name); if web_arg_value(lwa, arg_name) is { not_found then if web_arg_value(lwa, "~"+arg_name) is { not_found then //println("failure"); failure, found(_) then //println("success(false)"); success(false) }, found(value) then with return_v = to_Bool(value), // println("value = '"+value+"' result = "+to_String(return_v)+" success("+to_String(return_v)+")"); success(return_v) }. public define Bool get_Bool ( List(Web_arg) lwa, String arg_name ) = // println("get_Bool "+arg_name); if web_arg_value(lwa, arg_name) is { not_found then false, found(value) then with return_v = to_Bool(value), // println("value = '"+value+"' result = "+to_String(return_v)); return_v }. public define Bool get_Bool ( List(Web_arg) lwa, String arg_name, Bool default_value ) = // println("get_Bool with default ["+arg_name+"] default = "+to_String(default_value)); if web_arg_value(lwa, arg_name) is { not_found then //println("return default_value"); default_value, found(value) then with return_v = to_Bool(value), //println("value = '"+value+"' result = "+to_String(return_v)); return_v //true }. public define Maybe(Bool) get_Bool ( List(Web_arg) lwa, String arg_name ) = if web_arg_value(lwa, arg_name) is { not_found then success(false), found(_) then success(true) }. public define Maybe(Int) get_Int ( List(Web_arg) lwa, String name ) = if web_arg_value(lwa, name) is { not_found then /*logDebug(debug_log, "Can't find argument '" + name + "'");*/ failure found(str) then if str = "" then failure else decimal_scan(str) }. public define Int get_Int ( List(Web_arg) lwa, String name, Int default_value ) = if get_Int(lwa, name) is { failure then default_value, success(value) then value }. public define Maybe(Int) get_Int ( List(Web_arg) lwa, String name, Int min, Int max, ) = if get_Int(lwa, name) is { failure then /*logDebug(debug_log, "Can't convert argument '" + name + "' to integer.");*/ failure success(value) then if (value < min) | (value > max) then /*logDebug(debug_log, "The entered value (" + val + ")is out of boundaries [" + min + "," + max + "].");*/ failure else success(value) }. public define Int get_Int ( List(Web_arg) lwa, String name, Int min, Int max, Int default_value ) = if get_Int(lwa, name, min, max) is { failure then default_value, success(value) then value }. public define List(Int) get_Int_list ( List(Web_arg) l, String name ) = if l is { [] then [], [h . t] then if h is web_arg(n, v) then if n = name then //println("matching int name "+name+" value "+v); if decimal_scan(v) is { failure then get_Int_list(t, name), success(value) then [ value . get_Int_list(t, name)] } else get_Int_list(t, name) else get_Int_list(t, name) } . public define Maybe(Float) get_Float ( List(Web_arg) lwa, String name ) = if web_arg_value(lwa, name) is { not_found then /*logDebug(debug_log, "Can't find argument '" + name + "'");*/ failure found(str) then if str = "" then failure else string_to_float(str) }. public define Float get_Float ( List(Web_arg) lwa, String name, Float default_value ) = if get_Float(lwa, name) is { failure then default_value, success(value) then value }. public define Maybe(Word32) get_Word32 ( List(Web_arg) lwa, String name ) = if get_Int(lwa, name) is { failure then failure, success(int_val) then success(truncate_to_Word32(int_val)) }. public define Word32 get_Word32 ( List(Web_arg) lwa, String name, Word32 default_value ) = if get_Word32(lwa, name) is { failure then /*logDebug(debug_log, "Can't convert argument '" + name + "' to integer.");*/ default_value, success(value) then value }. public define Maybe(Word32) get_Word32 ( List(Web_arg) lwa, String name, Word32 min, Word32 max, ) = if get_Word32(lwa, name) is { failure then failure success(value) then if value +< min | value >+ max then failure else success(value) }. public define Word32 get_Word32 ( List(Web_arg) lwa, String name, Word32 min, Word32 max, Word32 default_value ) = if get_Word32(lwa, name, min, max) is { failure then default_value, success(value) then value }. public define Maybe(Word8) get_Word8 ( List(Web_arg) lwa, String name ) = if get_Int(lwa, name) is { failure then failure, success(int_val) then success(truncate_to_Word8(int_val)) }. public define Maybe(Word8) get_Word8 ( List(Web_arg) lwa, String name, Word8 min, Word8 max, ) = if get_Word8(lwa, name) is { failure then failure success(value) then if value +< min | value >+ max then failure else success(value) }. public define Word8 get_Word8 ( List(Web_arg) lwa, String name, Word8 min, Word8 max, Word8 default_value ) = if get_Word8(lwa, name, min, max) is { failure then default_value, success(value) then value }. public define WEB_Action_Name get_WEB_Action_Name ( List(Web_arg) lwa, String controller, String action )= if get_String(lwa, action) is { failure then no_action success(action_n) then if get_String(lwa, controller) is { failure then action_name(action_n) success(controller_n) then controller_action(controller_n, action_n) } } .