controller.anubis
3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Created by PyramIDE.
* User: フランスのトトロ aka (David RENÉ)
* Date: 18/04/2020
* Time: 00:50
* © David RENÉ
*/
read system/logger.anubis
read language_web_action_name.anubis
read hayamiki_lib/model/types/hk_database.anubis
read hayamiki_lib/view/view_table_manager_types.anubis
read xlib/web/controllers_web_site.anubis
read xlib/web_controllers/language/language_management.anubis
read xlib/web/plugin/plugin.anubis
define WEB_Action
do_change_language
=
web_action(
do_change_language,
http_https,
(WEB_Session _session) |-> true,
(WEB_Session _session) |->
//
since _session is web_session(id, _old_lang, fields, current, previous, draw),
//increment 1 to message TTL
with step = get_Int(fields, "AWS_SESSION_STEP",0),
replace_Int(fields, "PAGE_MESSAGE_TTL", step+1);
if web_arg_value(*current.lwa, "language_code") is
{
not_found then redirect_to_previous, //http_answer(web_session(id, _old_lang, fields, previous, previous), plain_text(http_no_content, "")) //
found(language_code) then //http_answer(web_session(id, language_code, fields, previous, previous), plain_text(http_no_content, ""))
with new_web_session = web_session(id, language_code, fields, draw, previous, draw),
// println("------- language change. New web session ---------");
// println(dump(new_web_session));
// println("--------------------------------------------------");
redirect(new_web_session)
}
)
.
public define HTTP_Answer
ajax_translate_to_json
(
WEB_Session _session,
String symbolic_names //list of symbolic names to translate separated by comma i.e. "JAN,FEB"
) =
with _T = make_translate_function(_session),
//construct a list of json_member with "symbolic_name: translated value"
with translated_list = map((String symbolic) |-> json_member(symbolic, json_string(_T(symbolic))), split_by_token(symbolic_names,',')),
json(http_ok, json_object(translated_list))
.
define WEB_Action
ajax_translate_json
=
web_action(
ajax_translate_json,
https,
(WEB_Session _session) |-> true,
(WEB_Session _session) |->
//here the function really call for creating domain name
since _session is web_session(id, lang, _, web_request, _, _draw),
if web_arg_value(*web_request.lwa, "to_translate") is
{
not_found then redirect_to_previous
found(symbolic_names) then ajax(ajax_translate_to_json(_session, symbolic_names))
}
)
.
public define List(WEB_Action)
make_language_actions =
[
//action lors de la demande de création d'un user dans un domaine
do_change_language,
ajax_translate_json
].
public define WEB_Controller
get_lang_controller
=
web_controller("language", var(make_language_actions))
.
public define List(WEB_Controller)
plugin_get_controller
(
SQLite3DataBase db,
HK_Database hk_db,
VTM _vtm,
(LogLevel, String) -> One logger
) =
[get_lang_controller]
.
define Maybe(HTML_Partial_Content)
plugin_get_typed_content
(
SQLite3DataBase db,
WEB_Session _session,
String type
)=
println("plugin_get_typed_content for L3 type "+type);
if type = "LEFT_MENU" then failure
else if type = "TOOLBAR" then failure
else if type = "CONTROL_PANEL" then failure
else
failure
.
module WEB_Plugin
l3_lib_1_19
=
web_plugin(
"L3",
"BASE",
"1.19.0",
_Int_to_ISO_8601_datetime(to_Int(__TIME__)),
plugin_get_controller,
plugin_get_typed_content
)
.