@rentman/rm-core 2.1.0 → 2.1.2

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.
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("moment")):"function"==typeof define&&define.amd?define(["moment"],e):"object"==typeof exports?exports.RmCore=e(require("moment")):t.RmCore=e(t.moment)}(window,function(t){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([function(e,r){e.exports=t},function(t,e,r){"use strict";r.r(e);var n=r(0);function i(t,e){for(var r in e)r in t&&void 0!==e[r]&&(t[r]=e[r])}function o(t,e){if(void 0===t)return e;var r={};for(var n in e)r[n]=void 0===t[n]?e[n]:t[n];return r}function s(t){for(var e in t)return!0;return!1}function a(t){if("object"!=typeof t)return null;for(var e in t)return e;return null}function c(t,e){for(var r=0,n=e;r<n.length;r++){if(t==n[r])return!0}return!1}function u(t,e){for(var r=[],n=0,i=t;n<i.length;n++){var o=i[n];e(o)&&r.push(o)}if(r.length===t.length)return!1;l(t);for(var s=0,a=r;s<a.length;s++){var c=a[s];t.push(c)}return!0}function l(t){t.splice(0)}function h(t,e){if(void 0===t)return!1;for(var r=0,n=e;r<n.length;r++){var i=n[r];if(void 0===t[i])return!1;t=t[i]}return!0}function p(t,e,r){for(var n=0;n<e.length;n++){var i=e[n];void 0===t[i]&&(t[i]=r[n]),t=t[i]}return t}function d(t,e,r){if(void 0===r&&(r=!1),void 0!==t){for(var n=0,i=e;n<i.length;n++){if(void 0===(t=t[i[n]])&&!r)return}return t}}function f(t,e,r){for(var n=0,i=e.length;n<i;++n){var o=e[n];if(v(o)||S(o))for(var s=Object.keys(o),a=0,c=s.length;a<c;a++){var u=s[a],l=o[u];r&&v(l)?E(l)?t[u]=new Date(l.valueOf()):q(l)?t[u]=new RegExp(l):l.nodeName?t[u]=l.cloneNode(!0):w(l)?t[u]=l.clone():(v(t[u])||(t[u]=F(l)?[]:{}),f(t[u],[l],!0)):t[u]=l}}return t}function m(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];return f(t,e,!1)}function y(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];return f(t,e,!0)}function v(t){return null!==t&&"object"==typeof t}function g(t){return null!==t&&"object"==typeof t&&!Object.getPrototypeOf(t)}function C(t){return"string"==typeof t}function I(t){return"number"==typeof t}function E(t){return"[object Date]"===toString.call(t)}var F=Array.isArray;function S(t){return"function"==typeof t}function R(t){return t&&S(t.then)}function q(t){return"[object RegExp]"===toString.call(t)}function T(t){return"boolean"==typeof t}function w(t){return!(!t||!(t.nodeName||t.prop&&t.attr&&t.find))}function b(t){return t&&t.window===t}function H(t){return void 0!==t}function M(t,e){if(t===e)return!0;if(null===t||null===e)return!1;if(t!=t&&e!=e)return!0;var r,n,i,o,s,a=typeof t;if(a===typeof e&&"object"===a){if(!F(t)){if(E(t))return!!E(e)&&(o=t.getTime(),s=e.getTime(),o===s||o!=o&&s!=s);if(q(t))return!!q(e)&&t.toString()===e.toString();if(b(t)||b(e)||F(e)||E(e)||q(e))return!1;for(n in i=Object.create(null),t)if(!S(t[n])){if(!M(t[n],e[n]))return!1;i[n]=!0}for(n in e)if(!(n in i)&&H(e[n])&&!S(e[n]))return!1;return!0}if(!F(e))return!1;if(r=t.length,t.length===e.length){for(n=0;n<r;n++)if(!M(t[n],e[n]))return!1;return!0}}return!1}function x(t,e,r){var n=[],i=[];if(r=function(t){return I(t)&&t>0}(r)?r:NaN,e){if(t===e)throw new Error("Can't copy! Source and destination are identical.");if(F(e))e.length=0;else for(var o in e)delete e[o];return n.push(t),i.push(e),s(t,e,r)}return a(t,r);function s(t,e,r){if(--r<0)return"...";if(F(t))for(var n=0,i=t.length;n<i;n++)e.push(a(t[n],r));else if(g(t))for(var o in t)e[o]=a(t[o],r);else if(t&&"function"==typeof t.hasOwnProperty)for(var o in t)t.hasOwnProperty(o)&&(e[o]=a(t[o],r));else for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=a(t[o],r));return e}function a(t,e){if(void 0===e&&(e=5),!v(t))return t;var r=n.indexOf(t);if(-1!==r)return i[r];if(b(t))throw new Error("Can't copy! Making copies of Window instances is not supported.");var o=!1,c=function(t){switch(toString.call(t)){case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Float32Array]":case"[object Float64Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return new t.constructor(a(t.buffer),t.byteOffset,t.length);case"[object ArrayBuffer]":if(!t.slice){var e=new ArrayBuffer(t.byteLength);return new Uint8Array(e).set(new Uint8Array(t)),e}return t.slice(0);case"[object Boolean]":case"[object Number]":case"[object String]":case"[object Date]":return new t.constructor(t.valueOf());case"[object RegExp]":var r=new RegExp(t._source,t.toString().match(/[^/]*$/)[0]);return r.lastIndex=t.lastIndex,r;case"[object Blob]":return new t.constructor([t],{type:t.type})}if(S(t.cloneNode))return t.cloneNode(!0)}(t);return void 0===c&&(c=F(t)?[]:Object.create(Object.getPrototypeOf(t)),o=!0),n.push(t),i.push(c),o?s(t,c,e):c}}var k,D,O=function(){function t(){this.MOMENT_INVALID="Invalid date",this.SERVER_DATETIME_FORMAT="YYYY-MM-DD[T]HH:mm:ssZ",this.SERVER_TIME_FORMAT="HH:mm:ss",this.SERVER_DATE_FORMAT="YYYY-MM-DD"}return t.prototype.isExpensiveFormat=function(t){switch(t){case"date":case"datetime":case"duration":return!0;default:return!1}},t.prototype.mergeCopyFields=function(t,e,r,n){for(var i=0,o=n;i<o.length;i++){var s=o[i],a=s.path;void 0===r[a]||"id"!==a&&void 0!==e[a]&&!this.compareFields(s.apiColumn.type,e[a],t[a])||(e[a]=this.clone(s.apiColumn.type,r[a]))}return e},t.prototype.formatRequest=function(t,e,r){for(var n={},i=0,o=r;i<o.length;i++){var s=o[i],a=s.id,c=s.apiColumn,u=c.type;c.readOnly||(this.compareFields(u,t[a],e[a])||(n[a]=this.formatRequestValue(u,e[a])))}return n},t.prototype.formatRequestLocal=function(t,e){for(var r={},n=0,i=e;n<i.length;n++){var o=i[n],s=o.id,a=o.apiColumn;a.readOnly||(r[s]=this.formatRequestValue(a.type,t[s]))}return r},t.prototype.hasChanges=function(t,e,r,n){void 0===n&&(n=!1);for(var i=0,o=r;i<o.length;i++){var s=o[i],a=s.id,c=s.apiColumn;if("link"===c.type||"parenttype"===c.type||"parentid"===c.type||n||!c.readOnly){if(this.isExpensiveFormat(s.apiColumn.type)){var u=Object.getOwnPropertyDescriptor(e,a);if(void 0!==u&&void 0===u.value&&void 0!==u.get)continue}if(!this.compareFields(c.type,t[a],e[a]))return!0}}return!1},t.prototype.getChanges=function(t,e,r){for(var n=[],i=0,o=r;i<o.length;i++){var s=o[i],a=s.id,c=s.apiColumn;c.readOnly||(this.compareFields(c.type,t[a],e[a])||n.push({oldValue:t[a],newValue:e[a],column:s.apiColumn}))}return n},t.prototype.copyFields=function(t,e,r){for(var n=0,i=r;n<i.length;n++){var o=i[n],s=o.path;t.hasOwnProperty(s)&&(this.isExpensiveFormat(o.apiColumn.type)||void 0!==t[s])&&(e[s]=this.clone(o.apiColumn.type,t[s]))}return e},t.prototype.shallowCopyFields=function(t,e,r,n){for(var i=0,o=n;i<o.length;i++){var s=o[i],a=s.path;r[a]=void 0!==t[a]?t[a]:this.clone(s.apiColumn.type,e[a])}return r},t.prototype.setDefaultValues=function(t,e){for(var r=0,n=e;r<n.length;r++){var i=n[r];t[i.id]=this.getDefaultValue(i.apiColumn.type)}return t},t.prototype.compareFields=function(t,e,r){if(void 0===e)return void 0===r;if(void 0===r)return!1;switch(t){case"date":case"time":case"datetime":return this.compareMomentObjects(e,r);case"duration":return this.compareDurations(e,r);case"id":case"item":case"link":case"child":case"sibling":return e==r;case"current":case"dimension":case"distance":case"double":case"filesize":case"number":case"power":case"quantity":case"volume":case"weight":case"coordinate":case"price":case"percentage":return this.compareFloats(e,r);case"int":case"bool":case"enum":case"email":case"phone":case"url":case"text":case"longtext":case"color":case"order":return e===r;default:return M(e,r)}},t.prototype.compareFloats=function(t,e){var r=Math.abs(t),n=Math.abs(e),i=Math.abs(t-e);return t===e||(0===t||0===e||i<Number.MIN_VALUE?i<1.19e-7*Number.MIN_VALUE:i/Math.min(r+n,Number.MAX_VALUE)<1.19e-7)},t.prototype.compareMomentObjects=function(t,e){return t.isValid()?!!e.isValid()&&t.isSame(e):!e.isValid()},t.prototype.compareDurations=function(t,e){return t.asMilliseconds()===e.asMilliseconds()},t.prototype.formatResponseValue=function(t,e){switch(t){case"datetime":case"date":return this.formatResponseDate(e);case"color":return this.formatResponseColor(e);case"duration":return this.formatResponseDuration(e);case"json":return"string"==typeof e&&""!==e?JSON.parse(e):e;case"number":return 0===e?null:e;case"filesize":return e/1e6;default:return e}},t.prototype.formatRequestValue=function(t,e){switch(t){case"datetime":return this.formatRequestDateTime(e);case"date":return this.formatRequestDate(e);case"color":return this.formatRequestColor(e);case"duration":return this.formatRequestDuration(e);case"number":return 0===e?null:e;default:return e}},t.prototype.formatResponseDate=function(t){return null===t?n.invalid():n(t)},t.prototype.formatResponseDuration=function(t){return n.duration(null===t?0:t,"seconds")},t.prototype.formatResponseColor=function(t){return"#"===t.charAt(0)?t:"#"+t},t.prototype.formatRequestDateTime=function(t){return t.isValid()?t.format(this.SERVER_DATETIME_FORMAT):null},t.prototype.formatRequestDate=function(t){return t.isValid()?t.format(this.SERVER_DATE_FORMAT):null},t.prototype.formatRequestDuration=function(t){return t.asSeconds()},t.prototype.formatRequestColor=function(t){return"#"===t.charAt(0)?t.substring(1):t},t.prototype.getDefaultValue=function(t){switch(t){case"int":case"double":case"percentage":case"price":case"order":return 0;case"item":case"link":case"child":case"sibling":return null;case"bool":return!1;case"enum":return"0";case"date":case"datetime":case"time":return n.invalid();case"duration":return n.duration();case"text":case"longtext":return"";case"color":return"#000000";default:return""}},t.prototype.isDefaultValue=function(t,e){return this.compareFields(t,e,this.getDefaultValue(t))},t.prototype.clone=function(t,e){switch(t){case"duration":return this.cloneDuration(e);case"date":case"datetime":return n(e);case"json":return x(e);default:return e}},t.prototype.getCloneFunction=function(t){switch(t){case"duration":return this.cloneDuration;case"date":case"datetime":return this.cloneDate;default:return this.identity}},t.prototype.cloneDuration=function(t){return n.duration(t)},t.prototype.cloneDate=function(t){return t.clone()},t.prototype.identity=function(t){return t},t}(),_=function(){function t(t,e){this.externalApiRequestService=t,this.apiResponseProcessorFactory=e}return t.prototype.template=function(t,e){return this.processResponse(this.externalApiRequestService.template(t,e))},t.prototype.create=function(t,e,r,n,i){return this.processResponse(this.externalApiRequestService.create(t,e,r,n,i))},t.prototype.delete=function(t,e){return this.processResponse(this.externalApiRequestService.delete(t,e))},t.prototype.updateItems=function(t,e,r){return this.processResponse(this.externalApiRequestService.updateItems(t,e,r))},t.prototype.requestSkeleton=function(t,e){return this.processResponse(this.externalApiRequestService.requestSkeleton(t,e))},t.prototype.moveItems=function(t,e,r){return this.processResponse(this.externalApiRequestService.moveItems(t,e,r))},t.prototype.columns=function(t,e,r){return this.processResponse(this.externalApiRequestService.columns(t,e,r))},t.prototype.query=function(t,e,r,n){return this.processResponse(this.externalApiRequestService.query(t,e,r,n))},t.prototype.processResponse=function(t){var e=this;return t.then(function(t){return e.apiResponseProcessorFactory.construct(t)})},t}(),P=function(){function t(t,e){this.apiFormatter=t,this.response=e,this.columnIndexMap={},this.columnMap={},this.columns=e.columns,this.items=e.items,this.links=e.links,this.cacheable=e.cacheable,this.map=e.map,this.itemType=e.itemType,this.createColumnMaps()}return t.prototype.createColumnMaps=function(){for(var t in this.columns){this.columnIndexMap[t]={},this.columnMap[t]={};for(var e=0;e<this.columns[t].length;e++){var r=this.columns[t][e];this.columnIndexMap[t][r.id]=e,this.columnMap[t][r.id]=r}}},t.prototype.fetchColumnObject=function(t){return this.columnMap[t]},t.prototype.fetchValue=function(t,e,r){if(void 0!==this.items[t][e]){var n=this.columnMap[t][r],i=this.columnIndexMap[t][r];return this.apiFormatter.formatResponseValue(n.type,this.items[t][e].data[i])}},t.prototype.fetchColumnArray=function(t){for(var e=[],r=0,n=this.columns[t];r<n.length;r++){var i=n[r];e.push(i)}return e},t.prototype.fetchDerivedObject=function(t,e,r){for(var n={},i=0,o=r;i<o.length;i++){var s=o[i];this.fetchDerivedValues(this.fetchValue(t,e,s.id),s,n)}return n},t.prototype.fetchDerivedValues=function(t,e,r){for(var n=0,i=e.children;n<i.length;n++){var o=i[n],s=void 0;null===t?(s=null,r[o.path]=this.apiFormatter.getDefaultValue(o.apiColumn.type)):(s=this.fetchValue(e.itemType,t,o.id),r[o.path]=s),o.isLeaf||this.fetchDerivedValues(s,o,r)}},t.prototype.fetchObject=function(t,e,r){var n=this;if((void 0===r&&(r=!1),void 0!==this.items[t])&&void 0!==this.items[t][e]){for(var i=this.items[t][e].data,o={},s=function(e){var r=a.columns[t][e];a.apiFormatter.isExpensiveFormat(r.type)?Object.defineProperty(o,r.id,{enumerable:!0,configurable:!0,set:function(t){delete o[r.id],o[r.id]=t},get:function(){return delete o[r.id],o[r.id]=n.apiFormatter.formatResponseValue(r.type,i[e])}}):o[r.id]=a.apiFormatter.formatResponseValue(r.type,i[e])},a=this,c=0;c<i.length;c++)s(c);if(r){var u=this.items[t][e].links;for(var l in o.__links={},u)o.__links[l]=this.fetchObjectArray(l,r,u[l])}return o}},t.prototype.fetchObjectArray=function(t,e,r){var n=[];if(null===r){for(var i in this.items[t])n.push(this.fetchObject(t,i,e));return n}void 0===r&&(r=this.links[t]);for(var o=0,s=r;o<s.length;o++){i=s[o];n.push(this.fetchObject(t,i,e))}return n},t.prototype.fetchColumnsObject=function(){return this.columnMap},t}(),L=function(){function t(t){this.transaction=t,this.compilation={create:{},delete:{},update:{},move:{}},this.processDelta()}return t.prototype.processDelta=function(){var t=this.transaction.getDelta();for(var e in t.deleted)for(var r=0,n=t.deleted[e];r<n.length;r++){var i=n[r];i.isLocal()||this.addDeleteEntry(i)}for(var o in t.created){var s=t.created[o];this.addCreateEntry(s)}for(var o in t.updated){s=t.updated[o];this.addUpdateEntry(s.entry)}for(var o in t.moved){s=t.moved[o];this.addMoveEntry(s.entry,s.to)}},t.prototype.getDefaultParent=function(){return{itemType:"Void",itemId:0}},t.prototype.addMoveEntry=function(t,e){p(this.compilation.move,[e.itemType,e.itemId],[{},[]]).push(t)},t.prototype.addDeleteEntry=function(t){p(this.compilation.delete,[t.itemType],[[]]).push(t)},t.prototype.addUpdateEntry=function(t){p(this.compilation.update,[t.itemType,t.itemId],[{},t])},t.prototype.addCreateEntry=function(t){var e=this.transaction.getParent(t.entry);null===e&&(e=this.getDefaultParent()),p(this.compilation.create,[e.itemType,e.itemId,t.entry.itemType,t.entry.itemId],[{},{},{},t])},t}(),j=function(){function t(t,e,r,n,i,o,s,a,c,u,l,h,p){this.changesDeltaFactory=t,this.apiRequestService=e,this.changesCompilationFactory=r,this.columnExpansionFactory=n,this.createRequestFactory=i,this.errorHandler=o,this.promiseService=s,this.requestColumnExpansionFactory=a,this.collectionEntryService=c,this.itemEntryService=u,this.transaction=l,this.breakUpByParent=h,this.onAfterCreateCallback=p,this.itemIdConversionMap={},this.serverCache=this.transaction.getServerCache()}return t.prototype.execute=function(){var t=this,e=this.changesCompilationFactory.construct(this.transaction),r=e.compilation;return this.executeCreateRequests(e).then(function(){return t.executeMoveRequests(r.move)},this.errorHandler.reject).then(function(){return t.executeUpdateRequests(r.update)},this.errorHandler.reject).then(function(){return t.executeDeleteRequests(r.delete)},this.errorHandler.reject).then(function(){return t.itemIdConversionMap},this.errorHandler.reject)},t.prototype.buildMoveRequest=function(t){for(var e={},r=0,n=t;r<n.length;r++){var i=n[r],o=i.itemType;void 0===e[o]&&(e[o]=[]),e[o].push(i.itemId)}return e},t.prototype.getMapValue=function(t,e,r){if(void 0===r&&(r=this.itemIdConversionMap),void 0!==r&&void 0!==r[t])return r[t][e]},t.prototype.executeCreateRequests=function(t){for(var e=this,r=[],n=0,i=this.createRequestFactory.construct(t.compilation.create,this.transaction,this.breakUpByParent).run();n<i.length;n++){var o=i[n];r.push(this.executeCreateRequest(o).then(function(t){return void 0!==e.onAfterCreateCallback&&e.onAfterCreateCallback(e.itemIdConversionMap),t},this.errorHandler.reject))}return this.promiseService.all(r)},t.prototype.executeCreateRequest=function(t){var e=this;return this.apiRequestService.requestSkeleton(t.request).then(function(r){var n=e.changesDeltaFactory.construct(),i=r.map,o=r.fetchColumnsObject(),a=t.items;for(var c in a){var u=e.columnExpansionFactory.construct(c,t.request.columns[c],o);for(var l in a[c]){var h=a[c][l],p=e.getMapValue(c,parseInt(l,10),i);if(void 0!==p){var d=e.transaction.itemHandler.entries.get(c,l);d.itemId=p,e.serverCache.itemHandler.itemChanges[d.id]=e.serverCache.itemHandler.copyTransactionItemEntryChanges(e.transaction.itemHandler.itemChanges[d.id],d),e.serverCache.itemHandler.entries.add(d),e.transaction.itemHandler.entries.clearByItemId(c,Number(l)),e.serverCache.itemHandler.processApiResponse(n,r,h.itemType,Number(p),h.columns,u)}else console.warn("Create failed!",h)}}for(var c in i)for(var l in void 0===e.itemIdConversionMap[c]&&(e.itemIdConversionMap[c]={}),i[c])e.itemIdConversionMap[c][l]=i[c][l];for(var f=0,m=e.transaction.collectionHandler.entries.toArray();f<m.length;f++){var y=m[f],v=y.parent;if(null!==v){var g=e.getMapValue(v.itemType,v.itemId);if(void 0!==g){v.itemId=g;var C=e.transaction.collectionHandler.getCollectionChanges(y.itemType,y.query.string);void 0!==e.transaction.collectionHandler.collectionChanges[y.itemType]&&delete e.transaction.collectionHandler.collectionChanges[y.itemType][y.query.string],y.query=e.collectionEntryService.createQuery(y.options),void 0!==C&&e.transaction.collectionHandler.setCollectionChanges(y.itemType,y.query.string,C)}}var I=y.getUpdatedItemColumns(e.itemIdConversionMap);s(I)&&(void 0!==I.id&&e.transaction.collectionHandler.onItemEntriesCreated(y,e.itemIdConversionMap[y.itemType]))}return e.serverCache.applyChangesDelta(n)},this.errorHandler.reject)},t.prototype.executeUpdateRequests=function(t){var e=[];for(var r in t)e.push(this.executeUpdateRequest(r,t[r]));return this.promiseService.all(e)},t.prototype.executeUpdateRequest=function(t,e){var r=this,n={},i=this.requestColumnExpansionFactory.construct(),o=this.transaction.collectionHandler.getCollectionMatcher();for(var s in n[t]={},e){var a=e[s],c=n[t][s]={},u=d(this.transaction.tabRequestParameters,[t,s]);c.values=this.transaction.itemHandler.formatRequest(a),void 0!==u&&(c.parameters=u),i.expand(a.columns),o.expand(a,this.transaction.itemHandler.itemChanges[a.id].changes)}for(var l=0,h=o.getCollectionsWithFittingItems();l<h.length;l++){var p=h[l];i.expand(p.columns)}var f=i.get();return this.apiRequestService.updateItems(t,n,f).then(function(t){return r.serverCache.processResponse(t,f,!0,!1)},this.errorHandler.reject)},t.prototype.executeDeleteRequests=function(t){var e=[];for(var r in t)e.push(this.executeDeleteRequest(r,t[r]));return this.promiseService.all(e)},t.prototype.executeDeleteRequest=function(t,e){var r=this;return this.apiRequestService.delete(t,e.map(function(t){return t.itemId})).then(function(t){for(var n=r.changesDeltaFactory.constructInternalDelta(),i=t.items,o=[],s=0,a=e;s<a.length;s++){var u=a[s];c(u.itemId,i)?o.push(u):console.warn("Delete failed!",u)}return n.setItemsDeleted(o),r.serverCache.applyChangesFromParent(n,!0)},this.errorHandler.reject)},t.prototype.executeMoveRequests=function(t){var e=this,r=[],n=function(n,i){var o=t[n][i],s=e.getMapValue(n,i);r.push(e.apiRequestService.moveItems(n,void 0!==s?s:i,e.buildMoveRequest(o)).then(function(){for(var t=e.changesDeltaFactory.constructInternalDelta(),r=0,a=o;r<a.length;r++){var c=a[r];t.setItemUpdated(c,e.itemEntryService.getLinkFieldsByParent({itemType:n,itemId:void 0!==s?s:i},c.itemType))}return e.serverCache.applyChangesFromParent(t,!0)},e.errorHandler.reject))};for(var i in t)for(var o in t[i])n(i,+o);return this.promiseService.all(r)},t}(),B=function(){return function(t){this.columns=!0,this.parent=null,this.templateOptions={},i(this,t)}}(),A=function(){return function(t){this.edit=!1,this.remote=!1,this.onChange=Je,i(this,t)}}(),Q=0,V=function(){function t(t,e,r,n){this.factory=t,this.itemType=e,this.itemId=r,this.columns=n,this.id=++Q,this.reloadQueued=!1}return t.prototype.queueReload=function(){return this.reloadQueued=!0,this},t.prototype.isLocal=function(){return this.factory.keyService.isLocalId(this.itemId)},t.prototype.isLockable=function(){if(this.isLocal())return!1;switch(this.itemType){case"Project":case"Materiaal":case"Contact":case"Medewerker":case"Voertuig":case"Template":return!0;default:return!1}},t.prototype.toJSON=function(){return{id:this.id,columns:this.columns}},t}(),U=function(){function t(t,e,r,n,i){this.factory=t,this.entry=e,this.options=r,this._isNew=n,this.transaction=i,this.columns=e.columns.response[e.columns.itemType],this.initial=this.transaction.itemHandler.itemChanges[e.id].initial,this.onConstruct()}return t.prototype.onConstruct=function(){},t.prototype.getParent=function(t){return this.transaction.getParent(this.entry,t,this.fields)},t.prototype.callOnChange=function(t){var e=this,r=this.transaction.itemHandler.itemResources[this.entry.id];if(void 0!==r)for(var n=0,i=r;n<i.length;n++){var o=i[n];try{o.options.onChange(o,t,function(r){return e.compareItemField(r,t)},!1)}catch(t){this.factory.exceptionHandler(t)}}},t.prototype.compareItemField=function(t,e){var r=this.columns[t];if(void 0===r)throw new Error("Missing column in ItemResource.compareItemField");return this.factory.apiFormatter.compareFields(r.type,this.fields[t],e[t])},t.prototype.hasChanges=function(){return this.transaction.itemHandler.detectEntryChanges(this.entry.id)},t.prototype.setTransactionParameters=function(t){p(this.transaction.tabRequestParameters,[this.entry.itemType,this.entry.itemId],[{},t])},t.prototype.isNew=function(){return this._isNew},t.prototype.isLocal=function(){return this.entry.isLocal()},t.prototype.clearResource=function(){this.transaction.clearItemResource(this)},t.prototype.toJSON=function(){var t=[];for(var e in this.columns)t.push(e);return{columns:t,fields:this.fields,entry:this.entry}},t.prototype.getDerivedValue=function(t){return this.transaction.itemHandler.getDerivedValue(this.entry,t)},t.prototype.getDerivedValues=function(t){return this.transaction.itemHandler.getDerivedValues(this.entry,t)},t}(),N=(k=function(t,e){return(k=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)},function(t,e){function r(){this.constructor=t}k(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),W=function(t){function e(e,r,n,i,o){var s=t.call(this,e,r,n,i,o)||this;return s.fields=o.itemHandler.itemChanges[r.id].changes,s}return N(e,t),e}(U),Y=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),J=function(t){function e(e,r,n,i,o){var s=t.call(this,e,r,n,i,o)||this;return s.localCopies=[],s.fields=o.itemHandler.itemChanges[r.id].changes,s}return Y(e,t),e.prototype.isNew=function(){return this._isNew},e.prototype.copyFields=function(t){void 0===t&&(t={});var e=this.entry;return this.factory.apiFormatter.copyFields(this.fields,t,e.columns.main),t},e.prototype.setFields=function(t){var e=this,r=this.columns;for(var n in t){void 0===r[n]&&console.warn("setFields: no column found for",n)}var i=this.transaction.createChangesDelta();return i.setItemUpdated(this.entry,t),this.transaction.applyChangesDelta(i).then(function(){return e},this.factory.errorHandler.reject)},e}(U),K=function(){return function(t){this.columns=[],this.query=null,this.queryParams={},this.queryColumns=[],this.parent=null,this.deferRequest=!1,this.limit=null,this.entryKey=null,i(this,t)}}(),z=function(){return function(t){this.editItems=!1,this.remoteItems=!1,this.editCollection=!1,this.enableSave=!0,this.callOnAddWithInitialItems=!1,this.onItemsCreated=Je,this.onChange=Je,this.onAdd=Je,this.onRemove=Je,this.onAddInitial=Je,this.onRemoveInitial=Je,this.resourceKey=null,this.custom=null,i(this,t)}}(),G=0,X=function(){function t(t,e,r,n,i){this.collectionEntryService=t,this.columnSetFactory=e,this.keyService=r,this.itemType=n,this.options=i,this.id=G++,this.parent=null,this.reloadQueued=!1,this.parent=i.parent,this.query=this.collectionEntryService.createQuery(i),this.columns=this.columnSetFactory.constructStub(n,i.columns)}return t.prototype.isLocal=function(){var t=this.parent;return null!==t&&this.keyService.isLocalId(t.itemId)},t.prototype.matchParent=function(t,e){var r=this.parent;return null!==r&&(r.itemType===t&&r.itemId==e)},t.prototype.extendQuery=function(t){var e=this.options;return void 0===t?this.query:(e.queryParams=t(e.queryParams),this.query=this.collectionEntryService.createQuery(e))},t.prototype.queueReload=function(){this.reloadQueued=!0},t.prototype.expandColumns=function(t){var e=t.run(this.columns);null!==e&&(this.columns=e.merged,this.options.columns=this.columns.request)},t.prototype.expandRequestColumns=function(t){this.columns.expandRequestColumns(t),this.options.columns=this.columns.request},t.prototype.getUpdatedItemColumns=function(t){for(var e={},r=0,n=this.columns.item;r<n.length;r++){var i=n[r];void 0!==t[i.apiColumn.itemType]&&(e[i.id]=i)}return e},t}(),Z=function(){function t(t,e,r,n){var i=this;this.factory=t,this.entry=e,this.options=r,this.transaction=n,this.itemIdMap={},this.items=[],this.itemIdMap={},this.columns=e.columns.response,this.onChange=function(t,e,r,n){t.compareItemField("id",e)||(delete i.itemIdMap[e.id],i.itemIdMap[t.entry.itemId]=t),i.options.onChange(t,e,function(r){return t.compareItemField(r,e)},n)},this.addItemResources(this.transaction.getCollectionChangesRecursively(this.entry.id),!0),this.onConstruct()}return t.prototype.onConstruct=function(){},t.prototype.getIdArray=function(){return this.items.map(function(t){return t.entry.itemId})},t.prototype.getItemById=function(t){return this.itemIdMap[t]},t.prototype.addItemResources=function(t,e){if(void 0===e&&(e=!1),0===t.length)return[];var r=this.items.map(function(t){return t.entry});t=t.filter(function(t){return-1===r.indexOf(t)});for(var n=this.transaction.createItemResources(t,{remote:this.options.remoteItems,edit:this.options.editItems,onChange:this.onChange}),i=0,o=n;i<o.length;i++){var s=o[i],a=s.entry.itemId;if(void 0!==this.itemIdMap[a])throw new Error("Added a resource of an entry that was already in the collection !");this.items.push(s),this.itemIdMap[a]=s}return e&&!this.options.callOnAddWithInitialItems||this.callOnAdd(n,e),n},t.prototype.removeItemResources=function(t){var e=this,r=[];return u(this.items,function(n){for(var i=0,o=t;i<o.length;i++){var s=o[i];if(n.entry===s)return n.clearResource(),r.push(n),delete e.itemIdMap[s.itemId],!1}return!0}),r},t.prototype.callOnAdd=function(t,e){void 0===e&&(e=!1);try{this.options.onAdd(t,this,e)}catch(t){this.factory.exceptionHandler(t)}},t.prototype.callOnRemove=function(t){try{this.options.onRemove(t,this)}catch(t){this.factory.exceptionHandler(t)}},t.prototype.forEach=function(t){for(var e=0,r=this.items;e<r.length;e++){t(r[e])}},t.prototype.filter=function(t){for(var e=[],r=0,n=this.items;r<n.length;r++){var i=n[r];t(i)&&e.push(i)}return e},t.prototype.first=function(t){for(var e=0,r=this.items;e<r.length;e++){var n=r[e];if(t(n))return n}return null},t.prototype.some=function(t){return null!==this.first(t)},t.prototype.groupBy=function(t){var e=this.items,r={};if("string"==typeof t){if(void 0===this.entry.columns.response[this.entry.itemType][t])throw new Error("Trying to group on a column not requested by this collection! (column '"+t+"')");for(var n=0,i=e;n<i.length;n++){void 0===r[c=(a=i[n]).fields[t]]&&(r[c]=[]),r[c].push(a)}}if("function"==typeof t)for(var o=0,s=e;o<s.length;o++){var a,c;null!==(c=t(a=s[o]))&&(void 0===r[c]&&(r[c]=[]),r[c].push(a))}return r},t.prototype.map=function(t){var e=this.items,r=e.length,n=new Array(r);if("string"==typeof t)for(var i=0;i<r;i++)n[i]=e[i].fields[t];if("function"==typeof t)for(i=0;i<r;i++)n[i]=t(e[i]);return n},t.prototype.reduce=function(t,e){for(var r=0,n=this.items;r<n.length;r++){e=t(n[r],e)}return e},t.prototype.extend=function(t){return this.transaction.collectionHandler.extendCollectionEntry(this.entry,t)},t.prototype.clearResource=function(t){if(void 0===t&&(t=!0),t)for(var e=0,r=this.items;e<r.length;e++){r[e].clearResource()}this.transaction.clearCollectionResource(this)},t}(),$=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),tt=function(t){function e(e,r,n,i){return t.call(this,e,r,n,i)||this}return $(e,t),e}(Z),et=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),rt=function(t){function e(e,r,n,i){return t.call(this,e,r,n,i)||this}return et(e,t),e.prototype.moveItems=function(t,e){if(this.options.enableSave)throw new Error("collectionResourceService: Cannot move items: saving enabled");return this.transaction.collectionHandler.moveItems(this.entry,e.entry,t)},e.prototype.removeItems=function(t){for(var e=this.factory.changesDeltaFactory.construct(),r=[],n=0,i=this.items;n<i.length;n++){var o=i[n].entry;-1!==t.indexOf(o.itemId)&&r.push(o)}e.setItemsDeleted(r),this.transaction.applyChangesDelta(e)},e.prototype.removeItem=function(t){return this.removeItems([t])},e.prototype.addItems=function(t){return this.transaction.itemHandler.createItems(this.entry.itemType,t,this.entry.parent)},e.prototype.addItem=function(t){return this.addItems([t])},e}(Z),nt=function(){return function(t,e,r,n,i){this.itemType=e,this.response=r,this.fields=r.fetchObject(e,r.links[e][0]);var o=r.fetchColumnsObject();this.responseColumns=t.columnUtil.mergeResponseColumns(o,i).merged,this.columns=t.columnSetFactory.constructFromResponse(e,o),this.columns=this.columns.expand(n[e],!1,i).merged}}(),it=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),ot=function(t){function e(e,r,n,i,o){var s=t.call(this,e,r,n,i,o)||this;return s.fields=s.transaction.itemHandler.itemChanges[r.id].initial,s}return it(e,t),e}(W),st=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),at=function(t){function e(e,r,n,i,o){var s=t.call(this,e,r,n,i,o)||this;return s.fields=o.itemHandler.itemChanges[r.id].changes,s}return st(e,t),e}(W);!function(t){t.ITEMTABLE="itemtable",t.DIRECT="direct"}(D||(D={}));var ct,ut=function(){function t(t,e,r,n,i,o,s,a){this.columnUtil=t,this.apiFormatter=e,this.itemEntryFactory=r,this.promiseService=n,this.errorHandler=i,this.requestColumnExpansionFactory=o,this.transaction=a,this.entries=s.construct(this.transaction)}return t.prototype.getDerivedValues=function(t,e){for(var r=t,n=this.transaction.getChangesFromItemChanges(this.itemChanges[t.id]),i=0,o=e;i<o.length;i++){var s=o[i],a=r.columns.response[r.itemType][s];if(void 0===a)throw new Error("Column '"+s+"' not found on entry in ItemResource.getDerivedValue");if(null===a.itemType)throw new Error("Column '"+s+"' doesn't have children in ItemResource.getDerivedValue");var c=n[s];if(null===c)return;if(void 0===(r=this.transaction.getLocalItemEntryByItemId(a.itemType,c)))throw new Error("Derived itemEntry "+a.itemType+":"+c+" couldn't be found");n=this.transaction.getItemChangesRecursively(r.id,!1)}return n},t.prototype.getDerivedValue=function(t,e){"string"==typeof e&&(e=this.columnUtil.parseConfigColumn(e));var r=this.getDerivedValues(t,e.slice(0,-1));if(void 0!==r)return r[e[e.length-1]]},t.prototype.clearItemEntry=function(t){this.entries.clear(t),delete this.itemChanges[t.id]},t.prototype.fetchDerivedValuesByColumn=function(t,e,r){var n=this,i=e.children;if(0===i.length)return this.promiseService.when();var o=i[0];if(1===i.length&&"id"===o.apiColumn.type)throw new Error("You should use fields[columnId] instead of derived['columnId>id'] to get the id of a derived item");for(var a={},c=0,u=t;c<u.length;c++){var l=u[c];null!==(p=this.getItemIdByColumn(l,e,r))&&(void 0===a[p]&&(a[p]=[]),a[p].push(l))}if(!s(a))return this.promiseService.when();var h=[];for(var p in a)h.push(+p);for(var d=[],f=0,m=i;f<m.length;f++){var y=m[f];d.push(y.id)}return this.fetchItemEntries(e.itemType,h,new B({columns:d})).then(function(){return n.resolveDerivedValues(t,i,r)},this.errorHandler.reject)},t.prototype.resolveDerivedValues=function(t,e,r){for(var n=[],i=0,o=e;i<o.length;i++){var s=o[i];n.push(this.fetchDerivedValuesByColumn(t,s,r))}return this.promiseService.all(n).then(function(){return t},this.errorHandler.reject)},t.prototype.createItemEntry=function(t){var e=this.itemEntryFactory.construct(t.itemId,t.columns);return this.entries.add(e),e},t.prototype.getItemIdByColumn=function(t,e,r){if(0===e.level)return void 0!==r&&void 0!==r.updated[t.id]?r.updated[t.id].changes.fields[e.path]:this.transaction.getChangesFromItemChanges(this.itemChanges[t.id])[e.path];var n=this.getItemIdByColumn(t,e.parent,r),i=this.transaction.getLocalItemEntryByItemId(e.parent.itemType,n);return void 0!==r&&void 0!==r.updated[i.id]?r.updated[i.id].changes.fields[e.id]:this.transaction.getChangesFromItemChanges(this.itemChanges[i.id])[e.id]},t.prototype.expandColumnsWithCollectionColumns=function(t,e){var r=this.requestColumnExpansionFactory.construct();void 0!==e&&r.expandWithRequestColumns(t,e);for(var n=function(e){for(var n=0,i=e.collectionHandler.entries.getByItemType(t);n<i.length;n++){var o=i[n];r.expandWithRequestColumns(t,o.options.queryColumns),r.expandWithRequestColumns(t,o.options.columns)}},i=function(t){for(var e=0,r=t;e<r.length;e++){var o=r[e];n(o),i(o.children)}},o=0,s=this.transaction.getTransactionChain();o<s.length;o++){var a=s[o];n(a)}return i(this.transaction.children),r.get()[t]},t}(),lt=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),ht=function(t){function e(e,r,n,i,o,s,a,c,u,l,h,p,d,f,m,y,v,g){var C=t.call(this,p,d,f,h,c,y,m,v)||this;return C.changesDeltaFactory=e,C.exceptionHandler=r,C.templateCache=n,C.columnExpansionFactory=i,C.columnHandler=o,C.columnSetFactory=s,C.columnSubsetCacheFactory=a,C.itemEntryService=u,C.keyService=l,C.transaction=v,C.validator=g,C.deletedItems={},C.itemChanges={},C.itemResources={},C}return lt(e,t),e.prototype.copyTransactionItemEntryChanges=function(t,e){return{initial:this.apiFormatter.copyFields(t.initial,{},e.columns.main),changes:this.apiFormatter.copyFields(t.changes,{},e.columns.main)}},e.prototype.createItemEntry=function(e){var r=t.prototype.createItemEntry.call(this,e),n=this.itemEntryService.getLocalDefaultValues();for(var i in n)e.fields[i]=n[i];var o=this.apiFormatter.copyFields(e.fields,{},e.columns.main);return this.itemChanges[r.id]={initial:e.fields,changes:o},this.itemChanges[r.id].initial.id=r.itemId,this.itemChanges[r.id].changes.id=r.itemId,void 0!==this.validator&&this.validator.validateItem(r,e.fields,e.fields),r},e.prototype.formatRequest=function(t){var e=t.columns.main;return t.isLocal()?this.apiFormatter.formatRequestLocal(this.itemChanges[t.id].changes,e):this.apiFormatter.formatRequest(this.itemChanges[t.id].initial,this.itemChanges[t.id].changes,e)},e.prototype.createItems=function(t,e,r){for(var n,i=this,o=[],s=this.changesDeltaFactory.construct(),a=((n={})[t]=this.expandColumnsWithCollectionColumns(t),n),c=function(e){var n=u.keyService.getLocalId();o.push(u.templateCache.fetchTemplate(t,n,{},a,r).then(function(o){i.resolveLocal(s,t,n,r,o,function(){return!0},function(r,n){if(r===t)for(var i in e)n[i]=e[i]})},u.errorHandler.reject))},u=this,l=0,h=e;l<h.length;l++){c(h[l])}return this.promiseService.all(o).then(function(){return i.transaction.applyChangesDelta(s)})},e.prototype.clearItemEntry=function(e){t.prototype.clearItemEntry.call(this,e),delete this.itemResources[e.id]},e.prototype.addResource=function(t){var e=this.itemResources[t.entry.id];void 0===e&&(e=this.itemResources[t.entry.id]=[]),e.push(t)},e.prototype.clearResource=function(t){var e=this.itemResources[t.entry.id];if(void 0!==e){var r=e.indexOf(t);-1!==r&&e.splice(r,1),0===e.length&&delete this.itemResources[t.entry.id]}},e.prototype.detectChanges=function(){for(var t in this.entries.entriesByEntryId)return!0;for(var e in this.itemChanges){if(this.detectEntryChanges(Number(e)))return!0}return!1},e.prototype.detectEntryChanges=function(t){var e=this.transaction.getLocalItemEntry(t),r=this.itemChanges[t];return this.apiFormatter.hasChanges(r.initial,r.changes,e.columns.main)},e.prototype.processItemEntryChanges=function(t,e,r,n,i){void 0===e&&(e=!1),void 0===r&&(r=!1),void 0===n&&(n=!1),void 0===i&&(i=!1);var o=t.entry,s=t.changes;if(void 0===this.itemChanges[o.id]){if(!i)return null;this.itemChanges[o.id]={initial:this.transaction.getItemChangesRecursively(o.id),changes:this.transaction.getItemChangesRecursively(o.id)}}null!==s.expandedColumns&&(o.columns=s.expandedColumns.merged);var a=this.itemChanges[o.id],c=this.apiFormatter.copyFields(a.changes,{},o.columns.main),u=this.apiFormatter.hasChanges(s.fields,a.changes,o.columns.main,!0);if(e?this.apiFormatter.copyFields(s.fields,a.changes,o.columns.main):this.apiFormatter.mergeCopyFields(a.initial,a.changes,s.fields,o.columns.main),r&&this.apiFormatter.copyFields(s.fields,a.initial,o.columns.main),void 0===s.fields.displayname){var l=this.itemEntryService.getDisplayName(o,a.changes);void 0!==l&&(a.changes.displayname=l)}if(u){void 0!==this.validator&&this.validator.validateItem(o,a.changes,c);var h=this.itemResources[o.id];if(void 0!==h)for(var p=function(t){try{t.options.onChange(t,c,function(e){return t.compareItemField(e,c)},n)}catch(t){d.exceptionHandler(t)}},d=this,f=0,m=h;f<m.length;f++){p(m[f])}}return c},e.prototype.cloneItemEntries=function(t,e,r){void 0===e&&(e={});var n=this.changesDeltaFactory.construct();this.itemEntryService.batchExpandConversionMap(t,e);for(var i=0,o=t;i<o.length;i++){var s=o[i];this.cloneItemEntry(n,s,{},e,r)}return this.transaction.applyChangesDelta(n)},e.prototype.cloneItemEntry=function(t,e,r,n,i){void 0===r&&(r={}),void 0===n&&(n={});var o=this.transaction.getItemChangesRecursively(e.id),s=this.itemEntryService.expandConversionMap(e,n),a=this.transaction.getParent(e),c=null;if(null!==a){var u=this.itemEntryService.getConversionValue(a.itemType,a.itemId,n);c={itemType:a.itemType,itemId:u||a.itemId}}var l=this.apiFormatter.copyFields(o,{},e.columns.main),h=this.updateItemValues(l,c,e.columns.item,n);for(var p in h)l[p]=h[p];for(var p in r)l[p]=r[p];return void 0!==i&&i(e,l),t.setItemCreated(s,l,e.columns),s},e.prototype.fetchItemEntriesByQuery=function(t,e,r){return this.transaction.getServerCache().itemHandler.fetchItemEntriesByQuery(t,e,r)},e.prototype.fetchItemEntry=function(t,e,r){var n=this;if(!this.keyService.isLocalId(e))return this.transaction.getServerCache().itemHandler.fetchItemEntry(t,e,r);if(void 0===this.entries.get(t,e))return this.transaction.parent instanceof Gt?this.errorHandler.reject(this.itemEntryService.createUnfoundLocalItemError(t)):this.transaction.parent.itemHandler.fetchItemEntry(t,e,r);r.columns=this.expandColumnsWithCollectionColumns(t,r.columns);var i=this.changesDeltaFactory.construct(),o=this.columnSubsetCacheFactory.construct(r.columns);return this.fetchLocalItemEntryData(i,t,e,o,r).then(function(t){return n.transaction.applyChangesDelta(i).then(function(){return t},n.errorHandler.reject)},this.errorHandler.reject)},e.prototype.fetchNewItemEntry=function(t,e,r){var n,i,o=this;return void 0!==this.entries.get(t,e)?this.errorHandler.reject(this.itemEntryService.createExistingLocalItemError(t)):this.templateCache.fetchTemplate(t,e,r.templateOptions,(n={},n[t]=r.columns,n),r.parent).then(function(n){if(void 0!==o.entries.get(t,e))return o.errorHandler.reject(o.itemEntryService.createExistingLocalItemError(t));var i=o.changesDeltaFactory.construct();return o.resolveLocal(i,t,e,r.parent,n),o.transaction.applyChangesDelta(i)},this.errorHandler.reject).then(function(t){var e=(i=t).created.reduce(function(t,e){return t.hasOwnProperty(e.itemType)||(t[e.itemType]=[]),t[e.itemType].push(e),t},{}),r=o.transaction.createChangesDelta(),n=[];for(var s in e)n.push(o.resolveDerivedValues(e[s],e[s][0].columns.root,r));return o.promiseService.all(n)}).then(function(){return i})},e.prototype.fetchItemEntries=function(t,e,r){for(var n=[],i=[],o=0,s=e;o<s.length;o++){var a=s[o];this.keyService.isLocalId(a)?i.push(a):n.push(a)}return this.promiseService.all({remote:this.transaction.getServerCache().itemHandler.fetchItemEntries(t,n,r),local:this.fetchLocalItemEntries(t,i,r)}).then(function(t){return t.remote.concat(t.local)})},e.prototype.fetchTitle=function(t,e){var r=this,n=this.itemEntryService.getTitleField(t);return this.fetchItemEntry(t,e,new B({columns:[n]})).then(function(t){return r.transaction.getItemChangesRecursively(t.id,!1)[n]},this.errorHandler.reject)},e.prototype.resolveLocalItemEntry=function(t,e,r,n){var i=this;if(r.run(e.columns))return this.promiseService.when(e);var o=this.getColumnDifference(e,n.columns);return this.columnHandler.fetch(e.itemType,o).then(function(r){return i.expandLocalItemEntries(t,e.itemType,[e],o,r)},this.errorHandler.reject).then(function(){return e},this.errorHandler.reject)},e.prototype.createLocalEntries=function(t,e,r,n,i,o,s){var a=this;void 0===o&&(o=function(){return!0});var c=n.response,u={},l=function(e,r,h){var p={itemType:e,itemId:r},d=c.items[e][h].links;for(var f in d)if(d.hasOwnProperty(f)){void 0===u[f]&&(u[f]=a.columnSetFactory.construct(f,!0,n.responseColumns));for(var m=0,y=d[f];m<y.length;m++){var v=y[m],g=c.fetchObject(f,v);if(o(f,g)){var C=i[f][v],I=a.updateItemValues(g,p,u[f].item,i);for(var E in I)g[E]=I[E];void 0!==s&&s(f,g,i),t.setItemCreated(C,g,u[f],p),l(f,C,v)}}}};l(e,r,c.links[e][0])},e.prototype.expandLocalItemEntries=function(t,e,r,n,i){if(0===r.length)return this.promiseService.when(r);for(var o=this.columnExpansionFactory.construct(e,n,i),s=0,a=r;s<a.length;s++){var c=a[s],u=o.run(c.columns);null!==u&&this.expandLocalItemEntry(t,c,u)}return this.resolveDerivedValues(r,o.aggregateRootColumns())},e.prototype.updateItemValues=function(t,e,r,n){for(var i={},o=0,s=r;o<s.length;o++){var a=s[o],c=a.id,u=a.apiColumn,l=void 0;"link"===u.type&&void 0===t[c]?null!==e&&(l=e.itemId):l=this.itemEntryService.getConversionValue(u.itemType,t[c],n),void 0!==l&&(i[c]=l)}return i},e.prototype.fetchLocalItemEntryData=function(t,e,r,n,i){var o=this.entries.get(e,r);return void 0===o?this.errorHandler.reject(this.itemEntryService.createUnfoundLocalItemError(e)):this.resolveLocalItemEntry(t,o,n,i)},e.prototype.fetchLocalItemEntries=function(t,e,r){var n=this;r.columns=this.expandColumnsWithCollectionColumns(t,r.columns);for(var i=this.changesDeltaFactory.construct(),o=this.columnSubsetCacheFactory.construct(r.columns),s=[],a=[],c=0,u=e;c<u.length;c++){var l=u[c];if(void 0!==this.entries.get(t,l))s.push(this.fetchLocalItemEntryData(i,t,l,o,r));else{if(this.transaction.parent instanceof Gt)return this.errorHandler.reject(this.itemEntryService.createUnfoundLocalItemError(t));a.push(l)}}if(a.length>0){if(this.transaction.parent instanceof Gt)throw new Error("Tried looking for local entries on the serverCache");s.push(this.transaction.parent.itemHandler.fetchLocalItemEntries(t,a,r))}return this.promiseService.all(s).then(function(){return n.transaction.applyChangesDelta(i).then(function(){return e.map(function(e){return n.transaction.getLocalItemEntryByItemId(t,e)})},n.errorHandler.reject)},this.errorHandler.reject)},e.prototype.getColumnDifference=function(t,e){return this.columnUtil.mergeRequestColumns(t.columns.request,e).difference},e.prototype.resolveLocal=function(t,e,r,n,i,o,s){void 0===o&&(o=function(){return!0});var a=this.itemEntryService.createLocalConversionMap(e,r,!0,i.response),c=this.apiFormatter.copyFields(i.fields,{},i.columns.main),u=this.updateItemValues(c,n,i.columns.item,a);for(var l in u)c[l]=u[l];void 0!==s&&s(e,c,a),t.setItemCreated(r,c,i.columns,n),this.createLocalEntries(t,e,r,i,a,o,s)},e.prototype.expandLocalItemEntry=function(t,e,r){var n=r.difference.main;if(e.columns=r.merged,0!==n.length){var i=this.getLocalValues(e,n);s(i)&&t.setItemUpdated(e,i,r)}},e.prototype.getLocalValues=function(t,e){for(var r=this.transaction.getParent(t),n=this.transaction.getChangesFromItemChanges(this.itemChanges[t.id]),i={},o=0,s=e;o<s.length;o++){var a=s[o],c=a.id;if(void 0===n[c]){var u=a.apiColumn.type;i[c]="link"===u&&null!==r?r.itemId:this.apiFormatter.getDefaultValue(u)}}return i},e}(ut),pt=function(){function t(t,e,r,n,i,o,s,a,c,u,l,h,p,d,f,m,y,v,g,C,I,E,F,S,R,q,T,w,b,H,M,x,k){this.core=t,this.columnCache=e,this.requestBufferManager=r,this.requestColumnExpansionFactory=n,this.queryMatcherFactory=i,this.authInterface=o,this.changesDeltaFactory=s,this.lockService=a,this.moduleChangesCompilationFactory=c,this.collectionResourceFactory=u,this.itemResourceFactory=l,this.templateCache=h,this.itemCacheFactory=p,this.collectionCacheFactory=d,this.errorHandler=f,this.exceptionHandler=m,this.promiseService=y,this.apiRequestService=v,this.columnExpansionFactory=g,this.columnHandler=C,this.columnSetFactory=I,this.columnSubsetCacheFactory=E,this.columnUtil=F,this.itemEntryFactory=S,this.itemEntryService=R,this.keyService=q,this.collectionEntryFactory=T,this.collectionEntryService=w,this.collectionMatcherFactory=b,this.queryParserFactory=H,this.queryService=M,this.apiFormatter=x,this.linkTreeService=k,this.children=[]}return t.prototype.createChild=function(t,e){var r=new Ft(this.core,this.columnCache,this.requestBufferManager,this.requestColumnExpansionFactory,this.queryMatcherFactory,this.authInterface,this.changesDeltaFactory,this.lockService,this.moduleChangesCompilationFactory,this.collectionResourceFactory,this.itemResourceFactory,this.templateCache,this.itemCacheFactory,this.collectionCacheFactory,this.errorHandler,this.exceptionHandler,this.promiseService,this.apiRequestService,this.columnExpansionFactory,this.columnHandler,this.columnSetFactory,this.columnSubsetCacheFactory,this.columnUtil,this.itemEntryFactory,this.itemEntryService,this.keyService,this.collectionEntryFactory,this.collectionEntryService,this.collectionMatcherFactory,this.queryParserFactory,this.queryService,this.apiFormatter,this.linkTreeService,this,t,e);return this.children.push(r),r},t.prototype.onChildDestroy=function(t){var e=this.children.indexOf(t);-1!==e&&this.children.splice(e,1)},t.prototype.getTransactionChain=function(){var t=[],e=this;do{t.push(e),e=e.parent}while(null!==e);return t},t.prototype.getCurrentCollectionEntryCache=function(){return this.collectionHandler.entries},t.prototype.getCurrentItemEntryCache=function(){return this.itemHandler.entries},t.prototype.getParentFromFields=function(t,e){if(void 0===e)return null;if(null!==t.columns.link)return{itemType:t.columns.link.apiColumn.itemType,itemId:e[t.columns.link.id]};var r=t.columns.response[t.itemType];return void 0!==r.itemtype&&void 0!==r.item?{itemType:e.itemtype,itemId:e.item}:null},t.prototype._applyChangesDelta=function(t){var e=this,r=this.changesDeltaFactory.constructInternalDelta();for(var n in t._queryResults)for(var i in t._queryResults[n])r._setQueryResult(n,i,t._queryResults[n][i]);for(var o=[],s=[],a=function(t){var e=c.itemHandler.createItemEntry(t);o.push(e),r.setItemCreated(e,c.getChangesFromItemChanges(c.itemHandler.itemChanges[e.id])),s.push(function(t){return t.setItemDeleted(e)})},c=this,u=0,l=t.created;u<l.length;u++){a(l[u])}var h=function(e){var n=t.updated[e],i=p.itemHandler.processItemEntryChanges(n,!0,!1,!1,!0);if(r.setItemUpdated(n.entry,n.changes.fields,n.changes.expandedColumns),null!==i&&s.push(function(t){return t.setItemUpdated(n.entry,i)}),null!==n.changes.parent&&r.setItemMoved(n.entry,n.changes.parent),p.itemHandler instanceof ht){var o=p.itemHandler.deletedItems[n.entry.itemType];if(void 0===o)return"continue";var a=o.indexOf(n.entry);a>-1&&o.splice(a,1)}},p=this;for(var d in t.updated)h(d);return{result:{created:o,rollback:function(){for(var t=e.changesDeltaFactory.construct(),r=0,n=s;r<n.length;r++){(0,n[r])(t)}return e.applyChangesDelta(t)}},internalChangesDelta:r,rollbackFunctions:s}},t.prototype.fetchUpdatedDerivedValuesFromDelta=function(t){var e=[];for(var r in t.updated){for(var n=t.updated[r],i=[],o=0,s=n.entry.columns.root;o<s.length;o++){var a=s[o];n.changes.fields.hasOwnProperty(a.id)&&n.changes.fields[a.id]!==this.getChangesFromItemChanges(this.itemHandler.itemChanges[n.entry.id])[a.id]&&i.push(a)}0!==i.length&&e.push(this.itemHandler.resolveDerivedValues([n.entry],i,t))}return this.promiseService.all(e)},t}(),dt=function(){function t(t,e,r){this.queryMatcherFactory=t,this.transaction=e,this.getCollectionEntries=r,this.map={}}return t.prototype.expand=function(t,e){var r=this.queryMatcherFactory.construct(t.itemType,e,this.transaction.getParent(t));return this._expand(t,function(t){return r.matchQuery(t.query.object)})},t.prototype.processDelta=function(t){for(var e in t.deleted)for(var r=0,n=t.deleted[e];r<n.length;r++){var i=n[r];this._expand(i,function(){return!1})}var o=function(e){var r=t.created[e],n=s.queryMatcherFactory.construct(r.entry.itemType,r.fields,s.transaction.getParent(r.entry));s._expand(r.entry,function(e){var i=t._queryResults[e.itemType];if(void 0!==i){var o=i[e.query.string];if(void 0!==o&&!r.entry.isLocal())return-1!==o.indexOf(r.entry.itemId)}return n.matchQuery(e.query.object)})},s=this;for(var a in t.created)o(a);var c=function(e){var r=t.moved[e];u._expand(r.entry,function(t){return t.matchParent(r.to.itemType,r.to.itemId)})},u=this;for(var a in t.moved)c(a);var l=function(e){var r=t.updated[e],n={},i=h.transaction.getItemChangesRecursively(Number(e),!1),o=function(t,e){var r=Object.getOwnPropertyDescriptor(t,e);void 0!==r?Object.defineProperty(n,e,r):n[e]=t[e]};for(var s in i)o(i,s);for(var s in r.changes.fields)o(r.changes.fields,s);var a=h.queryMatcherFactory.construct(r.entry.itemType,n,h.transaction.getParent(r.entry));h._expand(r.entry,function(e){var n=t._queryResults[e.itemType];if(void 0!==n){var i=n[e.query.string];if(void 0!==i&&!r.entry.isLocal())return-1!==i.indexOf(r.entry.itemId)}return a.matchQuery(e.query.object)})},h=this;for(var a in t.updated)l(a);return this},t.prototype.hasFittingItems=function(t){for(var e in t)if(!0===t[e].isMatch)return!0;return!1},t.prototype._expand=function(t,e){for(var r=this.map,n=t.itemId,i=0,o=this.getCollectionEntries(t.itemType);i<o.length;i++){var s=o[i],a=s.id,c=void 0;void 0===r[a]&&(r[a]={collection:s,matches:{}}),void 0===(c=r[a].matches)[n]&&(c[n]={item:t,isMatch:e(s)})}return this},t}(),ft=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),mt=function(t){function e(e,r,n){return t.call(this,e,r,n)||this}return ft(e,t),e.prototype.getCollectionsWithFittingItems=function(){var t=[];for(var e in this.map){var r=this.map[e];this.hasFittingItems(r.matches)&&t.push(r.collection)}return t},e}(dt),yt=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),vt=function(t){function e(e,r,n,i){var o=t.call(this,r,n,i)||this;return o.apiRequestService=e,o}return yt(e,t),e.prototype.removeFromAndAddToCollections=function(t){var e=this;void 0===t&&(t=!1);var r=function(r){var i,o=n.map[r],s=o.collection,a=n.groupItemEntries(o.matches);n.transaction.collectionHandler.removeItemEntriesFromCollectionChanges(s,a.notFitting,t),n.transaction.collectionHandler.addItemEntriesToCollectionChanges(s,a.fitting,t),a.maybe.length>0&&n.apiRequestService.query(s.itemType,s.query.object,(i={},i[s.itemType]=["id"],i)).then(function(r){e.transaction.collectionHandler.addItemEntriesToCollectionChanges(s,a.maybe.filter(function(t){return r.links[s.itemType].indexOf(t.itemId)>-1}),t)})},n=this;for(var i in this.map)r(i)},e.prototype.groupItemEntries=function(t){var e=[],r=[],n=[];for(var i in t){var o=t[i],s=o.item,a=o.isMatch;!0===a?e.push(s):!1===a?r.push(s.itemId):n.push(s)}return{fitting:e,notFitting:r,maybe:n}},e}(mt),gt=function(){function t(t,e,r){this.errorHandler=t,this.exceptionHandler=e,this.promiseService=r,this.callbacks={onBeforeSave:[],onSaveSuccess:[]}}return t.prototype.registerCallback=function(t,e,r,n,i){var o=this;return void 0===n&&(n="always"),void 0===i&&(i=100),this.getPriorityLevel(t,i)[e]={callback:r,condition:n},function(){delete o.getPriorityLevel(t,i)[e]}},t.prototype.executeCallbacks=function(t,e,r){for(var n=this.callbacks[t],i=r?"onClose":"skipOnClose",o=this.promiseService.when(),s=0,a=n;s<a.length;s++){var c=a[s];o=o.then(this.executeCallbacksPriorityLevel(c[1],i,e),this.errorHandler.reject)}return o},t.prototype.getPriorityLevel=function(t,e){for(var r,n=this.callbacks[t],i=0;i<n.length;i++){var o=n[i];if(!(o[0]<e))return o[0]===e?o[1]:(r={},n.splice(i,0,[e,r]),r)}return r={},n.push([e,r]),r},t.prototype.executeCallbacksPriorityLevel=function(t,e,r){var n=this;return function(){var i={};for(var o in t){var s=t[o];if(s.condition===e||"always"===s.condition)try{i[o]=r(s.callback)}catch(t){n.exceptionHandler(t)}}return n.promiseService.all(i)}},t}(),Ct=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),It=function(){return(It=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};!function(t){t.warning="warning",t.error="error"}(ct||(ct={}));var Et,Ft=function(t){function e(e,r,n,i,o,s,a,c,u,l,h,p,d,f,m,y,v,g,C,I,E,F,S,R,q,T,w,b,H,M,x,k,D,O,_,P){var L=t.call(this,e,r,n,i,o,s,a,c,u,l,h,p,d,f,m,y,v,g,C,I,E,F,S,R,q,T,w,b,H,M,x,k,D)||this;return L.id=_,L.errors={item:{},global:{}},L.isValid=!0,L.tabRequestParameters={},L.isSaving=!1,L.hasChanges=!1,L.changesInterval=null,L.validator=void 0===P?void 0:P.construct(L),L.parent=O,L.itemHandler=new ht(a,y,p,C,I,E,F,m,q,T,v,S,k,R,d,i,L,L.validator),L.collectionHandler=new fe(i,S,F,C,a,f,b,H,I,m,L.itemHandler,T,v,y,L),L.eventHandler=new gt(m,y,v),L}return Ct(e,t),e.prototype.destroy=function(){this.parent.onChildDestroy(this)},e.prototype.createChangesDelta=function(){return this.changesDeltaFactory.construct()},e.prototype.getFirstErrorString=function(){for(var t in this.errors.global){if((o=this.errors.global[t]).level===ct.error)return o.string}for(var e in this.errors.item){var r=this.errors.item[e];for(var n in r){var i=r[n];for(var t in i){var o;if((o=i[t]).level===ct.error)return o.string}}}},e.prototype._setGlobalError=function(t,e,r,n){e?(this.errors.global[t]={string:r,level:n},this._setIsValid()):this.clearGlobalError(t)},e.prototype._setItemError=function(t,e,r,n,i,o){n?(p(this.errors.item,[t,e,r],[{},{},{string:i,level:o}]),this._setIsValid()):this.clearItemError(t,e,r)},e.prototype._setIsValid=function(){for(var t in this.isValid=!0,this.errors.global){if(this.errors.global[t].level===ct.error)return void(this.isValid=!1)}for(var e in this.errors.item){var r=this.errors.item[e];for(var n in r){var i=r[n];for(var t in i){if(i[t].level===ct.error)return void(this.isValid=!1)}}}},e.prototype.applyChangesFromParent=function(t,e,r){var n=this;for(var i in void 0===e&&(e=!1),void 0===r&&(r=!1),t.updated){var o=t.updated[i];this.itemHandler.processItemEntryChanges(o,e,!0,r)}for(var s in t.deleted)for(var a=0,c=t.deleted[s];a<c.length;a++){var u=c[a];if(this.itemHandler.entries.clear(u),delete this.itemHandler.itemChanges[u.id],delete this.itemHandler.itemResources[u.id],void 0!==this.itemHandler.deletedItems[u.itemType]){var l=this.itemHandler.deletedItems[u.itemType].indexOf(u);-1!==l&&this.itemHandler.deletedItems[u.itemType].splice(l,1)}}new vt(this.apiRequestService,this.queryMatcherFactory,this,function(t){return n.collectionHandler.getAllCollectionsByItemType(t)}).processDelta(t).removeFromAndAddToCollections(r);for(var h=0,p=this.children;h<p.length;h++){p[h].applyChangesFromParent(t)}this.hasChanges=!1,this.detectChanges(),void 0!==this.validator&&(this.clearGlobalError(),this.validator.validateTransaction())},e.prototype.applyChangesDelta=function(e){var r=this;return 0!==e.created.length||s(e.updated)||s(e.deleted)?this.fetchUpdatedDerivedValuesFromDelta(e).then(function(){var n=t.prototype._applyChangesDelta.call(r,e),i=n.result,o=n.internalChangesDelta,s=n.rollbackFunctions;for(var a in e.deleted)for(var c=function(t){r.itemHandler.entries.clear(t);var n=r.itemHandler.itemChanges[t.id];delete e.updated[t.id],delete r.itemHandler.itemChanges[t.id],delete r.itemHandler.itemResources[t.id],void 0===r.itemHandler.deletedItems[t.itemType]&&(r.itemHandler.deletedItems[t.itemType]=[]),r.itemHandler.deletedItems[t.itemType].push(t),o.setItemDeleted(t),s.push(function(e){e.setItemUpdated(t,n.changes)})},u=0,l=e.deleted[a];u<l.length;u++){c(l[u])}new vt(r.apiRequestService,r.queryMatcherFactory,r,function(t){return r.collectionHandler.getAllCollectionsByItemType(t)}).processDelta(o).removeFromAndAddToCollections();for(var h=0,p=r.children;h<p.length;h++){p[h].applyChangesFromParent(o)}return r.hasChanges=!1,r.detectChanges(),void 0!==r.validator&&r.validator.validateTransaction(),i}):this.promiseService.when({created:[],rollback:Je})},e.prototype.getServerCache=function(){return this.parent.getServerCache()},e.prototype.getParent=function(t,e,r){var n;if(void 0===e&&(e=!1),void 0!==r)n=r;else{var i=this.itemHandler.itemChanges[t.id];void 0!==i&&(n=i[e?"initial":"changes"])}if(void 0!==n){var o=this.getParentFromFields(t,n);if(null!==o)return o}return this.parent.getParent(t,e)},e.prototype.getCollectionChangesRecursively=function(t){var e=this.getLocalCollectionEntry(t);if(void 0===e)throw new Error("Called getCollectionChangesRecursively with a collectionEntryId that isn't cached");var r=this.collectionHandler.getCollectionChanges(e.itemType,e.query.string);return void 0===r&&(r=this.parent.getCollectionChangesRecursively(t).slice(),this.collectionHandler.setCollectionChanges(e.itemType,e.query.string,r)),r},e.prototype.getItemChangesRecursively=function(t,e){void 0===e&&(e=!0);var r=this.itemHandler.itemChanges[t],n=this.getLocalItemEntry(t);return void 0!==r&&void 0!==n?e?this.apiFormatter.copyFields(r.changes,{},n.columns.main):r.changes:this.parent.getItemChangesRecursively(t,e)},e.prototype.clearItemResource=function(t){return this.itemHandler.clearResource(t)},e.prototype.clearCollectionResource=function(t){return this.collectionHandler.clearResource(t)},e.prototype.isLockable=function(){return void 0!==this.rootItem&&this.rootItem.isLockable()},e.prototype.disableChangesWatcher=function(){null!==this.changesInterval&&(clearInterval(this.changesInterval),this.changesInterval=null)},e.prototype.enableChangesWatcher=function(){var t=this;null!==this.changesInterval&&(console.warn("Changes watcher already running!",this),this.disableChangesWatcher()),this.changesInterval=window.setInterval(function(){t.detectChanges()&&(t.disableChangesWatcher(),t.isLockable()&&t.lockService.fetchLock(t.rootItem))},3e3)},e.prototype.save=function(t,e,r,n){var i,o=this;return void 0===t&&(t=!1),void 0===e&&(e={}),this.isSaving?this.errorHandler.reject():(this.isSaving=!0,this.detectChanges(),this.disableChangesWatcher(),(this.isLockable()?this.lockService.fetchLock(this.rootItem):this.promiseService.when()).then(function(){return o.eventHandler.executeCallbacks("onBeforeSave",function(t){return t(o)},t)},this.errorHandler.reject).then(function(){return o.tabRequestParameters=It({},o.tabRequestParameters,e),o.parent.applyChangesFromChild(o,r,n)}).then(function(e){return i=e,o.tabRequestParameters={},o.isLockable()&&o.lockService.clearLock(o.rootItem),o.hasChanges=!1,o.eventHandler.executeCallbacks("onSaveSuccess",function(t){return t(o,i)},t)},this.errorHandler.reject).then(function(){return t||o.enableChangesWatcher(),o.isSaving=!1,i},this.errorHandler.reject).catch(function(t){return o.isSaving=!1,o.errorHandler.reject(t)}))},e.prototype.detectChanges=function(){return!!this.hasChanges||(this.itemHandler.detectChanges()?this.hasChanges=!0:this.hasChanges=!1)},e.prototype.clearItem=function(t){this.clearItemEntry(t.entry)},e.prototype.clearItemEntry=function(t){return this.itemHandler.clearItemEntry(t)},e.prototype.clearCollection=function(t){return this.collectionHandler.clearEntry(t.entry)},e.prototype.onBeforeSave=function(t,e,r,n){return this.eventHandler.registerCallback("onBeforeSave",t,e,r,n)},e.prototype.onSaveSuccess=function(t,e,r,n){return this.eventHandler.registerCallback("onSaveSuccess",t,e,r,n)},e.prototype.getModuleChanges=function(){if(void 0===this.rootItem)throw new Error("No root item for transaction cache "+this);return this.moduleChangesCompilationFactory.construct(this).process()},e.prototype.updateItemIdMap=function(t,e){if(void 0!==e)for(var r in e){var n=e[r];void 0!==t[r]&&(t[n]=t[r],delete t[r])}},e.prototype.cloneCollection=function(t,e,r){var n=e.parent;if(null===n||void 0===n)throw new Error("Parent required for cloneCollection");return this.createCollectionResource(this.collectionHandler.cloneCollectionEntry(t.entry,n,r),e)},e.prototype.cloneItem=function(t,e){var r=this,n=this.changesDeltaFactory.construct();return this.itemHandler.cloneItemEntry(n,t.entry),this.applyChangesDelta(n).then(function(t){var n=t.created[0];return r.createItemResource(n,e,!1)})},e.prototype.getAllLinkCollections=function(t,e,r){var n,i=this;return this.apiRequestService.query(t,{},(n={},n[t]=["id"],n)).then(function(n){return i.getLinkCollections(t,n.links[t],e,r)},this.errorHandler.reject)},e.prototype.getLinkCollectionsFromDef=function(t,e,r){var n=this;return this.collectionHandler.fetchLinkedCollectionEntries(t,e,r.itemType,r.options.entry).then(function(t){return n.createCollectionResources(t,r.options.resource)},this.errorHandler.reject)},e.prototype.getLinkCollections=function(t,e,r,n){var i=this;return this.collectionHandler.fetchLinkedCollectionEntries(t,e,r,new K(n)).then(function(t){return i.createCollectionResources(t,n)},this.errorHandler.reject)},e.prototype.getCollectionFromDef=function(t){var e=this;return this.collectionHandler.fetchCollectionEntry(t.itemType,t.options.entry).then(function(r){return e.createCollectionResource(r,t.options.resource)},this.errorHandler.reject)},e.prototype.getCollection=function(t,e){var r=this;return this.collectionHandler.fetchCollectionEntry(t,new K(e)).then(function(t){return r.createCollectionResource(t,new z(e))},this.errorHandler.reject)},e.prototype.getCollectionDef=function(t,e){return{itemType:t,options:{entry:new K(e),resource:new z(e)}}},e.prototype.getLinkCollectionsDef=function(t,e,r){return{itemType:t,linkField:e,options:{entry:new K(r),resource:new z(r)}}},e.prototype.getItemByState=function(t,e,r,n){void 0===r&&(r={});var i=this.keyService.parseStateKey(e);if(null===i){var o=e;if(!this.keyService.isLocalId(o)||this.itemHandler.entries.contains(t,o))return this.getItemById(t,o,r,n)}else if("duplicate"===i.type)return this.getDuplicateById(t,i.itemId,r,!1,n);return this.getNewResource(t,r,!1,n)},e.prototype.getDuplicateById=function(t,e,r,n,i){return void 0===r&&(r={}),void 0===r.templateOptions&&(r.templateOptions={}),void 0===r.templateOptions.item&&(r.templateOptions.item=e),this.getNewResourceWithId(t,this.keyService.getLocalDuplicateId(),r,n,i)},e.prototype.getNewResourceWithId=function(t,e,r,n,i){var o=this;return void 0===n&&(n=!1),r.edit=!0,this.itemHandler.fetchNewItemEntry(t,e,new B(r)).then(function(s){for(var a,c={},u=0,l=s.created;u<l.length;u++){var h=l[u];h.itemType!==t||h.itemId!==e?(void 0===c[h.itemType]&&(c[h.itemType]=[]),c[h.itemType].push(h)):a=h}if(void 0===a)throw new Error("The ItemEntry with the requested ItemId was not in the template response");var p=o.createItemResource(a,r,i,!0);return n?{main:p,linked:o.processLinkedItems(c,r)}:p},this.errorHandler.reject)},e.prototype.getNewResource=function(t,e,r,n){return void 0===e&&(e={}),this.getNewResourceWithId(t,this.keyService.getLocalId(),e,r,n)},e.prototype.getItemsByQuery=function(t,e,r){var n=this;void 0===r&&(r={});var i=new B(r);return this.collectionHandler.fetchItemEntriesByQuery(t,e,i).then(function(t){return n.createItemResources(t,r)},this.errorHandler.reject)},e.prototype.getItemsById=function(t,e,r){var n=this;return void 0===r&&(r={}),this.itemHandler.fetchItemEntries(t,e,new B(r)).then(function(t){return n.createItemResources(t,r)},this.errorHandler.reject)},e.prototype.getItemById=function(t,e,r,n){var i=this;return void 0===r&&(r={}),this.itemHandler.fetchItemEntry(t,e,new B(r)).then(function(t){return i.createItemResource(t,r,n)},this.errorHandler.reject)},e.prototype.fetchTitle=function(t,e){return this.itemHandler.fetchTitle(t,e)},e.prototype.applyChangesFromChild=function(t,e,r){var n=this,i=this.linkTreeService.get(),o=t.getDelta();for(var s in o.moved){var a=o.moved[s];o.setItemUpdated(a.entry,{},null,a.to),delete o.moved[s]}for(var s in o.updated){a=o.updated[s];void 0===this.itemHandler.itemChanges[s]?this.itemHandler.itemChanges[s]=this.itemHandler.copyTransactionItemEntryChanges(t.itemHandler.itemChanges[s],a.entry):this.itemHandler.processItemEntryChanges(a,!0)}for(var s in o.created){a=o.created[s];this.itemHandler.entries.add(a.entry),t.itemHandler.entries.clear(a.entry);var c=this.itemHandler.itemChanges[a.entry.id]=this.itemHandler.copyTransactionItemEntryChanges(t.itemHandler.itemChanges[s],a.entry),u=this.itemEntryService.getDisplayName(a.entry,c.changes);if(void 0!==u&&(c.changes.displayname=u),void 0!==this.rootItem){var l=i[this.rootItem.itemType][a.entry.itemType];void 0!==l&&(l.type===D.ITEMTABLE?(c.changes.itemtype=this.rootItem.itemType,c.changes.item=this.rootItem.itemId):l.type===D.DIRECT&&(c.changes[l.field]=this.rootItem.itemId))}}for(var h in o.deleted){void 0===this.itemHandler.deletedItems[h]&&(this.itemHandler.deletedItems[h]=[]);for(var p=0,d=o.deleted[h];p<d.length;p++){var f=d[p];f.isLocal()||(this.itemHandler.entries.clear(f),this.itemHandler.deletedItems[h].push(f))}}return this.hasChanges=!0,this.expandItemsFromDelta(o).then(function(){new vt(n.apiRequestService,n.queryMatcherFactory,n,function(t){return n.collectionHandler.getAllCollectionsByItemType(t)}).processDelta(o).removeFromAndAddToCollections();for(var e=0,r=n.children;e<r.length;e++){var i=r[e];i!==t&&i.applyChangesFromParent(o)}return void 0!==n.validator&&n.validator.validateTransaction(),o.itemIdConversionMap})},e.prototype.getLocalItemEntryChangesTuple=function(t){var e=this.getLocalItemEntry(t);if(void 0===e)throw new Error("Tried to get a local ItemEntry with entryId '"+t+"' but couldn't find it");return{entry:e,changes:this.itemHandler.itemChanges[t]}},e.prototype.getLocalItemEntry=function(t){var e=this.itemHandler.entries.getByEntryId(t);return void 0!==e?e:this.parent.getLocalItemEntry(t)},e.prototype.getLocalItemEntryByItemId=function(t,e){var r=this.itemHandler.entries.get(t,e);return void 0!==r?r:this.parent.getLocalItemEntryByItemId(t,e)},e.prototype.getLocalCollectionEntryByQueryString=function(t,e){var r=this.collectionHandler.entries.getByQueryString(t,e);return null!==r?r:this.parent.getLocalCollectionEntryByQueryString(t,e)},e.prototype.getLocalCollectionEntry=function(t){var e=this.collectionHandler.entries.getByEntryId(t);return void 0!==e?e:this.parent.getLocalCollectionEntry(t)},e.prototype.getDelta=function(){var t=this.changesDeltaFactory.constructInternalDelta();for(var e in this.itemHandler.itemChanges){var r=this.getLocalItemEntryChangesTuple(Number(e));if(this.itemHandler.entries.contains(r.entry.itemType,r.entry.itemId)&&r.entry.isLocal())t.setItemCreated(r.entry,r.changes.changes);else{var n=this.getParent(r.entry);if(null!==n){var i=this.getParent(r.entry,!0);this.itemEntryService.matchParent(i,n)||t.setItemMoved(r.entry,n)}this.apiFormatter.hasChanges(r.changes.initial,r.changes.changes,r.entry.columns.main)&&t.setItemUpdated(r.entry,r.changes.changes)}}for(var o in this.itemHandler.deletedItems)t.setItemsDeleted(this.itemHandler.deletedItems[o]);return t},e.prototype.createItemResource=function(t,e,r,n){void 0===r&&(r=!1),r&&(this.rootItem=t),void 0===this.itemHandler.itemChanges[t.id]&&(this.itemHandler.itemChanges[t.id]={initial:this.getItemChangesRecursively(t.id),changes:this.getItemChangesRecursively(t.id)});var i=this.itemResourceFactory.construct(t,e,this,n);return this.itemHandler.addResource(i),i},e.prototype.createItemResources=function(t,e){for(var r=this.itemResourceFactory.getConstructor(e,this),n=[],i=0,o=t;i<o.length;i++){var s=o[i];void 0===this.itemHandler.itemChanges[s.id]&&(this.itemHandler.itemChanges[s.id]={initial:this.getItemChangesRecursively(s.id,!0),changes:this.getItemChangesRecursively(s.id,!0)});var a=r(s);n.push(a),this.itemHandler.addResource(a)}return n},e.prototype.processLinkedItems=function(t,e){var r={};for(var n in t)r[n]=this.createItemResources(t[n],e);return r},e.prototype.createCollectionResource=function(t,e){var r=this.collectionResourceFactory.construct(t,e,this);return this.collectionHandler.addResource(r),r},e.prototype.getChangesFromItemChanges=function(t){return t.changes},e.prototype.createCollectionResources=function(t,e){var r={};for(var n in t)r[n]=this.createCollectionResource(t[n],e);return r},e.prototype.expandItemsFromDelta=function(t){var e={},r={},n=function(t){void 0===e[t.itemType]&&(e[t.itemType]=[]),e[t.itemType].push(t)};for(var i in t.created)n(t.created[i].entry);for(var i in t.updated)n(t.updated[i].entry);for(var o in e){var s=this.collectionHandler.getAllCollectionsByItemType(o);if(0!==s.length){for(var a=this.requestColumnExpansionFactory.construct(),c=0,u=s;c<u.length;c++){var l=u[c];a.expand(l.columns)}r[o]=a.get()[o]}}var h=[];for(var o in r)h.push(this.itemHandler.expandLocalItemEntries(t,o,e[o],r[o],this.columnCache.retrieve(o,r[o]).cached));return this.promiseService.all(h)},e.prototype.clearGlobalError=function(t){void 0===t?this.errors.global={}:delete this.errors.global[t],this._setIsValid()},e.prototype.clearItemError=function(t,e,r){if(void 0===t)return this.errors.item={},void this._setIsValid();if(void 0===e)return delete this.errors[t],void this._setIsValid();if(void 0!==this.errors[t]){if(void 0===r)return delete this.errors[t][e],void(s(this.errors[t])||this.clearItemError(t));delete this.errors[t][e][r],s(this.errors[t][e])||this.clearItemError(t,e)}},e}(pt);!function(t){t.MAYBE="maybe"}(Et||(Et={}));var St,Rt,qt=function(){function t(t,e){this.queryMatcherFactory=t,this.transaction=e,this.entries={}}return t.prototype.getByEntryId=function(t){for(var e in this.entries){var r=this.entries[e][t];if(void 0!==r)return r}},t.prototype.contains=function(t){var e=this.entries[t.itemType];return void 0!==e&&void 0!==e[t.id]},t.prototype.some=function(t){var e=this.entries;for(var r in e)for(var n in e[r])if(t(e[r][n]))return!0;return!1},t.prototype.forEach=function(t){var e=this.entries;for(var r in e)for(var n in e[r])t(e[r][n])},t.prototype.toArray=function(){var t=this.entries,e=[];for(var r in t)for(var n in t[r])e.push(t[r][n]);return e},t.prototype.add=function(t){var e=this.entries,r=t.itemType;return void 0===e[r]&&(e[r]={}),e[r][t.id]=t},t.prototype.clear=function(t){return void 0===t?(this.entries={},!0):!!this.contains(t)&&delete this.entries[t.itemType][t.id]},t.prototype.getByItemType=function(t){var e=this.entries[t],r=[];if(void 0===e)return r;for(var n in e)r.push(e[n]);return r},t.prototype.matchParent=function(t,e,r){var n=t.parent;return null!==n&&(n.itemType===e&&n.itemId==r)},t.prototype.getByParent=function(t,e,r){var n=this.entries[r];if(void 0===n)return null;for(var i in n)if(this.matchParent(n[i],t,e))return n[i];return null},t.prototype.getCollectionsByParent=function(t,e){var r=this.entries,n=[];for(var i in r)for(var o in r[i]){var s=r[i][o];this.matchParent(s,t,e)&&n.push(s)}return n},t.prototype.getByContainingItem=function(t,e){var r=this.entries[t],n=[];if(void 0===r)return n;for(var i in r){var o=r[i],s=this.transaction.collectionHandler.getCollectionChanges(o.itemType,o.query.string);void 0!==s&&(s.some(function(t){return t.itemId==e})&&n.push(o))}return n},t.prototype.getByFittingItem=function(t,e,r){var n=this.entries[t],i={fitting:[],notfitting:[],maybe:[]};if(void 0===n)return i;var o=this.queryMatcherFactory.construct(t,e,r);for(var s in n){var a=n[s],c=o.matchQuery(a.query.object);!0===c?i.fitting.push(a):c===Et.MAYBE?i.maybe.push(a):i.notfitting.push(a)}return i},t.prototype.getByQuery=function(t,e){var r=this.entries[t];if(void 0===r)return null;for(var n in r){var i=r[n];if(i.query.string===e.string)return i}return null},t.prototype.getByQueryString=function(t,e){var r=this.entries[t];if(void 0===r)return null;for(var n in r){var i=r[n];if(i.query.string===e)return i}return null},t.prototype.getByKey=function(t,e){var r=this.entries[t],n=[];if(void 0===r)return n;for(var i in r){var o=r[i];o.options.entryKey===e&&n.push(o)}return n},t.prototype.getResourceByKey=function(t,e){var r=this.entries[t],n=[];if(void 0===r||!(this.transaction instanceof Ft))return n;for(var i in r)for(var o=0,s=this.transaction.collectionHandler.collectionResources[i];o<s.length;o++){var a=s[o];a.options.resourceKey===e&&n.push(a)}return n},t}(),Tt=function(){function t(t,e){this.queryParserFactory=t,this.queryService=e}return t.prototype.createUnfoundLocalCollectionError=function(t){return{message:"A local collection of type "+t+" could not be found"}},t.prototype.cloneOptions=function(t,e){var r=new K(t);return r.queryParams=this.cloneQueryParams(t.queryParams),r.parent=e,r},t.prototype.processOptions=function(t){return new K(t)},t.prototype.cloneQueryParams=function(t){var e={};for(var r in t){var i=t[r],o=void 0;o=Array.isArray(i)?i.slice():n.isMoment(i)?i.clone():i,e[r]=o}return e},t.prototype.createQuery=function(t){var e,r=t.parent;if(null===r)e=t.query;else{var n={linkedTo:r.itemType,query:{id:"&parentId"}};t.queryParams.parentId=r.itemId,e=null===t.query?n:this.queryService.addAndCondition(t.query,n)}var i=this.queryParserFactory.construct(e,t.queryParams).parse();return{object:i[0],string:i[1]}},t.prototype.getIdArray=function(t,e){void 0===e&&(e=[]),void 0===e&&(e=[]);for(var r=0,n=t;r<n.length;r++){var i=n[r];e.push(i.itemId)}return e},t.prototype.filterArray=function(t,e){for(var r=[],n=[],i=0,o=t;i<o.length;i++){var s=o[i];(e(s)?r:n).push(s)}if(0===n.length)return n;t.length=r.length;for(var a=0;a<t.length;a++)t[a]=r[a];return n},t}(),wt=function(){function t(){}return t.prototype.processOptions=function(t){return new z(t)},t.prototype.getIdArray=function(t){for(var e=[],r=0,n=t;r<n.length;r++){var i=n[r];e.push(i.entry.itemId)}return e},t}(),bt=function(){function t(t){this.columnUtil=t,this.cache={},this.allColumns={}}return t.prototype.setColumn=function(t,e){var r=this.cache;void 0===r[t]&&(r[t]={});var n=r[t],i=e.id;return void 0===n[i]&&(n[i]=e),n[i]},t.prototype.setColumns=function(t,e,r){var n={};for(var i in r){var o=r[i];for(var s in n[i]={},o)n[i][s]=this.setColumn(i,o[s])}return!0===e&&(this.allColumns[t]=!0),n},t.prototype.retrieve=function(t,e){if(!0===e)return this.containsAll(t)?{cached:this.getColumns(t),missing:[]}:{cached:{},missing:!0};var r={},n=[];return this.retrieveColumns(t,e,n,r),{cached:r,missing:n}},t.prototype.containsAll=function(t){return!0===this.allColumns[t]},t.prototype.getColumns=function(t){var e,r=this.cache;return(e={})[t]=void 0===r[t]?[]:r[t],e},t.prototype.retrieveColumns=function(t,e,r,n){this.retrieveColumn(t,"id",r,n);for(var i=0,o=e;i<o.length;i++){var s=o[i];this.retrieveColumn(t,s,r,n)}},t.prototype.retrieveColumn=function(t,e,r,n){var i,o=this.columnUtil.parseRequestColumn(e),s=this.getColumn(t,o.id);if(void 0!==s){if(void 0===n[t]&&(n[t]={}),n[t][o.id]=s,0!==o.children.length){var a=[];this.retrieveColumns(s.itemType,o.children,a,n),0!==a.length&&r.push(((i={})[o.id]=a,i))}}else r.push(e)},t.prototype.getColumn=function(t,e){var r=this.cache[t];if(void 0!==r)return r[e]},t}(),Ht=function(){function t(t,e,r,n){if(this.columnInfoFactory=t,this.itemType=e,this.responseColumns=n,this.expansionMap={},this.expansionMapSize=0,!0===r)for(var i in this.requestColumnsTrue=!0,this.requestColumns=[],n[e])this.requestColumns.push(i);else this.requestColumnsTrue=!1,this.requestColumns=r}return t.prototype.run=function(t){var e=this.expansionMap,r=t.id;return void 0!==e[r]?e[r]:(this.expansionMapSize++,e[r]=t.isSupersetOf(this.requestColumns)?null:t.expand(this.requestColumns,this.requestColumnsTrue,this.responseColumns))},t.prototype.aggregateRootColumns=function(){var t=this.expansionMap;if(1===this.expansionMapSize){var e=t[a(t)];return null!==e?e.difference.root:[]}var r={};for(var n in t){var i=t[n];null!==i&&this.expandRootColumnMap(i.difference.root,r)}return this.columnInfoFactory.constructFromRootMap(r)},t.prototype.expandRootColumnMap=function(t,e){for(var r=0,n=t;r<n.length;r++){var i=n[r],o=i.id;void 0===e[o]&&(e[o]={apiColumn:i.apiColumn,children:{}}),this.expandRootColumnMap(i.children,e[o].children)}},t}(),Mt=function(){function t(t,e,r,n,i){this.apiRequestService=t,this.errorHandler=e,this.promiseService=r,this.cache=n,this.columnUtil=i}return t.prototype.setColumn=function(t,e){return this.cache.setColumn(t,e)},t.prototype.setColumns=function(t,e,r){return this.cache.setColumns(t,e,r)},t.prototype.fetchItemTypeTranslations=function(t){for(var e={},r=0,n=t;r<n.length;r++){var i=n[r];e[i]=this.fetch(i,["id"])}return this.promiseService.all(e).then(function(t){var e={};for(var r in t)e[r]=t[r][r].id.name;return e},this.errorHandler.reject)},t.prototype.request=function(t,e,r){var n,i=this;return void 0===r&&(r={filter:!1}),this.apiRequestService.columns(t,(n={},n[t]=e,n),r).then(function(r){return i.cache.setColumns(t,e,r.fetchColumnsObject())},this.errorHandler.reject)},t.prototype.fetch=function(t,e,r){var n=this,i=this.cache.retrieve(t,e);return!0!==i.missing&&0===i.missing.length?this.promiseService.when(i.cached):this.request(t,i.missing,r).then(function(t){return n.columnUtil.mergeResponseColumns(t,i.cached).merged})},t.prototype.fetchAll=function(t){return this.cache.containsAll(t)?this.promiseService.when(this.cache.getColumns(t)):this.request(t,!0)},t}(),xt=">",kt=function(){function t(t,e){void 0===e&&(e=null),this.apiColumn=t,this.parent=e,this.itemType=null,this.children=[],this.isLeaf=!0;var r=t.id;this.id=r,null===e?(this.level=0,this.path=r,this.tailPath=""):(this.level=e.level+1,this.path=e.path+xt+r,this.tailPath=0===e.level?r:e.tailPath+xt+r)}return t.prototype.setChildren=function(t,e){return this.itemType=t,this.children=e,this.isLeaf=!1,this},t}(),Dt={},Ot=0,_t=function(){function t(t,e,r){this.columnUtil=t,this.columnSetFactory=e,this.itemType=r,this.id=++Ot,this.response=Dt,this.link=null,this.main=[],this.derived=[],this.root=[],this.leaf=[],this.formatted={main:[],derived:[]},this.filtered=[],this.custom=[],this.searchable=[],this.item=[],this.notItem=[]}return t.prototype.groupColumnInfo=function(t){var e=this.columnUtil,r=t.apiColumn,n=null!==t.parent;n?this.derived.push(t):(this.main.push(t),"link"===r.type&&(this.link=t),this[e.isItemColumn(r)?"item":"notItem"].push(t),t.isLeaf||this.root.push(t)),e.isFormattedColumn(r)&&this.formatted[n?"derived":"main"].push(t),e.isFilteredColumn(r)&&this.filtered.push(t),e.isSearchableColumn(r)&&this.searchable.push(t),e.isCustomColumn(r)&&this.custom.push(t),t.isLeaf&&this.leaf.push(t)},t.prototype.toJSON=function(){var t=function(t){return t.map(function(t){return t.id})};return{main:t(this.main),derived:t(this.derived)}},t.prototype.expandRequestColumns=function(t){var e=this.columnUtil.mergeRequestColumns(this.request,t).merged;this.request=e,this.requestColumnsTrue=!0===e},t.prototype.isSupersetOf=function(t){if(!0===t)return this.requestColumnsTrue;var e=this.columnUtil,r=this.request;if(!0===r)return!e.containsDerivedColumns(t);for(var n=0,i=t;n<i.length;n++){var o=i[n];if(!e.containsColumn(o,r))return!1}return!0},t.prototype.getMergedColumnSet=function(t,e,r){var n=this.columnSetFactory.construct(this.itemType,t.merged,e);return n.requestColumnsTrue=this.requestColumnsTrue||r,n},t.prototype.mergeRequestColumns=function(t){return this.columnUtil.mergeRequestColumns(this.request,t)},t.prototype.mergeResponseColumns=function(t){return this.columnUtil.mergeResponseColumns(this.response,t).merged},t.prototype.merge=function(t){return this.getMergedColumnSet(this.mergeRequestColumns(t.request),this.mergeResponseColumns(t.response),t.requestColumnsTrue)},t.prototype.expand=function(t,e,r){var n=this.mergeRequestColumns(t),i=this.mergeResponseColumns(r);return{merged:this.getMergedColumnSet(n,i,e),difference:this.columnSetFactory.construct(this.itemType,n.difference,i,!1,!1)}},t}(),Pt=function(){function t(t){this.requestColumns=t,this.cache={}}return t.prototype.run=function(t){var e=this.cache,r=t.id;return void 0!==e[r]?e[r]:e[r]=t.isSupersetOf(this.requestColumns)},t}(),Lt=function(){function t(t){this.linkTreeService=t}return t.prototype.getColumnsFromLink=function(t,e){var r=this.linkTreeService.get()[t][e],n=[];switch(r.type){case D.DIRECT:n.push(r.field);break;case D.ITEMTABLE:n.push("itemtype"),n.push("item")}return n},t.prototype.getColumnPath=function(t,e){for(var r="",n="",i=0,o=t;i<o.length;i++){n+=r+o[i].id,r=xt}return null!==e&&(n+=":"+e),n},t.prototype.getDateFormatOptions=function(t){var e=n(),r={"J-M-Y":e.format("DD-MM-YYYY"),"J-M":e.format("DD-MM"),"j+F+Y":e.format("D MMM YYYY"),"D+j+F+Y":e.format("dddd D MMM YYYY"),F:e.format("MMM"),f:e.format("MMMM"),D:e.format("dddd"),d:e.format("ddd")};return"datetime"===t&&m(r,{"J-M-Y+H:i":e.format("DD-MM-YYYY HH:mm"),"J-M+H:i":e.format("DD-MM HH:mm"),"j+F+Y+H:i":e.format("DD MMMM Y HH:mm"),"D+j+F+Y+H:i":e.format("dddd DD MMM Y HH:mm"),"H:i":e.format("HH:mm")}),r},t.prototype.isStringColumn=function(t){switch(t.type){case"email":case"phone":case"url":case"text":case"longtext":case"textreplace":return!0;default:return!1}},t.prototype.isFloatColumn=function(t){switch(t.type){case"double":case"volume":case"weight":case"distance":case"dimension":case"power":case"current":case"price":case"percentage":return!0;default:return!1}},t.prototype.isIntColumn=function(t){switch(t.type){case"int":case"number":case"quantity":return!0;default:return!1}},t.prototype.isNumberColumn=function(t){return this.isFloatColumn(t)||this.isIntColumn(t)},t.prototype.isCustomColumn=function(t){return"customfield"===t.fieldtype},t.prototype.isItemColumn=function(t,e){switch(void 0===e&&(e=!0),t.type){case"id":return e;case"item":case"child":case"sibling":case"link":return!0;default:return!1}},t.prototype.isDateColumn=function(t){switch(t.type){case"datetime":case"date":return!0;default:return!1}},t.prototype.isRenderedColumn=function(t){switch(t.type){case"datetime":case"date":case"duration":return!0;default:return!1}},t.prototype.isFilteredColumn=function(t){if("staffel"===t.id)return!0;if(void 0!==t.generator)return!0;switch(t.type){case"price":case"bool":case"enum":case"country":case"volume":case"weight":case"distance":case"dimension":case"quantity":case"email":case"url":case"datetime":case"date":case"time":case"duration":case"html":case"textreplace":case"longtext":case"percentage":return!0;default:return!1}},t.prototype.isFormattedColumn=function(t){switch(t.type){case"datetime":case"date":case"time":case"duration":case"color":case"json":case"number":case"filesize":return!0;default:return!1}},t.prototype.isSelectableColumn=function(t){switch(t.type){case"blob":case"coordinate":case"forceupdate":case"id":case"json":case"order":case"parentid":case"parenttype":case"password":case"token":return!1}return!0},t.prototype.hasLocationProperty=function(t,e){return 0!=(e&t.location)},t.prototype.isEditableColumn=function(t){if(t.readOnly)return!1;switch(t.type){case"date":case"datetime":case"duration":return!1}return!0},t.prototype.isSearchableColumn=function(t){switch(t.type){case"email":case"phone":case"text":case"longtext":case"html":return!0;default:return!1}},t.prototype.getDefaultWeight=function(t){switch(t.type){case"double":case"price":case"bool":case"int":case"percentage":case"color":case"number":case"power":case"current":return.5;case"url":case"enum":case"email":case"text":case"item":case"link":return 1.5;case"longtext":case"html":case"textreplace":return 2;case"date":case"datetime":case"time":case"duration":default:return 1}},t.prototype.getComparators=function(t){switch(t.type){case"dimension":case"weight":case"price":return["=",">","<"];case"date":case"datetime":case"time":case"duration":return[">","<"];default:return["=","!="]}},t.prototype.containsColumn=function(t,e){var r=this.parseRequestColumn(t),n=this.findRequestColumn(r.id,e);if(-1===n)return!1;if(0===r.children.length)return!0;if("string"==typeof e[n])return!1;for(var i=0,o=r.children;i<o.length;i++){var s=o[i];if(!this.containsColumn(s,e[n][r.id]))return!1}return!0},t.prototype.containsDerivedColumns=function(t){for(var e=0,r=t;e<r.length;e++){var n=r[e];if(this.parseRequestColumn(n).children.length>0)return!0}return!1},t.prototype.responseColumnsAvailable=function(t,e,r){for(var n=0,i=e;n<i.length;n++){var o,s=i[n],a=this.parseRequestColumn(s),c=a.children,u=r[t];if(void 0===u)return!1;if(void 0===(o=u[a.id]))return!1;if(c.length>0&&!this.responseColumnsAvailable(o.itemType,c,r))return!1}return!0},t.prototype.copyRequestColumns=function(t){if(!0===t)return!0;for(var e=[],r=0,n=t;r<n.length;r++){var i=n[r];e.push(this.copyRequestColumn(i))}return e},t.prototype.copyRequestColumn=function(t){var e,r=this.parseRequestColumn(t);if(0===r.children.length)return r.id;for(var n=[],i=0,o=r.children;i<o.length;i++){var s=o[i];n.push(this.copyRequestColumn(s))}return(e={})[r.id]=n,e},t.prototype.mergeRequestColumns=function(t,e){if(!0===t)return{merged:!0,difference:[]};if(!0===e)return{merged:!0,difference:!0};for(var r=this.copyRequestColumns(t),n=[],i=0,o=e;i<o.length;i++){var s=o[i],a=this.mergeRequestColumn(s,r);null!==a&&n.push(a)}return{merged:r,difference:n}},t.prototype.mergeRequestColumn=function(t,e){var r,n,i=this.parseRequestColumn(t),o=this.findRequestColumn(i.id,e);if(-1===o)return e.push(t),t;if(0===i.children.length)return null;"string"==typeof e[o]&&(e[o]=((r={})[i.id]=[],r));for(var s=[],a=0,c=i.children;a<c.length;a++){var u=c[a],l=this.mergeRequestColumn(u,e[o][i.id]);null!==l&&s.push(l)}return 0===s.length?null:((n={})[i.id]=s,n)},t.prototype.getRequestColumnId=function(t){if("string"==typeof t)return t;var e;for(e in t);return e},t.prototype.parseRequestColumn=function(t){if("string"==typeof t)return{id:t,children:[]};var e;for(e in t);return{id:e,children:t[e]}},t.prototype.mergeResponseColumns=function(t,e){var r={},n={};for(var i in t)if(void 0!==e[i]){var o=this.mergeResponseColumnMap(t[i],e[i]);r[i]=o.merged,n[i]=o.difference}else r[i]=t[i];for(var i in e)void 0===t[i]&&(r[i]=e[i],n[i]=e[i]);return{merged:r,difference:n}},t.prototype.mergeResponseColumnMap=function(t,e){var r={},n={};for(var i in t)r[i]=t[i];for(var i in e)H(t[i])||(r[i]=e[i],n[i]=e[i]);return{merged:r,difference:n}},t.prototype.isLocalColumnId=function(t){return"__"===t.substring(0,2)},t.prototype.processConfigColumns=function(t){for(var e=[],r=0,n=t;r<n.length;r++){var i=n[r];this.isLocalColumnId(i)||this.processConfigColumn(this.parseConfigColumn(i),e)}return e},t.prototype.parseConfigColumn=function(t){return t.split(":")[0].split(xt)},t.prototype.processConfigColumn=function(t,e){var r,n,i=t[0],o=1===t.length,s=this.findRequestColumn(i,e);o?-1===s&&e.push(i):(-1===s?s=e.push(((r={})[i]=[],r))-1:"string"==typeof e[s]&&(e[s]=((n={})[i]=[],n)),this.processConfigColumn(t.slice(1),e[s][i]))},t.prototype.findRequestColumn=function(t,e){for(var r=0;r<e.length;r++){var n=e[r];if(this.getRequestColumnId(n)===t)return r}return-1},t}(),jt=function(){function t(t,e,r,n,i,o){void 0===o&&(o=!1),this.apiFormatter=t,this.keyService=e,this.requestColumnExpansionFactory=r,this.compilation=n,this.transaction=i,this.breakupByParent=o,this.requests=[]}return t.prototype.finalizeRequest=function(t){for(var e=t.collections.getCollectionsWithFittingItems(),r=t.columns,n=0,i=e;n<i.length;n++){var o=i[n];r.expand(o.columns)}return t.request.columns=r.get(),t},t.prototype.setRequestParent=function(t,e){var r=e.request;return"Void"!==t&&(r.parentType=t,r.parentId={},!0)},t.prototype.run=function(){var t=this.compilation;if(this.breakupByParent)for(var e in t){var r=t[e];for(var n in r)if(!this.keyService.isLocalId(n)){var i=this.initializeRequest();this.extendRequest(r[n],this.setRequestParent(e,i)?+n:null,i),this.requests.push(this.finalizeRequest(i))}}else for(var e in t){r=t[e],i=this.initializeRequest();var o=this.setRequestParent(e,i),s=!1;for(var n in r)this.keyService.isLocalId(n)||(this.extendRequest(r[n],o?+n:null,i),s=!0);s&&this.requests.push(this.finalizeRequest(i))}return this.requests},t.prototype.initializeRequest=function(){return{request:{requestType:"create",items:{},columns:{}},columns:this.requestColumnExpansionFactory.construct(),items:{},collections:this.transaction.collectionHandler.getCollectionMatcher()}},t.prototype.extendRequest=function(t,e,r){var n=r.request,i=r.items;for(var o in t)for(var s in void 0===n.itemType&&(n.itemType=o),void 0===i[o]&&(i[o]={},n.items[o]={}),t[o]){var a=t[o][s],c=a.entry,u=d(this.compilation,[o,c.itemId]),l=n.items[o][c.itemId]={},h=d(this.transaction.tabRequestParameters,[o,c.itemId]);if(null!==e&&(n.parentId[c.itemId]=e),r.columns.expand(c.columns),i[o][s]=c,l.values=this.apiFormatter.formatRequestLocal(a.fields,c.columns.main),l.parameters=h,void 0!==u){var p=l.links={};for(var f in u)for(var m in p[f]=[],u[f])p[f].push(parseInt(m,10));this.extendRequest(u,null,r)}}},t}();!function(t){t.OR="OR",t.AND="AND"}(St||(St={})),function(t){t.EQUALS="=",t.NOT_EQUALS="!=",t.LESS_THAN="<",t.MORE_THAN=">",t.LESS_OR_EQUAL_THAN="<=",t.EQUAL_OR_MORE_THAN=">=",t.IN="IN"}(Rt||(Rt={}));var Bt,At,Qt=function(){function t(t){this.query=t}return t.prototype.parse=function(t){if(void 0===t&&(t=this.query),void 0!==t.linkedTo)return this.parseLinkedToQuery(t.linkedTo,t.query,t.reverse,t.not);if(void 0!==t.custom)return this.parseCustomQuery(t.custom,t.parameters,t.not);if(void 0!==t.search)return this.parseSearchQuery(t.search,t.not);if(void 0!==t.conditions)return this.parseComplexQuery(t.conditions,t.operator,t.not);if(void 0!==t.itemType)return this.parseSubFieldQuery(t.key,t.itemType,t.field,t.query,t.not);if(void 0!==t.key)return"object"==typeof t.query?this.parseSubQuery(t.key,t.query,t.not):this.parseSimpleQuery(t.key,t.value,t.comparator,t.not);var e=a(t);if(null===e)return this.parseEmptyQuery();var r=t[e];return null!==r&&"object"==typeof r&&r.constructor===Object?this.parseSubQuery(e,r,!1):this.parseSimpleQuery(e,r,t.comparator,t.not)},t}(),Vt=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),Ut=function(t){function e(e,r,n){var i=t.call(this,n)||this;return i.columnUtil=e,i.itemType=r,i}return Vt(e,t),e.prototype.parseEmptyQuery=function(){return[]},e.prototype.parseSubQuery=function(t,e,r){var n;return void 0===r&&(r=!1),[(n={},n[t]=this.parse(e),n)]},e.prototype.parseSubFieldQuery=function(t,e,r,n,i){return[]},e.prototype.parseSearchQuery=function(t,e){return[]},e.prototype.parseCustomQuery=function(t,e,r){return void 0===r&&(r=!1),[]},e.prototype.parseSimpleQuery=function(t,e,r,n){return[t]},e.prototype.parseLinkedToQuery=function(t,e,r,n){return void 0===e&&(e={}),void 0===r&&(r=!1),void 0===n&&(n=!1),this.columnUtil.getColumnsFromLink(t,this.itemType)},e.prototype.parseComplexQuery=function(t,e,r){return this.parseConditions(t)},e.prototype.parseConditions=function(t){var e=this;return t.reduce(function(t,r){return t.concat(e.parse(r))},[])},e}(Qt),Nt=function(){function t(t,e,r,n,i){this.collectionEntryService=t,this.columnUtil=e,this.requestColumnExpansionFactory=r,this.transaction=i,this.collectionChanges={},this.entries=n.construct(this.transaction)}return t.prototype.setCollectionChanges=function(t,e,r){void 0===this.collectionChanges[t]&&(this.collectionChanges[t]={}),this.collectionChanges[t][e]=r},t.prototype.getCollectionChanges=function(t,e){if(void 0!==this.collectionChanges[t])return this.collectionChanges[t][e]},t.prototype.createCollectionEntry=function(t,e){var r=this.transaction.core.collectionEntryFactory.construct(t,e);this.entries.add(r),this.setCollectionChanges(r.itemType,r.query.string,[]);for(var n=new vt(this.transaction.core.apiRequestService,this.transaction.core.queryMatcherFactory,this.transaction,function(t){return t===r.itemType?[r]:[]}),i=0,o=this.transaction.getTransactionChain();i<o.length;i++)for(var s=0,a=o[i].itemHandler.entries.getByItemType(r.itemType);s<a.length;s++){var c=a[s],u=this.transaction.getItemChangesRecursively(c.id,!1);n.expand(c,u)}return n.removeFromAndAddToCollections(),r},t.prototype._addItemEntriesToCollectionChanges=function(t,e,r,n){if(0!==e.length){var i=this.getCollectionChanges(t.itemType,t.query.string);if(void 0!==i){for(var o=[],s=0,a=e;s<a.length;s++){var c=a[s];-1!==i.indexOf(c)||r(c)||(i.push(c),o.push(c))}return this.handleAddedItemEntriesCallback(t,o,n)}}},t.prototype.removeItemEntriesFromCollectionChanges=function(t,e,r){if(void 0===r&&(r=!1),0===e.length)return[];var n=this.getCollectionChanges(t.itemType,t.query.string);if(void 0!==n){var i=this.collectionEntryService.filterArray(n,function(t){return!c(t.itemId,e)});return this.handleRemovedItemEntriesCallback(t,i,r)}},t.prototype.expandColumnsWithQueryColumns=function(t,e,r){var n=new Ut(this.columnUtil,t,r);if(e.queryColumns=n.parse(),!0!==e.columns){var i=this.requestColumnExpansionFactory.construct();i.expandWithRequestColumns(t,e.columns),i.expandWithRequestColumns(t,e.queryColumns),e.columns=i.get()[t]}},t}(),Wt=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),Yt=function(t){function e(e,r,n,i,o,s,a,c,u,l,h,p,d,f){var m=t.call(this,a,d,n,s,f)||this;return m.columnSubsetCacheFactory=e,m.requestBufferManager=r,m.columnExpansionFactory=i,m.apiRequestService=o,m.collectionMatcherFactory=c,m.errorHandler=u,m.itemHandler=l,m.promiseService=h,m.queryService=p,m.transaction=f,m}return Wt(e,t),e.prototype.fetchItemEntriesByQuery=function(t,e,r){var n=this;return this.fetchCollectionEntry(t,new K({columns:r.columns,parent:r.parent,query:e})).then(function(t){return n.collectionChanges[t.itemType][t.query.string]},this.errorHandler.reject)},e.prototype.getCollectionMatcher=function(){var t=this;return this.collectionMatcherFactory.construct(this.transaction,function(e){return t.entries.getByItemType(e)})},e.prototype.fetchCollectionEntry=function(t,e){var r=this.collectionEntryService.createQuery(e);this.expandColumnsWithQueryColumns(t,e,r.object);var n=this.columnSubsetCacheFactory.construct(e.columns);return this.fetchCollectionData(t,n,e,r)},e.prototype.fetchLinkedCollectionEntries=function(t,e,r,n){var i={};S(e)&&(e=e());for(var o=0,s=e;o<s.length;o++){var a=s[o],c=this.collectionEntryService.cloneOptions(n,{itemType:t,itemId:a}),u=this.collectionEntryService.createQuery(c);this.expandColumnsWithQueryColumns(r,c,u.object);var l=this.columnSubsetCacheFactory.construct(c.columns);i[a]=this.fetchCollectionData(r,l,c,u)}return this.promiseService.all(i)},e.prototype.extendCollectionEntry=function(t,e){var r,n,i=t.extendQuery(e).object,o=this.queryService.addAndCondition(i,this.queryService.createNotIn(this.getCollectionChanges(t.itemType,t.query.string).map(function(t){return t.itemId})));return this.expandColumnsWithQueryColumns(t.itemType,t.options,i),n=null!==t.options.limit?this.apiRequestService.requestSkeleton({requestType:"query",itemType:t.itemType,columns:(r={},r[t.itemType]=t.options.columns,r),query:i,limit:t.options.limit}):this.requestBufferManager.fetchByQuery(t.itemType,o,t.options.columns),t.promise=n,n.then(function(){delete t.promise},this.errorHandler.reject),n.then(function(){return t})},e.prototype.expandCollectionEntries=function(t,e,r,n){var i=this;if(0===n.length)return this.promiseService.when(r);var o=[];for(var s in r){var a=r[s].entry;o.push(a.parent.itemId)}return this.itemHandler.fetchLinkedItemEntriesData(t,o,e,null,n).then(function(t){for(var s=i.columnExpansionFactory.construct(e,n,t.fetchColumnsObject()),a=0,c=o;a<c.length;a++){var u=c[a];r[u].entry.expandColumns(s)}return r})},e.prototype.extendCollectionEntries=function(t,e,r,n,i){if(!s(i))return this.promiseService.when();var o=[],a=[];for(var c in r.queryParams=n(r.queryParams),i){var u=i[c].entry;u.extendQuery(n),o.push(u.parent.itemId),a=a.concat(this.getCollectionChanges(u.itemType,u.query.string).map(function(t){return t.itemId}))}return this.itemHandler.fetchLinkedItemEntriesData(t,o,e,this.queryService.addAndCondition(this.collectionEntryService.createQuery(r).object,this.queryService.createNotIn(a)),r.columns).then(function(){},this.errorHandler.reject)},e.prototype.addItemEntriesToCollectionChanges=function(e,r,n){void 0===n&&(n=!1),t.prototype._addItemEntriesToCollectionChanges.call(this,e,r,function(t){return t.isLocal()},n)},e.prototype.expandCollectionEntry=function(t,e){var r=this,n=t.columns.mergeRequestColumns(e),i=n.merged,o=n.difference;if(!0!==o&&0===o.length)return this.promiseService.when(t);var s=t.itemType;return(null!==t.options.limit?this.apiRequestService.requestSkeleton({requestType:"query",itemType:s,columns:i,query:t.query.object,limit:t.options.limit}):this.requestBufferManager.fetchByQuery(t.itemType,[t.query.object,t.query.string],i)).then(function(e){var n=r.columnExpansionFactory.construct(s,i,e.fetchColumnsObject());return t.expandColumns(n),n},this.errorHandler.reject)},e.prototype.handleAddedItemEntriesCallback=function(t,e){e.length},e.prototype.handleRemovedItemEntriesCallback=function(t,e){e.length},e.prototype.fetchCollectionData=function(t,e,r,n){var i,o=this,s=this.entries.getByQuery(t,n);if(null!==s&&e.run(s.columns))return this.promiseService.when(s);var a,c=null===s;if(null===s&&(s=this.createCollectionEntry(t,r)),null!==r.limit){var u,l=((i={})[t]=r.columns,i);a=this.apiRequestService.requestSkeleton({requestType:"query",itemType:t,columns:l,query:r.query,limit:r.limit}).then(function(t){return u=t,o.transaction.processResponse(u,l,!1,!1)},this.errorHandler.reject).then(function(){return u},this.errorHandler.reject)}else a=this.requestBufferManager.fetchByQuery(t,[n.object,n.string],e.requestColumns);return a.then(function(r){if(c)s.columns=o.transaction.core.columnSetFactory.construct(t,e.requestColumns,r.fetchColumnsObject());else{var n=o.columnExpansionFactory.construct(t,e.requestColumns,r.fetchColumnsObject());s.expandColumns(n)}return s})},e}(Nt),Jt=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),Kt=function(t){function e(e,r,n,i,o,s,a,c,u,l,h,p){var d=t.call(this,a,c,u,s,o,h,l,p)||this;return d.requestBufferManager=e,d.queryParserFactory=r,d.queryService=n,d.columnSubsetCacheFactory=i,d.transaction=p,d.itemChanges={},d}return Jt(e,t),e.prototype.createItemEntry=function(e){var r=t.prototype.createItemEntry.call(this,e);return this.itemChanges[r.id]=e.fields,r},e.prototype.processItemEntryChanges=function(t,e,r,n,i){var o=t.entry,s=t.changes;void 0===this.itemChanges[o.id]&&(this.itemChanges[o.id]={}),null!==s.expandedColumns&&(o.columns=s.expandedColumns.merged);var a=this.apiFormatter.copyFields(this.itemChanges[o.id],{},o.columns.main);return this.apiFormatter.copyFields(s.fields,this.itemChanges[o.id],o.columns.main),void 0!==s.fields.id&&(o.itemId=s.fields.id),a},e.prototype.copyTransactionItemEntryChanges=function(t,e){return this.apiFormatter.copyFields(t.changes,{},e.columns.main)},e.prototype.fetchItemEntry=function(t,e,r){var n=this;return r.columns=this.expandColumnsWithCollectionColumns(t,r.columns),this.fetchItemEntryData(t,e,this.columnSubsetCacheFactory.construct(r.columns)).then(function(){return n.entries.get(t,e)},this.errorHandler.reject)},e.prototype.fetchItemEntriesByQuery=function(t,e,r){var n=this;return r.columns=this.expandColumnsWithCollectionColumns(t,r.columns),this.requestBufferManager.fetchByQuery(t,this.queryParserFactory.construct(this.queryService.addParentCondition(e,r.parent)).parse(),r.columns).then(function(e){for(var r=[],i=0,o=e.links[t];i<o.length;i++){var s=o[i],a=n.entries.get(t,s);void 0!==a&&r.push(a)}return r},this.errorHandler.reject)},e.prototype.fetchItemEntries=function(t,e,r){var n=this;r.columns=this.expandColumnsWithCollectionColumns(t,r.columns);for(var i=this.columnSubsetCacheFactory.construct(r.columns),o=[],s=0,a=e;s<a.length;s++){var c=a[s];o.push(this.fetchItemEntryData(t,c,i))}return this.promiseService.all(o).then(function(){for(var r=[],i=0,o=e;i<o.length;i++){var s=o[i];r.push(n.entries.get(t,s))}return r},this.errorHandler.reject)},e.prototype.fetchLinkedItemEntriesData=function(t,e,r,n,i){return null===n?this.requestBufferManager.fetchByIds(t,e,i):this.requestBufferManager.fetchByQuery(r,this.queryParserFactory.construct(this.queryService.addAndCondition(n,{linkedTo:t,query:{id:e}})).parse(),i)},e.prototype.processApiResponse=function(t,e,r,n,i,o){var s=this.entries.get(r,n),a=e.fetchObject(r,n);if(void 0===a)throw new Error("Fields not found in response for "+r+":"+n);void 0===s?t.setItemCreated(n,a,i):t.setItemUpdated(s,a,o.run(s.columns))},e.prototype.fetchItemEntryData=function(t,e,r){var n=this.entries.get(t,e);return void 0!==n&&r.run(n.columns)?this.promiseService.when():this.requestBufferManager.fetchById(t,e,r.requestColumns).then(function(){},this.errorHandler.reject)},e}(ut),zt=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),Gt=function(t){function e(e,r,n,i,o,s,a,c,u,l,h,p,d,f,m,y,v,g,C,I,E,F,S,R,q,T,w,b,H,M,x,k,D,O){var _=t.call(this,r,n,i,o,s,a,c,u,l,h,p,d,f,m,y,v,g,I,E,F,S,R,q,T,w,b,H,M,x,k,D,C,O)||this;return _.changesProcessorFactory=e,_.parent=null,_.itemHandler=new Kt(i,k,D,R,y,g,q,C,T,f,o,_),_.collectionHandler=new Yt(R,i,o,E,I,m,M,x,y,_.itemHandler,g,D,q,_),_}return zt(e,t),e.prototype.getServerCache=function(){return this},e.prototype.processResponse=function(t,e,r,n,i){void 0===r&&(r=!1),void 0===n&&(n=!1),void 0===i&&(i=this.core.changesDeltaFactory.construct());var o=t.fetchColumnsObject();for(var s in t.items){var a=void 0;a=s===t.itemType?this.core.columnSetFactory.construct(s,e[s],o):this.core.columnSetFactory.constructFromResponse(s,o);var c=this.core.columnExpansionFactory.construct(s,!!a.requestColumnsTrue||a.request,o);for(var u in t.items[s])this.itemHandler.processApiResponse(i,t,s,Number(u),a,c)}return this.applyChangesDelta(i,r,n)},e.prototype.applyChangesFromParent=function(t,e,r){var n=this;for(var i in void 0===e&&(e=!1),void 0===r&&(r=!1),t.updated)this.itemHandler.processItemEntryChanges(t.updated[i],r);for(var o in t.deleted)for(var s=0,a=t.deleted[o];s<a.length;s++){var c=a[s];this.itemHandler.entries.clear(c),delete this.itemHandler.itemChanges[c.id]}new vt(this.apiRequestService,this.queryMatcherFactory,this,function(t){return n.collectionHandler.entries.getByItemType(t)}).processDelta(t).removeFromAndAddToCollections(r);for(var u=0,l=this.children;u<l.length;u++){l[u].applyChangesFromParent(t,e,r)}},e.prototype.getLinkFieldsByParent=function(t,e){var r=this.linkTreeService.get()[t.itemType][e],n={};if(void 0===r)throw new Error("Non existing link between '"+t.itemType+"'->'"+e+"'");return r.type===D.DIRECT?n[r.field]=t.itemId:(n.itemtype=t.itemType,n.item=t.itemId),n},e.prototype.getParent=function(t,e,r){return this.getParentFromFields(t,this.itemHandler.itemChanges[t.id])},e.prototype.getItemChangesRecursively=function(t,e){void 0===e&&(e=!0);var r=this.itemHandler.itemChanges[t],n=this.getLocalItemEntry(t);if(void 0!==r&&void 0!==n)return e?this.apiFormatter.copyFields(r,{},n.columns.main):r;if(void 0===n)throw new Error("No local entry found");throw new Error("No local fields found for ItemEntry with ItemType '"+n.itemType+"'")},e.prototype.getLocalItemEntryChangesTuple=function(t){var e=this.getLocalItemEntry(t);if(void 0===e)throw new Error("Tried to get a local ItemEntry with entryId '"+t+"' but couldn't find it");return{entry:e,changes:this.itemHandler.itemChanges[t]}},e.prototype.getCollectionChangesRecursively=function(t){var e=this.getLocalCollectionEntry(t);if(void 0!==e){var r=this.collectionHandler.getCollectionChanges(e.itemType,e.query.string);return void 0===r&&(r=[],this.collectionHandler.setCollectionChanges(e.itemType,e.query.string,r)),r}throw new Error("No local collection items found")},e.prototype.invalidateCache=function(){this.itemHandler.entries.forEach(function(t){return t.queueReload()}),this.collectionHandler.entries.forEach(function(t){return t.queueReload()})},e.prototype.applyChangesFromChild=function(t,e,r){return this.changesProcessorFactory.construct(t,e,r).execute()},e.prototype.applyChangesDelta=function(e,r,n){var i=this;return void 0===r&&(r=!0),void 0===n&&(n=!1),0!==e.created.length||s(e.updated)||s(e.deleted)?this.fetchUpdatedDerivedValuesFromDelta(e).then(function(){var o=t.prototype._applyChangesDelta.call(i,e),s=o.result,a=o.internalChangesDelta,c=o.rollbackFunctions;for(var u in e.deleted)for(var l=function(t){i.itemHandler.entries.clear(t);var r=i.itemHandler.itemChanges[t.id];delete e.updated[t.id],delete i.itemHandler.itemChanges[t.id],a.setItemDeleted(t),c.push(function(e){e.setItemUpdated(t,r)})},h=0,p=e.deleted[u];h<p.length;h++){l(p[h])}new vt(i.apiRequestService,i.queryMatcherFactory,i,function(t){return i.collectionHandler.entries.getByItemType(t)}).processDelta(a).removeFromAndAddToCollections(n);for(var d=0,f=i.children;d<f.length;d++){f[d].applyChangesFromParent(a,r,n)}return s}):this.promiseService.when({created:[],rollback:Je})},e.prototype.getLocalItemEntry=function(t){var e=this.itemHandler.entries.getByEntryId(t);if(void 0!==e)return e},e.prototype.getLocalItemEntryByItemId=function(t,e){var r=this.itemHandler.entries.get(t,e);if(void 0!==r)return r},e.prototype.getLocalCollectionEntryByQueryString=function(t,e){var r=this.collectionHandler.entries.getByQueryString(t,e);if(null!==r)return r},e.prototype.getLocalCollectionEntry=function(t){var e=this.collectionHandler.entries.getByEntryId(t);if(void 0!==e)return e},e.prototype.getChangesFromItemChanges=function(t){return t},e}(pt),Xt=function(){function t(t,e){this.queryMatcherFactory=t,this.transaction=e,this.entries={},this.entriesByEntryId={}}return t.prototype.getByEntryId=function(t){return this.entriesByEntryId[t]},t.prototype.some=function(t){var e=this.entries;for(var r in e)for(var n in e[r])if(t(e[r][n]))return!0;return!1},t.prototype.getByItemType=function(t){var e=this.entries[t],r=[];if(void 0===e)return r;for(var n in e)r.push(e[n]);return r},t.prototype.getByQuery=function(t,e){var r=this.entries[t],n=[];if(void 0===r)return n;for(var i in r){var o=r[i];this.matchQuery(o,e)&&n.push(o)}return n},t.prototype.getLocalByQuery=function(t,e){var r=this.entries[t],n=[];if(void 0===r)return n;for(var i in r){var o=r[i];o.isLocal()&&(this.matchQuery(o,e)&&n.push(o))}return n},t.prototype.getByParent=function(t,e,r){var n=this.entries[r],i=[];if(void 0===n)return i;for(var o in n){var s=n[o],a=this.transaction.getParent(s);null!==a&&(a.itemType===t&&a.itemId==e&&i.push(s))}return i},t.prototype.batchGetLocalByParent=function(t,e,r,n){for(var i=this.entries[r],o={},s=0,a=e;s<a.length;s++){o[a[s]]=[]}if(void 0===i)return o;for(var c in i){var u=i[c],l=this.transaction.getParent(u);null!==l&&(l.itemType===t&&void 0!==o[l.itemId]&&u.isLocal()&&(null===n||this.matchQuery(u,n))&&o[l.itemId].push(u))}return o},t.prototype.forEach=function(t){var e=this.entries;for(var r in e)for(var n in e[r])t(e[r][n])},t.prototype.toArray=function(){var t=this.entries,e=[];for(var r in t)for(var n in t[r])e.push(t[r][n]);return e},t.prototype.add=function(t){var e=this.entries,r=t.itemType;return void 0===e[r]&&(e[r]={}),this.entriesByEntryId[t.id]=t,e[r][t.itemId]=t},t.prototype.get=function(t,e){return void 0===this.entries[t]?void 0:this.entries[t][e]},t.prototype.contains=function(t,e){return void 0!==this.entries[t]&&void 0!==this.entries[t][e]},t.prototype.updateItemId=function(t,e){var r=this.entries[t.itemType];return delete r[e],r[t.itemId]=t},t.prototype.clear=function(t){return void 0===t?(this.entries={},this.entriesByEntryId={},!0):this.clearByItemId(t.itemType,t.itemId)},t.prototype.clearByItemId=function(t,e){var r=this.entries[t];return void 0!==r&&(!!r.hasOwnProperty(e)&&(delete this.entriesByEntryId[r[e].id],delete r[e]))},t.prototype.matchQuery=function(t,e){var r=this.transaction.getLocalItemEntryChangesTuple(t.id);return!0===this.queryMatcherFactory.construct(t.itemType,this.transaction instanceof Gt?r.changes:r.changes.changes,this.transaction.getParent(t)).matchQuery(e.object)},t}(),Zt=function(){function t(t,e,r){this.authInterface=t,this.keyService=e,this.linkTreeService=r}return t.prototype.matchParent=function(t,e){return null===t&&null===e||!(null===t&&null!==e||null!==t&&null===e)&&(t.itemType===e.itemType&&t.itemId==e.itemId)},t.prototype.getLinkFieldsByParent=function(t,e){var r=this.linkTreeService.get()[t.itemType][e];if(void 0===r)throw new Error("Non existing link between '"+t.itemType+"'->'"+e+"'");var n={};return r.type===D.DIRECT?n[r.field]=t.itemId:(n.itemtype=t.itemType,n.item=t.itemId),n},t.prototype.getParentByFields=function(t,e,r){var n=this.linkTreeService.get()[t][e.itemType];if(void 0===n)throw new Error("Non existing link between '"+t+"'->'"+e.itemType+"'");var i={};return n.type===D.DIRECT?(i.itemType=t,i.itemId=r[n.field]):(i.itemType=r.itemtype,i.itemId=r.item),i},t.prototype.getDisplayName=function(t,e){switch(t.itemType){case"Contact":return"bedrijf"===e.type?e.bedrijf:this.getFullName(e.voornaam,e.tussenvoegsel,e.naam);case"Medewerker":case"Person":return this.getFullName(e.voornaam,e.tussenvoegsel,e.achternaam);default:return e[this.getTitleField(t.itemType)]}},t.prototype.processOptions=function(t){return new B(t)},t.prototype.createUnfoundRemoteItemError=function(){return{message:"The requested item could not be found / your current permissions are not sufficient"}},t.prototype.createUnfoundLocalItemError=function(t){return{message:"A local item of type "+t+" could not be found"}},t.prototype.createExistingLocalItemError=function(t){return{message:"A local item of type "+t+" not be created, the ID is already in use"}},t.prototype.createLocalConversionMap=function(t,e,r,n){void 0===r&&(r=!1);var i=n.links[t][0],o={};return o[t]={},o[t][i]=e,r&&this.expandLocalConversionMap(t,i,n,o),o},t.prototype.expandLocalConversionMap=function(t,e,r,n){var i=r.items[t][e].links;for(var o in i){var s=i[o];void 0===n[o]&&(n[o]={});for(var a=0,c=s;a<c.length;a++){var u=c[a];n[o][u]=this.keyService.getLocalId(),this.expandLocalConversionMap(o,u,r,n)}}},t.prototype.expandConversionMap=function(t,e,r){var n,i=t.itemType,o=t.itemId;return void 0===e[i]&&(e[i]={}),void 0!==(n=e[i])[o]?n[o]:(void 0===r&&(r=this.keyService.getLocalId()),n[o]=r)},t.prototype.batchExpandConversionMap=function(t,e){for(var r=0,n=t;r<n.length;r++){var i=n[r];this.expandConversionMap(i,e)}return e},t.prototype.getConversionValue=function(t,e,r){if(void 0!==r[t])return r[t][e]},t.prototype.getFullName=function(t,e,r){return void 0===t&&(t=""),void 0===e&&(e=""),void 0===r&&(r=""),t.trim().concat(" ",e).trim().concat(" ",r).trim()},t.prototype.getTitleField=function(t){switch(t){case"Exemplaar":return"serienummer";case"Factuur":return"nummer";case"Files":return"friendlyname";case"Functie":case"Standaardfunctie":return"naamintern";case"Voorraadmutatie":return"omschrijving";case"Barcode":return"code";case"Betaalmiddel":case"Betalingsconditie":case"Briefpapier":case"TaxClass":case"TaxSchema":case"Condition":case"Factuurmoment":case"Functiegroep":case"Grootboek":case"Inhuur":case"Inhuurgroep":case"Inhuurmateriaal":case"Materiaal":case"MateriaalCat":case"Medewerkertarief":case"Notitie":case"Planningmateriaal":case"Project":case"Staffelgroep":case"Subproject":case"Taak":case"Tag":case"Template":case"Tijd":case"Titel":case"Type":case"Voertuig":return"naam";default:return"displayname"}},t.prototype.getLocalDefaultValues=function(){return{permissions:"7",creator:this.authInterface.getUserId(),created:n()}},t}(),$t=function(){function t(){this.separator=":"}return t.prototype.getSingleKey=function(t,e){return t+this.separator+e},t.prototype.getCssKey=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return t.join("_")},t.prototype.parseStateKey=function(t){return"new-"===(t=t.toString()).substring(0,"new-".length)?{type:"new",template:t.substring("new-".length)}:"dup-"===t.substring(0,"dup-".length)?{type:"duplicate",itemId:+t.substring("dup-".length)}:null},t.prototype.getDuplicateStateKey=function(t){return"dup-"+t},t.prototype.getNewStateKey=function(t){return"new-"+t},t.prototype.getLocalId=function(){return+("-1"+this.getRandomString())},t.prototype.getLocalDuplicateId=function(){return+("-2"+this.getRandomString())},t.prototype.getRandomString=function(){return(""+Math.random()).split(".")[1].substr(0,8)},t.prototype.isLocalId=function(t){return void 0!==t&&(this.isNewId(t)||this.isDuplicateId(t))},t.prototype.isNewId=function(t){return"new-"===t||"-1"===(""+t).substring(0,"-1".length)},t.prototype.isDuplicateId=function(t){return"dup-"===t||"-2"===(""+t).substring(0,"-2".length)},t}(),te=function(){function t(t,e,r,n){this.apiRequestService=t,this.errorHandler=e,this.keyService=r,this.promiseService=n,this.lockItems={},this.promises={}}return t.prototype.getLocks=function(){return this.lockItems},t.prototype.hasLock=function(t){var e=this.lockItems;for(var r in e)for(var n in e[r]){var i=e[r][n];if(!i.isForeign&&i.id==t)return!0}return!1},t.prototype.isLocked=function(t){var e=this.getValue(t,this.lockItems);return void 0!==e&&e.isForeign},t.prototype.getMessage=function(t){var e=this.getValue(t,this.lockItems);if(void 0!==e&&e.isForeign)return e.message},t.prototype.fetchCachedLock=function(t){var e=this.getValue(t,this.lockItems);if(void 0!==e)return this.promiseService.when(e);var r=this.getValue(t,this.promises);return void 0!==r?r:this.promiseService.when()},t.prototype.fetchLock=function(t){var e=this,r=this.errorHandler;return this.fetchCachedLock(t).then(function(r){return void 0!==r?r:e.requestLock(t)},r.reject).then(function(t){return t.isForeign?r.reject(t.message):t.token},r.reject)},t.prototype.requestLock=function(t){var e=this,r=t.itemType,n=t.itemId,i=this.apiRequestService.create("Locktoken",this.keyService.getLocalId(),{itemtype:r,item:n}).then(function(i){return delete e.promises[r][n],e.setValue(t,i.fetchObject("Locktoken",i.links.Locktoken[0]),e.lockItems)},function(i){return delete e.promises[r][n],301===i.code?e.setValue(t,{isForeign:!0,message:i.message},e.lockItems):e.errorHandler.reject(i)});return this.setValue(t,i,this.promises)},t.prototype.deleteLock=function(t){var e=this;return this.fetchCachedLock(t).then(function(r){if(void 0!==r){if(!r.isForeign)return e.apiRequestService.delete("Locktoken",[r.id]).then(function(){e.clearLock(t)},e.errorHandler.reject);e.clearLock(t)}},this.errorHandler.reject)},t.prototype.clearLock=function(t){var e=this.lockItems[t.itemType];return void 0!==e&&delete e[t.itemId]},t.prototype.getValue=function(t,e){var r=t.itemType;if(void 0!==e[r])return e[r][t.itemId]},t.prototype.setValue=function(t,e,r){return p(r,[t.itemType,t.itemId],[{},e])},t}(),ee={},re=function(){function t(t){this.transaction=t,this.parentMap={},this.destination={}}return t.prototype.process=function(){if(void 0===this.transaction.rootItem)throw new Error("A TransactionCache rootItem is required for ModuleChangesCompilation");return this.parentMap=this.createParentMap(),this.processItems(this.transaction.rootItem.itemType,[this.transaction.rootItem],{}),{itemType:this.transaction.rootItem.itemType,itemId:this.transaction.rootItem.itemId,items:this.destination}},t.prototype.createParentMap=function(){var t=this,e={};return this.transaction.itemHandler.entries.forEach(function(r){var n=r.itemType,i=t.transaction.getParent(r);if(null!==i){var o=i.itemType,s=i.itemId;void 0===e[o]&&(e[o]={}),void 0===e[o][s]&&(e[o][s]={}),void 0===e[o][s][n]&&(e[o][s][n]=[]),e[o][s][n].push(r)}}),e},t.prototype.processItems=function(t,e,r){void 0===this.destination[t]&&(this.destination[t]={}),void 0===r[t]&&(r[t]=[]);for(var n=0,i=e;n<i.length;n++){var o=i[n],s=o.itemId;void 0===this.destination[t][s]&&(r[t].push(s),this.destination[t][s]=this.processItem(o))}},t.prototype.processItem=function(t){var e=t.itemType,r=t.itemId,n=this.getItemsByParent(e,r),i=this.transaction.collectionHandler.entries.getCollectionsByParent(e,r),o=this.transaction.itemHandler.formatRequest(t),a={};for(var c in n)this.processItems(c,n[c],a);for(var u=0,l=i;u<l.length;u++){var h=l[u];null===h.options.query&&this.processItems(h.itemType,this.transaction.getCollectionChangesRecursively(h.id),a)}var p=s(o),d=s(a);return p&&d?{values:o,links:a}:p?{values:o}:d?{links:a}:ee},t.prototype.getItemsByParent=function(t,e){var r=this.parentMap[t];return void 0===r?{}:void 0===r[e]?{}:r[e]},t}(),ne="maybe",ie=function(){function t(t,e,r,n){void 0===n&&(n=null),this.apiFormatter=t,this.itemType=e,this.fields=r,this.parent=n}return t.prototype.compareValues=function(t,e){return n.isMoment(e)?this.apiFormatter.compareMomentObjects(e,t):n.isDuration(e)?this.apiFormatter.compareDurations(e,t):e==t},t.prototype.matchQuery=function(t){if(void 0!==t.search)return ne;if(void 0!==t.custom)return ne;if(void 0!==t.linkedTo)return this.matchLinkedToQuery(t);if(void 0!==t.query)return ne;if(void 0!==t.conditions)return this.matchComplexQuery(t);if(void 0!==t.key)return this.matchSimpleQuery(this.fields[t.key],t);if(!s(t))return!0;throw new Error("queryMatcher: Unsupported query! Parsed?")},t.prototype.matchLinkedToQuery=function(t){if(t.reverse)return ne;var e,r=this.parent;return(e=null!==r&&(t.linkedTo===r.itemType&&this.matchSimpleQuery(r.itemId,t.query)))===ne?ne:t.not?!e:!!e},t.prototype.matchComplexQuery=function(t){var e,r,n=t.conditions;switch(t.operator){case"AND":e=!0,r=!1;break;case"OR":e=!1,r=!0;break;default:throw new Error("queryMatcher: Unsupported operator")}for(var i=0,o=n;i<o.length;i++){var s=o[i],a=this.matchQuery(s);if(a===r)return t.not?!r:r;a===ne&&(e=ne)}return e===ne?ne:t.not?!e:e},t.prototype.matchSimpleQuery=function(t,e){var r=e.key,i=e.value;if(!s(e))return!0;if(void 0===t)return console.warn("Required field",r,"not found for",this.itemType),ne;switch("NOW"===i&&(i=n()),e.comparator){case"=":return this.compareValues(t,i);case"!=":return!this.compareValues(t,i);case"<":return t<i;case"<=":return t<=i;case">":return t>i;case">=":return t>=i;case"IN":var o=c(t,i);return e.not?!o:o;default:throw new Error("queryMatcher: Unsupported comparator: "+e.comparator+" in query "+e)}},t}(),oe=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();!function(t){t[t.OBJ=0]="OBJ",t[t.STR=1]="STR",t.SEP=":"}(At||(At={}));var se=Object.keys(Rt).map(function(t){return Rt[t]}),ae=((Bt={})[Rt.EQUALS]=Rt.NOT_EQUALS,Bt[Rt.NOT_EQUALS]=Rt.EQUALS,Bt[Rt.MORE_THAN]=Rt.LESS_OR_EQUAL_THAN,Bt[Rt.LESS_THAN]=Rt.EQUAL_OR_MORE_THAN,Bt[Rt.LESS_OR_EQUAL_THAN]=Rt.MORE_THAN,Bt[Rt.EQUAL_OR_MORE_THAN]=Rt.LESS_THAN,Bt[Rt.IN]=Rt.IN,Bt),ce=function(t){function e(e,r){var n=t.call(this,e)||this;return n.parameters=r,n}return oe(e,t),e.prototype.parseEmptyQuery=function(){return[{},"{}"]},e.prototype.parseSubQuery=function(t,e,r){void 0===r&&(r=!1);var n=this.parse(e);return[{key:t,query:n[At.OBJ],not:r},"[sub"+At.SEP+t+At.SEP+n[At.STR]+At.SEP+r+"]"]},e.prototype.parseSubFieldQuery=function(t,e,r,n,i){void 0===t&&(t=""),void 0===e&&(e=""),void 0===r&&(r=""),void 0===i&&(i=!1);var o=this.parse(n);return[{key:t,itemType:e,field:r,query:o[At.OBJ],not:i},"[subField"+At.SEP+t+At.SEP+e+At.SEP+r+At.SEP+o[At.STR]+At.SEP+i+"]"]},e.prototype.parseSearchQuery=function(t,e){return void 0===e&&(e=!1),[{search:(t=this.formatValue(t))[At.OBJ],not:e},"[search"+At.SEP+t[At.STR]+At.SEP+e+"]"]},e.prototype.parseCustomQuery=function(t,e,r){if(void 0===r&&(r=!1),void 0===e)return[{custom:t,not:r},"["+t+At.SEP+r+"]"];var n=this.parseCustomParameters(e);return[{custom:t,parameters:n[At.OBJ],not:r},"["+t+At.SEP+n[At.STR]+At.SEP+r+"]"]},e.prototype.parseCustomParameters=function(t){for(var e=Object.keys(t).sort(),r={},n="",i=0;i<e.length;i++){var o=e[i],s=this.formatValue(t[o]);r[o]=s[At.OBJ],i>0&&(n+=At.SEP),n+=s[At.STR]}return[r,n]},e.prototype.parseSimpleQuery=function(t,e,r,n){if(void 0===n&&(n=!1),e=this.formatValue(e),void 0===r&&(r=Array.isArray(e[At.OBJ])?Rt.IN:Rt.EQUALS),-1===se.indexOf(r))throw new Error("Unknown comparator '"+r+"', it might be that the backend supports it but the frontend doesn't !");n&&(r=ae[r]);var i=r===Rt.IN&&n,o=[{key:t,value:e[At.OBJ],comparator:r,not:i},"["+r+At.SEP+t+At.SEP+e[At.STR]+"]"];return i&&(o[1]=o[1].slice(0,-1),o[1]+=At.SEP+n+"]"),o},e.prototype.parseLinkedToQuery=function(t,e,r,n){void 0===e&&(e={}),void 0===r&&(r=!1),void 0===n&&(n=!1);var i=this.parse(e);return[{linkedTo:t,query:i[At.OBJ],reverse:r,not:n},"[linkedTo"+At.SEP+t+At.SEP+i[At.STR]+At.SEP+r+At.SEP+n+"]"]},e.prototype.parseComplexQuery=function(t,e,r){void 0===e&&(e=St.AND),void 0===r&&(r=!1),e=e.toUpperCase();var n=this.parseConditions(t);return[{conditions:n[At.OBJ],operator:e,not:r},"["+e+n[At.STR]+At.SEP+r+"]"]},e.prototype.parseConditions=function(t){for(var e=this,r=[],n=[],i="",o=0,s=t;o<s.length;o++){var a=s[o];r.push(this.parse(a))}for(var c=0,u=r=r.sort(function(t,r){return e.compareParsedQueries(t,r)});c<u.length;c++){var l=u[c];n.push(l[At.OBJ]),i+=l[At.STR]}return[n,i]},e.prototype.formatValue=function(t){var e;if("string"==typeof t&&"&"===t.charAt(0)){var r=t.substring(1);if(void 0===(t=this.parameters[r]))throw new Error("queryParser: Undefined template parameter '"+r+"'");return[e=this.processValue(t),r+">"+t]}return[e=this.processValue(t),""+e]},e.prototype.processValue=function(t){return Array.isArray(t)?t.slice().sort():n.isMoment(t)?n(t):n.isDuration(t)?n.duration(t):t},e.prototype.compareParsedQueries=function(t,e){return t[At.STR]===e[At.STR]?0:t[At.STR]>e[At.STR]?1:-1},e}(Qt),ue=function(){function t(){}return t.prototype.addAndCondition=function(t,e){return void 0===t.conditions||t.operator===St.OR?{conditions:[t,e]}:{conditions:t.conditions.concat(e)}},t.prototype.addOrCondition=function(t,e){return t.operator===St.OR?{conditions:t.conditions.concat(e)}:{conditions:[t,e],operator:St.OR}},t.prototype.addParentCondition=function(t,e){var r;return null===e?t:(r={linkedTo:e.itemType,query:e.itemId},null===t?r:this.addAndCondition(t,r))},t.prototype.createNotIn=function(t){return{comparator:Rt.IN,key:"id",value:t,not:!0}},t}(),le=function(){function t(t){this.columnUtil=t,this.columns={},this.columnSetIdMap={}}return t.prototype.expandWithRequestColumns=function(t,e){var r=this.columns;void 0===r[t]&&(r[t]=[]),r[t]=this.columnUtil.mergeRequestColumns(r[t],e).merged},t.prototype.expand=function(t){if(!this.columnSetIdMap[t.id]){var e=this.columns,r=t.itemType;void 0===e[r]&&(e[r]=[]),e[r]=this.columnUtil.mergeRequestColumns(e[r],t.request).merged,this.columnSetIdMap[t.id]=!0}},t.prototype.get=function(){return this.columns},t}(),he=function(){function t(t,e,r,n,i,o,s,a){this.requestBufferManager=t,this.changesDeltaFactory=e,this.apiFormatter=r,this.errorHandler=n,this.transactionCacheFactory=i,this.promiseService=o,this.requestColumnExpansionFactory=s,this.apiRequestService=a}return t.prototype.onMessageReceived=function(t){switch(t.body.eventType){case"update":return this.handleUpdate(t);case"create":return this.handleCreate(t);case"delete":return this.handleDelete(t);case"linkTo":return this.handleLinkMove(t)}},t.prototype.formatMessageValues=function(t,e){var r={};for(var n in e)r[n]=this.apiFormatter.formatResponseValue(e[n].type,t[n]);return r},t.prototype.createCollectionMap=function(t,e,r){var n=this.transactionCacheFactory.getServerCache(),i={};for(var o in e){var s=e[o],a=null!==s.parent?s.parent:{},c=this.formatMessageValues(s.values,r);i[o]=n.collectionHandler.entries.getByFittingItem(t,c,a)}return i},t.prototype.getRequestColumns=function(t,e){var r=this.transactionCacheFactory.getServerCache(),n=this.requestColumnExpansionFactory.construct();for(var i in e){for(var o=e[i].fitting,s=r.itemHandler.entries.get(t,i),a=0,c=o;a<c.length;a++){var u=c[a];n.expand(u.columns)}void 0!==s&&n.expand(s.columns)}return n.get()},t.prototype.processMessage=function(t){var e=this.transactionCacheFactory.getServerCache(),r=t.itemType,n=[],i=this.createCollectionMap(r,t.items[r],t.columns[r]),o=this.getRequestColumns(r,i);for(var s in i){var a=+s;void 0===e.itemHandler.entries.get(r,s)?0!==i[a].fitting.length&&n.push(a):n.push(a)}return 0===n.length?this.promiseService.when():this.apiRequestService.query(r,{key:"id",comparator:"IN",value:n},o).then(function(t){return e.processResponse(t,o,!1,!0)},this.errorHandler.reject)},t.prototype.processFunctionChangesResolve=function(t){var e=this,r=this.transactionCacheFactory.getServerCache(),n=t.items.FunctionChangesResolve,i=[];for(var o in n){var s=n[o].parent.itemId,a=r.itemHandler.entries.get("Functie",s);void 0!==a&&void 0!==a.columns.response.Functie.newchanges&&i.push(s)}return 0===i.length?this.promiseService.when():this.requestBufferManager.fetchByIds("Functie",i,["newchanges"]).then(function(t){for(var n=e.changesDeltaFactory.construct(),i=0,o=t.response.links.Functie;i<o.length;i++){var s=o[i],a=r.itemHandler.entries.get("Functie",s),c=r.itemHandler.itemChanges[a.id],u=t.response.fetchObject("Functie",s,!1);void 0!==u&&u.newchanges!==c.newchanges&&n.setItemUpdated(a,{newchanges:u.newchanges})}return r.applyChangesDelta(n,!1,!0)},this.errorHandler.reject).catch(this.errorHandler.notifyError)},t.prototype.isFunctionChangesResolveMessage=function(t){return"FunctionChangesResolve"===t.body.itemType},t.prototype.handleCreate=function(t){var e=t.body;return this.isFunctionChangesResolveMessage(t)?this.processFunctionChangesResolve(e):this.processMessage(e).catch(this.errorHandler.notifyError)},t.prototype.handleUpdate=function(t){return this.processMessage(t.body).catch(this.errorHandler.notifyError)},t.prototype.handleDelete=function(t){for(var e=this.changesDeltaFactory.constructInternalDelta(),r=this.transactionCacheFactory.getServerCache(),n=t.body,i=[],o=0,s=n.items;o<s.length;o++){var a=s[o],c=r.itemHandler.entries.get(n.itemType,a);void 0!==c&&i.push(c)}return e.setItemsDeleted(i),r.applyChangesFromParent(e,!1,!0),this.promiseService.when()},t.prototype.handleLinkMove=function(t){return this.processMessage(t.body).catch(this.errorHandler.notifyError)},t}(),pe=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),de=function(){return(de=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},fe=function(t){function e(e,r,n,i,o,s,a,c,u,l,h,p,d,f,m){var y=t.call(this,a,r,e,s,m)||this;return y.columnSubsetCacheFactory=n,y.columnExpansionFactory=i,y.changesDeltaFactory=o,y.collectionMatcherFactory=c,y.columnHandler=u,y.errorHandler=l,y.itemHandler=h,y.keyService=p,y.promiseService=d,y.exceptionHandler=f,y.transaction=m,y.collectionResources={},y}return pe(e,t),e.prototype.fetchItemEntriesByQuery=function(t,e,r){var n=this;return this.isLocal(r)?this.fetchCollectionEntry(t,new K({columns:r.columns,parent:r.parent,query:e})).then(function(t){return n.collectionChanges[t.itemType][t.query.string]},this.errorHandler.reject):this.transaction.getServerCache().collectionHandler.fetchItemEntriesByQuery(t,e,r)},e.prototype.getAllCollectionsByItemType=function(t){var e=[];if(void 0===this.collectionChanges[t])return e;for(var r in this.collectionChanges[t]){var n=this.transaction.getLocalCollectionEntryByQueryString(t,r);void 0!==n&&n.itemType===t&&e.push(n)}return e},e.prototype.createCollectionEntry=function(e,r){return this.isLocal(r)?t.prototype.createCollectionEntry.call(this,e,r):this.transaction.getServerCache().collectionHandler.createCollectionEntry(e,r)},e.prototype.onItemEntriesCreated=function(t,e){var r=this.collectionResources[t.id];if(void 0!==r)for(var n=0,i=r;n<i.length;n++){var o=i[n];try{o.options.onItemsCreated(e)}catch(t){this.exceptionHandler(t)}}},e.prototype.clearEntry=function(t){this.entries.clear(t),delete this.collectionResources[t.id]},e.prototype.addResource=function(t){var e=this.collectionResources[t.entry.id];void 0===e&&(e=this.collectionResources[t.entry.id]=[]),e.push(t)},e.prototype.clearResource=function(t){var e=this.collectionResources[t.entry.id],r=e.indexOf(t);-1!==r&&e.splice(r,1),0===e.length&&delete this.collectionResources[t.entry.id]},e.prototype.moveItems=function(t,e,r){if(t.itemType!==e.itemType)throw new Error("collectionResourceService: Cannot move items: itemType mismatch");for(var n=this.changesDeltaFactory.construct(),i=0,o=r;i<o.length;i++){var s=o[i];n.setItemMoved(s,e.parent)}this.transaction.applyChangesDelta(n)},e.prototype.extendCollectionEntry=function(t,e){return this.transaction.getServerCache().collectionHandler.extendCollectionEntry(t,e)},e.prototype.cloneCollectionEntry=function(t,e,r){void 0===r&&(r={});var n=this.transaction.getCollectionChangesRecursively(t.id),i=this.createCollectionEntry(t.itemType,this.collectionEntryService.cloneOptions(t.options,e));if(i.columns=this.transaction.core.columnSetFactory.construct(i.itemType,t.columns.request,t.columns.response),null!==t.parent){var o=t.parent;void 0===r[o.itemType]&&(r[o.itemType]={}),r[o.itemType][o.itemId]=e.itemId}return this.itemHandler.cloneItemEntries(n,r),i},e.prototype.getCollectionMatcher=function(){var t=this;return this.collectionMatcherFactory.construct(this.transaction,function(e){return t.getAllCollectionsByItemType(e)})},e.prototype.fetchCollectionEntry=function(t,e){var r=this;if(!this.isLocal(e))return this.transaction.getServerCache().collectionHandler.fetchCollectionEntry(t,e);var n=this.collectionEntryService.createQuery(e);this.expandColumnsWithQueryColumns(t,e,n.object);var i,o=this.changesDeltaFactory.construct(),s=this.columnSubsetCacheFactory.construct(e.columns);return this.fetchCollectionData(o,t,s,e,n).then(function(t){return i=t,r.transaction.applyChangesDelta(o)},this.errorHandler.reject).then(function(){return i},this.errorHandler.reject)},e.prototype.fetchLinkedCollectionEntries=function(t,e,r,n){S(e)&&(e=e());for(var i=[],o=[],s=0,a=e;s<a.length;s++){var c=a[s];this.keyService.isLocalId(c)?o.push(c):i.push(c)}return this.promiseService.all({remote:this.transaction.getServerCache().collectionHandler.fetchLinkedCollectionEntries(t,i,r,n),local:this.fetchLinkedLocalCollectionEntries(t,o,r,n)}).then(function(t){return de({},t.remote,t.local)})},e.prototype.expandCollectionEntries=function(t,e,r,n){return this.transaction.getServerCache().collectionHandler.expandCollectionEntries(t,e,r,n)},e.prototype.extendCollectionEntries=function(t,e,r,n,i){return this.transaction.getServerCache().collectionHandler.extendCollectionEntries(t,e,r,n,i)},e.prototype.addItemEntriesToCollectionChanges=function(e,r,n){void 0===n&&(n=!1),t.prototype._addItemEntriesToCollectionChanges.call(this,e,r,function(){return!1},n)},e.prototype.isLocal=function(t){var e=t.parent;return null!==e&&this.keyService.isLocalId(e.itemId)},e.prototype.expandCollectionEntry=function(t,e,r){var n=this,i=e.columns.mergeRequestColumns(r).difference;if(!0!==i&&0===i.length)return this.promiseService.when(e);var o=e.itemType;return this.columnHandler.fetch(o,i).then(function(r){return n.itemHandler.expandLocalItemEntries(t,o,n.getCollectionChanges(e.itemType,e.query.string),i,r).then(function(){var t=n.columnExpansionFactory.construct(o,i,r);return e.expandColumns(t),e},n.errorHandler.reject)},this.errorHandler.reject)},e.prototype.handleAddedItemEntriesCallback=function(t,e){var r=this.collectionResources[t.id];if(0!==e.length&&void 0!==r&&0!==r.length)for(var n=0,i=r;n<i.length;n++){i[n].addItemResources(e)}},e.prototype.handleRemovedItemEntriesCallback=function(t,e){var r=this.collectionResources[t.id];if(0!==e.length&&void 0!==r&&0!==r.length)for(var n=0,i=r;n<i.length;n++){var o=i[n],s=o.removeItemResources(e);o.callOnRemove(s)}},e.prototype.fetchCollectionData=function(t,e,r,n,i){var o=this,s=this.entries.getByQuery(e,i);if(null!==s)return r.run(s.columns)?this.promiseService.when(s):this.expandCollectionEntry(t,s,r.requestColumns);var a=this.createCollectionEntry(e,n);return this.columnHandler.fetch(e,n.columns).then(function(t){return a.columns=o.transaction.core.columnSetFactory.construct(a.itemType,n.columns,t),a})},e.prototype.fetchLinkedLocalCollectionEntries=function(t,e,r,n){for(var i=this,o=this.changesDeltaFactory.construct(),s={},a=0,c=e;a<c.length;a++){var u=c[a],l=this.collectionEntryService.cloneOptions(n,{itemType:t,itemId:u}),h=this.collectionEntryService.createQuery(l);this.expandColumnsWithQueryColumns(r,l,h.object);var p=this.columnSubsetCacheFactory.construct(l.columns);s[u]=this.fetchCollectionData(o,r,p,l,h)}return this.promiseService.all(s).then(function(t){return i.transaction.applyChangesDelta(o).then(function(){return t},i.errorHandler.reject)},this.errorHandler.reject)},e}(Nt),me=function(){function t(t){this.transaction=t,this.lastCallId={global:{},item:{}}}return t.prototype.setGlobalError=function(t,e,r,n){var i=this,o=this.getRandomId();this.lastCallId.global[t]=o,R(e)?(this.transaction.isValid=!1,e.then(function(e){o===i.lastCallId.global[t]&&(delete i.lastCallId.global[t],i.transaction._setGlobalError(t,e,r,n))},function(){i.transaction._setIsValid()})):this.transaction._setGlobalError(t,e,r,n)},t.prototype.setItemError=function(t,e,r,n,i,o){var s=this,a=this.getRandomId();this.lastCallId.item[t]=a,R(n)?(this.transaction.isValid=!1,n.then(function(n){a===s.lastCallId.item[t]&&(delete s.lastCallId.item[t],s.transaction._setItemError(t,e,r,n,i,o))},function(){s.transaction._setIsValid()})):this.transaction._setItemError(t,e,r,n,i,o)},t.prototype.getRandomId=function(){return Math.random().toString().split(".")[1]},t}(),ye=function(){function t(t){this.itemEntryService=t,this.updated={},this.deleted={},this._queryResults={}}return t.prototype._setQueryResult=function(t,e,r){void 0===this._queryResults[t]&&(this._queryResults[t]={}),this._queryResults[t][e]=r},t.prototype.setItemUpdated=function(t,e,r,n){void 0===r&&(r=null),void 0===n&&(n=null),void 0===this.updated[t.id]&&(this.updated[t.id]={entry:t,changes:{fields:{},expandedColumns:null,parent:n}});var i=this.updated[t.id];if(null!==n){var o=this.itemEntryService.getLinkFieldsByParent(n,t.itemType);for(var s in o)e[s]=o[s]}for(var a in e){var c=Object.getOwnPropertyDescriptor(e,a);void 0!==c?Object.defineProperty(i.changes.fields,a,c):i.changes.fields[a]=e[a]}null!==r&&(i.changes.expandedColumns=r)},t.prototype.setItemDeleted=function(t){this.setItemsDeleted([t])},t.prototype.setItemsDeleted=function(t){for(var e=0,r=t;e<r.length;e++){var n=r[e];void 0===this.deleted[n.itemType]&&(this.deleted[n.itemType]=[]),this.deleted[n.itemType].indexOf(n)>-1||this.deleted[n.itemType].push(n)}},t}(),ve=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),ge=function(t){function e(e){var r=t.call(this,e)||this;return r.created=[],r}return ve(e,t),e.prototype.setItemCreated=function(t,e,r,n){void 0===n&&(n=null);var i={};if(null!==n)for(var o in i=this.itemEntryService.getLinkFieldsByParent(n,r.itemType))e[o]=i[o];var s=this.itemEntryService.getLocalDefaultValues();for(var o in s)e[o]=s[o];this.created.push({itemId:t,fields:e,columns:r})},e.prototype.setItemMoved=function(t,e){this.setItemUpdated(t,{},null,e)},e}(ye),Ce=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),Ie=function(t){function e(e){var r=t.call(this,e)||this;return r.created={},r.moved={},r.itemIdConversionMap={},r}return Ce(e,t),e.prototype.setItemCreated=function(t,e){this.created[t.id]={entry:t,fields:e}},e.prototype.setItemMoved=function(t,e){this.moved[t.id]={entry:t,to:e}},e}(ye),Ee=function(){function t(t,e,r,n,i,o){this.promiseLibrary=t,this.apiRequestService=e,this.requestColumnExpansionFactory=r,this.changesDeltaFactory=n,this.serverCache=i,this.itemType=o,this.deferred=this.promiseLibrary.defer(),this.requestColumnExpansion=this.requestColumnExpansionFactory.construct(),this.singleItemIds=[],this.queries={}}return t.prototype.containsId=function(t){return-1!==this.singleItemIds.indexOf(t)},t.prototype.containsQuery=function(t){return void 0!==this.queries[t]},t.prototype.addSingleItem=function(t,e){return this.requestColumnExpansion.expandWithRequestColumns(this.itemType,e),-1===this.singleItemIds.indexOf(t)&&this.singleItemIds.push(t),this.getPromise()},t.prototype.addQuery=function(t,e){return this.requestColumnExpansion.expandWithRequestColumns(this.itemType,e),void 0===this.queries[t[1]]&&(this.queries[t[1]]=t[0]),this.getPromise()},t.prototype.flush=function(){var t=this,e=[];for(var r in this.singleItemIds.length>0&&e.push({key:"id",comparator:"IN",value:this.singleItemIds}),this.queries)e.push(this.queries[r]);if(0===e.length)throw new Error("Tried to flush a RequestBuffer without singleItems or queries");var n,i=this.requestColumnExpansion.get();return this.apiRequestService.query(this.itemType,{conditions:e,operator:"OR"},i).then(function(e){n=e;var r=t.changesDeltaFactory.construct();if(0===t.singleItemIds.length&&!t.hasMultipleQueries()){var o=t.getFirstQueryString();void 0!==o&&r._setQueryResult(t.itemType,o,n.links[t.itemType])}return t.serverCache.processResponse(n,i,!1,!1,r)},function(e){return t.deferred.reject(e)}).then(function(){return t.deferred.resolve(n)},function(e){return t.deferred.reject(e)}),this.getPromise()},t.prototype.getPromise=function(){return this.deferred.promise},t.prototype.hasMultipleQueries=function(){var t=!0;for(var e in this.queries){if(!t)return!0;t=!1}return!1},t.prototype.getFirstQueryString=function(){for(var t in this.queries)return t},t}(),Fe=function(){function t(t,e,r,n,i,o){this.promiseLibrary=t,this.apiRequestService=e,this.requestColumnExpansionFactory=r,this.keyService=n,this.errorHandler=i,this.changesDeltaFactory=o,this.pendingBufferMap={},this.pendingTrueBufferMap={},this.pendingQueryBufferMap={},this.pendingTemplateBufferMap={}}return t.prototype.setServerCache=function(t){this.serverCache=t},t.prototype.containsId=function(t,e){return!!d(this.pendingTemplateBufferMap,[t,e])||void 0!==this.pendingBufferMap[t]&&this.pendingBufferMap[t].containsId(e)},t.prototype.containsQuery=function(t,e){return void 0!==d(this.pendingQueryBufferMap,[t,e])},t.prototype.fetchByIds=function(t,e,r){for(var n=0,i=e;n<i.length;n++){var o=i[n];this.fetchById(t,o,r)}return this.pendingBufferMap[t].getPromise()},t.prototype.fetchById=function(t,e,r){if(this.keyService.isLocalId(e))throw new Error("Unexpected local ItemId in RequestBufferManager.fetchById, for local ItemIds you should use RequestBufferManager.fetchByLocalId");var n;return!0===r?void 0===(n=this.pendingTrueBufferMap[t])?n=this.constructBuffer(t,this.pendingTrueBufferMap):console.log("Existing 'columns: true' RequestBuffer "+t+" at "+performance.now()+" by id"):void 0===(n=this.pendingBufferMap[t])?n=this.constructBuffer(t):console.log("Existing RequestBuffer "+t+" at "+performance.now()+" by id"),n.addSingleItem(e,r),n.getPromise()},t.prototype.fetchByQuery=function(t,e,r){var n=this.pendingBufferMap[t];return void 0===n?n=this.constructBuffer(t):console.log("Existing RequestBuffer "+t+" at "+performance.now()+" with query"),n.addQuery(e,r),n.getPromise()},t.prototype.fetchByLocalId=function(t,e,r){return void 0===e&&(e="no-id"),void 0===this.pendingTemplateBufferMap[t]||void 0===this.pendingTemplateBufferMap[t][e]?this.constructTemplateBuffer(t,e,r):this.pendingTemplateBufferMap[t][e]},t.prototype.constructBuffer=function(t,e){void 0===e&&(e=this.pendingBufferMap);var r=e[t]=new Ee(this.promiseLibrary,this.apiRequestService,this.requestColumnExpansionFactory,this.changesDeltaFactory,this.serverCache,t);return window.setTimeout(function(){r.flush(),delete e[t]},150),r},t.prototype.constructTemplateBuffer=function(t,e,r){var n=this;return void 0===this.pendingTemplateBufferMap[t]&&(this.pendingTemplateBufferMap[t]={}),this.pendingTemplateBufferMap[t][e]=this.apiRequestService.template(t,r).then(function(r){return delete n.pendingTemplateBufferMap[t][e],r},function(){return delete n.pendingTemplateBufferMap[t][e],n.errorHandler.reject()})},t}(),Se=function(){function t(t,e,r,n,i,o,s){this.columnUtil=t,this.promiseService=e,this.requestBufferFactory=r,this.columnHandler=n,this.templateFactory=i,this.errorHandler=o,this.requestColumnExpansionFactory=s,this.templates={}}return t.prototype.fetchTemplate=function(t,e,r,n,i){var o=this;void 0===r&&(r={}),void 0===n&&(n={}),void 0===i&&(i=null);var a=s(r),c=this.requestColumnExpansionFactory.construct();if(void 0!==n[t]&&c.expandWithRequestColumns(t,n[t]),c.expandWithRequestColumns(t,[{creator:["displayname"]},"created","permissions"]),null!==i&&c.expandWithRequestColumns(t,this.columnUtil.getColumnsFromLink("string"==typeof i?i:i.itemType,t)),n[t]=c.get()[t],!a){var u=this.templates[t];if(void 0!==u&&(null===t||this.columnUtil.responseColumnsAvailable(t,n[t],u.responseColumns)))return this.promiseService.when(u)}return this.promiseService.all({template:this.requestBufferFactory.fetchByLocalId(t,e,r),additionalColumns:void 0===n[t]?{}:this.columnHandler.fetch(t,n[t])}).then(function(e){var r=e.template,i=o.templateFactory.construct(t,r,n,e.additionalColumns);return!a&&r.cacheable&&(o.templates[t]=i),i},this.errorHandler.reject)},t}(),Re=function(){function t(t){this.apiFormatter=t}return t.prototype.construct=function(t){return new P(this.apiFormatter,t)},t}(),qe=function(){function t(){}return t.prototype.construct=function(t){return new L(t)},t}(),Te=function(){function t(t){this.queryMatcherFactory=t}return t.prototype.construct=function(t){return new qt(this.queryMatcherFactory,t)},t}(),we=function(){function t(t,e,r){this.collectionEntryService=t,this.columnSetFactory=e,this.keyService=r}return t.prototype.construct=function(t,e){return new X(this.collectionEntryService,this.columnSetFactory,this.keyService,t,new K(e))},t}(),be=function(){function t(t){this.queryMatcherFactory=t}return t.prototype.construct=function(t,e){return new mt(this.queryMatcherFactory,t,e)},t}(),He=function(){function t(t,e,r,n,i,o){this.errorHandler=t,this.exceptionHandler=e,this.itemResourceFactory=r,this.keyService=n,this.promiseService=i,this.changesDeltaFactory=o}return t.prototype.construct=function(t,e,r){var n=new z(e);return n.editCollection?new rt(this,t,n,r):new tt(this,t,n,r)},t}(),Me=function(){function t(t){this.columnInfoFactory=t}return t.prototype.construct=function(t,e,r){return new Ht(this.columnInfoFactory,t,e,r)},t}(),xe=function(){function t(){}return t.prototype.construct=function(t,e){return new kt(t,e)},t.prototype.constructFromRootMap=function(t,e){void 0===e&&(e=null);var r=[];for(var n in t){var i=t[n],o=this.construct(i.apiColumn,e),s=this.constructFromRootMap(i.children,o);s.length>0&&o.setChildren(o.apiColumn.itemType,s),r.push(o)}return r},t}(),ke=function(){function t(t,e,r){this.columnHandler=t,this.columnUtil=e,this.columnInfoFactory=r}return t.prototype.constructStub=function(t,e){var r=new _t(this.columnUtil,this,t);return r.request=e,r.requestColumnsTrue=!0===e,r},t.prototype.resolveStub=function(t,e,r,n){return void 0===r&&(r=!0),void 0===n&&(n=!0),t.requestColumnsTrue?this.processResponseColumns(t,e,r):this.processRequestColumns(t,e,r,n)},t.prototype.construct=function(t,e,r,n,i){return this.resolveStub(this.constructStub(t,e),r,n,i)},t.prototype.constructFromResponse=function(t,e,r){void 0===r&&(r=!0);var n=new _t(this.columnUtil,this,t);return n.requestColumnsTrue=!1,this.processResponseColumns(n,e,r)},t.prototype.processResponseColumns=function(t,e,r){var n=t.itemType,i={};return t.response=e,this.expandRootColumnMapFromResponseColumns(n,e,i,r,{}),this.processColumnInfo(t,this.columnInfoFactory.constructFromRootMap(i),n),t.request=this.constructRequestColumnsFromRootColumnMap(i),t},t.prototype.constructRequestColumnsFromRootColumnMap=function(t){var e,r=[];for(var n in t){var i=t[n];s(i.children)?r.push(((e={})[n]=this.constructRequestColumnsFromRootColumnMap(i.children),e)):r.push(n)}return r},t.prototype.expandRootColumnMapFromResponseColumns=function(t,e,r,n,i){if(!0!==i[t])for(var o in i[t]=!0,e[t]){var a=e[t][o];if(void 0!==a&&(n&&this.columnHandler.setColumn(t,a),void 0===r[o]&&(r[o]={apiColumn:a,children:{}}),this.columnUtil.isItemColumn(a,!1))){var c=e[a.itemType];void 0!==c&&s(c)&&this.expandRootColumnMapFromResponseColumns(a.itemType,e,r[o].children,n,i)}}},t.prototype.processRequestColumns=function(t,e,r,n){var i=t.itemType,o={};return this.expandRootColumnMap(t.request,i,e,o,r),n&&this.expandRootColumnMap(["id"],i,e,o,r),t.response={},this.processColumnInfo(t,this.columnInfoFactory.constructFromRootMap(o),i),t},t.prototype.processColumnInfo=function(t,e,r){var n=t.response;void 0===n[r]&&(n[r]={});for(var i=0,o=e;i<o.length;i++){var s=o[i];n[r][s.id]=s.apiColumn,t.groupColumnInfo(s),s.isLeaf||this.processColumnInfo(t,s.children,s.itemType)}},t.prototype.expandRootColumnMap=function(t,e,r,n,i){for(var o=0,s=t;o<s.length;o++){var a=s[o],c=this.columnUtil.parseRequestColumn(a),u=c.id,l=c.children,h=void 0;void 0!==r[e]&&(h=r[e][u]),void 0!==h?(i&&(h=this.columnHandler.setColumn(e,h)),void 0===n[u]&&(n[u]={apiColumn:h,children:{}}),0!==l.length&&this.expandRootColumnMap(l,h.itemType,r,n[u].children,i)):console.warn("No api column for request column",u,"for itemType",e)}},t}(),De=function(){function t(){}return t.prototype.construct=function(t){return new Pt(t)},t}(),Oe=function(){function t(t,e,r){this.apiFormatter=t,this.keyService=e,this.requestColumnExpansionFactory=r}return t.prototype.construct=function(t,e,r){return new jt(this.apiFormatter,this.keyService,this.requestColumnExpansionFactory,t,e,r)},t}(),_e=function(){function t(t){this.queryMatcherFactory=t}return t.prototype.construct=function(t){return new Xt(this.queryMatcherFactory,t)},t}(),Pe=function(){function t(t,e,r,n,i,o,s,a){this.authInterface=t,this.apiFormatter=e,this.columnSetFactory=r,this.exceptionHandler=n,this.itemEntryService=i,this.itemResourceFactory=o,this.keyService=s,this.promiseService=a}return t.prototype.construct=function(t,e){return new V(this,e.itemType,t,e)},t}(),Le=function(){function t(t,e,r,n,i,o,s){this.apiFormatter=t,this.lockService=e,this.errorHandler=r,this.promiseService=n,this.exceptionHandler=i,this.columnUtil=o,this.linkTreeService=s}return t.prototype.getConstructor=function(t,e){var r=this,n=new A(t);return function(t){return r.constructWithOptions(t,n,e)}},t.prototype.construct=function(t,e,r,n){return this.constructWithOptions(t,new A(e),r,n)},t.prototype.constructWithOptions=function(t,e,r,n){return void 0===n&&(n=!1),e.edit?new J(this,t,e,n,r):e.remote?new ot(this,t,e,n,r):new at(this,t,e,n,r)},t}(),je=function(){function t(t,e,r,n,i,o,s,a,c,u,l,h,p,d,f,m,y,v,g,C,I,E,F,S,R,q,T,w,b,H,M,x,k,D){this.core=t,this.columnCache=e,this.requestBufferManager=r,this.requestColumnExpansionFactory=n,this.queryMatcherFactory=i,this.authInterface=o,this.changesDeltaFactory=s,this.changesProcessorFactory=a,this.lockService=c,this.moduleChangesCompilationFactory=u,this.collectionResourceFactory=l,this.itemResourceFactory=h,this.templateCache=p,this.itemCacheFactory=d,this.collectionCacheFactory=f,this.errorHandler=m,this.exceptionHandler=y,this.promiseService=v,this.apiFormatter=g,this.apiRequestService=C,this.columnExpansionFactory=I,this.columnHandler=E,this.columnSetFactory=F,this.columnSubsetCacheFactory=S,this.columnUtil=R,this.itemEntryFactory=q,this.itemEntryService=T,this.keyService=w,this.collectionEntryFactory=b,this.collectionEntryService=H,this.collectionMatcherFactory=M,this.queryParserFactory=x,this.queryService=k,this.linkTreeService=D,this.serverCache=new Gt(this.changesProcessorFactory,this.core,this.columnCache,this.requestBufferManager,this.requestColumnExpansionFactory,this.queryMatcherFactory,this.authInterface,this.changesDeltaFactory,this.lockService,this.moduleChangesCompilationFactory,this.collectionResourceFactory,this.itemResourceFactory,this.templateCache,this.itemCacheFactory,this.collectionCacheFactory,this.errorHandler,this.exceptionHandler,this.promiseService,this.apiFormatter,this.apiRequestService,this.columnExpansionFactory,this.columnHandler,this.columnSetFactory,this.columnSubsetCacheFactory,this.columnUtil,this.itemEntryFactory,this.itemEntryService,this.keyService,this.collectionEntryFactory,this.collectionEntryService,this.collectionMatcherFactory,this.queryParserFactory,this.queryService,this.linkTreeService)}return t.prototype.getById=function(t){var e=function(r){for(var n=0,i=r;n<i.length;n++){var o=i[n];if(o.id===t)return o;var s=e(o.children);if(void 0!==s)return s}};return e(this.serverCache.children)},t.prototype.construct=function(t,e){return this.serverCache.createChild(t,e)},t.prototype.getServerCache=function(){return this.serverCache},t}(),Be=function(){function t(){}return t.prototype.construct=function(t){return new re(t)},t}(),Ae=function(){function t(t){this.apiFormatter=t}return t.prototype.construct=function(t,e,r){return new ie(this.apiFormatter,t,e,r)},t}(),Qe=function(){function t(){}return t.prototype.construct=function(t,e){return new ce(t,e)},t}(),Ve=function(){function t(t){this.columnUtil=t}return t.prototype.construct=function(){return new le(this.columnUtil)},t}(),Ue=function(){function t(t,e){this.columnSetFactory=t,this.columnUtil=e}return t.prototype.construct=function(t,e,r,n){return new nt(this,t,e,r,n)},t}(),Ne=function(){function t(t){this.itemEntryService=t}return t.prototype.construct=function(){return new ge(this.itemEntryService)},t.prototype.constructInternalDelta=function(){return new Ie(this.itemEntryService)},t}(),We=function(){function t(t,e,r,n,i,o,s,a,c,u){this.changesDeltaFactory=t,this.apiRequestService=e,this.changesCompilationFactory=r,this.columnExpansionFactory=n,this.createRequestFactory=i,this.errorHandler=o,this.promiseService=s,this.requestColumnExpansionFactory=a,this.collectionEntryService=c,this.itemEntryService=u}return t.prototype.construct=function(t,e,r){return new j(this.changesDeltaFactory,this.apiRequestService,this.changesCompilationFactory,this.columnExpansionFactory,this.createRequestFactory,this.errorHandler,this.promiseService,this.requestColumnExpansionFactory,this.collectionEntryService,this.itemEntryService,t,e,r)},t}(),Ye=function(){return function(t,e,r,n,i,o){this.version="2.1.0",this.noop=Je;var s=new $t,a=new O,c=new Ae(a),u=new Qe,l=new ue,h=new Zt(e,s,o),p=new Ne(h),d=new Re(a),f=new _(t,d),m=new Lt(o),y=new bt(m),v=new Mt(f,r,i,y,m),g=new xe,C=new Me(g),I=new ke(v,m,g),E=new De,F=new te(f,r,s,i),S=new Ue(I,m),R=new _e(c),q=new Le(a,F,r,i,n,m,o),T=new He(r,n,q,s,i,p),w=new Pe(e,a,I,n,h,q,s,i),b=new Tt(u,l),H=new wt,M=new we(b,I,s),x=new Te(c),k=new be(c),D=new Ve(m),P=new Oe(a,s,D),L=new qe,j=new We(p,f,L,C,P,r,i,D,b,h),B=new Be,A=new Fe(i,f,D,s,r,p),Q=new Se(m,i,A,v,S,r,D),V=new je(this,y,A,D,c,e,p,j,F,B,T,q,Q,R,x,r,n,i,a,f,C,v,I,E,m,w,h,s,M,b,k,u,l,o);A.setServerCache(V.getServerCache());var U=new he(A,p,a,r,V,i,D,f);this.apiFormatter=a,this.apiRequestService=f,this.apiResponseProcessorFactory=d,this.changesCompilationFactory=L,this.changesProcessorFactory=j,this.collectionCacheFactory=x,this.collectionEntryFactory=M,this.collectionEntryService=b,this.collectionMatcherFactory=k,this.collectionResourceFactory=T,this.collectionResourceService=H,this.columnCache=y,this.columnExpansionFactory=C,this.columnHandler=v,this.columnInfoFactory=g,this.columnSetFactory=I,this.columnSubsetCacheFactory=E,this.columnUtil=m,this.createRequestFactory=P,this.itemCacheFactory=R,this.itemEntryFactory=w,this.itemEntryService=h,this.itemResourceFactory=q,this.keyService=s,this.transactionCacheFactory=V,this.lockService=F,this.moduleChangesCompilationFactory=B,this.queryMatcherFactory=c,this.queryParserFactory=u,this.queryService=l,this.requestColumnExpansionFactory=D,this.socketMessageHandler=U,this.templateFactory=S,this.changesDeltaFactory=p,this.templateCache=Q}}();function Je(){}function Ke(t){return t}r.d(e,"RmCore",function(){return Ye}),r.d(e,"noop",function(){return Je}),r.d(e,"identity",function(){return Ke}),r.d(e,"ALL_PERMISSIONS",function(){return"7"}),r.d(e,"COLUMN_SEPERATOR",function(){return xt}),r.d(e,"RENDER_AS_SEPERATOR",function(){return":"}),r.d(e,"NEW_PREFIX",function(){return"-1"}),r.d(e,"DUPLICATE_PREFIX",function(){return"-2"}),r.d(e,"NEW_KEYWORD",function(){return"new-"}),r.d(e,"DUPLICATE_KEYWORD",function(){return"dup-"}),r.d(e,"ItemEntryOptions",function(){return B}),r.d(e,"ItemResourceOptions",function(){return A}),r.d(e,"ItemEntry",function(){return V}),r.d(e,"ItemResource",function(){return U}),r.d(e,"ViewResource",function(){return W}),r.d(e,"EditResource",function(){return J}),r.d(e,"CollectionEntryOptions",function(){return K}),r.d(e,"CollectionResourceOptions",function(){return z}),r.d(e,"CollectionEntry",function(){return X}),r.d(e,"CollectionResource",function(){return Z}),r.d(e,"CollectionViewResource",function(){return tt}),r.d(e,"CollectionEditResource",function(){return rt}),r.d(e,"Template",function(){return nt}),r.d(e,"RemoteViewResource",function(){return ot}),r.d(e,"LocalViewResource",function(){return at}),r.d(e,"ApiFormatter",function(){return O}),r.d(e,"ApiRequestService",function(){return _}),r.d(e,"ApiResponseProcessor",function(){return P}),r.d(e,"ChangesCompilation",function(){return L}),r.d(e,"ChangesProcessor",function(){return j}),r.d(e,"CollectionCache",function(){return qt}),r.d(e,"CollectionEntryService",function(){return Tt}),r.d(e,"CollectionMatcher",function(){return mt}),r.d(e,"CollectionResourceService",function(){return wt}),r.d(e,"ColumnCache",function(){return bt}),r.d(e,"ColumnExpansion",function(){return Ht}),r.d(e,"ColumnHandler",function(){return Mt}),r.d(e,"ColumnInfo",function(){return kt}),r.d(e,"ColumnSet",function(){return _t}),r.d(e,"ColumnSubsetCache",function(){return Pt}),r.d(e,"ColumnUtil",function(){return Lt}),r.d(e,"CreateRequest",function(){return jt}),r.d(e,"ItemCache",function(){return Xt}),r.d(e,"ItemEntryService",function(){return Zt}),r.d(e,"KeyService",function(){return $t}),r.d(e,"TransactionEventHandler",function(){return gt}),r.d(e,"LockService",function(){return te}),r.d(e,"ModuleChangesCompilation",function(){return re}),r.d(e,"QueryMatcher",function(){return ie}),r.d(e,"CONSTANTS",function(){return At}),r.d(e,"QueryParser",function(){return ce}),r.d(e,"QueryService",function(){return ue}),r.d(e,"RequestColumnExpansion",function(){return le}),r.d(e,"SocketMessageHandler",function(){return he}),r.d(e,"instantiateOptions",function(){return i}),r.d(e,"shallowMerge",function(){return o}),r.d(e,"hasProperties",function(){return s}),r.d(e,"getFirstProperty",function(){return a}),r.d(e,"inArray",function(){return c}),r.d(e,"filterArray",function(){return u}),r.d(e,"emptyArray",function(){return l}),r.d(e,"pathExists",function(){return h}),r.d(e,"createPath",function(){return p}),r.d(e,"getPath",function(){return d}),r.d(e,"extend",function(){return m}),r.d(e,"merge",function(){return y}),r.d(e,"isObject",function(){return v}),r.d(e,"isBlankObject",function(){return g}),r.d(e,"isString",function(){return C}),r.d(e,"isNumber",function(){return I}),r.d(e,"isDate",function(){return E}),r.d(e,"isArray",function(){return F}),r.d(e,"isFunction",function(){return S}),r.d(e,"isPromiseLike",function(){return R}),r.d(e,"isRegExp",function(){return q}),r.d(e,"isBoolean",function(){return T}),r.d(e,"isElement",function(){return w}),r.d(e,"isWindow",function(){return b}),r.d(e,"isDefined",function(){return H}),r.d(e,"equals",function(){return M}),r.d(e,"copy",function(){return x}),r.d(e,"AbstractCache",function(){return pt}),r.d(e,"ServerCache",function(){return Gt}),r.d(e,"ServerItemHandler",function(){return Kt}),r.d(e,"ServerCollectionHandler",function(){return Yt}),r.d(e,"TransactionErrorLevel",function(){return ct}),r.d(e,"TransactionCache",function(){return Ft}),r.d(e,"TransactionItemHandler",function(){return ht}),r.d(e,"TransactionCollectionHandler",function(){return fe}),r.d(e,"TransactionValidator",function(){return me}),r.d(e,"ChangesDelta",function(){return ge}),r.d(e,"InternalChangesDelta",function(){return Ie}),r.d(e,"RequestBufferManager",function(){return Fe}),r.d(e,"RequestBuffer",function(){return Ee}),r.d(e,"ApiResponseProcessorFactory",function(){return Re}),r.d(e,"ChangesCompilationFactory",function(){return qe}),r.d(e,"CollectionCacheFactory",function(){return Te}),r.d(e,"CollectionEntryFactory",function(){return we}),r.d(e,"CollectionMatcherFactory",function(){return be}),r.d(e,"CollectionResourceFactory",function(){return He}),r.d(e,"ColumnExpansionFactory",function(){return Me}),r.d(e,"ColumnInfoFactory",function(){return xe}),r.d(e,"ColumnSetFactory",function(){return ke}),r.d(e,"ColumnSubsetCacheFactory",function(){return De}),r.d(e,"CreateRequestFactory",function(){return Oe}),r.d(e,"ItemCacheFactory",function(){return _e}),r.d(e,"ItemEntryFactory",function(){return Pe}),r.d(e,"ItemResourceFactory",function(){return Le}),r.d(e,"TransactionCacheFactory",function(){return je}),r.d(e,"ModuleChangesCompilationFactory",function(){return Be}),r.d(e,"QueryMatcherFactory",function(){return Ae}),r.d(e,"QueryParserFactory",function(){return Qe}),r.d(e,"RequestColumnExpansionFactory",function(){return Ve}),r.d(e,"TemplateFactory",function(){return Ue}),r.d(e,"ChangesDeltaFactory",function(){return Ne}),r.d(e,"ChangesProcessorFactory",function(){return We}),r.d(e,"ApiLinkTreeType",function(){return D})}])});
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("moment")):"function"==typeof define&&define.amd?define(["moment"],e):"object"==typeof exports?exports.RmCore=e(require("moment")):t.RmCore=e(t.moment)}(window,function(t){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([function(e,r){e.exports=t},function(t,e,r){"use strict";r.r(e);var n=r(0);function i(t,e){for(var r in e)r in t&&void 0!==e[r]&&(t[r]=e[r])}function o(t,e){if(void 0===t)return e;var r={};for(var n in e)r[n]=void 0===t[n]?e[n]:t[n];return r}function s(t){for(var e in t)return!0;return!1}function a(t){if("object"!=typeof t)return null;for(var e in t)return e;return null}function c(t,e){for(var r=0,n=e;r<n.length;r++){if(t==n[r])return!0}return!1}function u(t,e){for(var r=[],n=0,i=t;n<i.length;n++){var o=i[n];e(o)&&r.push(o)}if(r.length===t.length)return!1;l(t);for(var s=0,a=r;s<a.length;s++){var c=a[s];t.push(c)}return!0}function l(t){t.splice(0)}function h(t,e){if(void 0===t)return!1;for(var r=0,n=e;r<n.length;r++){var i=n[r];if(void 0===t[i])return!1;t=t[i]}return!0}function p(t,e,r){for(var n=0;n<e.length;n++){var i=e[n];void 0===t[i]&&(t[i]=r[n]),t=t[i]}return t}function d(t,e,r){if(void 0===r&&(r=!1),void 0!==t){for(var n=0,i=e;n<i.length;n++){if(void 0===(t=t[i[n]])&&!r)return}return t}}function f(t,e,r){for(var n=0,i=e.length;n<i;++n){var o=e[n];if(v(o)||S(o))for(var s=Object.keys(o),a=0,c=s.length;a<c;a++){var u=s[a],l=o[u];r&&v(l)?E(l)?t[u]=new Date(l.valueOf()):q(l)?t[u]=new RegExp(l):l.nodeName?t[u]=l.cloneNode(!0):w(l)?t[u]=l.clone():(v(t[u])||(t[u]=F(l)?[]:{}),f(t[u],[l],!0)):t[u]=l}}return t}function m(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];return f(t,e,!1)}function y(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];return f(t,e,!0)}function v(t){return null!==t&&"object"==typeof t}function g(t){return null!==t&&"object"==typeof t&&!Object.getPrototypeOf(t)}function C(t){return"string"==typeof t}function I(t){return"number"==typeof t}function E(t){return"[object Date]"===toString.call(t)}var F=Array.isArray;function S(t){return"function"==typeof t}function R(t){return t&&S(t.then)}function q(t){return"[object RegExp]"===toString.call(t)}function T(t){return"boolean"==typeof t}function w(t){return!(!t||!(t.nodeName||t.prop&&t.attr&&t.find))}function b(t){return t&&t.window===t}function H(t){return void 0!==t}function M(t,e){if(t===e)return!0;if(null===t||null===e)return!1;if(t!=t&&e!=e)return!0;var r,n,i,o,s,a=typeof t;if(a===typeof e&&"object"===a){if(!F(t)){if(E(t))return!!E(e)&&(o=t.getTime(),s=e.getTime(),o===s||o!=o&&s!=s);if(q(t))return!!q(e)&&t.toString()===e.toString();if(b(t)||b(e)||F(e)||E(e)||q(e))return!1;for(n in i=Object.create(null),t)if(!S(t[n])){if(!M(t[n],e[n]))return!1;i[n]=!0}for(n in e)if(!(n in i)&&H(e[n])&&!S(e[n]))return!1;return!0}if(!F(e))return!1;if(r=t.length,t.length===e.length){for(n=0;n<r;n++)if(!M(t[n],e[n]))return!1;return!0}}return!1}function x(t,e,r){var n=[],i=[];if(r=function(t){return I(t)&&t>0}(r)?r:NaN,e){if(t===e)throw new Error("Can't copy! Source and destination are identical.");if(F(e))e.length=0;else for(var o in e)delete e[o];return n.push(t),i.push(e),s(t,e,r)}return a(t,r);function s(t,e,r){if(--r<0)return"...";if(F(t))for(var n=0,i=t.length;n<i;n++)e.push(a(t[n],r));else if(g(t))for(var o in t)e[o]=a(t[o],r);else if(t&&"function"==typeof t.hasOwnProperty)for(var o in t)t.hasOwnProperty(o)&&(e[o]=a(t[o],r));else for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=a(t[o],r));return e}function a(t,e){if(void 0===e&&(e=5),!v(t))return t;var r=n.indexOf(t);if(-1!==r)return i[r];if(b(t))throw new Error("Can't copy! Making copies of Window instances is not supported.");var o=!1,c=function(t){switch(toString.call(t)){case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Float32Array]":case"[object Float64Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return new t.constructor(a(t.buffer),t.byteOffset,t.length);case"[object ArrayBuffer]":if(!t.slice){var e=new ArrayBuffer(t.byteLength);return new Uint8Array(e).set(new Uint8Array(t)),e}return t.slice(0);case"[object Boolean]":case"[object Number]":case"[object String]":case"[object Date]":return new t.constructor(t.valueOf());case"[object RegExp]":var r=new RegExp(t._source,t.toString().match(/[^/]*$/)[0]);return r.lastIndex=t.lastIndex,r;case"[object Blob]":return new t.constructor([t],{type:t.type})}if(S(t.cloneNode))return t.cloneNode(!0)}(t);return void 0===c&&(c=F(t)?[]:Object.create(Object.getPrototypeOf(t)),o=!0),n.push(t),i.push(c),o?s(t,c,e):c}}var k,D,_=function(){function t(){this.MOMENT_INVALID="Invalid date",this.SERVER_DATETIME_FORMAT="YYYY-MM-DD[T]HH:mm:ssZ",this.SERVER_TIME_FORMAT="HH:mm:ss",this.SERVER_DATE_FORMAT="YYYY-MM-DD"}return t.prototype.isExpensiveFormat=function(t){switch(t){case"date":case"datetime":case"duration":return!0;default:return!1}},t.prototype.mergeCopyFields=function(t,e,r,n){for(var i=0,o=n;i<o.length;i++){var s=o[i],a=s.path;void 0===r[a]||"id"!==a&&void 0!==e[a]&&!this.compareFields(s.apiColumn.type,e[a],t[a])||(e[a]=this.clone(s.apiColumn.type,r[a]))}return e},t.prototype.formatRequest=function(t,e,r){for(var n={},i=0,o=r;i<o.length;i++){var s=o[i],a=s.id,c=s.apiColumn,u=c.type;c.readOnly||(this.compareFields(u,t[a],e[a])||(n[a]=this.formatRequestValue(u,e[a])))}return n},t.prototype.formatRequestLocal=function(t,e){for(var r={},n=0,i=e;n<i.length;n++){var o=i[n],s=o.id,a=o.apiColumn;a.readOnly||(r[s]=this.formatRequestValue(a.type,t[s]))}return r},t.prototype.hasChanges=function(t,e,r,n){void 0===n&&(n=!1);for(var i=0,o=r;i<o.length;i++){var s=o[i],a=s.id,c=s.apiColumn;if("link"===c.type||"parenttype"===c.type||"parentid"===c.type||n||!c.readOnly){if(this.isExpensiveFormat(s.apiColumn.type)){var u=Object.getOwnPropertyDescriptor(e,a);if(void 0!==u&&void 0===u.value&&void 0!==u.get)continue}if(!this.compareFields(c.type,t[a],e[a]))return!0}}return!1},t.prototype.getChanges=function(t,e,r){for(var n=[],i=0,o=r;i<o.length;i++){var s=o[i],a=s.id,c=s.apiColumn;c.readOnly||(this.compareFields(c.type,t[a],e[a])||n.push({oldValue:t[a],newValue:e[a],column:s.apiColumn}))}return n},t.prototype.copyFields=function(t,e,r){for(var n=0,i=r;n<i.length;n++){var o=i[n],s=o.path;t.hasOwnProperty(s)&&(this.isExpensiveFormat(o.apiColumn.type)||void 0!==t[s])&&(e[s]=this.clone(o.apiColumn.type,t[s]))}return e},t.prototype.shallowCopyFields=function(t,e,r,n){for(var i=0,o=n;i<o.length;i++){var s=o[i],a=s.path;r[a]=void 0!==t[a]?t[a]:this.clone(s.apiColumn.type,e[a])}return r},t.prototype.setDefaultValues=function(t,e){for(var r=0,n=e;r<n.length;r++){var i=n[r];t[i.id]=this.getDefaultValue(i.apiColumn.type)}return t},t.prototype.compareFields=function(t,e,r){if(void 0===e)return void 0===r;if(void 0===r)return!1;switch(t){case"date":case"time":case"datetime":return this.compareMomentObjects(e,r);case"duration":return this.compareDurations(e,r);case"id":case"item":case"link":case"child":case"sibling":return e==r;case"current":case"dimension":case"distance":case"double":case"filesize":case"number":case"power":case"quantity":case"volume":case"weight":case"coordinate":case"price":case"percentage":return this.compareFloats(e,r);case"int":case"bool":case"enum":case"email":case"phone":case"url":case"text":case"longtext":case"color":case"order":return e===r;default:return M(e,r)}},t.prototype.compareFloats=function(t,e){var r=Math.abs(t),n=Math.abs(e),i=Math.abs(t-e);return t===e||(0===t||0===e||i<Number.MIN_VALUE?i<1.19e-7*Number.MIN_VALUE:i/Math.min(r+n,Number.MAX_VALUE)<1.19e-7)},t.prototype.compareMomentObjects=function(t,e){return t.isValid()?!!e.isValid()&&t.isSame(e):!e.isValid()},t.prototype.compareDurations=function(t,e){return t.asMilliseconds()===e.asMilliseconds()},t.prototype.formatResponseValue=function(t,e){switch(t){case"datetime":case"date":return this.formatResponseDate(e);case"color":return this.formatResponseColor(e);case"duration":return this.formatResponseDuration(e);case"json":return"string"==typeof e&&""!==e?JSON.parse(e):e;case"number":return 0===e?null:e;case"filesize":return e/1e6;default:return e}},t.prototype.formatRequestValue=function(t,e){switch(t){case"datetime":return this.formatRequestDateTime(e);case"date":return this.formatRequestDate(e);case"color":return this.formatRequestColor(e);case"duration":return this.formatRequestDuration(e);case"number":return 0===e?null:e;default:return e}},t.prototype.formatResponseDate=function(t){return null===t?n.invalid():n(t)},t.prototype.formatResponseDuration=function(t){return n.duration(null===t?0:t,"seconds")},t.prototype.formatResponseColor=function(t){return"#"===t.charAt(0)?t:"#"+t},t.prototype.formatRequestDateTime=function(t){return t.isValid()?t.format(this.SERVER_DATETIME_FORMAT):null},t.prototype.formatRequestDate=function(t){return t.isValid()?t.format(this.SERVER_DATE_FORMAT):null},t.prototype.formatRequestDuration=function(t){return t.asSeconds()},t.prototype.formatRequestColor=function(t){return"#"===t.charAt(0)?t.substring(1):t},t.prototype.getDefaultValue=function(t){switch(t){case"int":case"double":case"percentage":case"price":case"order":return 0;case"item":case"link":case"child":case"sibling":return null;case"bool":return!1;case"enum":return"0";case"date":case"datetime":case"time":return n.invalid();case"duration":return n.duration();case"text":case"longtext":return"";case"color":return"#000000";default:return""}},t.prototype.isDefaultValue=function(t,e){return this.compareFields(t,e,this.getDefaultValue(t))},t.prototype.clone=function(t,e){switch(t){case"duration":return this.cloneDuration(e);case"date":case"datetime":return n(e);case"json":return x(e);default:return e}},t.prototype.getCloneFunction=function(t){switch(t){case"duration":return this.cloneDuration;case"date":case"datetime":return this.cloneDate;default:return this.identity}},t.prototype.cloneDuration=function(t){return n.duration(t)},t.prototype.cloneDate=function(t){return t.clone()},t.prototype.identity=function(t){return t},t}(),O=function(){function t(t,e){this.externalApiRequestService=t,this.apiResponseProcessorFactory=e}return t.prototype.template=function(t,e){return this.processResponse(this.externalApiRequestService.template(t,e))},t.prototype.create=function(t,e,r,n,i){return this.processResponse(this.externalApiRequestService.create(t,e,r,n,i))},t.prototype.delete=function(t,e){return this.processResponse(this.externalApiRequestService.delete(t,e))},t.prototype.updateItems=function(t,e,r){return this.processResponse(this.externalApiRequestService.updateItems(t,e,r))},t.prototype.requestSkeleton=function(t,e){return this.processResponse(this.externalApiRequestService.requestSkeleton(t,e))},t.prototype.moveItems=function(t,e,r){return this.processResponse(this.externalApiRequestService.moveItems(t,e,r))},t.prototype.columns=function(t,e,r){return this.processResponse(this.externalApiRequestService.columns(t,e,r))},t.prototype.query=function(t,e,r,n){return this.processResponse(this.externalApiRequestService.query(t,e,r,n))},t.prototype.processResponse=function(t){var e=this;return t.then(function(t){return e.apiResponseProcessorFactory.construct(t)})},t}(),P=function(){function t(t,e){this.apiFormatter=t,this.response=e,this.columnIndexMap={},this.columnMap={},this.columns=e.columns,this.items=e.items,this.links=e.links,this.cacheable=e.cacheable,this.map=e.map,this.itemType=e.itemType,this.createColumnMaps()}return t.prototype.createColumnMaps=function(){for(var t in this.columns){this.columnIndexMap[t]={},this.columnMap[t]={};for(var e=0;e<this.columns[t].length;e++){var r=this.columns[t][e];this.columnIndexMap[t][r.id]=e,this.columnMap[t][r.id]=r}}},t.prototype.fetchColumnObject=function(t){return this.columnMap[t]},t.prototype.fetchValue=function(t,e,r){if(void 0!==this.items[t][e]){var n=this.columnMap[t][r],i=this.columnIndexMap[t][r];return this.apiFormatter.formatResponseValue(n.type,this.items[t][e].data[i])}},t.prototype.fetchColumnArray=function(t){for(var e=[],r=0,n=this.columns[t];r<n.length;r++){var i=n[r];e.push(i)}return e},t.prototype.fetchDerivedObject=function(t,e,r){for(var n={},i=0,o=r;i<o.length;i++){var s=o[i];this.fetchDerivedValues(this.fetchValue(t,e,s.id),s,n)}return n},t.prototype.fetchDerivedValues=function(t,e,r){for(var n=0,i=e.children;n<i.length;n++){var o=i[n],s=void 0;null===t?(s=null,r[o.path]=this.apiFormatter.getDefaultValue(o.apiColumn.type)):(s=this.fetchValue(e.itemType,t,o.id),r[o.path]=s),o.isLeaf||this.fetchDerivedValues(s,o,r)}},t.prototype.fetchObject=function(t,e,r){var n=this;if((void 0===r&&(r=!1),void 0!==this.items[t])&&void 0!==this.items[t][e]){for(var i=this.items[t][e].data,o={},s=function(e){var r=a.columns[t][e];a.apiFormatter.isExpensiveFormat(r.type)?Object.defineProperty(o,r.id,{enumerable:!0,configurable:!0,set:function(t){delete o[r.id],o[r.id]=t},get:function(){return delete o[r.id],o[r.id]=n.apiFormatter.formatResponseValue(r.type,i[e])}}):o[r.id]=a.apiFormatter.formatResponseValue(r.type,i[e])},a=this,c=0;c<i.length;c++)s(c);if(r){var u=this.items[t][e].links;for(var l in o.__links={},u)o.__links[l]=this.fetchObjectArray(l,r,u[l])}return o}},t.prototype.fetchObjectArray=function(t,e,r){var n=[];if(null===r){for(var i in this.items[t])n.push(this.fetchObject(t,i,e));return n}void 0===r&&(r=this.links[t]);for(var o=0,s=r;o<s.length;o++){i=s[o];n.push(this.fetchObject(t,i,e))}return n},t.prototype.fetchColumnsObject=function(){return this.columnMap},t}(),L=function(){function t(t){this.transaction=t,this.compilation={create:{},delete:{},update:{},move:{}},this.processDelta()}return t.prototype.processDelta=function(){var t=this.transaction.getDelta();for(var e in t.deleted)for(var r=0,n=t.deleted[e];r<n.length;r++){var i=n[r];i.isLocal()||this.addDeleteEntry(i)}for(var o in t.created){var s=t.created[o];this.addCreateEntry(s)}for(var o in t.updated){s=t.updated[o];this.addUpdateEntry(s.entry)}for(var o in t.moved){s=t.moved[o];this.addMoveEntry(s.entry,s.to)}},t.prototype.getDefaultParent=function(){return{itemType:"Void",itemId:0}},t.prototype.addMoveEntry=function(t,e){p(this.compilation.move,[e.itemType,e.itemId],[{},[]]).push(t)},t.prototype.addDeleteEntry=function(t){p(this.compilation.delete,[t.itemType],[[]]).push(t)},t.prototype.addUpdateEntry=function(t){p(this.compilation.update,[t.itemType,t.itemId],[{},t])},t.prototype.addCreateEntry=function(t){var e=this.transaction.getParent(t.entry);null===e&&(e=this.getDefaultParent()),p(this.compilation.create,[e.itemType,e.itemId,t.entry.itemType,t.entry.itemId],[{},{},{},t])},t}(),j=function(){function t(t,e,r,n,i,o,s,a,c,u,l,h,p){this.changesDeltaFactory=t,this.apiRequestService=e,this.changesCompilationFactory=r,this.columnExpansionFactory=n,this.createRequestFactory=i,this.errorHandler=o,this.promiseService=s,this.requestColumnExpansionFactory=a,this.collectionEntryService=c,this.itemEntryService=u,this.transaction=l,this.breakUpByParent=h,this.onAfterCreateCallback=p,this.itemIdConversionMap={},this.serverCache=this.transaction.getServerCache()}return t.prototype.execute=function(){var t=this,e=this.changesCompilationFactory.construct(this.transaction),r=e.compilation;return this.executeCreateRequests(e).then(function(){return t.executeMoveRequests(r.move)},this.errorHandler.reject).then(function(){return t.executeUpdateRequests(r.update)},this.errorHandler.reject).then(function(){return t.executeDeleteRequests(r.delete)},this.errorHandler.reject).then(function(){return t.itemIdConversionMap},this.errorHandler.reject)},t.prototype.buildMoveRequest=function(t){for(var e={},r=0,n=t;r<n.length;r++){var i=n[r],o=i.itemType;void 0===e[o]&&(e[o]=[]),e[o].push(i.itemId)}return e},t.prototype.getMapValue=function(t,e,r){if(void 0===r&&(r=this.itemIdConversionMap),void 0!==r&&void 0!==r[t])return r[t][e]},t.prototype.executeCreateRequests=function(t){for(var e=this,r=[],n=0,i=this.createRequestFactory.construct(t.compilation.create,this.transaction,this.breakUpByParent).run();n<i.length;n++){var o=i[n];r.push(this.executeCreateRequest(o).then(function(t){return void 0!==e.onAfterCreateCallback&&e.onAfterCreateCallback(e.itemIdConversionMap),t},this.errorHandler.reject))}return this.promiseService.all(r)},t.prototype.executeCreateRequest=function(t){var e=this;return this.apiRequestService.requestSkeleton(t.request).then(function(r){var n=e.changesDeltaFactory.construct(),i=r.map,o=r.fetchColumnsObject(),a=t.items;for(var c in a){var u=e.columnExpansionFactory.construct(c,t.request.columns[c],o);for(var l in a[c]){var h=a[c][l],p=e.getMapValue(c,parseInt(l,10),i);if(void 0!==p){var d=e.transaction.itemHandler.entries.get(c,l);d.itemId=p,e.serverCache.itemHandler.itemChanges[d.id]=e.serverCache.itemHandler.copyTransactionItemEntryChanges(e.transaction.itemHandler.itemChanges[d.id],d),e.serverCache.itemHandler.entries.add(d),e.transaction.itemHandler.entries.clearByItemId(c,Number(l)),e.serverCache.itemHandler.processApiResponse(n,r,h.itemType,Number(p),h.columns,u)}else console.warn("Create failed!",h)}}for(var c in i)for(var l in void 0===e.itemIdConversionMap[c]&&(e.itemIdConversionMap[c]={}),i[c])e.itemIdConversionMap[c][l]=i[c][l];for(var f=0,m=e.transaction.collectionHandler.entries.toArray();f<m.length;f++){var y=m[f],v=y.parent;if(null!==v){var g=e.getMapValue(v.itemType,v.itemId);if(void 0!==g){v.itemId=g;var C=e.transaction.collectionHandler.getCollectionChanges(y.itemType,y.query.string);void 0!==e.transaction.collectionHandler.collectionChanges[y.itemType]&&delete e.transaction.collectionHandler.collectionChanges[y.itemType][y.query.string],y.query=e.collectionEntryService.createQuery(y.options),void 0!==C&&e.transaction.collectionHandler.setCollectionChanges(y.itemType,y.query.string,C)}}var I=y.getUpdatedItemColumns(e.itemIdConversionMap);s(I)&&(void 0!==I.id&&e.transaction.collectionHandler.onItemEntriesCreated(y,e.itemIdConversionMap[y.itemType]))}return e.serverCache.applyChangesDelta(n)},this.errorHandler.reject)},t.prototype.executeUpdateRequests=function(t){var e=[];for(var r in t)e.push(this.executeUpdateRequest(r,t[r]));return this.promiseService.all(e)},t.prototype.executeUpdateRequest=function(t,e){var r=this,n={},i=this.requestColumnExpansionFactory.construct(),o=this.transaction.collectionHandler.getCollectionMatcher();for(var s in n[t]={},e){var a=e[s],c=n[t][s]={},u=d(this.transaction.tabRequestParameters,[t,s]);c.values=this.transaction.itemHandler.formatRequest(a),void 0!==u&&(c.parameters=u),i.expand(a.columns),o.expand(a,this.transaction.itemHandler.itemChanges[a.id].changes)}for(var l=0,h=o.getCollectionsWithFittingItems();l<h.length;l++){var p=h[l];i.expand(p.columns)}var f=i.get();return this.apiRequestService.updateItems(t,n,f).then(function(t){return r.serverCache.processResponse(t,f,!0,!1)},this.errorHandler.reject)},t.prototype.executeDeleteRequests=function(t){var e=[];for(var r in t)e.push(this.executeDeleteRequest(r,t[r]));return this.promiseService.all(e)},t.prototype.executeDeleteRequest=function(t,e){var r=this;return this.apiRequestService.delete(t,e.map(function(t){return t.itemId})).then(function(t){for(var n=r.changesDeltaFactory.constructInternalDelta(),i=t.items,o=[],s=0,a=e;s<a.length;s++){var u=a[s];c(u.itemId,i)?o.push(u):console.warn("Delete failed!",u)}return n.setItemsDeleted(o),r.serverCache.applyChangesFromParent(n,!0)},this.errorHandler.reject)},t.prototype.executeMoveRequests=function(t){var e=this,r=[],n=function(n,i){var o=t[n][i],s=e.getMapValue(n,i);r.push(e.apiRequestService.moveItems(n,void 0!==s?s:i,e.buildMoveRequest(o)).then(function(){for(var t=e.changesDeltaFactory.constructInternalDelta(),r=0,a=o;r<a.length;r++){var c=a[r];t.setItemUpdated(c,e.itemEntryService.getLinkFieldsByParent({itemType:n,itemId:void 0!==s?s:i},c.itemType))}return e.serverCache.applyChangesFromParent(t,!0)},e.errorHandler.reject))};for(var i in t)for(var o in t[i])n(i,+o);return this.promiseService.all(r)},t}(),B=function(){return function(t){this.columns=!0,this.parent=null,this.templateOptions={},i(this,t)}}(),A=function(){return function(t){this.edit=!1,this.remote=!1,this.onChange=Je,i(this,t)}}(),Q=0,V=function(){function t(t,e,r,n){this.factory=t,this.itemType=e,this.itemId=r,this.columns=n,this.id=++Q,this.reloadQueued=!1}return t.prototype.queueReload=function(){return this.reloadQueued=!0,this},t.prototype.isLocal=function(){return this.factory.keyService.isLocalId(this.itemId)},t.prototype.isLockable=function(){if(this.isLocal())return!1;switch(this.itemType){case"Project":case"Materiaal":case"Contact":case"Medewerker":case"Voertuig":case"Template":return!0;default:return!1}},t.prototype.toJSON=function(){return{id:this.id,columns:this.columns}},t}(),U=function(){function t(t,e,r,n,i){this.factory=t,this.entry=e,this.options=r,this._isNew=n,this.transaction=i,this.columns=e.columns.response[e.columns.itemType],this.initial=this.transaction.itemHandler.itemChanges[e.id].initial,this.onConstruct()}return t.prototype.onConstruct=function(){},t.prototype.getParent=function(t){return this.transaction.getParent(this.entry,t,this.fields)},t.prototype.callOnChange=function(t){var e=this,r=this.transaction.itemHandler.itemResources[this.entry.id];if(void 0!==r)for(var n=0,i=r;n<i.length;n++){var o=i[n];try{o.options.onChange(o,t,function(r){return e.compareItemField(r,t)},!1)}catch(t){this.factory.exceptionHandler(t)}}},t.prototype.compareItemField=function(t,e){var r=this.columns[t];if(void 0===r)throw new Error("Missing column in ItemResource.compareItemField");return this.factory.apiFormatter.compareFields(r.type,this.fields[t],e[t])},t.prototype.hasChanges=function(){return this.transaction.itemHandler.detectEntryChanges(this.entry.id)},t.prototype.setTransactionParameters=function(t){p(this.transaction.tabRequestParameters,[this.entry.itemType,this.entry.itemId],[{},t])},t.prototype.isNew=function(){return this._isNew},t.prototype.isLocal=function(){return this.entry.isLocal()},t.prototype.clearResource=function(){this.transaction.clearItemResource(this)},t.prototype.toJSON=function(){var t=[];for(var e in this.columns)t.push(e);return{columns:t,fields:this.fields,entry:this.entry}},t.prototype.getDerivedValue=function(t){return this.transaction.itemHandler.getDerivedValue(this.entry,t)},t.prototype.getDerivedValues=function(t){return this.transaction.itemHandler.getDerivedValues(this.entry,t)},t}(),N=(k=function(t,e){return(k=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)},function(t,e){function r(){this.constructor=t}k(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),W=function(t){function e(e,r,n,i,o){var s=t.call(this,e,r,n,i,o)||this;return s.fields=o.itemHandler.itemChanges[r.id].changes,s}return N(e,t),e}(U),Y=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),J=function(t){function e(e,r,n,i,o){var s=t.call(this,e,r,n,i,o)||this;return s.localCopies=[],s.fields=o.itemHandler.itemChanges[r.id].changes,s}return Y(e,t),e.prototype.isNew=function(){return this._isNew},e.prototype.copyFields=function(t){void 0===t&&(t={});var e=this.entry;return this.factory.apiFormatter.copyFields(this.fields,t,e.columns.main),t},e.prototype.setFields=function(t){var e=this,r=this.columns;for(var n in t){void 0===r[n]&&console.warn("setFields: no column found for",n)}var i=this.transaction.createChangesDelta();return i.setItemUpdated(this.entry,t),this.transaction.applyChangesDelta(i).then(function(){return e},this.factory.errorHandler.reject)},e}(U),K=function(){return function(t){this.columns=[],this.query=null,this.queryParams={},this.queryColumns=[],this.parent=null,this.deferRequest=!1,this.limit=null,this.entryKey=null,i(this,t)}}(),z=function(){return function(t){this.editItems=!1,this.remoteItems=!1,this.editCollection=!1,this.enableSave=!0,this.callOnAddWithInitialItems=!1,this.onItemsCreated=Je,this.onChange=Je,this.onAdd=Je,this.onRemove=Je,this.onAddInitial=Je,this.onRemoveInitial=Je,this.resourceKey=null,this.custom=null,i(this,t)}}(),G=0,X=function(){function t(t,e,r,n,i){this.collectionEntryService=t,this.columnSetFactory=e,this.keyService=r,this.itemType=n,this.options=i,this.id=G++,this.parent=null,this.reloadQueued=!1,this.parent=i.parent,this.query=this.collectionEntryService.createQuery(i),this.columns=this.columnSetFactory.constructStub(n,i.columns)}return t.prototype.isLocal=function(){var t=this.parent;return null!==t&&this.keyService.isLocalId(t.itemId)},t.prototype.matchParent=function(t,e){var r=this.parent;return null!==r&&(r.itemType===t&&r.itemId==e)},t.prototype.extendQuery=function(t){var e=this.options;return void 0===t?this.query:(e.queryParams=t(e.queryParams),this.query=this.collectionEntryService.createQuery(e))},t.prototype.queueReload=function(){this.reloadQueued=!0},t.prototype.expandColumns=function(t){var e=t.run(this.columns);null!==e&&(this.columns=e.merged,this.options.columns=this.columns.request)},t.prototype.expandRequestColumns=function(t){this.columns.expandRequestColumns(t),this.options.columns=this.columns.request},t.prototype.getUpdatedItemColumns=function(t){for(var e={},r=0,n=this.columns.item;r<n.length;r++){var i=n[r];void 0!==t[i.apiColumn.itemType]&&(e[i.id]=i)}return e},t}(),Z=function(){function t(t,e,r,n){var i=this;this.factory=t,this.entry=e,this.options=r,this.transaction=n,this.itemIdMap={},this.items=[],this.itemIdMap={},this.columns=e.columns.response,this.onChange=function(t,e,r,n){t.compareItemField("id",e)||(delete i.itemIdMap[e.id],i.itemIdMap[t.entry.itemId]=t),i.options.onChange(t,e,function(r){return t.compareItemField(r,e)},n)},this.addItemResources(this.transaction.getCollectionChangesRecursively(this.entry.id),!0),this.onConstruct()}return t.prototype.onConstruct=function(){},t.prototype.getIdArray=function(){return this.items.map(function(t){return t.entry.itemId})},t.prototype.getItemById=function(t){return this.itemIdMap[t]},t.prototype.addItemResources=function(t,e){if(void 0===e&&(e=!1),0===t.length)return[];var r=this.items.map(function(t){return t.entry});t=t.filter(function(t){return-1===r.indexOf(t)});for(var n=this.transaction.createItemResources(t,{remote:this.options.remoteItems,edit:this.options.editItems,onChange:this.onChange}),i=0,o=n;i<o.length;i++){var s=o[i],a=s.entry.itemId;if(void 0!==this.itemIdMap[a])throw new Error("Added a resource of an entry that was already in the collection !");this.items.push(s),this.itemIdMap[a]=s}return e&&!this.options.callOnAddWithInitialItems||this.callOnAdd(n,e),n},t.prototype.removeItemResources=function(t){var e=this,r=[];return u(this.items,function(n){for(var i=0,o=t;i<o.length;i++){var s=o[i];if(n.entry===s)return n.clearResource(),r.push(n),delete e.itemIdMap[s.itemId],!1}return!0}),r},t.prototype.callOnAdd=function(t,e){void 0===e&&(e=!1);try{this.options.onAdd(t,this,e)}catch(t){this.factory.exceptionHandler(t)}},t.prototype.callOnRemove=function(t){try{this.options.onRemove(t,this)}catch(t){this.factory.exceptionHandler(t)}},t.prototype.forEach=function(t){for(var e=0,r=this.items;e<r.length;e++){t(r[e])}},t.prototype.filter=function(t){for(var e=[],r=0,n=this.items;r<n.length;r++){var i=n[r];t(i)&&e.push(i)}return e},t.prototype.first=function(t){for(var e=0,r=this.items;e<r.length;e++){var n=r[e];if(t(n))return n}return null},t.prototype.some=function(t){return null!==this.first(t)},t.prototype.groupBy=function(t){var e=this.items,r={};if("string"==typeof t){if(void 0===this.entry.columns.response[this.entry.itemType][t])throw new Error("Trying to group on a column not requested by this collection! (column '"+t+"')");for(var n=0,i=e;n<i.length;n++){void 0===r[c=(a=i[n]).fields[t]]&&(r[c]=[]),r[c].push(a)}}if("function"==typeof t)for(var o=0,s=e;o<s.length;o++){var a,c;null!==(c=t(a=s[o]))&&(void 0===r[c]&&(r[c]=[]),r[c].push(a))}return r},t.prototype.map=function(t){var e=this.items,r=e.length,n=new Array(r);if("string"==typeof t)for(var i=0;i<r;i++)n[i]=e[i].fields[t];if("function"==typeof t)for(i=0;i<r;i++)n[i]=t(e[i]);return n},t.prototype.reduce=function(t,e){for(var r=0,n=this.items;r<n.length;r++){e=t(n[r],e)}return e},t.prototype.extend=function(t){return this.transaction.collectionHandler.extendCollectionEntry(this.entry,t)},t.prototype.clearResource=function(t){if(void 0===t&&(t=!0),t)for(var e=0,r=this.items;e<r.length;e++){r[e].clearResource()}this.transaction.clearCollectionResource(this)},t}(),$=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),tt=function(t){function e(e,r,n,i){return t.call(this,e,r,n,i)||this}return $(e,t),e}(Z),et=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),rt=function(t){function e(e,r,n,i){return t.call(this,e,r,n,i)||this}return et(e,t),e.prototype.moveItems=function(t,e){if(this.options.enableSave)throw new Error("collectionResourceService: Cannot move items: saving enabled");return this.transaction.collectionHandler.moveItems(this.entry,e.entry,t)},e.prototype.removeItems=function(t){for(var e=this.factory.changesDeltaFactory.construct(),r=[],n=0,i=this.items;n<i.length;n++){var o=i[n].entry;-1!==t.indexOf(o.itemId)&&r.push(o)}e.setItemsDeleted(r),this.transaction.applyChangesDelta(e)},e.prototype.removeItem=function(t){return this.removeItems([t])},e.prototype.addItems=function(t){return this.transaction.itemHandler.createItems(this.entry.itemType,t,this.entry.parent)},e.prototype.addItem=function(t){return this.addItems([t])},e}(Z),nt=function(){return function(t,e,r,n,i){this.itemType=e,this.response=r,this.fields=r.fetchObject(e,r.links[e][0]);var o=r.fetchColumnsObject();this.responseColumns=t.columnUtil.mergeResponseColumns(o,i).merged,this.columns=t.columnSetFactory.constructFromResponse(e,o),this.columns=this.columns.expand(n[e],!1,i).merged}}(),it=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),ot=function(t){function e(e,r,n,i,o){var s=t.call(this,e,r,n,i,o)||this;return s.fields=s.transaction.itemHandler.itemChanges[r.id].initial,s}return it(e,t),e}(W),st=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),at=function(t){function e(e,r,n,i,o){var s=t.call(this,e,r,n,i,o)||this;return s.fields=o.itemHandler.itemChanges[r.id].changes,s}return st(e,t),e}(W);!function(t){t.ITEMTABLE="itemtable",t.DIRECT="direct"}(D||(D={}));var ct,ut=function(){function t(t,e,r,n,i,o,s,a){this.columnUtil=t,this.apiFormatter=e,this.itemEntryFactory=r,this.promiseService=n,this.errorHandler=i,this.requestColumnExpansionFactory=o,this.transaction=a,this.entries=s.construct(this.transaction)}return t.prototype.getDerivedValues=function(t,e){for(var r=t,n=this.transaction.getChangesFromItemChanges(this.itemChanges[t.id]),i=0,o=e;i<o.length;i++){var s=o[i],a=r.columns.response[r.itemType][s];if(void 0===a)throw new Error("Column '"+s+"' not found on entry in ItemResource.getDerivedValue");if(null===a.itemType)throw new Error("Column '"+s+"' doesn't have children in ItemResource.getDerivedValue");var c=n[s];if(null===c)return;if(void 0===(r=this.transaction.getLocalItemEntryByItemId(a.itemType,c)))throw new Error("Derived itemEntry "+a.itemType+":"+c+" couldn't be found");n=this.transaction.getItemChangesRecursively(r.id,!1)}return n},t.prototype.getDerivedValue=function(t,e){"string"==typeof e&&(e=this.columnUtil.parseConfigColumn(e));var r=this.getDerivedValues(t,e.slice(0,-1));if(void 0!==r)return r[e[e.length-1]]},t.prototype.clearItemEntry=function(t){this.entries.clear(t),delete this.itemChanges[t.id]},t.prototype.fetchDerivedValuesByColumn=function(t,e,r){var n=this,i=e.children;if(0===i.length)return this.promiseService.when();var o=i[0];if(1===i.length&&"id"===o.apiColumn.type)throw new Error("You should use fields[columnId] instead of derived['columnId>id'] to get the id of a derived item");for(var a={},c=0,u=t;c<u.length;c++){var l=u[c];null!==(p=this.getItemIdByColumn(l,e,r))&&(void 0===a[p]&&(a[p]=[]),a[p].push(l))}if(!s(a))return this.promiseService.when();var h=[];for(var p in a)h.push(+p);for(var d=[],f=0,m=i;f<m.length;f++){var y=m[f];d.push(y.id)}return this.fetchItemEntries(e.itemType,h,new B({columns:d})).then(function(){return n.resolveDerivedValues(t,i,r)},this.errorHandler.reject)},t.prototype.resolveDerivedValues=function(t,e,r){for(var n=[],i=0,o=e;i<o.length;i++){var s=o[i];n.push(this.fetchDerivedValuesByColumn(t,s,r))}return this.promiseService.all(n).then(function(){return t},this.errorHandler.reject)},t.prototype.createItemEntry=function(t){var e=this.itemEntryFactory.construct(t.itemId,t.columns);return this.entries.add(e),e},t.prototype.getItemIdByColumn=function(t,e,r){if(0===e.level)return void 0!==r&&void 0!==r.updated[t.id]?r.updated[t.id].changes.fields[e.path]:this.transaction.getChangesFromItemChanges(this.itemChanges[t.id])[e.path];var n=this.getItemIdByColumn(t,e.parent,r),i=this.transaction.getLocalItemEntryByItemId(e.parent.itemType,n);return void 0!==r&&void 0!==r.updated[i.id]?r.updated[i.id].changes.fields[e.id]:this.transaction.getChangesFromItemChanges(this.itemChanges[i.id])[e.id]},t.prototype.expandColumnsWithCollectionColumns=function(t,e){var r=this.requestColumnExpansionFactory.construct();void 0!==e&&r.expandWithRequestColumns(t,e);for(var n=function(e){for(var n=0,i=e.collectionHandler.entries.getByItemType(t);n<i.length;n++){var o=i[n];r.expandWithRequestColumns(t,o.options.queryColumns),r.expandWithRequestColumns(t,o.options.columns)}},i=function(t){for(var e=0,r=t;e<r.length;e++){var o=r[e];n(o),i(o.children)}},o=0,s=this.transaction.getTransactionChain();o<s.length;o++){var a=s[o];n(a)}return i(this.transaction.children),r.get()[t]},t}(),lt=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),ht=function(t){function e(e,r,n,i,o,s,a,c,u,l,h,p,d,f,m,y,v,g){var C=t.call(this,p,d,f,h,c,y,m,v)||this;return C.changesDeltaFactory=e,C.exceptionHandler=r,C.templateCache=n,C.columnExpansionFactory=i,C.columnHandler=o,C.columnSetFactory=s,C.columnSubsetCacheFactory=a,C.itemEntryService=u,C.keyService=l,C.transaction=v,C.validator=g,C.deletedItems={},C.itemChanges={},C.itemResources={},C}return lt(e,t),e.prototype.copyTransactionItemEntryChanges=function(t,e){return{initial:this.apiFormatter.copyFields(t.initial,{},e.columns.main),changes:this.apiFormatter.copyFields(t.changes,{},e.columns.main)}},e.prototype.createItemEntry=function(e){var r=t.prototype.createItemEntry.call(this,e),n=this.itemEntryService.getLocalDefaultValues();for(var i in n)e.fields[i]=n[i];var o=this.apiFormatter.copyFields(e.fields,{},e.columns.main);return this.itemChanges[r.id]={initial:e.fields,changes:o},this.itemChanges[r.id].initial.id=r.itemId,this.itemChanges[r.id].changes.id=r.itemId,void 0!==this.validator&&this.validator.validateItem(r,e.fields,e.fields),r},e.prototype.formatRequest=function(t){var e=t.columns.main;return t.isLocal()?this.apiFormatter.formatRequestLocal(this.itemChanges[t.id].changes,e):this.apiFormatter.formatRequest(this.itemChanges[t.id].initial,this.itemChanges[t.id].changes,e)},e.prototype.createItems=function(t,e,r){for(var n,i=this,o=[],s=this.changesDeltaFactory.construct(),a=((n={})[t]=this.expandColumnsWithCollectionColumns(t),n),c=function(e){var n=u.keyService.getLocalId();o.push(u.templateCache.fetchTemplate(t,n,{},a,r).then(function(o){i.resolveLocal(s,t,n,r,o,function(){return!0},function(r,n){if(r===t)for(var i in e)n[i]=e[i]})},u.errorHandler.reject))},u=this,l=0,h=e;l<h.length;l++){c(h[l])}return this.promiseService.all(o).then(function(){return i.transaction.applyChangesDelta(s)})},e.prototype.clearItemEntry=function(e){t.prototype.clearItemEntry.call(this,e),delete this.itemResources[e.id]},e.prototype.addResource=function(t){var e=this.itemResources[t.entry.id];void 0===e&&(e=this.itemResources[t.entry.id]=[]),e.push(t)},e.prototype.clearResource=function(t){var e=this.itemResources[t.entry.id];if(void 0!==e){var r=e.indexOf(t);-1!==r&&e.splice(r,1),0===e.length&&delete this.itemResources[t.entry.id]}},e.prototype.detectChanges=function(){for(var t in this.entries.entriesByEntryId)return!0;for(var e in this.deletedItems)if(this.deletedItems[e].length>0)return!0;for(var r in this.itemChanges){if(this.detectEntryChanges(Number(r)))return!0}return!1},e.prototype.detectEntryChanges=function(t){var e=this.transaction.getLocalItemEntry(t),r=this.itemChanges[t];return this.apiFormatter.hasChanges(r.initial,r.changes,e.columns.main)},e.prototype.processItemEntryChanges=function(t,e,r,n,i){void 0===e&&(e=!1),void 0===r&&(r=!1),void 0===n&&(n=!1),void 0===i&&(i=!1);var o=t.entry,s=t.changes;if(void 0===this.itemChanges[o.id]){if(!i)return null;this.itemChanges[o.id]={initial:this.transaction.getItemChangesRecursively(o.id),changes:this.transaction.getItemChangesRecursively(o.id)}}null!==s.expandedColumns&&(o.columns=s.expandedColumns.merged);var a=this.itemChanges[o.id],c=this.apiFormatter.copyFields(a.changes,{},o.columns.main),u=this.apiFormatter.hasChanges(s.fields,a.changes,o.columns.main,!0);if(e?this.apiFormatter.copyFields(s.fields,a.changes,o.columns.main):this.apiFormatter.mergeCopyFields(a.initial,a.changes,s.fields,o.columns.main),r&&this.apiFormatter.copyFields(s.fields,a.initial,o.columns.main),void 0===s.fields.displayname){var l=this.itemEntryService.getDisplayName(o,a.changes);void 0!==l&&(a.changes.displayname=l)}if(u){void 0!==this.validator&&this.validator.validateItem(o,a.changes,c);var h=this.itemResources[o.id];if(void 0!==h)for(var p=function(t){try{t.options.onChange(t,c,function(e){return t.compareItemField(e,c)},n)}catch(t){d.exceptionHandler(t)}},d=this,f=0,m=h;f<m.length;f++){p(m[f])}}return c},e.prototype.cloneItemEntries=function(t,e,r){void 0===e&&(e={});var n=this.changesDeltaFactory.construct();this.itemEntryService.batchExpandConversionMap(t,e);for(var i=0,o=t;i<o.length;i++){var s=o[i];this.cloneItemEntry(n,s,{},e,r)}return this.transaction.applyChangesDelta(n)},e.prototype.cloneItemEntry=function(t,e,r,n,i){void 0===r&&(r={}),void 0===n&&(n={});var o=this.transaction.getItemChangesRecursively(e.id),s=this.itemEntryService.expandConversionMap(e,n),a=this.transaction.getParent(e),c=null;if(null!==a){var u=this.itemEntryService.getConversionValue(a.itemType,a.itemId,n);c={itemType:a.itemType,itemId:u||a.itemId}}var l=this.apiFormatter.copyFields(o,{},e.columns.main),h=this.updateItemValues(l,c,e.columns.item,n);for(var p in h)l[p]=h[p];for(var p in r)l[p]=r[p];return void 0!==i&&i(e,l),t.setItemCreated(s,l,e.columns),s},e.prototype.fetchItemEntriesByQuery=function(t,e,r){return this.transaction.getServerCache().itemHandler.fetchItemEntriesByQuery(t,e,r)},e.prototype.fetchItemEntry=function(t,e,r){var n=this;if(!this.keyService.isLocalId(e))return this.transaction.getServerCache().itemHandler.fetchItemEntry(t,e,r);if(void 0===this.entries.get(t,e))return this.transaction.parent instanceof Gt?this.errorHandler.reject(this.itemEntryService.createUnfoundLocalItemError(t)):this.transaction.parent.itemHandler.fetchItemEntry(t,e,r);r.columns=this.expandColumnsWithCollectionColumns(t,r.columns);var i=this.changesDeltaFactory.construct(),o=this.columnSubsetCacheFactory.construct(r.columns);return this.fetchLocalItemEntryData(i,t,e,o,r).then(function(t){return n.transaction.applyChangesDelta(i).then(function(){return t},n.errorHandler.reject)},this.errorHandler.reject)},e.prototype.fetchNewItemEntry=function(t,e,r){var n,i,o=this;return void 0!==this.entries.get(t,e)?this.errorHandler.reject(this.itemEntryService.createExistingLocalItemError(t)):this.templateCache.fetchTemplate(t,e,r.templateOptions,(n={},n[t]=r.columns,n),r.parent).then(function(n){if(void 0!==o.entries.get(t,e))return o.errorHandler.reject(o.itemEntryService.createExistingLocalItemError(t));var i=o.changesDeltaFactory.construct();return o.resolveLocal(i,t,e,r.parent,n),o.transaction.applyChangesDelta(i)},this.errorHandler.reject).then(function(t){var e=(i=t).created.reduce(function(t,e){return t.hasOwnProperty(e.itemType)||(t[e.itemType]=[]),t[e.itemType].push(e),t},{}),r=o.transaction.createChangesDelta(),n=[];for(var s in e)n.push(o.resolveDerivedValues(e[s],e[s][0].columns.root,r));return o.promiseService.all(n)}).then(function(){return i})},e.prototype.fetchItemEntries=function(t,e,r){for(var n=[],i=[],o=0,s=e;o<s.length;o++){var a=s[o];this.keyService.isLocalId(a)?i.push(a):n.push(a)}return this.promiseService.all({remote:this.transaction.getServerCache().itemHandler.fetchItemEntries(t,n,r),local:this.fetchLocalItemEntries(t,i,r)}).then(function(t){return t.remote.concat(t.local)})},e.prototype.fetchTitle=function(t,e){var r=this,n=this.itemEntryService.getTitleField(t);return this.fetchItemEntry(t,e,new B({columns:[n]})).then(function(t){return r.transaction.getItemChangesRecursively(t.id,!1)[n]},this.errorHandler.reject)},e.prototype.resolveLocalItemEntry=function(t,e,r,n){var i=this;if(r.run(e.columns))return this.promiseService.when(e);var o=this.getColumnDifference(e,n.columns);return this.columnHandler.fetch(e.itemType,o).then(function(r){return i.expandLocalItemEntries(t,e.itemType,[e],o,r)},this.errorHandler.reject).then(function(){return e},this.errorHandler.reject)},e.prototype.createLocalEntries=function(t,e,r,n,i,o,s){var a=this;void 0===o&&(o=function(){return!0});var c=n.response,u={},l=function(e,r,h){var p={itemType:e,itemId:r},d=c.items[e][h].links;for(var f in d)if(d.hasOwnProperty(f)){void 0===u[f]&&(u[f]=a.columnSetFactory.construct(f,!0,n.responseColumns));for(var m=0,y=d[f];m<y.length;m++){var v=y[m],g=c.fetchObject(f,v);if(o(f,g)){var C=i[f][v],I=a.updateItemValues(g,p,u[f].item,i);for(var E in I)g[E]=I[E];void 0!==s&&s(f,g,i),t.setItemCreated(C,g,u[f],p),l(f,C,v)}}}};l(e,r,c.links[e][0])},e.prototype.expandLocalItemEntries=function(t,e,r,n,i){if(0===r.length)return this.promiseService.when(r);for(var o=this.columnExpansionFactory.construct(e,n,i),s=0,a=r;s<a.length;s++){var c=a[s],u=o.run(c.columns);null!==u&&this.expandLocalItemEntry(t,c,u)}return this.resolveDerivedValues(r,o.aggregateRootColumns())},e.prototype.updateItemValues=function(t,e,r,n){for(var i={},o=0,s=r;o<s.length;o++){var a=s[o],c=a.id,u=a.apiColumn,l=void 0;"link"===u.type&&void 0===t[c]?null!==e&&(l=e.itemId):l=this.itemEntryService.getConversionValue(u.itemType,t[c],n),void 0!==l&&(i[c]=l)}return i},e.prototype.fetchLocalItemEntryData=function(t,e,r,n,i){var o=this.entries.get(e,r);return void 0===o?this.errorHandler.reject(this.itemEntryService.createUnfoundLocalItemError(e)):this.resolveLocalItemEntry(t,o,n,i)},e.prototype.fetchLocalItemEntries=function(t,e,r){var n=this;r.columns=this.expandColumnsWithCollectionColumns(t,r.columns);for(var i=this.changesDeltaFactory.construct(),o=this.columnSubsetCacheFactory.construct(r.columns),s=[],a=[],c=0,u=e;c<u.length;c++){var l=u[c];if(void 0!==this.entries.get(t,l))s.push(this.fetchLocalItemEntryData(i,t,l,o,r));else{if(this.transaction.parent instanceof Gt)return this.errorHandler.reject(this.itemEntryService.createUnfoundLocalItemError(t));a.push(l)}}if(a.length>0){if(this.transaction.parent instanceof Gt)throw new Error("Tried looking for local entries on the serverCache");s.push(this.transaction.parent.itemHandler.fetchLocalItemEntries(t,a,r))}return this.promiseService.all(s).then(function(){return n.transaction.applyChangesDelta(i).then(function(){return e.map(function(e){return n.transaction.getLocalItemEntryByItemId(t,e)})},n.errorHandler.reject)},this.errorHandler.reject)},e.prototype.getColumnDifference=function(t,e){return this.columnUtil.mergeRequestColumns(t.columns.request,e).difference},e.prototype.resolveLocal=function(t,e,r,n,i,o,s){void 0===o&&(o=function(){return!0});var a=this.itemEntryService.createLocalConversionMap(e,r,!0,i.response),c=this.apiFormatter.copyFields(i.fields,{},i.columns.main),u=this.updateItemValues(c,n,i.columns.item,a);for(var l in u)c[l]=u[l];void 0!==s&&s(e,c,a),t.setItemCreated(r,c,i.columns,n),this.createLocalEntries(t,e,r,i,a,o,s)},e.prototype.expandLocalItemEntry=function(t,e,r){var n=r.difference.main;if(e.columns=r.merged,0!==n.length){var i=this.getLocalValues(e,n);s(i)&&t.setItemUpdated(e,i,r)}},e.prototype.getLocalValues=function(t,e){for(var r=this.transaction.getParent(t),n=this.transaction.getChangesFromItemChanges(this.itemChanges[t.id]),i={},o=0,s=e;o<s.length;o++){var a=s[o],c=a.id;if(void 0===n[c]){var u=a.apiColumn.type;i[c]="link"===u&&null!==r?r.itemId:this.apiFormatter.getDefaultValue(u)}}return i},e}(ut),pt=function(){function t(t,e,r,n,i,o,s,a,c,u,l,h,p,d,f,m,y,v,g,C,I,E,F,S,R,q,T,w,b,H,M,x,k){this.core=t,this.columnCache=e,this.requestBufferManager=r,this.requestColumnExpansionFactory=n,this.queryMatcherFactory=i,this.authInterface=o,this.changesDeltaFactory=s,this.lockService=a,this.moduleChangesCompilationFactory=c,this.collectionResourceFactory=u,this.itemResourceFactory=l,this.templateCache=h,this.itemCacheFactory=p,this.collectionCacheFactory=d,this.errorHandler=f,this.exceptionHandler=m,this.promiseService=y,this.apiRequestService=v,this.columnExpansionFactory=g,this.columnHandler=C,this.columnSetFactory=I,this.columnSubsetCacheFactory=E,this.columnUtil=F,this.itemEntryFactory=S,this.itemEntryService=R,this.keyService=q,this.collectionEntryFactory=T,this.collectionEntryService=w,this.collectionMatcherFactory=b,this.queryParserFactory=H,this.queryService=M,this.apiFormatter=x,this.linkTreeService=k,this.children=[]}return t.prototype.createChild=function(t,e){var r=new Ft(this.core,this.columnCache,this.requestBufferManager,this.requestColumnExpansionFactory,this.queryMatcherFactory,this.authInterface,this.changesDeltaFactory,this.lockService,this.moduleChangesCompilationFactory,this.collectionResourceFactory,this.itemResourceFactory,this.templateCache,this.itemCacheFactory,this.collectionCacheFactory,this.errorHandler,this.exceptionHandler,this.promiseService,this.apiRequestService,this.columnExpansionFactory,this.columnHandler,this.columnSetFactory,this.columnSubsetCacheFactory,this.columnUtil,this.itemEntryFactory,this.itemEntryService,this.keyService,this.collectionEntryFactory,this.collectionEntryService,this.collectionMatcherFactory,this.queryParserFactory,this.queryService,this.apiFormatter,this.linkTreeService,this,t,e);return this.children.push(r),r},t.prototype.onChildDestroy=function(t){var e=this.children.indexOf(t);-1!==e&&this.children.splice(e,1)},t.prototype.getTransactionChain=function(){var t=[],e=this;do{t.push(e),e=e.parent}while(null!==e);return t},t.prototype.getCurrentCollectionEntryCache=function(){return this.collectionHandler.entries},t.prototype.getCurrentItemEntryCache=function(){return this.itemHandler.entries},t.prototype.getParentFromFields=function(t,e){if(void 0===e)return null;if(null!==t.columns.link)return{itemType:t.columns.link.apiColumn.itemType,itemId:e[t.columns.link.id]};var r=t.columns.response[t.itemType];return void 0!==r.itemtype&&void 0!==r.item?{itemType:e.itemtype,itemId:e.item}:null},t.prototype._applyChangesDelta=function(t){var e=this,r=this.changesDeltaFactory.constructInternalDelta();for(var n in t._queryResults)for(var i in t._queryResults[n])r._setQueryResult(n,i,t._queryResults[n][i]);for(var o=[],s=[],a=function(t){var e=c.itemHandler.createItemEntry(t);o.push(e),r.setItemCreated(e,c.getChangesFromItemChanges(c.itemHandler.itemChanges[e.id])),s.push(function(t){return t.setItemDeleted(e)})},c=this,u=0,l=t.created;u<l.length;u++){a(l[u])}var h=function(e){var n=t.updated[e],i=p.itemHandler.processItemEntryChanges(n,!0,!1,!1,!0);if(r.setItemUpdated(n.entry,n.changes.fields,n.changes.expandedColumns),null!==i&&s.push(function(t){return t.setItemUpdated(n.entry,i)}),null!==n.changes.parent&&r.setItemMoved(n.entry,n.changes.parent),p.itemHandler instanceof ht){var o=p.itemHandler.deletedItems[n.entry.itemType];if(void 0===o)return"continue";var a=o.indexOf(n.entry);a>-1&&o.splice(a,1)}},p=this;for(var d in t.updated)h(d);return{result:{created:o,rollback:function(){for(var t=e.changesDeltaFactory.construct(),r=0,n=s;r<n.length;r++){(0,n[r])(t)}return e.applyChangesDelta(t)}},internalChangesDelta:r,rollbackFunctions:s}},t.prototype.fetchUpdatedDerivedValuesFromDelta=function(t){var e=[];for(var r in t.updated){for(var n=t.updated[r],i=[],o=0,s=n.entry.columns.root;o<s.length;o++){var a=s[o];n.changes.fields.hasOwnProperty(a.id)&&n.changes.fields[a.id]!==this.getChangesFromItemChanges(this.itemHandler.itemChanges[n.entry.id])[a.id]&&i.push(a)}0!==i.length&&e.push(this.itemHandler.resolveDerivedValues([n.entry],i,t))}return this.promiseService.all(e)},t}(),dt=function(){function t(t,e,r){this.queryMatcherFactory=t,this.transaction=e,this.getCollectionEntries=r,this.map={}}return t.prototype.expand=function(t,e){var r=this.queryMatcherFactory.construct(t.itemType,e,this.transaction.getParent(t));return this._expand(t,function(t){return r.matchQuery(t.query.object)})},t.prototype.processDelta=function(t){for(var e in t.deleted)for(var r=0,n=t.deleted[e];r<n.length;r++){var i=n[r];this._expand(i,function(){return!1})}var o=function(e){var r=t.created[e],n=s.queryMatcherFactory.construct(r.entry.itemType,r.fields,s.transaction.getParent(r.entry));s._expand(r.entry,function(e){var i=t._queryResults[e.itemType];if(void 0!==i){var o=i[e.query.string];if(void 0!==o&&!r.entry.isLocal())return-1!==o.indexOf(r.entry.itemId)}return n.matchQuery(e.query.object)})},s=this;for(var a in t.created)o(a);var c=function(e){var r=t.moved[e];u._expand(r.entry,function(t){return t.matchParent(r.to.itemType,r.to.itemId)})},u=this;for(var a in t.moved)c(a);var l=function(e){var r=t.updated[e],n={},i=h.transaction.getItemChangesRecursively(Number(e),!1),o=function(t,e){var r=Object.getOwnPropertyDescriptor(t,e);void 0!==r?Object.defineProperty(n,e,r):n[e]=t[e]};for(var s in i)o(i,s);for(var s in r.changes.fields)o(r.changes.fields,s);var a=h.queryMatcherFactory.construct(r.entry.itemType,n,h.transaction.getParent(r.entry));h._expand(r.entry,function(e){var n=t._queryResults[e.itemType];if(void 0!==n){var i=n[e.query.string];if(void 0!==i&&!r.entry.isLocal())return-1!==i.indexOf(r.entry.itemId)}return a.matchQuery(e.query.object)})},h=this;for(var a in t.updated)l(a);return this},t.prototype.hasFittingItems=function(t){for(var e in t)if(!0===t[e].isMatch)return!0;return!1},t.prototype._expand=function(t,e){for(var r=this.map,n=t.itemId,i=0,o=this.getCollectionEntries(t.itemType);i<o.length;i++){var s=o[i],a=s.id,c=void 0;void 0===r[a]&&(r[a]={collection:s,matches:{}}),void 0===(c=r[a].matches)[n]&&(c[n]={item:t,isMatch:e(s)})}return this},t}(),ft=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),mt=function(t){function e(e,r,n){return t.call(this,e,r,n)||this}return ft(e,t),e.prototype.getCollectionsWithFittingItems=function(){var t=[];for(var e in this.map){var r=this.map[e];this.hasFittingItems(r.matches)&&t.push(r.collection)}return t},e}(dt),yt=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),vt=function(t){function e(e,r,n,i){var o=t.call(this,r,n,i)||this;return o.apiRequestService=e,o}return yt(e,t),e.prototype.removeFromAndAddToCollections=function(t){var e=this;void 0===t&&(t=!1);var r=function(r){var i,o=n.map[r],s=o.collection,a=n.groupItemEntries(o.matches);n.transaction.collectionHandler.removeItemEntriesFromCollectionChanges(s,a.notFitting,t),n.transaction.collectionHandler.addItemEntriesToCollectionChanges(s,a.fitting,t),a.maybe.length>0&&n.apiRequestService.query(s.itemType,s.query.object,(i={},i[s.itemType]=["id"],i)).then(function(r){e.transaction.collectionHandler.addItemEntriesToCollectionChanges(s,a.maybe.filter(function(t){return r.links[s.itemType].indexOf(t.itemId)>-1}),t)})},n=this;for(var i in this.map)r(i)},e.prototype.groupItemEntries=function(t){var e=[],r=[],n=[];for(var i in t){var o=t[i],s=o.item,a=o.isMatch;!0===a?e.push(s):!1===a?r.push(s.itemId):n.push(s)}return{fitting:e,notFitting:r,maybe:n}},e}(mt),gt=function(){function t(t,e,r){this.errorHandler=t,this.exceptionHandler=e,this.promiseService=r,this.callbacks={onBeforeSave:[],onSaveSuccess:[]}}return t.prototype.registerCallback=function(t,e,r,n,i){var o=this;return void 0===n&&(n="always"),void 0===i&&(i=100),this.getPriorityLevel(t,i)[e]={callback:r,condition:n},function(){delete o.getPriorityLevel(t,i)[e]}},t.prototype.executeCallbacks=function(t,e,r){for(var n=this.callbacks[t],i=r?"onClose":"skipOnClose",o=this.promiseService.when(),s=0,a=n;s<a.length;s++){var c=a[s];o=o.then(this.executeCallbacksPriorityLevel(c[1],i,e),this.errorHandler.reject)}return o},t.prototype.getPriorityLevel=function(t,e){for(var r,n=this.callbacks[t],i=0;i<n.length;i++){var o=n[i];if(!(o[0]<e))return o[0]===e?o[1]:(r={},n.splice(i,0,[e,r]),r)}return r={},n.push([e,r]),r},t.prototype.executeCallbacksPriorityLevel=function(t,e,r){var n=this;return function(){var i={};for(var o in t){var s=t[o];if(s.condition===e||"always"===s.condition)try{i[o]=r(s.callback)}catch(t){n.exceptionHandler(t)}}return n.promiseService.all(i)}},t}(),Ct=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),It=function(){return(It=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};!function(t){t.warning="warning",t.error="error"}(ct||(ct={}));var Et,Ft=function(t){function e(e,r,n,i,o,s,a,c,u,l,h,p,d,f,m,y,v,g,C,I,E,F,S,R,q,T,w,b,H,M,x,k,D,_,O,P){var L=t.call(this,e,r,n,i,o,s,a,c,u,l,h,p,d,f,m,y,v,g,C,I,E,F,S,R,q,T,w,b,H,M,x,k,D)||this;return L.id=O,L.errors={item:{},global:{}},L.isValid=!0,L.tabRequestParameters={},L.isSaving=!1,L.hasChanges=!1,L.changesInterval=null,L.validator=void 0===P?void 0:P.construct(L),L.parent=_,L.itemHandler=new ht(a,y,p,C,I,E,F,m,q,T,v,S,k,R,d,i,L,L.validator),L.collectionHandler=new fe(i,S,F,C,a,f,b,H,I,m,L.itemHandler,T,v,y,L),L.eventHandler=new gt(m,y,v),L}return Ct(e,t),e.prototype.destroy=function(){this.parent.onChildDestroy(this)},e.prototype.createChangesDelta=function(){return this.changesDeltaFactory.construct()},e.prototype.getFirstErrorString=function(){for(var t in this.errors.global){if((o=this.errors.global[t]).level===ct.error)return o.string}for(var e in this.errors.item){var r=this.errors.item[e];for(var n in r){var i=r[n];for(var t in i){var o;if((o=i[t]).level===ct.error)return o.string}}}},e.prototype._setGlobalError=function(t,e,r,n){e?(this.errors.global[t]={string:r,level:n},this._setIsValid()):this.clearGlobalError(t)},e.prototype._setItemError=function(t,e,r,n,i,o){n?(p(this.errors.item,[t,e,r],[{},{},{string:i,level:o}]),this._setIsValid()):this.clearItemError(t,e,r)},e.prototype._setIsValid=function(){for(var t in this.isValid=!0,this.errors.global){if(this.errors.global[t].level===ct.error)return void(this.isValid=!1)}for(var e in this.errors.item){var r=this.errors.item[e];for(var n in r){var i=r[n];for(var t in i){if(i[t].level===ct.error)return void(this.isValid=!1)}}}},e.prototype.applyChangesFromParent=function(t,e,r){var n=this;for(var i in void 0===e&&(e=!1),void 0===r&&(r=!1),t.updated){var o=t.updated[i];this.itemHandler.processItemEntryChanges(o,e,!0,r)}for(var s in t.deleted)for(var a=0,c=t.deleted[s];a<c.length;a++){var u=c[a];if(this.itemHandler.entries.clear(u),delete this.itemHandler.itemChanges[u.id],delete this.itemHandler.itemResources[u.id],this.clearItemError(u.id),void 0!==this.itemHandler.deletedItems[u.itemType]){var l=this.itemHandler.deletedItems[u.itemType].indexOf(u);-1!==l&&this.itemHandler.deletedItems[u.itemType].splice(l,1)}}new vt(this.apiRequestService,this.queryMatcherFactory,this,function(t){return n.collectionHandler.getAllCollectionsByItemType(t)}).processDelta(t).removeFromAndAddToCollections(r);for(var h=0,p=this.children;h<p.length;h++){p[h].applyChangesFromParent(t)}this.hasChanges=!1,this.detectChanges(),void 0!==this.validator&&(this.clearGlobalError(),this.validator.validateTransaction())},e.prototype.applyChangesDelta=function(e){var r=this;return 0!==e.created.length||s(e.updated)||s(e.deleted)?this.fetchUpdatedDerivedValuesFromDelta(e).then(function(){var n=t.prototype._applyChangesDelta.call(r,e),i=n.result,o=n.internalChangesDelta,s=n.rollbackFunctions;for(var a in e.deleted)for(var c=function(t){r.itemHandler.entries.clear(t);var n=r.itemHandler.itemChanges[t.id];delete e.updated[t.id],delete r.itemHandler.itemChanges[t.id],delete r.itemHandler.itemResources[t.id],void 0===r.itemHandler.deletedItems[t.itemType]&&(r.itemHandler.deletedItems[t.itemType]=[]),r.itemHandler.deletedItems[t.itemType].push(t),o.setItemDeleted(t),r.clearItemError(t.id),s.push(function(e){e.setItemUpdated(t,n.changes)})},u=0,l=e.deleted[a];u<l.length;u++){c(l[u])}new vt(r.apiRequestService,r.queryMatcherFactory,r,function(t){return r.collectionHandler.getAllCollectionsByItemType(t)}).processDelta(o).removeFromAndAddToCollections();for(var h=0,p=r.children;h<p.length;h++){p[h].applyChangesFromParent(o)}return r.hasChanges=!1,r.detectChanges(),void 0!==r.validator&&r.validator.validateTransaction(),i}):this.promiseService.when({created:[],rollback:Je})},e.prototype.getServerCache=function(){return this.parent.getServerCache()},e.prototype.getParent=function(t,e,r){var n;if(void 0===e&&(e=!1),void 0!==r)n=r;else{var i=this.itemHandler.itemChanges[t.id];void 0!==i&&(n=i[e?"initial":"changes"])}if(void 0!==n){var o=this.getParentFromFields(t,n);if(null!==o)return o}return this.parent.getParent(t,e)},e.prototype.getCollectionChangesRecursively=function(t){var e=this.getLocalCollectionEntry(t);if(void 0===e)throw new Error("Called getCollectionChangesRecursively with a collectionEntryId that isn't cached");var r=this.collectionHandler.getCollectionChanges(e.itemType,e.query.string);return void 0===r&&(r=this.parent.getCollectionChangesRecursively(t).slice(),this.collectionHandler.setCollectionChanges(e.itemType,e.query.string,r)),r},e.prototype.getItemChangesRecursively=function(t,e){void 0===e&&(e=!0);var r=this.itemHandler.itemChanges[t],n=this.getLocalItemEntry(t);return void 0!==r&&void 0!==n?e?this.apiFormatter.copyFields(r.changes,{},n.columns.main):r.changes:this.parent.getItemChangesRecursively(t,e)},e.prototype.clearItemResource=function(t){return this.itemHandler.clearResource(t)},e.prototype.clearCollectionResource=function(t){return this.collectionHandler.clearResource(t)},e.prototype.isLockable=function(){return void 0!==this.rootItem&&this.rootItem.isLockable()},e.prototype.disableChangesWatcher=function(){null!==this.changesInterval&&(clearInterval(this.changesInterval),this.changesInterval=null)},e.prototype.enableChangesWatcher=function(){var t=this;null!==this.changesInterval&&(console.warn("Changes watcher already running!",this),this.disableChangesWatcher()),this.changesInterval=window.setInterval(function(){t.detectChanges()&&(t.disableChangesWatcher(),t.isLockable()&&t.lockService.fetchLock(t.rootItem))},3e3)},e.prototype.save=function(t,e,r,n){var i,o=this;return void 0===t&&(t=!1),void 0===e&&(e={}),this.isSaving?this.errorHandler.reject():(this.isSaving=!0,this.detectChanges(),this.disableChangesWatcher(),(this.isLockable()?this.lockService.fetchLock(this.rootItem):this.promiseService.when()).then(function(){return o.eventHandler.executeCallbacks("onBeforeSave",function(t){return t(o)},t)},this.errorHandler.reject).then(function(){return o.tabRequestParameters=It({},o.tabRequestParameters,e),o.parent.applyChangesFromChild(o,r,n)}).then(function(e){return i=e,o.tabRequestParameters={},o.isLockable()&&o.lockService.clearLock(o.rootItem),o.hasChanges=!1,o.eventHandler.executeCallbacks("onSaveSuccess",function(t){return t(o,i)},t)},this.errorHandler.reject).then(function(){return t||o.enableChangesWatcher(),o.isSaving=!1,i},this.errorHandler.reject).catch(function(t){return o.isSaving=!1,o.errorHandler.reject(t)}))},e.prototype.detectChanges=function(){return!!this.hasChanges||(this.itemHandler.detectChanges()?this.hasChanges=!0:this.hasChanges=!1)},e.prototype.clearItem=function(t){this.clearItemEntry(t.entry)},e.prototype.clearItemEntry=function(t){return this.itemHandler.clearItemEntry(t)},e.prototype.clearCollection=function(t){return this.collectionHandler.clearEntry(t.entry)},e.prototype.onBeforeSave=function(t,e,r,n){return this.eventHandler.registerCallback("onBeforeSave",t,e,r,n)},e.prototype.onSaveSuccess=function(t,e,r,n){return this.eventHandler.registerCallback("onSaveSuccess",t,e,r,n)},e.prototype.getModuleChanges=function(){if(void 0===this.rootItem)throw new Error("No root item for transaction cache "+this);return this.moduleChangesCompilationFactory.construct(this).process()},e.prototype.updateItemIdMap=function(t,e){if(void 0!==e)for(var r in e){var n=e[r];void 0!==t[r]&&(t[n]=t[r],delete t[r])}},e.prototype.cloneCollection=function(t,e,r){var n=e.parent;if(null===n||void 0===n)throw new Error("Parent required for cloneCollection");return this.createCollectionResource(this.collectionHandler.cloneCollectionEntry(t.entry,n,r),e)},e.prototype.cloneItem=function(t,e){var r=this,n=this.changesDeltaFactory.construct();return this.itemHandler.cloneItemEntry(n,t.entry),this.applyChangesDelta(n).then(function(t){var n=t.created[0];return r.createItemResource(n,e,!1)})},e.prototype.getAllLinkCollections=function(t,e,r){var n,i=this;return this.apiRequestService.query(t,{},(n={},n[t]=["id"],n)).then(function(n){return i.getLinkCollections(t,n.links[t],e,r)},this.errorHandler.reject)},e.prototype.getLinkCollectionsFromDef=function(t,e,r){var n=this;return this.collectionHandler.fetchLinkedCollectionEntries(t,e,r.itemType,r.options.entry).then(function(t){return n.createCollectionResources(t,r.options.resource)},this.errorHandler.reject)},e.prototype.getLinkCollections=function(t,e,r,n){var i=this;return this.collectionHandler.fetchLinkedCollectionEntries(t,e,r,new K(n)).then(function(t){return i.createCollectionResources(t,n)},this.errorHandler.reject)},e.prototype.getCollectionFromDef=function(t){var e=this;return this.collectionHandler.fetchCollectionEntry(t.itemType,t.options.entry).then(function(r){return e.createCollectionResource(r,t.options.resource)},this.errorHandler.reject)},e.prototype.getCollection=function(t,e){var r=this;return this.collectionHandler.fetchCollectionEntry(t,new K(e)).then(function(t){return r.createCollectionResource(t,new z(e))},this.errorHandler.reject)},e.prototype.getCollectionDef=function(t,e){return{itemType:t,options:{entry:new K(e),resource:new z(e)}}},e.prototype.getLinkCollectionsDef=function(t,e,r){return{itemType:t,linkField:e,options:{entry:new K(r),resource:new z(r)}}},e.prototype.getItemByState=function(t,e,r,n){void 0===r&&(r={});var i=this.keyService.parseStateKey(e);if(null===i){var o=e;if(!this.keyService.isLocalId(o)||this.itemHandler.entries.contains(t,o))return this.getItemById(t,o,r,n)}else if("duplicate"===i.type)return this.getDuplicateById(t,i.itemId,r,!1,n);return this.getNewResource(t,r,!1,n)},e.prototype.getDuplicateById=function(t,e,r,n,i){return void 0===r&&(r={}),void 0===r.templateOptions&&(r.templateOptions={}),void 0===r.templateOptions.item&&(r.templateOptions.item=e),this.getNewResourceWithId(t,this.keyService.getLocalDuplicateId(),r,n,i)},e.prototype.getNewResourceWithId=function(t,e,r,n,i){var o=this;return void 0===n&&(n=!1),r.edit=!0,this.itemHandler.fetchNewItemEntry(t,e,new B(r)).then(function(s){for(var a,c={},u=0,l=s.created;u<l.length;u++){var h=l[u];h.itemType!==t||h.itemId!==e?(void 0===c[h.itemType]&&(c[h.itemType]=[]),c[h.itemType].push(h)):a=h}if(void 0===a)throw new Error("The ItemEntry with the requested ItemId was not in the template response");var p=o.createItemResource(a,r,i,!0);return n?{main:p,linked:o.processLinkedItems(c,r)}:p},this.errorHandler.reject)},e.prototype.getNewResource=function(t,e,r,n){return void 0===e&&(e={}),this.getNewResourceWithId(t,this.keyService.getLocalId(),e,r,n)},e.prototype.getItemsByQuery=function(t,e,r){var n=this;void 0===r&&(r={});var i=new B(r);return this.collectionHandler.fetchItemEntriesByQuery(t,e,i).then(function(t){return n.createItemResources(t,r)},this.errorHandler.reject)},e.prototype.getItemsById=function(t,e,r){var n=this;return void 0===r&&(r={}),this.itemHandler.fetchItemEntries(t,e,new B(r)).then(function(t){return n.createItemResources(t,r)},this.errorHandler.reject)},e.prototype.getItemById=function(t,e,r,n){var i=this;return void 0===r&&(r={}),this.itemHandler.fetchItemEntry(t,e,new B(r)).then(function(t){return i.createItemResource(t,r,n)},this.errorHandler.reject)},e.prototype.fetchTitle=function(t,e){return this.itemHandler.fetchTitle(t,e)},e.prototype.applyChangesFromChild=function(t,e,r){var n=this,i=this.linkTreeService.get(),o=t.getDelta();for(var s in o.moved){var a=o.moved[s];o.setItemUpdated(a.entry,{},null,a.to),delete o.moved[s]}for(var s in o.updated){a=o.updated[s];void 0===this.itemHandler.itemChanges[s]?this.itemHandler.itemChanges[s]=this.itemHandler.copyTransactionItemEntryChanges(t.itemHandler.itemChanges[s],a.entry):this.itemHandler.processItemEntryChanges(a,!0)}for(var s in o.created){a=o.created[s];this.itemHandler.entries.add(a.entry),t.itemHandler.entries.clear(a.entry);var c=this.itemHandler.itemChanges[a.entry.id]=this.itemHandler.copyTransactionItemEntryChanges(t.itemHandler.itemChanges[s],a.entry),u=this.itemEntryService.getDisplayName(a.entry,c.changes);if(void 0!==u&&(c.changes.displayname=u),void 0!==this.rootItem){var l=i[this.rootItem.itemType][a.entry.itemType];void 0!==l&&(l.type===D.ITEMTABLE?(c.changes.itemtype=this.rootItem.itemType,c.changes.item=this.rootItem.itemId):l.type===D.DIRECT&&(c.changes[l.field]=this.rootItem.itemId))}}for(var h in o.deleted){void 0===this.itemHandler.deletedItems[h]&&(this.itemHandler.deletedItems[h]=[]);for(var p=0,d=o.deleted[h];p<d.length;p++){var f=d[p];f.isLocal()||(this.itemHandler.entries.clear(f),this.itemHandler.deletedItems[h].push(f),this.clearItemError(f.id))}}return this.hasChanges=!0,this.expandItemsFromDelta(o).then(function(){new vt(n.apiRequestService,n.queryMatcherFactory,n,function(t){return n.collectionHandler.getAllCollectionsByItemType(t)}).processDelta(o).removeFromAndAddToCollections();for(var e=0,r=n.children;e<r.length;e++){var i=r[e];i!==t&&i.applyChangesFromParent(o)}return void 0!==n.validator&&n.validator.validateTransaction(),o.itemIdConversionMap})},e.prototype.getLocalItemEntryChangesTuple=function(t){var e=this.getLocalItemEntry(t);if(void 0===e)throw new Error("Tried to get a local ItemEntry with entryId '"+t+"' but couldn't find it");return{entry:e,changes:this.itemHandler.itemChanges[t]}},e.prototype.getLocalItemEntry=function(t){var e=this.itemHandler.entries.getByEntryId(t);return void 0!==e?e:this.parent.getLocalItemEntry(t)},e.prototype.getLocalItemEntryByItemId=function(t,e){var r=this.itemHandler.entries.get(t,e);return void 0!==r?r:this.parent.getLocalItemEntryByItemId(t,e)},e.prototype.getLocalCollectionEntryByQueryString=function(t,e){var r=this.collectionHandler.entries.getByQueryString(t,e);return null!==r?r:this.parent.getLocalCollectionEntryByQueryString(t,e)},e.prototype.getLocalCollectionEntry=function(t){var e=this.collectionHandler.entries.getByEntryId(t);return void 0!==e?e:this.parent.getLocalCollectionEntry(t)},e.prototype.getDelta=function(){var t=this.changesDeltaFactory.constructInternalDelta();for(var e in this.itemHandler.itemChanges){var r=this.getLocalItemEntryChangesTuple(Number(e));if(this.itemHandler.entries.contains(r.entry.itemType,r.entry.itemId)&&r.entry.isLocal())t.setItemCreated(r.entry,r.changes.changes);else{var n=this.getParent(r.entry);if(null!==n){var i=this.getParent(r.entry,!0);this.itemEntryService.matchParent(i,n)||t.setItemMoved(r.entry,n)}this.apiFormatter.hasChanges(r.changes.initial,r.changes.changes,r.entry.columns.main)&&t.setItemUpdated(r.entry,r.changes.changes)}}for(var o in this.itemHandler.deletedItems)t.setItemsDeleted(this.itemHandler.deletedItems[o]);return t},e.prototype.createItemResource=function(t,e,r,n){void 0===r&&(r=!1),r&&(this.rootItem=t),void 0===this.itemHandler.itemChanges[t.id]&&(this.itemHandler.itemChanges[t.id]={initial:this.getItemChangesRecursively(t.id),changes:this.getItemChangesRecursively(t.id)});var i=this.itemResourceFactory.construct(t,e,this,n);return this.itemHandler.addResource(i),i},e.prototype.createItemResources=function(t,e){for(var r=this.itemResourceFactory.getConstructor(e,this),n=[],i=0,o=t;i<o.length;i++){var s=o[i];void 0===this.itemHandler.itemChanges[s.id]&&(this.itemHandler.itemChanges[s.id]={initial:this.getItemChangesRecursively(s.id,!0),changes:this.getItemChangesRecursively(s.id,!0)});var a=r(s);n.push(a),this.itemHandler.addResource(a)}return n},e.prototype.processLinkedItems=function(t,e){var r={};for(var n in t)r[n]=this.createItemResources(t[n],e);return r},e.prototype.createCollectionResource=function(t,e){var r=this.collectionResourceFactory.construct(t,e,this);return this.collectionHandler.addResource(r),r},e.prototype.getChangesFromItemChanges=function(t){return t.changes},e.prototype.createCollectionResources=function(t,e){var r={};for(var n in t)r[n]=this.createCollectionResource(t[n],e);return r},e.prototype.expandItemsFromDelta=function(t){var e={},r={},n=function(t){void 0===e[t.itemType]&&(e[t.itemType]=[]),e[t.itemType].push(t)};for(var i in t.created)n(t.created[i].entry);for(var i in t.updated)n(t.updated[i].entry);for(var o in e){var s=this.collectionHandler.getAllCollectionsByItemType(o);if(0!==s.length){for(var a=this.requestColumnExpansionFactory.construct(),c=0,u=s;c<u.length;c++){var l=u[c];a.expand(l.columns)}r[o]=a.get()[o]}}var h=[];for(var o in r)h.push(this.itemHandler.expandLocalItemEntries(t,o,e[o],r[o],this.columnCache.retrieve(o,r[o]).cached));return this.promiseService.all(h)},e.prototype.clearGlobalError=function(t){void 0===t?this.errors.global={}:delete this.errors.global[t],this._setIsValid()},e.prototype.clearItemError=function(t,e,r){if(void 0===t)return this.errors.item={},void this._setIsValid();if(void 0===e)return delete this.errors.item[t],void this._setIsValid();if(void 0!==this.errors.item[t]){if(void 0===r)return delete this.errors.item[t][e],this._setIsValid(),void(s(this.errors.item[t])||this.clearItemError(t));delete this.errors.item[t][e][r],this._setIsValid(),s(this.errors.item[t][e])||this.clearItemError(t,e)}},e}(pt);!function(t){t.MAYBE="maybe"}(Et||(Et={}));var St,Rt,qt=function(){function t(t,e){this.queryMatcherFactory=t,this.transaction=e,this.entries={}}return t.prototype.getByEntryId=function(t){for(var e in this.entries){var r=this.entries[e][t];if(void 0!==r)return r}},t.prototype.contains=function(t){var e=this.entries[t.itemType];return void 0!==e&&void 0!==e[t.id]},t.prototype.some=function(t){var e=this.entries;for(var r in e)for(var n in e[r])if(t(e[r][n]))return!0;return!1},t.prototype.forEach=function(t){var e=this.entries;for(var r in e)for(var n in e[r])t(e[r][n])},t.prototype.toArray=function(){var t=this.entries,e=[];for(var r in t)for(var n in t[r])e.push(t[r][n]);return e},t.prototype.add=function(t){var e=this.entries,r=t.itemType;return void 0===e[r]&&(e[r]={}),e[r][t.id]=t},t.prototype.clear=function(t){return void 0===t?(this.entries={},!0):!!this.contains(t)&&delete this.entries[t.itemType][t.id]},t.prototype.getByItemType=function(t){var e=this.entries[t],r=[];if(void 0===e)return r;for(var n in e)r.push(e[n]);return r},t.prototype.matchParent=function(t,e,r){var n=t.parent;return null!==n&&(n.itemType===e&&n.itemId==r)},t.prototype.getByParent=function(t,e,r){var n=this.entries[r];if(void 0===n)return null;for(var i in n)if(this.matchParent(n[i],t,e))return n[i];return null},t.prototype.getCollectionsByParent=function(t,e){var r=this.entries,n=[];for(var i in r)for(var o in r[i]){var s=r[i][o];this.matchParent(s,t,e)&&n.push(s)}return n},t.prototype.getByContainingItem=function(t,e){var r=this.entries[t],n=[];if(void 0===r)return n;for(var i in r){var o=r[i],s=this.transaction.collectionHandler.getCollectionChanges(o.itemType,o.query.string);void 0!==s&&(s.some(function(t){return t.itemId==e})&&n.push(o))}return n},t.prototype.getByFittingItem=function(t,e,r){var n=this.entries[t],i={fitting:[],notfitting:[],maybe:[]};if(void 0===n)return i;var o=this.queryMatcherFactory.construct(t,e,r);for(var s in n){var a=n[s],c=o.matchQuery(a.query.object);!0===c?i.fitting.push(a):c===Et.MAYBE?i.maybe.push(a):i.notfitting.push(a)}return i},t.prototype.getByQuery=function(t,e){var r=this.entries[t];if(void 0===r)return null;for(var n in r){var i=r[n];if(i.query.string===e.string)return i}return null},t.prototype.getByQueryString=function(t,e){var r=this.entries[t];if(void 0===r)return null;for(var n in r){var i=r[n];if(i.query.string===e)return i}return null},t.prototype.getByKey=function(t,e){var r=this.entries[t],n=[];if(void 0===r)return n;for(var i in r){var o=r[i];o.options.entryKey===e&&n.push(o)}return n},t.prototype.getResourceByKey=function(t,e){var r=this.entries[t],n=[];if(void 0===r||!(this.transaction instanceof Ft))return n;for(var i in r)for(var o=0,s=this.transaction.collectionHandler.collectionResources[i];o<s.length;o++){var a=s[o];a.options.resourceKey===e&&n.push(a)}return n},t}(),Tt=function(){function t(t,e){this.queryParserFactory=t,this.queryService=e}return t.prototype.createUnfoundLocalCollectionError=function(t){return{message:"A local collection of type "+t+" could not be found"}},t.prototype.cloneOptions=function(t,e){var r=new K(t);return r.queryParams=this.cloneQueryParams(t.queryParams),r.parent=e,r},t.prototype.processOptions=function(t){return new K(t)},t.prototype.cloneQueryParams=function(t){var e={};for(var r in t){var i=t[r],o=void 0;o=Array.isArray(i)?i.slice():n.isMoment(i)?i.clone():i,e[r]=o}return e},t.prototype.createQuery=function(t){var e,r=t.parent;if(null===r)e=t.query;else{var n={linkedTo:r.itemType,query:{id:"&parentId"}};t.queryParams.parentId=r.itemId,e=null===t.query?n:this.queryService.addAndCondition(t.query,n)}var i=this.queryParserFactory.construct(e,t.queryParams).parse();return{object:i[0],string:i[1]}},t.prototype.getIdArray=function(t,e){void 0===e&&(e=[]),void 0===e&&(e=[]);for(var r=0,n=t;r<n.length;r++){var i=n[r];e.push(i.itemId)}return e},t.prototype.filterArray=function(t,e){for(var r=[],n=[],i=0,o=t;i<o.length;i++){var s=o[i];(e(s)?r:n).push(s)}if(0===n.length)return n;t.length=r.length;for(var a=0;a<t.length;a++)t[a]=r[a];return n},t}(),wt=function(){function t(){}return t.prototype.processOptions=function(t){return new z(t)},t.prototype.getIdArray=function(t){for(var e=[],r=0,n=t;r<n.length;r++){var i=n[r];e.push(i.entry.itemId)}return e},t}(),bt=function(){function t(t){this.columnUtil=t,this.cache={},this.allColumns={}}return t.prototype.setColumn=function(t,e){var r=this.cache;void 0===r[t]&&(r[t]={});var n=r[t],i=e.id;return void 0===n[i]&&(n[i]=e),n[i]},t.prototype.setColumns=function(t,e,r){var n={};for(var i in r){var o=r[i];for(var s in n[i]={},o)n[i][s]=this.setColumn(i,o[s])}return!0===e&&(this.allColumns[t]=!0),n},t.prototype.retrieve=function(t,e){if(!0===e)return this.containsAll(t)?{cached:this.getColumns(t),missing:[]}:{cached:{},missing:!0};var r={},n=[];return this.retrieveColumns(t,e,n,r),{cached:r,missing:n}},t.prototype.containsAll=function(t){return!0===this.allColumns[t]},t.prototype.getColumns=function(t){var e,r=this.cache;return(e={})[t]=void 0===r[t]?[]:r[t],e},t.prototype.retrieveColumns=function(t,e,r,n){this.retrieveColumn(t,"id",r,n);for(var i=0,o=e;i<o.length;i++){var s=o[i];this.retrieveColumn(t,s,r,n)}},t.prototype.retrieveColumn=function(t,e,r,n){var i,o=this.columnUtil.parseRequestColumn(e),s=this.getColumn(t,o.id);if(void 0!==s){if(void 0===n[t]&&(n[t]={}),n[t][o.id]=s,0!==o.children.length){var a=[];this.retrieveColumns(s.itemType,o.children,a,n),0!==a.length&&r.push(((i={})[o.id]=a,i))}}else r.push(e)},t.prototype.getColumn=function(t,e){var r=this.cache[t];if(void 0!==r)return r[e]},t}(),Ht=function(){function t(t,e,r,n){if(this.columnInfoFactory=t,this.itemType=e,this.responseColumns=n,this.expansionMap={},this.expansionMapSize=0,!0===r)for(var i in this.requestColumnsTrue=!0,this.requestColumns=[],n[e])this.requestColumns.push(i);else this.requestColumnsTrue=!1,this.requestColumns=r}return t.prototype.run=function(t){var e=this.expansionMap,r=t.id;return void 0!==e[r]?e[r]:(this.expansionMapSize++,e[r]=t.isSupersetOf(this.requestColumns)?null:t.expand(this.requestColumns,this.requestColumnsTrue,this.responseColumns))},t.prototype.aggregateRootColumns=function(){var t=this.expansionMap;if(1===this.expansionMapSize){var e=t[a(t)];return null!==e?e.difference.root:[]}var r={};for(var n in t){var i=t[n];null!==i&&this.expandRootColumnMap(i.difference.root,r)}return this.columnInfoFactory.constructFromRootMap(r)},t.prototype.expandRootColumnMap=function(t,e){for(var r=0,n=t;r<n.length;r++){var i=n[r],o=i.id;void 0===e[o]&&(e[o]={apiColumn:i.apiColumn,children:{}}),this.expandRootColumnMap(i.children,e[o].children)}},t}(),Mt=function(){function t(t,e,r,n,i){this.apiRequestService=t,this.errorHandler=e,this.promiseService=r,this.cache=n,this.columnUtil=i}return t.prototype.setColumn=function(t,e){return this.cache.setColumn(t,e)},t.prototype.setColumns=function(t,e,r){return this.cache.setColumns(t,e,r)},t.prototype.fetchItemTypeTranslations=function(t){for(var e={},r=0,n=t;r<n.length;r++){var i=n[r];e[i]=this.fetch(i,["id"])}return this.promiseService.all(e).then(function(t){var e={};for(var r in t)e[r]=t[r][r].id.name;return e},this.errorHandler.reject)},t.prototype.request=function(t,e,r){var n,i=this;return void 0===r&&(r={filter:!1}),this.apiRequestService.columns(t,(n={},n[t]=e,n),r).then(function(r){return i.cache.setColumns(t,e,r.fetchColumnsObject())},this.errorHandler.reject)},t.prototype.fetch=function(t,e,r){var n=this,i=this.cache.retrieve(t,e);return!0!==i.missing&&0===i.missing.length?this.promiseService.when(i.cached):this.request(t,i.missing,r).then(function(t){return n.columnUtil.mergeResponseColumns(t,i.cached).merged})},t.prototype.fetchAll=function(t){return this.cache.containsAll(t)?this.promiseService.when(this.cache.getColumns(t)):this.request(t,!0)},t}(),xt=">",kt=function(){function t(t,e){void 0===e&&(e=null),this.apiColumn=t,this.parent=e,this.itemType=null,this.children=[],this.isLeaf=!0;var r=t.id;this.id=r,null===e?(this.level=0,this.path=r,this.tailPath=""):(this.level=e.level+1,this.path=e.path+xt+r,this.tailPath=0===e.level?r:e.tailPath+xt+r)}return t.prototype.setChildren=function(t,e){return this.itemType=t,this.children=e,this.isLeaf=!1,this},t}(),Dt={},_t=0,Ot=function(){function t(t,e,r){this.columnUtil=t,this.columnSetFactory=e,this.itemType=r,this.id=++_t,this.response=Dt,this.link=null,this.main=[],this.derived=[],this.root=[],this.leaf=[],this.formatted={main:[],derived:[]},this.filtered=[],this.custom=[],this.searchable=[],this.item=[],this.notItem=[]}return t.prototype.groupColumnInfo=function(t){var e=this.columnUtil,r=t.apiColumn,n=null!==t.parent;n?this.derived.push(t):(this.main.push(t),"link"===r.type&&(this.link=t),this[e.isItemColumn(r)?"item":"notItem"].push(t),t.isLeaf||this.root.push(t)),e.isFormattedColumn(r)&&this.formatted[n?"derived":"main"].push(t),e.isFilteredColumn(r)&&this.filtered.push(t),e.isSearchableColumn(r)&&this.searchable.push(t),e.isCustomColumn(r)&&this.custom.push(t),t.isLeaf&&this.leaf.push(t)},t.prototype.toJSON=function(){var t=function(t){return t.map(function(t){return t.id})};return{main:t(this.main),derived:t(this.derived)}},t.prototype.expandRequestColumns=function(t){var e=this.columnUtil.mergeRequestColumns(this.request,t).merged;this.request=e,this.requestColumnsTrue=!0===e},t.prototype.isSupersetOf=function(t){if(!0===t)return this.requestColumnsTrue;var e=this.columnUtil,r=this.request;if(!0===r)return!e.containsDerivedColumns(t);for(var n=0,i=t;n<i.length;n++){var o=i[n];if(!e.containsColumn(o,r))return!1}return!0},t.prototype.getMergedColumnSet=function(t,e,r){var n=this.columnSetFactory.construct(this.itemType,t.merged,e);return n.requestColumnsTrue=this.requestColumnsTrue||r,n},t.prototype.mergeRequestColumns=function(t){return this.columnUtil.mergeRequestColumns(this.request,t)},t.prototype.mergeResponseColumns=function(t){return this.columnUtil.mergeResponseColumns(this.response,t).merged},t.prototype.merge=function(t){return this.getMergedColumnSet(this.mergeRequestColumns(t.request),this.mergeResponseColumns(t.response),t.requestColumnsTrue)},t.prototype.expand=function(t,e,r){var n=this.mergeRequestColumns(t),i=this.mergeResponseColumns(r);return{merged:this.getMergedColumnSet(n,i,e),difference:this.columnSetFactory.construct(this.itemType,n.difference,i,!1,!1)}},t}(),Pt=function(){function t(t){this.requestColumns=t,this.cache={}}return t.prototype.run=function(t){var e=this.cache,r=t.id;return void 0!==e[r]?e[r]:e[r]=t.isSupersetOf(this.requestColumns)},t}(),Lt=function(){function t(t){this.linkTreeService=t}return t.prototype.getColumnsFromLink=function(t,e){var r=this.linkTreeService.get()[t][e],n=[];switch(r.type){case D.DIRECT:n.push(r.field);break;case D.ITEMTABLE:n.push("itemtype"),n.push("item")}return n},t.prototype.getColumnPath=function(t,e){for(var r="",n="",i=0,o=t;i<o.length;i++){n+=r+o[i].id,r=xt}return null!==e&&(n+=":"+e),n},t.prototype.getDateFormatOptions=function(t){var e=n(),r={"J-M-Y":e.format("DD-MM-YYYY"),"J-M":e.format("DD-MM"),"j+F+Y":e.format("D MMM YYYY"),"D+j+F+Y":e.format("dddd D MMM YYYY"),F:e.format("MMM"),f:e.format("MMMM"),D:e.format("dddd"),d:e.format("ddd")};return"datetime"===t&&m(r,{"J-M-Y+H:i":e.format("DD-MM-YYYY HH:mm"),"J-M+H:i":e.format("DD-MM HH:mm"),"j+F+Y+H:i":e.format("DD MMMM Y HH:mm"),"D+j+F+Y+H:i":e.format("dddd DD MMM Y HH:mm"),"H:i":e.format("HH:mm")}),r},t.prototype.isStringColumn=function(t){switch(t.type){case"email":case"phone":case"url":case"text":case"longtext":case"textreplace":return!0;default:return!1}},t.prototype.isFloatColumn=function(t){switch(t.type){case"double":case"volume":case"weight":case"distance":case"dimension":case"power":case"current":case"price":case"percentage":return!0;default:return!1}},t.prototype.isIntColumn=function(t){switch(t.type){case"int":case"number":case"quantity":return!0;default:return!1}},t.prototype.isNumberColumn=function(t){return this.isFloatColumn(t)||this.isIntColumn(t)},t.prototype.isCustomColumn=function(t){return"customfield"===t.fieldtype},t.prototype.isItemColumn=function(t,e){switch(void 0===e&&(e=!0),t.type){case"id":return e;case"item":case"child":case"sibling":case"link":return!0;default:return!1}},t.prototype.isDateColumn=function(t){switch(t.type){case"datetime":case"date":return!0;default:return!1}},t.prototype.isRenderedColumn=function(t){switch(t.type){case"datetime":case"date":case"duration":return!0;default:return!1}},t.prototype.isFilteredColumn=function(t){if("staffel"===t.id)return!0;if(void 0!==t.generator)return!0;switch(t.type){case"price":case"bool":case"enum":case"country":case"volume":case"weight":case"distance":case"dimension":case"quantity":case"email":case"url":case"datetime":case"date":case"time":case"duration":case"html":case"textreplace":case"longtext":case"percentage":return!0;default:return!1}},t.prototype.isFormattedColumn=function(t){switch(t.type){case"datetime":case"date":case"time":case"duration":case"color":case"json":case"number":case"filesize":return!0;default:return!1}},t.prototype.isSelectableColumn=function(t){switch(t.type){case"blob":case"coordinate":case"forceupdate":case"id":case"json":case"order":case"parentid":case"parenttype":case"password":case"token":return!1}return!0},t.prototype.hasLocationProperty=function(t,e){return 0!=(e&t.location)},t.prototype.isEditableColumn=function(t){if(t.readOnly)return!1;switch(t.type){case"date":case"datetime":case"duration":return!1}return!0},t.prototype.isSearchableColumn=function(t){switch(t.type){case"email":case"phone":case"text":case"longtext":case"html":return!0;default:return!1}},t.prototype.getDefaultWeight=function(t){switch(t.type){case"double":case"price":case"bool":case"int":case"percentage":case"color":case"number":case"power":case"current":return.5;case"url":case"enum":case"email":case"text":case"item":case"link":return 1.5;case"longtext":case"html":case"textreplace":return 2;case"date":case"datetime":case"time":case"duration":default:return 1}},t.prototype.getComparators=function(t){switch(t.type){case"dimension":case"weight":case"price":return["=",">","<"];case"date":case"datetime":case"time":case"duration":return[">","<"];default:return["=","!="]}},t.prototype.containsColumn=function(t,e){var r=this.parseRequestColumn(t),n=this.findRequestColumn(r.id,e);if(-1===n)return!1;if(0===r.children.length)return!0;if("string"==typeof e[n])return!1;for(var i=0,o=r.children;i<o.length;i++){var s=o[i];if(!this.containsColumn(s,e[n][r.id]))return!1}return!0},t.prototype.containsDerivedColumns=function(t){for(var e=0,r=t;e<r.length;e++){var n=r[e];if(this.parseRequestColumn(n).children.length>0)return!0}return!1},t.prototype.responseColumnsAvailable=function(t,e,r){for(var n=0,i=e;n<i.length;n++){var o,s=i[n],a=this.parseRequestColumn(s),c=a.children,u=r[t];if(void 0===u)return!1;if(void 0===(o=u[a.id]))return!1;if(c.length>0&&!this.responseColumnsAvailable(o.itemType,c,r))return!1}return!0},t.prototype.copyRequestColumns=function(t){if(!0===t)return!0;for(var e=[],r=0,n=t;r<n.length;r++){var i=n[r];e.push(this.copyRequestColumn(i))}return e},t.prototype.copyRequestColumn=function(t){var e,r=this.parseRequestColumn(t);if(0===r.children.length)return r.id;for(var n=[],i=0,o=r.children;i<o.length;i++){var s=o[i];n.push(this.copyRequestColumn(s))}return(e={})[r.id]=n,e},t.prototype.mergeRequestColumns=function(t,e){if(!0===t)return{merged:!0,difference:[]};if(!0===e)return{merged:!0,difference:!0};for(var r=this.copyRequestColumns(t),n=[],i=0,o=e;i<o.length;i++){var s=o[i],a=this.mergeRequestColumn(s,r);null!==a&&n.push(a)}return{merged:r,difference:n}},t.prototype.mergeRequestColumn=function(t,e){var r,n,i=this.parseRequestColumn(t),o=this.findRequestColumn(i.id,e);if(-1===o)return e.push(t),t;if(0===i.children.length)return null;"string"==typeof e[o]&&(e[o]=((r={})[i.id]=[],r));for(var s=[],a=0,c=i.children;a<c.length;a++){var u=c[a],l=this.mergeRequestColumn(u,e[o][i.id]);null!==l&&s.push(l)}return 0===s.length?null:((n={})[i.id]=s,n)},t.prototype.getRequestColumnId=function(t){if("string"==typeof t)return t;var e;for(e in t);return e},t.prototype.parseRequestColumn=function(t){if("string"==typeof t)return{id:t,children:[]};var e;for(e in t);return{id:e,children:t[e]}},t.prototype.mergeResponseColumns=function(t,e){var r={},n={};for(var i in t)if(void 0!==e[i]){var o=this.mergeResponseColumnMap(t[i],e[i]);r[i]=o.merged,n[i]=o.difference}else r[i]=t[i];for(var i in e)void 0===t[i]&&(r[i]=e[i],n[i]=e[i]);return{merged:r,difference:n}},t.prototype.mergeResponseColumnMap=function(t,e){var r={},n={};for(var i in t)r[i]=t[i];for(var i in e)H(t[i])||(r[i]=e[i],n[i]=e[i]);return{merged:r,difference:n}},t.prototype.isLocalColumnId=function(t){return"__"===t.substring(0,2)},t.prototype.processConfigColumns=function(t){for(var e=[],r=0,n=t;r<n.length;r++){var i=n[r];this.isLocalColumnId(i)||this.processConfigColumn(this.parseConfigColumn(i),e)}return e},t.prototype.parseConfigColumn=function(t){return t.split(":")[0].split(xt)},t.prototype.processConfigColumn=function(t,e){var r,n,i=t[0],o=1===t.length,s=this.findRequestColumn(i,e);o?-1===s&&e.push(i):(-1===s?s=e.push(((r={})[i]=[],r))-1:"string"==typeof e[s]&&(e[s]=((n={})[i]=[],n)),this.processConfigColumn(t.slice(1),e[s][i]))},t.prototype.findRequestColumn=function(t,e){for(var r=0;r<e.length;r++){var n=e[r];if(this.getRequestColumnId(n)===t)return r}return-1},t}(),jt=function(){function t(t,e,r,n,i,o){void 0===o&&(o=!1),this.apiFormatter=t,this.keyService=e,this.requestColumnExpansionFactory=r,this.compilation=n,this.transaction=i,this.breakupByParent=o,this.requests=[]}return t.prototype.finalizeRequest=function(t){for(var e=t.collections.getCollectionsWithFittingItems(),r=t.columns,n=0,i=e;n<i.length;n++){var o=i[n];r.expand(o.columns)}return t.request.columns=r.get(),t},t.prototype.setRequestParent=function(t,e){var r=e.request;return"Void"!==t&&(r.parentType=t,r.parentId={},!0)},t.prototype.run=function(){var t=this.compilation;if(this.breakupByParent)for(var e in t){var r=t[e];for(var n in r)if(!this.keyService.isLocalId(n)){var i=this.initializeRequest();this.extendRequest(r[n],this.setRequestParent(e,i)?+n:null,i),this.requests.push(this.finalizeRequest(i))}}else for(var e in t){r=t[e],i=this.initializeRequest();var o=this.setRequestParent(e,i),s=!1;for(var n in r)this.keyService.isLocalId(n)||(this.extendRequest(r[n],o?+n:null,i),s=!0);s&&this.requests.push(this.finalizeRequest(i))}return this.requests},t.prototype.initializeRequest=function(){return{request:{requestType:"create",items:{},columns:{}},columns:this.requestColumnExpansionFactory.construct(),items:{},collections:this.transaction.collectionHandler.getCollectionMatcher()}},t.prototype.extendRequest=function(t,e,r){var n=r.request,i=r.items;for(var o in t)for(var s in void 0===n.itemType&&(n.itemType=o),void 0===i[o]&&(i[o]={},n.items[o]={}),t[o]){var a=t[o][s],c=a.entry,u=d(this.compilation,[o,c.itemId]),l=n.items[o][c.itemId]={},h=d(this.transaction.tabRequestParameters,[o,c.itemId]);if(null!==e&&(n.parentId[c.itemId]=e),r.columns.expand(c.columns),i[o][s]=c,l.values=this.apiFormatter.formatRequestLocal(a.fields,c.columns.main),l.parameters=h,void 0!==u){var p=l.links={};for(var f in u)for(var m in p[f]=[],u[f])p[f].push(parseInt(m,10));this.extendRequest(u,null,r)}}},t}();!function(t){t.OR="OR",t.AND="AND"}(St||(St={})),function(t){t.EQUALS="=",t.NOT_EQUALS="!=",t.LESS_THAN="<",t.MORE_THAN=">",t.LESS_OR_EQUAL_THAN="<=",t.EQUAL_OR_MORE_THAN=">=",t.IN="IN"}(Rt||(Rt={}));var Bt,At,Qt=function(){function t(t){this.query=t}return t.prototype.parse=function(t){if(void 0===t&&(t=this.query),void 0!==t.linkedTo)return this.parseLinkedToQuery(t.linkedTo,t.query,t.reverse,t.not);if(void 0!==t.custom)return this.parseCustomQuery(t.custom,t.parameters,t.not);if(void 0!==t.search)return this.parseSearchQuery(t.search,t.not);if(void 0!==t.conditions)return this.parseComplexQuery(t.conditions,t.operator,t.not);if(void 0!==t.itemType)return this.parseSubFieldQuery(t.key,t.itemType,t.field,t.query,t.not);if(void 0!==t.key)return"object"==typeof t.query?this.parseSubQuery(t.key,t.query,t.not):this.parseSimpleQuery(t.key,t.value,t.comparator,t.not);var e=a(t);if(null===e)return this.parseEmptyQuery();var r=t[e];return null!==r&&"object"==typeof r&&r.constructor===Object?this.parseSubQuery(e,r,!1):this.parseSimpleQuery(e,r,t.comparator,t.not)},t}(),Vt=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),Ut=function(t){function e(e,r,n){var i=t.call(this,n)||this;return i.columnUtil=e,i.itemType=r,i}return Vt(e,t),e.prototype.parseEmptyQuery=function(){return[]},e.prototype.parseSubQuery=function(t,e,r){var n;return void 0===r&&(r=!1),[(n={},n[t]=this.parse(e),n)]},e.prototype.parseSubFieldQuery=function(t,e,r,n,i){return[]},e.prototype.parseSearchQuery=function(t,e){return[]},e.prototype.parseCustomQuery=function(t,e,r){return void 0===r&&(r=!1),[]},e.prototype.parseSimpleQuery=function(t,e,r,n){return[t]},e.prototype.parseLinkedToQuery=function(t,e,r,n){return void 0===e&&(e={}),void 0===r&&(r=!1),void 0===n&&(n=!1),this.columnUtil.getColumnsFromLink(t,this.itemType)},e.prototype.parseComplexQuery=function(t,e,r){return this.parseConditions(t)},e.prototype.parseConditions=function(t){var e=this;return t.reduce(function(t,r){return t.concat(e.parse(r))},[])},e}(Qt),Nt=function(){function t(t,e,r,n,i){this.collectionEntryService=t,this.columnUtil=e,this.requestColumnExpansionFactory=r,this.transaction=i,this.collectionChanges={},this.entries=n.construct(this.transaction)}return t.prototype.setCollectionChanges=function(t,e,r){void 0===this.collectionChanges[t]&&(this.collectionChanges[t]={}),this.collectionChanges[t][e]=r},t.prototype.getCollectionChanges=function(t,e){if(void 0!==this.collectionChanges[t])return this.collectionChanges[t][e]},t.prototype.createCollectionEntry=function(t,e){var r=this.transaction.core.collectionEntryFactory.construct(t,e);this.entries.add(r),this.setCollectionChanges(r.itemType,r.query.string,[]);for(var n=new vt(this.transaction.core.apiRequestService,this.transaction.core.queryMatcherFactory,this.transaction,function(t){return t===r.itemType?[r]:[]}),i=0,o=this.transaction.getTransactionChain();i<o.length;i++)for(var s=0,a=o[i].itemHandler.entries.getByItemType(r.itemType);s<a.length;s++){var c=a[s],u=this.transaction.getItemChangesRecursively(c.id,!1);n.expand(c,u)}return n.removeFromAndAddToCollections(),r},t.prototype._addItemEntriesToCollectionChanges=function(t,e,r,n){if(0!==e.length){var i=this.getCollectionChanges(t.itemType,t.query.string);if(void 0!==i){for(var o=[],s=0,a=e;s<a.length;s++){var c=a[s];-1!==i.indexOf(c)||r(c)||(i.push(c),o.push(c))}return this.handleAddedItemEntriesCallback(t,o,n)}}},t.prototype.removeItemEntriesFromCollectionChanges=function(t,e,r){if(void 0===r&&(r=!1),0===e.length)return[];var n=this.getCollectionChanges(t.itemType,t.query.string);if(void 0!==n){var i=this.collectionEntryService.filterArray(n,function(t){return!c(t.itemId,e)});return this.handleRemovedItemEntriesCallback(t,i,r)}},t.prototype.expandColumnsWithQueryColumns=function(t,e,r){var n=new Ut(this.columnUtil,t,r);if(e.queryColumns=n.parse(),!0!==e.columns){var i=this.requestColumnExpansionFactory.construct();i.expandWithRequestColumns(t,e.columns),i.expandWithRequestColumns(t,e.queryColumns),e.columns=i.get()[t]}},t}(),Wt=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),Yt=function(t){function e(e,r,n,i,o,s,a,c,u,l,h,p,d,f){var m=t.call(this,a,d,n,s,f)||this;return m.columnSubsetCacheFactory=e,m.requestBufferManager=r,m.columnExpansionFactory=i,m.apiRequestService=o,m.collectionMatcherFactory=c,m.errorHandler=u,m.itemHandler=l,m.promiseService=h,m.queryService=p,m.transaction=f,m}return Wt(e,t),e.prototype.fetchItemEntriesByQuery=function(t,e,r){var n=this;return this.fetchCollectionEntry(t,new K({columns:r.columns,parent:r.parent,query:e})).then(function(t){return n.collectionChanges[t.itemType][t.query.string]},this.errorHandler.reject)},e.prototype.getCollectionMatcher=function(){var t=this;return this.collectionMatcherFactory.construct(this.transaction,function(e){return t.entries.getByItemType(e)})},e.prototype.fetchCollectionEntry=function(t,e){var r=this.collectionEntryService.createQuery(e);this.expandColumnsWithQueryColumns(t,e,r.object);var n=this.columnSubsetCacheFactory.construct(e.columns);return this.fetchCollectionData(t,n,e,r)},e.prototype.fetchLinkedCollectionEntries=function(t,e,r,n){var i={};S(e)&&(e=e());for(var o=0,s=e;o<s.length;o++){var a=s[o],c=this.collectionEntryService.cloneOptions(n,{itemType:t,itemId:a}),u=this.collectionEntryService.createQuery(c);this.expandColumnsWithQueryColumns(r,c,u.object);var l=this.columnSubsetCacheFactory.construct(c.columns);i[a]=this.fetchCollectionData(r,l,c,u)}return this.promiseService.all(i)},e.prototype.extendCollectionEntry=function(t,e){var r,n,i=t.extendQuery(e).object,o=this.queryService.addAndCondition(i,this.queryService.createNotIn(this.getCollectionChanges(t.itemType,t.query.string).map(function(t){return t.itemId})));return this.expandColumnsWithQueryColumns(t.itemType,t.options,i),n=null!==t.options.limit?this.apiRequestService.requestSkeleton({requestType:"query",itemType:t.itemType,columns:(r={},r[t.itemType]=t.options.columns,r),query:i,limit:t.options.limit}):this.requestBufferManager.fetchByQuery(t.itemType,o,t.options.columns),t.promise=n,n.then(function(){delete t.promise},this.errorHandler.reject),n.then(function(){return t})},e.prototype.expandCollectionEntries=function(t,e,r,n){var i=this;if(0===n.length)return this.promiseService.when(r);var o=[];for(var s in r){var a=r[s].entry;o.push(a.parent.itemId)}return this.itemHandler.fetchLinkedItemEntriesData(t,o,e,null,n).then(function(t){for(var s=i.columnExpansionFactory.construct(e,n,t.fetchColumnsObject()),a=0,c=o;a<c.length;a++){var u=c[a];r[u].entry.expandColumns(s)}return r})},e.prototype.extendCollectionEntries=function(t,e,r,n,i){if(!s(i))return this.promiseService.when();var o=[],a=[];for(var c in r.queryParams=n(r.queryParams),i){var u=i[c].entry;u.extendQuery(n),o.push(u.parent.itemId),a=a.concat(this.getCollectionChanges(u.itemType,u.query.string).map(function(t){return t.itemId}))}return this.itemHandler.fetchLinkedItemEntriesData(t,o,e,this.queryService.addAndCondition(this.collectionEntryService.createQuery(r).object,this.queryService.createNotIn(a)),r.columns).then(function(){},this.errorHandler.reject)},e.prototype.addItemEntriesToCollectionChanges=function(e,r,n){void 0===n&&(n=!1),t.prototype._addItemEntriesToCollectionChanges.call(this,e,r,function(t){return t.isLocal()},n)},e.prototype.expandCollectionEntry=function(t,e){var r=this,n=t.columns.mergeRequestColumns(e),i=n.merged,o=n.difference;if(!0!==o&&0===o.length)return this.promiseService.when(t);var s=t.itemType;return(null!==t.options.limit?this.apiRequestService.requestSkeleton({requestType:"query",itemType:s,columns:i,query:t.query.object,limit:t.options.limit}):this.requestBufferManager.fetchByQuery(t.itemType,[t.query.object,t.query.string],i)).then(function(e){var n=r.columnExpansionFactory.construct(s,i,e.fetchColumnsObject());return t.expandColumns(n),n},this.errorHandler.reject)},e.prototype.handleAddedItemEntriesCallback=function(t,e){e.length},e.prototype.handleRemovedItemEntriesCallback=function(t,e){e.length},e.prototype.fetchCollectionData=function(t,e,r,n){var i,o=this,s=this.entries.getByQuery(t,n);if(null!==s&&e.run(s.columns))return this.promiseService.when(s);var a,c=null===s;if(null===s&&(s=this.createCollectionEntry(t,r)),null!==r.limit){var u,l=((i={})[t]=r.columns,i);a=this.apiRequestService.requestSkeleton({requestType:"query",itemType:t,columns:l,query:r.query,limit:r.limit}).then(function(t){return u=t,o.transaction.processResponse(u,l,!1,!1)},this.errorHandler.reject).then(function(){return u},this.errorHandler.reject)}else a=this.requestBufferManager.fetchByQuery(t,[n.object,n.string],e.requestColumns);return a.then(function(r){if(c)s.columns=o.transaction.core.columnSetFactory.construct(t,e.requestColumns,r.fetchColumnsObject());else{var n=o.columnExpansionFactory.construct(t,e.requestColumns,r.fetchColumnsObject());s.expandColumns(n)}return s})},e}(Nt),Jt=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),Kt=function(t){function e(e,r,n,i,o,s,a,c,u,l,h,p){var d=t.call(this,a,c,u,s,o,h,l,p)||this;return d.requestBufferManager=e,d.queryParserFactory=r,d.queryService=n,d.columnSubsetCacheFactory=i,d.transaction=p,d.itemChanges={},d}return Jt(e,t),e.prototype.createItemEntry=function(e){var r=t.prototype.createItemEntry.call(this,e);return this.itemChanges[r.id]=e.fields,r},e.prototype.processItemEntryChanges=function(t,e,r,n,i){var o=t.entry,s=t.changes;void 0===this.itemChanges[o.id]&&(this.itemChanges[o.id]={}),null!==s.expandedColumns&&(o.columns=s.expandedColumns.merged);var a=this.apiFormatter.copyFields(this.itemChanges[o.id],{},o.columns.main);return this.apiFormatter.copyFields(s.fields,this.itemChanges[o.id],o.columns.main),void 0!==s.fields.id&&(o.itemId=s.fields.id),a},e.prototype.copyTransactionItemEntryChanges=function(t,e){return this.apiFormatter.copyFields(t.changes,{},e.columns.main)},e.prototype.fetchItemEntry=function(t,e,r){var n=this;return r.columns=this.expandColumnsWithCollectionColumns(t,r.columns),this.fetchItemEntryData(t,e,this.columnSubsetCacheFactory.construct(r.columns)).then(function(){return n.entries.get(t,e)},this.errorHandler.reject)},e.prototype.fetchItemEntriesByQuery=function(t,e,r){var n=this;return r.columns=this.expandColumnsWithCollectionColumns(t,r.columns),this.requestBufferManager.fetchByQuery(t,this.queryParserFactory.construct(this.queryService.addParentCondition(e,r.parent)).parse(),r.columns).then(function(e){for(var r=[],i=0,o=e.links[t];i<o.length;i++){var s=o[i],a=n.entries.get(t,s);void 0!==a&&r.push(a)}return r},this.errorHandler.reject)},e.prototype.fetchItemEntries=function(t,e,r){var n=this;r.columns=this.expandColumnsWithCollectionColumns(t,r.columns);for(var i=this.columnSubsetCacheFactory.construct(r.columns),o=[],s=0,a=e;s<a.length;s++){var c=a[s];o.push(this.fetchItemEntryData(t,c,i))}return this.promiseService.all(o).then(function(){for(var r=[],i=0,o=e;i<o.length;i++){var s=o[i];r.push(n.entries.get(t,s))}return r},this.errorHandler.reject)},e.prototype.fetchLinkedItemEntriesData=function(t,e,r,n,i){return null===n?this.requestBufferManager.fetchByIds(t,e,i):this.requestBufferManager.fetchByQuery(r,this.queryParserFactory.construct(this.queryService.addAndCondition(n,{linkedTo:t,query:{id:e}})).parse(),i)},e.prototype.processApiResponse=function(t,e,r,n,i,o){var s=this.entries.get(r,n),a=e.fetchObject(r,n);if(void 0===a)throw new Error("Fields not found in response for "+r+":"+n);void 0===s?t.setItemCreated(n,a,i):t.setItemUpdated(s,a,o.run(s.columns))},e.prototype.fetchItemEntryData=function(t,e,r){var n=this.entries.get(t,e);return void 0!==n&&r.run(n.columns)?this.promiseService.when():this.requestBufferManager.fetchById(t,e,r.requestColumns).then(function(){},this.errorHandler.reject)},e}(ut),zt=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),Gt=function(t){function e(e,r,n,i,o,s,a,c,u,l,h,p,d,f,m,y,v,g,C,I,E,F,S,R,q,T,w,b,H,M,x,k,D,_){var O=t.call(this,r,n,i,o,s,a,c,u,l,h,p,d,f,m,y,v,g,I,E,F,S,R,q,T,w,b,H,M,x,k,D,C,_)||this;return O.changesProcessorFactory=e,O.parent=null,O.itemHandler=new Kt(i,k,D,R,y,g,q,C,T,f,o,O),O.collectionHandler=new Yt(R,i,o,E,I,m,M,x,y,O.itemHandler,g,D,q,O),O}return zt(e,t),e.prototype.getServerCache=function(){return this},e.prototype.processResponse=function(t,e,r,n,i){void 0===r&&(r=!1),void 0===n&&(n=!1),void 0===i&&(i=this.core.changesDeltaFactory.construct());var o=t.fetchColumnsObject();for(var s in t.items){var a=void 0;a=s===t.itemType?this.core.columnSetFactory.construct(s,e[s],o):this.core.columnSetFactory.constructFromResponse(s,o);var c=this.core.columnExpansionFactory.construct(s,!!a.requestColumnsTrue||a.request,o);for(var u in t.items[s])this.itemHandler.processApiResponse(i,t,s,Number(u),a,c)}return this.applyChangesDelta(i,r,n)},e.prototype.applyChangesFromParent=function(t,e,r){var n=this;for(var i in void 0===e&&(e=!1),void 0===r&&(r=!1),t.updated)this.itemHandler.processItemEntryChanges(t.updated[i],r);for(var o in t.deleted)for(var s=0,a=t.deleted[o];s<a.length;s++){var c=a[s];this.itemHandler.entries.clear(c),delete this.itemHandler.itemChanges[c.id]}new vt(this.apiRequestService,this.queryMatcherFactory,this,function(t){return n.collectionHandler.entries.getByItemType(t)}).processDelta(t).removeFromAndAddToCollections(r);for(var u=0,l=this.children;u<l.length;u++){l[u].applyChangesFromParent(t,e,r)}},e.prototype.getLinkFieldsByParent=function(t,e){var r=this.linkTreeService.get()[t.itemType][e],n={};if(void 0===r)throw new Error("Non existing link between '"+t.itemType+"'->'"+e+"'");return r.type===D.DIRECT?n[r.field]=t.itemId:(n.itemtype=t.itemType,n.item=t.itemId),n},e.prototype.getParent=function(t,e,r){return this.getParentFromFields(t,this.itemHandler.itemChanges[t.id])},e.prototype.getItemChangesRecursively=function(t,e){void 0===e&&(e=!0);var r=this.itemHandler.itemChanges[t],n=this.getLocalItemEntry(t);if(void 0!==r&&void 0!==n)return e?this.apiFormatter.copyFields(r,{},n.columns.main):r;if(void 0===n)throw new Error("No local entry found");throw new Error("No local fields found for ItemEntry with ItemType '"+n.itemType+"'")},e.prototype.getLocalItemEntryChangesTuple=function(t){var e=this.getLocalItemEntry(t);if(void 0===e)throw new Error("Tried to get a local ItemEntry with entryId '"+t+"' but couldn't find it");return{entry:e,changes:this.itemHandler.itemChanges[t]}},e.prototype.getCollectionChangesRecursively=function(t){var e=this.getLocalCollectionEntry(t);if(void 0!==e){var r=this.collectionHandler.getCollectionChanges(e.itemType,e.query.string);return void 0===r&&(r=[],this.collectionHandler.setCollectionChanges(e.itemType,e.query.string,r)),r}throw new Error("No local collection items found")},e.prototype.invalidateCache=function(){this.itemHandler.entries.forEach(function(t){return t.queueReload()}),this.collectionHandler.entries.forEach(function(t){return t.queueReload()})},e.prototype.applyChangesFromChild=function(t,e,r){return this.changesProcessorFactory.construct(t,e,r).execute()},e.prototype.applyChangesDelta=function(e,r,n){var i=this;return void 0===r&&(r=!0),void 0===n&&(n=!1),0!==e.created.length||s(e.updated)||s(e.deleted)?this.fetchUpdatedDerivedValuesFromDelta(e).then(function(){var o=t.prototype._applyChangesDelta.call(i,e),s=o.result,a=o.internalChangesDelta,c=o.rollbackFunctions;for(var u in e.deleted)for(var l=function(t){i.itemHandler.entries.clear(t);var r=i.itemHandler.itemChanges[t.id];delete e.updated[t.id],delete i.itemHandler.itemChanges[t.id],a.setItemDeleted(t),c.push(function(e){e.setItemUpdated(t,r)})},h=0,p=e.deleted[u];h<p.length;h++){l(p[h])}new vt(i.apiRequestService,i.queryMatcherFactory,i,function(t){return i.collectionHandler.entries.getByItemType(t)}).processDelta(a).removeFromAndAddToCollections(n);for(var d=0,f=i.children;d<f.length;d++){f[d].applyChangesFromParent(a,r,n)}return s}):this.promiseService.when({created:[],rollback:Je})},e.prototype.getLocalItemEntry=function(t){var e=this.itemHandler.entries.getByEntryId(t);if(void 0!==e)return e},e.prototype.getLocalItemEntryByItemId=function(t,e){var r=this.itemHandler.entries.get(t,e);if(void 0!==r)return r},e.prototype.getLocalCollectionEntryByQueryString=function(t,e){var r=this.collectionHandler.entries.getByQueryString(t,e);if(null!==r)return r},e.prototype.getLocalCollectionEntry=function(t){var e=this.collectionHandler.entries.getByEntryId(t);if(void 0!==e)return e},e.prototype.getChangesFromItemChanges=function(t){return t},e}(pt),Xt=function(){function t(t,e){this.queryMatcherFactory=t,this.transaction=e,this.entries={},this.entriesByEntryId={}}return t.prototype.getByEntryId=function(t){return this.entriesByEntryId[t]},t.prototype.some=function(t){var e=this.entries;for(var r in e)for(var n in e[r])if(t(e[r][n]))return!0;return!1},t.prototype.getByItemType=function(t){var e=this.entries[t],r=[];if(void 0===e)return r;for(var n in e)r.push(e[n]);return r},t.prototype.getByQuery=function(t,e){var r=this.entries[t],n=[];if(void 0===r)return n;for(var i in r){var o=r[i];this.matchQuery(o,e)&&n.push(o)}return n},t.prototype.getLocalByQuery=function(t,e){var r=this.entries[t],n=[];if(void 0===r)return n;for(var i in r){var o=r[i];o.isLocal()&&(this.matchQuery(o,e)&&n.push(o))}return n},t.prototype.getByParent=function(t,e,r){var n=this.entries[r],i=[];if(void 0===n)return i;for(var o in n){var s=n[o],a=this.transaction.getParent(s);null!==a&&(a.itemType===t&&a.itemId==e&&i.push(s))}return i},t.prototype.batchGetLocalByParent=function(t,e,r,n){for(var i=this.entries[r],o={},s=0,a=e;s<a.length;s++){o[a[s]]=[]}if(void 0===i)return o;for(var c in i){var u=i[c],l=this.transaction.getParent(u);null!==l&&(l.itemType===t&&void 0!==o[l.itemId]&&u.isLocal()&&(null===n||this.matchQuery(u,n))&&o[l.itemId].push(u))}return o},t.prototype.forEach=function(t){var e=this.entries;for(var r in e)for(var n in e[r])t(e[r][n])},t.prototype.toArray=function(){var t=this.entries,e=[];for(var r in t)for(var n in t[r])e.push(t[r][n]);return e},t.prototype.add=function(t){var e=this.entries,r=t.itemType;return void 0===e[r]&&(e[r]={}),this.entriesByEntryId[t.id]=t,e[r][t.itemId]=t},t.prototype.get=function(t,e){return void 0===this.entries[t]?void 0:this.entries[t][e]},t.prototype.contains=function(t,e){return void 0!==this.entries[t]&&void 0!==this.entries[t][e]},t.prototype.updateItemId=function(t,e){var r=this.entries[t.itemType];return delete r[e],r[t.itemId]=t},t.prototype.clear=function(t){return void 0===t?(this.entries={},this.entriesByEntryId={},!0):this.clearByItemId(t.itemType,t.itemId)},t.prototype.clearByItemId=function(t,e){var r=this.entries[t];return void 0!==r&&(!!r.hasOwnProperty(e)&&(delete this.entriesByEntryId[r[e].id],delete r[e]))},t.prototype.matchQuery=function(t,e){var r=this.transaction.getLocalItemEntryChangesTuple(t.id);return!0===this.queryMatcherFactory.construct(t.itemType,this.transaction instanceof Gt?r.changes:r.changes.changes,this.transaction.getParent(t)).matchQuery(e.object)},t}(),Zt=function(){function t(t,e,r){this.authInterface=t,this.keyService=e,this.linkTreeService=r}return t.prototype.matchParent=function(t,e){return null===t&&null===e||!(null===t&&null!==e||null!==t&&null===e)&&(t.itemType===e.itemType&&t.itemId==e.itemId)},t.prototype.getLinkFieldsByParent=function(t,e){var r=this.linkTreeService.get()[t.itemType][e];if(void 0===r)throw new Error("Non existing link between '"+t.itemType+"'->'"+e+"'");var n={};return r.type===D.DIRECT?n[r.field]=t.itemId:(n.itemtype=t.itemType,n.item=t.itemId),n},t.prototype.getParentByFields=function(t,e,r){var n=this.linkTreeService.get()[t][e.itemType];if(void 0===n)throw new Error("Non existing link between '"+t+"'->'"+e.itemType+"'");var i={};return n.type===D.DIRECT?(i.itemType=t,i.itemId=r[n.field]):(i.itemType=r.itemtype,i.itemId=r.item),i},t.prototype.getDisplayName=function(t,e){switch(t.itemType){case"Contact":return"bedrijf"===e.type?e.bedrijf:this.getFullName(e.voornaam,e.tussenvoegsel,e.naam);case"Medewerker":case"Person":return this.getFullName(e.voornaam,e.tussenvoegsel,e.achternaam);default:return e[this.getTitleField(t.itemType)]}},t.prototype.processOptions=function(t){return new B(t)},t.prototype.createUnfoundRemoteItemError=function(){return{message:"The requested item could not be found / your current permissions are not sufficient"}},t.prototype.createUnfoundLocalItemError=function(t){return{message:"A local item of type "+t+" could not be found"}},t.prototype.createExistingLocalItemError=function(t){return{message:"A local item of type "+t+" not be created, the ID is already in use"}},t.prototype.createLocalConversionMap=function(t,e,r,n){void 0===r&&(r=!1);var i=n.links[t][0],o={};return o[t]={},o[t][i]=e,r&&this.expandLocalConversionMap(t,i,n,o),o},t.prototype.expandLocalConversionMap=function(t,e,r,n){var i=r.items[t][e].links;for(var o in i){var s=i[o];void 0===n[o]&&(n[o]={});for(var a=0,c=s;a<c.length;a++){var u=c[a];n[o][u]=this.keyService.getLocalId(),this.expandLocalConversionMap(o,u,r,n)}}},t.prototype.expandConversionMap=function(t,e,r){var n,i=t.itemType,o=t.itemId;return void 0===e[i]&&(e[i]={}),void 0!==(n=e[i])[o]?n[o]:(void 0===r&&(r=this.keyService.getLocalId()),n[o]=r)},t.prototype.batchExpandConversionMap=function(t,e){for(var r=0,n=t;r<n.length;r++){var i=n[r];this.expandConversionMap(i,e)}return e},t.prototype.getConversionValue=function(t,e,r){if(void 0!==r[t])return r[t][e]},t.prototype.getFullName=function(t,e,r){return void 0===t&&(t=""),void 0===e&&(e=""),void 0===r&&(r=""),t.trim().concat(" ",e).trim().concat(" ",r).trim()},t.prototype.getTitleField=function(t){switch(t){case"Exemplaar":return"serienummer";case"Factuur":return"nummer";case"Files":return"friendlyname";case"Functie":case"Standaardfunctie":return"naamintern";case"Voorraadmutatie":return"omschrijving";case"Barcode":return"code";case"Betaalmiddel":case"Betalingsconditie":case"Briefpapier":case"TaxClass":case"TaxSchema":case"Condition":case"Factuurmoment":case"Functiegroep":case"Grootboek":case"Inhuur":case"Inhuurgroep":case"Inhuurmateriaal":case"Materiaal":case"MateriaalCat":case"Medewerkertarief":case"Notitie":case"Planningmateriaal":case"Project":case"Staffelgroep":case"Subproject":case"Taak":case"Tag":case"Template":case"Tijd":case"Titel":case"Type":case"Voertuig":return"naam";default:return"displayname"}},t.prototype.getLocalDefaultValues=function(){return{permissions:"7",creator:this.authInterface.getUserId(),created:n()}},t}(),$t=function(){function t(){this.separator=":"}return t.prototype.getSingleKey=function(t,e){return t+this.separator+e},t.prototype.getCssKey=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return t.join("_")},t.prototype.parseStateKey=function(t){return"new-"===(t=t.toString()).substring(0,"new-".length)?{type:"new",template:t.substring("new-".length)}:"dup-"===t.substring(0,"dup-".length)?{type:"duplicate",itemId:+t.substring("dup-".length)}:null},t.prototype.getDuplicateStateKey=function(t){return"dup-"+t},t.prototype.getNewStateKey=function(t){return"new-"+t},t.prototype.getLocalId=function(){return+("-1"+this.getRandomString())},t.prototype.getLocalDuplicateId=function(){return+("-2"+this.getRandomString())},t.prototype.getRandomString=function(){return(""+Math.random()).split(".")[1].substr(0,8)},t.prototype.isLocalId=function(t){return void 0!==t&&(this.isNewId(t)||this.isDuplicateId(t))},t.prototype.isNewId=function(t){return"new-"===t||"-1"===(""+t).substring(0,"-1".length)},t.prototype.isDuplicateId=function(t){return"dup-"===t||"-2"===(""+t).substring(0,"-2".length)},t}(),te=function(){function t(t,e,r,n){this.apiRequestService=t,this.errorHandler=e,this.keyService=r,this.promiseService=n,this.lockItems={},this.promises={}}return t.prototype.getLocks=function(){return this.lockItems},t.prototype.hasLock=function(t){var e=this.lockItems;for(var r in e)for(var n in e[r]){var i=e[r][n];if(!i.isForeign&&i.id==t)return!0}return!1},t.prototype.isLocked=function(t){var e=this.getValue(t,this.lockItems);return void 0!==e&&e.isForeign},t.prototype.getMessage=function(t){var e=this.getValue(t,this.lockItems);if(void 0!==e&&e.isForeign)return e.message},t.prototype.fetchCachedLock=function(t){var e=this.getValue(t,this.lockItems);if(void 0!==e)return this.promiseService.when(e);var r=this.getValue(t,this.promises);return void 0!==r?r:this.promiseService.when()},t.prototype.fetchLock=function(t){var e=this,r=this.errorHandler;return this.fetchCachedLock(t).then(function(r){return void 0!==r?r:e.requestLock(t)},r.reject).then(function(t){return t.isForeign?r.reject(t.message):t.token},r.reject)},t.prototype.requestLock=function(t){var e=this,r=t.itemType,n=t.itemId,i=this.apiRequestService.create("Locktoken",this.keyService.getLocalId(),{itemtype:r,item:n}).then(function(i){return delete e.promises[r][n],e.setValue(t,i.fetchObject("Locktoken",i.links.Locktoken[0]),e.lockItems)},function(i){return delete e.promises[r][n],301===i.code?e.setValue(t,{isForeign:!0,message:i.message},e.lockItems):e.errorHandler.reject(i)});return this.setValue(t,i,this.promises)},t.prototype.deleteLock=function(t){var e=this;return this.fetchCachedLock(t).then(function(r){if(void 0!==r){if(!r.isForeign)return e.apiRequestService.delete("Locktoken",[r.id]).then(function(){e.clearLock(t)},e.errorHandler.reject);e.clearLock(t)}},this.errorHandler.reject)},t.prototype.clearLock=function(t){var e=this.lockItems[t.itemType];return void 0!==e&&delete e[t.itemId]},t.prototype.getValue=function(t,e){var r=t.itemType;if(void 0!==e[r])return e[r][t.itemId]},t.prototype.setValue=function(t,e,r){return p(r,[t.itemType,t.itemId],[{},e])},t}(),ee={},re=function(){function t(t){this.transaction=t,this.parentMap={},this.destination={}}return t.prototype.process=function(){if(void 0===this.transaction.rootItem)throw new Error("A TransactionCache rootItem is required for ModuleChangesCompilation");return this.parentMap=this.createParentMap(),this.processItems(this.transaction.rootItem.itemType,[this.transaction.rootItem],{}),{itemType:this.transaction.rootItem.itemType,itemId:this.transaction.rootItem.itemId,items:this.destination}},t.prototype.createParentMap=function(){var t=this,e={};return this.transaction.itemHandler.entries.forEach(function(r){var n=r.itemType,i=t.transaction.getParent(r);if(null!==i){var o=i.itemType,s=i.itemId;void 0===e[o]&&(e[o]={}),void 0===e[o][s]&&(e[o][s]={}),void 0===e[o][s][n]&&(e[o][s][n]=[]),e[o][s][n].push(r)}}),e},t.prototype.processItems=function(t,e,r){void 0===this.destination[t]&&(this.destination[t]={}),void 0===r[t]&&(r[t]=[]);for(var n=0,i=e;n<i.length;n++){var o=i[n],s=o.itemId;void 0===this.destination[t][s]&&(r[t].push(s),this.destination[t][s]=this.processItem(o))}},t.prototype.processItem=function(t){var e=t.itemType,r=t.itemId,n=this.getItemsByParent(e,r),i=this.transaction.collectionHandler.entries.getCollectionsByParent(e,r),o=this.transaction.itemHandler.formatRequest(t),a={};for(var c in n)this.processItems(c,n[c],a);for(var u=0,l=i;u<l.length;u++){var h=l[u];null===h.options.query&&this.processItems(h.itemType,this.transaction.getCollectionChangesRecursively(h.id),a)}var p=s(o),d=s(a);return p&&d?{values:o,links:a}:p?{values:o}:d?{links:a}:ee},t.prototype.getItemsByParent=function(t,e){var r=this.parentMap[t];return void 0===r?{}:void 0===r[e]?{}:r[e]},t}(),ne="maybe",ie=function(){function t(t,e,r,n){void 0===n&&(n=null),this.apiFormatter=t,this.itemType=e,this.fields=r,this.parent=n}return t.prototype.compareValues=function(t,e){return n.isMoment(e)?this.apiFormatter.compareMomentObjects(e,t):n.isDuration(e)?this.apiFormatter.compareDurations(e,t):e==t},t.prototype.matchQuery=function(t){if(void 0!==t.search)return ne;if(void 0!==t.custom)return ne;if(void 0!==t.linkedTo)return this.matchLinkedToQuery(t);if(void 0!==t.query)return ne;if(void 0!==t.conditions)return this.matchComplexQuery(t);if(void 0!==t.key)return this.matchSimpleQuery(this.fields[t.key],t);if(!s(t))return!0;throw new Error("queryMatcher: Unsupported query! Parsed?")},t.prototype.matchLinkedToQuery=function(t){if(t.reverse)return ne;var e,r=this.parent;return(e=null!==r&&(t.linkedTo===r.itemType&&this.matchSimpleQuery(r.itemId,t.query)))===ne?ne:t.not?!e:!!e},t.prototype.matchComplexQuery=function(t){var e,r,n=t.conditions;switch(t.operator){case"AND":e=!0,r=!1;break;case"OR":e=!1,r=!0;break;default:throw new Error("queryMatcher: Unsupported operator")}for(var i=0,o=n;i<o.length;i++){var s=o[i],a=this.matchQuery(s);if(a===r)return t.not?!r:r;a===ne&&(e=ne)}return e===ne?ne:t.not?!e:e},t.prototype.matchSimpleQuery=function(t,e){var r=e.key,i=e.value;if(!s(e))return!0;if(void 0===t)return console.warn("Required field",r,"not found for",this.itemType),ne;switch("NOW"===i&&(i=n()),e.comparator){case"=":return this.compareValues(t,i);case"!=":return!this.compareValues(t,i);case"<":return t<i;case"<=":return t<=i;case">":return t>i;case">=":return t>=i;case"IN":var o=c(t,i);return e.not?!o:o;default:throw new Error("queryMatcher: Unsupported comparator: "+e.comparator+" in query "+e)}},t}(),oe=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();!function(t){t[t.OBJ=0]="OBJ",t[t.STR=1]="STR",t.SEP=":"}(At||(At={}));var se=Object.keys(Rt).map(function(t){return Rt[t]}),ae=((Bt={})[Rt.EQUALS]=Rt.NOT_EQUALS,Bt[Rt.NOT_EQUALS]=Rt.EQUALS,Bt[Rt.MORE_THAN]=Rt.LESS_OR_EQUAL_THAN,Bt[Rt.LESS_THAN]=Rt.EQUAL_OR_MORE_THAN,Bt[Rt.LESS_OR_EQUAL_THAN]=Rt.MORE_THAN,Bt[Rt.EQUAL_OR_MORE_THAN]=Rt.LESS_THAN,Bt[Rt.IN]=Rt.IN,Bt),ce=function(t){function e(e,r){var n=t.call(this,e)||this;return n.parameters=r,n}return oe(e,t),e.prototype.parseEmptyQuery=function(){return[{},"{}"]},e.prototype.parseSubQuery=function(t,e,r){void 0===r&&(r=!1);var n=this.parse(e);return[{key:t,query:n[At.OBJ],not:r},"[sub"+At.SEP+t+At.SEP+n[At.STR]+At.SEP+r+"]"]},e.prototype.parseSubFieldQuery=function(t,e,r,n,i){void 0===t&&(t=""),void 0===e&&(e=""),void 0===r&&(r=""),void 0===i&&(i=!1);var o=this.parse(n);return[{key:t,itemType:e,field:r,query:o[At.OBJ],not:i},"[subField"+At.SEP+t+At.SEP+e+At.SEP+r+At.SEP+o[At.STR]+At.SEP+i+"]"]},e.prototype.parseSearchQuery=function(t,e){return void 0===e&&(e=!1),[{search:(t=this.formatValue(t))[At.OBJ],not:e},"[search"+At.SEP+t[At.STR]+At.SEP+e+"]"]},e.prototype.parseCustomQuery=function(t,e,r){if(void 0===r&&(r=!1),void 0===e)return[{custom:t,not:r},"["+t+At.SEP+r+"]"];var n=this.parseCustomParameters(e);return[{custom:t,parameters:n[At.OBJ],not:r},"["+t+At.SEP+n[At.STR]+At.SEP+r+"]"]},e.prototype.parseCustomParameters=function(t){for(var e=Object.keys(t).sort(),r={},n="",i=0;i<e.length;i++){var o=e[i],s=this.formatValue(t[o]);r[o]=s[At.OBJ],i>0&&(n+=At.SEP),n+=s[At.STR]}return[r,n]},e.prototype.parseSimpleQuery=function(t,e,r,n){if(void 0===n&&(n=!1),e=this.formatValue(e),void 0===r&&(r=Array.isArray(e[At.OBJ])?Rt.IN:Rt.EQUALS),-1===se.indexOf(r))throw new Error("Unknown comparator '"+r+"', it might be that the backend supports it but the frontend doesn't !");n&&(r=ae[r]);var i=r===Rt.IN&&n,o=[{key:t,value:e[At.OBJ],comparator:r,not:i},"["+r+At.SEP+t+At.SEP+e[At.STR]+"]"];return i&&(o[1]=o[1].slice(0,-1),o[1]+=At.SEP+n+"]"),o},e.prototype.parseLinkedToQuery=function(t,e,r,n){void 0===e&&(e={}),void 0===r&&(r=!1),void 0===n&&(n=!1);var i=this.parse(e);return[{linkedTo:t,query:i[At.OBJ],reverse:r,not:n},"[linkedTo"+At.SEP+t+At.SEP+i[At.STR]+At.SEP+r+At.SEP+n+"]"]},e.prototype.parseComplexQuery=function(t,e,r){void 0===e&&(e=St.AND),void 0===r&&(r=!1),e=e.toUpperCase();var n=this.parseConditions(t);return[{conditions:n[At.OBJ],operator:e,not:r},"["+e+n[At.STR]+At.SEP+r+"]"]},e.prototype.parseConditions=function(t){for(var e=this,r=[],n=[],i="",o=0,s=t;o<s.length;o++){var a=s[o];r.push(this.parse(a))}for(var c=0,u=r=r.sort(function(t,r){return e.compareParsedQueries(t,r)});c<u.length;c++){var l=u[c];n.push(l[At.OBJ]),i+=l[At.STR]}return[n,i]},e.prototype.formatValue=function(t){var e;if("string"==typeof t&&"&"===t.charAt(0)){var r=t.substring(1);if(void 0===(t=this.parameters[r]))throw new Error("queryParser: Undefined template parameter '"+r+"'");return[e=this.processValue(t),r+">"+t]}return[e=this.processValue(t),""+e]},e.prototype.processValue=function(t){return Array.isArray(t)?t.slice().sort():n.isMoment(t)?n(t):n.isDuration(t)?n.duration(t):t},e.prototype.compareParsedQueries=function(t,e){return t[At.STR]===e[At.STR]?0:t[At.STR]>e[At.STR]?1:-1},e}(Qt),ue=function(){function t(){}return t.prototype.addAndCondition=function(t,e){return void 0===t.conditions||t.operator===St.OR?{conditions:[t,e]}:{conditions:t.conditions.concat(e)}},t.prototype.addOrCondition=function(t,e){return t.operator===St.OR?{conditions:t.conditions.concat(e)}:{conditions:[t,e],operator:St.OR}},t.prototype.addParentCondition=function(t,e){var r;return null===e?t:(r={linkedTo:e.itemType,query:e.itemId},null===t?r:this.addAndCondition(t,r))},t.prototype.createNotIn=function(t){return{comparator:Rt.IN,key:"id",value:t,not:!0}},t}(),le=function(){function t(t){this.columnUtil=t,this.columns={},this.columnSetIdMap={}}return t.prototype.expandWithRequestColumns=function(t,e){var r=this.columns;void 0===r[t]&&(r[t]=[]),r[t]=this.columnUtil.mergeRequestColumns(r[t],e).merged},t.prototype.expand=function(t){if(!this.columnSetIdMap[t.id]){var e=this.columns,r=t.itemType;void 0===e[r]&&(e[r]=[]),e[r]=this.columnUtil.mergeRequestColumns(e[r],t.request).merged,this.columnSetIdMap[t.id]=!0}},t.prototype.get=function(){return this.columns},t}(),he=function(){function t(t,e,r,n,i,o,s,a){this.requestBufferManager=t,this.changesDeltaFactory=e,this.apiFormatter=r,this.errorHandler=n,this.transactionCacheFactory=i,this.promiseService=o,this.requestColumnExpansionFactory=s,this.apiRequestService=a}return t.prototype.onMessageReceived=function(t){switch(t.body.eventType){case"update":return this.handleUpdate(t);case"create":return this.handleCreate(t);case"delete":return this.handleDelete(t);case"linkTo":return this.handleLinkMove(t)}},t.prototype.formatMessageValues=function(t,e){var r={};for(var n in e)r[n]=this.apiFormatter.formatResponseValue(e[n].type,t[n]);return r},t.prototype.createCollectionMap=function(t,e,r){var n=this.transactionCacheFactory.getServerCache(),i={};for(var o in e){var s=e[o],a=null!==s.parent?s.parent:{},c=this.formatMessageValues(s.values,r);i[o]=n.collectionHandler.entries.getByFittingItem(t,c,a)}return i},t.prototype.getRequestColumns=function(t,e){var r=this.transactionCacheFactory.getServerCache(),n=this.requestColumnExpansionFactory.construct();for(var i in e){for(var o=e[i].fitting,s=r.itemHandler.entries.get(t,i),a=0,c=o;a<c.length;a++){var u=c[a];n.expand(u.columns)}void 0!==s&&n.expand(s.columns)}return n.get()},t.prototype.processMessage=function(t){var e=this.transactionCacheFactory.getServerCache(),r=t.itemType,n=[],i=this.createCollectionMap(r,t.items[r],t.columns[r]),o=this.getRequestColumns(r,i);for(var s in i){var a=+s;void 0===e.itemHandler.entries.get(r,s)?0!==i[a].fitting.length&&n.push(a):n.push(a)}return 0===n.length?this.promiseService.when():this.apiRequestService.query(r,{key:"id",comparator:"IN",value:n},o).then(function(t){return e.processResponse(t,o,!1,!0)},this.errorHandler.reject)},t.prototype.processFunctionChangesResolve=function(t){var e=this,r=this.transactionCacheFactory.getServerCache(),n=t.items.FunctionChangesResolve,i=[];for(var o in n){var s=n[o].parent.itemId,a=r.itemHandler.entries.get("Functie",s);void 0!==a&&void 0!==a.columns.response.Functie.newchanges&&i.push(s)}return 0===i.length?this.promiseService.when():this.requestBufferManager.fetchByIds("Functie",i,["newchanges"]).then(function(t){for(var n=e.changesDeltaFactory.construct(),i=0,o=t.response.links.Functie;i<o.length;i++){var s=o[i],a=r.itemHandler.entries.get("Functie",s),c=r.itemHandler.itemChanges[a.id],u=t.response.fetchObject("Functie",s,!1);void 0!==u&&u.newchanges!==c.newchanges&&n.setItemUpdated(a,{newchanges:u.newchanges})}return r.applyChangesDelta(n,!1,!0)},this.errorHandler.reject).catch(this.errorHandler.notifyError)},t.prototype.isFunctionChangesResolveMessage=function(t){return"FunctionChangesResolve"===t.body.itemType},t.prototype.handleCreate=function(t){var e=t.body;return this.isFunctionChangesResolveMessage(t)?this.processFunctionChangesResolve(e):this.processMessage(e).catch(this.errorHandler.notifyError)},t.prototype.handleUpdate=function(t){return this.processMessage(t.body).catch(this.errorHandler.notifyError)},t.prototype.handleDelete=function(t){for(var e=this.changesDeltaFactory.constructInternalDelta(),r=this.transactionCacheFactory.getServerCache(),n=t.body,i=[],o=0,s=n.items;o<s.length;o++){var a=s[o],c=r.itemHandler.entries.get(n.itemType,a);void 0!==c&&i.push(c)}return e.setItemsDeleted(i),r.applyChangesFromParent(e,!1,!0),this.promiseService.when()},t.prototype.handleLinkMove=function(t){return this.processMessage(t.body).catch(this.errorHandler.notifyError)},t}(),pe=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),de=function(){return(de=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},fe=function(t){function e(e,r,n,i,o,s,a,c,u,l,h,p,d,f,m){var y=t.call(this,a,r,e,s,m)||this;return y.columnSubsetCacheFactory=n,y.columnExpansionFactory=i,y.changesDeltaFactory=o,y.collectionMatcherFactory=c,y.columnHandler=u,y.errorHandler=l,y.itemHandler=h,y.keyService=p,y.promiseService=d,y.exceptionHandler=f,y.transaction=m,y.collectionResources={},y}return pe(e,t),e.prototype.fetchItemEntriesByQuery=function(t,e,r){var n=this;return this.isLocal(r)?this.fetchCollectionEntry(t,new K({columns:r.columns,parent:r.parent,query:e})).then(function(t){return n.collectionChanges[t.itemType][t.query.string]},this.errorHandler.reject):this.transaction.getServerCache().collectionHandler.fetchItemEntriesByQuery(t,e,r)},e.prototype.getAllCollectionsByItemType=function(t){var e=[];if(void 0===this.collectionChanges[t])return e;for(var r in this.collectionChanges[t]){var n=this.transaction.getLocalCollectionEntryByQueryString(t,r);void 0!==n&&n.itemType===t&&e.push(n)}return e},e.prototype.createCollectionEntry=function(e,r){return this.isLocal(r)?t.prototype.createCollectionEntry.call(this,e,r):this.transaction.getServerCache().collectionHandler.createCollectionEntry(e,r)},e.prototype.onItemEntriesCreated=function(t,e){var r=this.collectionResources[t.id];if(void 0!==r)for(var n=0,i=r;n<i.length;n++){var o=i[n];try{o.options.onItemsCreated(e)}catch(t){this.exceptionHandler(t)}}},e.prototype.clearEntry=function(t){this.entries.clear(t),delete this.collectionResources[t.id]},e.prototype.addResource=function(t){var e=this.collectionResources[t.entry.id];void 0===e&&(e=this.collectionResources[t.entry.id]=[]),e.push(t)},e.prototype.clearResource=function(t){var e=this.collectionResources[t.entry.id],r=e.indexOf(t);-1!==r&&e.splice(r,1),0===e.length&&delete this.collectionResources[t.entry.id]},e.prototype.moveItems=function(t,e,r){if(t.itemType!==e.itemType)throw new Error("collectionResourceService: Cannot move items: itemType mismatch");for(var n=this.changesDeltaFactory.construct(),i=0,o=r;i<o.length;i++){var s=o[i];n.setItemMoved(s,e.parent)}this.transaction.applyChangesDelta(n)},e.prototype.extendCollectionEntry=function(t,e){return this.transaction.getServerCache().collectionHandler.extendCollectionEntry(t,e)},e.prototype.cloneCollectionEntry=function(t,e,r){void 0===r&&(r={});var n=this.transaction.getCollectionChangesRecursively(t.id),i=this.createCollectionEntry(t.itemType,this.collectionEntryService.cloneOptions(t.options,e));if(i.columns=this.transaction.core.columnSetFactory.construct(i.itemType,t.columns.request,t.columns.response),null!==t.parent){var o=t.parent;void 0===r[o.itemType]&&(r[o.itemType]={}),r[o.itemType][o.itemId]=e.itemId}return this.itemHandler.cloneItemEntries(n,r),i},e.prototype.getCollectionMatcher=function(){var t=this;return this.collectionMatcherFactory.construct(this.transaction,function(e){return t.getAllCollectionsByItemType(e)})},e.prototype.fetchCollectionEntry=function(t,e){var r=this;if(!this.isLocal(e))return this.transaction.getServerCache().collectionHandler.fetchCollectionEntry(t,e);var n=this.collectionEntryService.createQuery(e);this.expandColumnsWithQueryColumns(t,e,n.object);var i,o=this.changesDeltaFactory.construct(),s=this.columnSubsetCacheFactory.construct(e.columns);return this.fetchCollectionData(o,t,s,e,n).then(function(t){return i=t,r.transaction.applyChangesDelta(o)},this.errorHandler.reject).then(function(){return i},this.errorHandler.reject)},e.prototype.fetchLinkedCollectionEntries=function(t,e,r,n){S(e)&&(e=e());for(var i=[],o=[],s=0,a=e;s<a.length;s++){var c=a[s];this.keyService.isLocalId(c)?o.push(c):i.push(c)}return this.promiseService.all({remote:this.transaction.getServerCache().collectionHandler.fetchLinkedCollectionEntries(t,i,r,n),local:this.fetchLinkedLocalCollectionEntries(t,o,r,n)}).then(function(t){return de({},t.remote,t.local)})},e.prototype.expandCollectionEntries=function(t,e,r,n){return this.transaction.getServerCache().collectionHandler.expandCollectionEntries(t,e,r,n)},e.prototype.extendCollectionEntries=function(t,e,r,n,i){return this.transaction.getServerCache().collectionHandler.extendCollectionEntries(t,e,r,n,i)},e.prototype.addItemEntriesToCollectionChanges=function(e,r,n){void 0===n&&(n=!1),t.prototype._addItemEntriesToCollectionChanges.call(this,e,r,function(){return!1},n)},e.prototype.isLocal=function(t){var e=t.parent;return null!==e&&this.keyService.isLocalId(e.itemId)},e.prototype.expandCollectionEntry=function(t,e,r){var n=this,i=e.columns.mergeRequestColumns(r).difference;if(!0!==i&&0===i.length)return this.promiseService.when(e);var o=e.itemType;return this.columnHandler.fetch(o,i).then(function(r){return n.itemHandler.expandLocalItemEntries(t,o,n.getCollectionChanges(e.itemType,e.query.string),i,r).then(function(){var t=n.columnExpansionFactory.construct(o,i,r);return e.expandColumns(t),e},n.errorHandler.reject)},this.errorHandler.reject)},e.prototype.handleAddedItemEntriesCallback=function(t,e){var r=this.collectionResources[t.id];if(0!==e.length&&void 0!==r&&0!==r.length)for(var n=0,i=r;n<i.length;n++){i[n].addItemResources(e)}},e.prototype.handleRemovedItemEntriesCallback=function(t,e){var r=this.collectionResources[t.id];if(0!==e.length&&void 0!==r&&0!==r.length)for(var n=0,i=r;n<i.length;n++){var o=i[n],s=o.removeItemResources(e);o.callOnRemove(s)}},e.prototype.fetchCollectionData=function(t,e,r,n,i){var o=this,s=this.entries.getByQuery(e,i);if(null!==s)return r.run(s.columns)?this.promiseService.when(s):this.expandCollectionEntry(t,s,r.requestColumns);var a=this.createCollectionEntry(e,n);return this.columnHandler.fetch(e,n.columns).then(function(t){return a.columns=o.transaction.core.columnSetFactory.construct(a.itemType,n.columns,t),a})},e.prototype.fetchLinkedLocalCollectionEntries=function(t,e,r,n){for(var i=this,o=this.changesDeltaFactory.construct(),s={},a=0,c=e;a<c.length;a++){var u=c[a],l=this.collectionEntryService.cloneOptions(n,{itemType:t,itemId:u}),h=this.collectionEntryService.createQuery(l);this.expandColumnsWithQueryColumns(r,l,h.object);var p=this.columnSubsetCacheFactory.construct(l.columns);s[u]=this.fetchCollectionData(o,r,p,l,h)}return this.promiseService.all(s).then(function(t){return i.transaction.applyChangesDelta(o).then(function(){return t},i.errorHandler.reject)},this.errorHandler.reject)},e}(Nt),me=function(){function t(t){this.transaction=t,this.lastCallId={global:{},item:{}}}return t.prototype.setGlobalError=function(t,e,r,n){var i=this,o=this.getRandomId();this.lastCallId.global[t]=o,R(e)?(this.transaction.isValid=!1,e.then(function(e){o===i.lastCallId.global[t]&&(delete i.lastCallId.global[t],i.transaction._setGlobalError(t,e,r,n))},function(){i.transaction._setIsValid()})):this.transaction._setGlobalError(t,e,r,n)},t.prototype.setItemError=function(t,e,r,n,i,o){var s=this,a=this.getRandomId();this.lastCallId.item[t]=a,R(n)?(this.transaction.isValid=!1,n.then(function(n){a===s.lastCallId.item[t]&&(delete s.lastCallId.item[t],s.transaction._setItemError(t,e,r,n,i,o))},function(){s.transaction._setIsValid()})):this.transaction._setItemError(t,e,r,n,i,o)},t.prototype.getRandomId=function(){return Math.random().toString().split(".")[1]},t}(),ye=function(){function t(t){this.itemEntryService=t,this.updated={},this.deleted={},this._queryResults={}}return t.prototype._setQueryResult=function(t,e,r){void 0===this._queryResults[t]&&(this._queryResults[t]={}),this._queryResults[t][e]=r},t.prototype.setItemUpdated=function(t,e,r,n){void 0===r&&(r=null),void 0===n&&(n=null),void 0===this.updated[t.id]&&(this.updated[t.id]={entry:t,changes:{fields:{},expandedColumns:null,parent:n}});var i=this.updated[t.id];if(null!==n){var o=this.itemEntryService.getLinkFieldsByParent(n,t.itemType);for(var s in o)e[s]=o[s]}for(var a in e){var c=Object.getOwnPropertyDescriptor(e,a);void 0!==c?Object.defineProperty(i.changes.fields,a,c):i.changes.fields[a]=e[a]}null!==r&&(i.changes.expandedColumns=r)},t.prototype.setItemDeleted=function(t){this.setItemsDeleted([t])},t.prototype.setItemsDeleted=function(t){for(var e=0,r=t;e<r.length;e++){var n=r[e];void 0===this.deleted[n.itemType]&&(this.deleted[n.itemType]=[]),this.deleted[n.itemType].indexOf(n)>-1||this.deleted[n.itemType].push(n)}},t}(),ve=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),ge=function(t){function e(e){var r=t.call(this,e)||this;return r.created=[],r}return ve(e,t),e.prototype.setItemCreated=function(t,e,r,n){void 0===n&&(n=null);var i={};if(null!==n)for(var o in i=this.itemEntryService.getLinkFieldsByParent(n,r.itemType))e[o]=i[o];var s=this.itemEntryService.getLocalDefaultValues();for(var o in s)e[o]=s[o];this.created.push({itemId:t,fields:e,columns:r})},e.prototype.setItemMoved=function(t,e){this.setItemUpdated(t,{},null,e)},e}(ye),Ce=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),Ie=function(t){function e(e){var r=t.call(this,e)||this;return r.created={},r.moved={},r.itemIdConversionMap={},r}return Ce(e,t),e.prototype.setItemCreated=function(t,e){this.created[t.id]={entry:t,fields:e}},e.prototype.setItemMoved=function(t,e){this.moved[t.id]={entry:t,to:e}},e}(ye),Ee=function(){function t(t,e,r,n,i,o){this.promiseLibrary=t,this.apiRequestService=e,this.requestColumnExpansionFactory=r,this.changesDeltaFactory=n,this.serverCache=i,this.itemType=o,this.deferred=this.promiseLibrary.defer(),this.requestColumnExpansion=this.requestColumnExpansionFactory.construct(),this.singleItemIds=[],this.queries={}}return t.prototype.containsId=function(t){return-1!==this.singleItemIds.indexOf(t)},t.prototype.containsQuery=function(t){return void 0!==this.queries[t]},t.prototype.addSingleItem=function(t,e){return this.requestColumnExpansion.expandWithRequestColumns(this.itemType,e),-1===this.singleItemIds.indexOf(t)&&this.singleItemIds.push(t),this.getPromise()},t.prototype.addQuery=function(t,e){return this.requestColumnExpansion.expandWithRequestColumns(this.itemType,e),void 0===this.queries[t[1]]&&(this.queries[t[1]]=t[0]),this.getPromise()},t.prototype.flush=function(){var t=this,e=[];for(var r in this.singleItemIds.length>0&&e.push({key:"id",comparator:"IN",value:this.singleItemIds}),this.queries)e.push(this.queries[r]);if(0===e.length)throw new Error("Tried to flush a RequestBuffer without singleItems or queries");var n,i=this.requestColumnExpansion.get();return this.apiRequestService.query(this.itemType,{conditions:e,operator:"OR"},i).then(function(e){n=e;var r=t.changesDeltaFactory.construct();if(0===t.singleItemIds.length&&!t.hasMultipleQueries()){var o=t.getFirstQueryString();void 0!==o&&r._setQueryResult(t.itemType,o,n.links[t.itemType])}return t.serverCache.processResponse(n,i,!1,!1,r)},function(e){return t.deferred.reject(e)}).then(function(){return t.deferred.resolve(n)},function(e){return t.deferred.reject(e)}),this.getPromise()},t.prototype.getPromise=function(){return this.deferred.promise},t.prototype.hasMultipleQueries=function(){var t=!0;for(var e in this.queries){if(!t)return!0;t=!1}return!1},t.prototype.getFirstQueryString=function(){for(var t in this.queries)return t},t}(),Fe=function(){function t(t,e,r,n,i,o){this.promiseLibrary=t,this.apiRequestService=e,this.requestColumnExpansionFactory=r,this.keyService=n,this.errorHandler=i,this.changesDeltaFactory=o,this.pendingBufferMap={},this.pendingTrueBufferMap={},this.pendingQueryBufferMap={},this.pendingTemplateBufferMap={}}return t.prototype.setServerCache=function(t){this.serverCache=t},t.prototype.containsId=function(t,e){return!!d(this.pendingTemplateBufferMap,[t,e])||void 0!==this.pendingBufferMap[t]&&this.pendingBufferMap[t].containsId(e)},t.prototype.containsQuery=function(t,e){return void 0!==d(this.pendingQueryBufferMap,[t,e])},t.prototype.fetchByIds=function(t,e,r){for(var n=0,i=e;n<i.length;n++){var o=i[n];this.fetchById(t,o,r)}return this.pendingBufferMap[t].getPromise()},t.prototype.fetchById=function(t,e,r){if(this.keyService.isLocalId(e))throw new Error("Unexpected local ItemId in RequestBufferManager.fetchById, for local ItemIds you should use RequestBufferManager.fetchByLocalId");var n;return!0===r?void 0===(n=this.pendingTrueBufferMap[t])?n=this.constructBuffer(t,this.pendingTrueBufferMap):console.log("Existing 'columns: true' RequestBuffer "+t+" at "+performance.now()+" by id"):void 0===(n=this.pendingBufferMap[t])?n=this.constructBuffer(t):console.log("Existing RequestBuffer "+t+" at "+performance.now()+" by id"),n.addSingleItem(e,r),n.getPromise()},t.prototype.fetchByQuery=function(t,e,r){var n=this.pendingBufferMap[t];return void 0===n?n=this.constructBuffer(t):console.log("Existing RequestBuffer "+t+" at "+performance.now()+" with query"),n.addQuery(e,r),n.getPromise()},t.prototype.fetchByLocalId=function(t,e,r){return void 0===e&&(e="no-id"),void 0===this.pendingTemplateBufferMap[t]||void 0===this.pendingTemplateBufferMap[t][e]?this.constructTemplateBuffer(t,e,r):this.pendingTemplateBufferMap[t][e]},t.prototype.constructBuffer=function(t,e){void 0===e&&(e=this.pendingBufferMap);var r=e[t]=new Ee(this.promiseLibrary,this.apiRequestService,this.requestColumnExpansionFactory,this.changesDeltaFactory,this.serverCache,t);return window.setTimeout(function(){r.flush(),delete e[t]},150),r},t.prototype.constructTemplateBuffer=function(t,e,r){var n=this;return void 0===this.pendingTemplateBufferMap[t]&&(this.pendingTemplateBufferMap[t]={}),this.pendingTemplateBufferMap[t][e]=this.apiRequestService.template(t,r).then(function(r){return delete n.pendingTemplateBufferMap[t][e],r},function(){return delete n.pendingTemplateBufferMap[t][e],n.errorHandler.reject()})},t}(),Se=function(){function t(t,e,r,n,i,o,s){this.columnUtil=t,this.promiseService=e,this.requestBufferFactory=r,this.columnHandler=n,this.templateFactory=i,this.errorHandler=o,this.requestColumnExpansionFactory=s,this.templates={}}return t.prototype.fetchTemplate=function(t,e,r,n,i){var o=this;void 0===r&&(r={}),void 0===n&&(n={}),void 0===i&&(i=null);var a=s(r),c=this.requestColumnExpansionFactory.construct();if(void 0!==n[t]&&c.expandWithRequestColumns(t,n[t]),c.expandWithRequestColumns(t,[{creator:["displayname"]},"created","permissions"]),null!==i&&c.expandWithRequestColumns(t,this.columnUtil.getColumnsFromLink("string"==typeof i?i:i.itemType,t)),n[t]=c.get()[t],!a){var u=this.templates[t];if(void 0!==u&&(null===t||this.columnUtil.responseColumnsAvailable(t,n[t],u.responseColumns)))return this.promiseService.when(u)}return this.promiseService.all({template:this.requestBufferFactory.fetchByLocalId(t,e,r),additionalColumns:void 0===n[t]?{}:this.columnHandler.fetch(t,n[t])}).then(function(e){var r=e.template,i=o.templateFactory.construct(t,r,n,e.additionalColumns);return!a&&r.cacheable&&(o.templates[t]=i),i},this.errorHandler.reject)},t}(),Re=function(){function t(t){this.apiFormatter=t}return t.prototype.construct=function(t){return new P(this.apiFormatter,t)},t}(),qe=function(){function t(){}return t.prototype.construct=function(t){return new L(t)},t}(),Te=function(){function t(t){this.queryMatcherFactory=t}return t.prototype.construct=function(t){return new qt(this.queryMatcherFactory,t)},t}(),we=function(){function t(t,e,r){this.collectionEntryService=t,this.columnSetFactory=e,this.keyService=r}return t.prototype.construct=function(t,e){return new X(this.collectionEntryService,this.columnSetFactory,this.keyService,t,new K(e))},t}(),be=function(){function t(t){this.queryMatcherFactory=t}return t.prototype.construct=function(t,e){return new mt(this.queryMatcherFactory,t,e)},t}(),He=function(){function t(t,e,r,n,i,o){this.errorHandler=t,this.exceptionHandler=e,this.itemResourceFactory=r,this.keyService=n,this.promiseService=i,this.changesDeltaFactory=o}return t.prototype.construct=function(t,e,r){var n=new z(e);return n.editCollection?new rt(this,t,n,r):new tt(this,t,n,r)},t}(),Me=function(){function t(t){this.columnInfoFactory=t}return t.prototype.construct=function(t,e,r){return new Ht(this.columnInfoFactory,t,e,r)},t}(),xe=function(){function t(){}return t.prototype.construct=function(t,e){return new kt(t,e)},t.prototype.constructFromRootMap=function(t,e){void 0===e&&(e=null);var r=[];for(var n in t){var i=t[n],o=this.construct(i.apiColumn,e),s=this.constructFromRootMap(i.children,o);s.length>0&&o.setChildren(o.apiColumn.itemType,s),r.push(o)}return r},t}(),ke=function(){function t(t,e,r){this.columnHandler=t,this.columnUtil=e,this.columnInfoFactory=r}return t.prototype.constructStub=function(t,e){var r=new Ot(this.columnUtil,this,t);return r.request=e,r.requestColumnsTrue=!0===e,r},t.prototype.resolveStub=function(t,e,r,n){return void 0===r&&(r=!0),void 0===n&&(n=!0),t.requestColumnsTrue?this.processResponseColumns(t,e,r):this.processRequestColumns(t,e,r,n)},t.prototype.construct=function(t,e,r,n,i){return this.resolveStub(this.constructStub(t,e),r,n,i)},t.prototype.constructFromResponse=function(t,e,r){void 0===r&&(r=!0);var n=new Ot(this.columnUtil,this,t);return n.requestColumnsTrue=!1,this.processResponseColumns(n,e,r)},t.prototype.processResponseColumns=function(t,e,r){var n=t.itemType,i={};return t.response=e,this.expandRootColumnMapFromResponseColumns(n,e,i,r,{}),this.processColumnInfo(t,this.columnInfoFactory.constructFromRootMap(i),n),t.request=this.constructRequestColumnsFromRootColumnMap(i),t},t.prototype.constructRequestColumnsFromRootColumnMap=function(t){var e,r=[];for(var n in t){var i=t[n];s(i.children)?r.push(((e={})[n]=this.constructRequestColumnsFromRootColumnMap(i.children),e)):r.push(n)}return r},t.prototype.expandRootColumnMapFromResponseColumns=function(t,e,r,n,i){if(!0!==i[t])for(var o in i[t]=!0,e[t]){var a=e[t][o];if(void 0!==a&&(n&&this.columnHandler.setColumn(t,a),void 0===r[o]&&(r[o]={apiColumn:a,children:{}}),this.columnUtil.isItemColumn(a,!1))){var c=e[a.itemType];void 0!==c&&s(c)&&this.expandRootColumnMapFromResponseColumns(a.itemType,e,r[o].children,n,i)}}},t.prototype.processRequestColumns=function(t,e,r,n){var i=t.itemType,o={};return this.expandRootColumnMap(t.request,i,e,o,r),n&&this.expandRootColumnMap(["id"],i,e,o,r),t.response={},this.processColumnInfo(t,this.columnInfoFactory.constructFromRootMap(o),i),t},t.prototype.processColumnInfo=function(t,e,r){var n=t.response;void 0===n[r]&&(n[r]={});for(var i=0,o=e;i<o.length;i++){var s=o[i];n[r][s.id]=s.apiColumn,t.groupColumnInfo(s),s.isLeaf||this.processColumnInfo(t,s.children,s.itemType)}},t.prototype.expandRootColumnMap=function(t,e,r,n,i){for(var o=0,s=t;o<s.length;o++){var a=s[o],c=this.columnUtil.parseRequestColumn(a),u=c.id,l=c.children,h=void 0;void 0!==r[e]&&(h=r[e][u]),void 0!==h?(i&&(h=this.columnHandler.setColumn(e,h)),void 0===n[u]&&(n[u]={apiColumn:h,children:{}}),0!==l.length&&this.expandRootColumnMap(l,h.itemType,r,n[u].children,i)):console.warn("No api column for request column",u,"for itemType",e)}},t}(),De=function(){function t(){}return t.prototype.construct=function(t){return new Pt(t)},t}(),_e=function(){function t(t,e,r){this.apiFormatter=t,this.keyService=e,this.requestColumnExpansionFactory=r}return t.prototype.construct=function(t,e,r){return new jt(this.apiFormatter,this.keyService,this.requestColumnExpansionFactory,t,e,r)},t}(),Oe=function(){function t(t){this.queryMatcherFactory=t}return t.prototype.construct=function(t){return new Xt(this.queryMatcherFactory,t)},t}(),Pe=function(){function t(t,e,r,n,i,o,s,a){this.authInterface=t,this.apiFormatter=e,this.columnSetFactory=r,this.exceptionHandler=n,this.itemEntryService=i,this.itemResourceFactory=o,this.keyService=s,this.promiseService=a}return t.prototype.construct=function(t,e){return new V(this,e.itemType,t,e)},t}(),Le=function(){function t(t,e,r,n,i,o,s){this.apiFormatter=t,this.lockService=e,this.errorHandler=r,this.promiseService=n,this.exceptionHandler=i,this.columnUtil=o,this.linkTreeService=s}return t.prototype.getConstructor=function(t,e){var r=this,n=new A(t);return function(t){return r.constructWithOptions(t,n,e)}},t.prototype.construct=function(t,e,r,n){return this.constructWithOptions(t,new A(e),r,n)},t.prototype.constructWithOptions=function(t,e,r,n){return void 0===n&&(n=!1),e.edit?new J(this,t,e,n,r):e.remote?new ot(this,t,e,n,r):new at(this,t,e,n,r)},t}(),je=function(){function t(t,e,r,n,i,o,s,a,c,u,l,h,p,d,f,m,y,v,g,C,I,E,F,S,R,q,T,w,b,H,M,x,k,D){this.core=t,this.columnCache=e,this.requestBufferManager=r,this.requestColumnExpansionFactory=n,this.queryMatcherFactory=i,this.authInterface=o,this.changesDeltaFactory=s,this.changesProcessorFactory=a,this.lockService=c,this.moduleChangesCompilationFactory=u,this.collectionResourceFactory=l,this.itemResourceFactory=h,this.templateCache=p,this.itemCacheFactory=d,this.collectionCacheFactory=f,this.errorHandler=m,this.exceptionHandler=y,this.promiseService=v,this.apiFormatter=g,this.apiRequestService=C,this.columnExpansionFactory=I,this.columnHandler=E,this.columnSetFactory=F,this.columnSubsetCacheFactory=S,this.columnUtil=R,this.itemEntryFactory=q,this.itemEntryService=T,this.keyService=w,this.collectionEntryFactory=b,this.collectionEntryService=H,this.collectionMatcherFactory=M,this.queryParserFactory=x,this.queryService=k,this.linkTreeService=D,this.serverCache=new Gt(this.changesProcessorFactory,this.core,this.columnCache,this.requestBufferManager,this.requestColumnExpansionFactory,this.queryMatcherFactory,this.authInterface,this.changesDeltaFactory,this.lockService,this.moduleChangesCompilationFactory,this.collectionResourceFactory,this.itemResourceFactory,this.templateCache,this.itemCacheFactory,this.collectionCacheFactory,this.errorHandler,this.exceptionHandler,this.promiseService,this.apiFormatter,this.apiRequestService,this.columnExpansionFactory,this.columnHandler,this.columnSetFactory,this.columnSubsetCacheFactory,this.columnUtil,this.itemEntryFactory,this.itemEntryService,this.keyService,this.collectionEntryFactory,this.collectionEntryService,this.collectionMatcherFactory,this.queryParserFactory,this.queryService,this.linkTreeService)}return t.prototype.getById=function(t){var e=function(r){for(var n=0,i=r;n<i.length;n++){var o=i[n];if(o.id===t)return o;var s=e(o.children);if(void 0!==s)return s}};return e(this.serverCache.children)},t.prototype.construct=function(t,e){return this.serverCache.createChild(t,e)},t.prototype.getServerCache=function(){return this.serverCache},t}(),Be=function(){function t(){}return t.prototype.construct=function(t){return new re(t)},t}(),Ae=function(){function t(t){this.apiFormatter=t}return t.prototype.construct=function(t,e,r){return new ie(this.apiFormatter,t,e,r)},t}(),Qe=function(){function t(){}return t.prototype.construct=function(t,e){return new ce(t,e)},t}(),Ve=function(){function t(t){this.columnUtil=t}return t.prototype.construct=function(){return new le(this.columnUtil)},t}(),Ue=function(){function t(t,e){this.columnSetFactory=t,this.columnUtil=e}return t.prototype.construct=function(t,e,r,n){return new nt(this,t,e,r,n)},t}(),Ne=function(){function t(t){this.itemEntryService=t}return t.prototype.construct=function(){return new ge(this.itemEntryService)},t.prototype.constructInternalDelta=function(){return new Ie(this.itemEntryService)},t}(),We=function(){function t(t,e,r,n,i,o,s,a,c,u){this.changesDeltaFactory=t,this.apiRequestService=e,this.changesCompilationFactory=r,this.columnExpansionFactory=n,this.createRequestFactory=i,this.errorHandler=o,this.promiseService=s,this.requestColumnExpansionFactory=a,this.collectionEntryService=c,this.itemEntryService=u}return t.prototype.construct=function(t,e,r){return new j(this.changesDeltaFactory,this.apiRequestService,this.changesCompilationFactory,this.columnExpansionFactory,this.createRequestFactory,this.errorHandler,this.promiseService,this.requestColumnExpansionFactory,this.collectionEntryService,this.itemEntryService,t,e,r)},t}(),Ye=function(){return function(t,e,r,n,i,o){this.version="2.1.2",this.noop=Je;var s=new $t,a=new _,c=new Ae(a),u=new Qe,l=new ue,h=new Zt(e,s,o),p=new Ne(h),d=new Re(a),f=new O(t,d),m=new Lt(o),y=new bt(m),v=new Mt(f,r,i,y,m),g=new xe,C=new Me(g),I=new ke(v,m,g),E=new De,F=new te(f,r,s,i),S=new Ue(I,m),R=new Oe(c),q=new Le(a,F,r,i,n,m,o),T=new He(r,n,q,s,i,p),w=new Pe(e,a,I,n,h,q,s,i),b=new Tt(u,l),H=new wt,M=new we(b,I,s),x=new Te(c),k=new be(c),D=new Ve(m),P=new _e(a,s,D),L=new qe,j=new We(p,f,L,C,P,r,i,D,b,h),B=new Be,A=new Fe(i,f,D,s,r,p),Q=new Se(m,i,A,v,S,r,D),V=new je(this,y,A,D,c,e,p,j,F,B,T,q,Q,R,x,r,n,i,a,f,C,v,I,E,m,w,h,s,M,b,k,u,l,o);A.setServerCache(V.getServerCache());var U=new he(A,p,a,r,V,i,D,f);this.apiFormatter=a,this.apiRequestService=f,this.apiResponseProcessorFactory=d,this.changesCompilationFactory=L,this.changesProcessorFactory=j,this.collectionCacheFactory=x,this.collectionEntryFactory=M,this.collectionEntryService=b,this.collectionMatcherFactory=k,this.collectionResourceFactory=T,this.collectionResourceService=H,this.columnCache=y,this.columnExpansionFactory=C,this.columnHandler=v,this.columnInfoFactory=g,this.columnSetFactory=I,this.columnSubsetCacheFactory=E,this.columnUtil=m,this.createRequestFactory=P,this.itemCacheFactory=R,this.itemEntryFactory=w,this.itemEntryService=h,this.itemResourceFactory=q,this.keyService=s,this.transactionCacheFactory=V,this.lockService=F,this.moduleChangesCompilationFactory=B,this.queryMatcherFactory=c,this.queryParserFactory=u,this.queryService=l,this.requestColumnExpansionFactory=D,this.socketMessageHandler=U,this.templateFactory=S,this.changesDeltaFactory=p,this.templateCache=Q}}();function Je(){}function Ke(t){return t}r.d(e,"RmCore",function(){return Ye}),r.d(e,"noop",function(){return Je}),r.d(e,"identity",function(){return Ke}),r.d(e,"ALL_PERMISSIONS",function(){return"7"}),r.d(e,"COLUMN_SEPERATOR",function(){return xt}),r.d(e,"RENDER_AS_SEPERATOR",function(){return":"}),r.d(e,"NEW_PREFIX",function(){return"-1"}),r.d(e,"DUPLICATE_PREFIX",function(){return"-2"}),r.d(e,"NEW_KEYWORD",function(){return"new-"}),r.d(e,"DUPLICATE_KEYWORD",function(){return"dup-"}),r.d(e,"ItemEntryOptions",function(){return B}),r.d(e,"ItemResourceOptions",function(){return A}),r.d(e,"ItemEntry",function(){return V}),r.d(e,"ItemResource",function(){return U}),r.d(e,"ViewResource",function(){return W}),r.d(e,"EditResource",function(){return J}),r.d(e,"CollectionEntryOptions",function(){return K}),r.d(e,"CollectionResourceOptions",function(){return z}),r.d(e,"CollectionEntry",function(){return X}),r.d(e,"CollectionResource",function(){return Z}),r.d(e,"CollectionViewResource",function(){return tt}),r.d(e,"CollectionEditResource",function(){return rt}),r.d(e,"Template",function(){return nt}),r.d(e,"RemoteViewResource",function(){return ot}),r.d(e,"LocalViewResource",function(){return at}),r.d(e,"ApiFormatter",function(){return _}),r.d(e,"ApiRequestService",function(){return O}),r.d(e,"ApiResponseProcessor",function(){return P}),r.d(e,"ChangesCompilation",function(){return L}),r.d(e,"ChangesProcessor",function(){return j}),r.d(e,"CollectionCache",function(){return qt}),r.d(e,"CollectionEntryService",function(){return Tt}),r.d(e,"CollectionMatcher",function(){return mt}),r.d(e,"CollectionResourceService",function(){return wt}),r.d(e,"ColumnCache",function(){return bt}),r.d(e,"ColumnExpansion",function(){return Ht}),r.d(e,"ColumnHandler",function(){return Mt}),r.d(e,"ColumnInfo",function(){return kt}),r.d(e,"ColumnSet",function(){return Ot}),r.d(e,"ColumnSubsetCache",function(){return Pt}),r.d(e,"ColumnUtil",function(){return Lt}),r.d(e,"CreateRequest",function(){return jt}),r.d(e,"ItemCache",function(){return Xt}),r.d(e,"ItemEntryService",function(){return Zt}),r.d(e,"KeyService",function(){return $t}),r.d(e,"TransactionEventHandler",function(){return gt}),r.d(e,"LockService",function(){return te}),r.d(e,"ModuleChangesCompilation",function(){return re}),r.d(e,"QueryMatcher",function(){return ie}),r.d(e,"CONSTANTS",function(){return At}),r.d(e,"QueryParser",function(){return ce}),r.d(e,"QueryService",function(){return ue}),r.d(e,"RequestColumnExpansion",function(){return le}),r.d(e,"SocketMessageHandler",function(){return he}),r.d(e,"instantiateOptions",function(){return i}),r.d(e,"shallowMerge",function(){return o}),r.d(e,"hasProperties",function(){return s}),r.d(e,"getFirstProperty",function(){return a}),r.d(e,"inArray",function(){return c}),r.d(e,"filterArray",function(){return u}),r.d(e,"emptyArray",function(){return l}),r.d(e,"pathExists",function(){return h}),r.d(e,"createPath",function(){return p}),r.d(e,"getPath",function(){return d}),r.d(e,"extend",function(){return m}),r.d(e,"merge",function(){return y}),r.d(e,"isObject",function(){return v}),r.d(e,"isBlankObject",function(){return g}),r.d(e,"isString",function(){return C}),r.d(e,"isNumber",function(){return I}),r.d(e,"isDate",function(){return E}),r.d(e,"isArray",function(){return F}),r.d(e,"isFunction",function(){return S}),r.d(e,"isPromiseLike",function(){return R}),r.d(e,"isRegExp",function(){return q}),r.d(e,"isBoolean",function(){return T}),r.d(e,"isElement",function(){return w}),r.d(e,"isWindow",function(){return b}),r.d(e,"isDefined",function(){return H}),r.d(e,"equals",function(){return M}),r.d(e,"copy",function(){return x}),r.d(e,"AbstractCache",function(){return pt}),r.d(e,"ServerCache",function(){return Gt}),r.d(e,"ServerItemHandler",function(){return Kt}),r.d(e,"ServerCollectionHandler",function(){return Yt}),r.d(e,"TransactionErrorLevel",function(){return ct}),r.d(e,"TransactionCache",function(){return Ft}),r.d(e,"TransactionItemHandler",function(){return ht}),r.d(e,"TransactionCollectionHandler",function(){return fe}),r.d(e,"TransactionValidator",function(){return me}),r.d(e,"ChangesDelta",function(){return ge}),r.d(e,"InternalChangesDelta",function(){return Ie}),r.d(e,"RequestBufferManager",function(){return Fe}),r.d(e,"RequestBuffer",function(){return Ee}),r.d(e,"ApiResponseProcessorFactory",function(){return Re}),r.d(e,"ChangesCompilationFactory",function(){return qe}),r.d(e,"CollectionCacheFactory",function(){return Te}),r.d(e,"CollectionEntryFactory",function(){return we}),r.d(e,"CollectionMatcherFactory",function(){return be}),r.d(e,"CollectionResourceFactory",function(){return He}),r.d(e,"ColumnExpansionFactory",function(){return Me}),r.d(e,"ColumnInfoFactory",function(){return xe}),r.d(e,"ColumnSetFactory",function(){return ke}),r.d(e,"ColumnSubsetCacheFactory",function(){return De}),r.d(e,"CreateRequestFactory",function(){return _e}),r.d(e,"ItemCacheFactory",function(){return Oe}),r.d(e,"ItemEntryFactory",function(){return Pe}),r.d(e,"ItemResourceFactory",function(){return Le}),r.d(e,"TransactionCacheFactory",function(){return je}),r.d(e,"ModuleChangesCompilationFactory",function(){return Be}),r.d(e,"QueryMatcherFactory",function(){return Ae}),r.d(e,"QueryParserFactory",function(){return Qe}),r.d(e,"RequestColumnExpansionFactory",function(){return Ve}),r.d(e,"TemplateFactory",function(){return Ue}),r.d(e,"ChangesDeltaFactory",function(){return Ne}),r.d(e,"ChangesProcessorFactory",function(){return We}),r.d(e,"ApiLinkTreeType",function(){return D})}])});