/*
* Created by PyramIDE.
* User: Totoro
* Date: 30/11/2011
* Time: 21:22
*
*/
read hayamiki_lib/view/types/hk_form_entry.anubis
read hayamiki_lib/view/types/hk_form.anubis
read hayamiki_lib/view/types/hk_view.anubis
read hayamiki_lib/view/jqgrid.anubis
read hayamiki_lib/view/view_table_manager_types.anubis
read hayamiki_lib/view/view_table_manager.anubis
read hayamiki_lib/view/web_action.anubis
read hayamiki_lib/types/hayamiki.anubis
read system/string.anubis
read locale/L3.anubis
read tools/basis.anubis
read tools/list.anubis
read data_base/sqlite.anubis
read system_colors/rgb.anubis
read system/convert.anubis
//read utils.anubis
read locale/L3LanguageInfo.anubis
read calexium_lib/web/CXM_common.anubis
read calexium_lib/web/CXM_web_arg_utils.anubis
read calexium_lib/web/CXM_making_a_web_site.anubis
read calexium_lib/web/CXM_multihost_http_server.anubis
read calexium_lib/web/jQuery/CXM_jquery_datatable.anubis
read calexium_lib/web/jQuery/CXM_jquery_datatable_types.anubis
read calexium_lib/web/jQuery/CXM_jquery_dialog.anubis
read calexium_lib/web/jQuery/CXM_jquery_button.anubis
read calexium_lib/web/jQuery/ui-addon/datetimepicker.anubis
read calexium_lib/web/jQuery/jqgrid.anubis
read calexium_lib/web/CXM_form.anubis
read calexium_lib/web/widgets/css_helper.anubis
read calexium_lib/web/widgets/button.anubis
read calexium_lib/web/CXM_urllib.anubis
define HTML_Off_Form
/* create a selector for choosing the view name.
* The selector create an immediate action. This means when the entry is selected, the action is fired.
* If only one view exists, the selector is not created
*/
table_view_selector
(
(String) -> String _T, //translator function
VTM_view vtm_v, //virtual table manager view
String current_view //
)=
if length(vtm_v.get_all_view_name(unique)) = 1 then
empty
else
form( "table_view_selector", [], "", [],
actioner(same, same,
immediate_selector([id("select_view")],
wan("view_name"), //web arg name of the selected entry
1,
map((String view_name) |-> ([], wav(view_name), _T(view_name)), vtm_v.get_all_view_name(unique)),
success(init(current_view)),
""
),
hkc_list_view,
[("table_name", vtm_v.table_name)], []))
.
// View table part
define HTML_Row(HTML_Off_Form) make_line
(
String uid,
String table_name,
String _action_name, //default is "edit_table", but can be surcharged for own use
List(VT_view_entry) entries,
List(HTML_Cell(HTML_Off_Form)) so_far
)=
if entries is
{
[] then row( [], reverse(so_far)),
[h . t] then
with cell = if h is
{
text(string) then cell((HTML_Off_Form)text(not_null_String(string))),
// link(id, string) then cell((HTML_Off_Form)actioner(same,same, link(string), action_name, [("table_name", table_name),("id",id)])),
link(id, string) then cell((HTML_Off_Form)literal(jq_dialog_open(string, dialog_id(uid+_action_name+"_dlg_ajax"), "'id="+id+"'"))),
link_id_action(id, name, action) then cell((HTML_Off_Form)actioner(same,same, link(name), action, [("id",id)])),
icon(icon_path) then cell((HTML_Off_Form)image([], icon_path, ""))
},
make_line(uid, table_name, _action_name, t, [cell . so_far])
}.
define List(HTML_Row(HTML_Off_Form))
make_lines
(
(String) -> String _T, //translator
String uid,
String table_name,
String action_name,
List(VT_view_row) entries,
List(HTML_Row(HTML_Off_Form)) so_far
)=
if entries is
{
[] then reverse(so_far),
[h . t] then
//compute each line
//prepare here the first cell for actioner
with actions_cell = (HTML_Cell(HTML_Off_Form))
cell([],
sequence([
partial(img_button_confirm(icn16_cross, _T("CONFIRMATION_REQUEST"), _T("CONFIRM_LINE_DELETION") , _T("OK"), _T("CANCEL"), jQuery_actioner(same, jqlink(controller_action("hk_c", "delete_row" + format_extra_operands([("table_name", table_name),("id",to_String(h.db_id))])))))),
partial(img_button(icn16_edit, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax"), "'id="+to_String(h.db_id)+"'"))], "", [])),
])
),
make_lines(_T, uid, table_name, action_name, t, [make_line(uid, table_name, action_name, h.list, [actions_cell]). so_far] )
}.
// View table part
define HTML_Header_Row(HTML_Off_Form)
make_header
(
(String) -> String _T, //translator
List(VT_view_entry) entries,
List(HTML_Header_Cell(HTML_Off_Form)) so_far
)=
if entries is
{
[] then header_row( [], reverse(so_far)),
[h . t] then
with cell = if h is
{
text(string) then header_cell((HTML_Off_Form)text(_T(string))),
link(id, string) then header_cell((HTML_Off_Form)actioner(same, same, link(string), hkc_edit_table,[])), //TODO
link_id_action(id, text, action) then header_cell((HTML_Off_Form)actioner(same,same, link(text), action,[("id",id)])), //TODO
icon(icon_path) then header_cell((HTML_Off_Form)image([], icon_path, ""))
},
make_header(_T, t, [cell . so_far])
}.
public define HTML_Partial_Content
view_table_form
(
(String) -> String _T,
String uid,
String action_name,
VT_view rows
)=
with action_header_cell = header_cell((HTML_Off_Form)text(_T("ACTION"))),
partial_content(
div( [/*class("tableau")*/],
sequence(
[
//partial(jq_dialog_create(dialog_id(uid+action_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&table_name="+rows.table_name)))),
//table([core_attrs([id(uid+"table_view"), class("tableau display compact nowrap")])],
// make_header(_T, rows.header.list, [action_header_cell])
// make_lines(_T, uid, rows.table_name, action_name, rows.list, [])
//)
]
)
))
.
define String
jqGrid_options
(
String uid,
VT_view rows,
(String) -> String _T
)=
"
editurl: '?aws_controller=hk_c&aws_action=grid_action&table_name="+rows.table_name+"',
iconSet: \"fontAwesome\",
autowidth:true,
shrinkToFit:false,
rowNum:30,
rowList:[5,10,30,50],
cellEdit: false,
cellsubmit: 'remote',
cellurl: '?aws_controller=hk_c&aws_action=grid_action&table_name="+rows.table_name+"',
editurl: '?aws_controller=hk_c&aws_action=grid_action&table_name="+rows.table_name+"',
onSelectRow: function (rowid, status, e) {
var $self = $(this), savedRow = $self.jqGrid(\"getGridParam\", \"savedRow\");
if (savedRow.length > 0 && savedRow[0].id !== rowid) {
$self.jqGrid(\"restoreRow\", savedRow[0].id);
}
},
ondblClickRow: function (rowid, iRow, iCol, e) {
var $self = $(this), savedRow = $self.jqGrid(\"getGridParam\", \"savedRow\");
if (savedRow.length > 0 && savedRow[0].id !== rowid) {
$self.jqGrid(\"restoreRow\", savedRow[0].id);
}
$self.jqGrid(\"editRow\", rowid, { focusField: e.target });
},
pager: '#"+uid+"_pager',
caption:"+to_JSON_String(_T(to_upper(rows.table_name)))+",
actionsNavOptions: {
openicon: \"fa-folder-open-o\",
opentitle: \"Open (Enter)\",
isDisplayButtons: function (options, rowData) {
if (options.rowData.closed) { // or rowData.closed
return { post: { hidden: true }, del: { display: false } };
}
},
custom: [
{ action: \"open\", position: \"first\",
onClick: function (options) {"+
jq_dialog_open(dialog_id(uid+"edit_table_dlg_ajax"), "'id='+options.rowid")+
"
}
}
]
}
"
// ondblClickRow: function( rowid) {"+
// jq_dialog_open(dialog_id(uid+"edit_table_dlg_ajax"), "'id='+rowid")+
.
public define HTML_Partial_Content
jqGrid_table
(
SQLite3DataBase db,
String uid,
VT_view rows,
(String) -> String _T,
String lang,
String clause,
HK_Referer table_referer
)=
with filter_clause = if clause = "" then "" else "&clause="+url_quote(clause),
with referer_arg = "&"+to_Web_arg(table_referer, ""),
with js = js_inline(jquery_ready("var lastSel;$(\"#"+uid+"_grid\").jqGrid({\n"+
"url:'?aws_controller=hk_c&aws_action=grid_view&table_name="+rows.table_name+"&view_name="+rows.view_name+filter_clause+referer_arg+"',"+
"datatype: \"json\","+
to_jqGrid_ColModel(db, table_referer, _T, rows.view_model.list)+","+
// rows.json_data_string+
jqGrid_options(uid, rows, _T)+
",loadComplete: function () {
jscolor.installByClassName(\"jscolor\");
}
}).jqGrid(\"gridResize\");
function formatColor(cellValue, options, rowObject) {
var colorInput = \"\";
return colorInput;
}
function unformatColor(cellValue, options, cellObject) {
return $(cellObject.html()).css(\"backgroundColor\").substring(1);
}
function formatPhone(cellValue, options, rowObject) {
var phoneInput = '
' + cellValue + '';
return phoneInput;
}
function unformatPhone(cellValue, options, cellObject) {
var jqo = $(cellObject);
var ret = jqo.text();
return ret;
}
function formatEmail(cellValue, options, rowObject) {
var phoneInput = '
' + cellValue + '';
return phoneInput;
}
function unformatEmail(cellValue, options, cellObject) {
var jqo = $(cellObject);
var ret = jqo.text();
return ret;
}")),
partial_content(jqgrid_init(lang) + [js],
div([],
sequence([
table([core_attrs([id(uid+"_grid")])],[]),
div_empty([id(uid+"_pager")])
])
)
)
.
public define HTML_Partial_Content
view_table_page
(
SQLite3DataBase db,
(String) -> String _T,
String lang,
String web_site_directory,
String action_name,
VTM_view vtm_v,
String view_name,
String f_clause, //filter for current table
HK_Referer table_referer,
String fk_clause //filter for foreign key of the table (one to many)
) =
with filter_clause = if f_clause = "" then "" else "&clause="+url_quote(f_clause),
//with foreign_clause = if fk_clause = "" then "" else "&fk_clause="+url_quote(fk_clause),
with referer_arg = "&"+to_Web_arg(table_referer, ""),
with current_view = vtm_v.get_view(view_name),
with uid = generate_random_string(20)+"_",
partial_content([ js(js_file("js/jscolor.min.js"))
]+jq_dialog_init + jq_datetimepicker_init(lang),
[html_wave_box_wide(_T(to_upper(current_view.table_name)),
sequence([
//create the dialog
partial(jq_dialog_create(dialog_id(uid+action_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&table_name="+current_view.table_name+filter_clause+referer_arg)))),
div([class("inline")], sequence([
// (+) icon for adding new entry
partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])),
// view selector if there is more than one view name
table_view_selector(_T, vtm_v, view_name),
])),
//grid with data
partial(jqGrid_table(db, uid, current_view, _T, lang, f_clause, table_referer))
//partial(jquery_datatable(uid+"table_view", view_table_form(_T, uid, action_name, rows), true, false, jq_dt_pt_full_numbers, false, scrollY(500), true, true, true, lang, no_extra, web_site_directory))
]))]).
public define HTML_Partial_Content
table_in_list_view
(
SQLite3DataBase db,
(String) -> String _T,
String lang,
String web_site_directory,
String action_name,
VTM_view vtm_v,
String view_name,
String f_clause, //filter for current table
HK_Referer table_referer,
String fk_clause //filter for foreign key of the table (one to many)
) =
with filter_clause = if f_clause = "" then "" else "&clause="+url_quote(f_clause),
with foreign_clause = if fk_clause = "" then "" else "&fk_clause="+url_quote(fk_clause),
with referer_arg = "&"+to_Web_arg(table_referer, ""),
with current_view = vtm_v.get_view(view_name),
with uid = generate_random_string(20)+"_",
partial_content([ js(js_file("js/jscolor.min.js"))
]+
jq_dialog_init +
jq_datetimepicker_init(lang),
[
partial(jq_dialog_create(dialog_id(uid+action_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&table_name="+current_view.table_name+filter_clause+referer_arg)))),
partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])),
//table_view_selector(_T, vtm_v, view_name),
partial(jqGrid_table(db, uid, current_view, _T, lang, fk_clause, table_referer)),
//partial(jquery_datatable(uid+"table_view", view_table_form(_T, uid, action_name, rows), true, false, jq_dt_pt_full_numbers, false, scrollY(200), true, true, true, lang, no_extra, web_site_directory))
]).
public define Maybe(HTML_Partial_Content)
view_table_content
(
SQLite3DataBase db,
(String) -> String _T,
String lang,
String web_site_directory,
String table,
String view_name,
String action_name,
String f_clause,
HK_Referer table_referer,
String fk_clause,
VTM vtm
) =
if vtm_get_view(table, vtm.view_list) is
{
failure then failure,
success(vtm_v) then
success(view_table_page(db, _T, lang, web_site_directory, action_name, vtm_v, view_name, f_clause, table_referer, fk_clause))
}.
public define Maybe(HTML_Partial_Content)
table_in_list_view_only
(
SQLite3DataBase db,
(String) -> String _T,
String lang,
String web_site_directory,
String table,
String view_name,
String action_name,
String f_clause,
HK_Referer table_referer,
String fk_filter,
VTM vtm
) =
if vtm_get_view(table, vtm.view_list) is
{
failure then failure,
success(vtm_v) then
success(table_in_list_view(db, _T, lang, web_site_directory, action_name, vtm_v, view_name, f_clause, table_referer, fk_filter))
}.
define CXM_Form_Field
help_line
(
HK_Help_Text help,
(String) -> String _T
)=
if help is
{
no_help_text then empty,
help_text_TAG(tag) then explain(_T(tag)),
help_text(str) then explain(str)
}.
//Edit table part
public define List(CXM_Form_Field)
edit_form_lines
(
SQLite3DataBase db,
String fk_clause,
HK_Referer table_referer,
(String) -> String _T,
List(HK_Form_Entry) list,
Bool new_entry,
List(CXM_Form_Field) so_far
)=
if list is
{
[] then reverse(so_far),
[ h . t] then
with line =
if h is
{
empty then [empty],
hidden(name, value) then
//print("hidden "+name+" = "+value);
[hidden(html_Id(""), wan(name), wav(value))],
label(name) then
[div([],text(name))],
primary_key(idx) then
[hidden(html_Id(""), wan("id"), wav(idx))],
information(s_name, c_name, value, width, help) then
[input_readonly(label(_T(s_name), no_help), wan(c_name), init(not_null_String(value)), if width > 0 then custom(width) else narrow), help_line(help, _T)],
text(s_name, c_name, value, help) then
[input(label(_T(s_name), no_help), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
password(s_name, c_name, help) then
with password_entries =
[ password_input(label(_T(s_name), no_help), wan(c_name+"_1"), init(""), narrow, non_mandatory),
password_input(label(_T(s_name), no_help), wan(c_name+"_2"), init(""), narrow, non_mandatory),
help_line(help, _T)
],
if new_entry = false then
[ checkbox_hide_show([], label(_T("CLICK_TO_CHANGE_PASSWORD")), wan(c_name+"_pwd_change"), wav("on"), false, //not checked at first
password_entries),
hidden(html_Id(""), wan(c_name+"_pwd_change_option"), wav("true"))
]
else
[ hidden(html_Id(""), wan(c_name+"_pwd_change_option"), wav("false")) .
password_entries
],
foreign_text(s_name, c_name, value, select, help) then
[selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, table_referer, fk_clause), success(init(to_String(value))), mandatory), help_line(help, _T)],
choices_text(s_name, c_name, value, select, help) then
[selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, no_referer, ""), success(init(value)), mandatory), help_line(help, _T)],
text_area(s_name, c_name, value, txt_editor, help) then
with id = if txt_editor is { none then "", rich_editor then c_name+"_editor"},
[text_area([],label(_T(s_name), no_help), html_Id(id), wan(c_name), init(not_null_String(value)), narrow, (Int)5, mandatory), help_line(help, _T)],
boolean(s_name, c_name, value, help) then
[checkboxr([],label(_T(s_name), no_help), html_Id(""), wan(c_name), wav("true"),value, mandatory), help_line(help, _T)],
integer(s_name, c_name, value, help) then
[input(label(_T(s_name), no_help), wan(c_name), init(abs_to_decimal(value)), small, mandatory), help_line(help, _T)],
float(s_name, c_name, value, help) then
[input(label(_T(s_name), no_help), wan(c_name), init(float_to_string(value, 5)), small, mandatory), help_line(help, _T)],
choices_int(s_name, c_name, value, select, help) then
[selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, no_referer, ""), success(init(to_String(value))), mandatory), help_line(help, _T)],
date(s_name, c_name, value, help) then
[input([class("datepicker")], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(value), small, non_mandatory), help_line(help, _T)],
time(s_name, c_name, value, help) then
[input([class("timepicker")], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(value), small, non_mandatory), help_line(help, _T)],
datetime(s_name, c_name, value, help) then
[input([class("datetimepicker")], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(value), custom(18), mandatory), help_line(help, _T)],
color( s_name, c_name, value, help) then
[input([class("jscolor")], label(_T(s_name), no_help), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
phone( s_name, c_name, value, help) then
[input([class("hk_input_phone")], label(_T(s_name), no_help), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
email( s_name, c_name, value, help) then
[input([class("hk_input_email")], label(_T(s_name), no_help), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
},
edit_form_lines(db, fk_clause, table_referer, _T, t, new_entry, reverse(line)+so_far)
}.
define List(String)
get_rich_editor_inline
(
List(HK_Form_Entry) list
)=
map_select((HK_Form_Entry entry) |->
if entry is text_area(s_name, c_name, value, txt_editor, help) then
if txt_editor is { none then failure,
rich_editor then success(" CKEDITOR.replace( '"+c_name+"_editor' );")
}
else
failure, list)
.
define List(HTML_Head_Tag)
get_editor_header
(
List(HK_Form_Entry) _list
)=
with result = get_rich_editor_inline(_list),
if length(result) > 0 then
[js(js_file("ckeditor/ckeditor.js")),
js_inline(jquery_ready(join("",result)))
]
else
[]
.
define List(String)
_get_editor_header
(
List(HK_Form_Table_Line) _lines
)=
map_append((HK_Form_Table_Line line)
|->
map_append((HK_Form_Table_Cell cell)
|->
if cell is
{
hk_form_table_cell(_, form_entry) then
if form_entry is text_area(s_name, c_name, value, txt_editor, help) then
if txt_editor is {
none then [],
rich_editor then [" CKEDITOR.replace( '"+c_name+"_editor' );"]
}
else
[],
hk_form_table_cell_table(_, t_lines) then
_get_editor_header(t_lines)
},
line.form_table_cells),
_lines)
.
define List(HTML_Head_Tag)
get_editor_header
(
List(HK_Form_Table_Line) _lines
)=
with result = _get_editor_header(_lines),
if length(result) > 0 then
[js(js_file("ckeditor/ckeditor.js")),
js_inline(jquery_ready(join("",result)))
]
else
[]
.
public define HTML_Partial_Content
renderer_edit_list_form
(
SQLite3DataBase db,
(String) -> String _T,
String lang,
String web_site_directory,
String table_name,
String view_name,
List(HK_Form_Entry) list_entries,
List(HK_Form_Tab) list_tabs,
List(Web_arg) lwa,
//HK_Form edit_form,
VTM vtm,
String clause,
String fk_clause,
HK_Referer table_referer //from which table and row id that editor is called
) =
//with table_name = vt_elist.table_name,
//true if need to create row or false for updating
with create = if get_String(lwa, "id","none") = "none" then true else false,
with id = get_String(lwa, "id","none"),
with button_name = if create then _T("CREATE") else _T("UPDATE"),
with button_name_and_new = if create then _T("CREATE_AND_EDIT_NEW") else _T("UPDATE_AND_EDIT_NEW"),
partial_content(
[ js(js_file("js/jscolor.min.js")),
js(js_file("js/dropzone.js")),
js_inline(jquery_ready("Dropzone.options.myAwesomeDropzone = {
maxFiles: 100,
dictDefaultMessage : \""+_T("DROP_FILE_HERE")+"\",
dictFileTooBig : \""+_T("FILE_TOO_BIG")+"\",
};
$('#my-awesome-dropzone').dropzone(); ")),
]+
jq_datetimepicker_init(lang) +
get_editor_header(list_entries), //add editor header if need. Like init ck_editor
sequence([
cxm_form( table_name, lwa,
[ one_line_fields([
submit(if create then hkc_save_row else hkc_update_row, failure, button_name, [("table_name", table_name)]),
submit(if create then hkc_save_row_and_new else hkc_update_row_and_new, failure, button_name_and_new, [("table_name", table_name)]),
submit(hkc_cancel, failure, _T("CANCEL"))
]),
hr
]+edit_form_lines(db, "", table_referer, _T, list_entries, create, [])
+
(if id = "none" then
[]
else
map( (HK_Form_Tab tab)
|->
since tab is hk_form_tab(fk_table_name, fk_col_name, list_view_name),
with referer = hk_referer(table_name, id, fk_table_name, fk_col_name),
if table_in_list_view_only(db, _T, lang, web_site_directory, fk_table_name, list_view_name, "edit", "", referer, fk_clause, vtm) is
{
failure then empty,
success(p_content) then partial(p_content)
}
//text("Foreign Key from table ["+fk_table_name+"] columns ["+fk_col_name+"] view to use ["+list_view_name+"]")
,list_tabs))+
[ hr,
one_line_fields([
submit(if create then hkc_save_row else hkc_update_row, failure, button_name, [("table_name", table_name)]),
submit(if create then hkc_save_row_and_new else hkc_update_row_and_new, failure, button_name_and_new, [("table_name", table_name)]),
submit(hkc_cancel, failure, _T("CANCEL"))
])
]
),
form("my-awesome-dropzone",[class("dropzone")], "upload_csv_file&step=2&format=csv&table_name="+table_name, [], literal("")),
]
)).
//Edit table part
public define List(CXM_Form_Field)
edit_form_cell
(
SQLite3DataBase db,
String fk_clause,
HK_Referer table_referer,
(String) -> String _T,
HK_Form_Entry cell,
Bool new_entry,
List(CXM_Form_Field) so_far
)=
if cell is
{
empty then [empty],
hidden(name, value) then
//print("hidden "+name+" = "+value);
[hidden(html_Id(""), wan(name), wav(value))],
label(name) then
[div([],text(_T(name)))],
primary_key(idx) then
[hidden(html_Id(""), wan("id"), wav(idx))],
information(s_name, c_name, value, width, help) then
[input_readonly(no_label, wan(c_name), init(not_null_String(value)), if width > 0 then custom(width) else narrow), help_line(help, _T)],
text(s_name, c_name, value, help) then
[input(no_label, wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
password(s_name, c_name, help) then
with password_entries =
[ password_input(no_label, wan(c_name+"_1"), init(""), narrow, non_mandatory),
password_input(no_label, wan(c_name+"_2"), init(""), narrow, non_mandatory),
help_line(help, _T)
],
if new_entry = false then
[ checkbox_hide_show([], label(_T("CLICK_TO_CHANGE_PASSWORD")), wan(c_name+"_pwd_change"), wav("on"), false, //not checked at first
password_entries),
hidden(html_Id(""), wan(c_name+"_pwd_change_option"), wav("true"))
]
else
[ hidden(html_Id(""), wan(c_name+"_pwd_change_option"), wav("false")) .
password_entries
],
foreign_text(s_name, c_name, value, select, help) then
[selector_c([],no_label, html_Id(""), wan(c_name), 1, select.get(db, table_referer, fk_clause), success(init(to_String(value))), mandatory), help_line(help, _T)],
choices_text(s_name, c_name, value, select, help) then
[selector_c([],no_label, html_Id(""), wan(c_name), 1, select.get(db, no_referer, ""), success(init(value)), mandatory), help_line(help, _T)],
text_area(s_name, c_name, value, txt_editor, help) then
with id = if txt_editor is { none then "", rich_editor then c_name+"_editor"},
[text_area([],no_label, html_Id(id), wan(c_name), init(not_null_String(value)), narrow, (Int)5, mandatory), help_line(help, _T)],
boolean(s_name, c_name, value, help) then
[checkboxr([],no_label, html_Id(""), wan(c_name), wav("true"),value, mandatory), help_line(help, _T)],
integer(s_name, c_name, value, help) then
[input(no_label, wan(c_name), init(abs_to_decimal(value)), small, mandatory), help_line(help, _T)],
float(s_name, c_name, value, help) then
[input(no_label, wan(c_name), init(float_to_string(value, 5)), small, mandatory), help_line(help, _T)],
choices_int(s_name, c_name, value, select, help) then
[selector_c([],no_label, html_Id(""), wan(c_name), 1, select.get(db, no_referer, ""), success(init(to_String(value))), mandatory), help_line(help, _T)],
date(s_name, c_name, value, help) then
[input([class("datepicker")], no_label, html_Id(c_name), wan(c_name), init(value), small, non_mandatory), help_line(help, _T)],
time(s_name, c_name, value, help) then
[input([class("timepicker")], no_label, html_Id(c_name), wan(c_name), init(value), small, non_mandatory), help_line(help, _T)],
datetime(s_name, c_name, value, help) then
[input([class("datetimepicker")], no_label, html_Id(c_name), wan(c_name), init(value), custom(18), mandatory), help_line(help, _T)],
color( s_name, c_name, value, help) then
[input([class("jscolor")], no_label, wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
phone( s_name, c_name, value, help) then
[input([class("hk_input_phone")], no_label, wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
email( s_name, c_name, value, help) then
[input([class("hk_input_email")], no_label, wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
}.
define List(Cell_Option)
make_cell_option
(
List(HK_Form_Table_Cell_Attribute) attributes
)=
map((HK_Form_Table_Cell_Attribute attr)
|->
if attr is
{
colspan(number) then columns(number),
rowspan(number) then rows(number)
},
attributes
)
.
define CXM_Form_Field
construct_edit_form_table
(
SQLite3DataBase db,
HK_Referer table_referer,
(String) -> String _T,
List(Web_arg) lwa,
List(HK_Form_Table_Line) form_lines,
Bool create
)=
div([],
table([class("striped")],
map((HK_Form_Table_Line line)
|-> //construct line
row(
map((HK_Form_Table_Cell cell_content)
|->
if cell_content is
{
//construct one cell
hk_form_table_cell(cell_attributes, entry) then
cell(make_cell_option(cell_attributes), to_HTML_In_Form(edit_form_cell(db, "", table_referer, _T, entry, create, []), lwa, "form_field table", false)),
//construct table in one cell
hk_form_table_cell_table(cell_attributes, lines) then
cell(make_cell_option(cell_attributes), to_HTML_In_Form([construct_edit_form_table(db, table_referer, _T, lwa, lines, create)], lwa, "form_field table", false))
},
line.form_table_cells
)
),
form_lines
)
)
)
.
public define List(CXM_Form_Field)
get_hidden
(
List(HK_Form_Table_Attribute) table_attrs
)=
map((HK_Form_Table_Attribute attr) |-> since attr is hidden(n, v), hidden(html_Id(""), wan(n), wav(v)), table_attrs)
.
public define HTML_Partial_Content
renderer_edit_table_form
(
SQLite3DataBase db,
(String) -> String _T,
String lang,
String web_site_directory,
String table_name,
String view_name,
HK_Form_Table table_form,
List(Web_arg) lwa,
VTM vtm,
String clause,
String fk_clause,
HK_Referer table_referer //from which table and row id that editor is called
) =
//with table_name = vt_elist.table_name,
//true if need to create row or false for updating
with create = if get_String(lwa, "id","none") = "none" then true else false,
with id = get_String(lwa, "id","none"),
with button_name = if create then _T("CREATE") else _T("UPDATE"),
with button_name_and_new = if create then _T("CREATE_AND_EDIT_NEW") else _T("UPDATE_AND_EDIT_NEW"),
partial_content(
[ js(js_file("js/jscolor.min.js"))
]+
jq_datetimepicker_init(lang) +
get_editor_header(table_form.form_lines), //add editor header if need. Like init ck_editor
sequence([
cxm_form( table_name, [], lwa,
get_hidden(table_form.table_attr)+
[construct_edit_form_table(db, table_referer, _T, lwa, table_form.form_lines, create)]+
[ one_line_fields([
submit(if create then hkc_save_row else hkc_update_row, failure, button_name, [("table_name", table_name)]),
submit(if create then hkc_save_row_and_new else hkc_update_row_and_new, failure, button_name_and_new, [("table_name", table_name)]),
submit(hkc_cancel, failure, _T("CANCEL"))
])
],
"form_field table",
false
)]
// if id = "none" then
// []
// else
// map( (HK_Form_Tab tab)
// |->
// since tab is hk_form_tab(fk_table_name, fk_col_name, list_view_name),
// with referer = hk_referer(table_name, id, fk_table_name, fk_col_name),
// if table_in_list_view_only(db, _T, lang, web_site_directory, fk_table_name, list_view_name, "edit", "", referer, fk_clause, vtm) is
// {
// failure then empty,
// success(p_content) then partial(p_content)
// }
// //text("Foreign Key from table ["+fk_table_name+"] columns ["+fk_col_name+"] view to use ["+list_view_name+"]")
// ,list_tabs)
))
.
public define Maybe(HTML_Partial_Content)
edit_table_content
(
SQLite3DataBase db,
(String) -> String _T,
String lang,
String web_site_directory,
List(Web_arg) lwa,
String table, //table name
String view_name, //view name to use
HK_Form_action action, //new_entry or edit an existing record
VTM vtm,
String clause,
String fk_clause,
HK_Referer referer
) =
if vtm_get_edit(table, vtm.edit_list) is
{
failure then failure,
success(vtm_e) then
since vtm_e is vtm_edit(_, get_edit),
if get_edit(db, action, view_name) is
{
hk_form_in_list(tb_name, v_name, list_form_entries, list_tabs) then
success(renderer_edit_list_form(db, _T, lang, web_site_directory, tb_name, v_name, list_form_entries, list_tabs, lwa, vtm, clause, fk_clause, referer)),
hk_form_in_table(tb_name, v_name, form_in_table) then
success(renderer_edit_table_form(db, _T, lang, web_site_directory, tb_name, v_name, form_in_table, lwa, vtm, clause, fk_clause, referer))
}
}.