sdc_client 0.57.15 → 0.57.16
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/index.js +26 -26
- package/dist/ugly.index.js +1 -1
- package/gulp/gulp.jsx +85 -78
- package/package.json +4 -6
- package/src/simpleDomControl/AbstractSDC.js +2 -2
- package/src/simpleDomControl/sdc_dom_events.js +17 -1
- package/src/simpleDomControl/sdc_params.js +67 -52
- package/src/simpleDomControl/sdc_socket.js +744 -716
- package/src/simpleDomControl/sdc_utils.js +1 -1
- package/src/simpleDomControl/sdc_view.js +39 -36
package/dist/ugly.index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};let n;e.d(t,{n$:()=>ue,du:()=>I,yA:()=>pe,g3:()=>d,u2:()=>p,n9:()=>N,on:()=>F,yy:()=>E,R6:()=>f,$n:()=>A,hA:()=>me,VB:()=>ge,hZ:()=>T});const r=/([^\s,]+)/g,o=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm;function s(){return new Promise((function(e){e()}))}function i(e){return(e=(e=e.replace(/[A-Z]/g,(e=>`-${e.toLowerCase()}`))).replace(/[0-9]+/g,(e=>`-${e}`))).replace(/^[-]/g,"")}function l(e){return e.replace(/-./g,(e=>`${e[1].toUpperCase()}`))}const a=(e,t)=>{let n=t,r=Object.getOwnPropertyNames(e.prototype).concat(Object.getOwnPropertySymbols(e.prototype));for(;""!==n.name;)Object.getOwnPropertyNames(n.prototype).concat(Object.getOwnPropertySymbols(n.prototype)).forEach((t=>{t.match(/^(?:constructor|prototype|arguments|caller|name|bind|call|apply|toString|length)$/)||r.includes(t)||(r.push(t),Object.defineProperty(e.prototype,t,Object.getOwnPropertyDescriptor(n.prototype,t)))})),n=Object.getPrototypeOf(n)};function c(e,t,n){return $.ajax({url:t,type:n||"POST",xhr:function(){var e=$.ajaxSettings.xhr();return e.upload&&e.upload.addEventListener("progress",u,!1),e},data:e,cache:!1,contentType:!1,processData:!1,beforeSend:function(e,t){(function(e){return/^(GET|HEAD|OPTIONS|TRACE)$/.test(e)})(t.type)||this.crossDomain||e.setRequestHeader("X-CSRFToken",window.CSRF_TOKEN)}})}function u(e){if(e.lengthComputable){var t=Math.round(e.loaded/e.total*100),n=$(".progress-container");100===t?n.hide():n.show(),t+="%",n.find(".progress-bar").css({width:t}).text(t)}}function d(e,t=null){return"string"!=typeof e?e:t&&void 0!==t[e]?"function"==typeof t[e]?t[e].bind(t):t[e]:e.match(/^(true|false)$/)?"true"===e:"undefined"!==e?"none"===e.toLowerCase()?null:e.match(/^-?\d+$/)?parseInt(e):e.match(/^-?\d+\.?\d+$/)?parseFloat(e):e.match(/^(['][^']*['])|(["][^"]*["])$/)?e.substr(1,e.length-2):e:void 0}function h(){return([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,(e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16)))}function p(e){e.find(".has-error").removeClass("has-error").find(".alert-danger").remove(),e.find(".non-field-errors").remove()}function f(e,t){t=$("<div>").append(t),e.find(".has-error").removeClass("has-error").find(".alert-danger").safeRemove(),e.find(".non-field-errors").safeRemove();let n=t.find("input[type=file]").parent();e.find("input[type=file]").parent().each((function(e){$(this).replaceWith(n[e])}));let r=0===t.find(".non-field-errors").insertAfter(e.find(".hidden-form-fields")).length;return t.find(".has-error").each((function(){r=!1;let t=$(this),n=t.data("auto-id"),o=e.find(".form-group."+n);o.addClass("has-error"),o.find(".form-input-container").append(t.find(".alert-danger"))})),r}function m(e,t,n=null){let r=function(e,t){let n;e||(e=[]);let r=t.data(),o={};for(let t in r)r.hasOwnProperty(t)&&t!==M&&!e.includes(t)&&(o[t]=r[t]);n=[];for(let t=0;t<e.length;t++){let o=e[t];r.hasOwnProperty(o)?n.push(r[o]):n.push("undefined")}return n.push(o),n}(e,t);return function(e,t=null){let n=[];for(let r=0;r<e.length;r++){let o=d(e[r],t);n.push(o)}return n}(r,n)}function g(e,t,n){if(!e)return!1;if("function"!=typeof e.onInit)return!1;let s;var i;"function"==typeof e._on_init_params?s=e._on_init_params():s=(i=e.onInit.toString().replace(o,"")).slice(i.indexOf("(")+1,i.indexOf(")")).match(r)||[];let l=m(s,t,n._parentController);if(e.onInit.apply(n,l),n===e)for(let r in e._mixins)g(e._mixins[r],t,n)}const y=["onbeforeunload","onunload"],v=Object.keys(window).filter((e=>/^on/.test(e)&&!y.includes(e))).map((e=>e.slice(2)));function w(e){let t=e.type;e.hasOwnProperty("namespace")&&e.namespace&&e.namespace.length&&(t+=`.${e.namespace}`);let n=$(e.target),r=null,o=!1,s=!1;for(e.stopImmediatePropagation=()=>s=!0,e.stopPropagation=()=>s=o=!0;n.length;){let i=n.attr(`sdc_${t}`);if(i){if(!r&&(r=B(n),!r))return;for(;r;){if(i.split(" ").forEach((s=>{if(o)return;let i=null;if("function"==typeof s)i=s;else if("function"==typeof r[s])i=r[s];else if("string"==typeof s&&s.startsWith("this.event_")){if(i=r.getEvents()[t],!i)return;if(i=i[s.slice(11)],!i)return}i&&i.call(r,n,e)})),s)return;r=r._parentController}}if(o)return;n=n.parent()}return{res:!0}}function C(e){if(e._isEventsSet)return;const t=e.getEvents();for(let n in t)if(t.hasOwnProperty(n)){let r=t[n];for(let t in r)r.hasOwnProperty(t)&&e.find(t).each((function(){let e=$(this),r=e.attr(`sdc_${n}`)||null;r=r?r.split(" "):[];const o=`this.event_${t}`;-1===r.indexOf(o)&&(r.push(o),e.attr(`sdc_${n}`,r.join(" ")))}))}}let O=[],b={};function k(e,t){if(e){let n=l(t._tagName);e._childController[n]||(e._childController[n]=[]),e._childController[n].push(t)}return t._parentController=e}function P(e,t,n,r){let o=[];r=function(e,t){e=(e=e.concat(b[t][1])).filter(((e,t,n)=>n.indexOf(e)===t));let n=!0;for(;n;){n=!1;for(let t of e)for(let r of b[t][1])e.includes(r)||(e.push(r),n=!0)}return e}(r,n);for(let e of r)o.push(b[e][0]);let s=new(function(e,...t){let n={[e.name]:class{constructor(...n){let r={};t.forEach((e=>{let t;Object.assign(this,t=new e),t._tagName=e.prototype._tagName,t._isMixin=!0,r[e.name]=t})),Object.assign(this,new e),this._mixins=r}static get name(){return e.name}static className(){return this.name}get mixins(){return this._mixins}}}[e.name];return a(n,e),t.forEach((e=>{a(n,e)})),n}(b[n][0],...o));return s._tagName=n,k(e,s),s.$container=t,function(e,t){g(t,e,t)}(t,s),s}function N(e,t,n,r){if(O.includes(n)){let o=l(n);return window[o]||(window[o]=P(e,t,n,r)),window[o].$container=t,window[o]}return P(e,t,n,r)}function E(e,t){const n=function(e){return function(e){let t={args:{}};return e.contentUrl&&(t=V(e,e.contentUrl),e.contentUrl=t.url),Promise.all([J(e.contentUrl,t.args,e._tagName,e.contentReload)]).then((function(e){let t=e[0];if(t)try{return $(t)}catch{return $("<div></div>").append(t)}return null}))}(e).then((t=>!e.onLoad||e._onLoadDone?t:(e._onLoadDone=!0,(e.onLoad(t)||s()).then((()=>t)))))}(e).then((function(t){return function(e,t){return W(e,t).then((function(t){if(t=t||!0,e.willShow){let n=e.willShow();if(n instanceof Promise)return n.then((function(){return t}))}return t}))}(e,t)})).then((()=>function(e,t){return z(null,e,t)}(e,t))).catch((function(t){return W(e,t)}));return e.load_async?Promise.resolve():n}function S(e){const t=function(e){let t=[];for(;e;)e._isEventsSet=!1,t.unshift(e),e=e._parentController;return t}(e.controller[0]),n=t.concat(e.controller.slice(1));for(let t of n)C(t),t.onRefresh(e.controller[0])}function R(e,t){let n=Boolean(e);return n?e.uuids.has(t._uuid)||(e.uuids.add(t._uuid),e.controller.push(t)):e={uuids:new Set([t._uuid]),controller:[t]},{isRunningProcess:n,refreshProcess:e}}let x={},q={};function F(e,t){return A(e),q.hasOwnProperty(e)?t[q[e]]?void x[e].push(t):console.log("No event handler: "+e,t):console.log("No event: "+e,t)}function A(e,t){t||(t=e),q[e]||(q[e]=t,x[e]=[])}function I(e){for(let t in x)if(x.hasOwnProperty(t))for(let n=x[t].length;n>=0;n--)e===x[t][n]&&x[t].splice(n,1)}function T(e){let t=Array.apply(null,arguments);if(e=t.shift(),!x.hasOwnProperty(e)||!q.hasOwnProperty(e))return s();let n=x[e],r=q[e],o=[];for(let e=0;e<n.length;e++){let s=n[e][r].apply(n[e],t);void 0!==s&&o.push(s)}return Promise.all(o)}let j={};const M="_controller_",L="_sdc_controller_";function U(e,t,n){if(!e)return[];let r=e.children(),o=[];return r.each((function(e,r){let s=$(r),i=s.prop("tagName").toLowerCase().split("_");$.inArray(i[0],t)>=0?o.push({tag:i[0],super:i.splice(1)||[],dom:s}):i[0].startsWith("this.")?s.addClass(`_bind_to_update_handler sdc_uuid_${n._uuid}`):o=o.concat(U(s,t,n))})),o}function J(e,t,n,r){return e?j[n]?Promise.resolve(j[n]):(t.VERSION=pe.VERSION,t._method="content",$.get(e,t).then((function(e){return r||(j[n]=e),e})).catch((function(e){throw 301===e.status&&T("_RedirectOnView",e.responseJSON["url-link"]),T("navLoaded",{controller_name:()=>e.status}),`<sdc-error data-code="${e.status}">${e.responseText}</sdc-error>`}))):Promise.resolve(!1)}function D(e,t,n=null){return t=t||e.data(M),K(pe.tagNames,e,t,n)}function V(e){let t=e.contentUrl;if(e&&0===e._urlParams.length){let n,r=/%\(([^)]+)\)\w/gm;for(e._urlParams=[];n=r.exec(t);)e._urlParams.push(n[1]),e.contentReload=!0}let n=function(e,t){return m(e._urlParams,t)}(e,e.$container);return e._urlParams.length&&(t=function(e,t,n){for(let r in e._urlParams)if(e._urlParams.hasOwnProperty(r)){let o=e._urlParams[r],s=RegExp("%\\("+o+"\\)\\w","gm");t=t.replace(s,""+n.shift())}return t}(e,t,n)),e.parsedContentUrl=t,{url:t,args:n[n.length-1]}}function B(e){return e.hasClass(L)?e.data(`${M}`):e.closest(`.${L}`).data(`${M}`)}function G(e,t,n,r,o){let s=e.data(M);return s?D(e,s,o):(s=N(r,e,t,n),e.data(M,s),e.addClass(L),E(s,o))}function W(e,t,n=null){if(t&&t.length>0){e.$container.empty(),e.$container.attr(e._tagName,"");for(let t in e._mixins)e.$container.attr(e._mixins[t]._tagName,"");e.$container.append(t)}return D(e.$container,e,n)}function K(e,t,n,r){return new Promise((o=>{let s=U(t,e,n),i=s.length;if(0===i)return o();for(let e=0;e<s.length;e++)G(s[e].dom,s[e].tag,s[e].super,n,r).then((()=>{if(i--,0===i)return o()}))}))}function H({$element:e,id:t=[],parent:n=null}){t.push(function(e){if(3===e[0].nodeType)return`TEXT__${e[0].nodeValue}`;const t=[e[0].tagName];return"INPUT"===e[0].nodeName&&[["name",""],["type","text"],["id",""]].forEach((([n,r])=>{const o=e.attr(n)??r;o&&t.push(o)})),t.join("__")}(e));const r={$element:e,id:t.join("::"),depth:t.length,idx:0,getRealParent:()=>n,getIdx:function(){return this.idx=(this.getRealParent()?.getIdx()??-1)+e.index()+1,this.idx},op:null,parent:n};return r.getIdx.bind(r),[r].concat(e.contents().toArray().map((e=>H({$element:$(e),id:t.slice(),parent:r}))).flat())}function X(e,t){const n=H({$element:t}),r=H({$element:e});n.map(((e,t)=>e.idx=t)),r.map(((e,t)=>e.idx=t));const o=Math.max(...r.concat(n).map((e=>e.depth))),s=Z(n,r,o);let i=[];window.MAIN=t,window.OPS=s,s.forEach(((e,t)=>{const{op:n,$element:r,idx:o}=e;if("keep_counterpart"===n.type){if(n.counterpart.getIdx()!==o){const t=e.getBefore();t?n.counterpart.$element.insertAfter(t.$element):e.getRealParent().$element.prepend(n.counterpart.$element)}!function(e,t){const n=e[0].attributes??[],r=t[0].attributes??[];[...n].forEach((n=>{t.is(`[${n.name}]`)||e.removeAttr(n.name)})),[...r].forEach((t=>{t.name.startsWith("data")||e.attr(t.name)===t.value||e.attr(t.name,t.value)})),e.removeData(),Object.entries(t.data()).forEach((([t,n])=>{e.data(t,n)}))}(n.counterpart.$element,r),r.hasClass(L)&&(r.data(M).$container=n.counterpart.$element,r.data(M,null)),i.push(r)}else if("delete"===n.type)r.safeRemove();else if("insert"===n.type){const{after:t,target:n}=e.op;t?r.insertAfter(t.$element):n&&n.$element.prepend(r)}})),i.forEach((e=>e.safeRemove()))}function Z(e,t,n){return t.filter((e=>e.depth===n&&!e.op)).forEach((t=>{const n=e.find((e=>!e.op&&e.id===t.id));if(n){const e=(t,n)=>{t.op={type:"keep",idx:n.idx},n.op={type:"keep_counterpart",counterpart:t},t=t.parent,n=n.parent,!t||t.op||n?.op||e(t,n)};e(n,t)}})),n>1?Z(e,t,n-1):(e.forEach(((t,n)=>{if(!t.op){const r=(e[n-1]?.op.idx??-1)+1;t.op={type:"delete",idx:r}}})),t.forEach(((e,n)=>{if(e.getBefore=()=>function(e,n){const r=e.depth;for(;n>=1&&e.depth>=r;)if((e=t[n-=1]).depth===r)return"keep_counterpart"===e.op.type?e.op.counterpart:e;return null}(e,n),e.getRealParent=()=>{return(t=e).parent?"keep_counterpart"===t.parent.op.type?t.parent.op.counterpart:t.parent:null;var t},!e.op){const t=e.getRealParent(),n="insert"===t?.op.type?"insert_ignore":"insert";e.op={type:n,target:t,after:e.getBefore()}}})),[...e,...t].sort(((e,t)=>(e.op?.idx??e.idx)-(t.op?.idx??t.idx))))}function z(e,t,n=null){if(t||(t=B(e)),!t)return Promise.resolve();const{refreshProcess:r,isRunningProcess:o}=R(n,t);return e??=t.$container,K(pe.tagNames,e,t,n).then((()=>{(function(e,t,n){return function(e,t,n){const r=[];return t.find(`._bind_to_update_handler.sdc_uuid_${e._uuid}`).each((function(){const t=$(this);let o;if(t.hasClass("_with_handler"))o=t.data("handler");else{let t=this.tagName.toLowerCase().replace(/^this./,"");e[t]&&(o=e[t])}"function"==typeof o&&(o=o.bind(e)(t.data())),void 0!==o&&r.push(Promise.resolve(o).then((r=>{let o=$("<div></div>");return o.append(r),""===t.html()&&t.append("<div></div>"),pe.reconcile(e,o,t.children(),n)})))})),Promise.all(r)}(e,t??e.$container,n)})(t,e,r).then((()=>{o||S(r)}))}))}const Q=25e3;class Y{constructor(e,t){this.pk=e,this._model=t}set model(e){this._model=e}get model(){return this._model}load(e){if(!this._model)throw new TypeError("Model is not set!!");return e.newModel(this._model,{pk:this.pk})}}const ee={get(e,t){const n=e[t]??void 0;if(n instanceof Y){if(!n.pk&&0!==n.pk)return null;const e=new Number(n.pk);return e.load=n.load.bind(n),e}return n},set(e,t,n){if(t in e){const r=e[t];r instanceof Y?n.hasOwnProperty("pk")?r.pk=n.pk:r.pk=n:e[t]=n}else e[t]=n;return!0}};class te{constructor(e,t={}){this._onNoOpenRequests=[],this.values_list=[],this.values={},this.model_name=e,this.model_query=t,this._is_connected=!1,this._is_conneting_process=!1,this._auto_reconnect=!0,this.socket=null,this.open_request={},this.on_update=()=>{},this.on_create=()=>{},this.form_id=h()}[Symbol.iterator](){let e=-1;return{next:()=>(++e,e<this.values_list.length?{value:this.values_list[e],done:!1}:{value:null,done:!0})}}length(){return this.values_list.length}byPk(e){if(null!==e){e=parseInt(e),isNaN(e)&&(e=-1);let t=this.values_list.find((t=>t.pk===e));return t||(t=new Proxy({pk:e},ee),this.values_list.push(t)),t}return{pk:e}}filter(e){return this.model_query=Object.assign({},this.model_query,e),this}load(){return this.isConnected().then((()=>{const e=h();return new Promise(((t,n)=>{this.socket.send(JSON.stringify({event:"model",event_type:"load",event_id:e,args:{model_name:this.model_name,model_query:this.model_query}})),this.open_request[e]=[t,n]}))}))}listView(e={},t=null,n=null,r={}){let o=$('<div class="container-fluid">');return this.isConnected().then((()=>{const s=h();this.socket.send(JSON.stringify({event:"model",event_type:"list_view",event_id:s,args:{model_name:this.model_name,model_query:this.model_query,filter:e,template_context:r}})),this.open_request[s]=[e=>{o.append(e.html),pe.refresh(o),t&&t(e)},e=>{n&&n(e)}]})),o}detailView(e=null,t=null,n=null,r={}){e=e??-1,e=parseInt(e),isNaN(e)&&(e=-1);let o,s=$('<div class="container-fluid">');return o=0!==this.values_list.length?this.isConnected():this.load(),o.then((()=>{-1===e&&(e=this.values_list[0].pk);const o=h();this.socket.send(JSON.stringify({event:"model",event_type:"detail_view",event_id:o,args:{model_name:this.model_name,model_query:this.model_query,pk:e,template_context:r}})),this.open_request[o]=[e=>{s.append(e.html),pe.refresh(s),t&&t(e)},e=>{n&&n(e)}]})),s}syncFormToModel(e){return this.syncForm(e)}syncModelToForm(e){e&&e.hasClass(this.form_id)||(e=$(`.${this.form_id}`));let t=this;e.each((function(){if(!this.hasAttribute("data-model_pk"))return;let e=$(this).data("model_pk"),n=t.byPk(e);for(let e of this.elements){let t=e.name;if(t&&""!==t)if("checkbox"===e.type)e.checked=n[t];else if("file"===e.type&&n[t]instanceof File){let r=new DataTransfer;r.items.add(n[t]),e.files=r}else $(e).val(n[t])}}))}syncForm(e){e&&e.hasClass(this.form_id)||(e=$(`.${this.form_id}`));const t=this;let n=[];return e.each((function(){let e=$(this).data("model_pk"),r=t.byPk(e);for(let e of this.elements){let t=e.name;t&&""!==t&&("hidden"===e.type?r[t]=(o=$(e).val()).toLowerCase().match(/^(true|false)$/)?"true"===o.toLowerCase():"undefined"!==o?"none"===o.toLowerCase()?null:o.match(/^-?\d+$/)?parseInt(o):o.match(/^-?\d+\.?\d+$/)?parseFloat(o):o.match(/^(['][^']*['])|(["][^"]*["])$/)?o.substring(1,o.length-1):o:void 0:"checkbox"===e.type?r[t]=e.checked:"file"===e.type?r[t]=e.files[0]:r[t]=$(e).val())}var o;return n.push(r),r})),this.values_list.length<=1&&n.length>0&&(this.values=n.at(-1)),n}createForm(e=null,t=null){let n=$('<div class="container-fluid">');return this.isConnected().then((()=>{this._getForm(null,"create_form",null,n,e,t)})),n}editForm(e=-1,t=null,n=null){let r;e=parseInt(e),isNaN(e)&&(e=-1),r=0!==this.values_list.length?this.isConnected():this.load();let o=$('<div class="container-fluid">');return r.then((()=>{e<=-1&&(e=this.values_list.at(e).pk),this._getForm(e,"edit_form",null,o,t,n)})),o}namedForm(e=-1,t,n=null,r=null){let o;e=parseInt(e),isNaN(e)&&(e=-1),o=0!==this.values_list.length?this.isConnected():this.load();let s=$('<div class="container-fluid">');return o.then((()=>{e<=-1&&(e=this.values_list.at(e).pk),this._getForm(e,"named_form",t,s,n,r)})),s}_getForm(e,t,n,r,o,s){e=parseInt(e),isNaN(e)&&(e=-1);const i=h();this.socket.send(JSON.stringify({event:"model",event_type:t,event_id:i,args:{model_name:this.model_name,model_query:this.model_query,pk:e,form_name:n}}));const l=null===e||-1===e?"create":"edit";this.open_request[i]=[t=>{r.append(t.html);let n=r.closest("form").addClass(`sdc-model-${l}-form sdc-model-form ${this.form_id}`).data("model",this).data("model_pk",e);n.length>0&&!n[0].hasAttribute("sdc_submit")&&n.attr("sdc_submit","submitModelFormDistributor"),pe.refresh(r),o&&o(t)},e=>{s&&s(e)}]}new(){return new Promise(((e,t)=>{const n=$("<form>").append(this.createForm((()=>{this.syncFormToModel(n),e()}),t))}))}save(e=-1){return e=parseInt(e),isNaN(e)&&(e=-1),this.isConnected().then((()=>{let t;t=e>-1?[this.byPk(e)]:this.values_list;let n=[];return t.forEach((e=>{const t=h();n.push(new Promise(((n,r)=>{this._readFiles(e).then((o=>{this.socket.send(JSON.stringify({event:"model",event_type:"save",event_id:t,args:{model_name:this.model_name,model_query:this.model_query,data:e,files:o}})),this.open_request[t]=[e=>{let t="string"==typeof e.data.instance?JSON.parse(e.data.instance):e.data.instance;e.data.instance=this._parseServerRes(t),n(e)},r]}))})))})),Promise.all(n)}))}create(e=this.values){const t=h();return this.isConnected().then((()=>new Promise(((n,r)=>{this._readFiles(e).then((o=>{this.socket.send(JSON.stringify({event:"model",event_type:"create",event_id:t,args:{model_name:this.model_name,model_query:this.model_query,data:e,files:o}})),this.open_request[t]=[e=>{let t="string"==typeof e.data.instance?JSON.parse(e.data.instance):e.data.instance;e.data.instance=this._parseServerRes(t)[0],n(e)},r]}))}))))}delete(e=-1){e=parseInt(e),isNaN(e)&&(e=-1),-1===e&&(e=this.values?.pk);const t=h();return this.isConnected().then((()=>new Promise(((n,r)=>{this.socket.send(JSON.stringify({event:"model",event_type:"delete",event_id:t,args:{model_name:this.model_name,model_query:this.model_query,pk:e}})),this.open_request[t]=[n,r]}))))}isConnected(){return new Promise(((e,t)=>{if(this._is_connected)e();else if(this._is_conneting_process){const[n,r]=this.open_request._connecting_process;this.open_request._connecting_process=[()=>{n(),e()},()=>{r(),t()}]}else this._is_conneting_process=!0,this.open_request._connecting_process=[()=>{},()=>{}],this._connectToServer().then((()=>{e(this._checkConnection())}))}))}close(){this.socket&&(this._auto_reconnect=!1,this.socket.onclose=()=>{},this.socket.close(),delete this.socket)}clean(){return this.values_list=[],this.values={},this}_readFiles(e){let t=[],n={};for(const[r,o]of Object.entries(e))o instanceof File&&t.push(new Promise(((e,t)=>{((r,o)=>{let s=new FileReader;s.onload=s=>{const i=h();this.open_request[i]=[e,t];let l=s.target.result,a=parseInt(Math.ceil(l.length/Q));n[r]={id:i,file_name:o.name,field_name:r,content_length:o.size};for(let e=0;e<a;++e)this.socket.send(JSON.stringify({event:"model",event_type:"upload",event_id:i,args:{chunk:l.slice(Q*e,Q*(e+1)),idx:e,number_of_chunks:a,file_name:o.name,field_name:r,content_length:o.size,content_type:o.type,model_name:this.model_name,model_query:this.model_query}}))},s.onerror=()=>{t()},s.readAsBinaryString(o)})(r,o)})));return Promise.all(t).then((()=>n))}_onMessage(e){let t=JSON.parse(e.data);if(t.is_error)this.open_request.hasOwnProperty(t.event_id)&&(this.open_request[t.event_id][1](t),this._closeOpenRequest(t.event_id)),(t.msg||t.header)&&T("pushErrorMsg",t.header||"",t.msg||""),"connect"===t.type&&(this.open_request._connecting_process[1](t),this._closeOpenRequest("_connecting_process"),this._auto_reconnect=!1,this.socket.close());else{if((t.msg||t.header)&&T("pushMsg",t.header||"",t.msg||""),"connect"===t.type)this._is_connected=!0,this._is_conneting_process=!1,this.open_request._connecting_process[0](t),this._closeOpenRequest("_connecting_process");else if("load"===t.type){const e=JSON.parse(t.args.data);this.values_list=[],t.args.data=this._parseServerRes(e)}else if("on_update"===t.type||"on_create"===t.type){const e=JSON.parse(t.args.data);let n,r=this._parseServerRes(e);n="on_create"===t.type?this.on_create:this.on_update,n(r),t.args.data=r}let e=t.data?.instance;e&&(t.data.instance=JSON.parse(t.data.instance)),this.open_request.hasOwnProperty(t.event_id)&&(this.open_request[t.event_id][0](t),this._closeOpenRequest(t.event_id))}}noOpenRequests(){return new Promise((e=>{if(0===Object.keys(this.open_request).length)return e();this._onNoOpenRequests.push(e)}))}_closeOpenRequest(e){delete this.open_request[e],0===Object.keys(this.open_request).length&&(this._onNoOpenRequests.forEach((e=>e())),this._onNoOpenRequests=[])}_connectToServer(){return new Promise((e=>{const t=`${this.model_name}`+(this.model_id>0?`/${this.model_id}`:"");"https:"===window.location.protocol?this.socket=new WebSocket(`wss://${window.location.host}/sdc_ws/model/${t}`):this.socket=new WebSocket(`ws://${window.location.host}/sdc_ws/model/${t}`),this.socket.onmessage=this._onMessage.bind(this),this.socket.onclose=e=>{console.error(`SDC Model (${this.model_name}, ${this.model_id}) Socket closed unexpectedly`),this._is_connected=!1;for(const[t,n]of Object.entries(this.open_request))n[1](e);this.open_request={},setTimeout((()=>{this._auto_reconnect&&this._connectToServer().then((()=>{}))}),1e3)},this.socket.onerror=e=>{if(console.error(`Model Socket encountered error: ${e} Closing socket`),this._is_connected)try{this.socket.close()}catch(e){}},this.socket.onopen=()=>{e()}}))}_checkConnection(){const e=h();return new Promise(((t,n)=>{this.socket.send(JSON.stringify({event:"model",event_type:"connect",event_id:e,args:{model_name:this.model_name,model_query:this.model_query}})),this.open_request[e]=[t,n]}))}_parseServerRes(e){let t=[];for(let n of e){const e=n.pk,r=this.byPk(e);for(const[e,t]of Object.entries(n.fields))t&&"object"==typeof t&&t.__is_sdc_model__?r[e]=new Y(t.pk,t.model):r[e]=t;t.push(r)}return 1===this.values_list.length?this.values=this.values_list.at(-1):this.values={},t}}let ne=!1,re=!1,oe=null,se={};function ie(){return window.SERVER_CALL_VIA_WEB_SOCKET?new Promise((e=>ne?e():re?void setTimeout((()=>{ie().then((()=>{e()}))}),200):e(ae()))):Promise.resolve(!0)}function le(){window.SERVER_CALL_VIA_WEB_SOCKET&&function(){if(ne){ne=!1;try{oe.close()}catch(e){}}}()}function ae(){return re=!0,new Promise((e=>{oe="https:"===window.location.protocol?new WebSocket(`wss://${window.location.host}/sdc_ws/ws/`):new WebSocket(`ws://${window.location.host}/sdc_ws/ws/`),oe.onmessage=function(e){ce(JSON.parse(e.data))},oe.onclose=function(){ne&&console.error("SDC Socket closed unexpectedly"),ne=!1;for(const[e,t]of Object.entries(se))t[1]({}),delete se[e];setTimeout((()=>{ae()}),1e3)},oe.onerror=function(e){if(console.error("Socket encountered error: ",e.message,"Closing socket"),ne)try{oe.close()}catch(e){}},oe.onopen=function(){ne=!0,re=!1,e()}}))}function ce(e){if(e||(e={}),e.is_error)(e.msg||e.header)&&T("pushErrorMsg",e.header||"",e.msg||""),e.id&&se[e.id]&&(se[e.id][1](e.data||null),delete se[e.id]);else if((e.msg||e.header)&&T("pushMsg",e.header||"",e.msg||""),e.type&&"sdc_recall"===e.type)e.id&&se[e.id]&&(se[e.id][0](e.data),delete se[e.id]);else if(e.type&&"sdc_event"===e.type){let t=e.event;t&&T(t,e.payload)}else e.type&&"sdc_redirect"===e.type&&T("onNavLink",e.link)}class ue{constructor(){this._uuid=h(),this.contentUrl="",this.contentReload=!1,this.parsedContentUrl=null,this.events=[],this.load_async=!1,this._isEventsSet=!1,this._allEvents=null,this._urlParams=[],this._models=[],this._cssUrls=[],this.afterShow=()=>{console.warn("afterShow is deprecated!!")},this._mixins={},this._tagName=Object.getPrototypeOf(this)._tagName??"",this._childController={},this._parentController=null,this._onLoadDone=!1,this.$container=null,this._isMixin=!1}_runLifecycle(e,t){pe.DEBUG&&!this._isMixin&&console.debug(e,this._tagName);let n=[];if(!this._isMixin){this._isMixin=!0;for(let r in this._mixins){let o=this._mixins[r];"function"==typeof o[e]&&n.push(o[e].apply(this,t))}return Promise.all(n).then((()=>{this._isMixin=!1}))}}onInit(){pe.DEBUG&&!this._isMixin&&console.DEBUG(Array.apply(null,arguments),this._tagName)}get parentController(){return this._parentController}get childController(){return this._childController}onLoad(){return this._runLifecycle("onLoad",arguments)}willShow(){return this._runLifecycle("willShow",arguments)}onRefresh(){return this._runLifecycle("onRefresh",arguments)}onRemove(){return this._runLifecycle("onRemove",arguments),!0}noOpenModelRequests(){return Promise.all(this._models.map((e=>e.noOpenRequests())))}remove(){for(const e of this._models)e.close();let e=this._childController;for(let t in e)if(e.hasOwnProperty(t))for(let n of e[t])if(!n.remove())return!1;if(!this.onRemove||this.onRemove()){I(this);const e=l(this._tagName);if(this._parentController._childController[e]){let t=this._parentController._childController[e];for(let e=0;e<t.length;e++)t[e]===this&&t.splice(e,1)}return this.$container.remove(),!0}return!1}controller_name(){return this._tagName.replace(/-./g,(e=>` ${e[1].toUpperCase()}`)).replace(/^./g,(e=>`${e.toUpperCase()}`))}addEvent(e,t,n){this.getEvents(),this._allEvents[e]=this._allEvents[e]||{},this._allEvents[e][t]=n}getEvents(){if(this._allEvents)return this._allEvents;let e=[];e=e.concat(this.events);for(let t in this._mixins){let n=this._mixins[t];Array.isArray(n.events)&&(e=e.concat(n.events))}return this._allEvents=_.merge(...e)}post(e,t){return pe.post(this,e,t)}get(e,t){return pe.get(this,e,t)}submitForm(e,t,n){return pe.submitFormAndUpdateView(this,e,t,n)}serverCall(e,t){let n=this.contentUrl.match(/sdc_view\/([^/]+)/i);if(n&&!(n.length<2))return function(e,t,n,r,o){return window.SERVER_CALL_VIA_WEB_SOCKET?function(e,t,n,r){let o=h();return ie().then((()=>{oe.send(JSON.stringify({event:"sdc_call",id:o,controller:t,app:e,function:n,args:r}))})),new Promise(((e,t)=>{se[o]=[e,t]}))}(e,t,r,o):function(e,t,n){return"object"!=typeof n&&Array.isArray(n)&&null===n&&(n={arg0:n}),n={data:JSON.stringify(n),_sdc_func_name:t,_method:"sdc_server_call"},$.post({url:e,data:n,beforeSend:function(e,t){e.setRequestHeader("X-CSRFToken",window.CSRF_TOKEN)}}).then((e=>{const t=e._return_data;return ce(t),t})).catch((e=>{const t=e.responseJSON;throw t.is_error=!0,ce(t),e}))}(n,r,o)}(n[1],this._tagName,this.parsedContentUrl??this.contentUrl,e,t);console.error("To use the serverCall function the contentUrl must be set: "+this.name)}newModel(e,t={}){if(e instanceof Number&&e.hasOwnProperty("load"))return e.load(this);const n=new te(e,t);return this._models.push(n),n}updateModel(e,t={},n){let r=new te(e,t);return r.load().then((()=>{r.values|=n,r.save().then((()=>(r.close(),r.values)))}))}find(e){return this.$container.find(e)}refresh(){return pe.refresh(this.$container,this)}reload(){return pe.reloadController(this)}reconcile(e,t=null){return pe.reconcile(this,e,t)}submitModelFormDistributor(e,t){return"function"==typeof this._submitModelForm?this._submitModelForm(e,t):"function"==typeof this.submitModelForm?this.submitModelForm(e,t):this.defaultSubmitModelForm(e,t)}iterateAllChildren(){let e=this._childController,t=[];for(let n in e)if(e.hasOwnProperty(n))for(let r of e[n])t.push(r),t.push(...r.iterateAllChildren());return t}defaultSubmitModelForm(e,t){let n=[];if(!this._isMixin){t.stopPropagation(),t.preventDefault();let r=e.data("model");const o=r.syncForm(e);for(let t of o)n.push(new Promise(((n,o)=>{let s;s=null!==t.pk&&t.pk>=0?r.save(t.pk):r.create(t),s.then((t=>{p(e),this.submit_model_form_success&&this.submit_model_form_success(t[0]);for(const e of this.iterateAllChildren())e.submit_model_form_success&&e.submit_model_form_success(t[0]);n(t)})).catch((t=>{f(e,$(t.html)),this.submit_model_form_error&&this.submit_model_form_error(t);for(const e of this.iterateAllChildren())e.submit_model_form_error&&e.submit_model_form_error(t);o(t)}))})))}return Promise.all(n).then((e=>Object.assign({},...e.flat())))}}const de={classname:"class"};window.sdcDom=function(e,t,...n){if(!e)return"";const r=function(e,t){let n,r=!1;if("string"==typeof e)n=$(document.createElement(e));else{const t=`this.${e.name}`;n=$(document.createElement(t)),n.data("handler",e),r=!0}return t&&Object.entries(t).forEach((([e,t])=>{e.startsWith("on")?n[0].addEventListener(e.substring(2).toLowerCase(),t):(de[e.toLowerCase()]&&(e=de[e.toLowerCase()]),n[0].setAttribute(e,t))})),r&&n.addClass("_bind_to_update_handler _with_handler"),n}(e,t);for(const e of n)r.append(e);return r};let he,pe={CSRF_TOKEN:window.CSRF_TOKEN||"",LANGUAGE_CODE:window.LANGUAGE_CODE||"en",DEBUG:window.DEBUG||!1,VERSION:window.VERSION||"0.0",tagNames:[],Global:O,rootController:null,globalRootController:null,_isInit:!1,_origin_trigger:null,_globalControllerClasses:[],init_sdc:()=>{pe._isInit||(pe._isInit=!0,pe._origin_trigger?le():(pe._origin_trigger=$.fn.trigger,$.fn.trigger=function(e){const t={}.hasOwnProperty.call(e,"type")?e.type:e;return v.includes(t)||(v.push(t),$(window).on(t,w)),pe._origin_trigger.call(this,e)},pe.updateJquery()),ie(),function(){const e=$(window);v.forEach((t=>{e.off(t).on(t,w)}))}(),pe.rootController=pe.rootController||new ue,pe.globalRootController=pe.globalRootController||new ue),pe.tagNames=Object.keys(b);const e=$("<div></div>");O.forEach((t=>{const n=b[t][0];e.append(`<${n.prototype._tagName}></${n.prototype._tagName}>`)}));const{refreshProcess:t}=R(null,pe.rootController);return K(pe.tagNames,e,pe.globalRootController,t).then((()=>K(pe.tagNames,(n||(n=$("body")),n),pe.rootController,t).then((e=>(S(t),e)))))},updateJquery:()=>{$.fn.safeReplace=function(e){return pe.safeReplace($(this),e)},$.fn.safeEmpty=function(){return pe.safeEmpty($(this))},$.fn.safeRemove=function(){return pe.safeRemove($(this))}},controllerToTag:e=>i(e.name).replace(/-controller$/,""),registerGlobal:e=>{pe.register(e);let t=e.prototype._tagName;O.push(t)},cleanCache:()=>{j={}},register:e=>{let t=pe.controllerToTag(e);return b[t]=[e,[]],e.prototype._tagName=t,{addMixin:(...e)=>{for(let n of e){let e;"string"==typeof n?e=i(n):n&&(e=pe.controllerToTag(n)),b[t][1].push(e)}}}},post:(e,t,n)=>(n||(n={}),n.CSRF_TOKEN=pe.CSRF_TOKEN,pe.ajax(e,t,params,$.post)),get:(e,t,n)=>pe.ajax(e,t,n,$.get),ajax:(e,t,n,r)=>{n||(n={}),n.VERSION=pe.VERSION,n._method=n._method||"api";const o=new Promise(((s,i)=>r(t,n).then(((t,n,r)=>{s(t,n,r),"redirect"===t.status?T("onNavLink",t["url-link"]):o.then((()=>{pe.refresh(e.$container)}))})).catch(i)));return o},submitFormAndUpdateView:(e,t,n,r)=>{let o=new FormData(t);const s=e=>{e["url-link"]?T("onNavLink",e["url-link"]):window.location.href=e.url},i=new Promise(((l,a)=>{c(o,n||t.action,r||t.method).then(((t,n,r)=>{l(t,n,r),"redirect"===t.status?s(t):i.then((()=>{pe.refresh(e.$container,e)}))})).catch(((e,t,n)=>{301===e.status?(e=e.responseJSON,s(e),l(e,t,n)):a(e,t,n)}))}));return i},submitForm:(e,t,n)=>{let r=new FormData(e);return new Promise(((o,s)=>{c(r,t||e.action,n||e.method).then(o).catch(s)}))},getController:e=>B(e),safeEmpty:e=>(e.children().each((function(e,t){let n=$(t);pe.safeRemove(n)})),e),safeReplace:(e,t)=>(t.insertBefore(e),pe.safeRemove(e)),safeRemove:e=>(e.each((function(){let e=$(this);e.data(`${M}`)&&e.data(`${M}`).remove()})),e.find(`.${L}`).each((function(){const e=$(this).data(`${M}`);e&&e.remove()})),e.remove()),reloadController:e=>function(e){if(e.contentUrl){let t=V(e,e.contentUrl);return e.contentUrl=t.url,J(e.contentUrl,t.args,e._tagName,e.contentReload)}return new Promise((e=>{e($())}))}(e).then((t=>{let n=$(t);return pe.reconcile(e,n)})),reconcile:(e,t,n=null,r=null)=>{if(!n){let n=e.$container.clone().empty();n.data(M,null),n.removeClass(L),n.append(t),t=n}n=n??e.$container;const{refreshProcess:o,isRunningProcess:s}=R(r,e);return z(t,e,o).then((()=>{var r;return X(t,n),(r=e)._childController={},r.find(`.${L}`).each((function(){const e=B($(this));e===r&&k(r,e)})),s||S(o),e}))},refresh:(e,t)=>z(e,t)},fe=[];function _e(){if(!jest)throw new Error("JEST is not defined");0===fe.length&&(he=$.ajax.bind($),fe.push(jest.spyOn($,"ajax")),fe[0].mockImplementation((function(e){return he(e).then((e=>e)).catch((e=>e))})))}const me=le,ge={get_controller:async function(e,t={},n=""){_e();const r=$("body");pe.updateJquery(),r.safeEmpty();const o=$(`<${e}>${n}</${e}>`);for(const[e,n]of Object.entries(t))o.data(e,n);const s=$("<div></div>").append(o);return r.append(s),pe._isInit=!1,pe.cleanCache(),await pe.init_sdc(),pe.getController(o)},getCsrfToken:function(){return function(e){if(document.cookie&&""!==document.cookie){const t=document.cookie.split(";");for(let n=0;n<t.length;n++){const r=t[n].trim();if(r.substring(0,10)===e+"=")return decodeURIComponent(r.substring(10))}}return""}("csrftoken")},controllerFromTestHtml:async function(e,t=null){_e();const n=$("body");pe.updateJquery(),n.safeEmpty().append(e),pe._isInit=!1,pe.cleanCache(),await pe.init_sdc();let r=pe.rootController.iterateAllChildren();if(!t)return r;const o=r[0].onRefresh,s=jest.spyOn(r[0],"onRefresh");return new Promise((e=>{s.mockImplementation((function(){s.mockRestore();const t=o.apply(r[0],arguments);return e(r),t}))}))}};var ye=t.n$,ve=t.du,we=t.yA,$e=t.g3,Ce=t.u2,Oe=t.n9,be=t.on,ke=t.yy,Pe=t.R6,Ne=t.$n,Ee=t.hA,Se=t.VB,Re=t.hZ;export{ye as AbstractSDC,ve as allOff,we as app,$e as checkIfParamNumberBoolOrString,Ce as clearErrorsInForm,Oe as controllerFactory,be as on,ke as runControlFlowFunctions,Pe as setErrorsInForm,Ne as setEvent,Ee as socketReconnect,Se as test_utils,Re as trigger};
|
|
1
|
+
var e={};let t;e.d=(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);const n=/((?<=^|,\s*)[^\s,]+)/g,r=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm;function o(){return new Promise(function(e){e()})}function s(e){return(e=(e=e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)).replace(/[0-9]+/g,e=>`-${e}`)).replace(/^[-]/g,"")}function i(e){return e.replace(/-./g,e=>`${e[1].toUpperCase()}`)}const l=(e,t)=>{let n=t,r=Object.getOwnPropertyNames(e.prototype).concat(Object.getOwnPropertySymbols(e.prototype));for(;""!==n.name;)Object.getOwnPropertyNames(n.prototype).concat(Object.getOwnPropertySymbols(n.prototype)).forEach(t=>{t.match(/^(?:constructor|prototype|arguments|caller|name|bind|call|apply|toString|length)$/)||r.includes(t)||(r.push(t),Object.defineProperty(e.prototype,t,Object.getOwnPropertyDescriptor(n.prototype,t)))}),n=Object.getPrototypeOf(n)};function a(e,t,n){return $.ajax({url:t,type:n||"POST",xhr:function(){var e=$.ajaxSettings.xhr();return e.upload&&e.upload.addEventListener("progress",c,!1),e},data:e,cache:!1,contentType:!1,processData:!1,beforeSend:function(e,t){(function(e){return/^(GET|HEAD|OPTIONS|TRACE)$/.test(e)})(t.type)||this.crossDomain||e.setRequestHeader("X-CSRFToken",window.CSRF_TOKEN)}})}function c(e){if(e.lengthComputable){var t=Math.round(e.loaded/e.total*100),n=$(".progress-container");100===t?n.hide():n.show(),t+="%",n.find(".progress-bar").css({width:t}).text(t)}}function u(e,t=null){return"string"!=typeof e?e:t&&void 0!==t[e]?"function"==typeof t[e]?t[e].bind(t):t[e]:e.match(/^(true|false)$/)?"true"===e:"undefined"!==e?"none"===e.toLowerCase()?null:e.match(/^-?\d+$/)?parseInt(e):e.match(/^-?\d+\.?\d+$/)?parseFloat(e):e.match(/^(['][^']*['])|(["][^"]*["])$/)?e.substr(1,e.length-2):e:void 0}function d(){return([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16))}function h(e){e.find(".has-error").removeClass("has-error").find(".alert-danger").remove(),e.find(".non-field-errors").remove()}function p(e,t){t=$("<div>").append(t),e.find(".has-error").removeClass("has-error").find(".alert-danger").safeRemove(),e.find(".non-field-errors").safeRemove();let n=t.find("input[type=file]").parent();e.find("input[type=file]").parent().each(function(e){$(this).replaceWith(n[e])});let r=0===t.find(".non-field-errors").insertAfter(e.find(".hidden-form-fields")).length;return t.find(".has-error").each(function(){r=!1;let t=$(this),n=t.data("auto-id"),o=e.find(".form-group."+n);o.addClass("has-error"),o.find(".form-input-container").append(t.find(".alert-danger"))}),r}function f(e,t=[]){return Object.fromEntries(Object.entries(e).filter(([e,n])=>e!==L&&!t.includes(e)).map(([e,t])=>{if("string"==typeof t&&t.startsWith("SDC_JSON_MODEL=["))try{const{pk:n,fields:r}=JSON.parse(t.slice(16,-1));return[e,{...r,id:n,pk:n}]}catch{}return[e,t]}))}function m(e,t,n=null){let r=function(e,t){let n;e||(e=[]);let r=t.data(),o=f(r,e);n=[];for(let t=0;t<e.length;t++){let o=e[t];r.hasOwnProperty(o)?n.push(r[o]):n.push("undefined")}return n.push(o),n}(e,t);return function(e,t=null){let n=[];for(let r=0;r<e.length;r++){let o=u(e[r],t);n.push(o)}return n}(r,n)}function g(e,t,o){if(!e)return!1;if("function"!=typeof e.onInit)return!1;let s;var i;"function"==typeof e._on_init_params?s=e._on_init_params():s=(i=e.onInit.toString().replace(r,"")).slice(i.indexOf("(")+1,i.indexOf(")")).match(n)||[];let l=m(s,t,o._parentController);if(e.onInit.apply(o,l),o===e)for(let n in e._mixins)g(e._mixins[n],t,o)}const y=["onbeforeunload","onunload"],v=Object.keys(window).filter(e=>/^on/.test(e)&&!y.includes(e)).map(e=>e.slice(2));function w(e,t,n){let r;switch(e){case"mouseleave":case"mouseout":case"mouseenter":case"mousein":return r=document.elementFromPoint(t.clientX,t.clientY),n!==r&&!n.contains(r);default:return!0}}function O(e){let t=e.type;e.hasOwnProperty("namespace")&&e.namespace&&e.namespace.length&&(t+=`.${e.namespace}`);let n=$(e.target),r=null,o=!1,s=!1;for(e.stopImmediatePropagation=()=>s=!0,e.stopPropagation=()=>s=o=!0;n.length;){let i=n.attr(`sdc_${t}`);if(i&&w(t,e,n[0])){if(!r&&(r=W(n),!r))return;for(;r;){if(i.split(" ").forEach(s=>{if(o)return;let i=null;if("function"==typeof s)i=s;else if("function"==typeof r[s])i=r[s];else if("string"==typeof s&&s.startsWith("this.event_")){if(i=r.getEvents()[t],!i)return;if(i=i[s.slice(11)],!i)return}i&&i.call(r,n,e)}),s)return;r=r._parentController}}if(o)return;n=n.parent()}return{res:!0}}function C(e){if(e._isEventsSet)return;const t=e.getEvents();for(let n in t)if(t.hasOwnProperty(n)){let r=t[n];for(let t in r)r.hasOwnProperty(t)&&e.find(t).each(function(){let e=$(this),r=e.attr(`sdc_${n}`)||null;r=r?r.split(" "):[];const o=`this.event_${t}`;-1===r.indexOf(o)&&(r.push(o),e.attr(`sdc_${n}`,r.join(" ")))})}}let b=[],k={};function N(e,t){if(e){let n=i(t._tagName);e._childController[n]||(e._childController[n]=[]),e._childController[n].push(t)}return t._parentController=e}function P(e,t,n,r){let o=[];r=function(e,t){e=(e=e.concat(k[t][1])).filter((e,t,n)=>n.indexOf(e)===t);let n=!0;for(;n;){n=!1;for(let t of e)for(let r of k[t][1])e.includes(r)||(e.push(r),n=!0)}return e}(r,n);for(let e of r)o.push(k[e][0]);let s=new(function(e,...t){let n={[e.name]:class{constructor(...n){let r={};t.forEach(e=>{let t;Object.assign(this,t=new e),t._tagName=e.prototype._tagName,t._isMixin=!0,r[e.name]=t}),Object.assign(this,new e),this._mixins=r}static get name(){return e.name}static className(){return this.name}get mixins(){return this._mixins}}}[e.name];return l(n,e),t.forEach(e=>{l(n,e)}),n}(k[n][0],...o));return s._tagName=n,N(e,s),s.$container=t,function(e,t){g(t,e,t)}(t,s),s}function S(e,t,n,r){if(b.includes(n)){let o=i(n);return window[o]||(window[o]=P(e,t,n,r)),window[o].$container=t,window[o]}return P(e,t,n,r)}function E(e,t){const n=function(e){return function(e){let t={args:{}};return e.contentUrl&&(t=B(e),e.contentUrl=t.url),Promise.all([D(e.contentUrl,t.args,e._tagName,e.contentReload)]).then(function(e){let t=e[0];if(t)try{return $(t)}catch{return $("<div></div>").append(t)}return null})}(e).then(t=>!e.onLoad||e._onLoadDone?t:(e._onLoadDone=!0,(e.onLoad(t)||o()).then(()=>t)))}(e).then(function(t){return function(e,t){return K(e,t).then(function(t){if(t=t||!0,e.willShow){let n=e.willShow();if(n instanceof Promise)return n.then(function(){return t})}return t})}(e,t)}).then(()=>function(e,t){return Z(null,e,t)}(e,t)).catch(function(t){return K(e,t)});return e.load_async?Promise.resolve():n}function R(e){const t=function(e){let t=[];for(;e;)e._isEventsSet=!1,t.unshift(e),e=e._parentController;return t}(e.controller[0]),n=t.concat(e.controller.slice(1));for(let t of n)C(t),t.onRefresh(e.controller[0])}function x(e,t){let n=Boolean(e);return n?e.uuids.has(t._uuid)||(e.uuids.add(t._uuid),e.controller.push(t)):e={uuids:new Set([t._uuid]),controller:[t]},{isRunningProcess:n,refreshProcess:e}}let q={},F={};function j(e,t){return T(e),F.hasOwnProperty(e)?t[F[e]]?void q[e].push(t):console.log("No event handler: "+e,t):console.log("No event: "+e,t)}function T(e,t){t||(t=e),F[e]||(F[e]=t,q[e]=[])}function A(e){for(let t in q)if(q.hasOwnProperty(t))for(let n=q[t].length;n>=0;n--)e===q[t][n]&&q[t].splice(n,1)}function M(e){let t=Array.apply(null,arguments);if(e=t.shift(),!q.hasOwnProperty(e)||!F.hasOwnProperty(e))return o();let n=q[e],r=F[e],s=[];for(let e=0;e<n.length;e++){let o=n[e][r].apply(n[e],t);void 0!==o&&s.push(o)}return Promise.all(s)}let I={};const L="_controller_",U="_sdc_controller_";function J(e,t,n){if(!e)return[];let r=e.children(),o=[];return r.each(function(e,r){let s=$(r),i=s.prop("tagName").toLowerCase().split("_");$.inArray(i[0],t)>=0?o.push({tag:i[0],super:i.splice(1)||[],dom:s}):i[0].startsWith("this.")?s.addClass(`_bind_to_update_handler sdc_uuid_${n._uuid}`):o=o.concat(J(s,t,n))}),o}function D(e,t,n,r){return e?I[n]?Promise.resolve(I[n]):(t.VERSION=_e.VERSION,t._method="content",$.get(e,t).then(function(e){return r||(I[n]=e),e}).catch(function(e){throw 301===e.status&&M("_RedirectOnView",e.responseJSON["url-link"]),M("navLoaded",{controller_name:()=>e.status}),`<sdc-error data-code="${e.status}">${e.responseText}</sdc-error>`})):Promise.resolve(!1)}function V(e,t,n=null){return t=t||e.data(L),H(_e.tagNames,e,t,n)}function B(e){let t=e.contentUrl;if(e&&0===e._urlParams.length){let n,r=/%\(([^)]+)\)\w/gm;for(e._urlParams=[];n=r.exec(t);)e._urlParams.push(n[1]),e.contentReload=!0}let n=function(e,t){return m(e._urlParams,t)}(e,e.$container);return e._urlParams.length&&(t=function(e,t,n){for(let r in e._urlParams)if(e._urlParams.hasOwnProperty(r)){let o=e._urlParams[r],s=RegExp("%\\("+o+"\\)\\w","gm");t=t.replace(s,""+n.shift())}return t}(e,t,n)),e.parsedContentUrl=t,{url:t,args:n[n.length-1]}}function W(e){return e.hasClass(U)?e.data(`${L}`):e.closest(`.${U}`).data(`${L}`)}function G(e,t,n,r,o){let s=e.data(L);return s?V(e,s,o):(s=S(r,e,t,n),e.data(L,s),e.addClass(U),E(s,o))}function K(e,t,n=null){if(t&&t.length>0){e.$container.empty(),e.$container.attr(e._tagName,"");for(let t in e._mixins)e.$container.attr(e._mixins[t]._tagName,"");e.$container.append(t)}return V(e.$container,e,n)}function H(e,t,n,r){return new Promise(o=>{let s=J(t,e,n),i=s.length;if(0===i)return o();for(let e=0;e<s.length;e++)G(s[e].dom,s[e].tag,s[e].super,n,r).then(()=>{if(i--,0===i)return o()})})}function X({$element:e,id:t=[],parent:n=null}){t.push(function(e){if(3===e[0].nodeType)return`TEXT__${e[0].nodeValue}`;const t=[e[0].tagName];return"INPUT"===e[0].nodeName&&[["name",""],["type","text"],["id",""]].forEach(([n,r])=>{const o=e.attr(n)??r;o&&t.push(o)}),t.join("__")}(e));const r={$element:e,id:t.join("::"),depth:t.length,idx:0,getRealParent:()=>n,getIdx:function(){return this.idx=Math.max(0,(this.getRealParent()?.getIdx()??-1)+e.index()+1),this.idx},op:null,parent:n};return r.getIdx.bind(r),[r].concat(e.contents().toArray().map(e=>X({$element:$(e),id:t.slice(),parent:r})).flat())}function z(e,t){const n=X({$element:t}),r=X({$element:e});n.map((e,t)=>e.idx=t),r.map((e,t)=>e.idx=t);const o=Math.max(...r.concat(n).map(e=>e.depth)),s=Y(n,r,o);let i=[];window.MAIN=t,window.OPS=s,s.forEach((e,t)=>{const{op:n,$element:r,idx:o}=e;if("keep_counterpart"===n.type){if(n.counterpart.getIdx()!==o){const t=e.getBefore();t?n.counterpart.$element.insertAfter(t.$element):e.getRealParent().$element.prepend(n.counterpart.$element)}!function(e,t){const n=e[0].attributes??[],r=t[0].attributes??[];[...n].forEach(n=>{t.is(`[${n.name}]`)||e.removeAttr(n.name)}),[...r].forEach(t=>{t.name.startsWith("data")||e.attr(t.name)===t.value||e.attr(t.name,t.value)}),e.removeData(),Object.entries(t.data()).forEach(([t,n])=>{e.data(t,n)})}(n.counterpart.$element,r),r.hasClass(U)&&(r.data(L).$container=n.counterpart.$element,r.data(L,null)),i.push(r)}else if("delete"===n.type)r.safeRemove();else if("insert"===n.type){const{after:t,target:n}=e.op;t?r.insertAfter(t.$element):n&&n.$element.prepend(r)}}),i.forEach(e=>e.safeRemove())}function Y(e,t,n){return t.filter(e=>e.depth===n&&!e.op).forEach(t=>{const n=e.find(e=>!e.op&&e.id===t.id);if(n){const e=(t,n)=>{t.op={type:"keep",idx:n.idx},n.op={type:"keep_counterpart",counterpart:t},t=t.parent,n=n.parent,!t||t.op||n?.op||e(t,n)};e(n,t)}}),n>1?Y(e,t,n-1):(e.forEach((t,n)=>{if(!t.op){const r=(e[n-1]?.op.idx??-1)+1;t.op={type:"delete",idx:r}}}),t.forEach((e,n)=>{if(e.getBefore=()=>function(e,n){const r=e.depth;for(;n>=1&&e.depth>=r;)if((e=t[n-=1]).depth===r)return"keep_counterpart"===e.op.type?e.op.counterpart:e;return null}(e,n),e.getRealParent=()=>{return(t=e).parent?"keep_counterpart"===t.parent.op.type?t.parent.op.counterpart:t.parent:null;var t},!e.op){const t=e.getRealParent(),n="insert"===t?.op.type?"insert_ignore":"insert";e.op={type:n,target:t,after:e.getBefore()}}}),[...e,...t].sort((e,t)=>(e.op?.idx??e.idx)-(t.op?.idx??t.idx)))}function Z(e,t,n=null){if(t||(t=W(e)),!t)return Promise.resolve();const{refreshProcess:r,isRunningProcess:o}=x(n,t);return e??=t.$container,H(_e.tagNames,e,t,n).then(()=>function(e,t,n){return function(e,t,n){const r=[];return t.find(`._bind_to_update_handler.sdc_uuid_${e._uuid}`).each(function(){const t=$(this);let o;if(t.hasClass("_with_handler"))o=t.data("handler");else{let t=this.tagName.toLowerCase().replace(/^this./,"");e[t]&&(o=e[t])}if("function"==typeof o){const n=f(t.data());o=o.bind(e)(n)}o&&r.push(Promise.resolve(o).then(r=>{let o=$("<div></div>");return o.append(r),""===t.html()&&t.append("<div></div>"),_e.reconcile(e,o,t.children(),n)}))}),Promise.all(r)}(e,t??e.$container,n)}(t,e,r).then(()=>{o||R(r)}))}const Q=25e3;class ee{constructor(e,t){this.pk=e,this._model=t}set model(e){this._model=e}get model(){return this._model}load(e){if(!this._model)throw new TypeError("Model is not set!!");return this.pk instanceof Array?e.newModel(this._model,{pk__in:this.pk}):e.newModel(this._model,{pk:this.pk})}}const te={get(e,t){const n=e[t]??void 0;if(n instanceof ee){if(!n.pk&&0!==n.pk)return null;let e;return e=n.pk instanceof Array?n.pk.slice():new Number(n.pk),e.load=n.load.bind(n),e}return n},set(e,t,n){if(t in e){const r=e[t];if(r instanceof ee)if(n.hasOwnProperty("pk"))r.pk=n.pk;else try{r.pk=JSON.parse(n)}catch{r.pk=n}else e[t]=n}else e[t]=n;return!0}};function ne(e){return e.toLowerCase().match(/^(true|false)$/)?"true"===e.toLowerCase():"undefined"!==e?"none"===e.toLowerCase()?null:e.match(/^-?\d+$/)?parseInt(e):e.match(/^-?\d+\.?\d+$/)?parseFloat(e):e.match(/^(['][^']*['])|(["][^"]*["])$/)?e.substring(1,e.length-1):e:void 0}class re{constructor(e,t={}){this._onNoOpenRequests=[],this.values_list=[],this.values={},this.model_name=e,this.model_query=t,this._is_connected=!1,this._is_conneting_process=!1,this._auto_reconnect=!0,this.socket=null,this.open_request={},this.on_update=()=>{},this.on_create=()=>{},this.form_id=d()}[Symbol.iterator](){let e=-1;return{next:()=>(++e,e<this.values_list.length?{value:this.values_list[e],done:!1}:{value:null,done:!0})}}length(){return this.values_list.length}byPk(e){if(null!==e){e=parseInt(e),isNaN(e)&&(e=-1);let t=this.values_list.find(t=>t.pk===e);return t||(t=new Proxy({pk:e},te),this.values_list.push(t)),t}return{pk:e}}filter(e){return this.model_query=Object.assign({},this.model_query,e),this}load(){return this.isConnected().then(()=>{const e=d();return new Promise((t,n)=>{this.socket.send(JSON.stringify({event:"model",event_type:"load",event_id:e,args:{model_name:this.model_name,model_query:this.model_query}})),this.open_request[e]=[t,n]})})}listView(e={},t=null,n=null,r={}){return this.view({filter:e,cbResolve:t,cbReject:n,templateContext:r})}view({viewName:e="html_list_template",filter:t={},cbResolve:n=null,cbReject:r=null,templateContext:o={}}){let s=$('<div class="container-fluid">');return this.isConnected().then(()=>{const i=d();this.socket.send(JSON.stringify({event:"model",event_type:"named_view",event_id:i,args:{view_name:e,model_name:this.model_name,model_query:this.model_query,filter:t,template_context:o}})),this.open_request[i]=[e=>{s.append(e.html),_e.refresh(s),n&&n(e)},e=>{r&&r(e)}]}),s}detailView(e=null,t=null,n=null,r={}){e=e??-1,e=parseInt(e),isNaN(e)&&(e=-1);let o,s=$('<div class="container-fluid">');return o=0!==this.values_list.length?this.isConnected():this.load(),o.then(()=>{-1===e&&(e=this.values_list[0].pk);const o=d();this.socket.send(JSON.stringify({event:"model",event_type:"detail_view",event_id:o,args:{model_name:this.model_name,model_query:this.model_query,pk:e,template_context:r}})),this.open_request[o]=[e=>{s.append(e.html),_e.refresh(s),t&&t(e)},e=>{n&&n(e)}]}),s}syncFormToModel(e){return this.syncForm(e)}syncModelToForm(e){e&&e.hasClass(this.form_id)||(e=$(`.${this.form_id}`));let t=this;e.each(function(){if(!this.hasAttribute("data-model_pk"))return;let e=$(this).data("model_pk"),n=t.byPk(e);for(let e of this.elements){let t=e.name;if(t&&""!==t)if("checkbox"===e.type)e.checked=n[t];else if("file"===e.type&&n[t]instanceof File){let r=new DataTransfer;r.items.add(n[t]),e.files=r}else $(e).val(n[t])}})}syncForm(e){e&&e.hasClass(this.form_id)||(e=$(`.${this.form_id}`));const t=this;let n=[];return e.each(function(){let e=$(this).data("model_pk"),r=t.byPk(e);for(let e of this.elements){let t=e.name;t&&""!==t&&("hidden"===e.type?r[t]=ne($(e).val()):"checkbox"===e.type?r[t]=e.checked:"file"===e.type?r[t]=e.files[0]:r[t]=$(e).val())}return n.push(r),r}),this.values_list.length<=1&&n.length>0&&(this.values=n.at(-1)),n}createForm(e=null,t=null){let n=$("<div>");return this.isConnected().then(()=>{this._getForm(null,"create_form",null,n,e,t)}),n}editForm(e=-1,t=null,n=null){let r;e=parseInt(e),isNaN(e)&&(e=-1),r=0!==this.values_list.length?this.isConnected():this.load();let o=$("<div>");return r.then(()=>{e<=-1&&(e=this.values_list.at(e).pk),this._getForm(e,"edit_form",null,o,t,n)}),o}namedForm(e=-1,t,n=null,r=null){let o;e=parseInt(e),isNaN(e)&&(e=-1),o=0!==this.values_list.length?this.isConnected():this.load();let s=$('<div class="container-fluid">');return o.then(()=>{e<=-1&&(e=this.values_list.at(e).pk),this._getForm(e,"named_form",t,s,n,r)}),s}_getForm(e,t,n,r,o,s){e=parseInt(e),isNaN(e)&&(e=-1);const i=d();this.socket.send(JSON.stringify({event:"model",event_type:t,event_id:i,args:{model_name:this.model_name,model_query:this.model_query,pk:e,form_name:n}}));const l=null===e||-1===e?"create":"edit";this.open_request[i]=[t=>{r.append(t.html);let s=r.closest("form").addClass(`sdc-model-${l}-form sdc-model-form ${this.form_id}`).data("model",this).data("model_pk",e).data("form_name",n);s.length>0&&!s[0].hasAttribute("sdc_submit")&&s.attr("sdc_submit","submitModelFormDistributor"),_e.refresh(r),o&&o(t)},e=>{s&&s(e)}]}new(){return new Promise((e,t)=>{const n=$("<form>").append(this.createForm(()=>{this.syncFormToModel(n),e()},t))})}save(e=-1,t="edit_form"){return e=parseInt(e),isNaN(e)&&(e=-1),this.isConnected().then(()=>{let n;n=e>-1?[this.byPk(e)]:this.values_list;let r=[];return n.forEach(e=>{const n=d();r.push(new Promise((r,o)=>{this._readFiles(e).then(s=>{this.socket.send(JSON.stringify({event:"model",event_type:"save",event_id:n,args:{form_name:t,model_name:this.model_name,model_query:this.model_query,data:e,files:s}})),this.open_request[n]=[e=>{let t="string"==typeof e.data.instance?JSON.parse(e.data.instance):e.data.instance;e.data.instance=this._parseServerRes(t),r(e)},o]})}))}),Promise.all(r)})}create(e=this.values){const t=d();return this.isConnected().then(()=>new Promise((n,r)=>{this._readFiles(e).then(o=>{this.socket.send(JSON.stringify({event:"model",event_type:"create",event_id:t,args:{model_name:this.model_name,model_query:this.model_query,data:e,files:o}})),this.open_request[t]=[e=>{let t="string"==typeof e.data.instance?JSON.parse(e.data.instance):e.data.instance;-1===this.values?.pk&&(this.values_list=[],this.values=null),e.data.instance=this._parseServerRes(t)[0],n(e)},r]})}))}delete(e=-1){e=parseInt(e),isNaN(e)&&(e=-1),-1===e&&(e=this.values?.pk);const t=d();return this.isConnected().then(()=>new Promise((n,r)=>{this.socket.send(JSON.stringify({event:"model",event_type:"delete",event_id:t,args:{model_name:this.model_name,model_query:this.model_query,pk:e}})),this.open_request[t]=[n,r]}))}isConnected(){return new Promise((e,t)=>{if(this._is_connected)e();else if(this._is_conneting_process){const[n,r]=this.open_request._connecting_process;this.open_request._connecting_process=[()=>{n(),e()},()=>{r(),t()}]}else this._is_conneting_process=!0,this.open_request._connecting_process=[()=>{},()=>{}],this._connectToServer().then(()=>{e(this._checkConnection())})})}close(){this.socket&&(this._auto_reconnect=!1,this.socket.onclose=()=>{},this.socket.close(),delete this.socket)}clean(){return this.values_list=[],this.values={},this}_readFiles(e){let t=[],n={};for(const[r,o]of Object.entries(e))o instanceof File&&t.push(new Promise((e,t)=>{((r,o)=>{let s=new FileReader;s.onload=s=>{const i=d();this.open_request[i]=[e,t];let l=s.target.result,a=parseInt(Math.ceil(l.length/Q));n[r]={id:i,file_name:o.name,field_name:r,content_length:o.size};for(let e=0;e<a;++e)this.socket.send(JSON.stringify({event:"model",event_type:"upload",event_id:i,args:{chunk:l.slice(Q*e,Q*(e+1)),idx:e,number_of_chunks:a,file_name:o.name,field_name:r,content_length:o.size,content_type:o.type,model_name:this.model_name,model_query:this.model_query}}))},s.onerror=()=>{t()},s.readAsBinaryString(o)})(r,o)}));return Promise.all(t).then(()=>n)}_onMessage(e){let t=JSON.parse(e.data);if(t.is_error)this.open_request.hasOwnProperty(t.event_id)&&(this.open_request[t.event_id][1](t),this._closeOpenRequest(t.event_id)),(t.msg||t.header)&&M("pushErrorMsg",t.header||"",t.msg||""),"connect"===t.type&&(this.open_request._connecting_process[1](t),this._closeOpenRequest("_connecting_process"),this._auto_reconnect=!1,this.socket.close());else{if((t.msg||t.header)&&M("pushMsg",t.header||"",t.msg||""),"connect"===t.type)this._is_connected=!0,this._is_conneting_process=!1,this.open_request._connecting_process[0](t),this._closeOpenRequest("_connecting_process");else if(["load","named_view","detail_view"].includes(t.type)){const e=JSON.parse(t.args.data);this.values_list=[],t.args.data=this._parseServerRes(e)}else if("on_update"===t.type||"on_create"===t.type){const e=JSON.parse(t.args.data);let n,r=this._parseServerRes(e);n="on_create"===t.type?this.on_create:this.on_update,n(r),t.args.data=r}let e=t.data?.instance;e&&(t.data.instance=JSON.parse(t.data.instance)),this.open_request.hasOwnProperty(t.event_id)&&(this.open_request[t.event_id][0](t),this._closeOpenRequest(t.event_id))}}noOpenRequests(){return new Promise(e=>{if(0===Object.keys(this.open_request).length)return e();this._onNoOpenRequests.push(e)})}_closeOpenRequest(e){delete this.open_request[e],0===Object.keys(this.open_request).length&&(this._onNoOpenRequests.forEach(e=>e()),this._onNoOpenRequests=[])}_connectToServer(){return new Promise(e=>{const t=`${this.model_name}`+(this.model_id>0?`/${this.model_id}`:"");"https:"===window.location.protocol?this.socket=new WebSocket(`wss://${window.location.host}/sdc_ws/model/${t}`):this.socket=new WebSocket(`ws://${window.location.host}/sdc_ws/model/${t}`),this.socket.onmessage=this._onMessage.bind(this),this.socket.onclose=e=>{console.error(`SDC Model (${this.model_name}, ${this.model_id}) Socket closed unexpectedly`),this._is_connected=!1;for(const[t,n]of Object.entries(this.open_request))n[1](e);this.open_request={},setTimeout(()=>{this._auto_reconnect&&this._connectToServer().then(()=>{})},1e3)},this.socket.onerror=e=>{if(console.error(`Model Socket encountered error: ${e} Closing socket`),this._is_connected)try{this.socket.close()}catch(e){}},this.socket.onopen=()=>{e()}})}_checkConnection(){const e=d();return new Promise((t,n)=>{this.socket.send(JSON.stringify({event:"model",event_type:"connect",event_id:e,args:{model_name:this.model_name,model_query:this.model_query}})),this.open_request[e]=[t,n]})}_parseServerRes(e){let t=[];for(let n of e){const e=n.pk,r=this.byPk(e);for(const[e,t]of Object.entries(n.fields))t&&"object"==typeof t&&t.__is_sdc_model__?r[e]=new ee(t.pk,t.model):r[e]=t;t.push(r)}return 1===this.values_list.length?this.values=this.values_list.at(-1):this.values={},t}}let oe=!1,se=!1,ie=null,le={};function ae(){return window.SERVER_CALL_VIA_WEB_SOCKET?new Promise(e=>oe?e():se?void setTimeout(()=>{ae().then(()=>{e()})},200):e(ue())):Promise.resolve(!0)}function ce(){window.SERVER_CALL_VIA_WEB_SOCKET&&function(){if(oe){oe=!1;try{ie.close()}catch(e){}}}()}function ue(){return se=!0,new Promise(e=>{ie="https:"===window.location.protocol?new WebSocket(`wss://${window.location.host}/sdc_ws/ws/`):new WebSocket(`ws://${window.location.host}/sdc_ws/ws/`),ie.onmessage=function(e){de(JSON.parse(e.data))},ie.onclose=function(){oe&&console.error("SDC Socket closed unexpectedly"),oe=!1;for(const[e,t]of Object.entries(le))t[1]({}),delete le[e];setTimeout(()=>{ue()},1e3)},ie.onerror=function(e){if(console.error("Socket encountered error: ",e.message,"Closing socket"),oe)try{ie.close()}catch(e){}},ie.onopen=function(){oe=!0,se=!1,e()}})}function de(e){if(e||(e={}),e.is_error)(e.msg||e.header)&&M("pushErrorMsg",e.header||"",e.msg||""),e.id&&le[e.id]&&(le[e.id][1](e.data||null),delete le[e.id]);else if((e.msg||e.header)&&M("pushMsg",e.header||"",e.msg||""),e.type&&"sdc_recall"===e.type)e.id&&le[e.id]&&(le[e.id][0](e.data),delete le[e.id]);else if(e.type&&"sdc_event"===e.type){let t=e.event;t&&M(t,e.payload)}else e.type&&"sdc_redirect"===e.type&&M("onNavLink",e.link)}class he{constructor(){this._uuid=d(),this.contentUrl="",this.contentReload=!1,this.parsedContentUrl=null,this.events=[],this.load_async=!1,this._isEventsSet=!1,this._allEvents=null,this._urlParams=[],this._models=[],this._cssUrls=[],this.afterShow=()=>{console.warn("afterShow is deprecated!!")},this._mixins={},this._tagName=Object.getPrototypeOf(this)._tagName??"",this._childController={},this._parentController=null,this._onLoadDone=!1,this.$container=null,this._isMixin=!1}_runLifecycle(e,t){_e.DEBUG&&!this._isMixin&&console.debug(e,this._tagName);let n=[];if(!this._isMixin){this._isMixin=!0;for(let r in this._mixins){let o=this._mixins[r];"function"==typeof o[e]&&n.push(o[e].apply(this,t))}return Promise.all(n).then(()=>{this._isMixin=!1})}}onInit(){_e.DEBUG&&!this._isMixin&&console.DEBUG(Array.apply(null,arguments),this._tagName)}get parentController(){return this._parentController}get childController(){return this._childController}onLoad(){return this._runLifecycle("onLoad",arguments)}willShow(){return this._runLifecycle("willShow",arguments)}onRefresh(){return this._runLifecycle("onRefresh",arguments)}onRemove(){return this._runLifecycle("onRemove",arguments),!0}noOpenModelRequests(){return Promise.all(this._models.map(e=>e.noOpenRequests()))}remove(){for(const e of this._models)e.close();let e=this._childController;for(let t in e)if(e.hasOwnProperty(t))for(let n of e[t])if(!n.remove())return!1;if(!this.onRemove||this.onRemove()){A(this);const e=i(this._tagName);if(this._parentController._childController[e]){let t=this._parentController._childController[e];for(let e=0;e<t.length;e++)t[e]===this&&t.splice(e,1)}return this.$container.remove(),!0}return!1}controller_name(){return this._tagName.replace(/-./g,e=>` ${e[1].toUpperCase()}`).replace(/^./g,e=>`${e.toUpperCase()}`)}addEvent(e,t,n){this.getEvents(),this._allEvents[e]=this._allEvents[e]||{},this._allEvents[e][t]=n}getEvents(){if(this._allEvents)return this._allEvents;let e=[];e=e.concat(this.events);for(let t in this._mixins){let n=this._mixins[t];Array.isArray(n.events)&&(e=e.concat(n.events))}return this._allEvents=_.merge(...e)}post(e,t){return _e.post(this,e,t)}get(e,t){return _e.get(this,e,t)}submitForm(e,t,n){return _e.submitFormAndUpdateView(this,e,t,n)}serverCall(e,t){let n=this.contentUrl.match(/sdc_view\/([^/]+)/i);if(n&&!(n.length<2))return function(e,t,n,r,o){return window.SERVER_CALL_VIA_WEB_SOCKET?function(e,t,n,r){let o=d();return ae().then(()=>{ie.send(JSON.stringify({event:"sdc_call",id:o,controller:t,app:e,function:n,args:r}))}),new Promise((e,t)=>{le[o]=[e,t]})}(e,t,r,o):function(e,t,n){return"object"!=typeof n&&Array.isArray(n)&&null===n&&(n={arg0:n}),n={data:JSON.stringify(n),_sdc_func_name:t,_method:"sdc_server_call"},$.post({url:e,data:n,beforeSend:function(e,t){e.setRequestHeader("X-CSRFToken",window.CSRF_TOKEN)}}).then(e=>{const t=e._return_data;return de(t),t}).catch(e=>{const t=e.responseJSON;throw t.is_error=!0,de(t),e})}(n,r,o)}(n[1],this._tagName,this.parsedContentUrl??this.contentUrl,e,t);console.error("To use the serverCall function the contentUrl must be set: "+this.name)}newModel(e,t={}){if(e instanceof Number&&e.hasOwnProperty("load"))return e.load(this);const n=new re(e,t);return this._models.push(n),n}updateModel(e,t={},n){let r=new re(e,t);return r.load().then(()=>{r.values|=n,r.save().then(()=>(r.close(),r.values))})}find(e){return this.$container.find(e)}refresh(){return _e.refresh(this.$container,this)}reload(){return _e.reloadController(this)}reconcile(e,t=null){return _e.reconcile(this,e,t)}submitModelFormDistributor(e,t){return"function"==typeof this._submitModelForm?this._submitModelForm(e,t):"function"==typeof this.submitModelForm?this.submitModelForm(e,t):this.defaultSubmitModelForm(e,t)}iterateAllChildren(){let e=this._childController,t=[];for(let n in e)if(e.hasOwnProperty(n))for(let r of e[n])t.push(r),t.push(...r.iterateAllChildren());return t}defaultSubmitModelForm(e,t){let n=[];if(!this._isMixin){t.stopPropagation(),t.preventDefault();let{model:r,form_name:o}=e.data();const s=r.syncForm(e);for(let t of s)n.push(new Promise((n,s)=>{let i;i=null!==t.pk&&t.pk>=0?r.save(t.pk,o):r.create(t),i.then(t=>{h(e),this.submit_model_form_success&&this.submit_model_form_success(t[0]);for(const e of this.iterateAllChildren())e.submit_model_form_success&&e.submit_model_form_success(t[0]);n(t)}).catch(t=>{p(e,$(t.html)),this.submit_model_form_error&&this.submit_model_form_error(t);for(const e of this.iterateAllChildren())e.submit_model_form_error&&e.submit_model_form_error(t);s(t)})}))}return Promise.all(n).then(e=>Object.assign({},...e.flat()))}}const pe={classname:"class"};window.sdcDom=function(e,t,...n){if(!e)return"";const r=function(e,t){let n,r=!1;if("string"==typeof e)n=$(document.createElement(e));else{const t=`this.${e.name}`;n=$(document.createElement(t)),n.data("handler",e),r=!0}return t&&Object.entries(t).forEach(([e,t])=>{e.startsWith("on")?n[0].addEventListener(e.substring(2).toLowerCase(),t):(pe[e.toLowerCase()]&&(e=pe[e.toLowerCase()]),n[0].setAttribute(e,t))}),r&&n.addClass("_bind_to_update_handler _with_handler"),n}(e,t);for(const e of n)r.append(e);return r};let fe,_e={CSRF_TOKEN:window.CSRF_TOKEN||"",LANGUAGE_CODE:window.LANGUAGE_CODE||"en",DEBUG:window.DEBUG||!1,VERSION:window.VERSION||"0.0",tagNames:[],Global:b,rootController:null,globalRootController:null,_isInit:!1,_origin_trigger:null,_globalControllerClasses:[],init_sdc:()=>{_e._isInit||(_e._isInit=!0,_e._origin_trigger?ce():(_e._origin_trigger=$.fn.trigger,$.fn.trigger=function(e){const t={}.hasOwnProperty.call(e,"type")?e.type:e;return v.includes(t)||(v.push(t),$(window).on(t,O)),_e._origin_trigger.call(this,e)},_e.updateJquery()),ae(),function(){const e=$(window);v.forEach(t=>{e.off(t).on(t,O)})}(),_e.rootController=_e.rootController||new he,_e.globalRootController=_e.globalRootController||new he),_e.tagNames=Object.keys(k);const e=$("<div></div>");b.forEach(t=>{const n=k[t][0];e.append(`<${n.prototype._tagName}></${n.prototype._tagName}>`)});const{refreshProcess:n}=x(null,_e.rootController);return H(_e.tagNames,e,_e.globalRootController,n).then(()=>H(_e.tagNames,(t||(t=$("body")),t),_e.rootController,n).then(e=>(R(n),e)))},updateJquery:()=>{$.fn.safeReplace=function(e){return _e.safeReplace($(this),e)},$.fn.safeEmpty=function(){return _e.safeEmpty($(this))},$.fn.safeRemove=function(){return _e.safeRemove($(this))}},controllerToTag:e=>s(e.name).replace(/-controller$/,""),registerGlobal:e=>{_e.register(e);let t=e.prototype._tagName;b.push(t)},cleanCache:()=>{I={}},register:e=>{let t=_e.controllerToTag(e);return k[t]=[e,[]],e.prototype._tagName=t,{addMixin:(...e)=>{for(let n of e){let e;"string"==typeof n?e=s(n):n&&(e=_e.controllerToTag(n)),k[t][1].push(e)}}}},post:(e,t,n)=>(n||(n={}),n.CSRF_TOKEN=_e.CSRF_TOKEN,_e.ajax(e,t,params,$.post)),get:(e,t,n)=>_e.ajax(e,t,n,$.get),ajax:(e,t,n,r)=>{n||(n={}),n.VERSION=_e.VERSION,n._method=n._method||"api";const o=new Promise((s,i)=>r(t,n).then((t,n,r)=>{s(t,n,r),"redirect"===t.status?M("onNavLink",t["url-link"]):o.then(()=>{_e.refresh(e.$container)})}).catch(i));return o},submitFormAndUpdateView:(e,t,n,r)=>{let o=new FormData(t);const s=e=>{e["url-link"]?M("onNavLink",e["url-link"]):window.location.href=e.url},i=new Promise((l,c)=>{a(o,n||t.action,r||t.method).then((t,n,r)=>{l(t,n,r),"redirect"===t.status?s(t):i.then(()=>{_e.refresh(e.$container,e)})}).catch((e,t,n)=>{301===e.status?(e=e.responseJSON,s(e),l(e,t,n)):c(e,t,n)})});return i},submitForm:(e,t,n)=>{let r=new FormData(e);return new Promise((o,s)=>{a(r,t||e.action,n||e.method).then(o).catch(s)})},getController:e=>W(e),safeEmpty:e=>(e.children().each(function(e,t){let n=$(t);_e.safeRemove(n)}),e),safeReplace:(e,t)=>(t.insertBefore(e),_e.safeRemove(e)),safeRemove:e=>(e.each(function(){let e=$(this);e.data(`${L}`)&&e.data(`${L}`).remove()}),e.find(`.${U}`).each(function(){const e=$(this).data(`${L}`);e&&e.remove()}),e.remove()),reloadController:e=>function(e){if(e.contentUrl){let t=B(e);return e.contentUrl=t.url,D(e.contentUrl,t.args,e._tagName,e.contentReload)}return new Promise(e=>{e($())})}(e).then(t=>{let n=$(t);return _e.reconcile(e,n)}),reconcile:(e,t,n=null,r=null)=>{if(!n){let n=e.$container.clone().empty();n.data(L,null),n.removeClass(U),n.append(t),t=n}n=n??e.$container;const{refreshProcess:o,isRunningProcess:s}=x(r,e);return Z(t,e,o).then(()=>{var r;return z(t,n),(r=e)._childController={},r.find(`.${U}`).each(function(){const e=W($(this));e===r&&N(r,e)}),s||R(o),e})},refresh:(e,t)=>Z(e,t)},me=[];function ge(){if(!jest)throw new Error("JEST is not defined");0===me.length&&(fe=$.ajax.bind($),me.push(jest.spyOn($,"ajax")),me[0].mockImplementation(function(e){return fe(e).then(e=>e).catch(e=>e)}))}const ye=ce,ve={get_controller:async function(e,t={},n=""){ge();const r=$("body");_e.updateJquery(),r.safeEmpty();const o=$(`<${e}>${n}</${e}>`);for(const[e,n]of Object.entries(t))o.data(e,n);const s=$("<div></div>").append(o);return r.append(s),_e._isInit=!1,_e.cleanCache(),await _e.init_sdc(),_e.getController(o)},getCsrfToken:function(){return function(e){if(document.cookie&&""!==document.cookie){const t=document.cookie.split(";");for(let n=0;n<t.length;n++){const r=t[n].trim();if(r.substring(0,10)===e+"=")return decodeURIComponent(r.substring(10))}}return""}("csrftoken")},controllerFromTestHtml:async function(e,t=null){ge();const n=$("body");_e.updateJquery(),n.safeEmpty().append(e),_e._isInit=!1,_e.cleanCache(),await _e.init_sdc();let r=_e.rootController.iterateAllChildren();if(!t)return r;const o=r[0].onRefresh,s=jest.spyOn(r[0],"onRefresh");return new Promise(e=>{s.mockImplementation(function(){s.mockRestore();const t=o.apply(r[0],arguments);return e(r),t})})}};export{he as AbstractSDC,A as allOff,_e as app,u as checkIfParamNumberBoolOrString,h as clearErrorsInForm,S as controllerFactory,j as on,E as runControlFlowFunctions,p as setErrorsInForm,T as setEvent,ye as socketReconnect,ve as test_utils,M as trigger};
|
package/gulp/gulp.jsx
CHANGED
|
@@ -5,12 +5,12 @@ const gclean = require('gulp-clean');
|
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
const exec = require('gulp-exec');
|
|
7
7
|
const dotenv = require("dotenv");
|
|
8
|
-
const
|
|
8
|
+
const gulp = require('gulp');
|
|
9
9
|
|
|
10
10
|
function scss() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
return src('./src/*.scss', {follow: true})
|
|
12
|
+
.pipe(sass().on('error', sass.logError))
|
|
13
|
+
.pipe(dest('../static'));
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -21,105 +21,112 @@ function scss() {
|
|
|
21
21
|
* @returns {*}
|
|
22
22
|
*/
|
|
23
23
|
function pre_compile_javascript() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
24
|
+
let file_extentions = process.env.JS_CILENT_FILE_EXTENTIONS?.split(',') || ['.js', '.json'];
|
|
25
|
+
return src(file_extentions.map((x) => `./src/**/*${x}`), {follow: true})
|
|
26
|
+
.pipe(through.obj(function (obj, enc, next) {
|
|
27
|
+
let srcFile = obj.path
|
|
28
|
+
if (!obj.isNull() && !obj.isDirectory() && obj.isBuffer() && /.js$/.test(srcFile)) {
|
|
29
|
+
let file_content = obj.contents.toString().split('\n');
|
|
30
|
+
let controller_name = null;
|
|
31
|
+
let on_init_p_name = null;
|
|
32
|
+
file_content.forEach((element) => {
|
|
33
|
+
if (!controller_name) {
|
|
34
|
+
let a = element.match(/class (.*)\s+extends\s*AbstractSDC /);
|
|
35
|
+
if (a) controller_name = a[1];
|
|
36
|
+
}
|
|
37
|
+
if (!on_init_p_name) {
|
|
38
|
+
let a = element.match(/^\s*onInit\s*\((.*)\)\s*\{/);
|
|
39
|
+
if (a) on_init_p_name = a[1].split(/\s*,\s*/).join('", "');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
});
|
|
44
|
+
if (file_content && controller_name && on_init_p_name) {
|
|
45
|
+
file_content.push(`${controller_name}.prototype._on_init_params = function() {return ["${on_init_p_name}"]; };`);
|
|
46
|
+
obj.contents = Buffer.from(file_content.join('\n'));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
next(null, obj);
|
|
51
|
+
}))
|
|
52
|
+
.pipe(dest('./_build'));
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
function clean(done) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
if (fs.existsSync('./_build')) {
|
|
57
|
+
return src('./_build').pipe(gclean());
|
|
58
|
+
} else {
|
|
59
|
+
done()
|
|
60
|
+
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
function link_files(cb) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
console.error(error_msg);
|
|
81
|
-
this.emit('end'); // Continue with the next task
|
|
82
|
-
})).on('end', () => {
|
|
83
|
-
process.chdir('./Assets');
|
|
84
|
-
});
|
|
85
|
-
} catch {
|
|
64
|
+
dotenv.config({path: process.cwd() + '/.sdc_python_env'});
|
|
65
|
+
let python = process.env.PYTHON
|
|
66
|
+
if (!python) {
|
|
67
|
+
console.error(`The environment variable PYTHON (Path to python interpreter) is not set. In this case link_files cannot be executed`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
process.chdir('..');
|
|
71
|
+
const options = {
|
|
72
|
+
continueOnError: true, // default = false, true means don't emit error event
|
|
73
|
+
pipeStdout: true, // default = false, true means stdout is written to file.contents
|
|
74
|
+
};
|
|
75
|
+
const error_msg = `The environment variable PYTHON (Path to python interpreter) is not set. In this case link_files cannot be executed. Or the ${process.cwd()} is not correct`;
|
|
76
|
+
try {
|
|
77
|
+
return src('./manage.py')
|
|
78
|
+
.pipe(exec(file => `${python} ${file.path} sdc_update_links`, options).on('error', function (err) {
|
|
79
|
+
console.error('Error:', err.message);
|
|
86
80
|
console.error(error_msg);
|
|
81
|
+
this.emit('end'); // Continue with the next task
|
|
82
|
+
})).on('end', () => {
|
|
87
83
|
process.chdir('./Assets');
|
|
88
|
-
|
|
89
|
-
|
|
84
|
+
});
|
|
85
|
+
} catch {
|
|
86
|
+
console.error(error_msg);
|
|
87
|
+
process.chdir('./Assets');
|
|
88
|
+
cb();
|
|
89
|
+
}
|
|
90
90
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
|
|
94
94
|
exports.sdc_watch_scss = function () {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
});
|
|
95
|
+
const watcher = gulp.watch('./src/**/*.scss', {followSymlinks: true});
|
|
96
|
+
watcher.on('change', (a) => {
|
|
97
|
+
console.log(`${a} has changed! SCSS is recompiling...`);
|
|
98
|
+
scss().on('end', () => {
|
|
99
|
+
console.log(`... recompiling done!`);
|
|
101
100
|
});
|
|
101
|
+
});
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
function webpack_series_factory(webpack_task) {
|
|
105
|
-
|
|
105
|
+
return series(clean, pre_compile_javascript, webpack_task, clean);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
exports.sdc_webpack_series_factory = webpack_series_factory
|
|
109
109
|
|
|
110
110
|
exports.sdc_watch_webpack_factory = (webpack_task) => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
111
|
+
return function () {
|
|
112
|
+
// const watcher = chokidar.watch('./src/**/*.js', {followSymlinks: true});
|
|
113
|
+
|
|
114
|
+
const watcher = gulp.watch(
|
|
115
|
+
'src/**/*.js',
|
|
116
|
+
{
|
|
117
|
+
followSymlinks: true, // ✅ this enables following symlinks
|
|
118
|
+
usePolling: false, // optional
|
|
119
|
+
ignored: /node_modules/,
|
|
120
|
+
})
|
|
121
|
+
watcher.on('change', (a) => {
|
|
122
|
+
console.log(`${a} has changed! javascript is recompiling...`);
|
|
123
|
+
webpack_series_factory(webpack_task)();
|
|
124
|
+
});
|
|
125
|
+
};
|
|
119
126
|
};
|
|
120
127
|
|
|
121
128
|
exports.sdc_default_build_factory = (webpack_task) => {
|
|
122
|
-
|
|
129
|
+
return series(link_files, parallel(scss, webpack_series_factory(webpack_task)));
|
|
123
130
|
};
|
|
124
131
|
|
|
125
132
|
exports.sdc_scss = scss;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sdc_client",
|
|
3
|
-
"version": "0.57.
|
|
3
|
+
"version": "0.57.16",
|
|
4
4
|
"description": "Simple Dom Control",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "dist/ugly.index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "gulp development & gulp build",
|
|
@@ -29,12 +29,11 @@
|
|
|
29
29
|
"@babel/preset-react": "^7.26.3",
|
|
30
30
|
"@babel/register": "^7.25.9",
|
|
31
31
|
"babel-loader": "^10.0.0",
|
|
32
|
-
"chokidar": "^4.0.3",
|
|
33
32
|
"dotenv": "^16.4.7",
|
|
34
33
|
"glob-parent": "^6.0.2",
|
|
35
|
-
"glob-watcher": "^6.0.0",
|
|
36
34
|
"gulp": "^5.0.0",
|
|
37
35
|
"gulp-clean": "^0.4.0",
|
|
36
|
+
"gulp-exec": "^5.0.0",
|
|
38
37
|
"gulp-sass": "^6.0.1",
|
|
39
38
|
"jest": "^29.7.0",
|
|
40
39
|
"jest-environment-jsdom": "^29.7.0",
|
|
@@ -46,8 +45,7 @@
|
|
|
46
45
|
"webpack-stream": "^7.0.0"
|
|
47
46
|
},
|
|
48
47
|
"overrides": {
|
|
49
|
-
"glob-parent": "$glob-parent"
|
|
50
|
-
"glob-watcher": "$glob-watcher"
|
|
48
|
+
"glob-parent": "$glob-parent"
|
|
51
49
|
},
|
|
52
50
|
"dependencies": {
|
|
53
51
|
"@popperjs/core": "^2.11.8",
|
|
@@ -297,13 +297,13 @@ export class AbstractSDC {
|
|
|
297
297
|
if (!this._isMixin) {
|
|
298
298
|
e.stopPropagation();
|
|
299
299
|
e.preventDefault();
|
|
300
|
-
let model = $form.data(
|
|
300
|
+
let {model, form_name} = $form.data();
|
|
301
301
|
const values = model.syncForm($form);
|
|
302
302
|
for (let instance_value of values) {
|
|
303
303
|
p_list.push(new Promise((resolve, reject) => {
|
|
304
304
|
let prom;
|
|
305
305
|
if (instance_value.pk !== null && instance_value.pk >= 0) {
|
|
306
|
-
prom = model.save(instance_value.pk);
|
|
306
|
+
prom = model.save(instance_value.pk, form_name);
|
|
307
307
|
} else {
|
|
308
308
|
prom = model.create(instance_value);
|
|
309
309
|
}
|
|
@@ -3,6 +3,22 @@ import {getController} from './sdc_view.js';
|
|
|
3
3
|
export const STD_EVENT_BLACK_LIST = ['onbeforeunload', 'onunload'];
|
|
4
4
|
export const STD_EVENT_LIST = Object.keys(window).filter(key => /^on/.test(key) && !STD_EVENT_BLACK_LIST.includes(key)).map(x => x.slice(2));
|
|
5
5
|
|
|
6
|
+
function checkIfEventFits(ev_type, e, target) {
|
|
7
|
+
let elementUnderMouse;
|
|
8
|
+
switch (ev_type) {
|
|
9
|
+
case "mouseleave":
|
|
10
|
+
case "mouseout":
|
|
11
|
+
elementUnderMouse = document.elementFromPoint(e.clientX, e.clientY);
|
|
12
|
+
return target !== elementUnderMouse && !target.contains(elementUnderMouse);
|
|
13
|
+
case "mouseenter":
|
|
14
|
+
case "mousein":
|
|
15
|
+
elementUnderMouse = document.elementFromPoint(e.clientX, e.clientY);
|
|
16
|
+
return target !== elementUnderMouse && !target.contains(elementUnderMouse);
|
|
17
|
+
default:
|
|
18
|
+
return true;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
6
22
|
export function windowEventHandler(event) {
|
|
7
23
|
let ev_type = event.type;
|
|
8
24
|
if (event.hasOwnProperty('namespace') && event.namespace && event.namespace.length) ev_type += `.${event.namespace}`;
|
|
@@ -15,7 +31,7 @@ export function windowEventHandler(event) {
|
|
|
15
31
|
event.stopPropagation = () => is_last_elem = is_done = true;
|
|
16
32
|
while ($elm.length) {
|
|
17
33
|
let attrs = $elm.attr(`sdc_${ev_type}`);
|
|
18
|
-
if (attrs) {
|
|
34
|
+
if (attrs && checkIfEventFits(ev_type, event, $elm[0])) {
|
|
19
35
|
if (!controller) {
|
|
20
36
|
controller = getController($elm);
|
|
21
37
|
if (!controller) return;
|
|
@@ -2,51 +2,66 @@ import {getParamsNameOfFunction, checkIfParamNumberBoolOrString} from "./sdc_uti
|
|
|
2
2
|
import {DATA_CONTROLLER_KEY} from "./sdc_view.js";
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
export function prepareData(data, paramNameList = []) {
|
|
6
|
+
const data_json_key = 'SDC_JSON_MODEL=['
|
|
7
|
+
return Object.fromEntries(
|
|
8
|
+
Object.entries(data).filter(([key, element]) => {
|
|
9
|
+
return key !== DATA_CONTROLLER_KEY && !paramNameList.includes(key);
|
|
10
|
+
}).map(([key, element]) => {
|
|
11
|
+
if (typeof element === 'string' && element.startsWith(data_json_key)) {
|
|
12
|
+
try {
|
|
13
|
+
const {pk, fields} = JSON.parse(element.slice(data_json_key.length, -1));
|
|
14
|
+
return [key, {
|
|
15
|
+
...fields,
|
|
16
|
+
id: pk,
|
|
17
|
+
pk
|
|
18
|
+
}];
|
|
19
|
+
} catch {
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return [key, element];
|
|
23
|
+
})
|
|
24
|
+
);
|
|
25
|
+
}
|
|
6
26
|
|
|
7
27
|
function getParamList(paramNameList, $element) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
28
|
+
let returnList;
|
|
29
|
+
if (!paramNameList) {
|
|
30
|
+
paramNameList = [];
|
|
31
|
+
}
|
|
12
32
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
for(let a in data) {
|
|
16
|
-
if(data.hasOwnProperty(a) && a !== DATA_CONTROLLER_KEY && !paramNameList.includes(a)) {
|
|
17
|
-
restdata[a] = data[a];
|
|
18
|
-
}
|
|
19
|
-
}
|
|
33
|
+
let data = $element.data();
|
|
34
|
+
let restData = prepareData(data, paramNameList);
|
|
20
35
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
36
|
+
returnList = [];
|
|
37
|
+
for (let i = 0; i < paramNameList.length; i++) {
|
|
38
|
+
let data_name = paramNameList[i];
|
|
24
39
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
40
|
+
if (data.hasOwnProperty(data_name)) {
|
|
41
|
+
returnList.push(data[data_name]);
|
|
42
|
+
} else {
|
|
43
|
+
returnList.push('undefined');
|
|
30
44
|
}
|
|
45
|
+
}
|
|
31
46
|
|
|
32
|
-
|
|
33
|
-
|
|
47
|
+
returnList.push(restData)
|
|
48
|
+
return returnList;
|
|
34
49
|
}
|
|
35
50
|
|
|
36
51
|
function parseParamNameList(list, controller = null) {
|
|
37
|
-
|
|
52
|
+
let values = [];
|
|
38
53
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
54
|
+
for (let i = 0; i < list.length; i++) {
|
|
55
|
+
let tempValue = checkIfParamNumberBoolOrString(list[i], controller);
|
|
56
|
+
values.push(tempValue);
|
|
57
|
+
}
|
|
43
58
|
|
|
44
|
-
|
|
59
|
+
return values;
|
|
45
60
|
}
|
|
46
61
|
|
|
47
|
-
function getDomTagParamsWithList(paramNameList, $element, controller=null) {
|
|
48
|
-
|
|
49
|
-
|
|
62
|
+
function getDomTagParamsWithList(paramNameList, $element, controller = null) {
|
|
63
|
+
let paramList = getParamList(paramNameList, $element);
|
|
64
|
+
return parseParamNameList(paramList, controller);
|
|
50
65
|
}
|
|
51
66
|
|
|
52
67
|
/**
|
|
@@ -57,32 +72,32 @@ function getDomTagParamsWithList(paramNameList, $element, controller=null) {
|
|
|
57
72
|
* @returns {boolean}
|
|
58
73
|
*/
|
|
59
74
|
function reg_runOnInitWithParameter(controller, $element, applyController) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
75
|
+
if (!controller) {
|
|
76
|
+
return false
|
|
77
|
+
} else if (typeof controller.onInit !== 'function') {
|
|
78
|
+
return false
|
|
79
|
+
}
|
|
80
|
+
let paramNameList;
|
|
81
|
+
if (typeof controller._on_init_params === 'function') {
|
|
82
|
+
paramNameList = controller._on_init_params();
|
|
83
|
+
} else {
|
|
84
|
+
paramNameList = getParamsNameOfFunction(controller.onInit);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
let initParams = getDomTagParamsWithList(paramNameList, $element, applyController._parentController);
|
|
89
|
+
controller.onInit.apply(applyController, initParams);
|
|
90
|
+
if (applyController === controller) {
|
|
91
|
+
for (let mixinKey in controller._mixins) {
|
|
92
|
+
reg_runOnInitWithParameter(controller._mixins[mixinKey], $element, applyController);
|
|
79
93
|
}
|
|
94
|
+
}
|
|
80
95
|
}
|
|
81
96
|
|
|
82
97
|
export function runOnInitWithParameter($element, controller) {
|
|
83
|
-
|
|
98
|
+
reg_runOnInitWithParameter(controller, $element, controller);
|
|
84
99
|
}
|
|
85
100
|
|
|
86
101
|
export function getUrlParam(controller, $element) {
|
|
87
|
-
|
|
102
|
+
return getDomTagParamsWithList(controller._urlParams, $element);
|
|
88
103
|
}
|