Commit 24513ca0e22583a0dc9b6c90f84274657e7efdef

Authored by totoro
1 parent 366f56a3

add editor attributes for text_field, like none for usual text area or rich_edit…

…or for using CK editor
Showing 2 changed files with 60 additions and 7 deletions   Show diff stats
types/model/fields.anubis
... ... @@ -106,6 +106,49 @@ public type HK_Int_Choices:
106 106 no_choice, //No list choice is available. Hence the user must enter the value
107 107 int_choices(List(HK_Int_Choice)). //List of possible choices
108 108  
  109 +public type HK_Text_Field_Attr:
  110 + none, //Nothing special, normal behaviour
  111 + rich_editor. //Use richt text editor for that area
  112 +
  113 +define String
  114 + to_String
  115 + (
  116 + HK_Text_Field_Attr attr
  117 + )=
  118 + if attr is
  119 + {
  120 + none then "none",
  121 + rich_editor then "rich_editor"
  122 + }.
  123 +
  124 +public define String
  125 + to_Anubis_source
  126 + (
  127 + HK_Text_Field_Attr attr
  128 + )=
  129 + to_String(attr)
  130 +.
  131 +
  132 +define HK_Text_Field_Attr
  133 + to_HK_Text_Field_Attr
  134 + (
  135 + String txt_attr_str
  136 + )=
  137 + if txt_attr_str = "none" then none else
  138 + if txt_attr_str = "rich_editor" then rich_editor
  139 + else none
  140 +.
  141 +
  142 +define HK_Text_Field_Attr
  143 + get_text_attribute
  144 + (
  145 + Message msg
  146 + )=
  147 + if find_string(msg, "text_attribute") is
  148 + {
  149 + failure then none,
  150 + success(text_attrib) then to_HK_Text_Field_Attr(text_attrib)
  151 + }.
109 152  
110 153 public type HK_Datetime_Field_Attr:
111 154 none, //Nothing special, normal behaviour
... ... @@ -155,7 +198,7 @@ public type HK_Model_Field:
155 198 integer_field (HK_Int_Choices choices), // integer of arbitrary size
156 199 char_field (HK_Text_Choices choices, Int size), // text of maximal size 'size' (number of characters)
157 200 password_field(Int min_size), // the password field doesn't show the password string or store it in hashed version into database
158   - text_field. // text of variable size
  201 + text_field (HK_Text_Field_Attr). // text of variable size
159 202  
160 203 //default initialization
161 204 public define HK_Model_Field
... ... @@ -177,6 +220,12 @@ public define HK_Model_Field
177 220 )=
178 221 foreign_key(this, table_name).
179 222  
  223 +public define HK_Model_Field
  224 + text_field
  225 + =
  226 + text_field(none)
  227 +.
  228 +
180 229 /* *
181 230 _HK_FIELD message format:
182 231 =============================
... ... @@ -248,8 +297,9 @@ public define Message
248 297 forget(add_string(hk_model_field_message, "type", "password_field"));
249 298 forget(add_int32(hk_model_field_message, "size", truncate_to_Word32(size))),
250 299  
251   - text_field then // text of variable size
252   - forget(add_string(hk_model_field_message, "type", "text_field"))
  300 + text_field(text_attr) then // text of variable size
  301 + forget(add_string(hk_model_field_message, "type", "text_field"));
  302 + forget(add_string(hk_model_field_message, "text_attribute", to_String(text_attr))),
253 303  
254 304 };
255 305 hk_model_field_message
... ... @@ -305,8 +355,10 @@ public define JsonValue
305 355 json_member("size", json_int(size))
306 356 ],
307 357  
308   - text_field then // text of variable size
309   - [ json_member("type", json_string("text_field"))]
  358 + text_field(attr) then // text of variable size
  359 + [ json_member("type", json_string("text_field")),
  360 + json_member("text_attribute", json_string(to_String(attr)))
  361 + ]
310 362 },
311 363  
312 364 json_object("_HK_FIELD", members).
... ... @@ -335,7 +387,7 @@ define Maybe(HK_Model_Field)
335 387 else if type = "password_field" then
336 388 if find_int32(hk_model_field_message, "size") is {failure then failure, success(w32_size) then
337 389 success(password_field(to_Int(w32_size)))}
338   - else if type = "text_field" then success(text_field)
  390 + else if type = "text_field" then success(text_field(get_text_attribute(hk_model_field_message)))
339 391 else failure
340 392 .
341 393  
... ...
view/view_table_types.anubis
... ... @@ -12,6 +12,7 @@ read hayamiki_lib/types/hayamiki.anubis
12 12 public type VT_edit_selector:
13 13 vt_edit_selector((SQLite3DataBase db) -> List((List(CoreAttrs), WebArgValue, String)) get).
14 14  
  15 +
15 16 public type VT_edit_entry:
16 17 hidden (String name, String value),
17 18 primary_key (String idx),
... ... @@ -21,7 +22,7 @@ public type VT_edit_entry:
21 22 foreign_text(String s_name, String c_name, DB_id selected, VT_edit_selector selector, HK_Help_Text help),
22 23 choices_text(String s_name, String c_name, String selected, VT_edit_selector selector, HK_Help_Text help),
23 24 text_area (String s_name, String c_name, String value, HK_Help_Text help), //s_name = show_name for translate, c_name = table column name
24   - boolean (String s_name, String c_name, Bool value, HK_Help_Text help),
  25 + boolean (String s_name, String c_name, Bool value, HK_Text_Field_Attr area_att, HK_Help_Text help),
25 26 integer (String s_name, String c_name, Int value, HK_Help_Text help),
26 27 choices_int (String s_name, String c_name, Int selected, VT_edit_selector selector, HK_Help_Text help),
27 28 date (String s_name, String c_name, String value, HK_Help_Text help),
... ...