Commit 87ca803d43f37584cc32f084fb55fa39f131d6ab

Authored by totoro
1 parent f80d566f

add int_choices to integer_field

hayamiki_lib @ c6605b532d8
1   -Subproject commit f3cb0a1f4255b7c9a03256ab1b5d4f424789d139
  1 +Subproject commit c6605b532d8610d3bbbad66926aa149aa86e8f88
... ...
src/generation/columns.anubis
... ... @@ -137,9 +137,9 @@ public define Maybe(String)
137 137 auto_now_add then
138 138 if insert then success(name) else failure
139 139 },
140   - foreign_key(_,_) then success(name),
141   - integer_field then success(name),
142   - char_field(_,_) then success(name),
  140 + foreign_key(_,_) then success(name),
  141 + integer_field(_) then success(name),
  142 + char_field(_,_) then success(name),
143 143 text_field then success(name)
144 144 }.
145 145  
... ... @@ -225,7 +225,19 @@ public define Maybe(String)
225 225 auto_now_add then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, 18, "+to_Anubis_source(help)+")")
226 226 },
227 227 foreign_key(app,foreign_table) then success("foreign_text(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", vt_edit_selector(get_selector_"+foreign_table+"), "+to_Anubis_source(help)+")"),
228   - integer_field then success("integer(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"),
  228 + integer_field(choices) then
  229 + //success("integer(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"),
  230 + if choices is
  231 + {
  232 + no_choice then success("integer(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"),
  233 + int_choices(choices_list) then
  234 + //if choice list is NOT empty we construct the possible choices selector
  235 + if length(choices_list) > 0 then
  236 + success("choices_int(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", vt_edit_selector(get_choices_selector_"+to_lower(type_name)+"_"+name+"), "+to_Anubis_source(help)+")")
  237 + else
  238 + success("integer(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"),
  239 + }
  240 +
229 241 //TODO make choices selection if need
230 242 char_field(choices,_) then
231 243 if choices is
... ... @@ -290,9 +302,9 @@ public define String
290 302 */
291 303 to_String
292 304 (
293   - HK_Model_Column col,
294   - String current_type_name,
295   - String general_type_name
  305 + HK_Model_Column col, //Model of the column
  306 + String current_type_name, //Instance name of the type i.e. toto (this is instance of Toto_Type below)
  307 + String general_type_name //Type declaration name i.e. Toto_Type
296 308 ) =
297 309 since col is hk_column(name, col_type, _, _),
298 310 if col_type is
... ... @@ -305,7 +317,7 @@ public define String
305 317 time_field(attrs) then "to_String("+current_type_name+"."+name+")",
306 318 datetime_field(attrs) then "to_String("+current_type_name+"."+name+")"
307 319 foreign_key(app,foreign_table) then "get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+")",
308   - integer_field then "to_String("+current_type_name+"."+name+")",
309   - char_field(_,_) then current_type_name+"."+name,
  320 + integer_field(_) then "to_String("+current_type_name+"."+name+")",
  321 + char_field(_,_) then current_type_name+"."+name,
310 322 text_field then current_type_name+"."+name
311 323 }.
... ...
src/generation/fields.anubis
... ... @@ -15,6 +15,8 @@ read hayamiki_lib/types/model/columns.anubis
15 15 read model.anubis
16 16  
17 17 public define String
  18 +/** Return the corresponding Anubis type of the field
  19 + */
18 20 to_Anubis_type
19 21 (
20 22 HK_Model_Field t
... ... @@ -29,7 +31,7 @@ public define String
29 31 time_field(_) then "DB_time",
30 32 datetime_field(_) then "DB_datetime",
31 33 foreign_key(_,_) then "Int",
32   - integer_field then "Int",
  34 + integer_field(_) then "Int",
33 35 char_field(_,_) then "String",
34 36 text_field then "String"
35 37 }.
... ... @@ -49,7 +51,7 @@ public define String
49 51 time_field(_) then fill("TIME", 15) +format_attributes(attributes),
50 52 datetime_field(_) then fill("DATETIME", 15)+format_attributes(attributes),
51 53 foreign_key(app,fk) then fill("INTEGER", 15) +format_attributes(attributes)+" REFERENCES "+fk+"(id) ",
52   - integer_field then fill("INTEGER", 15) +format_attributes(attributes),
  54 + integer_field(_) then fill("INTEGER", 15) +format_attributes(attributes),
53 55 char_field(_,size) then fill("VARCHAR("+size+")", 15) +format_attributes(attributes),
54 56 text_field then fill("TEXT", 15) +format_attributes(attributes),
55 57 }.
... ... @@ -68,8 +70,8 @@ public define String
68 70 date_field(_) then "db_date(\"\")",
69 71 time_field(_) then "db_time(\"\")",
70 72 datetime_field(_) then "db_datetime(\"\")",
71   - foreign_key(_,_) then "(Int)0",
72   - integer_field then "(Int)0",
  73 + foreign_key(_,_) then "(Int)0",
  74 + integer_field(_) then "(Int)0",
73 75 char_field(choices,size) then "\"\"",
74 76 text_field then "\"\""
75 77 }.
... ... @@ -90,7 +92,7 @@ public define String
90 92 time_field(attrs) then if attrs = none then "get_DB_time(lwa, __prefix__+\""+name+"\")" else "with "+name+" = get_dummy_DB_time,",
91 93 datetime_field(attrs) then if attrs = none then "get_DB_datetime(lwa, __prefix__+\""+name+"\")" else "with "+name+" = get_dummy_DB_datetime,",
92 94 foreign_key(_,_) then "get_Int(lwa, __prefix__+\""+name+"\")",
93   - integer_field then "get_Int(lwa, __prefix__+\""+name+"\")",
  95 + integer_field(_) then "get_Int(lwa, __prefix__+\""+name+"\")",
94 96 char_field(_,_) then "get_String(lwa, __prefix__+\""+name+"\")",
95 97 text_field then "get_String(lwa, __prefix__+\""+name+"\")"
96 98 }.
... ... @@ -111,7 +113,7 @@ public define String
111 113 time_field(_) then "db_time(text"+cursor_index+")",
112 114 datetime_field(_) then "db_datetime(text"+cursor_index+")",
113 115 foreign_key(_,_) then "(Int)db_integer"+cursor_index,
114   - integer_field then "(Int)db_integer"+cursor_index,
  116 + integer_field(_) then "(Int)db_integer"+cursor_index,
115 117 char_field(_,_) then "text"+cursor_index,
116 118 text_field then "text"+cursor_index
117 119 }.
... ... @@ -143,7 +145,7 @@ public define String
143 145 ""
144 146 },
145 147 foreign_key(_,_) then "bind_Int(\":v_"+name+"\", "+type_name+"."+name+")",
146   - integer_field then "bind_Int(\":v_"+name+"\", "+type_name+"."+name+")",
  148 + integer_field(_) then "bind_Int(\":v_"+name+"\", "+type_name+"."+name+")",
147 149 char_field(_,_) then "bind_String(\":v_"+name+"\", "+type_name+"."+name+")",
148 150 text_field then "bind_String(\":v_"+name+"\", "+type_name+"."+name+")"
149 151 }.
... ...
src/generation/html.anubis
... ... @@ -92,9 +92,9 @@ public define String
92 92 date_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name),
93 93 time_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name),
94 94 datetime_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name),
95   - foreign_key(app,foreign_table) then to_HTML_cell_text(column, data_name, general_type_name),
96   - integer_field then to_HTML_cell_text(column, data_name, general_type_name),
97   - char_field(choices,size) then to_HTML_cell_text(column, data_name, general_type_name),
  95 + foreign_key(app, foreign_table) then to_HTML_cell_text(column, data_name, general_type_name),
  96 + integer_field(choices) then to_HTML_cell_text(column, data_name, general_type_name),
  97 + char_field(choices, size) then to_HTML_cell_text(column, data_name, general_type_name),
98 98 text_field then to_HTML_cell_text(column, data_name, general_type_name),
99 99 }
100 100 }.
... ...
src/generation/icons.anubis
... ... @@ -29,7 +29,7 @@ public define String
29 29 time_field(attrs) then icn16_clock,
30 30 datetime_field(attrs) then icn16_clock,
31 31 foreign_key(app,foreign_table) then icn16_question,
32   - integer_field then icn16_question,
  32 + integer_field(choice) then icn16_question,
33 33 char_field(choice, size) then icn16_question,
34 34 text_field then icn16_question
35 35 }.
... ...