@liedekef/ftable 1.1.22 → 1.1.23
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/ftable.esm.js +4 -4
- package/ftable.js +4 -4
- package/ftable.min.js +1 -1
- package/ftable.umd.js +4 -4
- package/package.json +1 -1
package/ftable.esm.js
CHANGED
|
@@ -614,7 +614,7 @@ class FTableFormBuilder {
|
|
|
614
614
|
await Promise.all(promises);
|
|
615
615
|
}*/
|
|
616
616
|
|
|
617
|
-
async resolveNonDependantFieldOptions(fieldValues) {
|
|
617
|
+
async resolveNonDependantFieldOptions(fieldValues, formType) {
|
|
618
618
|
// Store original options before first resolution
|
|
619
619
|
this.storeOriginalFieldOptions();
|
|
620
620
|
|
|
@@ -627,8 +627,8 @@ class FTableFormBuilder {
|
|
|
627
627
|
|
|
628
628
|
if (originalOptions && (typeof originalOptions === 'function' || typeof originalOptions === 'string')) {
|
|
629
629
|
try {
|
|
630
|
-
// Pass fieldValues as dependedValues for dependency resolution
|
|
631
|
-
const params = { dependedValues: fieldValues };
|
|
630
|
+
// Pass fieldValues as dependedValues for dependency resolution (but record contains everything too ...)
|
|
631
|
+
const params = { dependedValues: fieldValues, source: formType, record: fieldValues };
|
|
632
632
|
|
|
633
633
|
// Resolve using original options, not the possibly already-resolved ones
|
|
634
634
|
const tempField = { ...field, options: originalOptions };
|
|
@@ -648,7 +648,7 @@ class FTableFormBuilder {
|
|
|
648
648
|
|
|
649
649
|
// Pre-resolve all options for fields depending on nothing, the others are handled down the road when dependancies are calculated
|
|
650
650
|
//await this.resolveAllFieldOptions(record);
|
|
651
|
-
await this.resolveNonDependantFieldOptions(record);
|
|
651
|
+
await this.resolveNonDependantFieldOptions(record, formType);
|
|
652
652
|
|
|
653
653
|
const form = FTableDOMHelper.create('form', {
|
|
654
654
|
className: `ftable-dialog-form ftable-${formType}-form`
|
package/ftable.js
CHANGED
|
@@ -619,7 +619,7 @@ class FTableFormBuilder {
|
|
|
619
619
|
await Promise.all(promises);
|
|
620
620
|
}*/
|
|
621
621
|
|
|
622
|
-
async resolveNonDependantFieldOptions(fieldValues) {
|
|
622
|
+
async resolveNonDependantFieldOptions(fieldValues, formType) {
|
|
623
623
|
// Store original options before first resolution
|
|
624
624
|
this.storeOriginalFieldOptions();
|
|
625
625
|
|
|
@@ -632,8 +632,8 @@ class FTableFormBuilder {
|
|
|
632
632
|
|
|
633
633
|
if (originalOptions && (typeof originalOptions === 'function' || typeof originalOptions === 'string')) {
|
|
634
634
|
try {
|
|
635
|
-
// Pass fieldValues as dependedValues for dependency resolution
|
|
636
|
-
const params = { dependedValues: fieldValues };
|
|
635
|
+
// Pass fieldValues as dependedValues for dependency resolution (but record contains everything too ...)
|
|
636
|
+
const params = { dependedValues: fieldValues, source: formType, record: fieldValues };
|
|
637
637
|
|
|
638
638
|
// Resolve using original options, not the possibly already-resolved ones
|
|
639
639
|
const tempField = { ...field, options: originalOptions };
|
|
@@ -653,7 +653,7 @@ class FTableFormBuilder {
|
|
|
653
653
|
|
|
654
654
|
// Pre-resolve all options for fields depending on nothing, the others are handled down the road when dependancies are calculated
|
|
655
655
|
//await this.resolveAllFieldOptions(record);
|
|
656
|
-
await this.resolveNonDependantFieldOptions(record);
|
|
656
|
+
await this.resolveNonDependantFieldOptions(record, formType);
|
|
657
657
|
|
|
658
658
|
const form = FTableDOMHelper.create('form', {
|
|
659
659
|
className: `ftable-dialog-form ftable-${formType}-form`
|
package/ftable.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
((e,t)=>{"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).FTable=t()})(this,function(){let s={serverCommunicationError:"An error occurred while communicating to the server.",loadingMessage:"Loading records...",noDataAvailable:"No data available!",addNewRecord:"Add new record",editRecord:"Edit record",areYouSure:"Are you sure?",deleteConfirmation:"This record will be deleted. Are you sure?",save:"Save",saving:"Saving",cancel:"Cancel",deleteText:"Delete",deleting:"Deleting",error:"An error has occured",close:"Close",cannotLoadOptionsFor:"Cannot load options for field {0}!",pagingInfo:"Showing {0}-{1} of {2}",canNotDeletedRecords:"Can not delete {0} of {1} records!",deleteProgress:"Deleting {0} of {1} records, processing...",pageSizeChangeLabel:"Row count",gotoPageLabel:"Go to page",sortingInfoPrefix:"Sorting applied: ",sortingInfoSuffix:"",ascending:"Ascending",descending:"Descending",sortingInfoNone:"No sorting applied",resetSorting:"Reset sorting",csvExport:"CSV",printTable:"🖨️ Print",cloneRecord:"Clone Record",resetTable:"Reset table",resetTableConfirm:"This will reset all columns, pagesize, sorting to their defaults. Do you want to continue?",resetSearch:"Reset"};class t{constructor(){this.cache=new Map}generateKey(e,t){return e+"?"+Object.keys(t||{}).sort().map(e=>e+"="+t[e]).join("&")}get(e,t){e=this.generateKey(e,t);return this.cache.get(e)}set(e,t,s){e=this.generateKey(e,t);this.cache.set(e,s)}clear(e=null,t=null){if(e)if(t){t=this.generateKey(e,t);this.cache.delete(t)}else{var s,a=e.split("?")[0];for([s]of this.cache)s.startsWith(a)&&this.cache.delete(s)}else this.cache.clear()}size(){return this.cache.size}}class a{static LOG_LEVELS={DEBUG:0,INFO:1,WARN:2,ERROR:3,NONE:4};constructor(e=a.LOG_LEVELS.WARN){this.level=e}log(t,e){var s;!window.console||t<this.level||(s=Object.keys(a.LOG_LEVELS).find(e=>a.LOG_LEVELS[e]===t),console.log(`fTable ${s}: `+e))}debug(e){this.log(a.LOG_LEVELS.DEBUG,e)}info(e){this.log(a.LOG_LEVELS.INFO,e)}warn(e){this.log(a.LOG_LEVELS.WARN,e)}error(e){this.log(a.LOG_LEVELS.ERROR,e)}}class u{static create(e,t={}){let s=document.createElement(e);return t.className&&(s.className=t.className),t.style&&(s.style.cssText=t.style),t.attributes&&Object.entries(t.attributes).forEach(([e,t])=>{s.setAttribute(e,t)}),t.text&&(s.textContent=t.text),t.html&&(s.innerHTML=t.html),t.parent&&t.parent.appendChild(s),s}static find(e,t=document){return t.querySelector(e)}static findAll(e,t=document){return Array.from(t.querySelectorAll(e))}static addClass(e,t){e.classList.add(...t.split(" "))}static removeClass(e,t){e.classList.remove(...t.split(" "))}static toggleClass(e,t){e.classList.toggle(t)}static show(e){e.style.display=""}static hide(e){e.style.display="none"}static escapeHtml(e){if(!e)return e;let t={"&":"&","<":"<",">":">",'"':""","'":"'"};return e.replace(/[&<>"']/g,e=>t[e])}}class l{static async request(e,t={}){var s={method:"GET",headers:{}},a={...s,...t};t.headers&&(a.headers={...s.headers,...t.headers});try{var i=await fetch(e,a);if(401===i.status)throw new Error("Unauthorized");if(!i.ok)throw new Error("HTTP error! status: "+i.status);var o=i.headers.get("content-type");if(o&&o.includes("application/json"))return await i.json();var r=await i.text();try{return JSON.parse(r)}catch{return{Result:"OK",Message:r}}}catch(e){throw e}}static async get(e,t={}){let a=new URL(e,window.location.href);return Object.entries(t).forEach(([e,s])=>{if(null!=s)if(Array.isArray(s)){let t=e.replace(/\[\]$/,"")+"[]";s.forEach(e=>{null!=e&&a.searchParams.append(t,e)})}else a.searchParams.append(e,s)}),this.request(a.toString(),{method:"GET",headers:{"Content-Type":"application/x-www-form-urlencoded"}})}static async post(e,t={}){e=new URL(e,window.location.href);let a=new FormData;return Object.entries(t).forEach(([e,s])=>{if(null!=s)if(Array.isArray(s)){let t=e.replace(/\[\]$/,"")+"[]";s.forEach(e=>{null!=e&&a.append(t,e)})}else a.append(e,s)}),this.request(e.toString(),{method:"POST",body:a})}}class i{constructor(e,t="localStorage"){this.prefix=e,this.method=t}set(e,t){var s,e=""+this.prefix+e;"localStorage"===this.method?localStorage.setItem(e,t):((s=new Date).setDate(s.getDate()+30),document.cookie=e+`=${t}; expires=${s.toUTCString()}; path=/`)}get(e){e=""+this.prefix+e;if("localStorage"===this.method)return localStorage.getItem(e);var t,s=e+"=";for(t of decodeURIComponent(document.cookie).split(";")){for(;" "===t.charAt(0);)t=t.substring(1);if(0===t.indexOf(s))return t.substring(s.length,t.length)}return null}remove(e){e=""+this.prefix+e;"localStorage"===this.method?localStorage.removeItem(e):document.cookie=e+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"}generatePrefix(e,t){e=e?e+"#":"";return"ftable#"+(t=>{let s=0;if(0!==t.length)for(let e=0;e<t.length;e++){var a=t.charCodeAt(e);s=(s<<5)-s+a,s&=s}return s})(e+=t.join("$")+"#c"+t.length)}}class e{constructor(e={}){this.options={title:"Modal",content:"",buttons:[],className:"ftable-modal",parent:document.body,...e},this.overlay=null,this.modal=null,this.isOpen=!1}create(){this.overlay=u.create("div",{className:"ftable-modal-overlay",parent:this.options.parent}),this.modal=u.create("div",{className:"ftable-modal "+this.options.className,parent:this.overlay});u.create("h2",{className:"ftable-modal-header",text:this.options.title,parent:this.modal});u.create("span",{className:"ftable-modal-close",html:"×",parent:this.modal}).addEventListener("click",()=>this.close());var e=u.create("div",{className:"ftable-modal-body",parent:this.modal});if("string"==typeof this.options.content?e.innerHTML=this.options.content:e.appendChild(this.options.content),0<this.options.buttons.length){let s=u.create("div",{className:"ftable-modal-footer",parent:this.modal});this.options.buttons.forEach(e=>{var t=u.create("button",{className:"ftable-dialog-button "+(e.className||""),html:`<span>${e.text}</span>`,parent:s});e.onClick&&t.addEventListener("click",e.onClick)})}return this.overlay.addEventListener("click",e=>{e.target===this.overlay&&this.close()}),this.hide(),this}show(){return this.modal||this.create(),this.overlay.style.display="flex",this.isOpen=!0,this}hide(){return this.overlay&&(this.overlay.style.display="none"),this.isOpen=!1,this}close(){return this.hide(),this.options.onClose&&this.options.onClose(),this}destroy(){return this.overlay&&this.overlay.remove(),this.isOpen=!1,this}setContent(e){this.options.content=e;var t=this.modal.querySelector(".ftable-modal-body");t&&(t.innerHTML="","string"==typeof e?t.innerHTML=e:t.appendChild(e))}}class o{constructor(e){this.options=e,this.dependencies=new Map,this.optionsCache=new t,this.originalFieldOptions=new Map}storeOriginalFieldOptions(){0<this.originalFieldOptions.size||Object.entries(this.options.fields).forEach(([e,t])=>{!t.options||"function"!=typeof t.options&&"string"!=typeof t.options||this.originalFieldOptions.set(e,t.options)})}shouldIncludeField(e,t){return"create"===t?!1!==e.create&&!(!0===e.key&&!0!==e.create):"edit"!==t||!1!==e.edit}createFieldContainer(e,t,s,a){var i=u.create("div",{className:"ftable-input-field-container",attributes:{id:"ftable-input-field-container-div-"+e}}),t=(u.create("div",{className:"ftable-input-label",text:t.inputTitle||t.title,parent:i}),this.createInput(e,t,s[e],a));return i.appendChild(t),i}async resolveNonDependantFieldOptions(r){this.storeOriginalFieldOptions();var e=Object.entries(this.options.fields).map(async([t,e])=>{if(!e.dependsOn){var s=this.originalFieldOptions.get(t)||e.options;if(s&&("function"==typeof s||"string"==typeof s))try{var a={dependedValues:r},i={...e,options:s},o=await this.resolveOptions(i,a);e.options=o}catch(e){console.error(`Failed to resolve options for ${t}:`,e)}}});await Promise.all(e)}async createForm(s="create",a={}){this.currentFormRecord=a,await this.resolveNonDependantFieldOptions(a);let i=u.create("form",{className:`ftable-dialog-form ftable-${s}-form`});return this.buildDependencyMap(),Object.entries(this.options.fields).forEach(([e,t])=>{this.shouldIncludeField(t,s)&&(e=this.createFieldContainer(e,t,a,s),i.appendChild(e))}),this.setupDependencyListeners(i),i}buildDependencyMap(){this.dependencies.clear(),Object.entries(this.options.fields).forEach(([t,s])=>{if(s.dependsOn){let e;"string"==typeof s.dependsOn&&(e=s.dependsOn.split(",").map(e=>e.trim()).filter(e=>e)).forEach(e=>{this.dependencies.has(e)||this.dependencies.set(e,[]),this.dependencies.get(e).push(t)})}})}setupDependencyListeners(s){Array.from(this.dependencies.keys()).forEach(e=>{var t=s.querySelector(`[name="${e}"]`);t&&t.addEventListener("change",()=>{this.handleDependencyChange(s,e)})}),this.handleDependencyChange(s)}async resolveOptions(t,e={}){if(!t.options)return[];if(Array.isArray(t.options)||"object"==typeof t.options)return t.options;let s,a=!1;e={...e,clearCache:()=>{a=!0}};if("function"==typeof t.options)s=await t.options(e);else{if("string"!=typeof t.options)return[];s=t.options}e=s&&"object"==typeof s&&s.url,t=e?s.url:s;if(a=e&&void 0!==s.noCache?s.noCache:a,"string"!=typeof t)return[];if(!a){e=this.optionsCache.get(t,{});if(e)return e}try{var i=this.options.forcePost?await l.post(t):await l.get(t),o=i.Options||i.options||i||[];return a||this.optionsCache.set(t,{},o),o}catch(e){return console.error(`Failed to load options from ${t}:`,e),[]}}clearOptionsCache(e=null,t=null){this.optionsCache.clear(e,t)}async handleDependencyChange(e,s=""){var t,a,i={};for([t,a]of Object.entries(this.options.fields)){var o=e.querySelector(`[name="${t}"]`);o&&("checkbox"===o.type?i[t]=o.checked?"1":"0":i[t]=o.value)}var r,n,l=e.classList.contains("ftable-create-form")?"create":"edit",c={record:this.currentFormRecord||{},source:l,form:e,dependedValues:i};for([r,n]of Object.entries(this.options.fields))if(n.dependsOn){if(""!==s)if(!n.dependsOn.split(",").map(e=>e.trim()).filter(e=>e).includes(s))continue;let t=e.querySelector(`[name="${r}"]`);if(t&&this.shouldIncludeField(n,l))try{"SELECT"===t.tagName?t.innerHTML='<option value="">Loading...</option>':"INPUT"===t.tagName&&t.list&&(d=document.getElementById(t.list.id))&&(d.innerHTML="");var d,h={...c,dependsOnField:n.dependsOn,dependsOnValue:i[n.dependsOn]},p=this.originalFieldOptions.get(r)||n.options,u={...n,options:p},m=await this.resolveOptions(u,h);"SELECT"===t.tagName?this.populateSelectOptions(t,m,""):"INPUT"===t.tagName&&t.list&&this.populateDatalistOptions(t.list,m),setTimeout(()=>{t.dispatchEvent(new Event("change",{bubbles:!0}))},0)}catch(e){console.error(`Error loading options for ${r}:`,e),"SELECT"===t.tagName&&(t.innerHTML='<option value="">Error</option>')}}}parseInputAttributes(e){if("string"!=typeof e)return e||{};for(var t={},s=/(\w+)(?:=("[^"]*"|'[^']*'|\S+))?/g;null!==(i=s.exec(e));){var a=i[1],i=i[2]?i[2].replace(/^["']|["']$/g,""):"";t[a]=""===i?"true":i}return t}createInput(e,t,s,a){var i=u.create("div",{className:`ftable-input ftable-${t.type||"text"}-input`});let o;switch(null==s&&(s=t.defaultValue),!t.type&&t.options&&(t.type="select"),t.type){case"hidden":o=this.createHiddenInput(e,t,s);break;case"textarea":o=this.createTextarea(e,t,s);break;case"select":o=this.createSelect(e,t,s);break;case"checkbox":o=this.createCheckbox(e,t,s);break;case"radio":o=this.createRadioGroup(e,t,s);break;case"datalist":o=this.createDatalistInput(e,t,s);break;case"file":o=this.createFileInput(e,t,s);break;case"date":case"datetime-local":o=this.createDateInput(e,t,s);break;default:o=this.createTypedInput(e,t,s)}return"function"==typeof t.input?(a={field:t,record:this.currentFormRecord,inputField:o,formType:a},"string"==typeof(a=t.input(a))?i.innerHTML=a:a instanceof Node?i.appendChild(a):i.appendChild(o)):i.appendChild(o),t.explain&&u.create("div",{className:"ftable-field-explain",html:`<small>${t.explain}</small>`,parent:i}),i}createDateInput(e,s,a){if("undefined"==typeof FDatepicker)return createTypedInput(e,s,a);{var i=s.dateFormat||this.options.defaultDateFormat,o=document.createElement("div"),r=u.create("input",{attributes:{id:"real-"+e,type:"hidden",value:a||"",name:e}});let t=u.create("input",{className:s.inputClass||"datepicker-input",attributes:{id:"Edit-"+e,type:"text","data-date":a,placeholder:s.placeholder||"",readOnly:!0}});s.inputAttributes&&Object.keys(s.inputAttributes).forEach(e=>{t.setAttribute(e,s.inputAttributes[e])}),o.appendChild(r),o.appendChild(t);new FDatepicker(t,{format:i,altField:"real-"+e,altFormat:"Y-m-d"});return o}}createTypedInput(e,t,s){var a,s={type:t.type||"text",id:"Edit-"+e,placeholder:t.placeholder||"",value:s||""};let i=e,o=(t.inputAttributes&&(a=this.parseInputAttributes(t.inputAttributes),Object.assign(s,a),void 0!==a.multiple&&!1!==a.multiple)&&(i=e+"[]"),s.name=i,u.create("input",{className:t.inputClass||"",attributes:s}));return o.addEventListener("keypress",e=>{if(13===(e.keyCode||e.which))return e.preventDefault(),o.dispatchEvent(new Event("change",{bubbles:!0})),!1}),o}createDatalistInput(e,t,s){s=u.create("input",{attributes:{type:"text",name:e,id:"Edit-"+e,placeholder:t.placeholder||"",value:s||"",class:t.inputClass||"",list:e+"-datalist"}}),e=u.create("datalist",{attributes:{id:e+"-datalist"}});return t.options&&this.populateDatalistOptions(e,t.options),document.body.appendChild(e),s.datalistElement=e,s}populateDatalistOptions(s,e){s.innerHTML="",Array.isArray(e)?e.forEach(e=>{u.create("option",{attributes:{value:e.Value||e.value||e},text:e.DisplayText||e.text||e,parent:s})}):"object"==typeof e&&Object.entries(e).forEach(([e,t])=>{u.create("option",{attributes:{value:e},text:t,parent:s})})}createHiddenInput(e,t,s){e={type:"hidden",name:e,id:"Edit-"+e,value:s||""};return t.inputAttributes&&(s=this.parseInputAttributes(t.inputAttributes),Object.assign(e,s)),u.create("input",{attributes:e})}createTextarea(e,t,s){e={name:e,id:"Edit-"+e,class:t.inputClass||"",placeholder:t.placeholder||""},t.inputAttributes&&(t=this.parseInputAttributes(t.inputAttributes),Object.assign(e,t)),t=u.create("textarea",{attributes:e});return t.value=s||"",t}createSelect(e,t,s){var e={name:e,id:"Edit-"+e,class:t.inputClass||""},a=(t.inputAttributes&&(a=this.parseInputAttributes(t.inputAttributes),Object.assign(e,a)),u.create("select",{attributes:e}));return t.options&&this.populateSelectOptions(a,t.options,s),a}createRadioGroup(o,r,n){let l=u.create("div",{className:"ftable-radio-group"});return r.options&&(Array.isArray(r.options)?r.options:"object"==typeof r.options?Object.entries(r.options).map(([e,t])=>({Value:e,DisplayText:t})):[]).forEach((e,t)=>{var s=u.create("div",{className:"ftable-radio-wrapper",parent:l}),a=o+"_"+t,i={type:"radio",name:o,id:a,value:e.Value||e.value||e,class:r.inputClass||""},t=(r.required&&0===t&&(i.required="required"),r.disabled&&(i.disabled="disabled"),r.inputAttributes&&(t=this.parseInputAttributes(r.inputAttributes),Object.assign(attributes,t)),u.create("input",{attributes:i,parent:s}));i.value===n&&(t.checked=!0),u.create("label",{attributes:{for:a},text:e.DisplayText||e.text||e,parent:s})}),l}createCheckbox(e,t,s){var a=u.create("div",{className:"ftable-yesno-check-wrapper"}),s=[1,"1",!0,"true"].includes(s);let i="No",o="Yes";return t.values&&"object"==typeof t.values&&(void 0!==t.values[0]&&(i=t.values[0]),void 0!==t.values[1])&&(o=t.values[1]),u.create("input",{className:["ftable-yesno-check-input",t.inputClass||""].filter(Boolean).join(" "),attributes:{type:"checkbox",name:e,id:"Edit-"+e,value:"1"},parent:a}).checked=s,t.label?u.create("label",{className:"ftable-yesno-check-fixedlabel",attributes:{for:"Edit-"+e},text:t.label,parent:a}):u.create("label",{className:"ftable-yesno-check-text",attributes:{for:"Edit-"+e,"data-yes":o,"data-no":i},parent:a}),a}populateSelectOptions(a,e,i){a.innerHTML="",Array.isArray(e)?e.forEach(e=>{var t=void 0!==e.Value?e.Value:void 0!==e.value?e.value:e;let s=u.create("option",{attributes:{value:t},text:e.DisplayText||e.text||e,parent:a});e.Data&&"object"==typeof e.Data&&Object.entries(e.Data).forEach(([e,t])=>{s.setAttribute("data-"+e,t)}),s.value==i&&(s.selected=!0)}):"object"==typeof e&&Object.entries(e).forEach(([e,t])=>{t=u.create("option",{attributes:{value:e},text:t,parent:a});e==i&&(t.selected=!0)})}createFileInput(e,t,s){var a={type:"file",id:"Edit-"+e,class:t.inputClass||""};let i=e;return t.inputAttributes&&(t=this.parseInputAttributes(t.inputAttributes),Object.assign(a,t),void 0!==t.multiple&&!1!==t.multiple)&&(i=e+"[]"),a.name=i,u.create("input",{attributes:a})}}class r extends class{constructor(){this.events={}}on(e,t){return this.events[e]||(this.events[e]=[]),this.events[e].push(t),this}once(t,s){let a=(...e)=>{this.off(t,a),s.apply(this,e)};return a.fn=s,this.on(t,a),this}emit(e,t={}){return this.events[e]&&this.events[e].forEach(e=>e(t)),this}off(e,t){return this.events[e]&&(this.events[e]=this.events[e].filter(e=>e!==t)),this}}{constructor(e,t={}){if(super(),this.element="string"==typeof e?document.querySelector(e):e,this.element){if(this.element.ftableInstance)return this.element.ftableInstance;this.options=this.mergeOptions(t),this.verifyOptions(),this.logger=new a(this.options.logLevel),this.userPrefs=new i("",this.options.saveUserPreferencesMethod),this.formBuilder=new o(this.options,this),this.state={records:[],totalRecordCount:0,currentPage:1,isLoading:!1,selectedRecords:new Set,sorting:[],searchQueries:{}},this.elements={},this.modals={},this.searchTimeout=null,this.lastSortEvent=null,this._recalculatedOnce=!1,(this.element.ftableInstance=this).init()}}mergeOptions(e){var t={tableId:void 0,logLevel:a.LOG_LEVELS.WARN,actions:{},fields:{},forcePost:!0,animationsEnabled:!0,loadingAnimationDelay:1e3,defaultDateLocale:"",defaultDateFormat:"Y-m-d",saveUserPreferences:!0,saveUserPreferencesMethod:"localStorage",defaultSorting:"",tableReset:!1,paging:!1,pageList:"normal",pageSize:10,pageSizes:[10,25,50,100,250,500],gotoPageArea:"combobox",sorting:!1,multiSorting:!1,multiSortingCtrlKey:!0,selecting:!1,multiselect:!1,openChildAsAccordion:!1,toolbarsearch:!1,toolbarreset:!0,searchDebounceMs:300,listCache:3e4,messages:{...s}};return this.deepMerge(t,e)}deepMerge(e,t){var s,a={...e};for(s in t)t[s]&&"object"==typeof t[s]&&!Array.isArray(t[s])?a[s]=this.deepMerge(a[s]||{},t[s]):a[s]=t[s];return a}verifyOptions(){this.options.pageSize&&!this.options.pageSizes.includes(this.options.pageSize)&&(this.options.pageSize=this.options.pageSizes[0])}static setMessages(e){Object.assign(s,e)}init(){this.processFieldDefinitions(),this.createMainStructure(),this.setupFTableUserPreferences(),this.createTable(),this.createModals(),this.options.paging&&this.createPagingUI(),this.resolveAsyncFieldOptions().then(()=>{setTimeout(()=>{this.refreshDisplayValues()},0)}).catch(console.error),this.bindEvents(),this.updateSortingHeaders(),this.renderSortingInfo(),this.initColumnWidths()}initColumnWidths(){var e=this.columnList.filter(e=>{e=this.options.fields[e];return"hidden"!==e.visibility&&"separator"!==e.visibility});let t=e.length;e.forEach(e=>{e=this.options.fields[e];e.width=e.width||100/t+"%"})}normalizeColumnWidths(){var e=this.elements.mainContainer,t=this.columnList.map(e=>({th:this.elements.table.querySelector(`[data-field-name="${e}"]`),field:this.options.fields[e]})).filter(e=>e.th&&"hidden"!==e.field.visibility&&"separator"!==e.field.visibility);if(0!==t.length){let s=e.offsetWidth,a=0;t.forEach(e=>{var t=e.th.offsetWidth/s*100;e.field.width=t+"%",e.th.style.width=e.field.width,a+=t})}}parseDefaultSorting(e){let o=[];return e&&"string"==typeof e&&e.split(",").forEach(s=>{s=s.trim();if(s){var a=s.toUpperCase().indexOf(" DESC"),i=s.toUpperCase().indexOf(" ASC");let e="ASC",t=s;e=0<a?(t=s.slice(0,a).trim(),"DESC"):(t=(0<i?s.slice(0,i):s).trim(),"ASC");a=this.options.fields[t];a&&!1!==a.sorting&&o.push({fieldName:t,direction:e})}}),o}addEssentialCSS(){var e;document.querySelector("#ftable-essential-css")||((e=document.createElement("style")).id="ftable-essential-css",e.textContent=`
|
|
1
|
+
((e,t)=>{"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).FTable=t()})(this,function(){let s={serverCommunicationError:"An error occurred while communicating to the server.",loadingMessage:"Loading records...",noDataAvailable:"No data available!",addNewRecord:"Add new record",editRecord:"Edit record",areYouSure:"Are you sure?",deleteConfirmation:"This record will be deleted. Are you sure?",save:"Save",saving:"Saving",cancel:"Cancel",deleteText:"Delete",deleting:"Deleting",error:"An error has occured",close:"Close",cannotLoadOptionsFor:"Cannot load options for field {0}!",pagingInfo:"Showing {0}-{1} of {2}",canNotDeletedRecords:"Can not delete {0} of {1} records!",deleteProgress:"Deleting {0} of {1} records, processing...",pageSizeChangeLabel:"Row count",gotoPageLabel:"Go to page",sortingInfoPrefix:"Sorting applied: ",sortingInfoSuffix:"",ascending:"Ascending",descending:"Descending",sortingInfoNone:"No sorting applied",resetSorting:"Reset sorting",csvExport:"CSV",printTable:"🖨️ Print",cloneRecord:"Clone Record",resetTable:"Reset table",resetTableConfirm:"This will reset all columns, pagesize, sorting to their defaults. Do you want to continue?",resetSearch:"Reset"};class t{constructor(){this.cache=new Map}generateKey(e,t){return e+"?"+Object.keys(t||{}).sort().map(e=>e+"="+t[e]).join("&")}get(e,t){e=this.generateKey(e,t);return this.cache.get(e)}set(e,t,s){e=this.generateKey(e,t);this.cache.set(e,s)}clear(e=null,t=null){if(e)if(t){t=this.generateKey(e,t);this.cache.delete(t)}else{var s,a=e.split("?")[0];for([s]of this.cache)s.startsWith(a)&&this.cache.delete(s)}else this.cache.clear()}size(){return this.cache.size}}class a{static LOG_LEVELS={DEBUG:0,INFO:1,WARN:2,ERROR:3,NONE:4};constructor(e=a.LOG_LEVELS.WARN){this.level=e}log(t,e){var s;!window.console||t<this.level||(s=Object.keys(a.LOG_LEVELS).find(e=>a.LOG_LEVELS[e]===t),console.log(`fTable ${s}: `+e))}debug(e){this.log(a.LOG_LEVELS.DEBUG,e)}info(e){this.log(a.LOG_LEVELS.INFO,e)}warn(e){this.log(a.LOG_LEVELS.WARN,e)}error(e){this.log(a.LOG_LEVELS.ERROR,e)}}class u{static create(e,t={}){let s=document.createElement(e);return t.className&&(s.className=t.className),t.style&&(s.style.cssText=t.style),t.attributes&&Object.entries(t.attributes).forEach(([e,t])=>{s.setAttribute(e,t)}),t.text&&(s.textContent=t.text),t.html&&(s.innerHTML=t.html),t.parent&&t.parent.appendChild(s),s}static find(e,t=document){return t.querySelector(e)}static findAll(e,t=document){return Array.from(t.querySelectorAll(e))}static addClass(e,t){e.classList.add(...t.split(" "))}static removeClass(e,t){e.classList.remove(...t.split(" "))}static toggleClass(e,t){e.classList.toggle(t)}static show(e){e.style.display=""}static hide(e){e.style.display="none"}static escapeHtml(e){if(!e)return e;let t={"&":"&","<":"<",">":">",'"':""","'":"'"};return e.replace(/[&<>"']/g,e=>t[e])}}class l{static async request(e,t={}){var s={method:"GET",headers:{}},a={...s,...t};t.headers&&(a.headers={...s.headers,...t.headers});try{var i=await fetch(e,a);if(401===i.status)throw new Error("Unauthorized");if(!i.ok)throw new Error("HTTP error! status: "+i.status);var o=i.headers.get("content-type");if(o&&o.includes("application/json"))return await i.json();var r=await i.text();try{return JSON.parse(r)}catch{return{Result:"OK",Message:r}}}catch(e){throw e}}static async get(e,t={}){let a=new URL(e,window.location.href);return Object.entries(t).forEach(([e,s])=>{if(null!=s)if(Array.isArray(s)){let t=e.replace(/\[\]$/,"")+"[]";s.forEach(e=>{null!=e&&a.searchParams.append(t,e)})}else a.searchParams.append(e,s)}),this.request(a.toString(),{method:"GET",headers:{"Content-Type":"application/x-www-form-urlencoded"}})}static async post(e,t={}){e=new URL(e,window.location.href);let a=new FormData;return Object.entries(t).forEach(([e,s])=>{if(null!=s)if(Array.isArray(s)){let t=e.replace(/\[\]$/,"")+"[]";s.forEach(e=>{null!=e&&a.append(t,e)})}else a.append(e,s)}),this.request(e.toString(),{method:"POST",body:a})}}class i{constructor(e,t="localStorage"){this.prefix=e,this.method=t}set(e,t){var s,e=""+this.prefix+e;"localStorage"===this.method?localStorage.setItem(e,t):((s=new Date).setDate(s.getDate()+30),document.cookie=e+`=${t}; expires=${s.toUTCString()}; path=/`)}get(e){e=""+this.prefix+e;if("localStorage"===this.method)return localStorage.getItem(e);var t,s=e+"=";for(t of decodeURIComponent(document.cookie).split(";")){for(;" "===t.charAt(0);)t=t.substring(1);if(0===t.indexOf(s))return t.substring(s.length,t.length)}return null}remove(e){e=""+this.prefix+e;"localStorage"===this.method?localStorage.removeItem(e):document.cookie=e+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"}generatePrefix(e,t){e=e?e+"#":"";return"ftable#"+(t=>{let s=0;if(0!==t.length)for(let e=0;e<t.length;e++){var a=t.charCodeAt(e);s=(s<<5)-s+a,s&=s}return s})(e+=t.join("$")+"#c"+t.length)}}class e{constructor(e={}){this.options={title:"Modal",content:"",buttons:[],className:"ftable-modal",parent:document.body,...e},this.overlay=null,this.modal=null,this.isOpen=!1}create(){this.overlay=u.create("div",{className:"ftable-modal-overlay",parent:this.options.parent}),this.modal=u.create("div",{className:"ftable-modal "+this.options.className,parent:this.overlay});u.create("h2",{className:"ftable-modal-header",text:this.options.title,parent:this.modal});u.create("span",{className:"ftable-modal-close",html:"×",parent:this.modal}).addEventListener("click",()=>this.close());var e=u.create("div",{className:"ftable-modal-body",parent:this.modal});if("string"==typeof this.options.content?e.innerHTML=this.options.content:e.appendChild(this.options.content),0<this.options.buttons.length){let s=u.create("div",{className:"ftable-modal-footer",parent:this.modal});this.options.buttons.forEach(e=>{var t=u.create("button",{className:"ftable-dialog-button "+(e.className||""),html:`<span>${e.text}</span>`,parent:s});e.onClick&&t.addEventListener("click",e.onClick)})}return this.overlay.addEventListener("click",e=>{e.target===this.overlay&&this.close()}),this.hide(),this}show(){return this.modal||this.create(),this.overlay.style.display="flex",this.isOpen=!0,this}hide(){return this.overlay&&(this.overlay.style.display="none"),this.isOpen=!1,this}close(){return this.hide(),this.options.onClose&&this.options.onClose(),this}destroy(){return this.overlay&&this.overlay.remove(),this.isOpen=!1,this}setContent(e){this.options.content=e;var t=this.modal.querySelector(".ftable-modal-body");t&&(t.innerHTML="","string"==typeof e?t.innerHTML=e:t.appendChild(e))}}class o{constructor(e){this.options=e,this.dependencies=new Map,this.optionsCache=new t,this.originalFieldOptions=new Map}storeOriginalFieldOptions(){0<this.originalFieldOptions.size||Object.entries(this.options.fields).forEach(([e,t])=>{!t.options||"function"!=typeof t.options&&"string"!=typeof t.options||this.originalFieldOptions.set(e,t.options)})}shouldIncludeField(e,t){return"create"===t?!1!==e.create&&!(!0===e.key&&!0!==e.create):"edit"!==t||!1!==e.edit}createFieldContainer(e,t,s,a){var i=u.create("div",{className:"ftable-input-field-container",attributes:{id:"ftable-input-field-container-div-"+e}}),t=(u.create("div",{className:"ftable-input-label",text:t.inputTitle||t.title,parent:i}),this.createInput(e,t,s[e],a));return i.appendChild(t),i}async resolveNonDependantFieldOptions(r,n){this.storeOriginalFieldOptions();var e=Object.entries(this.options.fields).map(async([t,e])=>{if(!e.dependsOn){var s=this.originalFieldOptions.get(t)||e.options;if(s&&("function"==typeof s||"string"==typeof s))try{var a={dependedValues:r,source:n,record:r},i={...e,options:s},o=await this.resolveOptions(i,a);e.options=o}catch(e){console.error(`Failed to resolve options for ${t}:`,e)}}});await Promise.all(e)}async createForm(s="create",a={}){this.currentFormRecord=a,await this.resolveNonDependantFieldOptions(a,s);let i=u.create("form",{className:`ftable-dialog-form ftable-${s}-form`});return this.buildDependencyMap(),Object.entries(this.options.fields).forEach(([e,t])=>{this.shouldIncludeField(t,s)&&(e=this.createFieldContainer(e,t,a,s),i.appendChild(e))}),this.setupDependencyListeners(i),i}buildDependencyMap(){this.dependencies.clear(),Object.entries(this.options.fields).forEach(([t,s])=>{if(s.dependsOn){let e;"string"==typeof s.dependsOn&&(e=s.dependsOn.split(",").map(e=>e.trim()).filter(e=>e)).forEach(e=>{this.dependencies.has(e)||this.dependencies.set(e,[]),this.dependencies.get(e).push(t)})}})}setupDependencyListeners(s){Array.from(this.dependencies.keys()).forEach(e=>{var t=s.querySelector(`[name="${e}"]`);t&&t.addEventListener("change",()=>{this.handleDependencyChange(s,e)})}),this.handleDependencyChange(s)}async resolveOptions(t,e={}){if(!t.options)return[];if(Array.isArray(t.options)||"object"==typeof t.options)return t.options;let s,a=!1;e={...e,clearCache:()=>{a=!0}};if("function"==typeof t.options)s=await t.options(e);else{if("string"!=typeof t.options)return[];s=t.options}e=s&&"object"==typeof s&&s.url,t=e?s.url:s;if(a=e&&void 0!==s.noCache?s.noCache:a,"string"!=typeof t)return[];if(!a){e=this.optionsCache.get(t,{});if(e)return e}try{var i=this.options.forcePost?await l.post(t):await l.get(t),o=i.Options||i.options||i||[];return a||this.optionsCache.set(t,{},o),o}catch(e){return console.error(`Failed to load options from ${t}:`,e),[]}}clearOptionsCache(e=null,t=null){this.optionsCache.clear(e,t)}async handleDependencyChange(e,s=""){var t,a,i={};for([t,a]of Object.entries(this.options.fields)){var o=e.querySelector(`[name="${t}"]`);o&&("checkbox"===o.type?i[t]=o.checked?"1":"0":i[t]=o.value)}var r,n,l=e.classList.contains("ftable-create-form")?"create":"edit",c={record:this.currentFormRecord||{},source:l,form:e,dependedValues:i};for([r,n]of Object.entries(this.options.fields))if(n.dependsOn){if(""!==s)if(!n.dependsOn.split(",").map(e=>e.trim()).filter(e=>e).includes(s))continue;let t=e.querySelector(`[name="${r}"]`);if(t&&this.shouldIncludeField(n,l))try{"SELECT"===t.tagName?t.innerHTML='<option value="">Loading...</option>':"INPUT"===t.tagName&&t.list&&(d=document.getElementById(t.list.id))&&(d.innerHTML="");var d,h={...c,dependsOnField:n.dependsOn,dependsOnValue:i[n.dependsOn]},p=this.originalFieldOptions.get(r)||n.options,u={...n,options:p},m=await this.resolveOptions(u,h);"SELECT"===t.tagName?this.populateSelectOptions(t,m,""):"INPUT"===t.tagName&&t.list&&this.populateDatalistOptions(t.list,m),setTimeout(()=>{t.dispatchEvent(new Event("change",{bubbles:!0}))},0)}catch(e){console.error(`Error loading options for ${r}:`,e),"SELECT"===t.tagName&&(t.innerHTML='<option value="">Error</option>')}}}parseInputAttributes(e){if("string"!=typeof e)return e||{};for(var t={},s=/(\w+)(?:=("[^"]*"|'[^']*'|\S+))?/g;null!==(i=s.exec(e));){var a=i[1],i=i[2]?i[2].replace(/^["']|["']$/g,""):"";t[a]=""===i?"true":i}return t}createInput(e,t,s,a){var i=u.create("div",{className:`ftable-input ftable-${t.type||"text"}-input`});let o;switch(null==s&&(s=t.defaultValue),!t.type&&t.options&&(t.type="select"),t.type){case"hidden":o=this.createHiddenInput(e,t,s);break;case"textarea":o=this.createTextarea(e,t,s);break;case"select":o=this.createSelect(e,t,s);break;case"checkbox":o=this.createCheckbox(e,t,s);break;case"radio":o=this.createRadioGroup(e,t,s);break;case"datalist":o=this.createDatalistInput(e,t,s);break;case"file":o=this.createFileInput(e,t,s);break;case"date":case"datetime-local":o=this.createDateInput(e,t,s);break;default:o=this.createTypedInput(e,t,s)}return"function"==typeof t.input?(a={field:t,record:this.currentFormRecord,inputField:o,formType:a},"string"==typeof(a=t.input(a))?i.innerHTML=a:a instanceof Node?i.appendChild(a):i.appendChild(o)):i.appendChild(o),t.explain&&u.create("div",{className:"ftable-field-explain",html:`<small>${t.explain}</small>`,parent:i}),i}createDateInput(e,s,a){if("undefined"==typeof FDatepicker)return createTypedInput(e,s,a);{var i=s.dateFormat||this.options.defaultDateFormat,o=document.createElement("div"),r=u.create("input",{attributes:{id:"real-"+e,type:"hidden",value:a||"",name:e}});let t=u.create("input",{className:s.inputClass||"datepicker-input",attributes:{id:"Edit-"+e,type:"text","data-date":a,placeholder:s.placeholder||"",readOnly:!0}});s.inputAttributes&&Object.keys(s.inputAttributes).forEach(e=>{t.setAttribute(e,s.inputAttributes[e])}),o.appendChild(r),o.appendChild(t);new FDatepicker(t,{format:i,altField:"real-"+e,altFormat:"Y-m-d"});return o}}createTypedInput(e,t,s){var a,s={type:t.type||"text",id:"Edit-"+e,placeholder:t.placeholder||"",value:s||""};let i=e,o=(t.inputAttributes&&(a=this.parseInputAttributes(t.inputAttributes),Object.assign(s,a),void 0!==a.multiple&&!1!==a.multiple)&&(i=e+"[]"),s.name=i,u.create("input",{className:t.inputClass||"",attributes:s}));return o.addEventListener("keypress",e=>{if(13===(e.keyCode||e.which))return e.preventDefault(),o.dispatchEvent(new Event("change",{bubbles:!0})),!1}),o}createDatalistInput(e,t,s){s=u.create("input",{attributes:{type:"text",name:e,id:"Edit-"+e,placeholder:t.placeholder||"",value:s||"",class:t.inputClass||"",list:e+"-datalist"}}),e=u.create("datalist",{attributes:{id:e+"-datalist"}});return t.options&&this.populateDatalistOptions(e,t.options),document.body.appendChild(e),s.datalistElement=e,s}populateDatalistOptions(s,e){s.innerHTML="",Array.isArray(e)?e.forEach(e=>{u.create("option",{attributes:{value:e.Value||e.value||e},text:e.DisplayText||e.text||e,parent:s})}):"object"==typeof e&&Object.entries(e).forEach(([e,t])=>{u.create("option",{attributes:{value:e},text:t,parent:s})})}createHiddenInput(e,t,s){e={type:"hidden",name:e,id:"Edit-"+e,value:s||""};return t.inputAttributes&&(s=this.parseInputAttributes(t.inputAttributes),Object.assign(e,s)),u.create("input",{attributes:e})}createTextarea(e,t,s){e={name:e,id:"Edit-"+e,class:t.inputClass||"",placeholder:t.placeholder||""},t.inputAttributes&&(t=this.parseInputAttributes(t.inputAttributes),Object.assign(e,t)),t=u.create("textarea",{attributes:e});return t.value=s||"",t}createSelect(e,t,s){var e={name:e,id:"Edit-"+e,class:t.inputClass||""},a=(t.inputAttributes&&(a=this.parseInputAttributes(t.inputAttributes),Object.assign(e,a)),u.create("select",{attributes:e}));return t.options&&this.populateSelectOptions(a,t.options,s),a}createRadioGroup(o,r,n){let l=u.create("div",{className:"ftable-radio-group"});return r.options&&(Array.isArray(r.options)?r.options:"object"==typeof r.options?Object.entries(r.options).map(([e,t])=>({Value:e,DisplayText:t})):[]).forEach((e,t)=>{var s=u.create("div",{className:"ftable-radio-wrapper",parent:l}),a=o+"_"+t,i={type:"radio",name:o,id:a,value:e.Value||e.value||e,class:r.inputClass||""},t=(r.required&&0===t&&(i.required="required"),r.disabled&&(i.disabled="disabled"),r.inputAttributes&&(t=this.parseInputAttributes(r.inputAttributes),Object.assign(attributes,t)),u.create("input",{attributes:i,parent:s}));i.value===n&&(t.checked=!0),u.create("label",{attributes:{for:a},text:e.DisplayText||e.text||e,parent:s})}),l}createCheckbox(e,t,s){var a=u.create("div",{className:"ftable-yesno-check-wrapper"}),s=[1,"1",!0,"true"].includes(s);let i="No",o="Yes";return t.values&&"object"==typeof t.values&&(void 0!==t.values[0]&&(i=t.values[0]),void 0!==t.values[1])&&(o=t.values[1]),u.create("input",{className:["ftable-yesno-check-input",t.inputClass||""].filter(Boolean).join(" "),attributes:{type:"checkbox",name:e,id:"Edit-"+e,value:"1"},parent:a}).checked=s,t.label?u.create("label",{className:"ftable-yesno-check-fixedlabel",attributes:{for:"Edit-"+e},text:t.label,parent:a}):u.create("label",{className:"ftable-yesno-check-text",attributes:{for:"Edit-"+e,"data-yes":o,"data-no":i},parent:a}),a}populateSelectOptions(a,e,i){a.innerHTML="",Array.isArray(e)?e.forEach(e=>{var t=void 0!==e.Value?e.Value:void 0!==e.value?e.value:e;let s=u.create("option",{attributes:{value:t},text:e.DisplayText||e.text||e,parent:a});e.Data&&"object"==typeof e.Data&&Object.entries(e.Data).forEach(([e,t])=>{s.setAttribute("data-"+e,t)}),s.value==i&&(s.selected=!0)}):"object"==typeof e&&Object.entries(e).forEach(([e,t])=>{t=u.create("option",{attributes:{value:e},text:t,parent:a});e==i&&(t.selected=!0)})}createFileInput(e,t,s){var a={type:"file",id:"Edit-"+e,class:t.inputClass||""};let i=e;return t.inputAttributes&&(t=this.parseInputAttributes(t.inputAttributes),Object.assign(a,t),void 0!==t.multiple&&!1!==t.multiple)&&(i=e+"[]"),a.name=i,u.create("input",{attributes:a})}}class r extends class{constructor(){this.events={}}on(e,t){return this.events[e]||(this.events[e]=[]),this.events[e].push(t),this}once(t,s){let a=(...e)=>{this.off(t,a),s.apply(this,e)};return a.fn=s,this.on(t,a),this}emit(e,t={}){return this.events[e]&&this.events[e].forEach(e=>e(t)),this}off(e,t){return this.events[e]&&(this.events[e]=this.events[e].filter(e=>e!==t)),this}}{constructor(e,t={}){if(super(),this.element="string"==typeof e?document.querySelector(e):e,this.element){if(this.element.ftableInstance)return this.element.ftableInstance;this.options=this.mergeOptions(t),this.verifyOptions(),this.logger=new a(this.options.logLevel),this.userPrefs=new i("",this.options.saveUserPreferencesMethod),this.formBuilder=new o(this.options,this),this.state={records:[],totalRecordCount:0,currentPage:1,isLoading:!1,selectedRecords:new Set,sorting:[],searchQueries:{}},this.elements={},this.modals={},this.searchTimeout=null,this.lastSortEvent=null,this._recalculatedOnce=!1,(this.element.ftableInstance=this).init()}}mergeOptions(e){var t={tableId:void 0,logLevel:a.LOG_LEVELS.WARN,actions:{},fields:{},forcePost:!0,animationsEnabled:!0,loadingAnimationDelay:1e3,defaultDateLocale:"",defaultDateFormat:"Y-m-d",saveUserPreferences:!0,saveUserPreferencesMethod:"localStorage",defaultSorting:"",tableReset:!1,paging:!1,pageList:"normal",pageSize:10,pageSizes:[10,25,50,100,250,500],gotoPageArea:"combobox",sorting:!1,multiSorting:!1,multiSortingCtrlKey:!0,selecting:!1,multiselect:!1,openChildAsAccordion:!1,toolbarsearch:!1,toolbarreset:!0,searchDebounceMs:300,listCache:3e4,messages:{...s}};return this.deepMerge(t,e)}deepMerge(e,t){var s,a={...e};for(s in t)t[s]&&"object"==typeof t[s]&&!Array.isArray(t[s])?a[s]=this.deepMerge(a[s]||{},t[s]):a[s]=t[s];return a}verifyOptions(){this.options.pageSize&&!this.options.pageSizes.includes(this.options.pageSize)&&(this.options.pageSize=this.options.pageSizes[0])}static setMessages(e){Object.assign(s,e)}init(){this.processFieldDefinitions(),this.createMainStructure(),this.setupFTableUserPreferences(),this.createTable(),this.createModals(),this.options.paging&&this.createPagingUI(),this.resolveAsyncFieldOptions().then(()=>{setTimeout(()=>{this.refreshDisplayValues()},0)}).catch(console.error),this.bindEvents(),this.updateSortingHeaders(),this.renderSortingInfo(),this.initColumnWidths()}initColumnWidths(){var e=this.columnList.filter(e=>{e=this.options.fields[e];return"hidden"!==e.visibility&&"separator"!==e.visibility});let t=e.length;e.forEach(e=>{e=this.options.fields[e];e.width=e.width||100/t+"%"})}normalizeColumnWidths(){var e=this.elements.mainContainer,t=this.columnList.map(e=>({th:this.elements.table.querySelector(`[data-field-name="${e}"]`),field:this.options.fields[e]})).filter(e=>e.th&&"hidden"!==e.field.visibility&&"separator"!==e.field.visibility);if(0!==t.length){let s=e.offsetWidth,a=0;t.forEach(e=>{var t=e.th.offsetWidth/s*100;e.field.width=t+"%",e.th.style.width=e.field.width,a+=t})}}parseDefaultSorting(e){let o=[];return e&&"string"==typeof e&&e.split(",").forEach(s=>{s=s.trim();if(s){var a=s.toUpperCase().indexOf(" DESC"),i=s.toUpperCase().indexOf(" ASC");let e="ASC",t=s;e=0<a?(t=s.slice(0,a).trim(),"DESC"):(t=(0<i?s.slice(0,i):s).trim(),"ASC");a=this.options.fields[t];a&&!1!==a.sorting&&o.push({fieldName:t,direction:e})}}),o}addEssentialCSS(){var e;document.querySelector("#ftable-essential-css")||((e=document.createElement("style")).id="ftable-essential-css",e.textContent=`
|
|
2
2
|
.ftable-row-animation {
|
|
3
3
|
transition: background-color 0.3s ease;
|
|
4
4
|
}
|
package/ftable.umd.js
CHANGED
|
@@ -619,7 +619,7 @@ class FTableFormBuilder {
|
|
|
619
619
|
await Promise.all(promises);
|
|
620
620
|
}*/
|
|
621
621
|
|
|
622
|
-
async resolveNonDependantFieldOptions(fieldValues) {
|
|
622
|
+
async resolveNonDependantFieldOptions(fieldValues, formType) {
|
|
623
623
|
// Store original options before first resolution
|
|
624
624
|
this.storeOriginalFieldOptions();
|
|
625
625
|
|
|
@@ -632,8 +632,8 @@ class FTableFormBuilder {
|
|
|
632
632
|
|
|
633
633
|
if (originalOptions && (typeof originalOptions === 'function' || typeof originalOptions === 'string')) {
|
|
634
634
|
try {
|
|
635
|
-
// Pass fieldValues as dependedValues for dependency resolution
|
|
636
|
-
const params = { dependedValues: fieldValues };
|
|
635
|
+
// Pass fieldValues as dependedValues for dependency resolution (but record contains everything too ...)
|
|
636
|
+
const params = { dependedValues: fieldValues, source: formType, record: fieldValues };
|
|
637
637
|
|
|
638
638
|
// Resolve using original options, not the possibly already-resolved ones
|
|
639
639
|
const tempField = { ...field, options: originalOptions };
|
|
@@ -653,7 +653,7 @@ class FTableFormBuilder {
|
|
|
653
653
|
|
|
654
654
|
// Pre-resolve all options for fields depending on nothing, the others are handled down the road when dependancies are calculated
|
|
655
655
|
//await this.resolveAllFieldOptions(record);
|
|
656
|
-
await this.resolveNonDependantFieldOptions(record);
|
|
656
|
+
await this.resolveNonDependantFieldOptions(record, formType);
|
|
657
657
|
|
|
658
658
|
const form = FTableDOMHelper.create('form', {
|
|
659
659
|
className: `ftable-dialog-form ftable-${formType}-form`
|