From b4174bbae9f28a186b844afb962bda1ee083977e Mon Sep 17 00:00:00 2001 From: totoro Date: Sun, 24 Jul 2022 10:03:55 +0900 Subject: [PATCH] in javascipt code change the double quote by single quote which more readable under anubis source --- view/jqgrid.anubis | 39 ++++++++++++++++++++------------------- view/view_table_renderer.anubis | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------- 2 files changed, 117 insertions(+), 54 deletions(-) diff --git a/view/jqgrid.anubis b/view/jqgrid.anubis index 26bfb87..412f7e1 100644 --- a/view/jqgrid.anubis +++ b/view/jqgrid.anubis @@ -7,6 +7,7 @@ */ read xlib/web/making_a_web_site.anubis +read xlib/web/js_tools.anubis read hayamiki_lib/types/hayamiki.anubis read hayamiki_lib/view/types/hk_form.anubis read hayamiki_lib/view/types/hk_view.anubis @@ -113,14 +114,14 @@ define String with empty_referer = hk_referer("","","",""), with result = if model is { - primary_key then "{ name: \"id\", hidden:true }", - information(label,column_name,width,help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", autoResizable: true, "+search_options(column_name)+"}", - text(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, autoResizable: true, "+search_options(column_name)+" }", - password(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", autoResizable: true }", + primary_key then "{ name: 'id', hidden:true }", + information(label,column_name,width,help) then "{ name: '"+column_name+"', label: "+to_JS_String(_T(label))+", autoResizable: true, "+search_options(column_name)+"}", + text(label,column_name,help) then "{ name: '"+column_name+"', label: "+to_JS_String(_T(label))+", editable:true, autoResizable: true, "+search_options(column_name)+" }", + password(label,column_name,help) then "{ name: '"+column_name+"', label: "+to_JS_String(_T(label))+", autoResizable: true }", foreign_text(label,column_name,selector,help) then logDebug("to_jqGrid_ColModel 1: foreign_text column_name "+column_name); with jqgrid_selector = to_jqGrid_selector(selector.get(db,table_referer,"")), - "{ name: '"+column_name+"', label: '"+_T(label)+"', editable:true, autoResizable: true, edittype:'select', editoptions: {value: "+jqgrid_selector+", dataInit: function (elem) { + "{ name: '"+column_name+"', label: "+to_JS_String(_T(label))+", editable:true, autoResizable: true, edittype:'select', editoptions: {value: "+jqgrid_selector+", dataInit: function (elem) { $(elem).select2({ dropdownCssClass: 'ui-widget ui-jqdialog', width: '100%' @@ -132,7 +133,7 @@ define String choices_text(label,column_name,selector,help) then logDebug("to_jqGrid_ColModel 1: choices_text column_name "+column_name); with jqgrid_selector = to_jqGrid_selector(selector.get(db, empty_referer, "")), - "{ name: '"+column_name+"', label: '"+_T(label)+"', editable:true, autoResizable: true, edittype:'select', editoptions:{value: "+jqgrid_selector+",dataInit: function (elem) { + "{ name: '"+column_name+"', label: "+to_JS_String(_T(label))+", editable:true, autoResizable: true, edittype:'select', editoptions:{value: "+jqgrid_selector+",dataInit: function (elem) { $(elem).select2({ dropdownCssClass: 'ui-widget ui-jqdialog', width: '100%' @@ -141,24 +142,24 @@ define String //" formatter: \"select\","+ //" formatoptions:{value: "+jqgrid_selector+"},"+ "}", - text_area(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\" }", - boolean(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, autoResizable: true, template: \"booleanCheckboxFa\" }", - integer(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, autoResizable: true, template: \"integer\" }", - float(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, autoResizable: true, template: \"number\" }", + text_area(label,column_name,help) then "{ name: '"+column_name+"', label: "+to_JS_String(_T(label))+" }", + boolean(label,column_name,help) then "{ name: '"+column_name+"', label: "+to_JS_String(_T(label))+", editable:true, autoResizable: true, template: 'booleanCheckboxFa' }", + integer(label,column_name,help) then "{ name: '"+column_name+"', label: "+to_JS_String(_T(label))+", editable:true, autoResizable: true, template: 'integer' }", + float(label,column_name,help) then "{ name: '"+column_name+"', label: "+to_JS_String(_T(label))+", editable:true, autoResizable: true, template: 'number' }", choices_int(label,column_name,selector,help) then logDebug("to_jqGrid_ColModel 1: choices_int column_name "+column_name); with jqgrid_selector = to_jqGrid_selector(selector.get(db, empty_referer, "")), - "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, autoResizable: true, edittype:\"select\", editoptions:{value: "+jqgrid_selector+"},"+ - " formatter: \"select\","+ + "{ name: '"+column_name+"', label: "+to_JS_String(_T(label))+", editable:true, autoResizable: true, edittype:'select', editoptions:{value: "+jqgrid_selector+"},"+ + " formatter: 'select',"+ " formatoptions:{value: "+jqgrid_selector+"},"+ "}", - date(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, autoResizable: true, formatter: \"date\", formatoptions: { newformat: \"Y-M-d\" }}", - time(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, autoResizable: true }", - datetime(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, autoResizable: true }", - color(label, column_name, help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", width: 40, editable:true, autoResizable: true, edittype: 'custom', formatter:formatColor, unformat:unformatColor, "+custom_edit_color+" }", - phone(label,column_name, ph_type, help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, autoResizable: true, edittype: 'custom', formatter:formatPhone, unformat:unformatPhone, "+custom_edit_phone+"}", - email(label,column_name, help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, autoResizable: true, edittype: 'custom', formatter:formatEmail, unformat:unformatEmail, "+custom_edit_email+"}", - url(label, column_name, help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, autoResizable: true, "+search_options(column_name)+" }", + date(label,column_name,help) then "{ name: '"+column_name+"', label: "+to_JS_String(_T(label))+", editable:true, autoResizable: true, formatter: 'date', formatoptions: { newformat: 'Y-M-d' }}", + time(label,column_name,help) then "{ name: '"+column_name+"', label: "+to_JS_String(_T(label))+", editable:true, autoResizable: true }", + datetime(label,column_name,help) then "{ name: '"+column_name+"', label: "+to_JS_String(_T(label))+", editable:true, autoResizable: true }", + color(label, column_name, help) then "{ name: '"+column_name+"', label: "+to_JS_String(_T(label))+", width: 40, editable:true, autoResizable: true, edittype: 'custom', formatter:formatColor, unformat:unformatColor, "+custom_edit_color+" }", + phone(label,column_name, ph_type, help) then "{ name: '"+column_name+"', label: "+to_JS_String(_T(label))+", editable:true, autoResizable: true, edittype: 'custom', formatter:formatPhone, unformat:unformatPhone, "+custom_edit_phone+"}", + email(label,column_name, help) then "{ name: '"+column_name+"', label: "+to_JS_String(_T(label))+", editable:true, autoResizable: true, edittype: 'custom', formatter:formatEmail, unformat:unformatEmail, "+custom_edit_email+"}", + url(label, column_name, help) then "{ name: '"+column_name+"', label: "+to_JS_String(_T(label))+", editable:true, autoResizable: true, "+search_options(column_name)+" }", }, logDebug(show_duration_string("to_jqGrid_ColModel 1: result", start_time)); result diff --git a/view/view_table_renderer.anubis b/view/view_table_renderer.anubis index 215dfd7..6d29570 100644 --- a/view/view_table_renderer.anubis +++ b/view/view_table_renderer.anubis @@ -6,6 +6,7 @@ * */ +read hayamiki_lib/controller/hk_utils.anubis 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 @@ -380,7 +381,7 @@ define String logDebug("jqGrid_options: entry"); with result = " editurl: '?aws_c=hk_c&aws_a=grid_action&table_name="+rows.table_name+"', - iconSet: \"fontAwesome\", + iconSet: 'fontAwesome', cmTemplate: { autoResizable: true}, autoResizing: { compact: true, resetWidthOrg: true }, autoresizeOnLoad: true, @@ -397,42 +398,42 @@ define String cellurl: '?aws_c=hk_c&aws_a=grid_action&table_name="+rows.table_name+"', editurl: '?aws_c=hk_c&aws_a=grid_action&table_name="+rows.table_name+"', onSelectRow: function (rowid, status, e) { - var $self = $(this), savedRow = $self.jqGrid(\"getGridParam\", \"savedRow\"); + 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\"); + var $self = $(this), savedRow = $self.jqGrid('getGridParam', 'savedRow'); if (savedRow.length > 0 && savedRow[0].id !== rowid) { - $self.jqGrid(\"restoreRow\", savedRow[0].id); + $self.jqGrid('restoreRow', savedRow[0].id); } - $self.jqGrid(\"editRow\", rowid, { focusField: e.target }); + $self.jqGrid('editRow', rowid, { focusField: e.target }); }, afterAddRow: function () { recreateFilterToolbar.call(this); - //updateAutocompleteSource.call(this, \"name\"); + //updateAutocompleteSource.call(this, 'name'); }, afterSetRow: function () { recreateFilterToolbar.call(this); - //updateAutocompleteSource.call(this, \"name\"); + //updateAutocompleteSource.call(this, 'name'); }, afterDelRow: function () { - //updateAutocompleteSource.call(this, \"name\"); + //updateAutocompleteSource.call(this, 'name'); recreateFilterToolbar.call(this); }, caption:"+to_JSON_String(_T(to_upper(rows.table_name)))+", actionsNavOptions: { - openicon: \"fa-folder-open-o\", - opentitle: \"Open (Enter)\", + 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\", + { action: 'open', position: 'first', onClick: function (options) {"+ jq_dialog_open(dialog_id(uid+"edit_table_dlg_ajax"), "'id='+options.rowid")+ " @@ -466,7 +467,7 @@ public define HTML_Partial_Content "var lastSel; initAutocomplete = function (elem, cmName) { $(elem).autocomplete({ - source: $(this).jqGrid(\"getUniqueValueFromColumnIndex\", cmName), + source: $(this).jqGrid('getUniqueValueFromColumnIndex', cmName), delay: 0, minLength: 0 }); @@ -477,11 +478,11 @@ public define HTML_Partial_Content .jqGrid(\"filterToolbar\"); }, updateAutocompleteSource = function (cmName) { - var newUniqueValues = $(this).jqGrid(\"getUniqueValueFromColumnIndex\", cmName); - $(\"#gs_\" + this.id + \"_\" + cmName) - .autocomplete(\"option\", \"source\", newUniqueValues); + var newUniqueValues = $(this).jqGrid('getUniqueValueFromColumnIndex', cmName); + $('#gs_' + this.id + '_' + cmName) + .autocomplete('option', 'source', newUniqueValues); }; -$(\"#"+uid+"_grid\").jqGrid({ +$('#"+uid+"_grid').jqGrid({ url:'?aws_controller=hk_c&aws_action=grid_view&table_name="+rows.table_name+"&view_name="+rows.view_name+"&filter_name="+filter_name+filter_clause+referer_arg+"',"+ "datatype: \"json\", "+ @@ -491,7 +492,7 @@ url:'?aws_controller=hk_c&aws_action=grid_view&table_name="+rows.table_name+"&vi ",loadComplete: function () { } - }).jqGrid(\"gridResize\"); + }).jqGrid('gridResize'); function formatColor(cellValue, options, rowObject) { var color_container = \"
\"; return color_container; @@ -688,7 +689,36 @@ define CXM_Form_Field help_text_TAG(tag) then explain(_T(tag)), help_text(str) then explain(str) }. - + +define String + select2_option + ( + String url, + String initial_id, + String initial_text + ) + = +"{ +// initSelection : function (element, callback) { +// var data = [{id:"+initial_id+",text:'"+initial_text+"'}]; +// callback(data) +// }, + ajax:{ + url: '"+url+"&select2=true', + type: 'post', + dataType: 'json', + delay: 250, + data: function(params){ + return { + search: params.term + }; + }, + }, + width: '200px !important', + dropdownCssClass: 'ui-widget ui-jqdialog', +}" +. + //Edit table part public define List(CXM_Form_Field) @@ -702,6 +732,7 @@ public define List(CXM_Form_Field) List(HK_Form_Entry) list, Bool new_entry, Bool no_add, + VTM vtm, List(CXM_Form_Field) so_far )= if list is @@ -741,6 +772,11 @@ public define List(CXM_Form_Field) ], foreign_text(s_name, c_name, _value, foreign_table_name, select, active_filters, help) then + println("foreign_text -----"); + println("s_name :"+s_name); + println("c_name :"+c_name); + println("_value :"+to_String(_value)); + with dummy = if length(active_filters) > 0 then println("ACTIVE FILTER for "+c_name); println(join("", map((HK_Foreign_Key_Active_Filter a_filter) |-> @@ -753,21 +789,39 @@ public define List(CXM_Form_Field) unique, with uid = "_"+generate_random_string(20)+"_", with refresh_func = uid+foreign_table_name+"_"+c_name+"_selector_refresh", - //Get the priority of the web argument content for the value, this means the value already set by the user or called with programmaticaly with it + + //Get the priority of the web argument content for the value, this means the value already set by the user or called with programmaticaly with it with value = get_DB_id(lwa, c_name, _value), - //create refresh function and call it first to construct the dropdown - with load_script = script("text/javascript","function "+refresh_func+"() { Xlib.load_content('"+uid+foreign_table_name+"_"+c_name+"_selector', '?aws_c=hk_c&aws_a=selector&table_name="+foreign_table_name+"&fk_filter="+fk_clause+"&selected="+value+"&"+to_Web_arg(table_referer, "")+"'); $('#"+uid+foreign_table_name+"_"+c_name+"_selector').select2();} "+refresh_func+"(); "), - [ - partial(jq_dialog_create(dialog_id(uid+foreign_table_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&dialog_id="+uid+foreign_table_name+"_dlg_ajax&sub_dialog=true&table_name="+foreign_table_name+"&after_close_cb="+refresh_func)))), - one_line_fields([ - partial(partial_content([js_inline(load_script)],empty)), - selector_c([],label(_T(s_name), no_help), html_Id(uid+foreign_table_name+"_"+c_name+"_selector"), wan(c_name), 1, [],/*select.get(db, table_referer, fk_clause), */ success(init("")), mandatory), help_line(help, _T), - if no_add then - empty - else - partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+foreign_table_name+"_dlg_ajax")))], "", [])), - ]) - ], + println("value :"+to_String(value)); + with view_only = get_Bool(lwa, "vo_"+c_name, false), + with fk_show_string = row_show_string(db, vtm, foreign_table_name, value), + if view_only then + //[input_readonly(label(_T(s_name), no_help), wan(c_name), init(not_null_String(fk_show_string)), narrow), help_line(help, _T)] + [ + hidden(html_Id(""), wan(c_name), wav(to_String(value))), + message(to_String(format_label(label(_T(s_name), no_help), html_Id("")))+not_null_String(fk_show_string))] + else + (with select2_option_str = select2_option("?aws_c=hk_c&aws_a=selector&table_name="+foreign_table_name+"&fk_filter="+fk_clause+"&selected="+value+"&"+to_Web_arg(table_referer, ""), + to_String(value), + fk_show_string), + //create refresh function and call it first to construct the dropdown + // with load_script = script("text/javascript","function "+refresh_func+"() { Xlib.load_content('"+uid+foreign_table_name+"_"+c_name+"_selector', '?aws_c=hk_c&aws_a=selector&table_name="+foreign_table_name+"&fk_filter="+fk_clause+"&selected="+value+"&"+to_Web_arg(table_referer, "")+"'); $('#"+uid+foreign_table_name+"_"+c_name+"_selector').select2();} "+refresh_func+"(); "), + with refresh_script = script("text/javascript","function "+refresh_func+"() { $('#"+uid+foreign_table_name+"_"+c_name+"_selector').select2('destroy');$('#"+uid+foreign_table_name+"_"+c_name+"_selector').select2("+select2_option_str+");} "), + with init_script = "var newOption"+uid+foreign_table_name+"_"+c_name+"_selector = new Option("+to_JS_String(fk_show_string)+", '"+to_String(value)+"', true, true); + $('#"+uid+foreign_table_name+"_"+c_name+"_selector').select2("+select2_option_str+").append(newOption"+uid+foreign_table_name+"_"+c_name+"_selector).trigger('change');", + [ + partial(jq_dialog_create(dialog_id(uid+foreign_table_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&dialog_id="+uid+foreign_table_name+"_dlg_ajax&sub_dialog=true&table_name="+foreign_table_name+"&after_close_cb="+refresh_func)))), + one_line_fields([ + partial(partial_content([js_inline(refresh_script), + js_inline(jquery_ready(init_script)) + ],empty)), + selector_c([],label(_T(s_name), no_help), html_Id(uid+foreign_table_name+"_"+c_name+"_selector"), wan(c_name), 1, [],/*select.get(db, table_referer, fk_clause), */ success(init("")), mandatory), help_line(help, _T), + if no_add then + empty + else + partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+foreign_table_name+"_dlg_ajax")))], "", [])), + ]) + ]), foreign_text_search(s_name, c_name, _select, foreign_table_name, s_fields, active_filters, help) then @@ -783,7 +837,15 @@ public define List(CXM_Form_Field) unique, with uid = "_"+generate_random_string(20)+"_", //Get the priority of the web argument content for the select, this means the value already set by the user or called with programmaticaly with it - with select = get_DB_id(lwa, c_name, _select), + with select = get_DB_id(lwa, c_name, _select), + with view_only = get_Bool(lwa, "vo_"+c_name, false), + with fk_show_string = row_show_string(db, vtm, foreign_table_name, select), + if view_only then + //[input_readonly(label(_T(s_name), no_help), wan(c_name), init(not_null_String(fk_show_string)), narrow), help_line(help, _T)] + [ + hidden(html_Id(""), wan(c_name), wav(to_String(select))), + message(to_String(format_label(label(_T(s_name), no_help), html_Id("")))+not_null_String(fk_show_string))] + else with combo_init = ajax_combo_init_parameter(uid, foreign_table_name, c_name, to_mb_Int(select), s_fields, active_filters), [ @@ -853,7 +915,7 @@ public define List(CXM_Form_Field) url( s_name, c_name, value, help) then [url_input([event(onclick, "hk_go_url(this)")], [class("hk_input_url")], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)], }, - edit_form_lines(db, fk_clause, table_referer, lwa, _T, t, new_entry, no_add, reverse(line)+so_far) + edit_form_lines(db, fk_clause, table_referer, lwa, _T, t, new_entry, no_add, vtm, reverse(line)+so_far) }. @@ -921,7 +983,7 @@ public define HTML_Partial_Content [] ) + - edit_form_lines(db, "", table_referer, lwa, _T, list_entries, create, no_add, []) + edit_form_lines(db, "", table_referer, lwa, _T, list_entries, create, no_add, vtm, []) + (if id = "none" then [] -- libgit2 0.21.4