gy-foo
Version:
A library that contains all models for the gy-web-project.
16 lines (14 loc) • 13.7 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define("gy-foo",["exports"],e):e((t=t||self)["gy-foo"]={})}(this,(function(t){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var e=function(){return(e=Object.assign||function(t){for(var e,r=1,i=arguments.length;r<i;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function r(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],i=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function i(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var i,o,n=r.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(t){o={error:t}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return s}var o,n,s,a=function(t){this.icon=t.icon?t.icon:"",this.label=t.label?t.label:"",this.class=t.class?t.class:"",this.disabled=!!t.disabled&&t.disabled,this.tooltip=t.tooltip?t.tooltip:"",this.tooltipPosition=t.tooltipPosition?t.tooltipPosition:"bottom"};(o=t.ModeFlags||(t.ModeFlags={})).ADD="add",o.CPY="cpy",o.DEL="del",function(t){t.ALL="ALL",t.RDO="RDO",t.DNY="DNY"}(n||(n={})),(s=t.FieldDisplay||(t.FieldDisplay={})).INPUT="INP",s.CALENDAR="CAL",s.CHECKBOX="CHK",s.DROPDOWN="DDL",s.IOV="IOV",s.RADIOGROUP="RAD",s.TEXTAREA="TXT";var c,u,d=function(){function e(t){var e=this;t&&Object.keys(t).forEach((function(r){return e[r]=t[r]}))}return e.prototype.canRead=function(t,e){var r=[n.RDO,n.ALL];return e&&e[t]?r.includes(e[t]):r.includes(this[t])},e.prototype.canReadWrite=function(t,e){return e&&e[t]?e[t]===n.ALL:this[t]===n.ALL},e.prototype.displayIOVBez=function(){return this.display===t.FieldDisplay.IOV&&this.iov},e.prototype.isIOVId=function(){return this.iov&&this.display!==t.FieldDisplay.IOV},e}(),p=function(){function e(t,r){t?t instanceof e?(this.pk=t.getPk(),this.structure=t.getStructure(),this.data=t.getData()?this.convertValues(t.getData(),t.getStructure()):{},this.meta=t.getMeta()||{},this.modified=t.isModified(),this.locked=t.isLocked()):(this.pk=t.pk,this.structure=t.structure,this.data=t.data?this.convertValues(t.data,t.structure):{},this.meta=t.meta||{},this.modified=!!t.modified&&t.modified,this.locked=!!t.locked&&t.locked):(this.pk=null,this.data={},this.structure={},this.meta={},this.modified=!1,this.locked=!1),this.setMode(r)}return e.prototype.convertValues=function(t,e){var i,o;try{for(var n=r(Object.keys(e)),s=n.next();!s.done;s=n.next()){var a=s.value,c=t[a.toUpperCase()];c&&(t[a.toUpperCase()]=new h(c.occs?c:{occs:c,structure:e[a.toUpperCase()]}))}}catch(t){i={error:t}}finally{try{s&&!s.done&&(o=n.return)&&o.call(n)}finally{if(i)throw i.error}}return t},e.prototype.getPk=function(){return this.pk},e.prototype.getStructure=function(){return this.structure},e.prototype.getValue=function(t){return this.data[t.toUpperCase()]},e.prototype.getMode=function(){return this.data._mode||""},e.prototype.getData=function(t){var e=this;return!1===t?Object.keys(this.data).filter((function(t){return!e.structure[t.toUpperCase()]})).reduce((function(t,r){var i;return Object.assign(t,((i={})[r]=e.data[r],i))}),{}):this.data},e.prototype.getSubEnt=function(t){return this.hasCollection(t)?this.data[t.toUpperCase()]:this.data[t.toUpperCase()]=new h},e.prototype.getCollection=function(t){return this.data[t.toUpperCase()]?this.data[t.toUpperCase()].occs:[]},e.prototype.getFields=function(t){var e=this;return Object.keys(this.data).filter((function(r){return t||!e.structure[r.toUpperCase()]}))},e.prototype.isModified=function(t){return void 0===t&&(t=!0),this.modified||(t&&this.hasAnyCollection()?this.checkSubEntityModified():this.modified)},e.prototype.isLocked=function(){return this.locked},e.prototype.getSubEntityStructure=function(t){return this.structure[t.toUpperCase()]},e.prototype.getMeta=function(){return this.meta},e.prototype.getMetaFieldList=function(t){return this.meta[t.toUpperCase()]&&this.meta[t.toUpperCase()].reduce((function(t,e){return Object.assign(t,e)}),{})||{}},e.prototype.getMetaField=function(t,e){var r=t.startsWith("_")?t:t.toUpperCase(),i=this.meta[e.toUpperCase()]?this.meta[e.toUpperCase()].find((function(t){return r in t})):void 0;return i?i[r]:{}},e.prototype.setMode=function(e,r){var i=this;e?e.del?this.data._mode=t.ModeFlags.DEL:e.cpy?this.data._mode=t.ModeFlags.CPY:e.add?this.data._mode=t.ModeFlags.ADD:this.data._mode&&delete this.data._mode:this.data._mode&&delete this.data._mode,r&&Object.keys(this.structure).forEach((function(t){i.data.hasOwnProperty(t)&&i.getCollection(t).forEach((function(t){return t.setMode(e,r)}))}))},e.prototype.addPk=function(t){this.pk||(this.pk=t)},e.prototype.setValue=function(t,e,r){if(void 0===r&&(r=!1),!r||!this.isLocked()){t.startsWith("_")||(t=t.toUpperCase());var i=this.data[t];this.data[t]=e,r&&i!=e&&(this.modified=!0)}},e.prototype.setValues=function(t,e){var r=this;void 0===e&&(e=!1),!t||e&&this.isLocked()||(Object.entries(t).forEach((function(t){var o=i(t,2),n=o[0],s=o[1];return r.setValue(n,s,e&&!r.modified)})),this.data=this.convertValues(this.data,this.structure))},e.prototype.setCollection=function(t,e){this.hasCollection(t.toUpperCase())?this.data[t.toUpperCase()].occs=e:this.getSubEntityStructure(t)&&(this.data[t.toUpperCase()]=new h({occs:e,structure:this.getSubEntityStructure(t)}))},e.prototype.setStructure=function(t){this.structure=Object.assign(this.structure,t)},e.prototype.setModified=function(t,e){var r=this;void 0===e&&(e=!1),this.modified=t,e&&Object.keys(this.structure).forEach((function(i){r.getSubEnt(i).setModified(t,e)}))},e.prototype.setMetaField=function(t,e,r){var i,o,n,s;if(r){var a=new d(r),c=t.toUpperCase(),u=e.toUpperCase();if(this.meta)if(this.meta[u]){var p=this.meta[u].find((function(t){return c in t}));p?Object.assign(p[c],a):this.meta[u].push(((s={})[c]=a,s))}else this.meta[u]=[(n={},n[c]=a,n)];else this.meta=((i={})[u]=[(o={},o[c]=a,o)],i)}},e.prototype.setMetaFieldList=function(t,e){var r,o=this;if(e){var n=Array.isArray(e)?e:[e],s=t.toUpperCase();this.meta?this.meta[s]?n.forEach((function(e){return Object.entries(e).forEach((function(e){var r=i(e,2),n=r[0],s=r[1];return o.setMetaField(n,t,s)}))})):this.meta[s]=n:this.meta=((r={})[s]=n,r)}},e.prototype.setMeta=function(t){var e=this;t&&(this.meta?Object.entries(t).forEach((function(t){var r=i(t,2),o=r[0],n=r[1];e.setMetaFieldList(o,n)})):this.meta=t)},e.prototype.copy=function(t,e,r){void 0===r&&(r=!1),this.pk=t.pk,this.data=t.data,this.structure=t.structure,this.meta=t.meta,this.modified=r,this.locked=!1,this.setMode({cpy:e})},e.prototype.copyOccFlat=function(){return new e({pk:this.pk,structure:this.structure,meta:this.meta,data:{_pk:this.data._pk,_hash:this.data._hash},modified:this.modified})},e.prototype.hasCollection=function(t){return this.data[t.toUpperCase()]},e.prototype.hasAnyCollection=function(){var t,e;try{for(var i=r(Object.keys(this.structure)),o=i.next();!o.done;o=i.next()){var n=o.value;if(this.data.hasOwnProperty(n))return!0}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=i.return)&&e.call(i)}finally{if(t)throw t.error}}return!1},e.prototype.changeSubEnt=function(t,e,r){void 0===r&&(r=!1),this.data[t.toUpperCase()]=e,r&&this.getSubEnt(t).setModified(!0,!1)},e.prototype.deleteSubEnt=function(t){delete this.data[t.toUpperCase()]},e.prototype.deleteValue=function(t){delete this.data[t.toUpperCase()]},e.prototype.checkSubEntityModified=function(){var t,e;try{for(var i=r(Object.keys(this.structure)),o=i.next();!o.done;o=i.next()){var n=o.value;if(this.hasCollection(n)&&this.getSubEnt(n).isModified())return!0}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=i.return)&&e.call(i)}finally{if(t)throw t.error}}return!1},e.prototype.equals=function(t){return this.getPk()===t.getPk()&&this.getValue("_hash")===t.getValue("_hash")},e.prototype.toString=function(){return JSON.stringify({pk:this.pk,_hash:this.data._hash})},e}(),h=function(){function o(t,e){void 0===e&&(e=!0),t?t instanceof o?(this.structure=t.getStructure(),this.occs=this.convertOccurences(t.getOccs(),e)||[]):(this.structure=t.structure,this.occs=this.convertOccurences(t.occs,e)||[]):(this.structure={},this.occs=[])}return o.isEntity=function(t){return!(!t||!t.occs)},o.prototype.getOccsLength=function(){return this.occs.length},o.prototype.getOccs=function(){return this.occs},o.prototype.setOccs=function(t){this.occs=t},o.prototype.hasOcc=function(t){return null!=this.occs.find((function(e){return e.getPk()===t}))},o.prototype.setOcc=function(t,e){e?this.occs=this.occs.map((function(r){return r.getPk()===e?t:r})):this.occs[0]=t},o.prototype.getOcc=function(t){if(t)return this.occs.find((function(e){return e.getPk()===t}));var e=void 0;return this.occs&&this.occs.length>0?e=this.occs[0]:(e=new p,this.addOcc(e)),e},o.prototype.getStructure=function(){return this.structure},o.prototype.addOcc=function(t,e,r){var i=null==e||e;if(t||(t=new p),t.setMode({add:i}),r&&t.setModified(!0,!1),!t.getPk()){var o="new_",n=1;this.occs.forEach((function(t){"new_"===t.getPk().substr(0,4)&&Number(t.getPk().substr(4))>=n&&(n=Number(t.getPk().substr(4))+1)})),o+=n,t.addPk(o)}t.getStructure()&&Object.keys(t.getStructure()).length||t.setStructure(this.structure);var s=this.occs.findIndex((function(e){return e.getPk()===t.getPk()}));return s>=0?this.occs[s]=t:this.occs.push(t),t.getPk()},o.prototype.copyOcc=function(t,r,i){var o=null==r||r,n=this.getOcc(t),s="add"===n.getMode();s&&(o=!1);var a=this.occs.filter((function(t){return t.getPk().search(new RegExp("^(?:copy_)?"+n.getPk()))>=0})).length,c=new p({pk:"copy_"+n.getPk()+"#"+a,data:e({},n.getData()),structure:n.getStructure(),meta:n.getMeta()},{add:s,cpy:o});return i&&n.setModified(!0,!1),this.occs.push(c),c.getPk()},o.prototype.addEntity=function(t){var e,r=this;(e=this.occs).push.apply(e,function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(i(arguments[e]));return t}(this.convertOccurences(t.occs).filter((function(t){return!r.hasOcc(t.getPk())}))))},o.prototype.convertOccurences=function(e,r){var i=this;return void 0===r&&(r=!0),e.map((function(e){return e instanceof p?e:new p(e.pk?e:{pk:e._pk,data:e,structure:i.structure||{}},r?{add:(null!=e.data?e.data._mode:e._mode)===t.ModeFlags.ADD,cpy:(null!=e.data?e.data._mode:e._mode)===t.ModeFlags.CPY,del:(null!=e.data?e.data._mode:e._mode)===t.ModeFlags.DEL}:null)}))},o.prototype.setModified=function(t,e){var i,o;void 0===e&&(e=!1);try{for(var n=r(this.getOccs()),s=n.next();!s.done;s=n.next()){s.value.setModified(t,e)}}catch(t){i={error:t}}finally{try{s&&!s.done&&(o=n.return)&&o.call(n)}finally{if(i)throw i.error}}},o.prototype.isModified=function(t){var e,i;void 0===t&&(t=!0);try{for(var o=r(this.getOccs()),n=o.next();!n.done;n=o.next()){if(n.value.isModified(t))return!0}}catch(t){e={error:t}}finally{try{n&&!n.done&&(i=o.return)&&i.call(o)}finally{if(e)throw e.error}}return!1},o}(),f=function(){function t(e){e instanceof t?(this.fields=e.getFields(),this.altdef=e.getAltdef(),this.init=e.getInitMode()):(this.fields=e?Object.entries(e.fields).map((function(t){var e=i(t,2),r=e[0],o=e[1];return[r,new d(o)]})).reduce((function(t,e){var r,o=i(e,2),n=o[0],s=o[1];return Object.assign(t,((r={})[n]=s,r))}),{}):{},this.altdef=e&&e.altdef||0,this.init=e&&e.init||0)}return t.prototype.getFields=function(){return this.fields},t.prototype.getField=function(t){return"string"==typeof t&&this.fields?this.fields[t.toUpperCase()]:void 0},t.prototype.getFieldList=function(t){var e=this;if(this.fields){var r=Object.entries(this.fields);if(t.type){var o="ar_"+t.type;r=t.write?r.filter((function(r){var n=i(r,2),s=n[0];n[1];return e.canReadWrite(s,o,t.meta?t.meta[s]:void 0)})):r.filter((function(r){var n=i(r,2),s=n[0];n[1];return e.canRead(s,o,t.meta?t.meta[s]:void 0)}))}return r.map((function(e){var r=i(e,2),o=r[0],n=r[1].bez;return t.meta&&t.meta[o]&&t.meta[o].bez&&(n=t.meta[o].bez),{fld:o,bez:n}}))}return[]},t.prototype.getAltdef=function(){return null!=this.altdef?this.altdef:0},t.prototype.getInitMode=function(){return null!=this.init?this.init:0},t.prototype.listCanRead=function(t,e){return this.canRead(t,"ar_lst",e)},t.prototype.canRead=function(t,e,r){var i=this.getField(t);return i&&i.canRead(e,r)},t.prototype.canReadWrite=function(t,e,r){var i=this.getField(t);return i&&i.canReadWrite(e,r)},t}(),l={ENTITY:h,OCCURRENCE:p,ENTITYDEF:f};(c=t.AccessTypes||(t.AccessTypes={})).LST="lst",c.OCC="occ",c.COL="col",(u=t.ReadModeFlags||(t.ReadModeFlags={})).DEF="DEF",u.RET="RET",u.ALL="ALL",t.Entity=h,t.EntityDef=f,t.Field=d,t.IButton=a,t.ModelsMap=l,t.Occurrence=p,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=gy-foo.umd.min.js.map