choices_selector.anubis
3.4 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
/*
* Created by PyramIDE.
* User: フランスのトトロ aka (David RENÉ)
* Date: 06/04/2016
* Time: 22:54
* © Calexium
*/
read hayamiki_lib/types/hayamiki.anubis
read tools/basis.anubis
read tools/streams.anubis
read system/string.anubis
read fields.anubis
read columns.anubis
read html.anubis
define Maybe(One)
_generate_choices_selector
(
Stream stream,
String table_name,
String column_name,
List(HK_Text_Choice) choices
)=
//generate the type of the table that contain all components
if write_string(stream,
"\n\n"+
"public define List((List(CoreAttrs), WebArgValue, String))\n"+
" get_choices_selector_"+table_name+"_"+column_name+"\n"+
" (\n"+
" SQLite3DataBase db,\n"+
" HK_Referer referer, //Not used, only there for compatibility\n"+
" String filter //Not used, only there for compatibility\n"+
" )=\n"+
" [\n"+
concat(map((HK_Text_Choice hk_txt_choice) |->
since hk_txt_choice is hk_text_choice(value, visible),
" ([], wav(\""+value+"\"), \""+visible+"\"),\n", choices))+
" ]."
) is //end of the function
{
failure then println("can't write generate_choices_selector_"+table_name+"_"+column_name); failure,
success(_) then success(unique)
}.
define Maybe(One)
_generate_choices_int_selector
(
Stream stream,
String table_name,
String column_name,
List(HK_Int_Choice) choices
)=
//generate the type of the table that contain all components
if write_string(stream,
"\n\n"+
"public define List((List(CoreAttrs), WebArgValue, String))\n"+
" get_choices_selector_"+table_name+"_"+column_name+"\n"+
" (\n"+
" SQLite3DataBase db,\n"+
" String clause\n"+
" )=\n"+
" [\n"+
concat(map((HK_Int_Choice hk_int_choice) |->
since hk_int_choice is hk_int_choice(value, visible),
" ([], wav(\""+to_String(value)+"\"), \""+visible+"\"),\n", choices))+
" ]."
) is //end of the function
{
failure then println("can't write generate_choices_selector_"+table_name+"_"+column_name); failure,
success(_) then success(unique)
}.
public define Maybe(One)
generate_choices_selector
(
Stream stream,
HK_Table table
)=
since table is hk_table(table_name, short_name, model, _),
since model is hk_model( columns, show_string),
map_forget((HK_Model_Column column) |->
since column is hk_column(column_name, field_type, _, _),
if field_type is char_field(choices, _) then
if choices is
{
no_choice then success(unique),
text_choices(choices_list) then
_generate_choices_selector(stream, table_name, column_name, choices_list)
}
else if field_type is integer_field(choices) then
if choices is
{
no_choice then success(unique),
int_choices(choices_list) then
_generate_choices_int_selector(stream, table_name, column_name, choices_list)
}
else
success(unique), columns);
success(unique).
with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.