@logimaxx/kgrid 0.7.3 → 0.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/kgrid.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @logimaxx/kgrid | (c) Logimaxx System SRL — proprietary | https://logimaxx.ro | built 2026-11-03T11:43:37.855Z */
1
+ /*! @logimaxx/kgrid | (c) Logimaxx System SRL — proprietary | https://logimaxx.ro | built 2026-11-17T14:32:51.460Z */
2
2
 
3
3
  /* --- configure.js --- */
4
4
  /**
@@ -210,6 +210,8 @@
210
210
  /** @deprecated use rowActions items [{ action: "clone" }] */
211
211
  "clone": false,
212
212
  "columnChooser": false,
213
+ /** dbAPI CSV from the column panel: all fields, or the visible columns. */
214
+ "csvExport": false,
213
215
  /** Leading checkbox column. Header checkbox toggles the current page. */
214
216
  "selection": false
215
217
  },
@@ -231,6 +233,10 @@
231
233
  filterStorageScope: null,
232
234
  columnChooserLabel: "Columns",
233
235
  columnChooserResetLabel: "Reset columns",
236
+ csvExportVisibleLabel: "Export CSV — visible fields",
237
+ csvExportAllLabel: "Export CSV — all fields",
238
+ /** Row cap sent as page[type][limit] on the CSV request. */
239
+ csvExportLimit: 10000,
234
240
  "defaultInteraction": "view",
235
241
  "insertFormRow": {
236
242
  "position": "top"
@@ -273,6 +279,11 @@
273
279
  defaultHidden: false,
274
280
  /** Runtime: user hid this column via chooser. Not a schema flag. */
275
281
  userHidden: false,
282
+ /**
283
+ * Sparse CSV: false omits the column. A string exports that field name
284
+ * instead of `name` (the column name is still the chooser key).
285
+ */
286
+ export: true,
276
287
  /** CSS class(es) on header/filter/data/insert cells (alias: columnClass) */
277
288
  class: null,
278
289
  columnClass: null,
@@ -951,7 +962,7 @@
951
962
  */
952
963
  CT.hasActionColumn = function (options) {
953
964
  const f = options && options.features;
954
- if (f && (f.create || f.columnChooser)) {
965
+ if (f && (f.create || f.columnChooser || f.csvExport)) {
955
966
  return true;
956
967
  }
957
968
  const ra = CT.resolveRowActions(options);
@@ -4133,6 +4144,143 @@
4133
4144
  })(window.KGrid);
4134
4145
 
4135
4146
 
4147
+ /* --- csv-export.js --- */
4148
+ /**
4149
+ * dbAPI CSV export from the column chooser.
4150
+ * Full export keeps the collection query (filters, sort, include).
4151
+ * Visible export sends fields[type] for the columns on screen and drops include,
4152
+ * so related resources are not appended in full.
4153
+ */
4154
+ (function (CT) {
4155
+ CT.csvExportFields = function (columns) {
4156
+ return CT.layoutVisibleColumns(columns)
4157
+ .filter(function (col) {
4158
+ return (
4159
+ col &&
4160
+ col.name &&
4161
+ !col.selection &&
4162
+ col.name !== CT.SELECTION_COLUMN_NAME &&
4163
+ col.export !== false
4164
+ );
4165
+ })
4166
+ .map(function (col) {
4167
+ return typeof col.exportField === "string" && col.exportField
4168
+ ? col.exportField
4169
+ : col.name;
4170
+ });
4171
+ };
4172
+
4173
+ /**
4174
+ * @param {string} href collection URL (relative or absolute)
4175
+ * @param {{ type: string, mode: "all"|"visible", fields?: string[], limit?: number }} spec
4176
+ * @returns {string} same shape as href (path+query, or absolute)
4177
+ */
4178
+ CT.buildCsvExportUrl = function (href, spec) {
4179
+ const parsed = new window.URL(href, "http://kgrid.local");
4180
+ const type = spec && spec.type;
4181
+ const limit = spec && spec.limit != null ? spec.limit : 10000;
4182
+ parsed.searchParams.set("format", "csv");
4183
+ parsed.searchParams.set("includetablehead", "true");
4184
+ if (type) {
4185
+ parsed.searchParams.set("page[" + type + "][limit]", String(limit));
4186
+ parsed.searchParams.set("page[" + type + "][offset]", "0");
4187
+ }
4188
+ const dropFields = [];
4189
+ parsed.searchParams.forEach(function (_value, key) {
4190
+ if (key.indexOf("fields[") === 0) {
4191
+ dropFields.push(key);
4192
+ }
4193
+ });
4194
+ dropFields.forEach(function (key) {
4195
+ parsed.searchParams.delete(key);
4196
+ });
4197
+ if (spec && spec.mode === "visible") {
4198
+ parsed.searchParams.delete("include");
4199
+ if (type && spec.fields && spec.fields.length) {
4200
+ parsed.searchParams.set("fields[" + type + "]", spec.fields.join(","));
4201
+ }
4202
+ }
4203
+ if (/^https?:\/\//i.test(href)) {
4204
+ return parsed.toString();
4205
+ }
4206
+ return parsed.pathname + parsed.search;
4207
+ };
4208
+
4209
+ CT.resolveApiUrl = function (href, kviews) {
4210
+ if (href == null || href === "") {
4211
+ return href;
4212
+ }
4213
+ const s = String(href);
4214
+ if (/^https?:\/\//i.test(s) || s.startsWith("//")) {
4215
+ return s;
4216
+ }
4217
+ const base = (kviews && (kviews.baseUrl || kviews.basePath)) || "";
4218
+ if (!base) {
4219
+ return s;
4220
+ }
4221
+ const baseNorm = String(base).replace(/\/+$/, "");
4222
+ const pathNorm = s.replace(/^\/+/, "");
4223
+ return pathNorm ? baseNorm + "/" + pathNorm : baseNorm + "/";
4224
+ };
4225
+
4226
+ function csvErrorMessage(response, data) {
4227
+ if (data && data.errors && data.errors[0]) {
4228
+ return data.errors[0].detail || data.errors[0].title || "";
4229
+ }
4230
+ if (data && data.error) {
4231
+ return String(data.error);
4232
+ }
4233
+ return "CSV export failed (" + response.status + ")";
4234
+ }
4235
+
4236
+ CT.downloadCsv = function (options, api, mode) {
4237
+ const instance = api && api.instance;
4238
+ const href =
4239
+ instance && instance.url && instance.url.toString ? instance.url.toString() : "";
4240
+ if (!href) {
4241
+ return Promise.reject(new Error("CSV export requires a collection URL"));
4242
+ }
4243
+ const type = options && options.type;
4244
+ if (!type) {
4245
+ return Promise.reject(new Error("CSV export requires a resource type"));
4246
+ }
4247
+ const fields = mode === "visible" ? CT.csvExportFields(options.columns) : null;
4248
+ if (mode === "visible" && (!fields || !fields.length)) {
4249
+ return Promise.reject(new Error("No visible columns to export"));
4250
+ }
4251
+ const built = CT.buildCsvExportUrl(href, {
4252
+ type: type,
4253
+ mode: mode === "visible" ? "visible" : "all",
4254
+ fields: fields,
4255
+ limit: options.csvExportLimit,
4256
+ });
4257
+ const requestUrl = CT.resolveApiUrl(built, CT.getKViews(options.kviews));
4258
+ return window.fetch(requestUrl).then(function (response) {
4259
+ if (!response.ok) {
4260
+ return response
4261
+ .json()
4262
+ .catch(function () {
4263
+ return null;
4264
+ })
4265
+ .then(function (data) {
4266
+ throw new Error(csvErrorMessage(response, data));
4267
+ });
4268
+ }
4269
+ return response.blob().then(function (blob) {
4270
+ const link = document.createElement("a");
4271
+ const objectUrl = window.URL.createObjectURL(blob);
4272
+ link.href = objectUrl;
4273
+ link.download = options.csvFileName || type + ".csv";
4274
+ document.body.appendChild(link);
4275
+ link.click();
4276
+ link.remove();
4277
+ window.URL.revokeObjectURL(objectUrl);
4278
+ });
4279
+ });
4280
+ };
4281
+ })(window.KGrid);
4282
+
4283
+
4136
4284
  /* --- column-chooser.js --- */
4137
4285
  /**
4138
4286
  * Column chooser: checkbox visibility + HTML5 drag reorder.
@@ -4154,8 +4302,44 @@
4154
4302
  }).length;
4155
4303
  }
4156
4304
 
4305
+ function bindCsvExport($panel, options, api) {
4306
+ $panel
4307
+ .off("click.kgridCsv")
4308
+ .on("click.kgridCsv", ".kgrid-csv-export-visible, .kgrid-csv-export-all", function () {
4309
+ const button = this;
4310
+ const mode = button.classList.contains("kgrid-csv-export-visible") ? "visible" : "all";
4311
+ button.disabled = true;
4312
+ Promise.resolve(CT.downloadCsv(options, api, mode))
4313
+ .catch(function (err) {
4314
+ CT.onError(err);
4315
+ })
4316
+ .finally(function () {
4317
+ button.disabled = false;
4318
+ });
4319
+ });
4320
+ }
4321
+
4157
4322
  CT.renderColumnChooserPanel = function ($panel, options, api) {
4158
4323
  $panel.empty();
4324
+ const chooser = !!(options.features && options.features.columnChooser);
4325
+ const csv = !!(options.features && options.features.csvExport);
4326
+ if (csv) {
4327
+ const $export = $("<div>").addClass("kgrid-column-chooser-export").appendTo($panel);
4328
+ $("<button>")
4329
+ .attr("type", "button")
4330
+ .addClass("btn btn-sm btn-outline-secondary kgrid-csv-export-visible")
4331
+ .text(options.csvExportVisibleLabel || "Export CSV — visible fields")
4332
+ .appendTo($export);
4333
+ $("<button>")
4334
+ .attr("type", "button")
4335
+ .addClass("btn btn-sm btn-outline-secondary kgrid-csv-export-all")
4336
+ .text(options.csvExportAllLabel || "Export CSV — all fields")
4337
+ .appendTo($export);
4338
+ bindCsvExport($panel, options, api);
4339
+ }
4340
+ if (!chooser) {
4341
+ return;
4342
+ }
4159
4343
  const $list = $("<ul>").addClass("kgrid-column-chooser-list").appendTo($panel);
4160
4344
  CT.chooserColumns(options.columns).forEach(function (col) {
4161
4345
  const $li = $("<li>")
@@ -4235,7 +4419,9 @@
4235
4419
  };
4236
4420
 
4237
4421
  CT.setupColumnChooser = function ($host, options, api) {
4238
- if (!options.features || !options.features.columnChooser) {
4422
+ const chooser = !!(options.features && options.features.columnChooser);
4423
+ const csv = !!(options.features && options.features.csvExport);
4424
+ if (!chooser && !csv) {
4239
4425
  return;
4240
4426
  }
4241
4427
  const $shell = CT.getTableInteractionHost($host);
package/dist/kgrid.min.js CHANGED
@@ -1,2 +1,2 @@
1
- /*! @logimaxx/kgrid | (c) Logimaxx System SRL — proprietary | https://logimaxx.ro | built 2026-11-03T11:43:37.855Z */
2
- !function(e){function t(e){const t={},n=e&&e.elements;if(!n)return t;for(let e=0;e<n.length;e++){const o=n[e],r=o.name;if(!r||o.disabled)continue;const i=o.type;if("submit"===i||"button"===i||"reset"===i||"file"===i)continue;if("checkbox"===i){t[r]=o.checked?"1":"0";continue}if("radio"===i){if(!o.checked)continue;t[r]=o.value;continue}if("SELECT"===o.tagName&&o.multiple){t[r]=Array.from(o.selectedOptions).map(function(e){return e.value});continue}const a=o.value;Object.prototype.hasOwnProperty.call(t,r)?(Array.isArray(t[r])||(t[r]=[t[r]]),t[r].push(a)):t[r]=a}return t}e.isFlagOn=function(e){return!0===e||1===e||"1"===e},e.serializeFormDefault=t;const n={log:function(){},onError:function(e){console.error(e)},confirm:function(e,t,n){"undefined"!=typeof window&&window.confirm(e)?t():n&&n()},deleteConfirm:null,serializeForm:t,customInputTypes:null,fieldTypes:null,kviews:null,filterDebounceMs:300,preferencesStorage:null};e._config=Object.assign({},n),e.configure=function(t){return t&&"object"==typeof t&&Object.assign(e._config,t),"function"==typeof e._syncCustomInputTypes&&e._syncCustomInputTypes(),e},e.log=function(){e._config.log.apply(null,arguments)},e.onError=function(t){return e._config.onError(t)},e.confirm=function(t,n,o){return e._config.confirm(t,n,o)},e.DEFAULT_DELETE_CONFIRM_MESSAGE="Delete this record?",e._defaultDeleteConfirm=function(t,n,o){e.confirm(e.DEFAULT_DELETE_CONFIRM_MESSAGE,n,o)},e.runDeleteConfirm=function(t,n,o){const r=t.options&&"function"==typeof t.options.deleteConfirm?t.options.deleteConfirm:null,i="function"==typeof e._config.deleteConfirm?e._config.deleteConfirm:null;return(r||i||e._defaultDeleteConfirm)(t,n,o)},e.serializeForm=function(t,n){return e._config.serializeForm(t,n)},e.getKViews=function(t){const n=[t,e._config.kviews];for(let e=0;e<n.length;e++){const t=n[e];if(t&&"function"==typeof t.createCollectionInstance)return t}const o=("undefined"!=typeof window?window:"undefined"!=typeof globalThis?globalThis:{}).KViews;return o&&"function"==typeof o.createCollectionInstance?o:null},e.KVIEWS_MISSING_MSG="KGrid requires KViews: install peer @logimaxx/kviews, load it before kgrid.js (window.KViews), or call KGrid.configure({ kviews: KViews }). You can also pass kviews in table options: KGrid.init(host, { kviews, ... })."}(window.KGrid=window.KGrid||{}),function(e){e.protoOptions={url:null,type:null,filter:null,features:{filtering:!1,sorting:!1,paging:!1,create:!1,update:!1,delete:!1,clone:!1,columnChooser:!1,selection:!1},selection:null,selectionAllLabel:"Toggle all",selectionRowLabel:"Select row",rowActions:null,storageKey:null,filterStorageScope:null,columnChooserLabel:"Columns",columnChooserResetLabel:"Reset columns",defaultInteraction:"view",insertFormRow:{position:"top"},onDuplicate:null,tableAttrs:{class:""},labelsRowAttrs:{},dataRowAttrs:{},filtersRowAttrs:null,pagingPageSizes:[10,25,50,75],pagingDefaultSize:10,emptyRowMessage:null,pagingFooterLabel:"records per page. Total"},e.protoColumnConfig={label:null,name:null,hidden:!1,locked:!1,defaultHidden:!1,userHidden:!1,class:null,columnClass:null,attrs:{},features:{create:!1,update:!1,filter:!1,sort:!1},display:{template:null,events:[]},input:null,insert:{type:"text",default:null,value:null,placeholder:null,disabled:!1,required:!1,options:null,events:[]},update:{type:"text",default:null,value:null,placeholder:null,disabled:!1,required:!1,options:null,template:null,events:[]},filter:{type:"text",operator:"~=~",default:null,placeholder:"",options:null,persist:!1,debounceMs:null}},e.VALID_NATIVE_INPUT_TYPES=["displayonly","text","textarea","number","date","datetime","time","checkbox","radio","file","password","email","url","search","tel","select","hidden"],e.VALID_INPUT_TYPES=e.VALID_NATIVE_INPUT_TYPES.slice(),e.VALID_NATIVE_FILTER_TYPES=e.VALID_NATIVE_INPUT_TYPES.filter(e=>"displayonly"!==e),e.VALID_FILTER_TYPES=e.VALID_NATIVE_FILTER_TYPES.concat(["multi_select","date_range"]),e.isValidInputType=function(t){return e.VALID_NATIVE_INPUT_TYPES.includes(t)||e.isPluggableFieldType(t)},e.isValidFilterType=function(t){return"displayonly"!==t&&(e.VALID_NATIVE_FILTER_TYPES.includes(t)||e.isPluggableFieldType(t))}}(window.KGrid=window.KGrid||{}),function(e){e.isPlainObject=function(e){return null!=e&&"object"==typeof e&&!Array.isArray(e)},e.setDefaultValues=function(t,n){const o={...t||{}};return Object.keys(n||{}).forEach(t=>{e.isPlainObject(n[t])&&e.isPlainObject(o[t])?o[t]=e.setDefaultValues(o[t],n[t]):e.isPlainObject(n[t])&&null==o[t]?o[t]=e.setDefaultValues({},n[t]):o[t]=n[t]}),o},e.normalizeColumnConfig=function(t){let n=t&&"object"==typeof t?{...t}:{};if(e.isPlainObject(n.input)){const t={...n.input};delete n.input,n.insert=e.setDefaultValues(t,n.insert||{}),n.update=e.setDefaultValues(t,n.update||{})}const o=e.setDefaultValues(e.protoColumnConfig,n);return null==o.class&&o.columnClass&&(o.class=o.columnClass),o.update&&"displayonly"===o.update.type&&!o.update.template&&o.display&&o.display.template&&(o.update.template=o.display.template),["display","insert","update"].forEach(e=>{o[e]&&"object"==typeof o[e]&&(Array.isArray(o[e].events)||(o[e].events=[]))}),o};const t=["error","ignore","update"],n=["set","add","sub"];function o(e,t){const o=String(e||"").trim(),r=null==t||""===t?"set":String(t).trim();if(!/^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)?$/.test(o))throw new Error("Invalid onDuplicate field: "+e);if(-1===n.indexOf(r))throw new Error("Invalid onDuplicate operator '"+r+"' on field '"+o+"'");return{name:o,op:r}}function r(e){const t=String(e||"").trim(),n=t.lastIndexOf(":");return-1===n?o(t,"set"):o(t.slice(0,n),t.slice(n+1))}e.onDuplicateParams=function(n){if(null==n||!1===n)return null;let i,a;if("string"==typeof n)i=n.trim();else{if(!e.isPlainObject(n))throw new Error("onDuplicate must be a string or an object");i=String(n.action||n.onduplicate||"").trim(),a=null!=n.fields?n.fields:n.update}if(-1===t.indexOf(i))throw new Error("Invalid onDuplicate action: "+i);const l={onduplicate:i};if("update"!==i)return l;const s=[],c={},u=function(e){if(c[e.name])throw new Error("onDuplicate field '"+e.name+"' is listed more than once");c[e.name]=!0,s.push("set"===e.op?e.name:e.name+":"+e.op)};if("string"==typeof a)a.split(",").forEach(function(e){e.trim()&&u(r(e))});else if(Array.isArray(a))a.forEach(function(e){u(r(e))});else if(e.isPlainObject(a))Object.keys(a).forEach(function(e){u(o(e,a[e]))});else if(null!=a)throw new Error("onDuplicate fields must be an object, array, or string");if(!s.length)throw new Error("onDuplicate action 'update' requires fields");return l.update=s.join(","),l},e.applyOnDuplicateToUrl=function(t,n){const o=e.onDuplicateParams(n);if(!o||!t)return t;const r=t.indexOf("#"),i=r>=0?t.slice(r):"",a=r>=0?t.slice(0,r):t,l=a.indexOf("?"),s=l>=0?a.slice(0,l):a,c=[];return l>=0&&a.slice(l+1).split("&").forEach(function(e){if(!e)return;const t=e.indexOf("="),n=decodeURIComponent(t>=0?e.slice(0,t):e);"onduplicate"!==n&&"update"!==n&&c.push(e)}),Object.keys(o).forEach(function(e){c.push(encodeURIComponent(e)+"="+encodeURIComponent(o[e]))}),s+(c.length?"?"+c.join("&"):"")+i}}(window.KGrid),function(e){e.resolveHostElement=function(e){if(null==e)throw new TypeError("KGrid.init(host, opts): host is required");if("object"==typeof e&&e.jquery){if(!e.length)throw new Error("KGrid.init(host, opts): empty jQuery selection");return e}if("object"==typeof e&&1===e.nodeType&&"string"==typeof e.nodeName)return $(e);throw new TypeError("KGrid.init(host, opts): host must be a DOM Element or jQuery object")},e.uuid=function(){return Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)},e.columnWidthCss=function(e){if(!e||!e.attrs)return null;const t=e.attrs.width;return null==t||""===t?null:"number"==typeof t||/^\d+(\.\d+)?$/.test(String(t))?String(t)+"px":String(t)},e.applyColumnDomAttrs=function(e,t){const n=t&&t.attrs&&"object"==typeof t.attrs?t.attrs:null;return n?(Object.keys(n).forEach(function(t){"width"!==t&&e.attr(t,n[t])}),e):e},e.layoutVisibleColumns=function(e){return(e||[]).filter(function(e){return e&&e.name&&!e.hidden&&!e.userHidden})},e.participatingColumnCount=function(t,n){return e.layoutVisibleColumns(t).length+(n?1:0)},e.syncActionColumnColgroup=function(t,n,o,r,i){let a=t.children("colgroup.kgrid-colgroup");a.length||(a=$("<colgroup>").addClass("kgrid-colgroup").prependTo(t)),a.empty();const l=Array.isArray(i)?i:null;let s=0;if(l&&l.length)l.forEach(function(t){if(t&&t.userHidden)return;const n=$("<col>");t&&t.name&&n.attr("data-name",t.name);const o=e.columnWidthCss(t);o&&n.css("width",o),a.append(n),s+=1});else for(let e=0;e<n;e++)a.append($("<col>")),s+=1;return o&&a.append($("<col>").addClass("kgrid-row-actions-col").css("width",e.actionColumnWidth(r))),s},e.syncSpanningCells=function(e,t){e&&e.length&&t&&e.find(".paging-footer td, .no-data-tbody td").attr("colspan",t)},e.anchorRowForm=function(e,t){if(!(e&&e.length&&t&&t.length))return e;e.attr("hidden","hidden").attr("aria-hidden","true");const n=t.children("td").first();return n.length&&e.prependTo(n),e},e.filterFormField=function(t,n){const o=e.filterFormFields(t,n);return o.length?o.eq(0):$()},e.filterFormFields=function(e,t){if(!e||!t)return $();const n=[],o=e.elements;if(o)for(let e=0;e<o.length;e++)o[e]&&o[e].name===t&&n.push(o[e]);if(!n.length&&e.id){const o=document.querySelectorAll('[form="'+e.id+'"][name="'+t+'"]');for(let e=0;e<o.length;e++)n.push(o[e])}return $(n)},e.columnClassName=function(e){if(!e)return null;const t=null!=e.class&&""!==e.class?e.class:e.columnClass;return null!=t&&""!==t?String(t):null},e.applyColumnCellMeta=function(t,n){if(!t||!t.length||!n)return t;n.name&&t.attr("data-name",n.name);const o=e.columnClassName(n);return o&&t.addClass(o),t.toggleClass("kgrid-user-hidden",!!n.userHidden),t}}(window.KGrid),function(e){function t(e){"undefined"!=typeof console&&"function"==typeof console.warn&&console.warn(e)}function n(e){return e?"<i class='"+e+"'></i>":""}function o(e,t,o){const r=$("<button>").addClass(t.btnClass||"btn btn-sm btn-outline-secondary").attr("type","save"===t.action?"submit":"button").attr("title",t.title||t.label||"");return t.class&&r.addClass(t.class),"save"!==t.action&&"cancel"!==t.action||(r.attr("name","save"===t.action?"save":"cancel"),o&&r.attr("form",o)),"cancel"===t.action&&r.attr("onclick","$(this).parents('[data-type=item]').data().instance.loadFromRemote()"),t.id&&r.attr("data-kgrid-action",t.id),t.action&&r.attr("data-kgrid-builtin",t.action),t.icon?(r.html(n(t.icon)),t.showLabel&&t.label&&r.append(document.createTextNode(" "+t.label))):t.label&&r.text(t.label),r.appendTo(e),r}function r(e,t,n){const o=n.indexOf(t);o<0||(e.attr("data-kgrid-action-index",String(o)),null!=t.visible&&e.addClass("kgrid-action-conditional kgrid-action-off"))}e.BUILTIN_ROW_ACTIONS={clone:{action:"clone",icon:"fa-regular fa-copy",label:"Clone",title:"Clone item",when:"idle",btnClass:"btn btn-sm btn-outline-secondary clone-item",groupClass:"clone-item-grp"},delete:{action:"delete",icon:"fas fa-trash",label:"Delete",title:"Delete item",when:"idle",btnClass:"btn btn-sm btn-danger delete-item",groupClass:"delete-item-grp"},save:{action:"save",icon:"fas fa-save",label:"Save",title:"Save item",when:"editing",btnClass:"btn btn-sm btn-success save-item",groupClass:"edit-item-grp"},cancel:{action:"cancel",icon:"fas fa-undo",label:"Cancel",title:"Cancel edit",when:"editing",btnClass:"btn btn-sm btn-secondary cancel-edit",groupClass:"edit-item-grp"}},e.normalizeRowActionItem=function(n,o,r){if(!n||"object"!=typeof n)return null;const i=n.action;if("save"===i||"cancel"===i)return t("KGrid: rowActions items should not list '"+i+"' — it is added automatically when features.update is true"),null;let a={};if(i&&e.BUILTIN_ROW_ACTIONS[i])a={...e.BUILTIN_ROW_ACTIONS[i]};else{if(!n.id)return t("KGrid: custom rowAction requires id: "+JSON.stringify(n)),null;a={id:n.id,when:"idle",btnClass:"btn btn-sm btn-outline-secondary",groupClass:"kgrid-custom-action-grp"}}const l={...a,...n};if(i&&e.BUILTIN_ROW_ACTIONS[i]&&(l.action=i),l.when||(l.when=l.action&&a.when||"idle"),!l.title&&l.label&&(l.title=l.label),!l.label&&l.title&&(l.label=l.title),"string"==typeof l.callback){const e=function(e,t,n){if(!e||"string"!=typeof e)return null;const o=t&&t[e]||n.functions&&n.functions[e];return"function"==typeof o?o:null}(l.callback,o,r);if(!e)throw new Error("rowAction callback "+l.callback+" not found or is not a function");l.callback=e}if(l.id&&"function"!=typeof l.callback&&!l.action)throw new Error("Custom rowAction '"+l.id+"' requires a callback");return l},e.rowActionVisible=function(e,t){if(null==t)return!0;if("function"==typeof t)return!!t(e);if(!t||"object"!=typeof t||Array.isArray(t))return!0;const n=e&&e.attributes||{};return Object.keys(t).every(function(e){const o=t[e],r=n[e];return Array.isArray(o)?o.some(function(e){return String(r??"")===String(e)}):String(r??"")===String(o)})},e.resolveRowActions=function(n,o){if(n&&n._resolvedRowActions&&arguments.length<2)return n._resolvedRowActions;const r=n&&n.features||{};let i="buttons",a=[];if(n&&null!=n.rowActions){const o=n.rowActions;Array.isArray(o)?a=o:e.isPlainObject(o)&&(i="dropdown"===o.display?"dropdown":"buttons",a=Array.isArray(o.items)?o.items:[]),(r.delete||r.clone)&&t("KGrid: features.delete / features.clone are ignored when rowActions is set")}else r.clone&&a.push({action:"clone"}),r.delete&&a.push({action:"delete"});const l=[];a.forEach(function(t){const r=e.normalizeRowActionItem(t,o,n||{});r&&l.push(r)});const s=[];r.update&&(s.push({...e.BUILTIN_ROW_ACTIONS.save}),s.push({...e.BUILTIN_ROW_ACTIONS.cancel}));const c={display:i,menuItems:l,editingItems:s};return n&&(n._resolvedRowActions=c),c},e.hasActionColumn=function(t){const n=t&&t.features;if(n&&(n.create||n.columnChooser))return!0;const o=e.resolveRowActions(t);return o.menuItems.length>0||o.editingItems.length>0},e.actionColumnWidth=function(t){const n=e.resolveRowActions(t),o=t&&t.features||{},r=n.editingItems.length,i=o.create?1:0;let a;a="dropdown"===n.display&&n.menuItems.length>0?1:n.menuItems.filter(function(e){return"editing"!==e.when}).length;return(2.5*Math.max(a,r,i,1)+.75).toFixed(2)+"rem"},e.closeRowActionDropdowns=function(e){$(".kgrid-row-actions-menu").each(function(){const t=$(this),n=t.children(".dropdown-menu");e&&n[0]===e[0]||(n.removeClass("show").css({top:"",left:"",right:"",position:""}),t.children(".kgrid-actions-dropdown-toggle").attr("aria-expanded","false").removeClass("show"))})},e.mountRowActionDropdowns=function(t){t&&t.length&&(e._rowActionsDropdownDocBound||(e._rowActionsDropdownDocBound=!0,$(document).on("click.kgridRowActions",function(){e.closeRowActionDropdowns()}).on("keydown.kgridRowActions",function(t){"Escape"===t.key&&e.closeRowActionDropdowns()})),t.find(".kgrid-row-actions-menu > .kgrid-actions-dropdown-toggle").each(function(){const t=this,n=$(t),o=n.parent(".kgrid-row-actions-menu").children(".dropdown-menu");n.off("click.kgridRowActions").on("click.kgridRowActions",function(r){r.preventDefault(),r.stopPropagation();const i=!o.hasClass("show");if(e.closeRowActionDropdowns(),!i)return;const a=t.getBoundingClientRect();o.addClass("show").css({position:"fixed",top:Math.round(a.bottom+2)+"px",left:"auto",right:Math.round(window.innerWidth-a.right)+"px",zIndex:1055}),n.addClass("show").attr("aria-expanded","true")}),o.off("click.kgridRowActions").on("click.kgridRowActions",function(e){e.stopPropagation()}),o.find(".dropdown-item").off("click.kgridRowActionsClose").on("click.kgridRowActionsClose",function(){setTimeout(function(){e.closeRowActionDropdowns()},0)})}))},e.applyRowActionVisibility=function(t,n,o){t&&t.length&&o&&o.forEach(function(o,r){if(!o||null==o.visible)return;const i=e.rowActionVisible(n,o.visible);t.find('[data-kgrid-action-index="'+r+'"]').toggleClass("kgrid-action-off",!i)})},e.escapeHtml=e.escapeHtml||function(e){return String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},e.renderRowActions=function(t,i,a){const l=e.resolveRowActions(i),s=l.menuItems.filter(function(e){return"editing"!==e.when}),c=l.menuItems.filter(function(e){return"editing"===e.when});if("dropdown"===l.display&&s.length>0){const o=$("<div>").addClass("btn-group kgrid-row-actions-menu").appendTo(t);$("<button>").addClass("btn btn-sm btn-outline-secondary dropdown-toggle kgrid-actions-dropdown-toggle").attr({type:"button","aria-expanded":"false",title:"Actions"}).html("<i class='fas fa-ellipsis-v'></i>").appendTo(o);const i=$("<ul>").addClass("dropdown-menu dropdown-menu-end").appendTo(o);s.forEach(function(t){const o=$("<li>").appendTo(i);r(o,t,l.menuItems);const a=$("<button>").addClass("dropdown-item").attr("type","button").appendTo(o);"clone"===t.action?a.addClass("clone-item"):"delete"===t.action&&a.addClass("delete-item text-danger"),t.id&&a.attr("data-kgrid-action",t.id),t.action&&a.attr("data-kgrid-builtin",t.action),t.class&&a.addClass(t.class),t.btnClass&&!t.action&&/\bbtn-danger\b|\btext-danger\b|\boutline-danger\b/.test(t.btnClass)&&a.addClass("text-danger");const s=t.label||t.title||t.action||t.id;t.icon?a.html(n(t.icon)+" "+e.escapeHtml(s)):a.text(s)})}else s.forEach(function(e){const n=$("<span>").addClass(e.groupClass||"btn-group kgrid-custom-action-grp").appendTo(t);"always"===e.when&&n.addClass("kgrid-action-always"),r(n,e,l.menuItems),o(n,e,a)});const u=l.editingItems.concat(c);if(u.length){const e=$("<span>").addClass("btn-group edit-item-grp").appendTo(t);u.forEach(function(t){o(e,t,a)})}}}(window.KGrid),function(e){e.DEFAULT_EMPTY_ROW_MESSAGE="No records match your search.",e.TABLE_SHELL_TEMPLATE='\n<table class="custom-table" style="table-layout: fixed;">\n <thead class="thead-labels">\n <tr>\n <th class="align-top">\n <a class="sort" data-sortfld="" style="cursor: pointer;">\n <span class="column-label"></span>\n <i class="fas fa-sort-up sort-up" style="display: none"></i>\n <i class="fas fa-sort-down sort-down" style="display: none"></i>\n <i class="fas fa-sort sort-default"></i>\n </a>\n </th>\n </tr>\n </thead>\n <thead class="thead-filters"></thead>\n <tbody class="before-main-tbody"></tbody>\n <tbody class="main-tbody"></tbody>\n <tbody class="after-main-tbody"></tbody>\n <tbody class="no-data-tbody">\n <tr><td>{{EMPTY_ROW_MESSAGE}}</td></tr>\n </tbody>\n <tfoot class="paging-footer">\n <tr>\n <td>\n <div class="btn-group pages" data-pagesize="{{PAGES_DATA_PAGESIZE}}">\n <button type="button" name="first" class="btn btn-sm btn-outline-secondary">&lt;&lt;</button>\n <button type="button" name="prev" class="btn btn-sm btn-outline-secondary">&lt;</button>\n <button type="button" name="page" class="btn btn-sm btn-outline-secondary">1</button>\n <button type="button" name="next" class="btn btn-sm btn-outline-secondary">&gt;</button>\n <button type="button" name="last" class="btn btn-sm btn-outline-secondary">&gt;&gt;</button>\n </div>\n <select class="pagesize">\n{{PAGE_SIZE_OPTIONS}}\n </select>\n {{PAGING_FOOTER_LABEL}} <span class="totalrecscount"></span>\n </td>\n </tr>\n </tfoot>\n</table>'.trim(),e._escapeTableShellText=function(e){return String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},e._renderPageSizeOptions=function(e,t){return e.map(e=>{const n=String(e);return` <option value="${n}"${n===String(t)?" selected":""}>${n}</option>`}).join("\n")},e.renderTableShellHtml=function(t,n){const o=Array.isArray(t.pagingPageSizes)?t.pagingPageSizes:[10,25,50,75],r=null!=t.pagingDefaultSize?t.pagingDefaultSize:o[0],i=e._escapeTableShellText(t.emptyRowMessage||e.DEFAULT_EMPTY_ROW_MESSAGE),a=e._escapeTableShellText(t.pagingFooterLabel||"records per page. Total");return(n||e.TABLE_SHELL_TEMPLATE).replace(/\{\{EMPTY_ROW_MESSAGE\}\}/g,i).replace(/\{\{PAGES_DATA_PAGESIZE\}\}/g,String(r)).replace(/\{\{PAGE_SIZE_OPTIONS\}\}/g,e._renderPageSizeOptions(o,r)).replace(/\{\{PAGING_FOOTER_LABEL\}\}/g,a)},e.createTableShell=function(t){const n=e.renderTableShellHtml(t),o=$.parseHTML(n,document,!0),r=$(o).filter("table").first();if(!r.length)throw new Error("KGrid TABLE_SHELL_TEMPLATE must contain a root <table> element");return t.tableAttrs&&e.isPlainObject(t.tableAttrs)&&(Object.keys(t.tableAttrs).forEach(e=>{"class"!==e&&r.attr(e,t.tableAttrs[e])}),"string"==typeof t.tableAttrs.class&&t.tableAttrs.class&&r.addClass(t.tableAttrs.class)),r},e.mountTableShell=function(t,n){const o=t.find("table.custom-table, table").first();if(o.length)return o;const r=e.getTableInteractionHost(t);r.hasClass("custom-table-shell")||r.addClass("custom-table-shell");const i=e.createTableShell(n);return r.append(i),i}}(window.KGrid),function(e){e._fieldTypes=Object.create(null),e._configuredCustomInputTypeNames=[],e.registerFieldType=function(t,n,o){if(!t||"string"!=typeof t)throw new TypeError("registerFieldType(name, plugin): name must be a string");if(!n||"function"!=typeof n.create)throw new TypeError("registerFieldType("+t+"): plugin.create is required");if(e._fieldTypes[t]&&(!o||!o.overwrite))throw new Error("Field type already registered: "+t);return e._fieldTypes[t]=Object.assign({name:t},n),e},e.unregisterFieldType=function(t){return t&&e._fieldTypes[t]&&delete e._fieldTypes[t],e},e.getFieldType=function(t){return t&&e._fieldTypes[t]||null},e.listFieldTypes=function(){return Object.keys(e._fieldTypes)},e.createFieldInput=function({mode:t,col:n,config:o}){const r=o.type??"text",i=e.getFieldType(r);if(!i)return null;"function"==typeof i.validate&&i.validate(o,t,n);const a=i.create({mode:t,col:n,config:o});if(!a||!a.$input||!a.$input.length)throw new Error('Field type "'+r+'" create() must return { $input: jQuery }');return a.$input.attr("data-type",r),a},e.mountField=function(t){const n=t.config?.type??t.type,o=e.getFieldType(n);o&&"function"==typeof o.mount&&o.mount(t)},e.resolveFilterEvents=function({plugin:e,$input:t,createResult:n}){let o;return n&&Object.prototype.hasOwnProperty.call(n,"filterEvents")?o=n.filterEvents:e&&Object.prototype.hasOwnProperty.call(e,"filterEvents")&&(o=e.filterEvents),!1===o||null===o?null:"string"==typeof o&&o.trim()?o.trim():t.is("select")?"change":"input"},e.normalizeFilterDebounceMs=function(e,t){if(!1===e)return 0;if(void 0===e)return t;if(null===e)return t;const n=Number(e);return!Number.isFinite(n)||n<0?0:n},e.resolveFilterDebounceMs=function({filterConfig:t,plugin:n}){return t&&Object.prototype.hasOwnProperty.call(t,"debounceMs")&&null!==t.debounceMs?e.normalizeFilterDebounceMs(t.debounceMs,0):n&&Object.prototype.hasOwnProperty.call(n,"filterDebounceMs")&&null!==n.filterDebounceMs?e.normalizeFilterDebounceMs(n.filterDebounceMs,0):e.normalizeFilterDebounceMs(e._config.filterDebounceMs,0)},e.shouldDebounceFilterSubmit=function(e,t){return!(!t||t<=0)&&!!e},e.bindFieldFilterSubmit=function(t,n,o){const r=e.getFieldType(t);r&&"function"==typeof r.bindFilterSubmit&&r.bindFilterSubmit(n,o)},e.bindFilterInputEvents=function({type:t,$input:n,onSubmit:o,createResult:r,filterConfig:i}){const a=t?e.getFieldType(t):null,l=e.resolveFilterEvents({plugin:a,$input:n,createResult:r}),s=e.resolveFilterDebounceMs({filterConfig:i,plugin:a}),c=e.wrapFilterSubmitHandler(n,o,l,s);l&&n.on(l,c),e.bindFieldFilterSubmit(t,n,c)},e.isPluggableFieldType=function(t){return!!e.getFieldType(t)},e.inputType=function(e,t){if("function"!=typeof e)throw new TypeError("inputType(mount, opts): mount must be a function");if(!t||"string"!=typeof t.element)throw new TypeError("inputType(mount, opts): opts.element is required (HTML string)");return{filterEvents:t.filterEvents,filterDebounceMs:t.filterDebounceMs,validate:t.validate,create({mode:e}){const n=$(t.element);return!t.formInputClass||"insert"!==e&&"update"!==e||n.addClass(t.formInputClass),{$input:n,skipValueAttr:!!t.skipValueAttr}},mount(t){e(t.$input,t.config?.options??t.config,t)},bindFilterSubmit:t.bindFilterSubmit}},e._getCustomInputTypesConfig=function(){return e._config.customInputTypes??e._config.fieldTypes??null},e._syncCustomInputTypes=function(){const t=e._getCustomInputTypesConfig(),n=t&&"object"==typeof t?Object.keys(t).filter(e=>null!=t[e]):[];e._configuredCustomInputTypeNames.forEach(t=>{n.includes(t)||e.unregisterFieldType(t)}),n.forEach(n=>{const o=t[n];if(!o||"object"!=typeof o||"function"!=typeof o.create){if("function"==typeof o)throw new Error("customInputTypes."+n+' is a function — use a plugin, e.g. KGrid.select2(fn) or KGrid.inputType(fn, { element: "..." })');throw new TypeError("customInputTypes."+n+" must be a plugin with create()")}e.registerFieldType(n,o,{overwrite:!0})}),e._configuredCustomInputTypeNames=n.slice()}}(window.KGrid),function(e){const t="kgrid-multi-select-value",n=";";function o(e,t,n){if(!e.length)return n;if(1===e.length){const n=t.find(function(t){return t.value===e[0]});return n?n.label:e[0]}return e.length+" selected"}function r(r,i,a){const l=i.separator||n,s=i.options||[],c=function(e){return null!=e.placeholder&&""!==e.placeholder?String(e.placeholder):"All"}(i),u="filter"===a;r.data("kgridMultiSep",l),r.addClass(t);const d=$("<div>").addClass("kgrid-multi-select").attr("data-mode",a),f=$("<div>").addClass("kgrid-multi-select-panel");let p=null;function m(){const t=e.parseMultiSelectValue(r[0].value,l);f.find("input[type='checkbox']").each(function(){this.checked=-1!==t.indexOf(this.value)}),p&&p.text(o(t,s,c))}function g(e){p&&(e?(f.appendTo(document.body),f.addClass("kgrid-multi-select-panel-floating"),f.removeAttr("hidden"),d.addClass("kgrid-multi-select-open"),p.attr("aria-expanded","true"),h()):(f.attr("hidden","hidden"),d.removeClass("kgrid-multi-select-open"),p.attr("aria-expanded","false"),f.css({position:"",top:"",left:"",width:"",minWidth:"",maxWidth:"",zIndex:""}),f.removeClass("kgrid-multi-select-panel-floating"),f.insertAfter(p)))}function h(){if(!p)return;const e=p[0].getBoundingClientRect(),t=Math.max(e.width,192);let n=e.left;const o=window.innerWidth-t-8;n>o&&(n=Math.max(8,o));let r=e.bottom+2;const i=Math.min(224,28*s.length+16);r+i>window.innerHeight-8&&e.top>i+8&&(r=e.top-i-2),f.css({position:"fixed",top:r+"px",left:n+"px",width:t+"px",minWidth:t+"px",maxWidth:"min(18rem, calc(100vw - 16px))",zIndex:1080})}u?(p=$("<button>").attr({type:"button","aria-expanded":"false"}).addClass("kgrid-multi-select-toggle form-select form-select-sm"),f.attr("hidden","hidden"),d.append(p,f)):(d.addClass("kgrid-multi-select-open"),d.append(f)),s.forEach(function(t,n){const o="kgrid_ms_"+e.uuid()+"_"+n,r=$("<label>").addClass("kgrid-multi-select-option").attr("for",o);$("<input>").attr({type:"checkbox",id:o,value:t.value,class:"kgrid-multi-select-check"}).appendTo(r),$("<span>").addClass("kgrid-multi-select-label").text(t.label).appendTo(r),f.append(r)}),r.before(d),d.append(r);const y=".kgridMultiSelect_"+e.uuid();f.on("change","input[type='checkbox']",function(){!function(e){const t=[];f.find("input[type='checkbox']:checked").each(function(){t.push(this.value)});const n=t.join(l);r[0].value!==n&&(r[0].value=n,e&&r.trigger("change")),p&&p.text(o(t,s,c))}(!0)}),r.on("kgrid:multiselect:set",function(){m()}),p&&(p.on("click",function(e){e.preventDefault(),e.stopPropagation(),g(!d.hasClass("kgrid-multi-select-open"))}),$(document).on("mousedown"+y,function(e){d.hasClass("kgrid-multi-select-open")&&($(e.target).closest(d).length||$(e.target).closest(f).length||g(!1))}),$(window).on("resize"+y+" scroll"+y,function(){d.hasClass("kgrid-multi-select-open")&&h()}));const b=function(){const e=r.prop("form")||r[0]&&r[0].form;e&&$(e).off("reset"+y).on("reset"+y,function(){setTimeout(m,0)})};return b(),setTimeout(b,0),m(),d}e.normalizeMultiSelectValue=function(e,t){const o=t||n;return null==e||""===e?"":Array.isArray(e)?e.filter(function(e){return null!=e&&""!==e}).map(String).join(o):String(e)},e.parseMultiSelectValue=function(t,o){const r=e.normalizeMultiSelectValue(t,o);return r?r.split(o||n).filter(Boolean):[]},function(){const o=$.valHooks.hidden||{};$.valHooks.hidden={get:function(e){return e&&e.classList&&e.classList.contains(t)?e.value:o.get?o.get(e):void 0},set:function(r,i){if(r&&r.classList&&r.classList.contains(t)){const t=$(r).data("kgridMultiSep")||n;return r.value=e.normalizeMultiSelectValue(i,t),$(r).triggerHandler("kgrid:multiselect:set"),!0}return o.set?o.set(r,i):void 0}}}(),e.registerFieldType("multi_select",{filterEvents:"change",filterDebounceMs:0,validate(e,t){!function(e,t){if(!Array.isArray(e.options))throw new Error("multi_select requires an options array ("+t+"): "+JSON.stringify(e,null,2));e.options.forEach(function(t){if(!t||"string"!=typeof t.label||"string"!=typeof t.value)throw new Error("multi_select options need string label and value: "+JSON.stringify(e,null,2))})}(e,t)},create({config:e}){const n=$("<input type='hidden'>").addClass(t);return e.separator&&n.data("kgridMultiSep",e.separator),{$input:n,skipValueAttr:!0}},mount(e){if(r(e.$input,e.config||{},e.mode),"update"===e.mode&&e.item&&e.col&&e.col.name){const t=e.item.attributes?e.item.attributes[e.col.name]:null;null!=t&&""!==t&&e.$input.val(t)}}});const i="kgrid-date-range-value";function a(e,t,n){const o=e&&e[t];return null!=o&&""!==o?String(o):n}e.dateRangeCalendarDate=function(e){if(null==e||""===e)return"";const t=/^(\d{4}-\d{2}-\d{2})/.exec(String(e).trim());return t?t[1]:""},e.dateRangeEndValue=function(e){return e?e+" 23:59:59":""},e.normalizeDateRangeDefault=function(t){if(null==t||"object"!=typeof t||Array.isArray(t))return{from:"",to:""};let n=e.dateRangeCalendarDate(t.from),o=e.dateRangeCalendarDate(t.to);return n&&o&&o<n&&(o=n),{from:n,to:o}},e.syncDateRangeVisible=function(t){if(!t||!t.getAttribute)return;const n=t.getAttribute("data-kgrid-date-range"),o=n&&t.ownerDocument.getElementById(n);if(!o)return;const r=t.ownerDocument.getElementById(n+"_panel");function i(e){return o.querySelector(e)||r&&r.querySelector(e)}const a=i("to"===t.getAttribute("data-kgrid-date-bound")?".kgrid-date-range-to":".kgrid-date-range-from");if(!a)return;const l=e.dateRangeCalendarDate(t.value);a.value!==l&&(a.value=l);const s=o.querySelector(".kgrid-date-range-display");if(!s)return;const c=i(".kgrid-date-range-from"),u=i(".kgrid-date-range-to"),d=function(e,t){function n(e){const t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e||"");return t?t[3]+"."+t[2]+"."+t[1]:""}const o=n(e),r=n(t);if(o&&r)return o+" – "+r;if(o)return o+" –";if(r)return"– "+r;return""}(c&&c.value,u&&u.value);s.value!==d&&(s.value=d);const f=o.querySelector(".kgrid-date-range-clear");f&&(d?(f.removeAttribute("hidden"),o.classList.add("kgrid-date-range-has-value")):(f.setAttribute("hidden","hidden"),o.classList.remove("kgrid-date-range-has-value")))},e.applyDateRangeDefault=function(t,n,o){const r=e.normalizeDateRangeDefault(o);if(!r.from&&!r.to)return;const i=e.filterFormFields(t,n);function a(e,t){if(!t)return;const n=i.filter(function(){return $(this).attr("data-operator")===e});n.length&&!n.val()&&(n.val(t),n[0]&&(n[0].defaultValue=n[0].value))}a(">=",r.from),a("<=",r.to)},function(){const t=$.valHooks.text||{};$.valHooks.text={get:function(e){return e&&e.classList&&e.classList.contains(i)?e.value:t.get?t.get(e):void 0},set:function(n,o){if(n&&n.classList&&n.classList.contains(i)){const t=e.dateRangeCalendarDate(o),r=n.getAttribute("data-kgrid-date-bound");return n.value="to"===r?e.dateRangeEndValue(t):t,e.syncDateRangeVisible(n),!0}return t.set?t.set(n,o):void 0}}}(),e.registerFieldType("date_range",{filterEvents:"change",filterDebounceMs:0,validate(e,t){if("filter"!==t)throw new Error("date_range is only valid as a filter")},create(){const e=$("<input type='text' autocomplete='off'>").addClass(i).attr("data-operator",">=").attr("data-kgrid-date-bound","from").attr("tabindex","-1").attr("aria-hidden","true"),t=$("<input type='text' autocomplete='off'>").addClass(i).attr("data-operator","<=").attr("data-kgrid-date-bound","to").attr("tabindex","-1").attr("aria-hidden","true");return e.data("kgridDateRangeTo",t),{$input:e,skipValueAttr:!0}},mount(t){!function(t,n){const o=t.data("kgridDateRangeTo"),r="kgrid_dr_"+e.uuid(),i=a(n,"fromLabel","From"),l=a(n,"toLabel","To"),s=n&&null!=n.placeholder&&""!==n.placeholder?String(n.placeholder):i+" – "+l,c=$("<div>",{class:"kgrid-date-range",id:r}),u=r+"_panel",d=$("<input type='text' readonly autocomplete='off' class='form-control form-control-sm kgrid-date-range-display'/>").attr("placeholder",s).attr("role","button").attr("aria-haspopup","dialog").attr("aria-expanded","false").attr("aria-controls",u),f=$("<button>",{type:"button",class:"kgrid-date-range-clear",hidden:"hidden","aria-label":"Clear",text:"×"}),p=$("<input autocomplete='off' type='date' class='form-control form-control-sm kgrid-date-range-from'/>"),m=$("<input autocomplete='off' type='date' class='form-control form-control-sm kgrid-date-range-to'/>"),g=$("<div>",{class:"kgrid-date-range-panel",id:u,hidden:"hidden",role:"dialog","aria-label":s});function h(e,n,r){e&&n&&n<e&&(n=e),p.val(e||""),m.val(n||""),t.val(e||""),o.val(n||""),r&&(t[0]&&(t[0].defaultValue=t[0].value),o[0]&&(o[0].defaultValue=o[0].value))}function y(e){e?(g.appendTo(document.body),g.addClass("kgrid-date-range-panel-floating"),g.removeAttr("hidden"),c.addClass("kgrid-date-range-open"),d.attr("aria-expanded","true"),b()):(g.attr("hidden","hidden"),c.removeClass("kgrid-date-range-open"),d.attr("aria-expanded","false"),g.css({position:"",top:"",left:"",width:"",zIndex:""}),g.removeClass("kgrid-date-range-panel-floating"),g.insertAfter(f))}function b(){const e=d[0].getBoundingClientRect(),t=Math.min(Math.max(e.width,320),window.innerWidth-16);let n=e.left;const o=window.innerWidth-t-8;n>o&&(n=Math.max(8,o)),g.css({position:"fixed",top:e.bottom+2+"px",left:n+"px",width:t+"px",zIndex:1080});const r=g[0].offsetHeight;let i=e.bottom+2;i+r>window.innerHeight-8&&e.top>r+8&&(i=e.top-r-2),g.css("top",i+"px")}g.append($("<label>",{class:"kgrid-date-range-bound"}).append($("<span>",{class:"kgrid-date-range-label",text:i}),p),$("<label>",{class:"kgrid-date-range-bound"}).append($("<span>",{class:"kgrid-date-range-label",text:l}),m)),c.append(d,f,g),t.before(c),t.attr("data-kgrid-date-range",r),o.attr("data-kgrid-date-range",r),c.append(t,o),p.add(m).on("change",function(){h(p.val()||"",m.val()||"",!1),t.trigger("change")}),d.on("click",function(e){e.preventDefault(),y(!c.hasClass("kgrid-date-range-open"))}),d.on("keydown",function(e){"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),y(!c.hasClass("kgrid-date-range-open")))}),f.on("click",function(e){e.preventDefault(),e.stopPropagation(),h("","",!1),t.trigger("change"),y(!1)});const w=".kgridDateRange_"+e.uuid();$(document).on("mousedown"+w,function(e){c.hasClass("kgrid-date-range-open")&&($(e.target).closest(c).length||$(e.target).closest(g).length||y(!1))}),$(document).on("keydown"+w,function(e){"Escape"===e.key&&c.hasClass("kgrid-date-range-open")&&y(!1)}),$(window).on("resize"+w+" scroll"+w,function(){c.hasClass("kgrid-date-range-open")&&b()});const v=function(){const n=t.prop("form")||t[0]&&t[0].form;n&&$(n).off("reset"+w).on("reset"+w,function(){setTimeout(function(){e.syncDateRangeVisible(t[0]),e.syncDateRangeVisible(o[0])},0)})};t.data("kgridDateRangeBindReset",v),v(),setTimeout(v,0);const C=e.normalizeDateRangeDefault(e.filterDefaultValue?e.filterDefaultValue(n&&n.default):n&&n.default);(C.from||C.to)&&h(C.from,C.to,!0)}(t.$input,t.config||{})}})}(window.KGrid),function(e){e.resolveDefaultInteraction=function(e){return"edit"===e.defaultInteraction||"view"===e.defaultInteraction?e.defaultInteraction:!0===e.editmode?"edit":(e.editmode,"view")},e.getTableInteractionHost=function(e){if(e.hasClass("custom-table-shell"))return e;const t=e.find(".custom-table-shell").first();return t.length?t:e},e.applyInteraction=function(t,n,o){const r=e.getTableInteractionHost(t),i="edit"===n?"edit":"view";r.attr("data-interaction",i),o&&"object"==typeof o?(void 0!==o.create&&r.attr("data-allow-insert",o.create?"true":"false"),void 0!==o.update&&r.attr("data-allow-update",o.update?"true":"false"),void 0!==o.delete&&r.attr("data-allow-delete",o.delete?"true":"false"),void 0!==o.clone&&r.attr("data-allow-clone",o.clone?"true":"false")):"edit"===i&&r.removeAttr("data-allow-insert data-allow-update data-allow-delete data-allow-clone")}}(window.KGrid),function(e){e.setupLabelsHeader=function(t,n){const o=t.children("tr"),r=o.children(),i=r.first().clone(!0);r.remove();return[...n.columns].forEach(t=>{if(t.hidden)return;let r=i.clone(!0);if(e.applyColumnDomAttrs(r,t),e.applyColumnCellMeta(r,t),t.selection){const i=r.empty();return $("<input>",{type:"checkbox",class:"form-check-input kgrid-select-all","aria-label":n.selectionAllLabel||"Toggle all"}).appendTo(i),e.applyColumnCellMeta(i,t),void o.append(i)}const a=t.label??"";if(!t.features?.sort){const n=r.empty().html(a);return""!==a&&n.attr("title",a),e.applyColumnCellMeta(n,t),void o.append(n)}if(!t.name)throw new Error("Column must have a name when column.sortable is true: \n"+JSON.stringify(t,null,2));const l=r.find("span.column-label").text(a);""!==a&&l.attr("title",a),r.children("a").attr("data-sortfld",t.name),r.appendTo(o)}),e.hasActionColumn(n)&&$("<th>").addClass("kgrid-row-actions").attr("aria-label","Actions").appendTo(o),o}}(window.KGrid),function(e){const t="kgridFilterDebounceTimer";e.cancelFilterSubmit=function(e){const n=e.data(t);n&&(clearTimeout(n),e.removeData(t))},e.cancelFilterDebounces=function(t){const n=$(t).attr("id");n&&$(document).find("[form='"+n+"']").each(function(){e.cancelFilterSubmit($(this))})},e.flushFilterSubmit=function(e){const n=e.data(t);if(!n)return;clearTimeout(n),e.removeData(t);const o=e[0]&&e[0].form;o&&$(o).trigger("submit")},e.wrapFilterSubmitHandler=function(n,o,r,i){if(!e.shouldDebounceFilterSubmit(r,i))return o;const a=i;return function(){e.cancelFilterSubmit(n);const r=setTimeout(function(){n.removeData(t),o.call(this)}.bind(this),a);n.data(t,r)}},e.filterDefaultValue=function(e){return null!=e&&"object"==typeof e&&null!=e.value?e.value:e},e.columnFilterPersisted=function(e){const t=e&&e.filter?e.filter:{};return!(!e||!e.hidden&&"hidden"!==t.type&&!t.persist)},e.ensureFilterField=function(e,t,n,o){if(!e||!t||null==n||""===n)return null;let r=e.elements&&e.elements.namedItem(t);return r&&null!=r.length&&!r.tagName&&(r=r[0]),r&&r.tagName||(r=document.createElement("input"),r.type="hidden",r.name=t,e.appendChild(r)),r.setAttribute("data-operator",o||"="),r.value=String(n),r.defaultValue=String(n),r},e.applyColumnDefaultFilters=function(t,n){t&&n&&n.forEach(function(n){if(!n.name||n.features&&!1===n.features.filter)return;const o=n.filter;if(!o||null==o.default||""===o.default)return;const r=e.filterDefaultValue(o.default);if(null==r||""===r)return;if("date_range"===o.type)return void e.applyDateRangeDefault(t,n.name,r);const i=o.operator||(e.columnFilterPersisted(n)?"=":"~=~"),a=e.filterFormField(t,n.name);!n.hidden&&"hidden"!==o.type&&a.length?a.val()||(a.val(String(r)),a.attr("data-operator",i)):e.ensureFilterField(t,n.name,r,i)})},e.setupDefaultFilters=function(t,n,o,r){const i=$(t)[0];if(!(i&&n&&n.features&&n.features.filtering))return;const a=n.columns||[];if(e.applyColumnDefaultFilters(i,a),a.some(e.columnFilterPersisted)){let t=!1;$(i).off("reset.kgridDefaultFilters").on("reset.kgridDefaultFilters",function(n){if(!t){n.preventDefault(),e.cancelFilterDebounces(i),t=!0;try{i.reset(),e.applyColumnDefaultFilters(i,a),o&&o.filtering&&"function"==typeof o.filtering.handleSubmit?o.filtering.handleSubmit(i):$(i).trigger("submit")}finally{t=!1}}})}if(!o||!o.filtering)return;const l=a.filter(function(t){return t.name&&t.filter&&null!=t.filter.default&&""!==t.filter.default&&e.columnFilterPersisted(t)});if(!l.length)return;const s=String(o.url&&o.url.parameters&&o.url.parameters.filter||"");!l.some(function(t){if(t.filter&&"date_range"===t.filter.type){const n=e.normalizeDateRangeDefault(e.filterDefaultValue(t.filter.default));return!(!n.from||-1!==s.indexOf(t.name+">="))||!(!n.to||-1!==s.indexOf(t.name+"<="))}return-1===s.indexOf(t.name+"=")})||r&&r.skipInitSubmit||o.filtering.handleSubmit(i)},e.setupFilterHeader=function(t,n){if(!n.features||!n.features.filtering)return null;const o=t.find(".thead-filters");o.empty();const r=[...n.columns],i=$("<tr>");i.appendTo(o);const a="filter_form_"+e.uuid(),l=$("<form>").attr("id",a).attr("hidden","hidden").attr("aria-hidden","true").addClass("table-filter-form").insertBefore(t);return r.forEach(t=>{const n=t.filter||{};if(t.hidden||"hidden"===n.type){if(t.features&&!1===t.features.filter)return;if(!t.name)return;const o=e.filterDefaultValue(n.default);return void(null!=o&&""!==o?e.ensureFilterField(l[0],t.name,o,n.operator||"="):e.columnFilterPersisted(t)&&e.ensureFilterField(l[0],t.name,"",n.operator||"="))}let o,r=$("<th>").appendTo(i).attr("data-label",t.label);if(e.applyColumnCellMeta(r,t),!1===t.features.filter)return;if(!t.name)throw new Error("Column must have a name when column.features.filter is true: \n"+JSON.stringify(t,null,2));let s=null;const c=e.createFieldInput({mode:"filter",col:t,config:n});if(c)s=c,o=c.$input,o.appendTo(r),e.mountField({mode:"filter",$input:o,col:t,config:n});else if("select"===n.type){if(!n.options)throw new Error("Column must have a filter.options array when column.filter.type is select: \n"+JSON.stringify(t,null,2));if(o=$("<select>").addClass("form-select form-select-sm"),!Array.isArray(n.options))throw new Error("Column must have a filter.options array when column.filter.type is select: \n"+JSON.stringify(t,null,2));n.options.forEach(e=>{if(!e.label||"string"!=typeof e.value)throw new Error("Column must have an filter.options object with label and value when column.filter.type is select: \n"+JSON.stringify(t,null,2));$("<option>").text(e.label).attr("value",e.value).appendTo(o)}),o.appendTo(r)}else{if(!e.isValidFilterType(n.type))throw new Error("Unknown filter type: "+n.type);o=$(`<input autocomplete='off' type='${n.type}' class='form-control form-control-sm'/>`),o.appendTo(r)}if("date_range"===n.type){r.find("input.kgrid-date-range-value").each(function(){this.setAttribute("form",a),this.setAttribute("name",t.name),l[0].appendChild(this)});const e=o.data("kgridDateRangeBindReset");"function"==typeof e&&e()}else{const r=n.operator||("multi_select"===n.type?"><":void 0);null!=r&&o.attr("data-operator",r),o.attr("form",a),o.attr("name",t.name);const i=e.filterDefaultValue(n.default);if(null!=i&&""!==i&&!o.val()){const t="multi_select"===n.type?e.normalizeMultiSelectValue(i,n.separator):String(i);o.val(t),o.attr("data-default",t),o[0]&&(o[0].defaultValue=t)}}e.bindFilterInputEvents({type:n.type,$input:o,onSubmit:function(){const e=this.form;e&&$(e).trigger("submit")},createResult:s,filterConfig:n})}),e.hasActionColumn(n)&&$("<th>").addClass("kgrid-row-actions").attr("data-label","Actions").appendTo(i),l},e.syncFormFiltersToCollectionUrl=function(e,t){if(!e||!t||!t.url)return;t.url.parameters||(t.url.parameters={});const n=[],o=e.elements;if(o){for(let e=0;e<o.length;e++){const t=o[e];if(!t||!t.name)continue;const r=$(t),i=r.val();if(null==i||""===i)continue;const a=r.attr("data-operator")||r.data("operator")||"=";n.push(t.name+a+i)}t.offset=0,n.length?t.url.parameters.filter=n.join(","):delete t.url.parameters.filter}},e.FilterForm=function(t){this.form=$(t)[0],this.filter=(t,n,o="~=~")=>{if(!this.form)return this;let r=e.filterFormField(this.form,t);if(r.length||(e.ensureFilterField(this.form,t,n,o),r=e.filterFormField(this.form,t)),!r.length)return this;e.flushFilterSubmit(r),r.val(n);const i=r.attr("data-operator");return r.attr("data-operator",o),$(this.form).trigger("submit"),r.attr("data-operator",i),this},this.ensure=(t,n,o="=")=>(e.ensureFilterField(this.form,t,n,o),this),this.reset=()=>(this.form&&(e.cancelFilterDebounces(this.form),this.form.reset()),this)}}(window.KGrid),function(e){e.wrapFlagSwitch=function(e){return e.attr({type:"checkbox",role:"switch",value:"1"}).removeClass("form-control form-input form-control-sm").addClass("form-check-input"),$("<div class='form-check form-switch kgrid-flag-switch mb-0'>").append(e)},e.setupCell=function(t,n){const o=n?n.attr("id"):null,r={...t},i=$("<td>").attr("data-label",t.label);e.applyColumnCellMeta(i,t),e.applyColumnDomAttrs(i,r);let a=$("<div>").addClass("cell-content");if(a.html(r.display.template??`{{${r.name}}}`),a.appendTo(i),null==n||!t.features.update)return a.clone(!0).removeClass("cell-content").addClass("cell-input").appendTo(i),i;if(!r.name)throw new Error("Column must have a name when column.features.update is true: \n"+JSON.stringify(t,null,2));const l=r.update,s=l.type??"text";let c,u=!1;const d=e.createFieldInput({mode:"update",col:t,config:l});if(d)c=d.$input,u=!!d.skipValueAttr;else{switch(s){case"textarea":c=$(`<textarea class='form-input form-control form-control-sm'>{{${l.value??r.name}}}</textarea>`),u=!0;break;case"select":if(c=$("<select class='form-input form-control form-control-sm'/>"),!Array.isArray(l.options))throw new Error("Select column must have an update.options array when column.features.update is true: \n"+JSON.stringify(t,null,2));l.options.forEach(e=>{if("string"!=typeof e.label||void 0===e.value)throw new Error("Select update.options entries need label and value: \n"+JSON.stringify(t,null,2));$("<option>").text(e.label).attr("value",e.value).appendTo(c)}),u=!0;break;case"hidden":c=$("<input type='hidden' class='form-input form-control form-control-sm'/>");break;case"displayonly":{const e=l.template||r.display.template||`{{${r.name}}}`;return $("<div>").addClass("cell-input").append(e).appendTo(i),i}case"checkbox":c=$("<input autocomplete='off' type='checkbox' class='form-check-input'/>"),u=!0;break;default:if(!e.isValidInputType(s))throw new Error("Invalid update updateConfig type: "+JSON.stringify(l,null,2));c=$(`<input autocomplete='off' type='${s}' class='form-input form-control form-control-sm'/>`)}c.attr("data-type",s)}if(l.attrs&&"object"==typeof l.attrs&&Object.keys(l.attrs).forEach(e=>c.attr(e,l.attrs[e])),c.attr("form",o),c.attr("name",r.name),!u&&"textarea"!==s){const e=l.value??`{{${r.name}}}`;null!=e&&"object"!=typeof e&&c.attr("value",e)}if(r.hidden)return c.attr("type","hidden").appendTo(n),i;l.disabled&&c.attr("disabled",!0),l.readonly&&c.attr("readonly",!0),l.required&&c.attr("required",!0),l.attrs&&"object"==typeof l.attrs&&Object.keys(l.attrs).forEach(e=>c.attr(e,l.attrs[e])),l.disabled||l.readonly||c.attr("onchange","$(this).parents('tr').addClass('editing')");const f="checkbox"===s?e.wrapFlagSwitch(c):c;return $("<div>").addClass("cell-input").append(f).appendTo(i),i}}(window.KGrid),function(e){e.setupNoDataTbody=function(e,t,n){const o=e.find("td").attr("colspan",n);return t.noDataTemplate&&o.html(t.noDataTemplate),o},e.fillDataRow=function(t,n){const o=[...n.columns],r="data_row_form_"+e.uuid()+"_{{this.id}}",i=n.features&&n.features.update?$("<form class='edit-form table-row-form'>").attr("id",r):null;if(o.forEach(n=>{const o=e.setupCell(n,i);n.hidden||o.appendTo(t)}),e.hasActionColumn(n)){const o=$("<td>").addClass("kgrid-row-actions").appendTo(t);e.renderRowActions(o,n,r)}return i&&e.anchorRowForm(i,t),t},e.setupDataBody=function(t,n,o,r,i,a){const l=$("<tr>").appendTo(t);if(n.dataRowAttrs&&"object"!=typeof n.dataRowAttrs)throw new Error("options.dataRowAttrs must be an object");const s={...n.dataRowAttrs??{}};return Object.keys(s).forEach(e=>l.attr(e,s[e])),t.data("emptyview",a),n?.features?.sorting&&t.data("sort",o),i&&t.data("paging",i.find(".pages")).data("pagesizeinp",i.find(".pagesize")).data("totalrecscount",i.find(".totalrecscount")),r&&t.data("filter",r),n.type&&t.data("type",n.type),e.fillDataRow(l,n),t},e.setupPagingFooter=function(t,n,o){return e.log("setupPagingFooter",t,n,o),n.pagingFooterAttrs&&e.isPlainObject(n.pagingFooterAttrs)&&Object.keys(n.pagingFooterAttrs).forEach(e=>t.attr(e,n.pagingFooterAttrs[e])),e.log("noVisibleCols",o),t.find("td").attr("colspan",o),t}}(window.KGrid),function(e){e.setupNewRecordForm=function(t,n,o){if(!n.insertFormRow||!e.isPlainObject(n.insertFormRow))return t.find(".before-main-tbody").remove(),void t.find(".after-main-tbody").remove();const r=[...n.columns],i=$("<tr>").addClass("new-record-row");"top"===(n.insertFormRow?.position??"top")?(t.find(".after-main-tbody").remove(),i.appendTo(t.find(".before-main-tbody"))):(t.find(".before-main-tbody").remove(),i.appendTo(t.find(".after-main-tbody")));const a="new_record_row_form_"+e.uuid(),l=$("<form class='table-row-form'>").attr("id",a).off("submit").on("submit",t=>{t.preventDefault();const i=e.serializeForm(t.target,r);Object.keys(i).forEach(e=>{r.find(t=>t.name===e)?.insert?.dontsave&&delete i[e]}),o.instance.newItem(i).then(()=>{t.target.reset(),"function"==typeof n.onNewItemCreated&&n.onNewItemCreated(i,t.target)}).catch(e.onError)});r.forEach(t=>{if(t.hidden){if(n.features?.create&&t.features?.create){const e=$("<input type='hidden'>").attr("name",t.name).attr("form",a).appendTo(l);t.insert.default&&e.val(t.insert.default)}return}if(!t.features.create){const n=$("<td>").appendTo(i).attr("data-label",t.label);return void e.applyColumnCellMeta(n,t)}const o=t.insert;if(!o||!e.isPlainObject(o))throw new Error("Column must have an insert config object when column.features.create is true: \n"+JSON.stringify(t,null,2));if(!o.type)throw new Error("Column must have an insert.type when column.features.insert is true: \n"+JSON.stringify(t,null,2));let r;const s=o.type??"text",c=e.createFieldInput({mode:"insert",col:t,config:o});if(c)r=c.$input;else switch(s){case"textarea":r=$("<textarea class='form-input form-control form-control-sm'>");break;case"select":if(r=$("<select class='form-input form-control form-control-sm'/>"),!o.options||!Array.isArray(o.options))throw new Error("Column must have an insert.options array when column.features.insert is true: \n"+JSON.stringify(t,null,2));o.options.forEach(e=>{if("string"!=typeof e.label||void 0===e.value)throw new Error("Column must have an insert.options object with label and value when column.features.insert is true: \n"+JSON.stringify(t,null,2));$("<option>").text(e.label).attr("value",e.value).appendTo(r)});break;case"hidden":r=$("<input type='hidden' class='form-input form-control form-control-sm'/>");break;case"checkbox":r=$("<input autocomplete='off' type='checkbox' class='form-check-input'/>"),r.attr("data-type",s);break;default:if(!e.isValidInputType(s))throw new Error("Invalid type: "+JSON.stringify(o,null,2));r=$(`<input autocomplete='off' type='${s}' class='form-input form-control form-control-sm'/>`),r.attr("data-type",s)}const u="object"==typeof o.default&&o.default&&null!=o.default.value?o.default.value:o.default;if("checkbox"===s){const t=e.isFlagOn(u);r.prop("checked",t).prop("defaultChecked",t)}else null==o.default||""===o.default||r.val()||String(u).trim()&&(r.val(u).trigger("change"),r[0]&&"defaultValue"in r[0]&&(r[0].defaultValue=r[0].value));if(o.attrs&&"object"==typeof o.attrs&&Object.keys(o.attrs).forEach(e=>r.attr(e,o.attrs[e])),r.attr("form",a).attr("name",t.name),o.disabled&&r.attr("disabled",!0),o.readonly&&r.attr("readonly",!0),o.required&&r.attr("required",!0),o.attrs&&"object"==typeof o.attrs&&Object.keys(o.attrs).forEach(e=>r.attr(e,o.attrs[e])),"hidden"!==o.type){const n="checkbox"===s?e.wrapFlagSwitch(r):r,o=$("<td>").append(n).appendTo(i).attr("data-label",t.label);e.applyColumnCellMeta(o,t)}e.mountField({mode:"insert",$input:r,col:t,config:o,formEl:l[0],rowEl:i[0]}),o.events&&Array.isArray(o.events)&&o.events.forEach(e=>{r.off(e.event).on(e.event,function(t,...n){"function"==typeof e.callback&&e.callback(t,l[0],i[0],...n)})})}),e.anchorRowForm(l,i);const s=$("<td>").addClass("kgrid-row-actions").appendTo(i).attr("data-label","action"),c=$("<div>").addClass("btn-group").appendTo(s);return $("<button>").addClass("btn btn-sm btn-primary new-item-btn").html("<i class='fas fa-plus-square'></i>").attr("form",a).attr("type","submit").appendTo(c),"function"==typeof n.onInsertRowReady&&n.onInsertRowReady(l[0],i[0]),i}}(window.KGrid),function(e){e.setupEvents=function(t,n,o,r){const i=t.views[0];i&&i.el&&"function"==typeof e.applyLayoutToRow&&e.applyLayoutToRow(i.el,o.columns),"function"==typeof e.bindSelectionRow&&e.bindSelectionRow(t,i,n,o),o.columns.forEach(n=>{n.display.events.forEach(e=>{if(!e.selector||!e.event||!e.callback)throw new Error("Invalid event: "+JSON.stringify(e,null,2));i.el.find(e.selector).off(e.event).on(e.event,n=>{if("function"!=typeof e.callback)throw new Error("Event callback must be a function: "+JSON.stringify(e,null,2));e.callback(n,t,i)})}),o.features.update&&n.update.events.forEach(o=>{if(!o.event||!o.callback)throw new Error("Invalid event: "+JSON.stringify(o,null,2));i.el.find("[name='"+n.name+"']").off(o.event).on(o.event,function(n,...r){if(e.log("event",o,n,this,r),"function"!=typeof o.callback)throw new Error("Event callback must be a function: "+JSON.stringify(o,null,2));o.callback(n,t,i,...r)})})}),o.features.update&&(i.el.find("[data-type]").each((n,o)=>{const a=o.getAttribute("data-type");if(!e.isPluggableFieldType(a))return;const l=r.get(o.name);l?.update&&e.mountField({mode:"update",$input:$(o),col:l,config:l.update,item:t,view:i})}),i.el.find("select[data-type='select']").each((e,n)=>{const o=r.get(n.name);if(!o)return;const i=t.attributes[o.name];null!=i&&""!==i&&$(n).val("boolean"==typeof i?String(i):i)}),i.el.find("input[type='checkbox']").each((n,o)=>{const i=r.get(o.name);i&&(o.checked=e.isFlagOn(t.attributes[i.name]))}),i.el.find("form.edit-form").off("submit").on("submit",t=>{const n=t.target;t.preventDefault();const r=$(n).parents("[data-type=item]").data().instance,i=e.serializeForm(n);Object.keys(i).forEach(e=>{o.columns.find(t=>t.name===e)?.update?.dontsave&&delete i[e]}),r.update(i).catch(e.onError)}));const a=e.resolveRowActions(o);e.applyRowActionVisibility(i.el,t,a.menuItems),e.mountRowActionDropdowns(i.el);const l=a.menuItems.some(e=>"clone"===e.action),s=a.menuItems.some(e=>"delete"===e.action);l&&i.el.find(".clone-item").off("click").on("click",e=>{e.preventDefault(),e.stopPropagation(),"function"==typeof o.onClone&&o.onClone(t,i,e)}),s&&i.el.find(".delete-item").off("click").on("click",n=>{n.preventDefault(),n.stopPropagation(),i.el.addClass("confirm-delete");const r=()=>i.el.removeClass("confirm-delete"),l=$(n.currentTarget).closest("[data-kgrid-action-index]").attr("data-kgrid-action-index"),s=null!=l?a.menuItems[Number(l)]:null,c=s&&"string"==typeof s.confirm?s.confirm:null;(c?(t,n)=>e.confirm(c,t,n):(n,r)=>e.runDeleteConfirm({item:t,view:i,options:o},n,r))(()=>{t.delete().catch(e.onError).finally(r)},r)});const c=new Map;a.menuItems.forEach(e=>{e.id&&"function"==typeof e.callback&&c.set(e.id,e.callback)}),c.size&&i.el.find("[data-kgrid-action]").off("click.kgridAction").on("click.kgridAction",e=>{const n=e.currentTarget.getAttribute("data-kgrid-action"),o=c.get(n);o&&(e.preventDefault(),e.stopPropagation(),o(e,t,i))}),"function"==typeof o.onRowFields&&o.onRowFields(t,i,n)}}(window.KGrid),function(e){e.PREFERENCES_VERSION=1,e.localStoragePreferences={get:function(e){try{const t="undefined"!=typeof window?window:globalThis,n=t&&t.localStorage;if(!n)return null;const o=n.getItem(e);return o?JSON.parse(o):null}catch(e){return null}},set:function(e,t){try{const n="undefined"!=typeof window?window:globalThis,o=n&&n.localStorage;if(!o)return;if(null==t)return void o.removeItem(e);o.setItem(e,JSON.stringify(t))}catch(e){}}},e.preferencesStorageFor=function(t){return t&&t.preferencesStorage?t.preferencesStorage:e._config&&e._config.preferencesStorage?e._config.preferencesStorage:e.localStoragePreferences},e.layoutStorageKey=function(e){return"kgrid:"+e+":layout"},e.filtersStorageKey=function(e,t){let n="kgrid:"+e+":filters";return null!=t&&""!==String(t)&&(n+=":"+String(t)),n},e.viewStorageKey=function(e,t){let n="kgrid:"+e+":view";return null!=t&&""!==String(t)&&(n+=":"+String(t)),n},e.chooserColumns=function(e){return(e||[]).filter(function(e){return e&&e.name&&!e.hidden&&!e.selection})},e.layoutFromColumns=function(t){return{v:e.PREFERENCES_VERSION,columns:e.chooserColumns(t).map(function(e){return{name:e.name,hidden:!!e.userHidden}})}},e.parseFilterExpression=function(e){const t=String(e||""),n=["~=~",">=","<=","!=","=",">","<"];for(let e=0;e<n.length;e++){const o=n[e],r=t.indexOf(o);if(r>0)return{name:t.slice(0,r),operator:o,value:t.slice(r+o.length)}}return null},e.isUserFilterColumn=function(e){return!(!e||!e.name||e.hidden||e.features&&!1===e.features.filter)},e.readUserFilters=function(t,n){if(!t)return[];const o=[];return(n||[]).forEach(function(n){if(!e.isUserFilterColumn(n))return;let r=e.filterFormFields(t,n.name);if(r.length||(r=e.filterFormField(t,n.name)),!r.length)return;if(r.length>1)return void r.each(function(){const e=$(this),t=e.val();null==t||""===t||Array.isArray(t)&&!t.length||o.push({name:n.name,value:Array.isArray(t)?t:String(t),operator:e.attr("data-operator")||n.filter&&n.filter.operator||">="})});const i=r,a=i.val();if(null==a||""===a||Array.isArray(a)&&!a.length)return;const l=i.attr("data-operator")||n.filter&&n.filter.operator||"~=~";o.push({name:n.name,value:Array.isArray(a)?a:String(a),operator:l})}),o},e.applyUserFilters=function(t,n,o){t&&o&&Array.isArray(o.filters)&&o.filters.forEach(function(o){if(!o||!o.name)return;const r=(n||[]).find(function(e){return e&&e.name===o.name});if(!e.isUserFilterColumn(r))return;if(null==o.value||""===o.value)return;const i=e.filterFormFields(t,o.name);if(i.length>1){if(!o.operator)return;const e=i.filter(function(){return $(this).attr("data-operator")===o.operator});return void(e.length&&e.val(o.value))}let a=e.filterFormField(t,o.name);a.length||(e.ensureFilterField(t,o.name,o.value,o.operator),a=e.filterFormField(t,o.name)),a.length&&(a.val(o.value),o.operator&&a.attr("data-operator",o.operator))})},e.ensureUrlFiltersOnForm=function(t,n){if(!(t&&n&&n.url&&n.url.parameters))return;const o=String(n.url.parameters.filter||"");o&&o.split(",").forEach(function(n){const o=e.parseFilterExpression(n.trim());if(!o||!o.name||""===o.value)return;const r=e.filterFormFields(t,o.name);if(r.length>1){const e=r.filter(function(){return $(this).attr("data-operator")===o.operator});return void(e.length&&!e.val()&&e.val(o.value))}const i=e.filterFormField(t,o.name);return i.length&&i.val()?void 0:i.length?(i.val(o.value),void i.attr("data-operator",o.operator)):void e.ensureFilterField(t,o.name,o.value,o.operator)})},e.preferencesLoadLayout=function(t){if(!t||!t.storageKey)return null;const n=e.preferencesStorageFor(t).get(e.layoutStorageKey(t.storageKey));return n&&n.v===e.PREFERENCES_VERSION&&Array.isArray(n.columns)?n:null},e.preferencesSaveLayout=function(t,n){t&&t.storageKey&&e.preferencesStorageFor(t).set(e.layoutStorageKey(t.storageKey),n)},e.preferencesLoadFilters=function(t){if(!t||!t.storageKey)return null;const n=e.preferencesStorageFor(t).get(e.filtersStorageKey(t.storageKey,t.filterStorageScope));return n&&n.v===e.PREFERENCES_VERSION&&Array.isArray(n.filters)?n:null},e.preferencesSaveFilters=function(t,n){t&&t.storageKey&&e.preferencesStorageFor(t).set(e.filtersStorageKey(t.storageKey,t.filterStorageScope),{v:e.PREFERENCES_VERSION,filters:n||[]})},e.preferencesLoadView=function(t){if(!t||!t.storageKey)return null;const n=e.preferencesStorageFor(t).get(e.viewStorageKey(t.storageKey,t.filterStorageScope));return n&&n.v===e.PREFERENCES_VERSION&&"object"==typeof n?n:null},e.preferencesSaveView=function(t,n){t&&t.storageKey&&e.preferencesStorageFor(t).set(e.viewStorageKey(t.storageKey,t.filterStorageScope),n)},e.sortableColumnNames=function(e){const t=new Set;return(e||[]).forEach(function(e){e&&e.name&&e.features&&e.features.sort&&!e.hidden&&t.add(e.name)}),t},e.sanitizeSort=function(t,n){const o=e.sortableColumnNames(n),r=[];return String(null==t?"":t).split(",").forEach(function(e){const t=/^(-*)([A-Za-z0-9_-]+)$/.exec(String(e).trim());t&&o.has(t[2])&&r.push((t[1].length?"-":"")+t[2])}),r.join(",")},e.collectionSort=function(e){const t=e&&e.url&&e.url.parameters;return t&&null!=t.sort&&""!==t.sort?String(t.sort):""},e.sortDirectionForField=function(e,t){const n=String(e||"").split(",");for(let e=0;e<n.length;e++){const o=/^(-*)([A-Za-z0-9_-]+)$/.exec(n[e].trim());if(o&&o[2]===t)return o[1].length?"desc":"asc"}return null},e.syncSortIndicators=function(t,n){t&&t.length&&t.find("[data-sortfld]").each(function(){const t=$(this),o=t.attr("data-sortfld"),r=e.sortDirectionForField(n,o),i=t.find(".sort-up"),a=t.find(".sort-down"),l=t.find(".sort-default");"asc"===r?(t.data("sortdir","up"),i.show(),a.hide(),l.hide()):"desc"===r?(t.data("sortdir","down"),i.hide(),a.show(),l.hide()):(t.removeData("sortdir"),i.hide(),a.hide(),l.show())})},e.applySavedPageSize=function(e,t,n){if(!e||!e.length||null==n)return!1;const o=String(n);if(!/^\d+$/.test(o)||"0"===o)return!1;const r=(t.pagingPageSizes||[]).map(function(e){return String(e)});if(r.length&&r.indexOf(o)<0)return!1;const i=e.find("select.pagesize");return!!i.length&&(i.val(o),e.find(".pages").attr("data-pagesize",o),!0)},e.applySavedOffset=function(e,t){e&&null!=t&&/^\d+$/.test(String(t))&&("function"!=typeof e.setOffset?e.offset=String(t):e.setOffset(String(t)))},e.applySavedSort=function(t,n,o){if(!(o&&null!=o.sort&&n&&n.features&&n.features.sorting))return;const r=t&&t.url&&t.url.parameters;if(!r)return;const i=e.sanitizeSort(o.sort,n.columns);i?r.sort=i:delete r.sort},e.persistViewState=function(t,n,o){if(!(n&&n.storageKey&&t&&n.features))return;const r=!!n.features.sorting,i=!!n.features.paging;if(!r&&!i)return;const a=e.preferencesLoadView(n)||{},l={v:e.PREFERENCES_VERSION};if(r){const o=t.url&&t.url.parameters;o&&Object.prototype.hasOwnProperty.call(o,"sort")?l.sort=e.sanitizeSort(o.sort,n.columns):"string"==typeof a.sort?l.sort=a.sort:l.sort=""}if(i){const e=o&&o.length?o.find("select.pagesize").val():null,r=(n.pagingPageSizes||[]).map(function(e){return String(e)});null!=e&&/^\d+$/.test(String(e))&&"0"!==String(e)&&(!r.length||r.indexOf(String(e))>=0)?l.pageSize=Number(e):null!=a.pageSize&&(l.pageSize=a.pageSize);const i=null!=t.offset?String(t.offset):"0";l.offset=/^\d+$/.test(i)?Number(i):0}e.preferencesSaveView(n,l)},e.bindViewPersistence=function(t,n,o){t&&"function"==typeof t.on&&n&&n.storageKey&&n.features&&(n.features.sorting||n.features.paging)&&t.on("load",function(){e.persistViewState(t,n,o),n.features.sorting&&e.syncSortIndicators(o,e.collectionSort(t))})},e.reorderColumns=function(e,t){const n=new Map,o=[],r=[];(e||[]).forEach(function(e,t){e&&e.hidden?o.push({col:e,index:t}):e&&e.selection?r.push(e):e&&e.name&&n.set(e.name,e)});const i=[];(t||[]).forEach(function(e){n.has(e)&&(i.push(n.get(e)),n.delete(e))}),n.forEach(function(e){i.push(e)});const a=r.concat(i);return o.forEach(function(e){a.splice(Math.min(e.index,a.length),0,e.col)}),a},e.columnDefaultUserHidden=function(e){return!(!e||!e.defaultHidden||e.locked||e.hidden)},e.mergeLayoutIntoColumns=function(t,n){const o=(t||[]).slice();o.forEach(function(t){t&&!t.hidden&&(t.userHidden=e.columnDefaultUserHidden(t))});const r=e.chooserColumns(o),i=new Map(r.map(function(e){return[e.name,e]})),a=[],l=new Set;(n&&Array.isArray(n.columns)?n.columns:[]).forEach(function(e){if(!e||!e.name||!i.has(e.name))return;const t=i.get(e.name);t.userHidden=!!e.hidden&&!t.locked,a.push(e.name),l.add(e.name)}),r.forEach(function(e){l.has(e.name)||a.push(e.name)});const s=e.reorderColumns(o,a),c=e.chooserColumns(s);if(c.length&&c.every(function(e){return e.userHidden})){(c.find(function(e){return!e.locked})||c[0]).userHidden=!1}return s},e.applyLayoutToRow=function(t,n){if(!t||!t.length)return;const o=e.chooserColumns(n),r=o.map(function(e){return e.name}),i={};o.forEach(function(e){e.userHidden&&(i[e.name]=!0)});const a=t.children(".kgrid-row-actions"),l={};t.children("[data-name]").each(function(){l[this.getAttribute("data-name")]=this}),r.forEach(function(e){const n=l[e];n&&(a.length?$(n).insertBefore(a):t.append(n),n.classList.toggle("kgrid-user-hidden",!!i[e]))})},e.applyLayoutToDom=function(t,n,o){if(!t||!t.length)return;t.find(".thead-labels tr, .thead-filters tr, .before-main-tbody tr, .main-tbody tr, .after-main-tbody tr").each(function(){e.applyLayoutToRow($(this),n)});const r=e.layoutVisibleColumns(n),i=t.find(".kgrid-row-actions").length>0;e.syncActionColumnColgroup(t,r.length,i,o,r),e.syncSpanningCells(t,e.participatingColumnCount(n,i))},e.refreshCollectionTemplate=function(t,n){if(!t||!t.instance||"function"!=typeof e.fillDataRow)return;const o=e.getKViews(n&&n.kviews);if(!o||"function"!=typeof o.template)return;const r=$("<tr>");n.dataRowAttrs&&e.isPlainObject(n.dataRowAttrs)&&Object.keys(n.dataRowAttrs).forEach(function(e){r.attr(e,n.dataRowAttrs[e])}),e.fillDataRow(r,n);const i=$("<div>").append(r).html(),a=o.template(i);t.instance.template=a,(t.instance.items||[]).forEach(function(e){(e.views||[]).forEach(function(e){e.template=a})})},e.setupFilterPersistence=function(t,n){t&&n&&n.storageKey&&n.features&&n.features.filtering&&$(t).off("submit.kgridFilterPrefs").on("submit.kgridFilterPrefs",function(){e.preferencesSaveFilters(n,e.readUserFilters(t,n.columns))})},e.applyColumnLayout=function(t,n,o){n.columns=e.mergeLayoutIntoColumns(n.columns,o);const r=t.$host.find("table").first();if(e.applyLayoutToDom(r,n.columns,n),e.refreshCollectionTemplate(t,n),"function"==typeof e.renderColumnChooserPanel){const o=t.$host.find(".kgrid-column-chooser-panel");o.length&&e.renderColumnChooserPanel(o,n,t)}return e.layoutFromColumns(n.columns)}}(window.KGrid),function(e){function t(t){const n=[];return t.find(".kgrid-column-chooser-list li[data-name]").each(function(){const e=this.getAttribute("data-name"),t=$(this).find("input[type='checkbox']").prop("checked");n.push({name:e,hidden:!t})}),{v:e.PREFERENCES_VERSION,columns:n}}e.renderColumnChooserPanel=function(n,o,r){n.empty();const i=$("<ul>").addClass("kgrid-column-chooser-list").appendTo(n);e.chooserColumns(o.columns).forEach(function(e){const t=$("<li>").attr("draggable","true").attr("data-name",e.name).appendTo(i);$("<span>").addClass("kgrid-column-chooser-handle").attr("aria-hidden","true").text("⋮⋮").appendTo(t);const n=$("<label>").appendTo(t),o=$("<input>").attr("type","checkbox").prop("checked",!e.userHidden).appendTo(n);e.locked&&o.prop("disabled",!0).attr("title","This column cannot be hidden"),n.append(document.createTextNode(" "+(e.label||e.name)))}),$("<button>").attr("type","button").addClass("btn btn-sm btn-outline-secondary kgrid-column-chooser-reset").text(o.columnChooserResetLabel||"Reset columns").appendTo(n),n.off("change.kgridChooser").on("change.kgridChooser","input[type='checkbox']",function(){const e=t(n);(function(e){return e.columns.filter(function(e){return!e.hidden}).length})(e)<1?this.checked=!0:r.setLayout(e)}),n.off("click.kgridChooserReset").on("click.kgridChooserReset",".kgrid-column-chooser-reset",function(){r.resetLayout()});let a=null;i.off(".kgridChooserDrag"),i.on("dragstart.kgridChooserDrag","li",function(e){a=this,$(this).addClass("kgrid-column-chooser-dragging"),e.originalEvent&&e.originalEvent.dataTransfer&&(e.originalEvent.dataTransfer.effectAllowed="move",e.originalEvent.dataTransfer.setData("text/plain",this.getAttribute("data-name")))}),i.on("dragend.kgridChooserDrag","li",function(){$(this).removeClass("kgrid-column-chooser-dragging"),a=null}),i.on("dragover.kgridChooserDrag","li",function(e){if(e.preventDefault(),!a||a===this)return;const t=this.getBoundingClientRect(),n=t.top+t.height/2;(e.originalEvent?e.originalEvent.clientY:0)<n?this.parentNode.insertBefore(a,this):this.parentNode.insertBefore(a,this.nextSibling)}),i.on("drop.kgridChooserDrag","li",function(e){e.preventDefault(),r.setLayout(t(n))})},e.setupColumnChooser=function(t,n,o){if(!n.features||!n.features.columnChooser)return;const r=e.getTableInteractionHost(t);r.find(".kgrid-column-chooser").remove();const i=r.find(".thead-labels th.kgrid-row-actions").first();if(!i.length)return;r.attr("data-has-column-chooser","true");const a=n.columnChooserLabel||"Columns",l=$("<div>").addClass("kgrid-column-chooser"),s=$("<button>").attr("type","button").addClass("kgrid-column-chooser-toggle btn btn-sm btn-outline-secondary").attr("title",a).attr("aria-label",a).attr("aria-expanded","false").attr("aria-haspopup","true").html('<i class="fas fa-cog" aria-hidden="true"></i>'),c=$("<div>").addClass("kgrid-column-chooser-panel").attr("hidden","hidden");function u(){const e=s[0].getBoundingClientRect();c.css({position:"fixed",top:Math.round(e.bottom+2)+"px",left:"auto",right:Math.round(window.innerWidth-e.right)+"px",zIndex:1055})}function d(){c.attr("hidden","hidden"),s.attr("aria-expanded","false"),c.css({top:"",left:"",right:"",position:"",zIndex:""})}l.append(s,c),i.append(l),e.renderColumnChooserPanel(c,n,o),s.on("click",function(e){e.stopPropagation(),c.attr("hidden")?(c.removeAttr("hidden"),s.attr("aria-expanded","true"),u()):d()});const f="kgridChooser"+e.uuid();$(window).on("scroll."+f+" resize."+f,function(){c.attr("hidden")||u()}),$(document).on("pointerdown."+f,function(e){if(!document.body.contains(l[0]))return $(document).off("."+f),void $(window).off("."+f);l[0].contains(e.target)||d()})}}(window.KGrid),function(e){e.SELECTION_COLUMN_NAME="__select",e.selectionEnabled=function(e){return!!(e&&e.features&&e.features.selection)},e.installSelectionColumn=function(t){if(!e.selectionEnabled(t))return t;if(t.columns=t.columns||[],t.columns.some(function(e){return e&&e.selection}))return t;const n=t.selectionRowLabel||"Select row";return t.columns.unshift({name:e.SELECTION_COLUMN_NAME,label:"",selection:!0,locked:!0,class:"kgrid-select",attrs:{width:40},features:{create:!1,update:!1,filter:!1,sort:!1},display:{template:'<input type="checkbox" class="form-check-input kgrid-select-row" aria-label="'+n+'">',events:[]}}),t.selectedRows||(t.selectedRows=new Map),t},e.selectionId=function(e){return e?null!=e.id&&""!==e.id?String(e.id):e.attributes&&null!=e.attributes.id&&""!==e.attributes.id?String(e.attributes.id):"":""},e.selectionItem=function(e){if(!e||!e.length)return null;const t=e.data("instance");if(t&&(null!=t.id||t.attributes))return t;return e.find("[data-type=item]").first().data("instance")||null},e.visibleSelectionRows=function(e){return e.find("tbody.main-tbody > tr").filter(function(){return $(this).find(".cell-content .kgrid-select-row").length>0})},e.selectionRecord=function(t,n,o){const r={id:e.selectionId(n)},i=t.selection&&t.selection.meta;if("function"==typeof i){const e=i(n,o);e&&"object"==typeof e&&Object.keys(e).forEach(function(t){"id"!==t&&(r[t]=e[t])})}return r},e.selectionApply=function(t,n,o,r){const i=r||e.selectionItem(n),a=e.selectionId(i);if(!a)return;const l=t.selectedRows;o?l.set(a,e.selectionRecord(t,i,n)):l.delete(a),n.find(".kgrid-select-row").prop("checked",!!o)},e.paintSelectionToggle=function(t){const n=e.visibleSelectionRows(t);let o=0,r=0;n.each(function(){o+=1,$(this).find(".cell-content .kgrid-select-row").prop("checked")&&(r+=1)}),t.find(".kgrid-select-all").each(function(){this.checked=o>0&&r===o,this.indeterminate=r>0&&r<o})},e.syncSelectionDom=function(t,n){const o=t.selectedRows;e.visibleSelectionRows(n).each(function(){const t=$(this),n=e.selectionId(e.selectionItem(t));t.find(".kgrid-select-row").prop("checked",!(!n||!o.has(n)))}),e.paintSelectionToggle(n)},e.toggleSelection=function(t,n,o){const r=e.visibleSelectionRows(n);let i=o;if("boolean"!=typeof i){let e=0,t=0;r.each(function(){e+=1,$(this).find(".cell-content .kgrid-select-row").prop("checked")&&(t+=1)}),i=!(e>0&&t===e)}return r.each(function(){e.selectionApply(t,$(this),i)}),e.paintSelectionToggle(n),i},e.bindSelectionRow=function(t,n,o,r){if(!e.selectionEnabled(r)||!n||!n.el)return;const i=n.el,a=$(o);i.find(".kgrid-select-row").off("change.kgridSelect").on("change.kgridSelect",function(){e.selectionApply(r,i,this.checked,t),e.paintSelectionToggle(a)});const l=e.selectionId(t),s=!!(l&&r.selectedRows&&r.selectedRows.has(l));i.find(".kgrid-select-row").prop("checked",s),s&&r.selectedRows.set(l,e.selectionRecord(r,t,i)),e.paintSelectionToggle(a)},e.bindSelection=function(t,n,o){return n.selectedRows||(n.selectedRows=new Map),t.selected=n.selectedRows,t.getSelection=function(){return Array.from(n.selectedRows.values())},t.clearSelection=function(){return n.selectedRows.clear(),e.syncSelectionDom(n,o),t},t.toggleAll=function(r){return e.toggleSelection(n,o,r),t.getSelection()},t.syncSelection=function(){return e.syncSelectionDom(n,o),t},o.find(".kgrid-select-all").off("change.kgridSelect").on("change.kgridSelect",function(){e.toggleSelection(n,o,this.checked)}),t}}(window.KGrid),function(e){e.init=async function(t,n){const o=e.resolveHostElement(t),r={...e.protoOptions,...n},i=e.mountTableShell(o,r);e.log("table config options",r);const a=e.resolveDefaultInteraction(r);e.applyInteraction(o,a);const l={$host:o,instance:null,filterForm:null,find:e=>o.find(e),setInteraction:(t,n)=>(e.applyInteraction(o,t,n),l),getInteraction:()=>"edit"===e.getTableInteractionHost(o).attr("data-interaction")?"edit":"view",setEditMode(e){if("boolean"!=typeof e)throw new TypeError("setEditMode(editMode) expects a boolean (true = edit, false = view)");return l.setInteraction(e?"edit":"view")},toggleEditMode:e=>(null!=e&&"object"==typeof e&&"function"==typeof e.preventDefault&&(e=void 0),"boolean"==typeof e?l.setInteraction(e?"edit":"view"):l.setInteraction("edit"===l.getInteraction()?"view":"edit")),getLayout:()=>e.layoutFromColumns(r.columns),setLayout:t=>(e.applyColumnLayout(l,r,t),e.preferencesSaveLayout(r,l.getLayout()),l.getLayout()),resetLayout(){const t=new Map;return r.columns.forEach(function(e){e&&e.name&&t.set(e.name,e)}),r.columns=s.map(function(e){return t.get(e)}).filter(Boolean),e.preferencesSaveLayout(r,null),e.applyColumnLayout(l,r,null),l.getLayout()}};e.installSelectionColumn(r),r.columns=(r.columns||[]).map(t=>e.normalizeColumnConfig(t));const s=r.columns.map(function(e){return e.name});r.columns=e.mergeLayoutIntoColumns(r.columns,e.preferencesLoadLayout(r));const c=r.handlers??{};if(delete r.handlers,"string"==typeof r.onClone){const e=c[r.onClone]||r.functions&&r.functions[r.onClone];if(!e||"function"!=typeof e)throw new Error("onClone handler "+r.onClone+" not found or is not a function");r.onClone=e}e.resolveRowActions(r,c);{const t=r._resolvedRowActions;e.getTableInteractionHost(o).attr("data-has-row-menu",t&&t.menuItems&&t.menuItems.length?"true":"false")}r.columns.forEach(e=>{["insert","update","display"].forEach(t=>{const n=e[t].events;if(!n||!Array.isArray(n))throw new Error("Column "+e.name+" events are not an array");n.forEach(t=>{if("string"==typeof t.callback){const n=c[t.callback]||r.functions&&r.functions[t.callback];if(!n||"function"!=typeof n)throw new Error("Event callback function "+t.callback+" not found for column "+e.name+" or is not a function");t.callback=n}else if("function"!=typeof t.callback)throw new Error("Event callback must be a function for column "+e.name)})});const t=e.display;t&&t.events&&Array.isArray(t.events)&&t.events.forEach(e=>{if("string"==typeof e.callback){const t=c[e.callback]||r.functions&&r.functions[e.callback];t&&"function"==typeof t&&(e.callback=t)}})});const u=new Map;r.columns.forEach(e=>{u.set(e.name,e)});const d=e.setupLabelsHeader(i.find(".thead-labels"),r),f=e.hasActionColumn(r),p=e.layoutVisibleColumns(r.columns),m=e.participatingColumnCount(r.columns,f);e.syncActionColumnColgroup(i,p.length,f,r,p);const g=r.filterForm??e.setupFilterHeader(i,r);let h;const y=r.storageKey&&r.features&&(r.features.sorting||r.features.paging)?e.preferencesLoadView(r):null;r.features&&r.features.paging?(h=e.setupPagingFooter(i.find(".paging-footer"),r,m),y&&e.applySavedPageSize(h,r,y.pageSize)):(h=null,i.find(".paging-footer").remove());const b=e.setupNoDataTbody(i.find(".no-data-tbody"),r,m);r.features&&r.features.create&&e.setupNewRecordForm(i,r,l),l.filterForm=new e.FilterForm(g);const w=e.setupDataBody(i.find(".main-tbody"),r,d,g,h,b),v={dontload:!0,setAttrAsId:r.setAttrAsId??!1,itemListeners:{afterrender:t=>e.setupEvents(t,l.find("table"),r,u)}},C=e.getKViews(r.kviews);if(!C)throw new Error(e.KVIEWS_MISSING_MSG);if(l.instance=await C.createCollectionInstance(w,v),r.url){l.instance.setUrl(r.url),r.deleteUrl&&(e.log("set deleteUrl",r.deleteUrl),l.instance.setUrl(r.deleteUrl,"delete")),r.updateUrl&&(e.log("set updateUrl",r.updateUrl),l.instance.setUrl(r.updateUrl,"update"));const t=r.insertUrl||r.url,n=r.onDuplicate?e.applyOnDuplicateToUrl(t,r.onDuplicate):r.insertUrl;n&&l.instance.setUrl(n,"insert"),y&&r.features&&r.features.sorting&&e.applySavedSort(l.instance,r,y),y&&r.features&&r.features.paging&&e.applySavedOffset(l.instance,y.offset)}r.features&&r.features.sorting&&e.syncSortIndicators(i,e.collectionSort(l.instance)),e.bindViewPersistence(l.instance,r,i),e.setupDefaultFilters(g,r,l.instance,{skipInitSubmit:!0});const S=g&&(g.jquery?g[0]:g);if(e.applyUserFilters(S,r.columns,e.preferencesLoadFilters(r)),e.ensureUrlFiltersOnForm(S,l.instance),e.setupFilterPersistence(S,r),e.setupColumnChooser(o,r,l),e.selectionEnabled(r)&&e.bindSelection(l,r,i),r.url)try{r.features&&r.features.filtering&&S&&e.syncFormFiltersToCollectionUrl(S,l.instance),await l.instance.loadFromRemote()}catch(t){e.onError(t)}else{if(!r.data||r.data.constructor!==Array)throw new Error("Invalid data: missing datasource url or data for table");{const e=r.data.map(e=>({attributes:e}));l.instance.loadFromData(e)}}return l}}(window.KGrid);
1
+ /*! @logimaxx/kgrid | (c) Logimaxx System SRL — proprietary | https://logimaxx.ro | built 2026-11-17T14:32:51.460Z */
2
+ !function(e){function t(e){const t={},n=e&&e.elements;if(!n)return t;for(let e=0;e<n.length;e++){const o=n[e],r=o.name;if(!r||o.disabled)continue;const i=o.type;if("submit"===i||"button"===i||"reset"===i||"file"===i)continue;if("checkbox"===i){t[r]=o.checked?"1":"0";continue}if("radio"===i){if(!o.checked)continue;t[r]=o.value;continue}if("SELECT"===o.tagName&&o.multiple){t[r]=Array.from(o.selectedOptions).map(function(e){return e.value});continue}const a=o.value;Object.prototype.hasOwnProperty.call(t,r)?(Array.isArray(t[r])||(t[r]=[t[r]]),t[r].push(a)):t[r]=a}return t}e.isFlagOn=function(e){return!0===e||1===e||"1"===e},e.serializeFormDefault=t;const n={log:function(){},onError:function(e){console.error(e)},confirm:function(e,t,n){"undefined"!=typeof window&&window.confirm(e)?t():n&&n()},deleteConfirm:null,serializeForm:t,customInputTypes:null,fieldTypes:null,kviews:null,filterDebounceMs:300,preferencesStorage:null};e._config=Object.assign({},n),e.configure=function(t){return t&&"object"==typeof t&&Object.assign(e._config,t),"function"==typeof e._syncCustomInputTypes&&e._syncCustomInputTypes(),e},e.log=function(){e._config.log.apply(null,arguments)},e.onError=function(t){return e._config.onError(t)},e.confirm=function(t,n,o){return e._config.confirm(t,n,o)},e.DEFAULT_DELETE_CONFIRM_MESSAGE="Delete this record?",e._defaultDeleteConfirm=function(t,n,o){e.confirm(e.DEFAULT_DELETE_CONFIRM_MESSAGE,n,o)},e.runDeleteConfirm=function(t,n,o){const r=t.options&&"function"==typeof t.options.deleteConfirm?t.options.deleteConfirm:null,i="function"==typeof e._config.deleteConfirm?e._config.deleteConfirm:null;return(r||i||e._defaultDeleteConfirm)(t,n,o)},e.serializeForm=function(t,n){return e._config.serializeForm(t,n)},e.getKViews=function(t){const n=[t,e._config.kviews];for(let e=0;e<n.length;e++){const t=n[e];if(t&&"function"==typeof t.createCollectionInstance)return t}const o=("undefined"!=typeof window?window:"undefined"!=typeof globalThis?globalThis:{}).KViews;return o&&"function"==typeof o.createCollectionInstance?o:null},e.KVIEWS_MISSING_MSG="KGrid requires KViews: install peer @logimaxx/kviews, load it before kgrid.js (window.KViews), or call KGrid.configure({ kviews: KViews }). You can also pass kviews in table options: KGrid.init(host, { kviews, ... })."}(window.KGrid=window.KGrid||{}),function(e){e.protoOptions={url:null,type:null,filter:null,features:{filtering:!1,sorting:!1,paging:!1,create:!1,update:!1,delete:!1,clone:!1,columnChooser:!1,csvExport:!1,selection:!1},selection:null,selectionAllLabel:"Toggle all",selectionRowLabel:"Select row",rowActions:null,storageKey:null,filterStorageScope:null,columnChooserLabel:"Columns",columnChooserResetLabel:"Reset columns",csvExportVisibleLabel:"Export CSV — visible fields",csvExportAllLabel:"Export CSV — all fields",csvExportLimit:1e4,defaultInteraction:"view",insertFormRow:{position:"top"},onDuplicate:null,tableAttrs:{class:""},labelsRowAttrs:{},dataRowAttrs:{},filtersRowAttrs:null,pagingPageSizes:[10,25,50,75],pagingDefaultSize:10,emptyRowMessage:null,pagingFooterLabel:"records per page. Total"},e.protoColumnConfig={label:null,name:null,hidden:!1,locked:!1,defaultHidden:!1,userHidden:!1,export:!0,class:null,columnClass:null,attrs:{},features:{create:!1,update:!1,filter:!1,sort:!1},display:{template:null,events:[]},input:null,insert:{type:"text",default:null,value:null,placeholder:null,disabled:!1,required:!1,options:null,events:[]},update:{type:"text",default:null,value:null,placeholder:null,disabled:!1,required:!1,options:null,template:null,events:[]},filter:{type:"text",operator:"~=~",default:null,placeholder:"",options:null,persist:!1,debounceMs:null}},e.VALID_NATIVE_INPUT_TYPES=["displayonly","text","textarea","number","date","datetime","time","checkbox","radio","file","password","email","url","search","tel","select","hidden"],e.VALID_INPUT_TYPES=e.VALID_NATIVE_INPUT_TYPES.slice(),e.VALID_NATIVE_FILTER_TYPES=e.VALID_NATIVE_INPUT_TYPES.filter(e=>"displayonly"!==e),e.VALID_FILTER_TYPES=e.VALID_NATIVE_FILTER_TYPES.concat(["multi_select","date_range"]),e.isValidInputType=function(t){return e.VALID_NATIVE_INPUT_TYPES.includes(t)||e.isPluggableFieldType(t)},e.isValidFilterType=function(t){return"displayonly"!==t&&(e.VALID_NATIVE_FILTER_TYPES.includes(t)||e.isPluggableFieldType(t))}}(window.KGrid=window.KGrid||{}),function(e){e.isPlainObject=function(e){return null!=e&&"object"==typeof e&&!Array.isArray(e)},e.setDefaultValues=function(t,n){const o={...t||{}};return Object.keys(n||{}).forEach(t=>{e.isPlainObject(n[t])&&e.isPlainObject(o[t])?o[t]=e.setDefaultValues(o[t],n[t]):e.isPlainObject(n[t])&&null==o[t]?o[t]=e.setDefaultValues({},n[t]):o[t]=n[t]}),o},e.normalizeColumnConfig=function(t){let n=t&&"object"==typeof t?{...t}:{};if(e.isPlainObject(n.input)){const t={...n.input};delete n.input,n.insert=e.setDefaultValues(t,n.insert||{}),n.update=e.setDefaultValues(t,n.update||{})}const o=e.setDefaultValues(e.protoColumnConfig,n);return null==o.class&&o.columnClass&&(o.class=o.columnClass),o.update&&"displayonly"===o.update.type&&!o.update.template&&o.display&&o.display.template&&(o.update.template=o.display.template),["display","insert","update"].forEach(e=>{o[e]&&"object"==typeof o[e]&&(Array.isArray(o[e].events)||(o[e].events=[]))}),o};const t=["error","ignore","update"],n=["set","add","sub"];function o(e,t){const o=String(e||"").trim(),r=null==t||""===t?"set":String(t).trim();if(!/^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)?$/.test(o))throw new Error("Invalid onDuplicate field: "+e);if(-1===n.indexOf(r))throw new Error("Invalid onDuplicate operator '"+r+"' on field '"+o+"'");return{name:o,op:r}}function r(e){const t=String(e||"").trim(),n=t.lastIndexOf(":");return-1===n?o(t,"set"):o(t.slice(0,n),t.slice(n+1))}e.onDuplicateParams=function(n){if(null==n||!1===n)return null;let i,a;if("string"==typeof n)i=n.trim();else{if(!e.isPlainObject(n))throw new Error("onDuplicate must be a string or an object");i=String(n.action||n.onduplicate||"").trim(),a=null!=n.fields?n.fields:n.update}if(-1===t.indexOf(i))throw new Error("Invalid onDuplicate action: "+i);const l={onduplicate:i};if("update"!==i)return l;const s=[],c={},u=function(e){if(c[e.name])throw new Error("onDuplicate field '"+e.name+"' is listed more than once");c[e.name]=!0,s.push("set"===e.op?e.name:e.name+":"+e.op)};if("string"==typeof a)a.split(",").forEach(function(e){e.trim()&&u(r(e))});else if(Array.isArray(a))a.forEach(function(e){u(r(e))});else if(e.isPlainObject(a))Object.keys(a).forEach(function(e){u(o(e,a[e]))});else if(null!=a)throw new Error("onDuplicate fields must be an object, array, or string");if(!s.length)throw new Error("onDuplicate action 'update' requires fields");return l.update=s.join(","),l},e.applyOnDuplicateToUrl=function(t,n){const o=e.onDuplicateParams(n);if(!o||!t)return t;const r=t.indexOf("#"),i=r>=0?t.slice(r):"",a=r>=0?t.slice(0,r):t,l=a.indexOf("?"),s=l>=0?a.slice(0,l):a,c=[];return l>=0&&a.slice(l+1).split("&").forEach(function(e){if(!e)return;const t=e.indexOf("="),n=decodeURIComponent(t>=0?e.slice(0,t):e);"onduplicate"!==n&&"update"!==n&&c.push(e)}),Object.keys(o).forEach(function(e){c.push(encodeURIComponent(e)+"="+encodeURIComponent(o[e]))}),s+(c.length?"?"+c.join("&"):"")+i}}(window.KGrid),function(e){e.resolveHostElement=function(e){if(null==e)throw new TypeError("KGrid.init(host, opts): host is required");if("object"==typeof e&&e.jquery){if(!e.length)throw new Error("KGrid.init(host, opts): empty jQuery selection");return e}if("object"==typeof e&&1===e.nodeType&&"string"==typeof e.nodeName)return $(e);throw new TypeError("KGrid.init(host, opts): host must be a DOM Element or jQuery object")},e.uuid=function(){return Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)},e.columnWidthCss=function(e){if(!e||!e.attrs)return null;const t=e.attrs.width;return null==t||""===t?null:"number"==typeof t||/^\d+(\.\d+)?$/.test(String(t))?String(t)+"px":String(t)},e.applyColumnDomAttrs=function(e,t){const n=t&&t.attrs&&"object"==typeof t.attrs?t.attrs:null;return n?(Object.keys(n).forEach(function(t){"width"!==t&&e.attr(t,n[t])}),e):e},e.layoutVisibleColumns=function(e){return(e||[]).filter(function(e){return e&&e.name&&!e.hidden&&!e.userHidden})},e.participatingColumnCount=function(t,n){return e.layoutVisibleColumns(t).length+(n?1:0)},e.syncActionColumnColgroup=function(t,n,o,r,i){let a=t.children("colgroup.kgrid-colgroup");a.length||(a=$("<colgroup>").addClass("kgrid-colgroup").prependTo(t)),a.empty();const l=Array.isArray(i)?i:null;let s=0;if(l&&l.length)l.forEach(function(t){if(t&&t.userHidden)return;const n=$("<col>");t&&t.name&&n.attr("data-name",t.name);const o=e.columnWidthCss(t);o&&n.css("width",o),a.append(n),s+=1});else for(let e=0;e<n;e++)a.append($("<col>")),s+=1;return o&&a.append($("<col>").addClass("kgrid-row-actions-col").css("width",e.actionColumnWidth(r))),s},e.syncSpanningCells=function(e,t){e&&e.length&&t&&e.find(".paging-footer td, .no-data-tbody td").attr("colspan",t)},e.anchorRowForm=function(e,t){if(!(e&&e.length&&t&&t.length))return e;e.attr("hidden","hidden").attr("aria-hidden","true");const n=t.children("td").first();return n.length&&e.prependTo(n),e},e.filterFormField=function(t,n){const o=e.filterFormFields(t,n);return o.length?o.eq(0):$()},e.filterFormFields=function(e,t){if(!e||!t)return $();const n=[],o=e.elements;if(o)for(let e=0;e<o.length;e++)o[e]&&o[e].name===t&&n.push(o[e]);if(!n.length&&e.id){const o=document.querySelectorAll('[form="'+e.id+'"][name="'+t+'"]');for(let e=0;e<o.length;e++)n.push(o[e])}return $(n)},e.columnClassName=function(e){if(!e)return null;const t=null!=e.class&&""!==e.class?e.class:e.columnClass;return null!=t&&""!==t?String(t):null},e.applyColumnCellMeta=function(t,n){if(!t||!t.length||!n)return t;n.name&&t.attr("data-name",n.name);const o=e.columnClassName(n);return o&&t.addClass(o),t.toggleClass("kgrid-user-hidden",!!n.userHidden),t}}(window.KGrid),function(e){function t(e){"undefined"!=typeof console&&"function"==typeof console.warn&&console.warn(e)}function n(e){return e?"<i class='"+e+"'></i>":""}function o(e,t,o){const r=$("<button>").addClass(t.btnClass||"btn btn-sm btn-outline-secondary").attr("type","save"===t.action?"submit":"button").attr("title",t.title||t.label||"");return t.class&&r.addClass(t.class),"save"!==t.action&&"cancel"!==t.action||(r.attr("name","save"===t.action?"save":"cancel"),o&&r.attr("form",o)),"cancel"===t.action&&r.attr("onclick","$(this).parents('[data-type=item]').data().instance.loadFromRemote()"),t.id&&r.attr("data-kgrid-action",t.id),t.action&&r.attr("data-kgrid-builtin",t.action),t.icon?(r.html(n(t.icon)),t.showLabel&&t.label&&r.append(document.createTextNode(" "+t.label))):t.label&&r.text(t.label),r.appendTo(e),r}function r(e,t,n){const o=n.indexOf(t);o<0||(e.attr("data-kgrid-action-index",String(o)),null!=t.visible&&e.addClass("kgrid-action-conditional kgrid-action-off"))}e.BUILTIN_ROW_ACTIONS={clone:{action:"clone",icon:"fa-regular fa-copy",label:"Clone",title:"Clone item",when:"idle",btnClass:"btn btn-sm btn-outline-secondary clone-item",groupClass:"clone-item-grp"},delete:{action:"delete",icon:"fas fa-trash",label:"Delete",title:"Delete item",when:"idle",btnClass:"btn btn-sm btn-danger delete-item",groupClass:"delete-item-grp"},save:{action:"save",icon:"fas fa-save",label:"Save",title:"Save item",when:"editing",btnClass:"btn btn-sm btn-success save-item",groupClass:"edit-item-grp"},cancel:{action:"cancel",icon:"fas fa-undo",label:"Cancel",title:"Cancel edit",when:"editing",btnClass:"btn btn-sm btn-secondary cancel-edit",groupClass:"edit-item-grp"}},e.normalizeRowActionItem=function(n,o,r){if(!n||"object"!=typeof n)return null;const i=n.action;if("save"===i||"cancel"===i)return t("KGrid: rowActions items should not list '"+i+"' — it is added automatically when features.update is true"),null;let a={};if(i&&e.BUILTIN_ROW_ACTIONS[i])a={...e.BUILTIN_ROW_ACTIONS[i]};else{if(!n.id)return t("KGrid: custom rowAction requires id: "+JSON.stringify(n)),null;a={id:n.id,when:"idle",btnClass:"btn btn-sm btn-outline-secondary",groupClass:"kgrid-custom-action-grp"}}const l={...a,...n};if(i&&e.BUILTIN_ROW_ACTIONS[i]&&(l.action=i),l.when||(l.when=l.action&&a.when||"idle"),!l.title&&l.label&&(l.title=l.label),!l.label&&l.title&&(l.label=l.title),"string"==typeof l.callback){const e=function(e,t,n){if(!e||"string"!=typeof e)return null;const o=t&&t[e]||n.functions&&n.functions[e];return"function"==typeof o?o:null}(l.callback,o,r);if(!e)throw new Error("rowAction callback "+l.callback+" not found or is not a function");l.callback=e}if(l.id&&"function"!=typeof l.callback&&!l.action)throw new Error("Custom rowAction '"+l.id+"' requires a callback");return l},e.rowActionVisible=function(e,t){if(null==t)return!0;if("function"==typeof t)return!!t(e);if(!t||"object"!=typeof t||Array.isArray(t))return!0;const n=e&&e.attributes||{};return Object.keys(t).every(function(e){const o=t[e],r=n[e];return Array.isArray(o)?o.some(function(e){return String(r??"")===String(e)}):String(r??"")===String(o)})},e.resolveRowActions=function(n,o){if(n&&n._resolvedRowActions&&arguments.length<2)return n._resolvedRowActions;const r=n&&n.features||{};let i="buttons",a=[];if(n&&null!=n.rowActions){const o=n.rowActions;Array.isArray(o)?a=o:e.isPlainObject(o)&&(i="dropdown"===o.display?"dropdown":"buttons",a=Array.isArray(o.items)?o.items:[]),(r.delete||r.clone)&&t("KGrid: features.delete / features.clone are ignored when rowActions is set")}else r.clone&&a.push({action:"clone"}),r.delete&&a.push({action:"delete"});const l=[];a.forEach(function(t){const r=e.normalizeRowActionItem(t,o,n||{});r&&l.push(r)});const s=[];r.update&&(s.push({...e.BUILTIN_ROW_ACTIONS.save}),s.push({...e.BUILTIN_ROW_ACTIONS.cancel}));const c={display:i,menuItems:l,editingItems:s};return n&&(n._resolvedRowActions=c),c},e.hasActionColumn=function(t){const n=t&&t.features;if(n&&(n.create||n.columnChooser||n.csvExport))return!0;const o=e.resolveRowActions(t);return o.menuItems.length>0||o.editingItems.length>0},e.actionColumnWidth=function(t){const n=e.resolveRowActions(t),o=t&&t.features||{},r=n.editingItems.length,i=o.create?1:0;let a;a="dropdown"===n.display&&n.menuItems.length>0?1:n.menuItems.filter(function(e){return"editing"!==e.when}).length;return(2.5*Math.max(a,r,i,1)+.75).toFixed(2)+"rem"},e.closeRowActionDropdowns=function(e){$(".kgrid-row-actions-menu").each(function(){const t=$(this),n=t.children(".dropdown-menu");e&&n[0]===e[0]||(n.removeClass("show").css({top:"",left:"",right:"",position:""}),t.children(".kgrid-actions-dropdown-toggle").attr("aria-expanded","false").removeClass("show"))})},e.mountRowActionDropdowns=function(t){t&&t.length&&(e._rowActionsDropdownDocBound||(e._rowActionsDropdownDocBound=!0,$(document).on("click.kgridRowActions",function(){e.closeRowActionDropdowns()}).on("keydown.kgridRowActions",function(t){"Escape"===t.key&&e.closeRowActionDropdowns()})),t.find(".kgrid-row-actions-menu > .kgrid-actions-dropdown-toggle").each(function(){const t=this,n=$(t),o=n.parent(".kgrid-row-actions-menu").children(".dropdown-menu");n.off("click.kgridRowActions").on("click.kgridRowActions",function(r){r.preventDefault(),r.stopPropagation();const i=!o.hasClass("show");if(e.closeRowActionDropdowns(),!i)return;const a=t.getBoundingClientRect();o.addClass("show").css({position:"fixed",top:Math.round(a.bottom+2)+"px",left:"auto",right:Math.round(window.innerWidth-a.right)+"px",zIndex:1055}),n.addClass("show").attr("aria-expanded","true")}),o.off("click.kgridRowActions").on("click.kgridRowActions",function(e){e.stopPropagation()}),o.find(".dropdown-item").off("click.kgridRowActionsClose").on("click.kgridRowActionsClose",function(){setTimeout(function(){e.closeRowActionDropdowns()},0)})}))},e.applyRowActionVisibility=function(t,n,o){t&&t.length&&o&&o.forEach(function(o,r){if(!o||null==o.visible)return;const i=e.rowActionVisible(n,o.visible);t.find('[data-kgrid-action-index="'+r+'"]').toggleClass("kgrid-action-off",!i)})},e.escapeHtml=e.escapeHtml||function(e){return String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},e.renderRowActions=function(t,i,a){const l=e.resolveRowActions(i),s=l.menuItems.filter(function(e){return"editing"!==e.when}),c=l.menuItems.filter(function(e){return"editing"===e.when});if("dropdown"===l.display&&s.length>0){const o=$("<div>").addClass("btn-group kgrid-row-actions-menu").appendTo(t);$("<button>").addClass("btn btn-sm btn-outline-secondary dropdown-toggle kgrid-actions-dropdown-toggle").attr({type:"button","aria-expanded":"false",title:"Actions"}).html("<i class='fas fa-ellipsis-v'></i>").appendTo(o);const i=$("<ul>").addClass("dropdown-menu dropdown-menu-end").appendTo(o);s.forEach(function(t){const o=$("<li>").appendTo(i);r(o,t,l.menuItems);const a=$("<button>").addClass("dropdown-item").attr("type","button").appendTo(o);"clone"===t.action?a.addClass("clone-item"):"delete"===t.action&&a.addClass("delete-item text-danger"),t.id&&a.attr("data-kgrid-action",t.id),t.action&&a.attr("data-kgrid-builtin",t.action),t.class&&a.addClass(t.class),t.btnClass&&!t.action&&/\bbtn-danger\b|\btext-danger\b|\boutline-danger\b/.test(t.btnClass)&&a.addClass("text-danger");const s=t.label||t.title||t.action||t.id;t.icon?a.html(n(t.icon)+" "+e.escapeHtml(s)):a.text(s)})}else s.forEach(function(e){const n=$("<span>").addClass(e.groupClass||"btn-group kgrid-custom-action-grp").appendTo(t);"always"===e.when&&n.addClass("kgrid-action-always"),r(n,e,l.menuItems),o(n,e,a)});const u=l.editingItems.concat(c);if(u.length){const e=$("<span>").addClass("btn-group edit-item-grp").appendTo(t);u.forEach(function(t){o(e,t,a)})}}}(window.KGrid),function(e){e.DEFAULT_EMPTY_ROW_MESSAGE="No records match your search.",e.TABLE_SHELL_TEMPLATE='\n<table class="custom-table" style="table-layout: fixed;">\n <thead class="thead-labels">\n <tr>\n <th class="align-top">\n <a class="sort" data-sortfld="" style="cursor: pointer;">\n <span class="column-label"></span>\n <i class="fas fa-sort-up sort-up" style="display: none"></i>\n <i class="fas fa-sort-down sort-down" style="display: none"></i>\n <i class="fas fa-sort sort-default"></i>\n </a>\n </th>\n </tr>\n </thead>\n <thead class="thead-filters"></thead>\n <tbody class="before-main-tbody"></tbody>\n <tbody class="main-tbody"></tbody>\n <tbody class="after-main-tbody"></tbody>\n <tbody class="no-data-tbody">\n <tr><td>{{EMPTY_ROW_MESSAGE}}</td></tr>\n </tbody>\n <tfoot class="paging-footer">\n <tr>\n <td>\n <div class="btn-group pages" data-pagesize="{{PAGES_DATA_PAGESIZE}}">\n <button type="button" name="first" class="btn btn-sm btn-outline-secondary">&lt;&lt;</button>\n <button type="button" name="prev" class="btn btn-sm btn-outline-secondary">&lt;</button>\n <button type="button" name="page" class="btn btn-sm btn-outline-secondary">1</button>\n <button type="button" name="next" class="btn btn-sm btn-outline-secondary">&gt;</button>\n <button type="button" name="last" class="btn btn-sm btn-outline-secondary">&gt;&gt;</button>\n </div>\n <select class="pagesize">\n{{PAGE_SIZE_OPTIONS}}\n </select>\n {{PAGING_FOOTER_LABEL}} <span class="totalrecscount"></span>\n </td>\n </tr>\n </tfoot>\n</table>'.trim(),e._escapeTableShellText=function(e){return String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},e._renderPageSizeOptions=function(e,t){return e.map(e=>{const n=String(e);return` <option value="${n}"${n===String(t)?" selected":""}>${n}</option>`}).join("\n")},e.renderTableShellHtml=function(t,n){const o=Array.isArray(t.pagingPageSizes)?t.pagingPageSizes:[10,25,50,75],r=null!=t.pagingDefaultSize?t.pagingDefaultSize:o[0],i=e._escapeTableShellText(t.emptyRowMessage||e.DEFAULT_EMPTY_ROW_MESSAGE),a=e._escapeTableShellText(t.pagingFooterLabel||"records per page. Total");return(n||e.TABLE_SHELL_TEMPLATE).replace(/\{\{EMPTY_ROW_MESSAGE\}\}/g,i).replace(/\{\{PAGES_DATA_PAGESIZE\}\}/g,String(r)).replace(/\{\{PAGE_SIZE_OPTIONS\}\}/g,e._renderPageSizeOptions(o,r)).replace(/\{\{PAGING_FOOTER_LABEL\}\}/g,a)},e.createTableShell=function(t){const n=e.renderTableShellHtml(t),o=$.parseHTML(n,document,!0),r=$(o).filter("table").first();if(!r.length)throw new Error("KGrid TABLE_SHELL_TEMPLATE must contain a root <table> element");return t.tableAttrs&&e.isPlainObject(t.tableAttrs)&&(Object.keys(t.tableAttrs).forEach(e=>{"class"!==e&&r.attr(e,t.tableAttrs[e])}),"string"==typeof t.tableAttrs.class&&t.tableAttrs.class&&r.addClass(t.tableAttrs.class)),r},e.mountTableShell=function(t,n){const o=t.find("table.custom-table, table").first();if(o.length)return o;const r=e.getTableInteractionHost(t);r.hasClass("custom-table-shell")||r.addClass("custom-table-shell");const i=e.createTableShell(n);return r.append(i),i}}(window.KGrid),function(e){e._fieldTypes=Object.create(null),e._configuredCustomInputTypeNames=[],e.registerFieldType=function(t,n,o){if(!t||"string"!=typeof t)throw new TypeError("registerFieldType(name, plugin): name must be a string");if(!n||"function"!=typeof n.create)throw new TypeError("registerFieldType("+t+"): plugin.create is required");if(e._fieldTypes[t]&&(!o||!o.overwrite))throw new Error("Field type already registered: "+t);return e._fieldTypes[t]=Object.assign({name:t},n),e},e.unregisterFieldType=function(t){return t&&e._fieldTypes[t]&&delete e._fieldTypes[t],e},e.getFieldType=function(t){return t&&e._fieldTypes[t]||null},e.listFieldTypes=function(){return Object.keys(e._fieldTypes)},e.createFieldInput=function({mode:t,col:n,config:o}){const r=o.type??"text",i=e.getFieldType(r);if(!i)return null;"function"==typeof i.validate&&i.validate(o,t,n);const a=i.create({mode:t,col:n,config:o});if(!a||!a.$input||!a.$input.length)throw new Error('Field type "'+r+'" create() must return { $input: jQuery }');return a.$input.attr("data-type",r),a},e.mountField=function(t){const n=t.config?.type??t.type,o=e.getFieldType(n);o&&"function"==typeof o.mount&&o.mount(t)},e.resolveFilterEvents=function({plugin:e,$input:t,createResult:n}){let o;return n&&Object.prototype.hasOwnProperty.call(n,"filterEvents")?o=n.filterEvents:e&&Object.prototype.hasOwnProperty.call(e,"filterEvents")&&(o=e.filterEvents),!1===o||null===o?null:"string"==typeof o&&o.trim()?o.trim():t.is("select")?"change":"input"},e.normalizeFilterDebounceMs=function(e,t){if(!1===e)return 0;if(void 0===e)return t;if(null===e)return t;const n=Number(e);return!Number.isFinite(n)||n<0?0:n},e.resolveFilterDebounceMs=function({filterConfig:t,plugin:n}){return t&&Object.prototype.hasOwnProperty.call(t,"debounceMs")&&null!==t.debounceMs?e.normalizeFilterDebounceMs(t.debounceMs,0):n&&Object.prototype.hasOwnProperty.call(n,"filterDebounceMs")&&null!==n.filterDebounceMs?e.normalizeFilterDebounceMs(n.filterDebounceMs,0):e.normalizeFilterDebounceMs(e._config.filterDebounceMs,0)},e.shouldDebounceFilterSubmit=function(e,t){return!(!t||t<=0)&&!!e},e.bindFieldFilterSubmit=function(t,n,o){const r=e.getFieldType(t);r&&"function"==typeof r.bindFilterSubmit&&r.bindFilterSubmit(n,o)},e.bindFilterInputEvents=function({type:t,$input:n,onSubmit:o,createResult:r,filterConfig:i}){const a=t?e.getFieldType(t):null,l=e.resolveFilterEvents({plugin:a,$input:n,createResult:r}),s=e.resolveFilterDebounceMs({filterConfig:i,plugin:a}),c=e.wrapFilterSubmitHandler(n,o,l,s);l&&n.on(l,c),e.bindFieldFilterSubmit(t,n,c)},e.isPluggableFieldType=function(t){return!!e.getFieldType(t)},e.inputType=function(e,t){if("function"!=typeof e)throw new TypeError("inputType(mount, opts): mount must be a function");if(!t||"string"!=typeof t.element)throw new TypeError("inputType(mount, opts): opts.element is required (HTML string)");return{filterEvents:t.filterEvents,filterDebounceMs:t.filterDebounceMs,validate:t.validate,create({mode:e}){const n=$(t.element);return!t.formInputClass||"insert"!==e&&"update"!==e||n.addClass(t.formInputClass),{$input:n,skipValueAttr:!!t.skipValueAttr}},mount(t){e(t.$input,t.config?.options??t.config,t)},bindFilterSubmit:t.bindFilterSubmit}},e._getCustomInputTypesConfig=function(){return e._config.customInputTypes??e._config.fieldTypes??null},e._syncCustomInputTypes=function(){const t=e._getCustomInputTypesConfig(),n=t&&"object"==typeof t?Object.keys(t).filter(e=>null!=t[e]):[];e._configuredCustomInputTypeNames.forEach(t=>{n.includes(t)||e.unregisterFieldType(t)}),n.forEach(n=>{const o=t[n];if(!o||"object"!=typeof o||"function"!=typeof o.create){if("function"==typeof o)throw new Error("customInputTypes."+n+' is a function — use a plugin, e.g. KGrid.select2(fn) or KGrid.inputType(fn, { element: "..." })');throw new TypeError("customInputTypes."+n+" must be a plugin with create()")}e.registerFieldType(n,o,{overwrite:!0})}),e._configuredCustomInputTypeNames=n.slice()}}(window.KGrid),function(e){const t="kgrid-multi-select-value",n=";";function o(e,t,n){if(!e.length)return n;if(1===e.length){const n=t.find(function(t){return t.value===e[0]});return n?n.label:e[0]}return e.length+" selected"}function r(r,i,a){const l=i.separator||n,s=i.options||[],c=function(e){return null!=e.placeholder&&""!==e.placeholder?String(e.placeholder):"All"}(i),u="filter"===a;r.data("kgridMultiSep",l),r.addClass(t);const d=$("<div>").addClass("kgrid-multi-select").attr("data-mode",a),f=$("<div>").addClass("kgrid-multi-select-panel");let p=null;function m(){const t=e.parseMultiSelectValue(r[0].value,l);f.find("input[type='checkbox']").each(function(){this.checked=-1!==t.indexOf(this.value)}),p&&p.text(o(t,s,c))}function g(e){p&&(e?(f.appendTo(document.body),f.addClass("kgrid-multi-select-panel-floating"),f.removeAttr("hidden"),d.addClass("kgrid-multi-select-open"),p.attr("aria-expanded","true"),h()):(f.attr("hidden","hidden"),d.removeClass("kgrid-multi-select-open"),p.attr("aria-expanded","false"),f.css({position:"",top:"",left:"",width:"",minWidth:"",maxWidth:"",zIndex:""}),f.removeClass("kgrid-multi-select-panel-floating"),f.insertAfter(p)))}function h(){if(!p)return;const e=p[0].getBoundingClientRect(),t=Math.max(e.width,192);let n=e.left;const o=window.innerWidth-t-8;n>o&&(n=Math.max(8,o));let r=e.bottom+2;const i=Math.min(224,28*s.length+16);r+i>window.innerHeight-8&&e.top>i+8&&(r=e.top-i-2),f.css({position:"fixed",top:r+"px",left:n+"px",width:t+"px",minWidth:t+"px",maxWidth:"min(18rem, calc(100vw - 16px))",zIndex:1080})}u?(p=$("<button>").attr({type:"button","aria-expanded":"false"}).addClass("kgrid-multi-select-toggle form-select form-select-sm"),f.attr("hidden","hidden"),d.append(p,f)):(d.addClass("kgrid-multi-select-open"),d.append(f)),s.forEach(function(t,n){const o="kgrid_ms_"+e.uuid()+"_"+n,r=$("<label>").addClass("kgrid-multi-select-option").attr("for",o);$("<input>").attr({type:"checkbox",id:o,value:t.value,class:"kgrid-multi-select-check"}).appendTo(r),$("<span>").addClass("kgrid-multi-select-label").text(t.label).appendTo(r),f.append(r)}),r.before(d),d.append(r);const y=".kgridMultiSelect_"+e.uuid();f.on("change","input[type='checkbox']",function(){!function(e){const t=[];f.find("input[type='checkbox']:checked").each(function(){t.push(this.value)});const n=t.join(l);r[0].value!==n&&(r[0].value=n,e&&r.trigger("change")),p&&p.text(o(t,s,c))}(!0)}),r.on("kgrid:multiselect:set",function(){m()}),p&&(p.on("click",function(e){e.preventDefault(),e.stopPropagation(),g(!d.hasClass("kgrid-multi-select-open"))}),$(document).on("mousedown"+y,function(e){d.hasClass("kgrid-multi-select-open")&&($(e.target).closest(d).length||$(e.target).closest(f).length||g(!1))}),$(window).on("resize"+y+" scroll"+y,function(){d.hasClass("kgrid-multi-select-open")&&h()}));const b=function(){const e=r.prop("form")||r[0]&&r[0].form;e&&$(e).off("reset"+y).on("reset"+y,function(){setTimeout(m,0)})};return b(),setTimeout(b,0),m(),d}e.normalizeMultiSelectValue=function(e,t){const o=t||n;return null==e||""===e?"":Array.isArray(e)?e.filter(function(e){return null!=e&&""!==e}).map(String).join(o):String(e)},e.parseMultiSelectValue=function(t,o){const r=e.normalizeMultiSelectValue(t,o);return r?r.split(o||n).filter(Boolean):[]},function(){const o=$.valHooks.hidden||{};$.valHooks.hidden={get:function(e){return e&&e.classList&&e.classList.contains(t)?e.value:o.get?o.get(e):void 0},set:function(r,i){if(r&&r.classList&&r.classList.contains(t)){const t=$(r).data("kgridMultiSep")||n;return r.value=e.normalizeMultiSelectValue(i,t),$(r).triggerHandler("kgrid:multiselect:set"),!0}return o.set?o.set(r,i):void 0}}}(),e.registerFieldType("multi_select",{filterEvents:"change",filterDebounceMs:0,validate(e,t){!function(e,t){if(!Array.isArray(e.options))throw new Error("multi_select requires an options array ("+t+"): "+JSON.stringify(e,null,2));e.options.forEach(function(t){if(!t||"string"!=typeof t.label||"string"!=typeof t.value)throw new Error("multi_select options need string label and value: "+JSON.stringify(e,null,2))})}(e,t)},create({config:e}){const n=$("<input type='hidden'>").addClass(t);return e.separator&&n.data("kgridMultiSep",e.separator),{$input:n,skipValueAttr:!0}},mount(e){if(r(e.$input,e.config||{},e.mode),"update"===e.mode&&e.item&&e.col&&e.col.name){const t=e.item.attributes?e.item.attributes[e.col.name]:null;null!=t&&""!==t&&e.$input.val(t)}}});const i="kgrid-date-range-value";function a(e,t,n){const o=e&&e[t];return null!=o&&""!==o?String(o):n}e.dateRangeCalendarDate=function(e){if(null==e||""===e)return"";const t=/^(\d{4}-\d{2}-\d{2})/.exec(String(e).trim());return t?t[1]:""},e.dateRangeEndValue=function(e){return e?e+" 23:59:59":""},e.normalizeDateRangeDefault=function(t){if(null==t||"object"!=typeof t||Array.isArray(t))return{from:"",to:""};let n=e.dateRangeCalendarDate(t.from),o=e.dateRangeCalendarDate(t.to);return n&&o&&o<n&&(o=n),{from:n,to:o}},e.syncDateRangeVisible=function(t){if(!t||!t.getAttribute)return;const n=t.getAttribute("data-kgrid-date-range"),o=n&&t.ownerDocument.getElementById(n);if(!o)return;const r=t.ownerDocument.getElementById(n+"_panel");function i(e){return o.querySelector(e)||r&&r.querySelector(e)}const a=i("to"===t.getAttribute("data-kgrid-date-bound")?".kgrid-date-range-to":".kgrid-date-range-from");if(!a)return;const l=e.dateRangeCalendarDate(t.value);a.value!==l&&(a.value=l);const s=o.querySelector(".kgrid-date-range-display");if(!s)return;const c=i(".kgrid-date-range-from"),u=i(".kgrid-date-range-to"),d=function(e,t){function n(e){const t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e||"");return t?t[3]+"."+t[2]+"."+t[1]:""}const o=n(e),r=n(t);if(o&&r)return o+" – "+r;if(o)return o+" –";if(r)return"– "+r;return""}(c&&c.value,u&&u.value);s.value!==d&&(s.value=d);const f=o.querySelector(".kgrid-date-range-clear");f&&(d?(f.removeAttribute("hidden"),o.classList.add("kgrid-date-range-has-value")):(f.setAttribute("hidden","hidden"),o.classList.remove("kgrid-date-range-has-value")))},e.applyDateRangeDefault=function(t,n,o){const r=e.normalizeDateRangeDefault(o);if(!r.from&&!r.to)return;const i=e.filterFormFields(t,n);function a(e,t){if(!t)return;const n=i.filter(function(){return $(this).attr("data-operator")===e});n.length&&!n.val()&&(n.val(t),n[0]&&(n[0].defaultValue=n[0].value))}a(">=",r.from),a("<=",r.to)},function(){const t=$.valHooks.text||{};$.valHooks.text={get:function(e){return e&&e.classList&&e.classList.contains(i)?e.value:t.get?t.get(e):void 0},set:function(n,o){if(n&&n.classList&&n.classList.contains(i)){const t=e.dateRangeCalendarDate(o),r=n.getAttribute("data-kgrid-date-bound");return n.value="to"===r?e.dateRangeEndValue(t):t,e.syncDateRangeVisible(n),!0}return t.set?t.set(n,o):void 0}}}(),e.registerFieldType("date_range",{filterEvents:"change",filterDebounceMs:0,validate(e,t){if("filter"!==t)throw new Error("date_range is only valid as a filter")},create(){const e=$("<input type='text' autocomplete='off'>").addClass(i).attr("data-operator",">=").attr("data-kgrid-date-bound","from").attr("tabindex","-1").attr("aria-hidden","true"),t=$("<input type='text' autocomplete='off'>").addClass(i).attr("data-operator","<=").attr("data-kgrid-date-bound","to").attr("tabindex","-1").attr("aria-hidden","true");return e.data("kgridDateRangeTo",t),{$input:e,skipValueAttr:!0}},mount(t){!function(t,n){const o=t.data("kgridDateRangeTo"),r="kgrid_dr_"+e.uuid(),i=a(n,"fromLabel","From"),l=a(n,"toLabel","To"),s=n&&null!=n.placeholder&&""!==n.placeholder?String(n.placeholder):i+" – "+l,c=$("<div>",{class:"kgrid-date-range",id:r}),u=r+"_panel",d=$("<input type='text' readonly autocomplete='off' class='form-control form-control-sm kgrid-date-range-display'/>").attr("placeholder",s).attr("role","button").attr("aria-haspopup","dialog").attr("aria-expanded","false").attr("aria-controls",u),f=$("<button>",{type:"button",class:"kgrid-date-range-clear",hidden:"hidden","aria-label":"Clear",text:"×"}),p=$("<input autocomplete='off' type='date' class='form-control form-control-sm kgrid-date-range-from'/>"),m=$("<input autocomplete='off' type='date' class='form-control form-control-sm kgrid-date-range-to'/>"),g=$("<div>",{class:"kgrid-date-range-panel",id:u,hidden:"hidden",role:"dialog","aria-label":s});function h(e,n,r){e&&n&&n<e&&(n=e),p.val(e||""),m.val(n||""),t.val(e||""),o.val(n||""),r&&(t[0]&&(t[0].defaultValue=t[0].value),o[0]&&(o[0].defaultValue=o[0].value))}function y(e){e?(g.appendTo(document.body),g.addClass("kgrid-date-range-panel-floating"),g.removeAttr("hidden"),c.addClass("kgrid-date-range-open"),d.attr("aria-expanded","true"),b()):(g.attr("hidden","hidden"),c.removeClass("kgrid-date-range-open"),d.attr("aria-expanded","false"),g.css({position:"",top:"",left:"",width:"",zIndex:""}),g.removeClass("kgrid-date-range-panel-floating"),g.insertAfter(f))}function b(){const e=d[0].getBoundingClientRect(),t=Math.min(Math.max(e.width,320),window.innerWidth-16);let n=e.left;const o=window.innerWidth-t-8;n>o&&(n=Math.max(8,o)),g.css({position:"fixed",top:e.bottom+2+"px",left:n+"px",width:t+"px",zIndex:1080});const r=g[0].offsetHeight;let i=e.bottom+2;i+r>window.innerHeight-8&&e.top>r+8&&(i=e.top-r-2),g.css("top",i+"px")}g.append($("<label>",{class:"kgrid-date-range-bound"}).append($("<span>",{class:"kgrid-date-range-label",text:i}),p),$("<label>",{class:"kgrid-date-range-bound"}).append($("<span>",{class:"kgrid-date-range-label",text:l}),m)),c.append(d,f,g),t.before(c),t.attr("data-kgrid-date-range",r),o.attr("data-kgrid-date-range",r),c.append(t,o),p.add(m).on("change",function(){h(p.val()||"",m.val()||"",!1),t.trigger("change")}),d.on("click",function(e){e.preventDefault(),y(!c.hasClass("kgrid-date-range-open"))}),d.on("keydown",function(e){"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),y(!c.hasClass("kgrid-date-range-open")))}),f.on("click",function(e){e.preventDefault(),e.stopPropagation(),h("","",!1),t.trigger("change"),y(!1)});const w=".kgridDateRange_"+e.uuid();$(document).on("mousedown"+w,function(e){c.hasClass("kgrid-date-range-open")&&($(e.target).closest(c).length||$(e.target).closest(g).length||y(!1))}),$(document).on("keydown"+w,function(e){"Escape"===e.key&&c.hasClass("kgrid-date-range-open")&&y(!1)}),$(window).on("resize"+w+" scroll"+w,function(){c.hasClass("kgrid-date-range-open")&&b()});const v=function(){const n=t.prop("form")||t[0]&&t[0].form;n&&$(n).off("reset"+w).on("reset"+w,function(){setTimeout(function(){e.syncDateRangeVisible(t[0]),e.syncDateRangeVisible(o[0])},0)})};t.data("kgridDateRangeBindReset",v),v(),setTimeout(v,0);const C=e.normalizeDateRangeDefault(e.filterDefaultValue?e.filterDefaultValue(n&&n.default):n&&n.default);(C.from||C.to)&&h(C.from,C.to,!0)}(t.$input,t.config||{})}})}(window.KGrid),function(e){e.resolveDefaultInteraction=function(e){return"edit"===e.defaultInteraction||"view"===e.defaultInteraction?e.defaultInteraction:!0===e.editmode?"edit":(e.editmode,"view")},e.getTableInteractionHost=function(e){if(e.hasClass("custom-table-shell"))return e;const t=e.find(".custom-table-shell").first();return t.length?t:e},e.applyInteraction=function(t,n,o){const r=e.getTableInteractionHost(t),i="edit"===n?"edit":"view";r.attr("data-interaction",i),o&&"object"==typeof o?(void 0!==o.create&&r.attr("data-allow-insert",o.create?"true":"false"),void 0!==o.update&&r.attr("data-allow-update",o.update?"true":"false"),void 0!==o.delete&&r.attr("data-allow-delete",o.delete?"true":"false"),void 0!==o.clone&&r.attr("data-allow-clone",o.clone?"true":"false")):"edit"===i&&r.removeAttr("data-allow-insert data-allow-update data-allow-delete data-allow-clone")}}(window.KGrid),function(e){e.setupLabelsHeader=function(t,n){const o=t.children("tr"),r=o.children(),i=r.first().clone(!0);r.remove();return[...n.columns].forEach(t=>{if(t.hidden)return;let r=i.clone(!0);if(e.applyColumnDomAttrs(r,t),e.applyColumnCellMeta(r,t),t.selection){const i=r.empty();return $("<input>",{type:"checkbox",class:"form-check-input kgrid-select-all","aria-label":n.selectionAllLabel||"Toggle all"}).appendTo(i),e.applyColumnCellMeta(i,t),void o.append(i)}const a=t.label??"";if(!t.features?.sort){const n=r.empty().html(a);return""!==a&&n.attr("title",a),e.applyColumnCellMeta(n,t),void o.append(n)}if(!t.name)throw new Error("Column must have a name when column.sortable is true: \n"+JSON.stringify(t,null,2));const l=r.find("span.column-label").text(a);""!==a&&l.attr("title",a),r.children("a").attr("data-sortfld",t.name),r.appendTo(o)}),e.hasActionColumn(n)&&$("<th>").addClass("kgrid-row-actions").attr("aria-label","Actions").appendTo(o),o}}(window.KGrid),function(e){const t="kgridFilterDebounceTimer";e.cancelFilterSubmit=function(e){const n=e.data(t);n&&(clearTimeout(n),e.removeData(t))},e.cancelFilterDebounces=function(t){const n=$(t).attr("id");n&&$(document).find("[form='"+n+"']").each(function(){e.cancelFilterSubmit($(this))})},e.flushFilterSubmit=function(e){const n=e.data(t);if(!n)return;clearTimeout(n),e.removeData(t);const o=e[0]&&e[0].form;o&&$(o).trigger("submit")},e.wrapFilterSubmitHandler=function(n,o,r,i){if(!e.shouldDebounceFilterSubmit(r,i))return o;const a=i;return function(){e.cancelFilterSubmit(n);const r=setTimeout(function(){n.removeData(t),o.call(this)}.bind(this),a);n.data(t,r)}},e.filterDefaultValue=function(e){return null!=e&&"object"==typeof e&&null!=e.value?e.value:e},e.columnFilterPersisted=function(e){const t=e&&e.filter?e.filter:{};return!(!e||!e.hidden&&"hidden"!==t.type&&!t.persist)},e.ensureFilterField=function(e,t,n,o){if(!e||!t||null==n||""===n)return null;let r=e.elements&&e.elements.namedItem(t);return r&&null!=r.length&&!r.tagName&&(r=r[0]),r&&r.tagName||(r=document.createElement("input"),r.type="hidden",r.name=t,e.appendChild(r)),r.setAttribute("data-operator",o||"="),r.value=String(n),r.defaultValue=String(n),r},e.applyColumnDefaultFilters=function(t,n){t&&n&&n.forEach(function(n){if(!n.name||n.features&&!1===n.features.filter)return;const o=n.filter;if(!o||null==o.default||""===o.default)return;const r=e.filterDefaultValue(o.default);if(null==r||""===r)return;if("date_range"===o.type)return void e.applyDateRangeDefault(t,n.name,r);const i=o.operator||(e.columnFilterPersisted(n)?"=":"~=~"),a=e.filterFormField(t,n.name);!n.hidden&&"hidden"!==o.type&&a.length?a.val()||(a.val(String(r)),a.attr("data-operator",i)):e.ensureFilterField(t,n.name,r,i)})},e.setupDefaultFilters=function(t,n,o,r){const i=$(t)[0];if(!(i&&n&&n.features&&n.features.filtering))return;const a=n.columns||[];if(e.applyColumnDefaultFilters(i,a),a.some(e.columnFilterPersisted)){let t=!1;$(i).off("reset.kgridDefaultFilters").on("reset.kgridDefaultFilters",function(n){if(!t){n.preventDefault(),e.cancelFilterDebounces(i),t=!0;try{i.reset(),e.applyColumnDefaultFilters(i,a),o&&o.filtering&&"function"==typeof o.filtering.handleSubmit?o.filtering.handleSubmit(i):$(i).trigger("submit")}finally{t=!1}}})}if(!o||!o.filtering)return;const l=a.filter(function(t){return t.name&&t.filter&&null!=t.filter.default&&""!==t.filter.default&&e.columnFilterPersisted(t)});if(!l.length)return;const s=String(o.url&&o.url.parameters&&o.url.parameters.filter||"");!l.some(function(t){if(t.filter&&"date_range"===t.filter.type){const n=e.normalizeDateRangeDefault(e.filterDefaultValue(t.filter.default));return!(!n.from||-1!==s.indexOf(t.name+">="))||!(!n.to||-1!==s.indexOf(t.name+"<="))}return-1===s.indexOf(t.name+"=")})||r&&r.skipInitSubmit||o.filtering.handleSubmit(i)},e.setupFilterHeader=function(t,n){if(!n.features||!n.features.filtering)return null;const o=t.find(".thead-filters");o.empty();const r=[...n.columns],i=$("<tr>");i.appendTo(o);const a="filter_form_"+e.uuid(),l=$("<form>").attr("id",a).attr("hidden","hidden").attr("aria-hidden","true").addClass("table-filter-form").insertBefore(t);return r.forEach(t=>{const n=t.filter||{};if(t.hidden||"hidden"===n.type){if(t.features&&!1===t.features.filter)return;if(!t.name)return;const o=e.filterDefaultValue(n.default);return void(null!=o&&""!==o?e.ensureFilterField(l[0],t.name,o,n.operator||"="):e.columnFilterPersisted(t)&&e.ensureFilterField(l[0],t.name,"",n.operator||"="))}let o,r=$("<th>").appendTo(i).attr("data-label",t.label);if(e.applyColumnCellMeta(r,t),!1===t.features.filter)return;if(!t.name)throw new Error("Column must have a name when column.features.filter is true: \n"+JSON.stringify(t,null,2));let s=null;const c=e.createFieldInput({mode:"filter",col:t,config:n});if(c)s=c,o=c.$input,o.appendTo(r),e.mountField({mode:"filter",$input:o,col:t,config:n});else if("select"===n.type){if(!n.options)throw new Error("Column must have a filter.options array when column.filter.type is select: \n"+JSON.stringify(t,null,2));if(o=$("<select>").addClass("form-select form-select-sm"),!Array.isArray(n.options))throw new Error("Column must have a filter.options array when column.filter.type is select: \n"+JSON.stringify(t,null,2));n.options.forEach(e=>{if(!e.label||"string"!=typeof e.value)throw new Error("Column must have an filter.options object with label and value when column.filter.type is select: \n"+JSON.stringify(t,null,2));$("<option>").text(e.label).attr("value",e.value).appendTo(o)}),o.appendTo(r)}else{if(!e.isValidFilterType(n.type))throw new Error("Unknown filter type: "+n.type);o=$(`<input autocomplete='off' type='${n.type}' class='form-control form-control-sm'/>`),o.appendTo(r)}if("date_range"===n.type){r.find("input.kgrid-date-range-value").each(function(){this.setAttribute("form",a),this.setAttribute("name",t.name),l[0].appendChild(this)});const e=o.data("kgridDateRangeBindReset");"function"==typeof e&&e()}else{const r=n.operator||("multi_select"===n.type?"><":void 0);null!=r&&o.attr("data-operator",r),o.attr("form",a),o.attr("name",t.name);const i=e.filterDefaultValue(n.default);if(null!=i&&""!==i&&!o.val()){const t="multi_select"===n.type?e.normalizeMultiSelectValue(i,n.separator):String(i);o.val(t),o.attr("data-default",t),o[0]&&(o[0].defaultValue=t)}}e.bindFilterInputEvents({type:n.type,$input:o,onSubmit:function(){const e=this.form;e&&$(e).trigger("submit")},createResult:s,filterConfig:n})}),e.hasActionColumn(n)&&$("<th>").addClass("kgrid-row-actions").attr("data-label","Actions").appendTo(i),l},e.syncFormFiltersToCollectionUrl=function(e,t){if(!e||!t||!t.url)return;t.url.parameters||(t.url.parameters={});const n=[],o=e.elements;if(o){for(let e=0;e<o.length;e++){const t=o[e];if(!t||!t.name)continue;const r=$(t),i=r.val();if(null==i||""===i)continue;const a=r.attr("data-operator")||r.data("operator")||"=";n.push(t.name+a+i)}t.offset=0,n.length?t.url.parameters.filter=n.join(","):delete t.url.parameters.filter}},e.FilterForm=function(t){this.form=$(t)[0],this.filter=(t,n,o="~=~")=>{if(!this.form)return this;let r=e.filterFormField(this.form,t);if(r.length||(e.ensureFilterField(this.form,t,n,o),r=e.filterFormField(this.form,t)),!r.length)return this;e.flushFilterSubmit(r),r.val(n);const i=r.attr("data-operator");return r.attr("data-operator",o),$(this.form).trigger("submit"),r.attr("data-operator",i),this},this.ensure=(t,n,o="=")=>(e.ensureFilterField(this.form,t,n,o),this),this.reset=()=>(this.form&&(e.cancelFilterDebounces(this.form),this.form.reset()),this)}}(window.KGrid),function(e){e.wrapFlagSwitch=function(e){return e.attr({type:"checkbox",role:"switch",value:"1"}).removeClass("form-control form-input form-control-sm").addClass("form-check-input"),$("<div class='form-check form-switch kgrid-flag-switch mb-0'>").append(e)},e.setupCell=function(t,n){const o=n?n.attr("id"):null,r={...t},i=$("<td>").attr("data-label",t.label);e.applyColumnCellMeta(i,t),e.applyColumnDomAttrs(i,r);let a=$("<div>").addClass("cell-content");if(a.html(r.display.template??`{{${r.name}}}`),a.appendTo(i),null==n||!t.features.update)return a.clone(!0).removeClass("cell-content").addClass("cell-input").appendTo(i),i;if(!r.name)throw new Error("Column must have a name when column.features.update is true: \n"+JSON.stringify(t,null,2));const l=r.update,s=l.type??"text";let c,u=!1;const d=e.createFieldInput({mode:"update",col:t,config:l});if(d)c=d.$input,u=!!d.skipValueAttr;else{switch(s){case"textarea":c=$(`<textarea class='form-input form-control form-control-sm'>{{${l.value??r.name}}}</textarea>`),u=!0;break;case"select":if(c=$("<select class='form-input form-control form-control-sm'/>"),!Array.isArray(l.options))throw new Error("Select column must have an update.options array when column.features.update is true: \n"+JSON.stringify(t,null,2));l.options.forEach(e=>{if("string"!=typeof e.label||void 0===e.value)throw new Error("Select update.options entries need label and value: \n"+JSON.stringify(t,null,2));$("<option>").text(e.label).attr("value",e.value).appendTo(c)}),u=!0;break;case"hidden":c=$("<input type='hidden' class='form-input form-control form-control-sm'/>");break;case"displayonly":{const e=l.template||r.display.template||`{{${r.name}}}`;return $("<div>").addClass("cell-input").append(e).appendTo(i),i}case"checkbox":c=$("<input autocomplete='off' type='checkbox' class='form-check-input'/>"),u=!0;break;default:if(!e.isValidInputType(s))throw new Error("Invalid update updateConfig type: "+JSON.stringify(l,null,2));c=$(`<input autocomplete='off' type='${s}' class='form-input form-control form-control-sm'/>`)}c.attr("data-type",s)}if(l.attrs&&"object"==typeof l.attrs&&Object.keys(l.attrs).forEach(e=>c.attr(e,l.attrs[e])),c.attr("form",o),c.attr("name",r.name),!u&&"textarea"!==s){const e=l.value??`{{${r.name}}}`;null!=e&&"object"!=typeof e&&c.attr("value",e)}if(r.hidden)return c.attr("type","hidden").appendTo(n),i;l.disabled&&c.attr("disabled",!0),l.readonly&&c.attr("readonly",!0),l.required&&c.attr("required",!0),l.attrs&&"object"==typeof l.attrs&&Object.keys(l.attrs).forEach(e=>c.attr(e,l.attrs[e])),l.disabled||l.readonly||c.attr("onchange","$(this).parents('tr').addClass('editing')");const f="checkbox"===s?e.wrapFlagSwitch(c):c;return $("<div>").addClass("cell-input").append(f).appendTo(i),i}}(window.KGrid),function(e){e.setupNoDataTbody=function(e,t,n){const o=e.find("td").attr("colspan",n);return t.noDataTemplate&&o.html(t.noDataTemplate),o},e.fillDataRow=function(t,n){const o=[...n.columns],r="data_row_form_"+e.uuid()+"_{{this.id}}",i=n.features&&n.features.update?$("<form class='edit-form table-row-form'>").attr("id",r):null;if(o.forEach(n=>{const o=e.setupCell(n,i);n.hidden||o.appendTo(t)}),e.hasActionColumn(n)){const o=$("<td>").addClass("kgrid-row-actions").appendTo(t);e.renderRowActions(o,n,r)}return i&&e.anchorRowForm(i,t),t},e.setupDataBody=function(t,n,o,r,i,a){const l=$("<tr>").appendTo(t);if(n.dataRowAttrs&&"object"!=typeof n.dataRowAttrs)throw new Error("options.dataRowAttrs must be an object");const s={...n.dataRowAttrs??{}};return Object.keys(s).forEach(e=>l.attr(e,s[e])),t.data("emptyview",a),n?.features?.sorting&&t.data("sort",o),i&&t.data("paging",i.find(".pages")).data("pagesizeinp",i.find(".pagesize")).data("totalrecscount",i.find(".totalrecscount")),r&&t.data("filter",r),n.type&&t.data("type",n.type),e.fillDataRow(l,n),t},e.setupPagingFooter=function(t,n,o){return e.log("setupPagingFooter",t,n,o),n.pagingFooterAttrs&&e.isPlainObject(n.pagingFooterAttrs)&&Object.keys(n.pagingFooterAttrs).forEach(e=>t.attr(e,n.pagingFooterAttrs[e])),e.log("noVisibleCols",o),t.find("td").attr("colspan",o),t}}(window.KGrid),function(e){e.setupNewRecordForm=function(t,n,o){if(!n.insertFormRow||!e.isPlainObject(n.insertFormRow))return t.find(".before-main-tbody").remove(),void t.find(".after-main-tbody").remove();const r=[...n.columns],i=$("<tr>").addClass("new-record-row");"top"===(n.insertFormRow?.position??"top")?(t.find(".after-main-tbody").remove(),i.appendTo(t.find(".before-main-tbody"))):(t.find(".before-main-tbody").remove(),i.appendTo(t.find(".after-main-tbody")));const a="new_record_row_form_"+e.uuid(),l=$("<form class='table-row-form'>").attr("id",a).off("submit").on("submit",t=>{t.preventDefault();const i=e.serializeForm(t.target,r);Object.keys(i).forEach(e=>{r.find(t=>t.name===e)?.insert?.dontsave&&delete i[e]}),o.instance.newItem(i).then(()=>{t.target.reset(),"function"==typeof n.onNewItemCreated&&n.onNewItemCreated(i,t.target)}).catch(e.onError)});r.forEach(t=>{if(t.hidden){if(n.features?.create&&t.features?.create){const e=$("<input type='hidden'>").attr("name",t.name).attr("form",a).appendTo(l);t.insert.default&&e.val(t.insert.default)}return}if(!t.features.create){const n=$("<td>").appendTo(i).attr("data-label",t.label);return void e.applyColumnCellMeta(n,t)}const o=t.insert;if(!o||!e.isPlainObject(o))throw new Error("Column must have an insert config object when column.features.create is true: \n"+JSON.stringify(t,null,2));if(!o.type)throw new Error("Column must have an insert.type when column.features.insert is true: \n"+JSON.stringify(t,null,2));let r;const s=o.type??"text",c=e.createFieldInput({mode:"insert",col:t,config:o});if(c)r=c.$input;else switch(s){case"textarea":r=$("<textarea class='form-input form-control form-control-sm'>");break;case"select":if(r=$("<select class='form-input form-control form-control-sm'/>"),!o.options||!Array.isArray(o.options))throw new Error("Column must have an insert.options array when column.features.insert is true: \n"+JSON.stringify(t,null,2));o.options.forEach(e=>{if("string"!=typeof e.label||void 0===e.value)throw new Error("Column must have an insert.options object with label and value when column.features.insert is true: \n"+JSON.stringify(t,null,2));$("<option>").text(e.label).attr("value",e.value).appendTo(r)});break;case"hidden":r=$("<input type='hidden' class='form-input form-control form-control-sm'/>");break;case"checkbox":r=$("<input autocomplete='off' type='checkbox' class='form-check-input'/>"),r.attr("data-type",s);break;default:if(!e.isValidInputType(s))throw new Error("Invalid type: "+JSON.stringify(o,null,2));r=$(`<input autocomplete='off' type='${s}' class='form-input form-control form-control-sm'/>`),r.attr("data-type",s)}const u="object"==typeof o.default&&o.default&&null!=o.default.value?o.default.value:o.default;if("checkbox"===s){const t=e.isFlagOn(u);r.prop("checked",t).prop("defaultChecked",t)}else null==o.default||""===o.default||r.val()||String(u).trim()&&(r.val(u).trigger("change"),r[0]&&"defaultValue"in r[0]&&(r[0].defaultValue=r[0].value));if(o.attrs&&"object"==typeof o.attrs&&Object.keys(o.attrs).forEach(e=>r.attr(e,o.attrs[e])),r.attr("form",a).attr("name",t.name),o.disabled&&r.attr("disabled",!0),o.readonly&&r.attr("readonly",!0),o.required&&r.attr("required",!0),o.attrs&&"object"==typeof o.attrs&&Object.keys(o.attrs).forEach(e=>r.attr(e,o.attrs[e])),"hidden"!==o.type){const n="checkbox"===s?e.wrapFlagSwitch(r):r,o=$("<td>").append(n).appendTo(i).attr("data-label",t.label);e.applyColumnCellMeta(o,t)}e.mountField({mode:"insert",$input:r,col:t,config:o,formEl:l[0],rowEl:i[0]}),o.events&&Array.isArray(o.events)&&o.events.forEach(e=>{r.off(e.event).on(e.event,function(t,...n){"function"==typeof e.callback&&e.callback(t,l[0],i[0],...n)})})}),e.anchorRowForm(l,i);const s=$("<td>").addClass("kgrid-row-actions").appendTo(i).attr("data-label","action"),c=$("<div>").addClass("btn-group").appendTo(s);return $("<button>").addClass("btn btn-sm btn-primary new-item-btn").html("<i class='fas fa-plus-square'></i>").attr("form",a).attr("type","submit").appendTo(c),"function"==typeof n.onInsertRowReady&&n.onInsertRowReady(l[0],i[0]),i}}(window.KGrid),function(e){e.setupEvents=function(t,n,o,r){const i=t.views[0];i&&i.el&&"function"==typeof e.applyLayoutToRow&&e.applyLayoutToRow(i.el,o.columns),"function"==typeof e.bindSelectionRow&&e.bindSelectionRow(t,i,n,o),o.columns.forEach(n=>{n.display.events.forEach(e=>{if(!e.selector||!e.event||!e.callback)throw new Error("Invalid event: "+JSON.stringify(e,null,2));i.el.find(e.selector).off(e.event).on(e.event,n=>{if("function"!=typeof e.callback)throw new Error("Event callback must be a function: "+JSON.stringify(e,null,2));e.callback(n,t,i)})}),o.features.update&&n.update.events.forEach(o=>{if(!o.event||!o.callback)throw new Error("Invalid event: "+JSON.stringify(o,null,2));i.el.find("[name='"+n.name+"']").off(o.event).on(o.event,function(n,...r){if(e.log("event",o,n,this,r),"function"!=typeof o.callback)throw new Error("Event callback must be a function: "+JSON.stringify(o,null,2));o.callback(n,t,i,...r)})})}),o.features.update&&(i.el.find("[data-type]").each((n,o)=>{const a=o.getAttribute("data-type");if(!e.isPluggableFieldType(a))return;const l=r.get(o.name);l?.update&&e.mountField({mode:"update",$input:$(o),col:l,config:l.update,item:t,view:i})}),i.el.find("select[data-type='select']").each((e,n)=>{const o=r.get(n.name);if(!o)return;const i=t.attributes[o.name];null!=i&&""!==i&&$(n).val("boolean"==typeof i?String(i):i)}),i.el.find("input[type='checkbox']").each((n,o)=>{const i=r.get(o.name);i&&(o.checked=e.isFlagOn(t.attributes[i.name]))}),i.el.find("form.edit-form").off("submit").on("submit",t=>{const n=t.target;t.preventDefault();const r=$(n).parents("[data-type=item]").data().instance,i=e.serializeForm(n);Object.keys(i).forEach(e=>{o.columns.find(t=>t.name===e)?.update?.dontsave&&delete i[e]}),r.update(i).catch(e.onError)}));const a=e.resolveRowActions(o);e.applyRowActionVisibility(i.el,t,a.menuItems),e.mountRowActionDropdowns(i.el);const l=a.menuItems.some(e=>"clone"===e.action),s=a.menuItems.some(e=>"delete"===e.action);l&&i.el.find(".clone-item").off("click").on("click",e=>{e.preventDefault(),e.stopPropagation(),"function"==typeof o.onClone&&o.onClone(t,i,e)}),s&&i.el.find(".delete-item").off("click").on("click",n=>{n.preventDefault(),n.stopPropagation(),i.el.addClass("confirm-delete");const r=()=>i.el.removeClass("confirm-delete"),l=$(n.currentTarget).closest("[data-kgrid-action-index]").attr("data-kgrid-action-index"),s=null!=l?a.menuItems[Number(l)]:null,c=s&&"string"==typeof s.confirm?s.confirm:null;(c?(t,n)=>e.confirm(c,t,n):(n,r)=>e.runDeleteConfirm({item:t,view:i,options:o},n,r))(()=>{t.delete().catch(e.onError).finally(r)},r)});const c=new Map;a.menuItems.forEach(e=>{e.id&&"function"==typeof e.callback&&c.set(e.id,e.callback)}),c.size&&i.el.find("[data-kgrid-action]").off("click.kgridAction").on("click.kgridAction",e=>{const n=e.currentTarget.getAttribute("data-kgrid-action"),o=c.get(n);o&&(e.preventDefault(),e.stopPropagation(),o(e,t,i))}),"function"==typeof o.onRowFields&&o.onRowFields(t,i,n)}}(window.KGrid),function(e){e.PREFERENCES_VERSION=1,e.localStoragePreferences={get:function(e){try{const t="undefined"!=typeof window?window:globalThis,n=t&&t.localStorage;if(!n)return null;const o=n.getItem(e);return o?JSON.parse(o):null}catch(e){return null}},set:function(e,t){try{const n="undefined"!=typeof window?window:globalThis,o=n&&n.localStorage;if(!o)return;if(null==t)return void o.removeItem(e);o.setItem(e,JSON.stringify(t))}catch(e){}}},e.preferencesStorageFor=function(t){return t&&t.preferencesStorage?t.preferencesStorage:e._config&&e._config.preferencesStorage?e._config.preferencesStorage:e.localStoragePreferences},e.layoutStorageKey=function(e){return"kgrid:"+e+":layout"},e.filtersStorageKey=function(e,t){let n="kgrid:"+e+":filters";return null!=t&&""!==String(t)&&(n+=":"+String(t)),n},e.viewStorageKey=function(e,t){let n="kgrid:"+e+":view";return null!=t&&""!==String(t)&&(n+=":"+String(t)),n},e.chooserColumns=function(e){return(e||[]).filter(function(e){return e&&e.name&&!e.hidden&&!e.selection})},e.layoutFromColumns=function(t){return{v:e.PREFERENCES_VERSION,columns:e.chooserColumns(t).map(function(e){return{name:e.name,hidden:!!e.userHidden}})}},e.parseFilterExpression=function(e){const t=String(e||""),n=["~=~",">=","<=","!=","=",">","<"];for(let e=0;e<n.length;e++){const o=n[e],r=t.indexOf(o);if(r>0)return{name:t.slice(0,r),operator:o,value:t.slice(r+o.length)}}return null},e.isUserFilterColumn=function(e){return!(!e||!e.name||e.hidden||e.features&&!1===e.features.filter)},e.readUserFilters=function(t,n){if(!t)return[];const o=[];return(n||[]).forEach(function(n){if(!e.isUserFilterColumn(n))return;let r=e.filterFormFields(t,n.name);if(r.length||(r=e.filterFormField(t,n.name)),!r.length)return;if(r.length>1)return void r.each(function(){const e=$(this),t=e.val();null==t||""===t||Array.isArray(t)&&!t.length||o.push({name:n.name,value:Array.isArray(t)?t:String(t),operator:e.attr("data-operator")||n.filter&&n.filter.operator||">="})});const i=r,a=i.val();if(null==a||""===a||Array.isArray(a)&&!a.length)return;const l=i.attr("data-operator")||n.filter&&n.filter.operator||"~=~";o.push({name:n.name,value:Array.isArray(a)?a:String(a),operator:l})}),o},e.applyUserFilters=function(t,n,o){t&&o&&Array.isArray(o.filters)&&o.filters.forEach(function(o){if(!o||!o.name)return;const r=(n||[]).find(function(e){return e&&e.name===o.name});if(!e.isUserFilterColumn(r))return;if(null==o.value||""===o.value)return;const i=e.filterFormFields(t,o.name);if(i.length>1){if(!o.operator)return;const e=i.filter(function(){return $(this).attr("data-operator")===o.operator});return void(e.length&&e.val(o.value))}let a=e.filterFormField(t,o.name);a.length||(e.ensureFilterField(t,o.name,o.value,o.operator),a=e.filterFormField(t,o.name)),a.length&&(a.val(o.value),o.operator&&a.attr("data-operator",o.operator))})},e.ensureUrlFiltersOnForm=function(t,n){if(!(t&&n&&n.url&&n.url.parameters))return;const o=String(n.url.parameters.filter||"");o&&o.split(",").forEach(function(n){const o=e.parseFilterExpression(n.trim());if(!o||!o.name||""===o.value)return;const r=e.filterFormFields(t,o.name);if(r.length>1){const e=r.filter(function(){return $(this).attr("data-operator")===o.operator});return void(e.length&&!e.val()&&e.val(o.value))}const i=e.filterFormField(t,o.name);return i.length&&i.val()?void 0:i.length?(i.val(o.value),void i.attr("data-operator",o.operator)):void e.ensureFilterField(t,o.name,o.value,o.operator)})},e.preferencesLoadLayout=function(t){if(!t||!t.storageKey)return null;const n=e.preferencesStorageFor(t).get(e.layoutStorageKey(t.storageKey));return n&&n.v===e.PREFERENCES_VERSION&&Array.isArray(n.columns)?n:null},e.preferencesSaveLayout=function(t,n){t&&t.storageKey&&e.preferencesStorageFor(t).set(e.layoutStorageKey(t.storageKey),n)},e.preferencesLoadFilters=function(t){if(!t||!t.storageKey)return null;const n=e.preferencesStorageFor(t).get(e.filtersStorageKey(t.storageKey,t.filterStorageScope));return n&&n.v===e.PREFERENCES_VERSION&&Array.isArray(n.filters)?n:null},e.preferencesSaveFilters=function(t,n){t&&t.storageKey&&e.preferencesStorageFor(t).set(e.filtersStorageKey(t.storageKey,t.filterStorageScope),{v:e.PREFERENCES_VERSION,filters:n||[]})},e.preferencesLoadView=function(t){if(!t||!t.storageKey)return null;const n=e.preferencesStorageFor(t).get(e.viewStorageKey(t.storageKey,t.filterStorageScope));return n&&n.v===e.PREFERENCES_VERSION&&"object"==typeof n?n:null},e.preferencesSaveView=function(t,n){t&&t.storageKey&&e.preferencesStorageFor(t).set(e.viewStorageKey(t.storageKey,t.filterStorageScope),n)},e.sortableColumnNames=function(e){const t=new Set;return(e||[]).forEach(function(e){e&&e.name&&e.features&&e.features.sort&&!e.hidden&&t.add(e.name)}),t},e.sanitizeSort=function(t,n){const o=e.sortableColumnNames(n),r=[];return String(null==t?"":t).split(",").forEach(function(e){const t=/^(-*)([A-Za-z0-9_-]+)$/.exec(String(e).trim());t&&o.has(t[2])&&r.push((t[1].length?"-":"")+t[2])}),r.join(",")},e.collectionSort=function(e){const t=e&&e.url&&e.url.parameters;return t&&null!=t.sort&&""!==t.sort?String(t.sort):""},e.sortDirectionForField=function(e,t){const n=String(e||"").split(",");for(let e=0;e<n.length;e++){const o=/^(-*)([A-Za-z0-9_-]+)$/.exec(n[e].trim());if(o&&o[2]===t)return o[1].length?"desc":"asc"}return null},e.syncSortIndicators=function(t,n){t&&t.length&&t.find("[data-sortfld]").each(function(){const t=$(this),o=t.attr("data-sortfld"),r=e.sortDirectionForField(n,o),i=t.find(".sort-up"),a=t.find(".sort-down"),l=t.find(".sort-default");"asc"===r?(t.data("sortdir","up"),i.show(),a.hide(),l.hide()):"desc"===r?(t.data("sortdir","down"),i.hide(),a.show(),l.hide()):(t.removeData("sortdir"),i.hide(),a.hide(),l.show())})},e.applySavedPageSize=function(e,t,n){if(!e||!e.length||null==n)return!1;const o=String(n);if(!/^\d+$/.test(o)||"0"===o)return!1;const r=(t.pagingPageSizes||[]).map(function(e){return String(e)});if(r.length&&r.indexOf(o)<0)return!1;const i=e.find("select.pagesize");return!!i.length&&(i.val(o),e.find(".pages").attr("data-pagesize",o),!0)},e.applySavedOffset=function(e,t){e&&null!=t&&/^\d+$/.test(String(t))&&("function"!=typeof e.setOffset?e.offset=String(t):e.setOffset(String(t)))},e.applySavedSort=function(t,n,o){if(!(o&&null!=o.sort&&n&&n.features&&n.features.sorting))return;const r=t&&t.url&&t.url.parameters;if(!r)return;const i=e.sanitizeSort(o.sort,n.columns);i?r.sort=i:delete r.sort},e.persistViewState=function(t,n,o){if(!(n&&n.storageKey&&t&&n.features))return;const r=!!n.features.sorting,i=!!n.features.paging;if(!r&&!i)return;const a=e.preferencesLoadView(n)||{},l={v:e.PREFERENCES_VERSION};if(r){const o=t.url&&t.url.parameters;o&&Object.prototype.hasOwnProperty.call(o,"sort")?l.sort=e.sanitizeSort(o.sort,n.columns):"string"==typeof a.sort?l.sort=a.sort:l.sort=""}if(i){const e=o&&o.length?o.find("select.pagesize").val():null,r=(n.pagingPageSizes||[]).map(function(e){return String(e)});null!=e&&/^\d+$/.test(String(e))&&"0"!==String(e)&&(!r.length||r.indexOf(String(e))>=0)?l.pageSize=Number(e):null!=a.pageSize&&(l.pageSize=a.pageSize);const i=null!=t.offset?String(t.offset):"0";l.offset=/^\d+$/.test(i)?Number(i):0}e.preferencesSaveView(n,l)},e.bindViewPersistence=function(t,n,o){t&&"function"==typeof t.on&&n&&n.storageKey&&n.features&&(n.features.sorting||n.features.paging)&&t.on("load",function(){e.persistViewState(t,n,o),n.features.sorting&&e.syncSortIndicators(o,e.collectionSort(t))})},e.reorderColumns=function(e,t){const n=new Map,o=[],r=[];(e||[]).forEach(function(e,t){e&&e.hidden?o.push({col:e,index:t}):e&&e.selection?r.push(e):e&&e.name&&n.set(e.name,e)});const i=[];(t||[]).forEach(function(e){n.has(e)&&(i.push(n.get(e)),n.delete(e))}),n.forEach(function(e){i.push(e)});const a=r.concat(i);return o.forEach(function(e){a.splice(Math.min(e.index,a.length),0,e.col)}),a},e.columnDefaultUserHidden=function(e){return!(!e||!e.defaultHidden||e.locked||e.hidden)},e.mergeLayoutIntoColumns=function(t,n){const o=(t||[]).slice();o.forEach(function(t){t&&!t.hidden&&(t.userHidden=e.columnDefaultUserHidden(t))});const r=e.chooserColumns(o),i=new Map(r.map(function(e){return[e.name,e]})),a=[],l=new Set;(n&&Array.isArray(n.columns)?n.columns:[]).forEach(function(e){if(!e||!e.name||!i.has(e.name))return;const t=i.get(e.name);t.userHidden=!!e.hidden&&!t.locked,a.push(e.name),l.add(e.name)}),r.forEach(function(e){l.has(e.name)||a.push(e.name)});const s=e.reorderColumns(o,a),c=e.chooserColumns(s);if(c.length&&c.every(function(e){return e.userHidden})){(c.find(function(e){return!e.locked})||c[0]).userHidden=!1}return s},e.applyLayoutToRow=function(t,n){if(!t||!t.length)return;const o=e.chooserColumns(n),r=o.map(function(e){return e.name}),i={};o.forEach(function(e){e.userHidden&&(i[e.name]=!0)});const a=t.children(".kgrid-row-actions"),l={};t.children("[data-name]").each(function(){l[this.getAttribute("data-name")]=this}),r.forEach(function(e){const n=l[e];n&&(a.length?$(n).insertBefore(a):t.append(n),n.classList.toggle("kgrid-user-hidden",!!i[e]))})},e.applyLayoutToDom=function(t,n,o){if(!t||!t.length)return;t.find(".thead-labels tr, .thead-filters tr, .before-main-tbody tr, .main-tbody tr, .after-main-tbody tr").each(function(){e.applyLayoutToRow($(this),n)});const r=e.layoutVisibleColumns(n),i=t.find(".kgrid-row-actions").length>0;e.syncActionColumnColgroup(t,r.length,i,o,r),e.syncSpanningCells(t,e.participatingColumnCount(n,i))},e.refreshCollectionTemplate=function(t,n){if(!t||!t.instance||"function"!=typeof e.fillDataRow)return;const o=e.getKViews(n&&n.kviews);if(!o||"function"!=typeof o.template)return;const r=$("<tr>");n.dataRowAttrs&&e.isPlainObject(n.dataRowAttrs)&&Object.keys(n.dataRowAttrs).forEach(function(e){r.attr(e,n.dataRowAttrs[e])}),e.fillDataRow(r,n);const i=$("<div>").append(r).html(),a=o.template(i);t.instance.template=a,(t.instance.items||[]).forEach(function(e){(e.views||[]).forEach(function(e){e.template=a})})},e.setupFilterPersistence=function(t,n){t&&n&&n.storageKey&&n.features&&n.features.filtering&&$(t).off("submit.kgridFilterPrefs").on("submit.kgridFilterPrefs",function(){e.preferencesSaveFilters(n,e.readUserFilters(t,n.columns))})},e.applyColumnLayout=function(t,n,o){n.columns=e.mergeLayoutIntoColumns(n.columns,o);const r=t.$host.find("table").first();if(e.applyLayoutToDom(r,n.columns,n),e.refreshCollectionTemplate(t,n),"function"==typeof e.renderColumnChooserPanel){const o=t.$host.find(".kgrid-column-chooser-panel");o.length&&e.renderColumnChooserPanel(o,n,t)}return e.layoutFromColumns(n.columns)}}(window.KGrid),function(e){e.csvExportFields=function(t){return e.layoutVisibleColumns(t).filter(function(t){return t&&t.name&&!t.selection&&t.name!==e.SELECTION_COLUMN_NAME&&!1!==t.export}).map(function(e){return"string"==typeof e.exportField&&e.exportField?e.exportField:e.name})},e.buildCsvExportUrl=function(e,t){const n=new window.URL(e,"http://kgrid.local"),o=t&&t.type,r=t&&null!=t.limit?t.limit:1e4;n.searchParams.set("format","csv"),n.searchParams.set("includetablehead","true"),o&&(n.searchParams.set("page["+o+"][limit]",String(r)),n.searchParams.set("page["+o+"][offset]","0"));const i=[];return n.searchParams.forEach(function(e,t){0===t.indexOf("fields[")&&i.push(t)}),i.forEach(function(e){n.searchParams.delete(e)}),t&&"visible"===t.mode&&(n.searchParams.delete("include"),o&&t.fields&&t.fields.length&&n.searchParams.set("fields["+o+"]",t.fields.join(","))),/^https?:\/\//i.test(e)?n.toString():n.pathname+n.search},e.resolveApiUrl=function(e,t){if(null==e||""===e)return e;const n=String(e);if(/^https?:\/\//i.test(n)||n.startsWith("//"))return n;const o=t&&(t.baseUrl||t.basePath)||"";if(!o)return n;const r=String(o).replace(/\/+$/,""),i=n.replace(/^\/+/,"");return i?r+"/"+i:r+"/"},e.downloadCsv=function(t,n,o){const r=n&&n.instance,i=r&&r.url&&r.url.toString?r.url.toString():"";if(!i)return Promise.reject(new Error("CSV export requires a collection URL"));const a=t&&t.type;if(!a)return Promise.reject(new Error("CSV export requires a resource type"));const l="visible"===o?e.csvExportFields(t.columns):null;if(!("visible"!==o||l&&l.length))return Promise.reject(new Error("No visible columns to export"));const s=e.buildCsvExportUrl(i,{type:a,mode:"visible"===o?"visible":"all",fields:l,limit:t.csvExportLimit}),c=e.resolveApiUrl(s,e.getKViews(t.kviews));return window.fetch(c).then(function(e){return e.ok?e.blob().then(function(e){const n=document.createElement("a"),o=window.URL.createObjectURL(e);n.href=o,n.download=t.csvFileName||a+".csv",document.body.appendChild(n),n.click(),n.remove(),window.URL.revokeObjectURL(o)}):e.json().catch(function(){return null}).then(function(t){throw new Error(function(e,t){return t&&t.errors&&t.errors[0]?t.errors[0].detail||t.errors[0].title||"":t&&t.error?String(t.error):"CSV export failed ("+e.status+")"}(e,t))})})}}(window.KGrid),function(e){function t(t){const n=[];return t.find(".kgrid-column-chooser-list li[data-name]").each(function(){const e=this.getAttribute("data-name"),t=$(this).find("input[type='checkbox']").prop("checked");n.push({name:e,hidden:!t})}),{v:e.PREFERENCES_VERSION,columns:n}}e.renderColumnChooserPanel=function(n,o,r){n.empty();const i=!(!o.features||!o.features.columnChooser);if(!(!o.features||!o.features.csvExport)){const t=$("<div>").addClass("kgrid-column-chooser-export").appendTo(n);$("<button>").attr("type","button").addClass("btn btn-sm btn-outline-secondary kgrid-csv-export-visible").text(o.csvExportVisibleLabel||"Export CSV — visible fields").appendTo(t),$("<button>").attr("type","button").addClass("btn btn-sm btn-outline-secondary kgrid-csv-export-all").text(o.csvExportAllLabel||"Export CSV — all fields").appendTo(t),function(t,n,o){t.off("click.kgridCsv").on("click.kgridCsv",".kgrid-csv-export-visible, .kgrid-csv-export-all",function(){const t=this,r=t.classList.contains("kgrid-csv-export-visible")?"visible":"all";t.disabled=!0,Promise.resolve(e.downloadCsv(n,o,r)).catch(function(t){e.onError(t)}).finally(function(){t.disabled=!1})})}(n,o,r)}if(!i)return;const a=$("<ul>").addClass("kgrid-column-chooser-list").appendTo(n);e.chooserColumns(o.columns).forEach(function(e){const t=$("<li>").attr("draggable","true").attr("data-name",e.name).appendTo(a);$("<span>").addClass("kgrid-column-chooser-handle").attr("aria-hidden","true").text("⋮⋮").appendTo(t);const n=$("<label>").appendTo(t),o=$("<input>").attr("type","checkbox").prop("checked",!e.userHidden).appendTo(n);e.locked&&o.prop("disabled",!0).attr("title","This column cannot be hidden"),n.append(document.createTextNode(" "+(e.label||e.name)))}),$("<button>").attr("type","button").addClass("btn btn-sm btn-outline-secondary kgrid-column-chooser-reset").text(o.columnChooserResetLabel||"Reset columns").appendTo(n),n.off("change.kgridChooser").on("change.kgridChooser","input[type='checkbox']",function(){const e=t(n);(function(e){return e.columns.filter(function(e){return!e.hidden}).length})(e)<1?this.checked=!0:r.setLayout(e)}),n.off("click.kgridChooserReset").on("click.kgridChooserReset",".kgrid-column-chooser-reset",function(){r.resetLayout()});let l=null;a.off(".kgridChooserDrag"),a.on("dragstart.kgridChooserDrag","li",function(e){l=this,$(this).addClass("kgrid-column-chooser-dragging"),e.originalEvent&&e.originalEvent.dataTransfer&&(e.originalEvent.dataTransfer.effectAllowed="move",e.originalEvent.dataTransfer.setData("text/plain",this.getAttribute("data-name")))}),a.on("dragend.kgridChooserDrag","li",function(){$(this).removeClass("kgrid-column-chooser-dragging"),l=null}),a.on("dragover.kgridChooserDrag","li",function(e){if(e.preventDefault(),!l||l===this)return;const t=this.getBoundingClientRect(),n=t.top+t.height/2;(e.originalEvent?e.originalEvent.clientY:0)<n?this.parentNode.insertBefore(l,this):this.parentNode.insertBefore(l,this.nextSibling)}),a.on("drop.kgridChooserDrag","li",function(e){e.preventDefault(),r.setLayout(t(n))})},e.setupColumnChooser=function(t,n,o){const r=!(!n.features||!n.features.columnChooser),i=!(!n.features||!n.features.csvExport);if(!r&&!i)return;const a=e.getTableInteractionHost(t);a.find(".kgrid-column-chooser").remove();const l=a.find(".thead-labels th.kgrid-row-actions").first();if(!l.length)return;a.attr("data-has-column-chooser","true");const s=n.columnChooserLabel||"Columns",c=$("<div>").addClass("kgrid-column-chooser"),u=$("<button>").attr("type","button").addClass("kgrid-column-chooser-toggle btn btn-sm btn-outline-secondary").attr("title",s).attr("aria-label",s).attr("aria-expanded","false").attr("aria-haspopup","true").html('<i class="fas fa-cog" aria-hidden="true"></i>'),d=$("<div>").addClass("kgrid-column-chooser-panel").attr("hidden","hidden");function f(){const e=u[0].getBoundingClientRect();d.css({position:"fixed",top:Math.round(e.bottom+2)+"px",left:"auto",right:Math.round(window.innerWidth-e.right)+"px",zIndex:1055})}function p(){d.attr("hidden","hidden"),u.attr("aria-expanded","false"),d.css({top:"",left:"",right:"",position:"",zIndex:""})}c.append(u,d),l.append(c),e.renderColumnChooserPanel(d,n,o),u.on("click",function(e){e.stopPropagation(),d.attr("hidden")?(d.removeAttr("hidden"),u.attr("aria-expanded","true"),f()):p()});const m="kgridChooser"+e.uuid();$(window).on("scroll."+m+" resize."+m,function(){d.attr("hidden")||f()}),$(document).on("pointerdown."+m,function(e){if(!document.body.contains(c[0]))return $(document).off("."+m),void $(window).off("."+m);c[0].contains(e.target)||p()})}}(window.KGrid),function(e){e.SELECTION_COLUMN_NAME="__select",e.selectionEnabled=function(e){return!!(e&&e.features&&e.features.selection)},e.installSelectionColumn=function(t){if(!e.selectionEnabled(t))return t;if(t.columns=t.columns||[],t.columns.some(function(e){return e&&e.selection}))return t;const n=t.selectionRowLabel||"Select row";return t.columns.unshift({name:e.SELECTION_COLUMN_NAME,label:"",selection:!0,locked:!0,class:"kgrid-select",attrs:{width:40},features:{create:!1,update:!1,filter:!1,sort:!1},display:{template:'<input type="checkbox" class="form-check-input kgrid-select-row" aria-label="'+n+'">',events:[]}}),t.selectedRows||(t.selectedRows=new Map),t},e.selectionId=function(e){return e?null!=e.id&&""!==e.id?String(e.id):e.attributes&&null!=e.attributes.id&&""!==e.attributes.id?String(e.attributes.id):"":""},e.selectionItem=function(e){if(!e||!e.length)return null;const t=e.data("instance");if(t&&(null!=t.id||t.attributes))return t;return e.find("[data-type=item]").first().data("instance")||null},e.visibleSelectionRows=function(e){return e.find("tbody.main-tbody > tr").filter(function(){return $(this).find(".cell-content .kgrid-select-row").length>0})},e.selectionRecord=function(t,n,o){const r={id:e.selectionId(n)},i=t.selection&&t.selection.meta;if("function"==typeof i){const e=i(n,o);e&&"object"==typeof e&&Object.keys(e).forEach(function(t){"id"!==t&&(r[t]=e[t])})}return r},e.selectionApply=function(t,n,o,r){const i=r||e.selectionItem(n),a=e.selectionId(i);if(!a)return;const l=t.selectedRows;o?l.set(a,e.selectionRecord(t,i,n)):l.delete(a),n.find(".kgrid-select-row").prop("checked",!!o)},e.paintSelectionToggle=function(t){const n=e.visibleSelectionRows(t);let o=0,r=0;n.each(function(){o+=1,$(this).find(".cell-content .kgrid-select-row").prop("checked")&&(r+=1)}),t.find(".kgrid-select-all").each(function(){this.checked=o>0&&r===o,this.indeterminate=r>0&&r<o})},e.syncSelectionDom=function(t,n){const o=t.selectedRows;e.visibleSelectionRows(n).each(function(){const t=$(this),n=e.selectionId(e.selectionItem(t));t.find(".kgrid-select-row").prop("checked",!(!n||!o.has(n)))}),e.paintSelectionToggle(n)},e.toggleSelection=function(t,n,o){const r=e.visibleSelectionRows(n);let i=o;if("boolean"!=typeof i){let e=0,t=0;r.each(function(){e+=1,$(this).find(".cell-content .kgrid-select-row").prop("checked")&&(t+=1)}),i=!(e>0&&t===e)}return r.each(function(){e.selectionApply(t,$(this),i)}),e.paintSelectionToggle(n),i},e.bindSelectionRow=function(t,n,o,r){if(!e.selectionEnabled(r)||!n||!n.el)return;const i=n.el,a=$(o);i.find(".kgrid-select-row").off("change.kgridSelect").on("change.kgridSelect",function(){e.selectionApply(r,i,this.checked,t),e.paintSelectionToggle(a)});const l=e.selectionId(t),s=!!(l&&r.selectedRows&&r.selectedRows.has(l));i.find(".kgrid-select-row").prop("checked",s),s&&r.selectedRows.set(l,e.selectionRecord(r,t,i)),e.paintSelectionToggle(a)},e.bindSelection=function(t,n,o){return n.selectedRows||(n.selectedRows=new Map),t.selected=n.selectedRows,t.getSelection=function(){return Array.from(n.selectedRows.values())},t.clearSelection=function(){return n.selectedRows.clear(),e.syncSelectionDom(n,o),t},t.toggleAll=function(r){return e.toggleSelection(n,o,r),t.getSelection()},t.syncSelection=function(){return e.syncSelectionDom(n,o),t},o.find(".kgrid-select-all").off("change.kgridSelect").on("change.kgridSelect",function(){e.toggleSelection(n,o,this.checked)}),t}}(window.KGrid),function(e){e.init=async function(t,n){const o=e.resolveHostElement(t),r={...e.protoOptions,...n},i=e.mountTableShell(o,r);e.log("table config options",r);const a=e.resolveDefaultInteraction(r);e.applyInteraction(o,a);const l={$host:o,instance:null,filterForm:null,find:e=>o.find(e),setInteraction:(t,n)=>(e.applyInteraction(o,t,n),l),getInteraction:()=>"edit"===e.getTableInteractionHost(o).attr("data-interaction")?"edit":"view",setEditMode(e){if("boolean"!=typeof e)throw new TypeError("setEditMode(editMode) expects a boolean (true = edit, false = view)");return l.setInteraction(e?"edit":"view")},toggleEditMode:e=>(null!=e&&"object"==typeof e&&"function"==typeof e.preventDefault&&(e=void 0),"boolean"==typeof e?l.setInteraction(e?"edit":"view"):l.setInteraction("edit"===l.getInteraction()?"view":"edit")),getLayout:()=>e.layoutFromColumns(r.columns),setLayout:t=>(e.applyColumnLayout(l,r,t),e.preferencesSaveLayout(r,l.getLayout()),l.getLayout()),resetLayout(){const t=new Map;return r.columns.forEach(function(e){e&&e.name&&t.set(e.name,e)}),r.columns=s.map(function(e){return t.get(e)}).filter(Boolean),e.preferencesSaveLayout(r,null),e.applyColumnLayout(l,r,null),l.getLayout()}};e.installSelectionColumn(r),r.columns=(r.columns||[]).map(t=>e.normalizeColumnConfig(t));const s=r.columns.map(function(e){return e.name});r.columns=e.mergeLayoutIntoColumns(r.columns,e.preferencesLoadLayout(r));const c=r.handlers??{};if(delete r.handlers,"string"==typeof r.onClone){const e=c[r.onClone]||r.functions&&r.functions[r.onClone];if(!e||"function"!=typeof e)throw new Error("onClone handler "+r.onClone+" not found or is not a function");r.onClone=e}e.resolveRowActions(r,c);{const t=r._resolvedRowActions;e.getTableInteractionHost(o).attr("data-has-row-menu",t&&t.menuItems&&t.menuItems.length?"true":"false")}r.columns.forEach(e=>{["insert","update","display"].forEach(t=>{const n=e[t].events;if(!n||!Array.isArray(n))throw new Error("Column "+e.name+" events are not an array");n.forEach(t=>{if("string"==typeof t.callback){const n=c[t.callback]||r.functions&&r.functions[t.callback];if(!n||"function"!=typeof n)throw new Error("Event callback function "+t.callback+" not found for column "+e.name+" or is not a function");t.callback=n}else if("function"!=typeof t.callback)throw new Error("Event callback must be a function for column "+e.name)})});const t=e.display;t&&t.events&&Array.isArray(t.events)&&t.events.forEach(e=>{if("string"==typeof e.callback){const t=c[e.callback]||r.functions&&r.functions[e.callback];t&&"function"==typeof t&&(e.callback=t)}})});const u=new Map;r.columns.forEach(e=>{u.set(e.name,e)});const d=e.setupLabelsHeader(i.find(".thead-labels"),r),f=e.hasActionColumn(r),p=e.layoutVisibleColumns(r.columns),m=e.participatingColumnCount(r.columns,f);e.syncActionColumnColgroup(i,p.length,f,r,p);const g=r.filterForm??e.setupFilterHeader(i,r);let h;const y=r.storageKey&&r.features&&(r.features.sorting||r.features.paging)?e.preferencesLoadView(r):null;r.features&&r.features.paging?(h=e.setupPagingFooter(i.find(".paging-footer"),r,m),y&&e.applySavedPageSize(h,r,y.pageSize)):(h=null,i.find(".paging-footer").remove());const b=e.setupNoDataTbody(i.find(".no-data-tbody"),r,m);r.features&&r.features.create&&e.setupNewRecordForm(i,r,l),l.filterForm=new e.FilterForm(g);const w=e.setupDataBody(i.find(".main-tbody"),r,d,g,h,b),v={dontload:!0,setAttrAsId:r.setAttrAsId??!1,itemListeners:{afterrender:t=>e.setupEvents(t,l.find("table"),r,u)}},C=e.getKViews(r.kviews);if(!C)throw new Error(e.KVIEWS_MISSING_MSG);if(l.instance=await C.createCollectionInstance(w,v),r.url){l.instance.setUrl(r.url),r.deleteUrl&&(e.log("set deleteUrl",r.deleteUrl),l.instance.setUrl(r.deleteUrl,"delete")),r.updateUrl&&(e.log("set updateUrl",r.updateUrl),l.instance.setUrl(r.updateUrl,"update"));const t=r.insertUrl||r.url,n=r.onDuplicate?e.applyOnDuplicateToUrl(t,r.onDuplicate):r.insertUrl;n&&l.instance.setUrl(n,"insert"),y&&r.features&&r.features.sorting&&e.applySavedSort(l.instance,r,y),y&&r.features&&r.features.paging&&e.applySavedOffset(l.instance,y.offset)}r.features&&r.features.sorting&&e.syncSortIndicators(i,e.collectionSort(l.instance)),e.bindViewPersistence(l.instance,r,i),e.setupDefaultFilters(g,r,l.instance,{skipInitSubmit:!0});const S=g&&(g.jquery?g[0]:g);if(e.applyUserFilters(S,r.columns,e.preferencesLoadFilters(r)),e.ensureUrlFiltersOnForm(S,l.instance),e.setupFilterPersistence(S,r),e.setupColumnChooser(o,r,l),e.selectionEnabled(r)&&e.bindSelection(l,r,i),r.url)try{r.features&&r.features.filtering&&S&&e.syncFormFiltersToCollectionUrl(S,l.instance),await l.instance.loadFromRemote()}catch(t){e.onError(t)}else{if(!r.data||r.data.constructor!==Array)throw new Error("Invalid data: missing datasource url or data for table");{const e=r.data.map(e=>({attributes:e}));l.instance.loadFromData(e)}}return l}}(window.KGrid);
package/docs/ai-guide.md CHANGED
@@ -109,7 +109,7 @@ Per-table override: pass `deleteConfirm` in `init(host, { deleteConfirm, ... })`
109
109
  **Features** (all default `false`):
110
110
 
111
111
  ```javascript
112
- features: { filtering, sorting, paging, create, update, delete, columnChooser, selection }
112
+ features: { filtering, sorting, paging, create, update, delete, columnChooser, csvExport, selection }
113
113
  ```
114
114
 
115
115
  **Interaction:**
@@ -164,7 +164,7 @@ Each column in `columns: []` is normalized via `KGrid.normalizeColumnConfig` (pr
164
164
 
165
165
  **Hidden / persist filters:** columns with `hidden: true` or `filter.type: "hidden"` get a hidden form field (no filter-row cell). `filter.persist` (or hidden) re-applies `filter.default` on form reset.
166
166
 
167
- **User column layout + filter reload:** `storageKey` persists layout (all companies), filter values, sort, and paging (`filterStorageScope` suffixes filters and the view key, e.g. company id) to `localStorage`. Sort icons follow `url.parameters.sort`. Page size is applied to `.pagesize` before the collection is created; offset is applied before the first `loadFromRemote`. `features.columnChooser` adds a gear in the trailing `th.kgrid-row-actions` that opens a Columns panel (reorder + hide) and keeps that column visible. The open panel uses `position:fixed` (like kebab menus) so card/`overflow` hosts do not clip it. Schema `hidden` columns stay out of the chooser. `defaultHidden: true` starts the column hidden (`display:none`, omitted from `<colgroup>`) but still listed in the chooser. `locked: true` columns cannot be hidden. Hidden columns keep filter/insert/update inputs in the DOM. `grid.getLayout()` / `setLayout()` / `resetLayout()` (reset restores `defaultHidden`, not “all visible”).
167
+ **User column layout + filter reload:** `storageKey` persists layout (all companies), filter values, sort, and paging (`filterStorageScope` suffixes filters and the view key, e.g. company id) to `localStorage`. Sort icons follow `url.parameters.sort`. Page size is applied to `.pagesize` before the collection is created; offset is applied before the first `loadFromRemote`. `features.columnChooser` adds a gear in the trailing `th.kgrid-row-actions` that opens a Columns panel (reorder + hide) and keeps that column visible. `features.csvExport` adds two buttons to that panel: dbAPI `format=csv` for every field (include kept, no `fields[]`) or for the visible columns only (`fields[type]`, `include` removed). A column with `export: false` is left out of the visible set; `exportField` renames it. The request copies the collection URL, sets `page[type][limit]` to `csvExportLimit` (10000) and offset 0. The open panel uses `position:fixed` (like kebab menus) so card/`overflow` hosts do not clip it. Schema `hidden` columns stay out of the chooser. `defaultHidden: true` starts the column hidden (`display:none`, omitted from `<colgroup>`) but still listed in the chooser. `locked: true` columns cannot be hidden. Hidden columns keep filter/insert/update inputs in the DOM. `grid.getLayout()` / `setLayout()` / `resetLayout()` (reset restores `defaultHidden`, not “all visible”).
168
168
 
169
169
  ---
170
170
 
package/docs/api.md CHANGED
@@ -119,7 +119,7 @@ See **[table-shell.md](table-shell.md)** for structure, placeholders, and custom
119
119
 
120
120
  | Symbol | Description |
121
121
  |--------|-------------|
122
- | `KGrid.hasActionColumn(options)` | `true` when `features.create`, `features.columnChooser`, or resolved `rowActions` / shimmed delete·clone / `features.update` (save/cancel) |
122
+ | `KGrid.hasActionColumn(options)` | `true` when `features.create`, `features.columnChooser`, `features.csvExport`, or resolved `rowActions` / shimmed delete·clone / `features.update` (save/cancel) |
123
123
  | `KGrid.actionColumnWidth(options)` | Compact CSS width for the actions column under `table-layout: fixed` |
124
124
  | `KGrid.resolveRowActions(options, handlers?)` | Normalize `rowActions` (or shim from features); caches on `options` |
125
125
  | `KGrid.renderRowActions($td, options, formId?)` | Fill a data-row actions cell (buttons or kebab dropdown) |
@@ -157,6 +157,7 @@ features: {
157
157
  delete: false,
158
158
  clone: false,
159
159
  columnChooser: false,
160
+ csvExport: false,
160
161
  selection: false,
161
162
  }
162
163
  ```
@@ -168,6 +169,10 @@ features: {
168
169
  | `storageKey` | `string` | Persist layout (order + user-hidden), filter values, sort, and paging. Layout key: `kgrid:{storageKey}:layout`. Filters: `kgrid:{storageKey}:filters`. Sort and page size / offset: `kgrid:{storageKey}:view`. Scope suffix applies to filters and view, not layout. |
169
170
  | `filterStorageScope` | `string` | Suffix for saved filters, sort, and paging (e.g. company id). Column layout is shared across scopes. |
170
171
  | `features.columnChooser` | `boolean` | Columns panel (checkbox + drag) opened from a gear icon in the trailing `th.kgrid-row-actions`. Ensures the actions column exists. Works without `storageKey` (session only). |
172
+ | `features.csvExport` | `boolean` | Two actions in that panel. Both download dbAPI `format=csv` for the current filter and sort, with `page[type][limit]` raised to `csvExportLimit` (default 10000) and offset 0. **All fields** leaves `include` in place and sends no `fields[...]`. **Visible fields** sends `fields[type]` for the columns on screen, in that order, and drops `include`. |
173
+ | `csvExportVisibleLabel` / `csvExportAllLabel` | `string` | Button labels. |
174
+ | `csvExportLimit` | `number` | Page limit on the CSV request (default `10000`). |
175
+ | `csvFileName` | `string` | Download name (default `{type}.csv`). |
171
176
  | `features.selection` | `boolean` | Leading checkbox column. The header checkbox toggles every row on the current page. Selected ids survive filter, sort, and paging. The column stays first and out of the column chooser. |
172
177
  | `selection` | `{ meta(item, $row) }` | Extra fields stored with each selected id. `id` is always the record id. |
173
178
  | `selectionAllLabel` | `string` | Header checkbox `aria-label` (default `"Toggle all"`). |
@@ -184,6 +189,8 @@ Column flags:
184
189
  | `defaultHidden: true` | Start collapsed (`userHidden`); still in the chooser so users can show it. Ignored when `locked`. Reset columns restores this default. |
185
190
  | `locked: true` | Visible; chooser cannot hide it (still reorderable). Use on required list fields such as name. |
186
191
  | `userHidden` | Runtime only — set via chooser / `setLayout` |
192
+ | `export: false` | Omit this column from the visible-fields CSV. The name is not a selectable field. |
193
+ | `exportField` | Field name sent in `fields[type]` instead of `name` |
187
194
 
188
195
  User-hidden columns use **`display: none`** on cells and are **omitted from `<colgroup>`**. `table-layout: fixed` maps each participating cell to the next `<col>`; a leftover zero-width col remaps every following column (letter-stacked headers, blank gaps). Chrome also treats `visibility: collapse` as `hidden`, so that is not a substitute. Filter/insert/update controls stay in the DOM. Filter values on hidden columns remain until Reset.
189
196
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logimaxx/kgrid",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "KGrid — declarative data table for KViews (filter, sort, paging, inline CRUD). Proprietary — Logimaxx System SRL.",
5
5
  "main": "dist/kgrid.js",
6
6
  "homepage": "https://logimaxx.ro",
@@ -18,8 +18,44 @@
18
18
  }).length;
19
19
  }
20
20
 
21
+ function bindCsvExport($panel, options, api) {
22
+ $panel
23
+ .off("click.kgridCsv")
24
+ .on("click.kgridCsv", ".kgrid-csv-export-visible, .kgrid-csv-export-all", function () {
25
+ const button = this;
26
+ const mode = button.classList.contains("kgrid-csv-export-visible") ? "visible" : "all";
27
+ button.disabled = true;
28
+ Promise.resolve(CT.downloadCsv(options, api, mode))
29
+ .catch(function (err) {
30
+ CT.onError(err);
31
+ })
32
+ .finally(function () {
33
+ button.disabled = false;
34
+ });
35
+ });
36
+ }
37
+
21
38
  CT.renderColumnChooserPanel = function ($panel, options, api) {
22
39
  $panel.empty();
40
+ const chooser = !!(options.features && options.features.columnChooser);
41
+ const csv = !!(options.features && options.features.csvExport);
42
+ if (csv) {
43
+ const $export = $("<div>").addClass("kgrid-column-chooser-export").appendTo($panel);
44
+ $("<button>")
45
+ .attr("type", "button")
46
+ .addClass("btn btn-sm btn-outline-secondary kgrid-csv-export-visible")
47
+ .text(options.csvExportVisibleLabel || "Export CSV — visible fields")
48
+ .appendTo($export);
49
+ $("<button>")
50
+ .attr("type", "button")
51
+ .addClass("btn btn-sm btn-outline-secondary kgrid-csv-export-all")
52
+ .text(options.csvExportAllLabel || "Export CSV — all fields")
53
+ .appendTo($export);
54
+ bindCsvExport($panel, options, api);
55
+ }
56
+ if (!chooser) {
57
+ return;
58
+ }
23
59
  const $list = $("<ul>").addClass("kgrid-column-chooser-list").appendTo($panel);
24
60
  CT.chooserColumns(options.columns).forEach(function (col) {
25
61
  const $li = $("<li>")
@@ -99,7 +135,9 @@
99
135
  };
100
136
 
101
137
  CT.setupColumnChooser = function ($host, options, api) {
102
- if (!options.features || !options.features.columnChooser) {
138
+ const chooser = !!(options.features && options.features.columnChooser);
139
+ const csv = !!(options.features && options.features.csvExport);
140
+ if (!chooser && !csv) {
103
141
  return;
104
142
  }
105
143
  const $shell = CT.getTableInteractionHost($host);
package/src/constants.js CHANGED
@@ -17,6 +17,8 @@
17
17
  /** @deprecated use rowActions items [{ action: "clone" }] */
18
18
  "clone": false,
19
19
  "columnChooser": false,
20
+ /** dbAPI CSV from the column panel: all fields, or the visible columns. */
21
+ "csvExport": false,
20
22
  /** Leading checkbox column. Header checkbox toggles the current page. */
21
23
  "selection": false
22
24
  },
@@ -38,6 +40,10 @@
38
40
  filterStorageScope: null,
39
41
  columnChooserLabel: "Columns",
40
42
  columnChooserResetLabel: "Reset columns",
43
+ csvExportVisibleLabel: "Export CSV — visible fields",
44
+ csvExportAllLabel: "Export CSV — all fields",
45
+ /** Row cap sent as page[type][limit] on the CSV request. */
46
+ csvExportLimit: 10000,
41
47
  "defaultInteraction": "view",
42
48
  "insertFormRow": {
43
49
  "position": "top"
@@ -80,6 +86,11 @@
80
86
  defaultHidden: false,
81
87
  /** Runtime: user hid this column via chooser. Not a schema flag. */
82
88
  userHidden: false,
89
+ /**
90
+ * Sparse CSV: false omits the column. A string exports that field name
91
+ * instead of `name` (the column name is still the chooser key).
92
+ */
93
+ export: true,
83
94
  /** CSS class(es) on header/filter/data/insert cells (alias: columnClass) */
84
95
  class: null,
85
96
  columnClass: null,
@@ -0,0 +1,134 @@
1
+ /**
2
+ * dbAPI CSV export from the column chooser.
3
+ * Full export keeps the collection query (filters, sort, include).
4
+ * Visible export sends fields[type] for the columns on screen and drops include,
5
+ * so related resources are not appended in full.
6
+ */
7
+ (function (CT) {
8
+ CT.csvExportFields = function (columns) {
9
+ return CT.layoutVisibleColumns(columns)
10
+ .filter(function (col) {
11
+ return (
12
+ col &&
13
+ col.name &&
14
+ !col.selection &&
15
+ col.name !== CT.SELECTION_COLUMN_NAME &&
16
+ col.export !== false
17
+ );
18
+ })
19
+ .map(function (col) {
20
+ return typeof col.exportField === "string" && col.exportField
21
+ ? col.exportField
22
+ : col.name;
23
+ });
24
+ };
25
+
26
+ /**
27
+ * @param {string} href collection URL (relative or absolute)
28
+ * @param {{ type: string, mode: "all"|"visible", fields?: string[], limit?: number }} spec
29
+ * @returns {string} same shape as href (path+query, or absolute)
30
+ */
31
+ CT.buildCsvExportUrl = function (href, spec) {
32
+ const parsed = new window.URL(href, "http://kgrid.local");
33
+ const type = spec && spec.type;
34
+ const limit = spec && spec.limit != null ? spec.limit : 10000;
35
+ parsed.searchParams.set("format", "csv");
36
+ parsed.searchParams.set("includetablehead", "true");
37
+ if (type) {
38
+ parsed.searchParams.set("page[" + type + "][limit]", String(limit));
39
+ parsed.searchParams.set("page[" + type + "][offset]", "0");
40
+ }
41
+ const dropFields = [];
42
+ parsed.searchParams.forEach(function (_value, key) {
43
+ if (key.indexOf("fields[") === 0) {
44
+ dropFields.push(key);
45
+ }
46
+ });
47
+ dropFields.forEach(function (key) {
48
+ parsed.searchParams.delete(key);
49
+ });
50
+ if (spec && spec.mode === "visible") {
51
+ parsed.searchParams.delete("include");
52
+ if (type && spec.fields && spec.fields.length) {
53
+ parsed.searchParams.set("fields[" + type + "]", spec.fields.join(","));
54
+ }
55
+ }
56
+ if (/^https?:\/\//i.test(href)) {
57
+ return parsed.toString();
58
+ }
59
+ return parsed.pathname + parsed.search;
60
+ };
61
+
62
+ CT.resolveApiUrl = function (href, kviews) {
63
+ if (href == null || href === "") {
64
+ return href;
65
+ }
66
+ const s = String(href);
67
+ if (/^https?:\/\//i.test(s) || s.startsWith("//")) {
68
+ return s;
69
+ }
70
+ const base = (kviews && (kviews.baseUrl || kviews.basePath)) || "";
71
+ if (!base) {
72
+ return s;
73
+ }
74
+ const baseNorm = String(base).replace(/\/+$/, "");
75
+ const pathNorm = s.replace(/^\/+/, "");
76
+ return pathNorm ? baseNorm + "/" + pathNorm : baseNorm + "/";
77
+ };
78
+
79
+ function csvErrorMessage(response, data) {
80
+ if (data && data.errors && data.errors[0]) {
81
+ return data.errors[0].detail || data.errors[0].title || "";
82
+ }
83
+ if (data && data.error) {
84
+ return String(data.error);
85
+ }
86
+ return "CSV export failed (" + response.status + ")";
87
+ }
88
+
89
+ CT.downloadCsv = function (options, api, mode) {
90
+ const instance = api && api.instance;
91
+ const href =
92
+ instance && instance.url && instance.url.toString ? instance.url.toString() : "";
93
+ if (!href) {
94
+ return Promise.reject(new Error("CSV export requires a collection URL"));
95
+ }
96
+ const type = options && options.type;
97
+ if (!type) {
98
+ return Promise.reject(new Error("CSV export requires a resource type"));
99
+ }
100
+ const fields = mode === "visible" ? CT.csvExportFields(options.columns) : null;
101
+ if (mode === "visible" && (!fields || !fields.length)) {
102
+ return Promise.reject(new Error("No visible columns to export"));
103
+ }
104
+ const built = CT.buildCsvExportUrl(href, {
105
+ type: type,
106
+ mode: mode === "visible" ? "visible" : "all",
107
+ fields: fields,
108
+ limit: options.csvExportLimit,
109
+ });
110
+ const requestUrl = CT.resolveApiUrl(built, CT.getKViews(options.kviews));
111
+ return window.fetch(requestUrl).then(function (response) {
112
+ if (!response.ok) {
113
+ return response
114
+ .json()
115
+ .catch(function () {
116
+ return null;
117
+ })
118
+ .then(function (data) {
119
+ throw new Error(csvErrorMessage(response, data));
120
+ });
121
+ }
122
+ return response.blob().then(function (blob) {
123
+ const link = document.createElement("a");
124
+ const objectUrl = window.URL.createObjectURL(blob);
125
+ link.href = objectUrl;
126
+ link.download = options.csvFileName || type + ".csv";
127
+ document.body.appendChild(link);
128
+ link.click();
129
+ link.remove();
130
+ window.URL.revokeObjectURL(objectUrl);
131
+ });
132
+ });
133
+ };
134
+ })(window.KGrid);
@@ -216,7 +216,7 @@
216
216
  */
217
217
  CT.hasActionColumn = function (options) {
218
218
  const f = options && options.features;
219
- if (f && (f.create || f.columnChooser)) {
219
+ if (f && (f.create || f.columnChooser || f.csvExport)) {
220
220
  return true;
221
221
  }
222
222
  const ra = CT.resolveRowActions(options);
package/styles/table.css CHANGED
@@ -438,6 +438,15 @@ th.kgrid-row-actions {
438
438
  .kgrid-column-chooser-reset {
439
439
  width: 100%;
440
440
  }
441
+ .kgrid-column-chooser-export {
442
+ display: flex;
443
+ flex-direction: column;
444
+ gap: 0.35rem;
445
+ margin-bottom: 0.5rem;
446
+ }
447
+ .kgrid-column-chooser-export .btn {
448
+ width: 100%;
449
+ }
441
450
 
442
451
  /* multi_select: checkbox list (dropdown in filter row) */
443
452
  .kgrid-multi-select {