@rentman/rm-core 1.7.0 → 1.7.1

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 o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.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 o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));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 o(t,e){for(var r in e)r in t&&void 0!==e[r]&&(t[r]=e[r])}function i(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 c(t){if("object"!=typeof t)return null;for(var e in t)return e;return null}function a(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,o=t;n<o.length;n++){var i=o[n];e(i)&&r.push(i)}if(r.length===t.length)return!1;l(t);for(var s=0,c=r;s<c.length;s++){var a=c[s];t.push(a)}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 o=n[r];if(void 0===t[o])return!1;t=t[o]}return!0}function p(t,e,r){for(var n=0;n<e.length;n++){var o=e[n];void 0===t[o]&&(t[o]=r[n]),t=t[o]}return t}function f(t,e,r){if(void 0===r&&(r=!1),void 0!==t){for(var n=0,o=e;n<o.length;n++){if(void 0===(t=t[o[n]])&&!r)return}return t}}function d(t,e,r){for(var n=0,o=e.length;n<o;++n){var i=e[n];if(v(i)||E(i))for(var s=Object.keys(i),c=0,a=s.length;c<a;c++){var u=s[c],l=i[u];r&&v(l)?S(l)?t[u]=new Date(l.valueOf()):F(l)?t[u]=new RegExp(l):l.nodeName?t[u]=l.cloneNode(!0):b(l)?t[u]=l.clone():(v(t[u])||(t[u]=R(l)?[]:{}),d(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 d(t,e,!1)}function y(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];return d(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 S(t){return"[object Date]"===toString.call(t)}var R=Array.isArray;function E(t){return"function"==typeof t}function F(t){return"[object RegExp]"===toString.call(t)}function q(t){return"boolean"==typeof t}function b(t){return!(!t||!(t.nodeName||t.prop&&t.attr&&t.find))}function O(t){return t&&t.window===t}function L(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,o,i,s,c=typeof t;if(c===typeof e&&"object"===c){if(!R(t)){if(S(t))return!!S(e)&&(i=t.getTime(),s=e.getTime(),i===s||i!=i&&s!=s);if(F(t))return!!F(e)&&t.toString()===e.toString();if(O(t)||O(e)||R(e)||S(e)||F(e))return!1;for(n in o=Object.create(null),t)if(!E(t[n])){if(!M(t[n],e[n]))return!1;o[n]=!0}for(n in e)if(!(n in o)&&L(e[n])&&!E(e[n]))return!1;return!0}if(!R(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 w(t,e,r){var n=[],o=[];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(R(e))e.length=0;else for(var i in e)delete e[i];return n.push(t),o.push(e),s(t,e,r)}return c(t,r);function s(t,e,r){if(--r<0)return"...";if(R(t))for(var n=0,o=t.length;n<o;n++)e.push(c(t[n],r));else if(g(t))for(var i in t)e[i]=c(t[i],r);else if(t&&"function"==typeof t.hasOwnProperty)for(var i in t)t.hasOwnProperty(i)&&(e[i]=c(t[i],r));else for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=c(t[i],r));return e}function c(t,e){if(void 0===e&&(e=5),!v(t))return t;var r=n.indexOf(t);if(-1!==r)return o[r];if(O(t))throw new Error("Can't copy! Making copies of Window instances is not supported.");var i=!1,a=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(c(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(E(t.cloneNode))return t.cloneNode(!0)}(t);return void 0===a&&(a=R(t)?[]:Object.create(Object.getPrototypeOf(t)),i=!0),n.push(t),o.push(a),i?s(t,a,e):a}}var T,x=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.formatResponse=function(t,e){for(var r=0,n=e;r<n.length;r++){var o=n[r];t[o.path]=this.formatResponseValue(o.apiColumn.type,t[o.path])}return t},t.prototype.expandResponse=function(t,e,r){for(var n=0,o=r;n<o.length;n++){var i=o[n];t[i.path]=this.formatResponseValue(i.apiColumn.type,e[i.path])}return t},t.prototype.formatRequest=function(t,e,r){for(var n={},o=0,i=r;o<i.length;o++){var s=i[o],c=s.id,a=s.apiColumn,u=a.type;a.readOnly||(this.compareFields(u,t[c],e[c])||(n[c]=this.formatRequestValue(u,e[c])))}return n},t.prototype.formatRequestLocal=function(t,e){for(var r={},n=0,o=e;n<o.length;n++){var i=o[n],s=i.id,c=i.apiColumn;c.readOnly||(r[s]=this.formatRequestValue(c.type,t[s]))}return r},t.prototype.hasChanges=function(t,e,r){for(var n=0,o=r;n<o.length;n++){var i=o[n],s=i.id,c=i.apiColumn;if(!c.readOnly&&!this.compareFields(c.type,t[s],e[s]))return!0}return!1},t.prototype.getChanges=function(t,e,r){for(var n=[],o=0,i=r;o<i.length;o++){var s=i[o],c=s.id,a=s.apiColumn;a.readOnly||(this.compareFields(a.type,t[c],e[c])||n.push({oldValue:t[c],newValue:e[c],column:s.apiColumn}))}return n},t.prototype.copyFields=function(t,e,r){for(var n=0,o=r;n<o.length;n++){var i=o[n],s=i.path;e[s]=this.clone(i.apiColumn.type,t[s])}return e},t.prototype.shallowCopyFields=function(t,e,r,n){for(var o=0,i=n;o<i.length;o++){var s=i[o],c=s.path;r[c]=void 0!==t[c]?t[c]:this.clone(s.apiColumn.type,e[c])}return r},t.prototype.setDefaultValues=function(t,e){for(var r=0,n=e;r<n.length;r++){var o=n[r];t[o.id]=this.getDefaultValue(o.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),o=Math.abs(t-e);return t===e||(0===t||0===e||o<Number.MIN_VALUE?o<1.19e-7*Number.MIN_VALUE:o/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 w(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}(),A=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,o){return this.processResponse(this.externalApiRequestService.create(t,e,r,n,o))},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}(),j=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.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.fetchValue=function(t,e,r){if(void 0!==this.items[t][e])return this.items[t][e].data[this.columnIndexMap[t][r]]},t.prototype.fetchDerivedObject=function(t,e,r){for(var n={},o=0,i=r;o<i.length;o++){var s=i[o];this.fetchDerivedValues(this.fetchValue(t,e,s.id),s,n)}return n},t.prototype.fetchDerivedValues=function(t,e,r){for(var n=0,o=e.children;n<o.length;n++){var i=o[n],s=void 0;null===t?(s=null,r[i.path]=this.apiFormatter.getDefaultValue(i.apiColumn.type)):(s=this.fetchValue(e.itemType,t,i.id),r[i.path]=s),i.isLeaf||this.fetchDerivedValues(s,i,r)}},t.prototype.fetchObject=function(t,e,r){if((void 0===r&&(r=!1),void 0!==this.items[t])&&void 0!==this.items[t][e]){for(var n=this.items[t][e].data,o={},i=0;i<n.length;i++)o[this.columns[t][i].id]=n[i];if(r){var s=this.items[t][e].links;for(var c in o.__links={},s)o.__links[c]=this.fetchObjectArray(c,r,s[c])}return o}},t.prototype.fetchObjectArray=function(t,e,r){var n=[];if(null===r){for(var o in this.items[t])n.push(this.fetchObject(t,o,e));return n}void 0===r&&(r=this.links[t]);for(var i=0,s=r;i<s.length;i++){o=s[i];n.push(this.fetchObject(t,o,e))}return n},t.prototype.fetchObjectMap=function(t,e,r,n){var o=this.columnIndexMap[t][e],i={},s=[];for(var c in this.items[t]){var a=this.items[t][c].data[o];s.push(a),i[a]=this.fetchObject(t,c,r)}return n?{result:i,keys:s}:i},t.prototype.fetchFieldMap=function(t,e){var r=this.columnIndexMap[t][e],n={};for(var o in this.items[t])n[o]=this.items[t][o].data[r];return n},t.prototype.fetchColumnArray=function(t){for(var e=[],r=0,n=this.columns[t];r<n.length;r++){var o=n[r];e.push(o)}return e},t.prototype.fetchColumnObject=function(t){return this.columnMap[t]},t.prototype.fetchColumnsObject=function(){return this.columnMap},t.prototype.createResource=function(t,e){return{object:this.fetchObject(t,e),links:this.items[t][e].links}},t.prototype.hasItems=function(t){for(var e in this.items[t])return!0;return!1},t.prototype.getIdArray=function(t){var e=[];for(var r in this.items[t])e.push(parseInt(r,10));return e},t}();!function(t){t.CACHED="cached",t.LOCAL="local",t.PROMISED="promised",t.EXPAND="expand",t.PROMISED_EXPAND="promised-expand",t.EXPAND_LOCAL="expand-local",t.PROMISED_EXPAND_LOCAL="promised-expand-local",t.RESOLVE="resolve",t.RESOLVE_VALUES="resolve-values"}(T||(T={}));var k,D=">",H=function(){function t(t,e,r,n){for(var o in this.promiseService=t,this.itemType=e,this.getItemId=r,this.getPromise=n,this.requestStatus=[T.RESOLVE,T.RESOLVE_VALUES,T.EXPAND,T.PROMISED_EXPAND],this.remoteExpandStatus=[T.EXPAND,T.PROMISED_EXPAND],this.localExpandStatus=[T.EXPAND_LOCAL,T.PROMISED_EXPAND_LOCAL],this.entries={},T)this.entries[T[o]]=[]}return t.prototype.add=function(t){this.entries[t.status].push(t.entry)},t.prototype.hasEntries=function(t){for(var e=0,r=t;e<r.length;e++){var n=r[e];if(this.entries[n].length>0)return!0}return!1},t.prototype.hasRequests=function(){return this.hasEntries(this.requestStatus)},t.prototype.forEachEntry=function(t,e){for(var r=0,n=t;r<n.length;r++)for(var o=n[r],i=0,s=this.entries[o];i<s.length;i++){var c=s[i];e(c,this.getItemId(c))}},t.prototype.reduceEntries=function(t,e,r){for(var n=0,o=t;n<o.length;n++)for(var i=o[n],s=0,c=this.entries[i];s<c.length;s++){var a=c[s];e(a,this.getItemId(a),r)}return r},t.prototype.reduceAllEntries=function(t,e){var r=this.entries;for(var n in r)for(var o=0,i=r[n];o<i.length;o++){var s=i[o];t(s,this.getItemId(s),e)}return e},t.prototype.getPromises=function(){var t=this;return this.promiseService.all(this.reduceEntries([T.PROMISED,T.PROMISED_EXPAND],function(e,r,n){n.push(t.getPromise(e))},[]))},t.prototype.getItemIds=function(t){return this.reduceEntries(t,function(t,e,r){r.push(e)},[])},t.prototype.getRequestIds=function(){return this.getItemIds(this.requestStatus)},t.prototype.getArray=function(t){var e=function(t,e,r){r.push(t)};return void 0===t?this.reduceAllEntries(e,[]):this.reduceEntries(t,e,[])},t.prototype.getMap=function(){return this.reduceAllEntries(function(t,e,r){r[e]=t},{})},t}(),P=function(){function t(t,e,r,n){this.collectionCacheFactory=t,this.keyService=e,this.singleItems=r,this.compilation={create:{},delete:{},update:{},move:{}},this.moveArray=[],this.deleteMap={},this.collections=this.collectionCacheFactory.construct(),this.processSingleItems(),this.processCollections(n),this.postProcess()}return t.prototype.getDefaultParent=function(){return{itemType:"Void",itemId:0}},t.prototype.addMoveEntry=function(t){this.moveArray.push(t)},t.prototype.addDeleteEntry=function(t,e){p(this.deleteMap,[t.itemType,t.itemId],[{},{item:t,parent:e}])},t.prototype.addUpdateEntry=function(t){p(this.compilation.update,[t.itemType,t.itemId],[{},t])},t.prototype.addCreateEntry=function(t){var e=t.parent;null===e&&(e=this.getDefaultParent()),p(this.compilation.create,[e.itemType,e.itemId,t.itemType,t.itemId],[{},{},{},t])},t.prototype.containsCreateEntry=function(t,e){var r=this.compilation.create;for(var n in r)for(var o in r[n]){var i=r[n][o][t];if(void 0!==i)for(var s in i)if(i[s].itemId===e)return!0}return!1},t.prototype.createDeleteCompilation=function(){var t=this.deleteMap,e=this.compilation.delete;for(var r in t)for(var n in t[r]){var o=t[r][n].item;void 0===e[r]&&(e[r]=[]),e[r].push(o)}},t.prototype.postProcess=function(){for(var t=this.deleteMap,e=0,r=this.moveArray;e<r.length;e++){var n=r[e],o=f(t,[n.itemType,n.itemId]);if(void 0!==o){var i=n.parent,s=i.itemType,c=i.itemId;!this.keyService.isLocalId(c)||this.containsCreateEntry(s,c)?(p(this.compilation.move,[s,c],[{},[]]).push(o),delete t[n.itemType][n.itemId]):n.parent=o.parent}}this.createDeleteCompilation()},t.prototype.processSingleItems=function(){for(var t=0,e=this.singleItems;t<e.length;t++){var r=e[t];r.isLocal()?this.addCreateEntry(r):r.hasChanges()&&this.addUpdateEntry(r)}},t.prototype.processCollections=function(t){for(var e=0,r=t;e<r.length;e++){var n=r[e];if(this.collections.add(n),!n.isDeferred()){var o=void 0,i=void 0;n.isLocal()?(o=n.items,i=[]):n.hasEditResources?(o=n.getAddedItems(),i=n.getRemovedItems()):(o=[],i=[]);for(var s=0,c=o;s<c.length;s++){var a=c[s];a.isLocal()?this.addCreateEntry(a):this.addMoveEntry(a)}for(var u=0,l=i;u<l.length;u++){var h=l[u];this.addDeleteEntry(h,n.parent)}if(n.hasItemEditResources)for(var p=0,f=n.getUpdatedItems();p<f.length;p++){var d=f[p];this.addUpdateEntry(d)}}}},t}(),_=function(){function t(t,e,r,n,o,i,s,c,a,u,l){this.apiFormatter=t,this.apiRequestService=e,this.changesCompilationFactory=r,this.collectionEntryService=n,this.collectionHandler=o,this.columnExpansionFactory=i,this.createRequestFactory=s,this.errorHandler=c,this.itemHandler=a,this.promiseService=u,this.requestColumnExpansionFactory=l}return t.prototype.buildMoveRequest=function(t){for(var e={},r=0,n=t;r<n.length;r++){var o=n[r].item,i=o.itemType;void 0===e[i]&&(e[i]=[]),e[i].push(o.itemId)}return e},t.prototype.getMapValue=function(t,e,r){if(void 0!==r&&void 0!==r[t])return r[t][e]},t.prototype.executeCreateRequests=function(t,e,r,n,o){for(var i=[],s=0,c=this.createRequestFactory.construct(t.compilation.create,t.collections,e,n).run();s<c.length;s++){var a=c[s];i.push(this.executeCreateRequest(a,r).then(u))}return this.promiseService.all(i).then(function(){return r},this.errorHandler.reject);function u(t){return void 0!==o&&o(r),t}},t.prototype.executeCreateRequest=function(t,e){var r=this;return this.apiRequestService.requestSkeleton(t.request).then(function(n){var o=n.map,i=n.fetchColumnsObject(),s=t.items;for(var c in s){var a=r.columnExpansionFactory.construct(c,t.request.columns[c],i);for(var u in s[c]){var l=s[c][u],h=r.getMapValue(c,parseInt(u,10),o);if(void 0!==h){var p=n.fetchObject(c,h),f=a.run(l.columns);l.itemId=h,l.updateFields(p,n.fetchDerivedObject(c,h,l.columns.root)),null!==f&&l.expand(p,n.fetchDerivedObject(c,h,f.difference.root),f),r.itemHandler.entries.add(l)}else console.warn("Create failed!",l)}}for(var c in t.collections.addToCollections(),o)for(var u in void 0===e[c]&&(e[c]={}),o[c])e[c][parseInt(u,10)]=o[c][u]},this.errorHandler.reject)},t.prototype.executeUpdateRequests=function(t,e){var r=[];for(var n in t)r.push(this.executeUpdateRequest(n,t[n],e));return this.promiseService.all(r)},t.prototype.executeUpdateRequest=function(t,e,r){var n=this,o={},i=this.requestColumnExpansionFactory.construct(),s=this.collectionHandler.getCollectionMatcher();for(var c in o[t]={},e){var a=e[c],u=o[t][c]={},l=f(r,[t,c]);u.values=a.formatRequest(),void 0!==l&&(u.parameters=l),i.expand(a.columns),s.expand(a)}for(var h=0,p=s.getCollectionsWithFittingItems();h<p.length;h++){var d=p[h];i.expand(d.columns)}return this.apiRequestService.updateItems(t,o,i.get()).then(function(r){var o=n.columnExpansionFactory.construct(t,i.get()[t],r.fetchColumnsObject());for(var c in e){var a=e[c],u=r.fetchObject(t,c);if(void 0!==u){var l=n.apiFormatter.copyFields(a.initial,{},a.columns.main);a.updateFields(u,r.fetchDerivedObject(t,c,a.columns.root)).callOnChange(l);var h=o.run(a.columns);null!==h&&a.expand(u,r.fetchDerivedObject(t,c,h.difference.root),h)}else console.warn("Update failed!",a)}s.removeFromAndAddToCollections()},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){for(var r=this,n=[],o=0,i=e;o<i.length;o++){var s=i[o];n.push(s.itemId)}return this.apiRequestService.delete(t,n).then(function(t){for(var n=t.items,o=r.collectionHandler.getCollectionMatcher(),i=0,s=e;i<s.length;i++){var c=s[i];a(c.itemId,n)||console.warn("Delete failed!",c),o.expand(c)}o.removeFromCollections()},this.errorHandler.reject)},t.prototype.executeMoveRequests=function(t,e){var r=this,n=[];for(var o in t)for(var i in t[o])s(o,+i);return this.promiseService.all(n);function s(o,i){var s=t[o][i],c=r.getMapValue(o,i,e);n.push(r.apiRequestService.moveItems(o,void 0!==c?c:i,r.buildMoveRequest(s)).then(function(){r.processMoveResponse(s)},r.errorHandler.reject))}},t.prototype.processMoveResponse=function(t){for(var e=[],r={},n={},o=0,i=t;o<i.length;o++){var s=i[o],c=s.item;this.addCollectionMapEntry(r,s.parent.itemId,c,c.itemId),this.addCollectionMapEntry(n,c.parent.itemId,c,c),e.push(c)}this.forEachCollection(r,function(t,e){t.removeItems(e,null,!0)}),this.forEachCollection(n,function(t,e){t.addItems(e,null,!0)})},t.prototype.addCollectionMapEntry=function(t,e,r,n){p(t,[r.parent.itemType,e,r.itemType],[{},{},[]]).push(n)},t.prototype.forEachCollection=function(t,e){for(var r in t)for(var n in t[r])for(var o in t[r][n]){var i=this.collectionHandler.entries.getByParent(r,+n,o);null!==i&&e(i,t[r][n][o])}},t.prototype.onItemsCreated=function(t,e,r){if(s(t)){for(var n=0,o=r;n<o.length;n++){var i=o[n],c=i.parent,a=i.getUpdatedItemColumns(t);if(null!==c)void 0!==(d=this.getMapValue(c.itemType,c.itemId,t))&&(c.itemId=d,i.query=this.collectionEntryService.createQuery(i.options),this.collectionHandler.entries.add(i));if(s(a)){void 0!==a.id&&i.onItemsCreated(t[i.itemType]);for(var u=0,l=i.items;u<l.length;u++){(f=l[u]).updateItemFields(t)}}}for(var h=0,p=e;h<p.length;h++){var f,d,m=(f=p[h]).parent;if(f.updateItemFields(t),null!==m)void 0!==(d=this.getMapValue(m.itemType,m.itemId,t))&&(m.itemId=d)}}},t.prototype.execute=function(t,e,r,n,o){var i=this;void 0===r&&(r={});var s=this.errorHandler,c=this.changesCompilationFactory.construct(t,e),a=c.compilation,u={};return this.executeCreateRequests(c,r,u,n,o).then(function(){return i.onItemsCreated(u,t,e),i.executeMoveRequests(a.move,u)},function(r){return i.onItemsCreated(u,t,e),s.reject(r)}).then(function(){return i.executeUpdateRequests(a.update,r)},s.reject).then(function(){return i.executeDeleteRequests(a.delete)},s.reject).then(function(){return u},s.reject)},t}();!function(t){t.MAYBE="maybe"}(k||(k={}));var V,N,B=function(){function t(t,e){this.collectionResourceFactory=t,this.queryMatcherFactory=e,this.entries={}}return 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 o in n)if(this.matchParent(n[o],t,e))return n[o];return null},t.prototype.getResourceByParent=function(t,e,r){var n=this.getByParent(t,e,r);return null===n?null:this.collectionResourceFactory.cache.getLatest(n)},t.prototype.getCollectionsByParent=function(t,e){var r=this.entries,n=[];for(var o in r)for(var i in r[o]){var s=r[o][i];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 o in r){var i=r[o];void 0!==i.getItemById(e)&&n.push(i)}return n},t.prototype.getByFittingItem=function(t,e,r){var n=this.entries[t],o={fitting:[],notfitting:[],maybe:[]};if(void 0===n)return o;var i=this.queryMatcherFactory.construct(t,e,r);for(var s in n){var c=n[s],a=i.matchQuery(c.query.object);!0===a?o.fitting.push(c):a===k.MAYBE?o.maybe.push(c):o.notfitting.push(c)}return o},t.prototype.getByQuery=function(t,e){var r=this.entries[t];if(void 0===r)return null;for(var n in r){var o=r[n];if(o.query.string===e.string)return o}return null},t.prototype.getByKey=function(t,e){var r=this.entries[t],n=[];if(void 0===r)return n;for(var o in r){var i=r[o];i.options.entryKey===e&&n.push(i)}return n},t.prototype.getResourceByKey=function(t,e){var r=this.entries[t],n=[];if(void 0===r)return n;for(var o in r)for(var i=0,s=this.collectionResourceFactory.cache.get(r[o]);i<s.length;i++){var c=s[i];c.options.resourceKey===e&&n.push(c)}return n},t}(),U=function(){return function(t){this.columns=!0,this.parent=null,this.templateOptions={},this.templateColumns={},this.deferRequest=!1,this.isDuplicate=!1,o(this,t)}}(),Q=function(){return function(t){this.edit=!1,this.remote=!1,this.onChange=ve,o(this,t)}}(),Y=0,X=function(){function t(t,e,r,n){this.factory=t,this.itemType=e,this.itemId=r,this.columns=n,this.id=++Y,this.reloadQueued=!1,this.deferRequest=!1,this.parent=null}return t.prototype.getResources=function(){return this.factory.itemResourceFactory.cache.get(this)},t.prototype.queueReload=function(){return this.reloadQueued=!0,this},t.prototype.defer=function(t){return void 0===t&&(t=!1),this.deferred=this.factory.promiseService.defer(),this.deferRequest=t,this},t.prototype.getPromise=function(){var t=this.deferred;return void 0===t?this.factory.promiseService.when(this):t.promise},t.prototype.resolve=function(){var t=this.deferred;return void 0===t?this:(delete this.deferred,delete this.deferRequest,t.resolve(this),this)},t.prototype.resolveDeferred=function(t,e,r){return this.columns=r,this.setFields(t,e),this.resolve()},t.prototype.isDeferred=function(){return void 0!==this.deferred},t.prototype.reject=function(t){void 0===t&&(t=this.factory.itemEntryService.createUnfoundRemoteItemError());var e=this.deferred;return void 0===e?this:(e.reject(t),delete this.deferred,delete this.deferRequest,this)},t.prototype.setFields=function(t,e){var r=this.factory.apiFormatter,n=this.columns.formatted;return this.initial=r.formatResponse(t,n.main),this.derived=r.formatResponse(e,n.derived),this},t.prototype.setLocalFields=function(t,e,r){void 0===r&&(r=this.columns);for(var n=this.factory,o=n.itemEntryService.getLocalDefaultValues(),i=0,s=r.main;i<s.length;i++){var c=s[i].id;o[c]=t[c]}return this.initial=n.apiFormatter.formatResponse(o,r.formatted.main),this.derived={"creator>displayname":n.authInterface.getUserDisplayname()},this.updateItemFields(e)},t.prototype.clone=function(t){void 0===t&&(t={});var e=this.factory,r=e.apiFormatter,n=e.itemEntryService,o=this.columns,i=this.parent,s=n.expandConversionMap(this,t),c=e.construct(s,r.copyFields(this.getFields(),{},o.main),r.copyFields(this.derived,{},o.derived),o);if(c.updateItemFields(t),c.modified=r.copyFields(c.initial,{},o.main),null===i)return c;var a=n.getConversionValue(i.itemType,i.itemId,t);return c.setParent(i.itemType,void 0===a?i.itemId:a),c},t.prototype.resetDerived=function(t){for(var e=this,r=[],n=0,o=this.columns.root;n<o.length;n++){var i=o[n];-1!==t.indexOf(i.id)&&r.push(i)}return function t(r){for(var n=0,o=r;n<o.length;n++){var i=o[n];i.isLeaf||t(i.children),delete e.derived[i.path]}}(r),this},t.prototype.getFields=function(){return void 0!==this.modified?this.modified:this.initial},t.prototype.expand=function(t,e,r){var n=this.factory.apiFormatter,o=r.difference;return this.columns=r.merged,n.expandResponse(this.initial,t,o.main),n.expandResponse(this.derived,e,o.derived),void 0===this.modified?this:(n.expandResponse(this.modified,t,o.main),this)},t.prototype.expandLocal=function(t){var e=t.difference.main;return this.columns=t.merged,0===e.length?this:(this.setLocalValues(this.initial,e),void 0===this.modified?this:(this.setLocalValues(this.modified,e),this))},t.prototype.setLocalValues=function(t,e){for(var r=this.factory,n=this.parent,o=0,i=e;o<i.length;o++){var s=i[o],c=s.id;if(void 0===t[c]){var a=s.apiColumn.type;t[c]="link"===a&&null!==n?n.itemId:r.apiFormatter.getDefaultValue(a)}}},t.prototype.updateFields=function(t,e,r){void 0===e&&(e=null),void 0===r&&(r=!0);var n=this.factory.apiFormatter,o=this.columns.main,i=this.initial,s=this.modified;if(void 0!==s)for(var c=0,a=o;c<a.length;c++){var u=(f=a[c]).id,l=f.apiColumn.type;(r||n.compareFields(l,i[u],s[u]))&&(s[u]=n.formatResponseValue(l,t[u]))}for(var h=0,p=o;h<p.length;h++){var f;i[u=(f=p[h]).id]=n.formatResponseValue(f.apiColumn.type,t[u])}return null!==e&&this.setDerived(e),this},t.prototype.updateItemValues=function(t,e,r){for(var n=this.factory.itemEntryService,o=this.parent,i=0,s=e;i<s.length;i++){var c=s[i],a=c.id,u=c.apiColumn,l=void 0;"link"===u.type&&void 0===t[a]?null!==o&&(l=o.itemId):l=n.getConversionValue(u.itemType,t[a],r),void 0!==l&&(t[a]=l)}},t.prototype.updateItemFields=function(t,e){void 0===e&&(e=this.columns);var r=e.item,n=this.modified;return this.updateItemValues(this.initial,r,t),void 0===n?this:(this.updateItemValues(n,r,t),this)},t.prototype.formatRequest=function(){var t=this.factory.apiFormatter,e=this.columns.main;return this.isLocal()?t.formatRequestLocal(this.getFields(),e):void 0===this.modified?{}:t.formatRequest(this.initial,this.modified,e)},t.prototype.setDisplayName=function(){if(void 0===this.modified)return this;var t=this.getDisplayName();return t&&(this.modified.displayname=t),this},t.prototype.getDisplayName=function(){var t=this.factory.itemEntryService,e=this.getFields();switch(this.itemType){case"Contact":return"bedrijf"===e.type?e.bedrijf:t.getFullName(e.voornaam,e.tussenvoegsel,e.naam);case"Medewerker":case"Person":return t.getFullName(e.voornaam,e.tussenvoegsel,e.achternaam);case"Reparatie":return this.derived["materiaal>naam"];default:return e[t.getTitleField(this.itemType)]}},t.prototype.getChanges=function(t){return void 0===t&&(t=!1),void 0!==this.modified||t?this.factory.apiFormatter.getChanges(this.initial,t?{}:this.modified,this.columns.main):[]},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.hasChanges=function(){return void 0!==this.modified&&this.factory.apiFormatter.hasChanges(this.initial,this.modified,this.columns.main)},t.prototype.resetModified=function(){var t=this.columns.main;if(void 0===this.modified)return this;for(var e=0,r=t;e<r.length;e++){var n=r[e];this.modified[n.id]=this.factory.apiFormatter.clone(n.apiColumn.type,this.initial[n.id])}return this},t.prototype.setInitial=function(t,e){void 0===e&&(e=!1);var r,n=this.factory.apiFormatter;for(var o in t)this.initial[o]=t[o];if(void 0===this.modified)return e&&this.callOnChange(n.copyFields(this.initial,{},this.columns.main)),this;for(var o in r=n.copyFields(this.modified,{},this.columns.main),t)this.modified[o]=t[o];return e&&this.callOnChange(r),this},t.prototype.setModified=function(t){var e=this.factory,r=e.apiFormatter,n=this.columns,o=n.response[this.itemType];if(void 0===this.modified){var i=this.initial,s=this.modified=this.isLocal()?e.itemEntryService.getLocalDefaultValues():{};if(void 0===t)r.copyFields(i,s,n.main);else for(var c in r.shallowCopyFields(t,i,s,n.main),t)void 0===o[c]&&(s[c]=t[c]);for(var a=0,u=this.getResources();a<u.length;a++){var l=u[a];l instanceof ht&&(l.fields=s)}return this}if(void 0===t)return this;for(var c in t)this.modified[c]=t[c];return this},t.prototype.setDerived=function(t){for(var e in t)this.derived[e]=t[e];return this},t.prototype.setParent=function(t,e){return this.parent={itemType:t,itemId:e},this},t.prototype.callOnChange=function(t){for(var e=0,r=this.getResources();e<r.length;e++){var n=r[e];try{n.options.onChange(n,t)}catch(t){this.factory.exceptionHandler(t)}}return this},t.prototype.toJSON=function(){return{id:this.id,parent:this.parent,initial:this.initial,modified:this.modified,derived:this.derived,columns:this.columns}},t}(),W=function(){function t(t,e,r,n,o){this.factory=t,this.entry=e,this.options=r,this._isNew=n,this.localCache=o,this.derived=e.derived,this.columns=e.columns.response[e.columns.itemType]}return t.prototype.isNew=function(){return this._isNew},t.prototype.isLocal=function(){return this.entry.isLocal()},t.prototype.clearResource=function(){this.factory.cache.clearResource(this)},t.prototype.deactivate=function(){null!==this.localCache&&this.localCache.onDeactivateItem(this.entry)},t.prototype.toJSON=function(){var t=[];for(var e in this.columns)t.push(e);return{columns:t,fields:this.fields,derived:this.derived,entry:this.entry}},t}(),J=(V=function(t,e){return(V=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}V(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),K=function(t){function e(e,r,n,o,i){return t.call(this,e,r,n,o,i)||this}return J(e,t),e}(W),z=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)}}(),G=function(t){function e(e,r,n,o,i){var s=t.call(this,e,r,n,o,i)||this;return s.localCopies=[],s.transactions=0,r.setModified(),s.fields=r.modified,s}return z(e,t),e.prototype.isNew=function(){return this._isNew&&0===this.transactions},e.prototype.start=function(){return void 0===this.localCopies&&(this.localCopies=[]),this.localCopies.push(this.copyFields()),this},e.prototype.rollback=function(){var t=this.entry;return this.factory.apiFormatter.copyFields(this.localCopies.pop(),t.modified,t.columns.main),this.isNew()&&0===this.localCopies.length&&null!==this.localCache&&this.localCache.onDeactivateItem(this.entry),this},e.prototype.commit=function(t){void 0===t&&(t=!0);var e=this.localCopies.pop();return t&&this.callOnChange(e),this.transactions++,this},e.prototype.getLocalCopy=function(){var t=this.localCopies;return void 0===t?null:0===t.length?null:t[t.length-1]},e.prototype.copyFields=function(t){void 0===t&&(t={});var e=this.entry;return this.factory.apiFormatter.copyFields(e.modified,t,e.columns.main)},e.prototype.setFields=function(t,e){void 0===e&&(e=!0);var r,n=this.columns,o=this.fields,i=!1;for(var s in e&&(r=this.copyFields()),t){var c=n[s];void 0!==c?this.factory.apiFormatter.compareFields(c.type,o[s],t[s])||(o[s]=t[s],i=!0):console.warn("setFields: no column found for",s)}return e&&i&&this.callOnChange(r),this},e.prototype.callOnChange=function(t){return this.entry.callOnChange(t),this},e.prototype.save=function(t){var e=this,r=this.factory,n=this.entry,o={};return void 0!==t&&p(o,[n.itemType,n.itemId],[{},t]),(n.isLockable()?r.lockService.fetchLock(n):r.promiseService.when()).then(function(){return r.changesProcessor.execute([n],[],o)},r.errorHandler.reject).then(function(){return e},r.errorHandler.reject)},e}(W),Z=function(){return function(t){this.columns=[],this.query=null,this.queryParams={},this.parent=null,this.deferRequest=!1,this.limit=null,this.entryKey=null,o(this,t)}}(),$=function(){return function(t){this.editItems=!1,this.remoteItems=!1,this.editCollection=!1,this.modInstant=!1,this.enableSave=!0,this.onItemsCreated=ve,this.onChange=ve,this.onAdd=ve,this.onRemove=ve,this.onAddInitial=ve,this.onRemoveInitial=ve,this.resourceKey=null,this.custom=null,o(this,t)}}(),tt=0,et=function(){function t(t,e,r){this.factory=t,this.itemType=e,this.options=r,this.id=tt++,this.parent=null,this.templateColumns=null,this.initial=[],this.items=[],this.reloadQueued=!1,this.hasEditResources=!1,this.hasItemEditResources=!1,this.parent=r.parent,this.query=t.collectionEntryService.createQuery(r),this.columns=t.columnSetFactory.constructStub(e,r.columns),this.defer()}return t.prototype.getResources=function(){return this.factory.collectionResourceFactory.cache.get(this)},t.prototype.defer=function(){return this.isDeferred()?this:(this.deferred=this.factory.promiseService.defer(),this.promise=this.deferred.promise,this)},t.prototype.isDeferred=function(){return void 0!==this.promise},t.prototype._resolve=function(){var t=this.deferred;return void 0===t?this:(delete this.deferred,delete this.promise,t.resolve(this),this)},t.prototype.resolve=function(t){var e=t.initial,r=t.modified;return this.columns=t.columns,this.initial=e,this.items=void 0!==r?r:e.slice(),this._resolve()},t.prototype.isLocal=function(){var t=this.parent;return null!==t&&this.factory.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.forEach=function(t){for(var e=0,r=this.items;e<r.length;e++){t(r[e])}},t.prototype.getItemById=function(t){for(var e=0,r=this.items;e<r.length;e++){var n=r[e];if(n.itemId===t)return n}},t.prototype.getIdArray=function(t){return void 0===t&&(t=[]),this.factory.collectionEntryService.getIdArray(this.items,t)},t.prototype.createItems=function(t){var e,r=this,n=this.factory,o=this.columns;return n.itemHandler.fetchTemplate(this.itemType).then(function(i){e=i;var s=[];null===r.templateColumns&&(r.templateColumns=e.columns.merge(o));for(var c=0,a=t;c<a.length;c++){var u=a[c];s.push(n.itemEntryFactory.constructLocal(n.keyService.getLocalId(),e,u,{},r.parent,r.templateColumns))}return s},n.errorHandler.reject)},t.prototype.resolveDerivedValues=function(t,e){return this.factory.itemHandler.resolveDerivedValues(t,this.columns.root,e)},t.prototype.addItems=function(t,e,r,n,o){if(void 0===r&&(r=!1),0===t.length)return[];var i=this.items,s=this.parent,c=this.columns.link,a=[],u=[];if(r)for(var l=this.initial,h=0,p=t;h<p.length;h++){var f=p[h];-1===l.indexOf(f)&&(l.push(f),a.push(f))}for(var d=0,m=t;d<m.length;d++){f=m[d];-1===i.indexOf(f)&&(null!==s&&(f.parent=s,null!==c&&void 0!==f.modified&&(f.modified[c.id]=s.itemId)),i.push(f),u.push(f))}return this.handleAddedItemCallbacks(a,u,e,n,o)},t.prototype.handleAddedItemCallbacks=function(t,e,r,n,o){void 0===r&&(r=null),void 0===n&&(n=!0),void 0===o&&(o=!0);var i,s,c=this.getResources();if(t.length>0&&this.onAddInitial(t),0===e.length||0===c.length)return null===r?null:[];for(var a=0,u=c;a<u.length;a++){var l=u[a];null!==l.localCache&&(i=l.localCache);var h=l.addItemResources(e);l===r?(s=h,n&&l.callOnAdd(h)):l.callOnAdd(h)}if(o&&void 0!==i)for(var p=0,f=e;p<f.length;p++){var d=f[p];i.onActivateItem(d)}return void 0!==s?s:null===r?null:[]},t.prototype.removeItems=function(t,e,r,n){return 0===t.length?[]:this.handleRemovedItems(function(e){return!a(e.itemId,t)},e,r,n)},t.prototype.clear=function(t,e,r){return this.handleRemovedItems(function(){return!1},t,e,r)},t.prototype.handleRemovedItems=function(t,e,r,n){void 0===r&&(r=!1);var o,i=this.factory.collectionEntryService,s=i.filterArray(this.items,t);if(r)o=i.filterArray(this.initial,t);else{for(var c=[],a=0,u=s;a<u.length;a++){var l=u[a];l.isLocal()&&c.push(l)}o=c.length>0?i.filterArray(this.initial,function(t){return-1===c.indexOf(t)}):[]}return this.handleRemovedItemCallbacks(o,s,e,n)},t.prototype.handleRemovedItemCallbacks=function(t,e,r,n){void 0===n&&(n=!0);var o,i,s=this.getResources();if(t.length>0&&this.onRemoveInitial(t),0===e.length||0===s.length)return null===r?null:[];for(var c=0,a=s;c<a.length;c++){var u=a[c];null!==u.localCache&&(o=u.localCache);var l=u.removeItemResources(e);u===r?(i=l,n&&u.callOnRemove(l)):u.callOnRemove(l)}if(void 0!==o)for(var h=0,p=e;h<p.length;h++){var f=p[h];o.onDeactivateItem(f)}return void 0!==i?i:null===r?null:[]},t.prototype.createBatchStatus=function(t,e,r){return this.factory.itemHandler.createBatchStatus(this.itemType,t,this.parent,e,!1,r,!1).batchStatus},t.prototype.expandLocal=function(t,e){var r=this,n=this.factory,o=n.errorHandler,i=this.itemType;return n.columnHandler.fetch(i,t).then(function(s){var c=n.columnExpansionFactory.construct(i,t,s),a=r.createBatchStatus(r.getIdArray(),t,e);return a.getPromises().then(function(){return n.itemHandler.handleBatchResponse(a,e,t,null,s,c)},o.reject).then(function(){return c},o.reject)},o.reject)},t.prototype.expandRemote=function(t,e){var r=this,n=this.factory,o=n.errorHandler,i=this.itemType;return n.itemRequestService.requestItems(this,void 0,t).then(function(s){var c=s.fetchColumnsObject(),a=n.columnExpansionFactory.construct(i,t,c),u=r.createBatchStatus(s.links[i],t,e);return u.getPromises().then(function(){return n.itemHandler.handleBatchResponse(u,e,t,s,c,a)},o.reject).then(function(){var t=s.items[i];return r.handleRemovedItems(function(e){return void 0!==t[e.itemId]||e.isLocal()},null,!0,!0),r.addItems(u.getArray([T.RESOLVE]),null,!0,!0,!1),a},o.reject)},o.reject)},t.prototype.expand=function(t,e){var r=this,n=this.columns.mergeRequestColumns(t),o=n.merged,i=n.difference;return!0!==i&&0===i.length?this.factory.promiseService.when(this):(this.isLocal()?this.expandLocal(i,e):this.expandRemote(o,e)).then(function(t){return r.expandColumns(t),r})},t.prototype.extendQuery=function(t){var e=this.options;return void 0===t?this.query:(e.queryParams=t(e.queryParams),this.query=this.factory.collectionEntryService.createQuery(e))},t.prototype.extend=function(t,e,r){var n=this,o=this.factory,i=o.errorHandler,s=this.extendQuery(t).object,c=o.queryService.addAndCondition(s,o.queryService.createNotIn(this.getIdArray())),a=o.itemRequestService.requestItems(this,null!==this.options.limit?s:c).then(function(t){return o.itemRequestService.processResponse(t,t.links[n.itemType],n.parent,n.columns)},i.reject).then(function(t){return delete n.promise,n.addItems(t,e,!0,r,!1)},i.reject);return this.promise=a.then(function(){return n},i.reject),a},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.templateColumns=null,this.options.columns=this.columns.request)},t.prototype.expandRequestColumns=function(t){this.columns.expandRequestColumns(t),this.options.columns=this.columns.request},t.prototype.getAddedItems=function(t){void 0===t&&(t=!1);for(var e=this.initial,r=[],n=0,o=this.items;n<o.length;n++){var i=o[n];-1===e.indexOf(i)&&r.push(t?i.itemId:i)}return r},t.prototype.getRemovedItems=function(t){void 0===t&&(t=!1);for(var e=this.initial,r=this.items,n=[],o=0,i=e;o<i.length;o++){var s=i[o];-1===r.indexOf(s)&&n.push(t?s.itemId:s)}return n},t.prototype.getUpdatedItems=function(){for(var t=[],e=0,r=this.items;e<r.length;e++){var n=r[e];!n.isLocal()&&n.hasChanges()&&t.push(n)}return t},t.prototype.hasAddedItems=function(){return this.items.length>this.initial.length},t.prototype.hasRemovedItems=function(){return this.initial.length>this.items.length},t.prototype.hasUpdatedItems=function(){for(var t=0,e=this.items;t<e.length;t++){if(e[t].hasChanges())return!0}return!1},t.prototype.revertChanges=function(){var t=this.getAddedItems(),e=this.getRemovedItems();this.items=this.initial.slice(),this.handleAddedItemCallbacks([],e),this.handleRemovedItemCallbacks([],t)},t.prototype.onItemsCreated=function(t){for(var e=0,r=this.getResources();e<r.length;e++){var n=r[e];n.rebuildMap();try{n.options.onItemsCreated(t)}catch(t){this.factory.exceptionHandler(t)}}},t.prototype.onAddInitial=function(t){for(var e=0,r=this.getResources();e<r.length;e++){var n=r[e];try{n.options.onAddInitial(t,this)}catch(t){this.factory.exceptionHandler(t)}}},t.prototype.onRemoveInitial=function(t){for(var e=0,r=this.getResources();e<r.length;e++){var n=r[e];try{n.options.onRemoveInitial(t,this)}catch(t){this.factory.exceptionHandler(t)}}},t.prototype.getUpdatedItemColumns=function(t){for(var e={},r=0,n=this.columns.item;r<n.length;r++){var o=n[r];void 0!==t[o.apiColumn.itemType]&&(e[o.id]=o)}return e},t.prototype.clone=function(t,e){for(var r=this.factory,n=r.itemEntryService.batchClone(this.items,e),o=0,i=n;o<i.length;o++){i[o].parent=t}return r.construct(this.itemType,r.collectionEntryService.cloneOptions(this.options,t)).resolve({columns:this.columns,initial:n})},t}(),rt=function(){function t(t,e,r,n,o){var i=this;this.factory=t,this.entry=e,this.options=r,this.level=n,this.localCache=o,this.itemIdMap={},this.items=[],this.itemIdMap={},this.columns=e.columns.response,this.onChange=function(t,e){i.options.onChange(t,e)},this.addItemResources(e.items)}return t.prototype.getItemById=function(t){return this.itemIdMap[t]},t.prototype.rebuildMap=function(){for(var t={},e=0,r=this.items;e<r.length;e++){var n=r[e];t[n.entry.itemId]=n}this.itemIdMap=t},t.prototype.addItemResources=function(t){if(0===t.length)return[];for(var e=[],r=this.options,n=this.items,o=this.itemIdMap,i=this.factory.itemResourceFactory.getConstructor({edit:r.editItems,onChange:this.onChange},this.level,this.localCache),s=0,c=t;s<c.length;s++){var a=c[s],u=a.itemId,l=void 0;void 0===o[u]?(l=i(a),n.push(l),o[u]=l):l=o[u],e.push(l)}return e},t.prototype.removeItemResources=function(t){var e=this,r=[];return u(this.items,function(n){for(var o=0,i=t;o<i.length;o++){var s=i[o];if(n.entry===s)return r.push(n),delete e.itemIdMap[s.itemId],!1}return!0}),r},t.prototype.callOnAdd=function(t){try{this.options.onAdd(t,this)}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 o=n[r];t(o)&&e.push(o)}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)for(var n=0,o=e;n<o.length;n++){void 0===r[a=(c=o[n]).fields[t]]&&(r[a]=[]),r[a].push(c)}if("function"==typeof t)for(var i=0,s=e;i<s.length;i++){var c,a;null!==(a=t(c=s[i]))&&(void 0===r[a]&&(r[a]=[]),r[a].push(c))}return r},t.prototype.map=function(t){var e=this.items,r=e.length,n=new Array(r);if("string"==typeof t)for(var o=0;o<r;o++)n[o]=e[o].fields[t];if("function"==typeof t)for(o=0;o<r;o++)n[o]=t(e[o]);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,e,r){var n=this;return void 0===e&&(e=!1),this.entry.extend(t,this,r).then(function(t){return e?n.items:t})},t.prototype.clearResource=function(){this.factory.cache.clearResource(this)},t.prototype.deactivate=function(){null!==this.localCache&&this.localCache.clearCollection(this)},t}(),nt=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,o,i){return t.call(this,e,r,n,o,i)||this}return nt(e,t),e}(rt),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)}}(),st=function(t){function e(e,r,n,o,i){return t.call(this,e,r,n,o,i)||this}return it(e,t),e.prototype.save=function(){if(!this.options.enableSave)throw new Error("collectionResourceService: Saving disabled");var t=this.factory,e=this.entry,r=e.parent;return null!==r&&t.keyService.isLocalId(r.itemId)?t.promiseService.when():t.changesProcessor.execute([],[e])},e.prototype.moveItems=function(t,e,r){var n=this.entry,o=this.options;if(o.enableSave||o.modInstant)throw new Error("collectionResourceService: Cannot move items: saving enabled");if(n.itemType!==e.entry.itemType)throw new Error("collectionResourceService: Cannot move items: itemType mismatch");var i=n.removeItems(t,this,!1,r),s=[];if(null!==i){for(var c=0,a=i;c<a.length;c++){var u=a[c];s.push(u.entry)}e.entry.addItems(s,e,!1,r)}return i},e.prototype.removeItems=function(t,e){var r=this;void 0===e&&(e=!0);var n=this.entry.removeItems(t,this,!1,!1);return null===n?this.factory.promiseService.when([]):this.options.modInstant?this.save().then(function(){return e&&r.callOnRemove(n),n}):(e&&this.callOnRemove(n),this.factory.promiseService.when(n))},e.prototype.removeItem=function(t,e){return this.removeItems([t],e).then(function(t){return t[0]},this.factory.errorHandler.reject)},e.prototype.addItems=function(t,e,r){var n=this;void 0===e&&(e=!0);var o=this.factory,i=this.options.modInstant;return this.entry.createItems(t).then(function(t){return i||null===n.localCache?t:n.entry.resolveDerivedValues(t,n.localCache.items)}).then(function(t){var s=n.entry.addItems(t,n,!1,!1,r);return null===s?[]:i?n.save().then(function(){return e&&n.callOnAdd(s),s},o.errorHandler.reject):(e&&n.callOnAdd(s),s)},o.errorHandler.reject)},e.prototype.addItem=function(t,e,r){return this.addItems([t],e,r).then(function(t){return t[0]},this.factory.errorHandler.reject)},e.prototype.clear=function(t){return this.entry.clear(this,!1,t)},e}(rt),ct=function(){return function(t,e,r,n){this.itemType=e,this.response=r,this.fields=r.fetchObject(e,r.links[e][0]),this.responseColumns=t.columnUtil.mergeResponseColumns(r.fetchColumnsObject(),n).merged,this.columns=t.columnSetFactory.construct(e,!0,this.responseColumns)}}(),at=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,o,i){var s=t.call(this,e,r,n,o,i)||this;return s.fields=r.initial,s}return at(e,t),e}(K),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,o,i){var s=t.call(this,e,r,n,o,i)||this;return s.fields=void 0===r.modified?r.initial:r.modified,s}return lt(e,t),e}(K),pt=function(){function t(t,e){this.queryParserFactory=t,this.queryService=e}return t.prototype.cloneOptions=function(t,e){var r=new Z(t);return r.queryParams=this.cloneQueryParams(t.queryParams),r.parent=e,r},t.prototype.processOptions=function(t){return new Z(t)},t.prototype.cloneQueryParams=function(t){var e={};for(var r in t){var o=t[r],i=void 0;i=Array.isArray(o)?o.slice():n.isMoment(o)?o.clone():o,e[r]=i}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 o=this.queryParserFactory.construct(e,t.queryParams).parse();return{object:o[0],string:o[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 o=n[r];e.push(o.itemId)}return e},t.prototype.filterArray=function(t,e){for(var r=[],n=[],o=0,i=t;o<i.length;o++){var s=i[o];(e(s)?r:n).push(s)}if(0===n.length)return n;t.length=r.length;for(var c=0;c<t.length;c++)t[c]=r[c];return n},t}(),ft=function(){function t(t,e,r,n,o,i,s,c,a,u,l,h,p,f){this.batchStatusFactory=t,this.collectionCacheFactory=e,this.collectionEntryFactory=r,this.collectionEntryService=n,this.collectionMatcherFactory=o,this.columnHandler=i,this.columnSetFactory=s,this.errorHandler=c,this.itemHandler=a,this.itemRequestService=u,this.keyService=l,this.promiseService=h,this.queryParserFactory=p,this.queryService=f,this.entries=this.collectionCacheFactory.construct()}return t.prototype.removeFromAndAddToCollections=function(t){for(var e in t){var r=t[e],n=r.collection;n.removeItems(r.notfitting,null,!0),n.addItems(r.fitting,null,!0),r.maybe.length>0&&n.extend(ge,null,!0)}},t.prototype.getCollectionMatcher=function(){return this.collectionMatcherFactory.construct([this.entries],!0,!0,!0)},t.prototype.removeFromCollections=function(t,e,r){var n;for(var o in void 0===r&&(r=null),t){for(var i=t[o],s=i.fitting,c=i.maybe,a=i.collection,u=[],l=0,h=s;l<h.length;l++){var p=h[l];u.push(p.itemId)}for(var f=0,d=c;f<d.length;f++){var m=d[f];u.push(m)}null!==r&&a===r.entry?n=a.removeItems(u,r,e):a.removeItems(u,null,e)}return n},t.prototype.addToCollections=function(t,e,r){var n;for(var o in void 0===r&&(r=null),t){var i=t[o],s=i.collection;s.isDeferred()||(null!==r&&s===r.entry?n=s.addItems(i.fitting,r,e):s.addItems(i.fitting,null,e),e&&i.maybe.length>0&&s.extend(ge,null,!0,e))}return n},t.prototype.batchExpand=function(t,e,r,n){var o=this;if(0===n.length)return this.promiseService.when(r);var i=[],s=[];for(var c in r){var a=r[c].entry;a.defer(),i.push(a.parent.itemId),s=s.concat(a.items)}return this.itemRequestService.requestLinkItems(t,i,e,null,n).then(function(t){for(var c=o.itemRequestService.processExpansion(n,t,e,s),a=0,u=i;a<u.length;a++){var l=u[a],h=r[l].entry;h.expandColumns(c),h._resolve()}return r})},t.prototype.batchExtend=function(t,e,r,n,o,i,c){var a=this;if(void 0===i&&(i=!1),!s(o))return this.promiseService.when({});var u=[],l=[];for(var h in r.queryParams=n(r.queryParams),o){var p=o[h].entry;p.extendQuery(n),u.push(p.parent.itemId),l=l.concat(p.getIdArray())}return this.itemRequestService.requestLinkItems(t,u,e,this.queryService.addAndCondition(this.collectionEntryService.createQuery(r).object,this.queryService.createNotIn(l)),r.columns).then(function(n){return a.itemRequestService.processLinkResponse(n,t,u,e,r)},this.errorHandler.reject).then(function(t){for(var e={},r=0,n=u;r<n.length;r++){var s=n[r],a=o[s],l=a.entry.addItems(t.items[s],a,!0,c,!1);e[s]=i?a.items:l}return e},this.errorHandler.reject)},t.prototype.batchFetch=function(t,e,r,n,o,i,s){var c=this,a=this.errorHandler,u=this.batchStatusFactory.construct(r,function(t){return t.parent.itemId},function(t){return t.promise});E(e)&&(e=e());for(var l=0,h=e;l<h.length;l++){var p=h[l];u.add(this.getEntryStatus(r,this.collectionEntryService.cloneOptions(n,{itemType:t,itemId:p}),i,s))}return u.getPromises().then(function(){var i,s,l=u.getRequestIds();if(null===n.query)s=null;else{var h=c.queryParserFactory.construct(n.query,n.queryParams).parse();s={object:h[0],string:h[1]}}if(l.length>0)i=c.itemRequestService.requestLinkItems(t,l,r,null===s?null:s.object,n.columns).then(function(e){return c.itemRequestService.processLinkResponse(e,t,l,r,n)},a.reject);else{if(!u.hasEntries([T.LOCAL]))return u.getMap();i=c.columnHandler.fetch(r,n.columns).then(function(t){return{columns:c.columnSetFactory.construct(r,n.columns,t,!1)}},a.reject)}return i.then(function(n){var i=o.batchGetLocalByParent(t,e,r,s),l=[];for(var h in i)l=l.concat(i[h]);return c.expandLocalItemEntries(r,l,n.columns,o).then(function(){return c.handleBatchResponse(u,n,i)},a.reject)},a.reject)},a.reject)},t.prototype.handleBatchResponse=function(t,e,r){var n={};return t.forEachEntry([T.CACHED],function(t,e){n[e]=t}),t.forEachEntry([T.RESOLVE],function(t,o){var i=e.items[o];n[o]=t.resolve({initial:i,modified:i.concat(r[o]),columns:e.columns})}),t.forEachEntry(t.remoteExpandStatus,function(t,r){t.expandColumns(e.columnExpansion),n[r]=t._resolve()}),t.forEachEntry([T.LOCAL],function(t,o){n[o]=t.resolve({initial:r[o],columns:e.columns})}),n},t.prototype.fetch=function(t,e,r,n,o){var i=this.getEntryStatus(t,e,n,o);return this.resolveCached(i.entry,i.status,e,r,n,o)},t.prototype.resolveCached=function(t,e,r,n,o,i){var s=this,c=this.errorHandler;switch(e){case T.CACHED:return this.promiseService.when(t);case T.PROMISED:return t.promise;case T.EXPAND:return t.expand(r.columns,n).then(function(){return t._resolve()},c.reject);case T.PROMISED_EXPAND:return t.promise.then(function(){return s.resolveCached(t,s.getCachedEntryStatus(t,r),r,n,o,i)},c.reject);case T.LOCAL:return this.resolveLocal(t,n);default:return this.resolveRemote(t,n)}},t.prototype.getCachedEntryStatus=function(t,e){return t.columns.isSupersetOf(e.columns)?t.isDeferred()?T.PROMISED:t.reloadQueued?(t.reloadQueued=!1,t.isLocal()?T.CACHED:(t.defer(),T.RESOLVE)):T.CACHED:t.isDeferred()?T.PROMISED_EXPAND:(t.defer(),T.EXPAND)},t.prototype.getDeferredEntryStatus=function(t,e,r,n){var o;return e.deferRequest?null!==(o=n.getByQuery(t,r))?(o.expandRequestColumns(e.columns),{entry:o,isDeferred:!1}):(o=this.collectionEntryFactory.construct(t,e),{entry:n.add(o),isDeferred:!0}):{entry:o=this.collectionEntryFactory.construct(t,e),isDeferred:!1}},t.prototype.getEntryStatus=function(t,e,r,n){var o,i,s,c=this.collectionEntryService.createQuery(e);return this.isLocal(e)?null!==(s=r.getByQuery(t,c))?{entry:s,status:this.getCachedEntryStatus(s,e)}:(s=(o=this.getDeferredEntryStatus(t,e,c,n)).entry,o.isDeferred?{entry:s,status:T.PROMISED}:{entry:r.add(s),status:T.LOCAL}):null!==(s=this.entries.getByQuery(t,c))?{entry:r.add(s),status:this.getCachedEntryStatus(s,e)}:(s=(i=this.getDeferredEntryStatus(t,e,c,n)).entry,i.isDeferred?{entry:s,status:T.PROMISED}:(r.add(s),this.entries.add(s),{entry:s,status:T.RESOLVE}))},t.prototype.resolveLocal=function(t,e){var r=this,n=t.itemType,o=t.options.columns;return this.columnHandler.fetch(n,o).then(function(i){var s=r.columnSetFactory.construct(n,o,i,!1);return r.expandLocalItemEntries(n,e.getLocalByQuery(n,t.query),s,e).then(function(e){return t.resolve({initial:e,columns:s})},r.errorHandler.reject)},this.errorHandler.reject)},t.prototype.resolveRemote=function(t,e){var r,n=this,o=this.errorHandler,i=t.itemType;return this.itemRequestService.requestItems(t).then(function(e){return r=n.columnSetFactory.construct(i,t.options.columns,e.fetchColumnsObject()),n.itemRequestService.processResponse(e,e.links[i],t.parent,r)},o.reject).then(function(s){return n.expandLocalItemEntries(i,e.getLocalByQuery(i,t.query),r,e).then(function(e){return t.resolve({initial:s,modified:s.concat(e),columns:r})},o.reject)},o.reject)},t.prototype.isLocal=function(t){var e=t.parent;return null!==e&&this.keyService.isLocalId(e.itemId)},t.prototype.expandLocalItemEntries=function(t,e,r,n){return this.itemHandler.expandLocalEntries(t,e,r.request,r.response,n)},t}(),dt=function(){function t(t,e,r,n,o){this.queryMatcherFactory=t,this.collectionCaches=e,this.updateInitial=r,this.callOnAdd=n,this.callOnActivate=o,this.map={}}return t.prototype.expand=function(t){var e=this.queryMatcherFactory.construct(t.itemType,t.getFields(),t.parent);return this._expand(t,function(t){return e.matchQuery(t.query.object)})},t.prototype._expand=function(t,e){for(var r=this.map,n=t.itemId,o=0,i=this.collectionCaches;o<i.length;o++)for(var s=0,c=i[o].getByItemType(t.itemType);s<c.length;s++){var a=c[s],u=a.id,l=void 0;void 0===r[u]&&(r[u]={collection:a,matches:{}}),void 0===(l=r[u].matches)[n]&&(l[n]={item:t,isMatch:e(a)})}return this},t.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},t.prototype.addToCollections=function(t){var e;for(var r in void 0===t&&(t=null),this.map){var n=this.map[r],o=n.collection,i=this.groupItemEntries(n.matches),s=i.fitting;o.isDeferred()||(null!==t&&o===t.entry?e=o.addItems(s,t,this.updateInitial,this.callOnAdd,this.callOnActivate):o.addItems(s,null,this.updateInitial,this.callOnAdd,this.callOnActivate),this.updateInitial&&i.maybe.length>0&&o.extend(ge,null,!0))}return void 0!==e?e:null!==t?[]:null},t.prototype.removeFromCollections=function(t){void 0===t&&(t=null);var e=null;for(var r in this.map){var n=this.map[r],o=n.collection,i=this.groupItemIds(n.matches).fitting;null===t||o!==t.entry?e=o.removeItems(i,t,this.updateInitial):o.removeItems(i,null,this.updateInitial)}return e},t.prototype.removeFromAndAddToCollections=function(){for(var t in this.map){var e=this.map[t],r=e.collection,n=this.groupItemEntries(e.matches);r.removeItems(n.notFitting,null,this.updateInitial),r.addItems(n.fitting,null,this.updateInitial),this.updateInitial&&n.maybe.length>0&&r.extend(ge,null,!0)}},t.prototype.groupItemEntries=function(t){var e=[],r=[],n=[];for(var o in t){var i=t[o],s=i.item,c=i.isMatch;!0===c?e.push(s):!1===c?r.push(s.itemId):n.push(s)}return{fitting:e,notFitting:r,maybe:n}},t.prototype.groupItemIds=function(t){var e=[],r=[];for(var n in t){var o=t[n];(!1===o.isMatch?r:e).push(o.item.itemId)}return{fitting:e,notFitting:r}},t.prototype.hasFittingItems=function(t){for(var e in t)if(!0===t[e].isMatch)return!0;return!1},t}(),mt=function(){function t(){}return t.prototype.processOptions=function(t){return new $(t)},t.prototype.getIdArray=function(t){for(var e=[],r=0,n=t;r<n.length;r++){var o=n[r];e.push(o.entry.itemId)}return e},t}(),yt=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],o=e.id;return void 0===n[o]&&(n[o]=e),n[o]},t.prototype.setColumns=function(t,e,r){var n={};for(var o in r){var i=r[o];for(var s in n[o]={},i)n[o][s]=this.setColumn(o,i[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 o=0,i=e;o<i.length;o++){var s=i[o];this.retrieveColumn(t,s,r,n)}},t.prototype.retrieveColumn=function(t,e,r,n){var o,i=this.columnUtil.parseRequestColumn(e),s=this.getColumn(t,i.id);if(void 0!==s){if(void 0===n[t]&&(n[t]={}),n[t][i.id]=s,0!==i.children.length){var c=[];this.retrieveColumns(s.itemType,i.children,c,n),0!==c.length&&r.push(((o={})[i.id]=c,o))}}else r.push(e)},t.prototype.getColumn=function(t,e){var r=this.cache[t];if(void 0!==r)return r[e]},t}(),vt=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 o in this.requestColumnsTrue=!0,this.requestColumns=[],n[e])this.requestColumns.push(o);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[c(t)];return null!==e?e.difference.root:[]}var r={};for(var n in t){var o=t[n];null!==o&&this.expandRootColumnMap(o.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 o=n[r],i=o.id;void 0===e[i]&&(e[i]={apiColumn:o.apiColumn,children:{}}),this.expandRootColumnMap(o.children,e[i].children)}},t}(),gt=function(){function t(t,e,r,n,o){this.apiRequestService=t,this.errorHandler=e,this.promiseService=r,this.cache=n,this.columnUtil=o}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 o=n[r];e[o]=this.fetch(o,["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,o=this;return void 0===r&&(r={filter:!1}),this.apiRequestService.columns(t,(n={},n[t]=e,n),r).then(function(r){return o.cache.setColumns(t,e,r.fetchColumnsObject())},this.errorHandler.reject)},t.prototype.fetch=function(t,e,r){var n=this,o=this.cache.retrieve(t,e);return!0!==o.missing&&0===o.missing.length?this.promiseService.when(o.cached):this.request(t,o.missing,r).then(function(t){return n.columnUtil.mergeResponseColumns(t,o.cached).merged})},t.prototype.fetchAll=function(t){return this.cache.containsAll(t)?this.promiseService.when(this.cache.getColumns(t)):this.request(t,!0)},t}(),Ct=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+D+r,this.tailPath=0===e.level?r:e.tailPath+D+r)}return t.prototype.setChildren=function(t,e){return this.itemType=t,this.children=e,this.isLeaf=!1,this},t}(),It={},St=0,Rt=function(){function t(t,e,r,n,o,i){this.columnHandler=t,this.columnUtil=e,this.columnInfoFactory=r,this.columnSetFactory=n,this.itemType=o,this.request=i,this.id=++St,this.response=It,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=[],this.requestColumnsTrue=!0===this.request}return 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.resolve=function(t,e,r){return void 0===e&&(e=!0),void 0===r&&(r=!0),this.requestColumnsTrue?this.processResponseColumns(t,e):this.processRequestColumns(t,e,r),this},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,o=t;n<o.length;n++){var i=o[n];if(!e.containsColumn(i,r))return!1}return!0},t.prototype.processResponseColumns=function(t,e){var r=this.itemType;for(var n in this.request=[],this.response=e?this.columnHandler.setColumns(this.itemType,!0,t):t,t[r])this.groupColumnInfo(this.columnInfoFactory.construct(t[r][n],null)),this.request.push(n)},t.prototype.processRequestColumns=function(t,e,r){var n=this.itemType,o={};this.createRootColumnMap(this.request,n,t,o,e),r&&this.createRootColumnMap(["id"],n,t,o,e),this.response={},this.processColumnInfo(this.columnInfoFactory.constructFromRootMap(o),n)},t.prototype.processColumnInfo=function(t,e){var r=this.response;void 0===r[e]&&(r[e]={});for(var n=0,o=t;n<o.length;n++){var i=o[n];r[e][i.id]=i.apiColumn,this.groupColumnInfo(i),i.isLeaf||this.processColumnInfo(i.children,i.itemType)}},t.prototype.createRootColumnMap=function(t,e,r,n,o){for(var i=0,s=t;i<s.length;i++){var c=s[i],a=this.columnUtil.parseRequestColumn(c),u=a.id,l=a.children,h=void 0;void 0!==r[e]&&(h=r[e][u]),void 0!==h?(o&&(h=this.columnHandler.setColumn(e,h)),void 0===n[u]&&(n[u]={apiColumn:h,children:{}}),0!==l.length&&this.createRootColumnMap(l,h.itemType,r,n[u].children,o)):console.warn("No api column for request column",u,"for itemType",e)}},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.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),o=this.mergeResponseColumns(r);return{merged:this.getMergedColumnSet(n,o,e),difference:this.columnSetFactory.construct(this.itemType,n.difference,o,!1,!1)}},t}(),Et=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}(),Ft=function(){function t(){}return t.prototype.getColumnPath=function(t,e){for(var r="",n="",o=0,i=t;o<i.length;o++){n+=r+i[o].id,r=D}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 o=0,i=r.children;o<i.length;o++){var s=i[o];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,o=e;n<o.length;n++){var i,s=o[n],c=this.parseRequestColumn(s),a=c.children,u=r[t];if(void 0===u)return!1;if(void 0===(i=u[c.id]))return!1;if(a.length>0&&!this.responseColumnsAvailable(i.itemType,a,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 o=n[r];e.push(this.copyRequestColumn(o))}return e},t.prototype.copyRequestColumn=function(t){var e,r=this.parseRequestColumn(t);if(0===r.children.length)return r.id;for(var n=[],o=0,i=r.children;o<i.length;o++){var s=i[o];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=[],o=0,i=e;o<i.length;o++){var s=i[o],c=this.mergeRequestColumn(s,r);null!==c&&n.push(c)}return{merged:r,difference:n}},t.prototype.mergeRequestColumn=function(t,e){var r,n,o=this.parseRequestColumn(t),i=this.findRequestColumn(o.id,e);if(-1===i)return e.push(t),t;if(0===o.children.length)return null;"string"==typeof e[i]&&(e[i]=((r={})[o.id]=[],r));for(var s=[],c=0,a=o.children;c<a.length;c++){var u=a[c],l=this.mergeRequestColumn(u,e[i][o.id]);null!==l&&s.push(l)}return 0===s.length?null:((n={})[o.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 o in t)if(void 0!==e[o]){var i=this.mergeResponseColumnMap(t[o],e[o]);r[o]=i.merged,n[o]=i.difference}else r[o]=t[o];for(var o in e)void 0===t[o]&&(r[o]=e[o],n[o]=e[o]);return{merged:r,difference:n}},t.prototype.mergeResponseColumnMap=function(t,e){var r={},n={};for(var o in t)r[o]=t[o];for(var o in e)L(t[o])||(r[o]=e[o],n[o]=e[o]);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 o=n[r];this.isLocalColumnId(o)||this.processConfigColumn(this.parseConfigColumn(o),e)}return e},t.prototype.parseConfigColumn=function(t){return t.split(":")[0].split(D)},t.prototype.processConfigColumn=function(t,e){var r,n,o=t[0],i=1===t.length,s=this.findRequestColumn(o,e);i?-1===s&&e.push(o):(-1===s?s=e.push(((r={})[o]=[],r))-1:"string"==typeof e[s]&&(e[s]=((n={})[o]=[],n)),this.processConfigColumn(t.slice(1),e[s][o]))},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}(),qt=function(){function t(t,e,r,n,o,i,s,c){void 0===c&&(c=!1),this.collectionHandler=t,this.collectionMatcherFactory=e,this.keyService=r,this.requestColumnExpansionFactory=n,this.compilation=o,this.localCollectionCache=i,this.parameterMap=s,this.breakupByParent=c,this.requests=[]}return t.prototype.finalizeRequest=function(t){for(var e=t.collections.getCollectionsWithFittingItems(),r=t.columns,n=0,o=e;n<o.length;n++){var i=o[n];r.expand(i.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 o=this.initializeRequest();this.extendRequest(r[n],this.setRequestParent(e,o)?+n:null,o),this.requests.push(this.finalizeRequest(o))}}else for(var e in t){r=t[e],o=this.initializeRequest();var i=this.setRequestParent(e,o),s=!1;for(var n in r)this.keyService.isLocalId(n)||(this.extendRequest(r[n],i?+n:null,o),s=!0);s&&this.requests.push(this.finalizeRequest(o))}return this.requests},t.prototype.initializeRequest=function(){return{request:{requestType:"create",items:{},columns:{}},columns:this.requestColumnExpansionFactory.construct(),items:{},collections:this.collectionMatcherFactory.construct([this.localCollectionCache,this.collectionHandler.entries],!0,!0,!1)}},t.prototype.extendRequest=function(t,e,r){var n=r.request,o=r.items;for(var i in t)for(var s in void 0===n.itemType&&(n.itemType=i),void 0===o[i]&&(o[i]={},n.items[i]={}),t[i]){var c=t[i][s],a=f(this.compilation,[i,s]),u=n.items[i][s]={},l=f(this.parameterMap,[i,s]);if(null!==e&&(n.parentId[s]=e),r.columns.expand(c.columns),r.collections.expand(c),o[i][s]=c,u.values=c.formatRequest(),u.parameters=l,void 0!==a){var h=u.links={};for(var p in a)for(var d in h[p]=[],a[p])h[p].push(parseInt(d,10));this.extendRequest(a,null,r)}}},t}(),bt=function(){function t(t,e,r,n,o,i,s,c,a,u,l,h,p,f,d){this.apiRequestService=t,this.authInterface=e,this.collectionHandler=r,this.collectionMatcherFactory=n,this.collectionResourceFactory=o,this.columnSetFactory=i,this.errorHandler=s,this.itemHandler=c,this.itemRequestService=a,this.itemResourceFactory=u,this.keyService=l,this.localCacheManager=h,this.moduleChangesCompilationFactory=p,this.promiseInterface=f,this.queryService=d}return t.prototype.invalidateCache=function(){this.itemHandler.entries.forEach(function(t){return t.queueReload()}),this.collectionHandler.entries.forEach(function(t){return t.queueReload()})},t.prototype.clearResources=function(t){this.itemResourceFactory.cache.clearResources(t),this.collectionResourceFactory.cache.clearResources(t)},t.prototype.getCollectionMatcher=function(t,e,r){void 0===e&&(e=!0),void 0===r&&(r=!0);for(var n=this.getLocalCache(),o=this.collectionMatcherFactory.construct([n.collections],!1,r,!0),i=0,s=t;i<s.length;i++){var c=s[i];e&&n.items.add(c),o.expand(c)}return o},t.prototype.fetchTitle=function(t,e,r){return this.itemHandler.fetchTitle(t,e,r,this.getLocalCache().items)},t.prototype.getItemById=function(t,e,r,n,o){void 0===r&&(r={});var i=this.getLocalCache();return this.itemHandler.fetchItem(t,e,new U(r),i.items).then(function(t){return i.createItemResource(t,r,n,o)},this.errorHandler.reject)},t.prototype.getItemsById=function(t,e,r,n){void 0===r&&(r={});var o=this.getLocalCache();return this.itemHandler.fetchItems(t,e,new U(r),o.items).then(function(t){return o.createItemResources(t,r,n)},this.errorHandler.reject)},t.prototype.getItemsByQuery=function(t,e,r,n){var o,i=this;void 0===r&&(r={});var s=this.getLocalCache(),c=new U(r);return this.apiRequestService.query(t,this.queryService.addParentCondition(e,c.parent),(o={},o[t]=c.columns,o)).then(function(e){return i.itemRequestService.processResponse(e,e.links[t],c.parent,i.columnSetFactory.construct(t,c.columns,e.fetchColumnsObject()))},this.errorHandler.reject).then(function(t){return s.createItemResources(t,r,n)},this.errorHandler.reject)},t.prototype.getNewResource=function(t,e,r,n,o){var i=this;void 0===e&&(e={}),void 0===r&&(r=!1);var s=this.getLocalCache();return e.edit=!0,this.itemHandler.fetchNewItem(t,new U(e),s.items).then(function(t){var c=s.createItemResource(t.main,e,n,o,!0),a=i.processLinkedItems(t.linked,e,n,!0);return r?{main:c,linked:a}:c},this.errorHandler.reject)},t.prototype.getDuplicateById=function(t,e,r,n,o,i){return void 0===r&&(r={}),r.isDuplicate=!0,void 0===r.templateOptions&&(r.templateOptions={}),void 0===r.templateOptions.item&&(r.templateOptions.item=e),this.getNewResource(t,r,o,n,i)},t.prototype.getItemByState=function(t,e,r,n,o){void 0===r&&(r={});var i=this.keyService.parseStateKey(e);if(null===i){var s=e;if(!this.keyService.isLocalId(s)||this.getLocalCache().items.contains(t,s))return this.getItemById(t,s,r,n,o)}else if("duplicate"===i.type)return this.getDuplicateById(t,i.itemId,r,n,!1,o);return this.getNewResource(t,r,!1,n,o)},t.prototype.getCollectionDef=function(t,e){return{itemType:t,options:{entry:new Z(e),resource:new $(e)}}},t.prototype.getLinkCollectionsDef=function(t,e,r){return{itemType:t,linkField:e,options:{entry:new Z(r),resource:new $(r)}}},t.prototype.getCollection=function(t,e,r){var n=this.getLocalCache();return this.collectionHandler.fetch(t,new Z(e),n.items,n.collections,n.deferredCollections).then(function(t){return n.createCollectionResource(t,new $(e),r)},this.errorHandler.reject)},t.prototype.getCollectionFromDef=function(t,e){var r=this.getLocalCache();return this.collectionHandler.fetch(t.itemType,t.options.entry,r.items,r.collections,r.deferredCollections).then(function(n){return r.createCollectionResource(n,t.options.resource,e)},this.errorHandler.reject)},t.prototype.getLinkCollections=function(t,e,r,n,o){var i=this.getLocalCache();return this.collectionHandler.batchFetch(t,e,r,new Z(n),i.items,i.collections,i.deferredCollections).then(function(t){return i.createCollectionResources(t,n,o)},this.errorHandler.reject)},t.prototype.getLinkCollectionsFromDef=function(t,e,r,n){var o=this.getLocalCache();return this.collectionHandler.batchFetch(t,e,r.itemType,r.options.entry,o.items,o.collections,o.deferredCollections).then(function(t){return o.createCollectionResources(t,r.options.resource,n)},this.errorHandler.reject)},t.prototype.getAllLinkCollections=function(t,e,r,n){var o=this;return this.apiRequestService.query(t,{},{}).then(function(i){return o.getLinkCollections(t,i.links[t],e,r,n)},this.errorHandler.reject)},t.prototype.cloneItem=function(t,e,r){return this.addSingleItem(t.entry.clone(),e,r,!1)},t.prototype.cloneCollection=function(t,e,r,n){var o=e.parent;return void 0===o&&(o=null),this.addCollection(t.entry.clone(o,r),e,n)},t.prototype.saveCurrentLocalCache=function(t,e,r,n){return this.getLocalCache().save(t,e,r,n)},t.prototype.getCurrentCollections=function(){return this.getLocalCache().collections},t.prototype.getCurrentItems=function(){return this.getLocalCache().items},t.prototype.getModuleChanges=function(t){if(void 0===t&&(t=this.getLocalCache()),void 0===t.rootItem)throw new Error("itemAdministrator: No root item for local cache "+t.id);return this.moduleChangesCompilationFactory.construct(t.rootItem,t.items,t.collections).process()},t.prototype.addSingleItem=function(t,e,r,n,o){return void 0===e&&(e={}),void 0===o&&(o=this.getLocalCache()),o.createItemResource(o.items.add(t),e,r,n)},t.prototype.addSingleItems=function(t,e,r){for(var n=this.getLocalCache(),o=[],i=0,s=t;i<s.length;i++){var c=s[i];o.push(this.addSingleItem(c,e,r,!1,n))}return o},t.prototype.addCollection=function(t,e,r){var n=this.getLocalCache();return n.collections.add(t),n.createCollectionResource(t,e,r)},t.prototype.createItemResources=function(t,e,r,n,o){for(var i=[],s=0,c=e;s<c.length;s++){var a=c[s];i.push(o.createItemResource(a,r,n)),"Projectnotitie"===t&&p(o.tabRequestParameters,[a.itemType,a.itemId],[{},{no_notification:!0}])}return i},t.prototype.processLinkedItems=function(t,e,r,n){void 0===n&&(n=!0);for(var o=this.getLocalCache(),i={},s=0,c=t;s<c.length;s++){i[(l=c[s]).itemType]=this.createItemResources(l.itemType,l.itemEntries,e,r,o)}if(!n)return i;for(var a=0,u=t;a<u.length;a++){var l=u[a];this.getCollectionMatcher(l.itemEntries,!1).addToCollections()}return i},t.prototype.expandProcessLinkedItems=function(t,e,r){for(var n=this.getLocalCache(),o=this.promiseInterface.when({}),i=0,s=t;i<s.length;i++){var c=s[i];o=o.then(this.constructOnItemsExpanded(c.itemType,c.itemEntries,r,e,n),this.errorHandler.reject)}return o},t.prototype.constructOnItemsExpanded=function(t,e,r,n,o){var i=this;return function(s){return i.expandAddToCollections(t,e,null,o).then(function(){return s[t]=i.createItemResources(t,e,r,n,o),s},i.errorHandler.reject)}},t.prototype.expandAddToCollections=function(t,e,r,n){void 0===r&&(r=null),void 0===n&&(n=this.getLocalCache());for(var o=this.collectionMatcherFactory.construct([n.collections],!1,!0,!1),i=0,s=e;i<s.length;i++){var c=s[i];o.expand(c)}var a=this.getColumnSuperset(o.getCollectionsWithFittingItems());return null===a?this.promiseInterface.when(null===rt?null:[]):this.itemHandler.expandLocalEntries(t,e,a.request,a.response,n.items).then(function(){return o.addToCollections(r)},this.errorHandler.reject)},t.prototype.getColumnSuperset=function(t){var e={};if(0===t.length)return null;for(var r=t[0].columns,n=1;n<t.length;n++){var o=t[n].columns;!0!==e[o.id]&&(e[o.id]=!0,r=r.merge(o))}return r},t.prototype.getLocalCache=function(){return this.localCacheManager.getCurrentLocalCache(this.authInterface.getUniqueUserId())},t.prototype.addToCollections=function(t,e,r){return void 0===r&&(r=!0),this.getCollectionMatcher(t,!0,r).addToCollections(e)},t.prototype.removeFromCollections=function(t,e){return this.getCollectionMatcher(t,!1).removeFromCollections(e)},t.prototype.saveLocal=function(t){var e=t.entry;return e.setDisplayName(),this.addToCollections([e]),this.promiseInterface.when(t)},t.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])}},t.prototype.createCollectionResource=function(t,e,r){return this.addCollection(t,e,r)},t.prototype.createItemResource=function(t,e,r,n){return this.addSingleItem(t,e,r,n)},t.prototype.onBeforeSave=function(t,e,r){return this.getLocalCache().onBeforeSave(t,e,r)},t.prototype.onSaveSuccess=function(t,e,r){return this.getLocalCache().onSaveSuccess(t,e,r)},t}(),Ot=function(){function t(t){this.queryMatcherFactory=t,this.entries={}}return 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 o in r){var i=r[o];i.isDeferred()||this.matchQuery(i,e)&&n.push(i)}return n},t.prototype.getLocalByQuery=function(t,e){var r=this.entries[t],n=[];if(void 0===r)return n;for(var o in r){var i=r[o];i.isLocal()&&(this.matchQuery(i,e)&&n.push(i))}return n},t.prototype.getByParent=function(t,e,r){var n=this.entries[r],o=[];if(void 0===n)return o;for(var i in n){var s=n[i],c=s.parent;null!==c&&(c.itemType===t&&c.itemId==e&&o.push(s))}return o},t.prototype.batchGetLocalByParent=function(t,e,r,n){for(var o=this.entries[r],i={},s=0,c=e;s<c.length;s++){i[c[s]]=[]}if(void 0===o)return i;for(var a in o){var u=o[a],l=u.parent;null!==l&&(l.itemType===t&&void 0!==i[l.itemId]&&u.isLocal()&&(null===n||this.matchQuery(u,n))&&i[l.itemId].push(u))}return i},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.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={},!0):this.clearByItemId(t.itemType,t.itemId)},t.prototype.clearByItemId=function(t,e){var r=this.entries[t];return void 0!==r&&delete r[e]},t.prototype.matchQuery=function(t,e){return!0===this.queryMatcherFactory.construct(t.itemType,t.getFields(),t.parent).matchQuery(e.object)},t}(),Lt=function(){function t(t,e){this.authInterface=t,this.keyService=e}return t.prototype.processOptions=function(t){return new U(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.createLocalConversionMap=function(t,e,r,n){void 0===r&&(r=!1);var o=n.links[t][0],i={};return i[t]={},i[t][o]=e,r&&this.expandLocalConversionMap(t,o,n,i),i},t.prototype.expandLocalConversionMap=function(t,e,r,n){var o=r.items[t][e].links;for(var i in o){var s=o[i];void 0===n[i]&&(n[i]={});for(var c=0,a=s;c<a.length;c++){var u=a[c];n[i][u]=this.keyService.getLocalId(),this.expandLocalConversionMap(i,u,r,n)}}},t.prototype.expandConversionMap=function(t,e,r){var n,o=t.itemType,i=t.itemId;return void 0===e[o]&&(e[o]={}),void 0!==(n=e[o])[i]?n[i]:(void 0===r&&(r=this.keyService.getLocalId()),n[i]=r)},t.prototype.batchExpandConversionMap=function(t,e){for(var r=0,n=t;r<n.length;r++){var o=n[r];this.expandConversionMap(o,e)}return e},t.prototype.getConversionValue=function(t,e,r){if(void 0!==r[t])return r[t][e]},t.prototype.batchClone=function(t,e){void 0===e&&(e={});var r=[];this.batchExpandConversionMap(t,e);for(var n=0,o=t;n<o.length;n++){var i=o[n];r.push(i.clone(e))}return r},t.prototype.getFullName=function(t,e,r){return t.trim().concat(" ",e).trim().concat(" ",r)},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.prototype.hasLocalDefaultValue=function(t){switch(t){case"permissions":case"creator":case"created":return!0;default:return!1}},t}(),Mt=function(){function t(t,e,r,n,o,i,s,c,a,u,l,h,p,f,d){this.apiFormatter=t,this.apiRequestService=e,this.batchStatusFactory=r,this.columnExpansionFactory=n,this.columnHandler=o,this.columnSetFactory=i,this.columnSubsetCacheFactory=s,this.columnUtil=c,this.errorHandler=a,this.itemCacheFactory=u,this.itemEntryFactory=l,this.itemEntryService=h,this.keyService=p,this.promiseService=f,this.templateFactory=d,this.templates={},this.entries=this.itemCacheFactory.construct()}return t.prototype.fetchItem=function(t,e,r,n){var o=this.getEntryStatus(t,e,r.parent,r.deferRequest,n,!0,this.columnSubsetCacheFactory.construct(r.columns));return null===o?this.errorHandler.reject(this.itemEntryService.createUnfoundLocalItemError(t)):this.resolveCached(o.entry,o.status,r,n)},t.prototype.fetchNewItem=function(t,e,r){var n=this,o=r.add(this.itemEntryFactory.constructDeferred(t,e.isDuplicate?this.keyService.getLocalDuplicateId():this.keyService.getLocalId(),!0,!1));return this.fetchTemplate(t,e.templateOptions,e.templateColumns).then(function(t){return n.resolveLocal(o,e.parent,t,r)},function(t){return o.reject(t),n.errorHandler.reject(t)})},t.prototype.createBatchStatus=function(t,e,r,n,o,i,s){for(var c=this.columnSubsetCacheFactory.construct(n),a=this.batchStatusFactory.construct(t,function(t){return t.itemId},function(t){return t.getPromise()}),u=!0,l=0,h=e;l<h.length;l++){var p=h[l],f=this.getEntryStatus(t,p,r,o,i,s,c);null!==f?a.add(f):u=!1}return{batchStatus:a,success:u}},t.prototype.fetchItems=function(t,e,r,n){var o,i,s=this,c=this.errorHandler,a=r.columns,u=this.createBatchStatus(t,e,r.parent,a,r.deferRequest,n,!0),l=u.batchStatus,h=u.success;return l.hasRequests()?i=(o=this.requestItems(t,l.getRequestIds(),a)).then(function(t){return t.fetchColumnsObject()},function(t){return l.forEachEntry([T.RESOLVE],function(t){return s.clearItem(t,n)}),c.reject(t)}):l.hasEntries(l.localExpandStatus)?(o=null,i=this.columnHandler.fetch(t,a)):(o=null,i=null),this.promiseService.all({entries:l.getPromises(),response:o,columns:i}).then(function(t){return s.handleBatchResponse(l,n,a,t.response,t.columns)},c.reject).then(function(t){return t&&h?l.getArray():c.reject()},c.reject)},t.prototype.handleBatchResponse=function(t,e,r,n,o,i){var s=this,c=t.itemType,a=!0;if(t.hasEntries([T.RESOLVE])){var u=this.columnSetFactory.construct(c,r,o);t.forEachEntry([T.RESOLVE],function(t){s.resolveRemote(t,u,n,e)||(a=!1)})}return t.forEachEntry([T.RESOLVE_VALUES],function(t){s.resolveRemoteValues(t,n)||(a=!1)}),t.hasEntries(t.remoteExpandStatus)&&(void 0===i&&(i=this.columnExpansionFactory.construct(c,r,o)),t.forEachEntry(t.remoteExpandStatus,function(t){return s.resolveExpansion(t,i,n)})),t.hasEntries(t.localExpandStatus)?this.expandLocalEntries(c,t.getArray(t.localExpandStatus),r,o,e).then(function(t){for(var e=0,r=t;e<r.length;e++){r[e].resolve()}return a},this.errorHandler.reject):this.promiseService.when(a)},t.prototype.resolveCached=function(t,e,r,n){var o,i=this,s=this.errorHandler,c=function(e){t.reject(e)};switch(e){case T.LOCAL:case T.CACHED:return this.promiseService.when(t);case T.PROMISED:return t.getPromise();case T.EXPAND:return o=this.getColumnDifference(t,r.columns),this.requestItem(t,o).then(function(e){i.resolveExpansion(t,i.columnExpansionFactory.construct(t.itemType,o,e.fetchColumnsObject()),e)},s.reject).catch(c),t.getPromise();case T.EXPAND_LOCAL:return o=this.getColumnDifference(t,r.columns),this.columnHandler.fetch(t.itemType,o).then(function(e){return i.expandLocalEntries(t.itemType,[t],o,e,n).then(function(){return t.resolve()},c)},c),t.getPromise();case T.PROMISED_EXPAND:case T.PROMISED_EXPAND_LOCAL:return t.getPromise().then(function(){return i.resolveCached(t,i.getCachedEntryStatus(t,i.columnSubsetCacheFactory.construct(r.columns)),r,n)},s.reject);case T.RESOLVE_VALUES:return this.requestItem(t).then(function(e){i.resolveRemoteValues(t,e)},s.reject).catch(c),t.getPromise();case T.RESOLVE:return this.requestItem(t).then(function(e){i.resolveRemote(t,t.columns.resolve(e.fetchColumnsObject()),e,n)},s.reject).catch(function(e){i.clearItem(t,n),t.reject(e)}),t.getPromise()}},t.prototype.getColumnDifference=function(t,e){return this.columnUtil.mergeRequestColumns(t.columns.request,e).difference},t.prototype.resolveLocal=function(t,e,r,n){var o=t.itemType,i=t.itemId,s=this.itemEntryService.createLocalConversionMap(o,i,!0,r.response);return t.columns=r.columns,null!==e&&t.setParent(e.itemType,e.itemId),t.setLocalFields(r.fields,s).resolve(),{main:t,linked:this.createLocalEntries(o,i,r,s,n)}},t.prototype.resolveExpansion=function(t,e,r){var n=t.itemType,o=t.itemId,i=e.run(t.columns);return null===i?t:(t.expand(r.fetchObject(n,o),r.fetchDerivedObject(n,o,i.difference.root),i),t.resolve())},t.prototype.clearItem=function(t,e){this.entries.clear(t),e.clear(t)},t.prototype.resolveRemote=function(t,e,r,n){var o=this.getResponseFields(t,e,r);return null===o?(this.clearItem(t,n),t.reject(),!1):(t.resolveDeferred(o.initial,o.derived,e),!0)},t.prototype.resolveRemoteValues=function(t,e){var r=this.getResponseFields(t,t.columns,e);return null===r?(t.reject(),!1):(t.updateFields(r.initial,r.derived,!1).resolve(),!0)},t.prototype.getResponseFields=function(t,e,r){var n=t.itemType,o=t.itemId,i=r.fetchObject(n,o);return void 0===i?null:{initial:i,derived:r.fetchDerivedObject(n,o,e.root)}},t.prototype.fetchTemplate=function(t,e,r){var n=this;void 0===e&&(e={}),void 0===r&&(r={});var o=s(e),i=c(r);if(!o){var a=this.templates[t];if(void 0!==a&&(null===i||this.columnUtil.responseColumnsAvailable(i,r[i],a.responseColumns)))return this.promiseService.when(a)}return this.promiseService.all({template:this.apiRequestService.template(t,e),additionalColumns:null===i?{}:this.columnHandler.fetch(i,r[i])}).then(function(e){var r=e.template,i=n.templateFactory.construct(t,r,e.additionalColumns);return!o&&r.cacheable&&(n.templates[t]=i),i},this.errorHandler.reject)},t.prototype.getEntryStatus=function(t,e,r,n,o,i,s){var c;return this.keyService.isLocalId(e)?void 0!==(c=o.get(t,e))?{entry:c,status:this.getCachedEntryStatus(c,s)}:null:void 0!==(c=this.entries.get(t,e))?{entry:i?o.add(c):c,status:this.getCachedEntryStatus(c,s)}:(c=this.itemEntryFactory.constructDeferred(t,e,s.requestColumns,n),null!==r&&c.setParent(r.itemType,r.itemId),i&&o.add(c),this.entries.add(c),{entry:c,status:n?T.PROMISED:T.RESOLVE})},t.prototype.getCachedEntryStatus=function(t,e){var r=t.columns;return t.isDeferred()?t.deferRequest?(r.expandRequestColumns(e.requestColumns),T.RESOLVE):e.run(r)?T.PROMISED:t.isLocal()?T.PROMISED_EXPAND_LOCAL:T.PROMISED_EXPAND:e.run(r)?t.reloadQueued?(t.reloadQueued=!1,t.isLocal()?T.CACHED:(t.defer(),T.RESOLVE_VALUES)):T.CACHED:(t.defer(),t.isLocal()?T.EXPAND_LOCAL:T.EXPAND)},t.prototype.fetchTitle=function(t,e,r,n){void 0===r&&(r=!0);var o=this.itemEntryService.getTitleField(t);return this.fetchItem(t,e,new U({columns:[o],deferRequest:r}),n).then(function(t){return t.getFields()[o]},this.errorHandler.reject)},t.prototype.createLocalEntries=function(t,e,r,n,o,i){var s=this;void 0===i&&(i=function(){return!0});var c=r.response,a={},u={},l=[],h=function(t,e,p){var f={itemType:t,itemId:e},d=c.items[t][p].links;for(var m in d)if(d.hasOwnProperty(m)){void 0===a[m]&&l.push({itemType:m,itemEntries:a[m]=[],columnSet:u[m]=s.columnSetFactory.construct(m,!0,r.responseColumns)});for(var y=0,v=d[m];y<v.length;y++){var g=v[y],C=n[m][g],I=s.itemEntryFactory.constructLocalLinked(m,C,c.fetchObject(m,g),f,u[m],n);i(I)&&(o.add(I),a[m].push(I),h(m,C,g))}}};return h(t,e,c.links[t][0]),l},t.prototype.expandLocalEntries=function(t,e,r,n,o){if(0===e.length)return this.promiseService.when(e);for(var i=this.columnExpansionFactory.construct(t,r,n),s=0,c=e;s<c.length;s++){var a=c[s],u=i.run(a.columns);null!==u&&a.expandLocal(u)}return this.resolveDerivedValues(e,i.aggregateRootColumns(),o)},t.prototype.resolveDerivedValues=function(t,e,r){for(var n=[],o=0,i=e;o<i.length;o++){var s=i[o];n.push(this.fetchDerivedValuesByColumn(t,s,r))}return this.promiseService.all(n).then(function(){return t},this.errorHandler.reject)},t.prototype.setDefaultValuesByColumn=function(t,e){var r=e.children;if(0!==r.length)for(var n=0,o=r;n<o.length;n++)for(var i=o[n],s=0,c=t;s<c.length;s++){c[s].derived[i.path]=this.apiFormatter.getDefaultValue(i.apiColumn.type)}},t.prototype.getItemIdByColumn=function(t,e){return 0===e.level?"link"===e.apiColumn.type&&null!==t.parent?t.parent.itemId:t.getFields()[e.path]:t.derived[e.path]},t.prototype.fetchDerivedValuesByColumn=function(t,e,r){var n=this,o=e.children;if(0===o.length)return this.promiseService.when();var i=o[0];if(1===o.length&&"id"===i.apiColumn.type){for(var s=0,c=t;s<c.length;s++){(h=c[s]).derived[i.path]=this.getItemIdByColumn(h,e)}return this.promiseService.when()}for(var a={},u=0,l=t;u<l.length;u++){var h=l[u],p=this.getItemIdByColumn(h,e);void 0===a[p]&&(a[p]=[]),a[p].push(h)}void 0!==a.null&&this.setDefaultValuesByColumn(a.null,e);var f=[];for(var p in a)"null"!==p&&f.push(+p);if(0===f.length)return this.promiseService.when();for(var d=[],m=0,y=o;m<y.length;m++){var v=y[m];d.push(v.id)}return this.fetchItems(e.itemType,f,new U({columns:d}),r).then(function(e){for(var i=0,s=e;i<s.length;i++)for(var c=s[i],u=c.getFields(),l=0,h=a[c.itemId];l<h.length;l++)for(var p=h[l],f=0,d=o;f<d.length;f++){var m=d[f];p.derived[m.path]=u[m.id]}return n.resolveDerivedValues(t,o,r)},this.errorHandler.reject)},t.prototype.requestItem=function(t,e){return void 0===e&&(e=t.columns.request),this.requestItems(t.itemType,[t.itemId],e)},t.prototype.requestItems=function(t,e,r){var n;return this.apiRequestService.query(t,{id:e},((n={})[t]=r,n))},t}(),wt=function(){function t(t,e,r,n,o,i,s,c){this.apiRequestService=t,this.errorHandler=e,this.itemHandler=r,this.columnExpansionFactory=n,this.columnSetFactory=o,this.itemEntryFactory=i,this.queryService=s,this.promiseService=c}return t.prototype.requestItem=function(t,e,r){var n,o=((n={})[t]=r,n);return this.apiRequestService.query(t,{id:e},o)},t.prototype.requestItems=function(t,e,r){var n;void 0===e&&(e=t.query.object),void 0===r&&(r=t.options.columns);var o=t.itemType;return this.apiRequestService.requestSkeleton({requestType:"query",itemType:o,columns:(n={},n[o]=r,n),query:e,limit:t.options.limit})},t.prototype.requestLinkItems=function(t,e,r,n,o){var i,s=((i={})[r]=o,i);return null===n?this.apiRequestService.query(t,{id:e},s):this.apiRequestService.query(r,this.queryService.addAndCondition(n,{linkedTo:t,query:{id:e}}),s)},t.prototype.processExpansion=function(t,e,r,n){for(var o=this.columnExpansionFactory.construct(r,t,e.fetchColumnsObject()),i=0,s=n;i<s.length;i++){var c=s[i];c.isLocal()||this.handleCachedItem(c,e,o)}return o},t.prototype.processResponse=function(t,e,r,n,o){var i=this;void 0===o&&(o=this.columnExpansionFactory.construct(n.itemType,!!n.requestColumnsTrue||n.request,n.response));for(var s=this.itemHandler,c=n.itemType,a=n.root,u=[],l=[],h=0,p=e;h<p.length;h++){var f=p[h],d=s.entries.get(c,f);void 0===d?(d=this.itemEntryFactory.construct(f,t.fetchObject(c,f),t.fetchDerivedObject(c,f,a),n),s.entries.add(d),u.push(d)):d.isDeferred()?d.deferRequest?u.push(d.resolveDeferred(t.fetchObject(c,f),t.fetchDerivedObject(c,f,a),n)):l.push(d.getPromise()):d.reloadQueued?(d.reloadQueued=!1,d.updateFields(t.fetchObject(c,f),t.fetchDerivedObject(c,f,a),!1),u.push(d)):u.push(this.handleCachedItem(d,t,o)),null!==r&&(d.parent=r)}return this.promiseService.all(l).then(function(e){for(var r=0,n=e;r<n.length;r++){var s=n[r];u.push(i.handleCachedItem(s,t,o))}return u},this.errorHandler.reject)},t.prototype.handleCachedItem=function(t,e,r){var n=r.run(t.columns);return null===n?t:t.expand(e.fetchObject(t.itemType,t.itemId),e.fetchDerivedObject(t.itemType,t.itemId,n.difference.root),n)},t.prototype.processLinkResponse=function(t,e,r,n,o){for(var i=t.fetchColumnsObject(),s=this.columnSetFactory.construct(n,o.columns,i),c=this.columnExpansionFactory.construct(n,o.columns,i),a=t.items[e],u={},l=0,p=r;l<p.length;l++){var f=p[l];u[f]=h(a,[f,"links",n])?this.processResponse(t,a[f].links[n],{itemType:e,itemId:f},s,c):[]}return this.promiseService.all(u).then(function(t){return{items:t,columns:s,columnExpansion:c}},this.errorHandler.reject)},t}(),Tt=function(){function t(){this.separator=":"}return t.prototype.getSingleKey=function(t,e){return t+this.separator+e},t.prototype.getCssKey=function(){return Array.prototype.join.call(arguments,"_")},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}();!function(t){t.Always="always",t.OnClose="onClose",t.SkipOnClose="skipOnClose"}(N||(N={}));var xt,At,jt,kt,Dt=function(){function t(t,e,r,n,o,i,s,c,a,u,l){this.changesProcessor=t,this.collectionCacheFactory=e,this.collectionResourceFactory=r,this.errorHandler=n,this.exceptionHandler=o,this.itemCacheFactory=i,this.itemResourceFactory=s,this.lockService=c,this.promiseService=a,this.id=u,this.defaultResourceLevel=l,this.tabRequestParameters={},this.isSaving=!1,this.callbacks={onBeforeSave:{always:{},onClose:{},skipOnClose:{}},onSaveSuccess:{always:{},onClose:{},skipOnClose:{}}},this.changesInterval=null,this.hasChanges=!1,this.items=this.itemCacheFactory.construct(),this.collections=this.collectionCacheFactory.construct(),this.deferredCollections=this.collectionCacheFactory.construct()}return t.prototype.createItemResource=function(t,e,r,n,o){return void 0===r&&(r=this.defaultResourceLevel),void 0===n&&(n=!1),n&&(this.rootItem=t),this.itemResourceFactory.construct(t,e,r,this,o)},t.prototype.createItemResources=function(t,e,r){void 0===r&&(r=this.defaultResourceLevel);for(var n=this.itemResourceFactory.getConstructor(e,r,this),o=[],i=0,s=t;i<s.length;i++){var c=s[i];o.push(n(c))}return o},t.prototype.createCollectionResource=function(t,e,r){return void 0===r&&(r=this.defaultResourceLevel),this.collectionResourceFactory.construct(t,e,r,this)},t.prototype.createCollectionResources=function(t,e,r){var n={};for(var o in t)n[o]=this.createCollectionResource(t[o],e,r);return n},t.prototype.clearItem=function(t){this.clearItemEntry(t.entry)},t.prototype.clearItemEntry=function(t){this.items.clear(t),this.itemResourceFactory.cache.clearEntry(t)},t.prototype.clearCollection=function(t){var e=t.entry;this.collections.clear(e),this.collectionResourceFactory.cache.clearEntry(e)},t.prototype.clearDeferredCollections=function(){this.deferredCollections.clear()},t.prototype.updateSingleItems=function(t){for(var e in t)for(var r in t[e]){var n=this.items.get(e,parseInt(r,10));void 0!==n&&this.items.updateItemId(n,parseInt(r,10))}},t.prototype.revertChanges=function(){var t=this;return this.items.forEach(function(t){return t.resetModified()}),this.collections.forEach(function(e){return t.resetCollection(e)}),this.hasChanges=!1,this.isLockable()?this.lockService.deleteLock(this.rootItem):this.promiseService.when()},t.prototype.resetCollection=function(t){if(t.items=t.initial.slice(),t.hasItemEditResources)for(var e=0,r=t.items;e<r.length;e++){r[e].resetModified()}},t.prototype.detectChanges=function(){var t=this;return!!this.hasChanges||(this.items.some(function(t){return t.hasChanges()})?this.hasChanges=!0:this.hasChanges=this.collections.some(function(e){return t.collectionHasChanges(e)}))},t.prototype.collectionHasChanges=function(t){return!(!t.hasEditResources||!t.hasAddedItems()&&!t.hasRemovedItems())||t.hasItemEditResources&&t.hasUpdatedItems()},t.prototype.isLockable=function(){return void 0!==this.rootItem&&this.rootItem.isLockable()},t.prototype.save=function(t,e,r,n){var 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.executeCallbackEvent(o.callbacks.onBeforeSave,function(t){return t(o)},t)},this.errorHandler.reject).then(function(){var t=m({},o.tabRequestParameters,e);return o.tabRequestParameters={},o.changesProcessor.execute(o.items.toArray(),o.collections.toArray(),t,r,n)},this.errorHandler.reject).then(function(e){return o.isLockable()&&o.lockService.clearLock(o.rootItem),o.hasChanges=!1,t||o.updateSingleItems(e),o.executeCallbackEvent(o.callbacks.onSaveSuccess,function(t){return t(o,e)},t).then(function(){return t||o.enableChangesWatcher(),o.isSaving=!1,e},o.errorHandler.reject)},this.errorHandler.reject).catch(function(t){return o.isSaving=!1,o.errorHandler.reject(t)}))},t.prototype.onBeforeSave=function(t,e,r){void 0===r&&(r=N.Always);var n=this.callbacks.onBeforeSave[r];return n[t]=e,function(){return delete n[t]}},t.prototype.onSaveSuccess=function(t,e,r){void 0===r&&(r=N.Always);var n=this.callbacks.onSaveSuccess[r];return n[t]=e,function(){return delete n[t]}},t.prototype.executeCallbackEvent=function(t,e,r){var n=this;return this.executeCallbacks(t[N.Always],e).then(function(){return n.executeCallbacks(t[r?N.OnClose:N.SkipOnClose],e)},this.errorHandler.reject)},t.prototype.executeCallbacks=function(t,e){var r={};for(var n in t)try{r[n]=e(t[n])}catch(t){this.exceptionHandler(t)}return this.promiseService.all(r)},t.prototype.enableChangesWatcher=function(){var t=this;null!==this.changesInterval&&(console.warn("Changes watcher already running!",this),this.disableChangesWatcher()),this.changesInterval=setInterval(function(){t.detectChanges()&&(t.disableChangesWatcher(),t.isLockable()&&t.lockService.fetchLock(t.rootItem))},3e3)},t.prototype.disableChangesWatcher=function(){null!==this.changesInterval&&(clearInterval(this.changesInterval),this.changesInterval=null)},t.prototype.onDeactivateItem=function(t){this.clearItemEntry(t)},t.prototype.onActivateItem=function(t){this.items.add(t)},t}(),Ht=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.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.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 o=e[r][n];if(!o.isForeign&&o.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,o=this.apiRequestService.create("Locktoken",this.keyService.getLocalId(),{itemtype:r,item:n}).then(function(o){return delete e.promises[r][n],e.setValue(t,o.fetchObject("Locktoken",o.links.Locktoken[0]),e.lockItems)},function(o){return delete e.promises[r][n],301===o.code?e.setValue(t,{isForeign:!0,message:o.message},e.lockItems):e.errorHandler.reject(o)});return this.setValue(t,o,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}(),Pt={},_t=function(){function t(t,e,r){this.rootItemEntry=t,this.singleItemCache=e,this.collectionCache=r,this.parentMap={},this.destination={}}return t.prototype.process=function(){return this.parentMap=this.createParentMap(this.singleItemCache),this.processItems(this.rootItemEntry.itemType,[this.rootItemEntry],{}),{itemType:this.rootItemEntry.itemType,itemId:this.rootItemEntry.itemId,items:this.destination}},t.prototype.createParentMap=function(t){var e={};return t.forEach(function(t){var r=t.itemType,n=t.parent;if(null!==n){var o=n.itemType,i=n.itemId;void 0===e[o]&&(e[o]={}),void 0===e[o][i]&&(e[o][i]={}),void 0===e[o][i][r]&&(e[o][i][r]=[]),e[o][i][r].push(t)}}),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,o=e;n<o.length;n++){var i=o[n],s=i.itemId;void 0===this.destination[t][s]&&(r[t].push(s),this.destination[t][s]=this.processItem(i))}},t.prototype.processItem=function(t){var e=t.itemType,r=t.itemId,n=this.getItemsByParent(e,r),o=this.collectionCache.getCollectionsByParent(e,r),i=t.formatRequest(),c={};for(var a in n)this.processItems(a,n[a],c);for(var u=0,l=o;u<l.length;u++){var h=l[u];null===h.options.query&&this.processItems(h.itemType,h.items,c)}var p=s(i),f=s(c);return p&&f?{values:i,links:c}:p?{values:i}:f?{links:c}:Pt},t.prototype.getItemsByParent=function(t,e){var r=this.parentMap[t];return void 0===r?{}:void 0===r[e]?{}:r[e]},t}(),Vt="maybe",Nt=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 Vt;if(void 0!==t.custom)return Vt;if(void 0!==t.linkedTo)return this.matchLinkedToQuery(t);if(void 0!==t.query)return Vt;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 Vt;var e,r=this.parent;return(e=null!==r&&(t.linkedTo===r.itemType&&this.matchSimpleQuery(r.itemId,t.query)))===Vt?Vt: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 o=0,i=n;o<i.length;o++){var s=i[o],c=this.matchQuery(s);if(c===r)return t.not?!r:r;c===Vt&&(e=Vt)}return e===Vt?Vt:t.not?!e:e},t.prototype.matchSimpleQuery=function(t,e){var r=e.key,o=e.value;if(!s(e))return!0;if(void 0===t)return console.warn("Required field",r,"not found for",this.itemType),Vt;switch("NOW"===o&&(o=n()),e.comparator){case"=":return this.compareValues(t,o);case"!=":return!this.compareValues(t,o);case"<":return t<o;case"<=":return t<=o;case">":return t>o;case">=":return t>=o;case"IN":var i=a(t,o);return e.not?!i:i;default:throw new Error("queryMatcher: Unsupported comparator: "+e.comparator+" in query "+e)}},t}();!function(t){t[t.OBJ=0]="OBJ",t[t.STR=1]="STR",t.SEP=":"}(At||(At={})),function(t){t.OR="OR",t.AND="AND"}(jt||(jt={})),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"}(kt||(kt={}));var Bt=Object.keys(kt).map(function(t){return kt[t]}),Ut=((xt={})[kt.EQUALS]=kt.NOT_EQUALS,xt[kt.NOT_EQUALS]=kt.EQUALS,xt[kt.MORE_THAN]=kt.LESS_OR_EQUAL_THAN,xt[kt.LESS_THAN]=kt.EQUAL_OR_MORE_THAN,xt[kt.LESS_OR_EQUAL_THAN]=kt.MORE_THAN,xt[kt.EQUAL_OR_MORE_THAN]=kt.LESS_THAN,xt[kt.IN]=kt.IN,xt),Qt=function(){function t(t,e){this.query=t,this.parameters=e}return t.prototype.compareParsedQueries=function(t,e){return t[At.STR]===e[At.STR]?0:t[At.STR]>e[At.STR]?1:-1},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=c(t);if(null===e)return[{},"{}"];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.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+"]"]},t.prototype.parseSubFieldQuery=function(t,e,r,n,o){void 0===t&&(t=""),void 0===e&&(e=""),void 0===r&&(r=""),void 0===o&&(o=!1);var i=this.parse(n);return[{key:t,itemType:e,field:r,query:i[At.OBJ],not:o},"[subField"+At.SEP+t+At.SEP+e+At.SEP+r+At.SEP+i[At.STR]+At.SEP+o+"]"]},t.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+"]"]},t.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+"]"]},t.prototype.parseCustomParameters=function(t){for(var e=Object.keys(t).sort(),r={},n="",o=0;o<e.length;o++){var i=e[o],s=this.formatValue(t[i]);r[i]=s[At.OBJ],o>0&&(n+=At.SEP),n+=s[At.STR]}return[r,n]},t.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])?kt.IN:kt.EQUALS),-1===Bt.indexOf(r))throw new Error("Unknown comparator '"+r+"', it might be that the backend supports it but the frontend doesn't !");n&&(r=Ut[r]);var o=r===kt.IN&&n,i=[{key:t,value:e[At.OBJ],comparator:r,not:o},"["+r+At.SEP+t+At.SEP+e[At.STR]+"]"];return o&&(i[1]=i[1].slice(0,-1),i[1]+=At.SEP+n+"]"),i},t.prototype.parseLinkedToQuery=function(t,e,r,n){void 0===e&&(e={}),void 0===r&&(r=!1),void 0===n&&(n=!1);var o=this.parse(e);return[{linkedTo:t,query:o[At.OBJ],reverse:r,not:n},"[linkedTo"+At.SEP+t+At.SEP+o[At.STR]+At.SEP+r+At.SEP+n+"]"]},t.prototype.parseComplexQuery=function(t,e,r){void 0===e&&(e=jt.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+"]"]},t.prototype.parseConditions=function(t){for(var e=this,r=[],n=[],o="",i=0,s=t;i<s.length;i++){var c=s[i];r.push(this.parse(c))}for(var a=0,u=r=r.sort(function(t,r){return e.compareParsedQueries(t,r)});a<u.length;a++){var l=u[a];n.push(l[At.OBJ]),o+=l[At.STR]}return[n,o]},t.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]},t.prototype.processValue=function(t){return Array.isArray(t)?t.slice().sort():n.isMoment(t)?n(t):n.isDuration(t)?n.duration(t):t},t}(),Yt=function(){function t(){}return t.prototype.addAndCondition=function(t,e){return void 0===t.conditions||t.operator===jt.OR?{conditions:[t,e]}:{conditions:t.conditions.concat(e)}},t.prototype.addOrCondition=function(t,e){return t.operator===jt.OR?{conditions:t.conditions.concat(e)}:{conditions:[t,e],operator:jt.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:kt.IN,key:"id",value:t,not:!0}},t}(),Xt=function(){function t(){this.cache=[]}return t.prototype.set=function(t,e){var r=t.entry.id,n=this.getCacheLevel(e)[1];return void 0===n[r]&&(n[r]=[]),n[r].push(t),t},t.prototype.getCacheLevel=function(t){for(var e=this.cache,r=e.length-1;r>=0;r--){var n=e[r];if(n[0]===t)return n;if(n[0]<t)return this.createCacheLevel(r+1,t)}return this.createCacheLevel(0,t)},t.prototype.createCacheLevel=function(t,e){var r=[e,{}];return this.cache.splice(t,0,r),r},t.prototype.hasResources=function(t){for(var e=this.cache,r=e.length-1;r>=0;r--)if(void 0!==e[r][1][t.id])return!0;return!1},t.prototype.get=function(t){for(var e=[],r=0,n=this.cache;r<n.length;r++){var o=n[r][1][t.id];if(void 0!==o)for(var i=0,s=o;i<s.length;i++){var c=s[i];e.push(c)}}return e},t.prototype.getLatest=function(t){for(var e=this.cache,r=e.length-1;r>=0;r--){var n=e[r][1][t.id];if(void 0!==n)return n[n.length-1]}return null},t.prototype.clearResource=function(t){for(var e=this.cache,r=t.entry.id,n=-1,o=e.length;-1===n&&o>0;){var i=e[--o][1][r];void 0!==i&&(n=i.indexOf(t))}if(-1===n)return!1;var s=e[o][1];return 1===s[r].length?delete s[r]:s[r].splice(n,1),!0},t.prototype.clearResources=function(t){for(var e=this.cache,r=e.length;r>0&&e[r-1][0]>=t;)r--;e.length=r},t.prototype.clearEntry=function(t){for(var e=0,r=this.cache;e<r.length;e++){delete r[e][t.id]}},t}(),Wt=function(){function t(t){this.columnUtil=t,this.columns={},this.columnSetIdMap={}}return 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}(),Jt=function(){function t(t,e,r,n,o,i,s,c,a,u,l){this.apiFormatter=t,this.apiRequestService=e,this.collectionHandler=r,this.columnExpansionFactory=n,this.columnSetFactory=o,this.errorHandler=i,this.itemEntryFactory=s,this.itemHandler=c,this.localCacheManager=a,this.promiseService=u,this.requestColumnExpansionFactory=l}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.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={};for(var o in e){var i=e[o],s=null!==i.parent?i.parent:{};n[o]=this.collectionHandler.entries.getByFittingItem(t,this.formatMessageValues(i.values,r),s)}return n},t.prototype.groupByCollectionId=function(t,e){var r={};for(var n in e){var o=e[n];for(var i in o)for(var s=0,c=o[i];s<c.length;s++){var a=c[s],u=a.id;void 0===r[u]&&(r[u]={collection:a,fitting:[],notfitting:[],maybe:[]}),r[u][i].push("fitting"===i?this.itemHandler.entries.get(t,n):n)}}return r},t.prototype.getRequestColumns=function(t,e){var r=this.requestColumnExpansionFactory.construct();for(var n in e){for(var o=e[n].fitting,i=this.itemHandler.entries.get(t,n),s=0,c=o;s<c.length;s++){var a=c[s];r.expand(a.columns)}void 0!==i&&r.expand(i.columns)}return r.get()},t.prototype.deferEntry=function(t){var e=t.deferred;return void 0===e?t.defer():e.promise.then(this.deferEntry.bind(this),this.errorHandler.reject)},t.prototype.processMessage=function(t){var e=this,r=t.itemType,n=this.createCollectionMap(r,t.items[r],t.columns[r]),o=this.getRequestColumns(r,n),i=[],s=[];for(var c in n){var a=this.itemHandler.entries.get(r,c),u=+c;void 0===a?0!==n[u].fitting.length&&(this.itemHandler.entries.add(this.itemEntryFactory.constructDeferred(r,u,o[r],!1)),s.push(u)):(i.push(this.deferEntry(a)),s.push(u))}return 0===s.length?this.promiseService.when(this.groupByCollectionId(r,n)):this.promiseService.all(i).then(function(){return e.apiRequestService.query(r,{id:s},o)},this.errorHandler.reject).then(function(t){return e.handleResponse(r,s,o[r],t,n)},this.errorHandler.reject)},t.prototype.processFunctionChangesResolve=function(t){var e=this,r=t.items.FunctionChangesResolve,n=[],o=[];for(var i in r){var s=r[i].parent.itemId,c=this.itemHandler.entries.get("Functie",s);void 0!==c&&void 0!==c.columns.response.Functie.newchanges&&(n.push(this.deferEntry(c)),o.push(s))}return 0===o.length?this.promiseService.when():this.promiseService.all(n).then(function(){return e.apiRequestService.query("Functie",{id:o},{Functie:["newchanges"]})},this.errorHandler.reject).then(function(t){for(var r=0,n=t.links.Functie;r<n.length;r++){var o=n[r],i=e.itemHandler.entries.get("Functie",o),s=e.apiFormatter.copyFields(i.getFields(),{},i.columns.main),c=t.fetchValue("Functie",o,"newchanges");c!==s.newchanges&&i.setInitial({newchanges:c},!0).callOnChange(s).resolve()}},this.errorHandler.reject).catch(this.errorHandler.notifyError)},t.prototype.handleResponse=function(t,e,r,n,o){for(var i=n.fetchColumnsObject(),s=this.columnSetFactory.construct(t,r,i),c=this.columnExpansionFactory.construct(t,r,i),a=0,u=e;a<u.length;a++){var l=u[a],h=this.itemHandler.entries.get(t,l),p=void 0===h.initial,f=n.fetchObject(t,l);if(void 0!==f){var d=n.fetchDerivedObject(t,l,s.root);if(p)h.resolveDeferred(f,d,s);else{var m=c.run(h.columns),y=this.apiFormatter.copyFields(h.getFields(),{},h.columns.main);null!==m&&h.expand(f,d,m),h.updateFields(f,d,!1).callOnChange(y).resolve()}}else h.reject(),p&&this.itemHandler.entries.clear(h),delete o[l]}return this.groupByCollectionId(t,o)},t.prototype.isFunctionChangesResolveMessage=function(t){return"FunctionChangesResolve"===t.body.itemType},t.prototype.handleCreate=function(t){var e=this,r=t.body;return this.isFunctionChangesResolveMessage(t)?this.processFunctionChangesResolve(r):this.processMessage(r).then(function(t){return e.collectionHandler.addToCollections(t,!0)},this.errorHandler.reject).catch(this.errorHandler.notifyError)},t.prototype.handleUpdate=function(t){var e=this;return this.processMessage(t.body).then(function(t){return e.collectionHandler.removeFromAndAddToCollections(t)},this.errorHandler.reject).catch(this.errorHandler.notifyError)},t.prototype.handleDelete=function(t){for(var e=t.body,r=e.itemType,n=this.localCacheManager.getAllLocalCaches(),o={},i=0,s=e.items;i<s.length;i++){for(var c=s[i],a=0,u=this.collectionHandler.entries.getByContainingItem(r,c);a<u.length;a++){var l=u[a];void 0===o[f=l.id]&&(o[f]={collection:l,items:[]}),o[f].items.push(c)}this.itemHandler.entries.clearByItemId(r,c);for(var h=0,p=n;h<p.length;h++){p[h].items.clearByItemId(r,c)}}for(var f in o){var d=o[f];d.collection.removeItems(d.items,null,!0)}return this.promiseService.when()},t.prototype.handleLinkMove=function(){return this.promiseService.when()},t}(),Kt=function(){function t(t){this.apiFormatter=t}return t.prototype.construct=function(t){return new j(this.apiFormatter,t)},t}(),zt=function(){function t(t){this.promiseService=t}return t.prototype.construct=function(t,e,r){return new H(this.promiseService,t,e,r)},t}(),Gt=function(){function t(t,e){this.collectionCacheFactory=t,this.keyService=e}return t.prototype.construct=function(t,e){return new P(this.collectionCacheFactory,this.keyService,t,e)},t}(),Zt=function(){function t(t,e){this.collectionResourceFactory=t,this.queryMatcherFactory=e}return t.prototype.construct=function(){return new B(this.collectionResourceFactory,this.queryMatcherFactory)},t}(),$t=function(){function t(t,e,r,n,o,i,s,c,a,u,l,h,p,f){this.collectionEntryService=t,this.collectionResourceFactory=e,this.columnExpansionFactory=r,this.columnHandler=n,this.columnSetFactory=o,this.errorHandler=i,this.exceptionHandler=s,this.itemEntryFactory=c,this.itemEntryService=a,this.itemHandler=u,this.itemRequestService=l,this.keyService=h,this.promiseService=p,this.queryService=f}return t.prototype.construct=function(t,e){return new et(this,t,new Z(e))},t}(),te=function(){function t(t){this.queryMatcherFactory=t}return t.prototype.construct=function(t,e,r,n){return new dt(this.queryMatcherFactory,t,e,r,n)},t}(),ee=function(){function t(t,e,r,n,o,i){this.errorHandler=t,this.exceptionHandler=e,this.itemResourceFactory=r,this.changesProcessor=n,this.keyService=o,this.promiseService=i,this.cache=new Xt}return t.prototype.construct=function(t,e,r,n){void 0===n&&(n=null);var o=new $(e);return o.editItems&&(t.hasItemEditResources=!0),o.editCollection?(t.hasEditResources=!0,this.cache.set(new st(this,t,o,r,n),r)):this.cache.set(new ot(this,t,o,r,n),r)},t}(),re=function(){function t(t){this.columnInfoFactory=t}return t.prototype.construct=function(t,e,r){return new vt(this.columnInfoFactory,t,e,r)},t}(),ne=function(){function t(){}return t.prototype.construct=function(t,e){return new Ct(t,e)},t.prototype.constructFromRootMap=function(t,e){void 0===e&&(e=null);var r=[];for(var n in t){var o=t[n],i=this.construct(o.apiColumn,e),s=this.constructFromRootMap(o.children,i);s.length>0&&i.setChildren(i.apiColumn.itemType,s),r.push(i)}return r},t}(),oe=function(){function t(t,e,r){this.columnHandler=t,this.columnUtil=e,this.columnInfoFactory=r}return t.prototype.constructStub=function(t,e){return new Rt(this.columnHandler,this.columnUtil,this.columnInfoFactory,this,t,e)},t.prototype.construct=function(t,e,r,n,o){return this.constructStub(t,e).resolve(r,n,o)},t}(),ie=function(){function t(){}return t.prototype.construct=function(t){return new Et(t)},t}(),se=function(){function t(t,e,r,n){this.collectionHandler=t,this.collectionMatcherFactory=e,this.keyService=r,this.requestColumnExpansionFactory=n}return t.prototype.construct=function(t,e,r,n){return new qt(this.collectionHandler,this.collectionMatcherFactory,this.keyService,this.requestColumnExpansionFactory,t,e,r,n)},t}(),ce=function(){function t(t){this.queryMatcherFactory=t}return t.prototype.construct=function(){return new Ot(this.queryMatcherFactory)},t}(),ae=function(){function t(t,e,r,n,o,i,s,c){this.authInterface=t,this.apiFormatter=e,this.columnSetFactory=r,this.exceptionHandler=n,this.itemEntryService=o,this.itemResourceFactory=i,this.keyService=s,this.promiseService=c}return t.prototype.constructStub=function(t,e,r){return new X(this,t,e,r)},t.prototype.constructLocalLinked=function(t,e,r,n,o,i){var s=this.constructStub(t,e,o);return s.parent=n,s.setLocalFields(r,i)},t.prototype.constructLocal=function(t,e,r,n,o,i,s){void 0===o&&(o=null),void 0===i&&(i=e.columns);var c=e.columns.itemType;void 0===s&&(s=this.itemEntryService.createLocalConversionMap(c,t,!0,e.response));var a=this.constructStub(c,t,i);return a.parent=o,a.setLocalFields(e.fields,s,e.columns).setModified(r).setDerived(n)},t.prototype.constructDeferred=function(t,e,r,n){var o=this.constructStub(t,e,this.columnSetFactory.constructStub(t,r));return o.defer(n),o},t.prototype.construct=function(t,e,r,n){return this.constructStub(n.itemType,t,n).setFields(e,r)},t}(),ue=function(){function t(t,e,r,n,o){this.apiFormatter=t,this.lockService=e,this.changesProcessor=r,this.errorHandler=n,this.promiseService=o,this.cache=new Xt}return t.prototype.getConstructor=function(t,e,r){var n=this,o=new Q(t);return function(t){return n.constructWithOptions(t,o,e,r)}},t.prototype.construct=function(t,e,r,n,o){return this.constructWithOptions(t,new Q(e),r,n,o)},t.prototype.constructWithOptions=function(t,e,r,n,o){return void 0===n&&(n=null),void 0===o&&(o=!1),this.cache.set(e.edit?new G(this,t,e,o,n):e.remote?new ut(this,t,e,o,n):new ht(this,t,e,o,n),r)},t}(),le=function(){function t(t,e,r,n,o,i,s,c,a){this.changesProcessor=t,this.collectionCacheFactory=e,this.collectionResourceFactory=r,this.errorHandler=n,this.exceptionHandler=o,this.itemCacheFactory=i,this.itemResourceFactory=s,this.lockService=c,this.promiseService=a}return t.prototype.construct=function(t,e){return new Dt(this.changesProcessor,this.collectionCacheFactory,this.collectionResourceFactory,this.errorHandler,this.exceptionHandler,this.itemCacheFactory,this.itemResourceFactory,this.lockService,this.promiseService,t,e)},t}(),he=function(){function t(){}return t.prototype.construct=function(t,e,r){return new _t(t,e,r)},t}(),pe=function(){function t(t){this.apiFormatter=t}return t.prototype.construct=function(t,e,r){return new Nt(this.apiFormatter,t,e,r)},t}(),fe=function(){function t(){}return t.prototype.construct=function(t,e){return new Qt(t,e)},t}(),de=function(){function t(t){this.columnUtil=t}return t.prototype.construct=function(){return new Wt(this.columnUtil)},t}(),me=function(){function t(t,e){this.columnSetFactory=t,this.columnUtil=e}return t.prototype.construct=function(t,e,r){return new ct(this,t,e,r)},t}(),ye=function(){return function(t,e,r,n,o,i){this.noop=ve,this.version="1.7.0",this.apiFormatter=new x,this.apiResponseProcessorFactory=new Kt(this.apiFormatter),this.apiRequestService=new A(t,this.apiResponseProcessorFactory),this.batchStatusFactory=new zt(i),this.keyService=new Tt,this.queryMatcherFactory=new pe(this.apiFormatter),this.queryParserFactory=new fe,this.queryService=new Yt,this.columnUtil=new Ft,this.columnCache=new yt(this.columnUtil),this.columnHandler=new gt(this.apiRequestService,r,i,this.columnCache,this.columnUtil),this.columnInfoFactory=new ne,this.columnExpansionFactory=new re(this.columnInfoFactory),this.columnSetFactory=new oe(this.columnHandler,this.columnUtil,this.columnInfoFactory),this.columnSubsetCacheFactory=new ie,this.lockService=new Ht(this.apiRequestService,r,this.keyService,i),this.templateFactory=new me(this.columnSetFactory,this.columnUtil),this.itemEntryService=new Lt(e,this.keyService),this.itemCacheFactory=new ce(this.queryMatcherFactory),this.itemResourceFactory=new ue(this.apiFormatter,this.lockService,this.changesProcessor,r,i),this.collectionResourceFactory=new ee(r,n,this.itemResourceFactory,this.changesProcessor,this.keyService,i),this.itemEntryFactory=new ae(e,this.apiFormatter,this.columnSetFactory,n,this.itemEntryService,this.itemResourceFactory,this.keyService,i),this.collectionEntryService=new pt(this.queryParserFactory,this.queryService),this.collectionResourceService=new mt,this.itemHandler=new Mt(this.apiFormatter,this.apiRequestService,this.batchStatusFactory,this.columnExpansionFactory,this.columnHandler,this.columnSetFactory,this.columnSubsetCacheFactory,this.columnUtil,r,this.itemCacheFactory,this.itemEntryFactory,this.itemEntryService,this.keyService,i,this.templateFactory),this.itemRequestService=new wt(this.apiRequestService,r,this.itemHandler,this.columnExpansionFactory,this.columnSetFactory,this.itemEntryFactory,this.queryService,i),this.collectionEntryFactory=new $t(this.collectionEntryService,this.collectionResourceFactory,this.columnExpansionFactory,this.columnHandler,this.columnSetFactory,r,n,this.itemEntryFactory,this.itemEntryService,this.itemHandler,this.itemRequestService,this.keyService,i,this.queryService),this.collectionCacheFactory=new Zt(this.collectionResourceFactory,this.queryMatcherFactory),this.collectionMatcherFactory=new te(this.queryMatcherFactory),this.collectionHandler=new ft(this.batchStatusFactory,this.collectionCacheFactory,this.collectionEntryFactory,this.collectionEntryService,this.collectionMatcherFactory,this.columnHandler,this.columnSetFactory,r,this.itemHandler,this.itemRequestService,this.keyService,i,this.queryParserFactory,this.queryService),this.changesCompilationFactory=new Gt(this.collectionCacheFactory,this.keyService),this.changesProcessor=new _(this.apiFormatter,this.apiRequestService,this.changesCompilationFactory,this.collectionEntryService,this.collectionHandler,this.columnExpansionFactory,this.createRequestFactory,r,this.itemHandler,i,this.requestColumnExpansionFactory),this.requestColumnExpansionFactory=new de(this.columnUtil),this.createRequestFactory=new se(this.collectionHandler,this.collectionMatcherFactory,this.keyService,this.requestColumnExpansionFactory),this.localCacheFactory=new le(this.changesProcessor,this.collectionCacheFactory,this.collectionResourceFactory,r,n,this.itemCacheFactory,this.itemResourceFactory,this.lockService,i),this.moduleChangesCompilationFactory=new he,this.itemAdministrator=new bt(this.apiRequestService,e,this.collectionHandler,this.collectionMatcherFactory,this.collectionResourceFactory,this.columnSetFactory,r,this.itemHandler,this.itemRequestService,this.itemResourceFactory,this.keyService,o,this.moduleChangesCompilationFactory,i,this.queryService),this.socketMessageHandler=new Jt(this.apiFormatter,this.apiRequestService,this.collectionHandler,this.columnExpansionFactory,this.columnSetFactory,r,this.itemEntryFactory,this.itemHandler,o,i,this.requestColumnExpansionFactory)}}();function ve(){}function ge(t){return t}r.d(e,"RmCore",function(){return ye}),r.d(e,"noop",function(){return ve}),r.d(e,"identity",function(){return ge}),r.d(e,"ENTRY_STATUS",function(){return T}),r.d(e,"ALL_PERMISSIONS",function(){return"7"}),r.d(e,"COLUMN_SEPERATOR",function(){return D}),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 U}),r.d(e,"ItemResourceOptions",function(){return Q}),r.d(e,"ItemEntry",function(){return X}),r.d(e,"ItemResource",function(){return W}),r.d(e,"ViewResource",function(){return K}),r.d(e,"EditResource",function(){return G}),r.d(e,"CollectionEntryOptions",function(){return Z}),r.d(e,"CollectionResourceOptions",function(){return $}),r.d(e,"CollectionEntry",function(){return et}),r.d(e,"CollectionResource",function(){return rt}),r.d(e,"CollectionViewResource",function(){return ot}),r.d(e,"CollectionEditResource",function(){return st}),r.d(e,"Template",function(){return ct}),r.d(e,"RemoteViewResource",function(){return ut}),r.d(e,"LocalViewResource",function(){return ht}),r.d(e,"ApiFormatter",function(){return x}),r.d(e,"ApiRequestService",function(){return A}),r.d(e,"ApiResponseProcessor",function(){return j}),r.d(e,"BatchStatus",function(){return H}),r.d(e,"ChangesCompilation",function(){return P}),r.d(e,"ChangesProcessor",function(){return _}),r.d(e,"CollectionCache",function(){return B}),r.d(e,"CollectionEntryService",function(){return pt}),r.d(e,"CollectionHandler",function(){return ft}),r.d(e,"CollectionMatcher",function(){return dt}),r.d(e,"CollectionResourceService",function(){return mt}),r.d(e,"ColumnCache",function(){return yt}),r.d(e,"ColumnExpansion",function(){return vt}),r.d(e,"ColumnHandler",function(){return gt}),r.d(e,"ColumnInfo",function(){return Ct}),r.d(e,"ColumnSet",function(){return Rt}),r.d(e,"ColumnSubsetCache",function(){return Et}),r.d(e,"ColumnUtil",function(){return Ft}),r.d(e,"CreateRequest",function(){return qt}),r.d(e,"ItemAdministrator",function(){return bt}),r.d(e,"ItemCache",function(){return Ot}),r.d(e,"ItemEntryService",function(){return Lt}),r.d(e,"ItemHandler",function(){return Mt}),r.d(e,"ItemRequestService",function(){return wt}),r.d(e,"KeyService",function(){return Tt}),r.d(e,"LocalCache",function(){return Dt}),r.d(e,"LockService",function(){return Ht}),r.d(e,"ModuleChangesCompilation",function(){return _t}),r.d(e,"QueryMatcher",function(){return Nt}),r.d(e,"OPERATORS",function(){return jt}),r.d(e,"COMPARATORS",function(){return kt}),r.d(e,"QueryParser",function(){return Qt}),r.d(e,"QueryService",function(){return Yt}),r.d(e,"ResourceCache",function(){return Xt}),r.d(e,"RequestColumnExpansion",function(){return Wt}),r.d(e,"SocketMessageHandler",function(){return Jt}),r.d(e,"instantiateOptions",function(){return o}),r.d(e,"shallowMerge",function(){return i}),r.d(e,"hasProperties",function(){return s}),r.d(e,"getFirstProperty",function(){return c}),r.d(e,"inArray",function(){return a}),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 f}),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 S}),r.d(e,"isArray",function(){return R}),r.d(e,"isFunction",function(){return E}),r.d(e,"isRegExp",function(){return F}),r.d(e,"isBoolean",function(){return q}),r.d(e,"isElement",function(){return b}),r.d(e,"isWindow",function(){return O}),r.d(e,"isDefined",function(){return L}),r.d(e,"equals",function(){return M}),r.d(e,"copy",function(){return w}),r.d(e,"ApiResponseProcessorFactory",function(){return Kt}),r.d(e,"BatchStatusFactory",function(){return zt}),r.d(e,"ChangesCompilationFactory",function(){return Gt}),r.d(e,"CollectionCacheFactory",function(){return Zt}),r.d(e,"CollectionEntryFactory",function(){return $t}),r.d(e,"CollectionMatcherFactory",function(){return te}),r.d(e,"CollectionResourceFactory",function(){return ee}),r.d(e,"ColumnExpansionFactory",function(){return re}),r.d(e,"ColumnInfoFactory",function(){return ne}),r.d(e,"ColumnSetFactory",function(){return oe}),r.d(e,"ColumnSubsetCacheFactory",function(){return ie}),r.d(e,"CreateRequestFactory",function(){return se}),r.d(e,"ItemCacheFactory",function(){return ce}),r.d(e,"ItemEntryFactory",function(){return ae}),r.d(e,"ItemResourceFactory",function(){return ue}),r.d(e,"LocalCacheFactory",function(){return le}),r.d(e,"ModuleChangesCompilationFactory",function(){return he}),r.d(e,"QueryMatcherFactory",function(){return pe}),r.d(e,"QueryParserFactory",function(){return fe}),r.d(e,"RequestColumnExpansionFactory",function(){return de}),r.d(e,"TemplateFactory",function(){return me}),r.d(e,"LocalCacheCallbackCondition",function(){return N})}])});
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 o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.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 o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));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 o(t,e){for(var r in e)r in t&&void 0!==e[r]&&(t[r]=e[r])}function i(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 c(t){if("object"!=typeof t)return null;for(var e in t)return e;return null}function a(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,o=t;n<o.length;n++){var i=o[n];e(i)&&r.push(i)}if(r.length===t.length)return!1;l(t);for(var s=0,c=r;s<c.length;s++){var a=c[s];t.push(a)}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 o=n[r];if(void 0===t[o])return!1;t=t[o]}return!0}function p(t,e,r){for(var n=0;n<e.length;n++){var o=e[n];void 0===t[o]&&(t[o]=r[n]),t=t[o]}return t}function f(t,e,r){if(void 0===r&&(r=!1),void 0!==t){for(var n=0,o=e;n<o.length;n++){if(void 0===(t=t[o[n]])&&!r)return}return t}}function d(t,e,r){for(var n=0,o=e.length;n<o;++n){var i=e[n];if(v(i)||E(i))for(var s=Object.keys(i),c=0,a=s.length;c<a;c++){var u=s[c],l=i[u];r&&v(l)?S(l)?t[u]=new Date(l.valueOf()):F(l)?t[u]=new RegExp(l):l.nodeName?t[u]=l.cloneNode(!0):b(l)?t[u]=l.clone():(v(t[u])||(t[u]=R(l)?[]:{}),d(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 d(t,e,!1)}function y(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];return d(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 S(t){return"[object Date]"===toString.call(t)}var R=Array.isArray;function E(t){return"function"==typeof t}function F(t){return"[object RegExp]"===toString.call(t)}function q(t){return"boolean"==typeof t}function b(t){return!(!t||!(t.nodeName||t.prop&&t.attr&&t.find))}function O(t){return t&&t.window===t}function L(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,o,i,s,c=typeof t;if(c===typeof e&&"object"===c){if(!R(t)){if(S(t))return!!S(e)&&(i=t.getTime(),s=e.getTime(),i===s||i!=i&&s!=s);if(F(t))return!!F(e)&&t.toString()===e.toString();if(O(t)||O(e)||R(e)||S(e)||F(e))return!1;for(n in o=Object.create(null),t)if(!E(t[n])){if(!M(t[n],e[n]))return!1;o[n]=!0}for(n in e)if(!(n in o)&&L(e[n])&&!E(e[n]))return!1;return!0}if(!R(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 w(t,e,r){var n=[],o=[];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(R(e))e.length=0;else for(var i in e)delete e[i];return n.push(t),o.push(e),s(t,e,r)}return c(t,r);function s(t,e,r){if(--r<0)return"...";if(R(t))for(var n=0,o=t.length;n<o;n++)e.push(c(t[n],r));else if(g(t))for(var i in t)e[i]=c(t[i],r);else if(t&&"function"==typeof t.hasOwnProperty)for(var i in t)t.hasOwnProperty(i)&&(e[i]=c(t[i],r));else for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=c(t[i],r));return e}function c(t,e){if(void 0===e&&(e=5),!v(t))return t;var r=n.indexOf(t);if(-1!==r)return o[r];if(O(t))throw new Error("Can't copy! Making copies of Window instances is not supported.");var i=!1,a=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(c(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(E(t.cloneNode))return t.cloneNode(!0)}(t);return void 0===a&&(a=R(t)?[]:Object.create(Object.getPrototypeOf(t)),i=!0),n.push(t),o.push(a),i?s(t,a,e):a}}var T,x=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.formatResponse=function(t,e){for(var r=0,n=e;r<n.length;r++){var o=n[r];t[o.path]=this.formatResponseValue(o.apiColumn.type,t[o.path])}return t},t.prototype.expandResponse=function(t,e,r){for(var n=0,o=r;n<o.length;n++){var i=o[n];t[i.path]=this.formatResponseValue(i.apiColumn.type,e[i.path])}return t},t.prototype.formatRequest=function(t,e,r){for(var n={},o=0,i=r;o<i.length;o++){var s=i[o],c=s.id,a=s.apiColumn,u=a.type;a.readOnly||(this.compareFields(u,t[c],e[c])||(n[c]=this.formatRequestValue(u,e[c])))}return n},t.prototype.formatRequestLocal=function(t,e){for(var r={},n=0,o=e;n<o.length;n++){var i=o[n],s=i.id,c=i.apiColumn;c.readOnly||(r[s]=this.formatRequestValue(c.type,t[s]))}return r},t.prototype.hasChanges=function(t,e,r){for(var n=0,o=r;n<o.length;n++){var i=o[n],s=i.id,c=i.apiColumn;if(!c.readOnly&&!this.compareFields(c.type,t[s],e[s]))return!0}return!1},t.prototype.getChanges=function(t,e,r){for(var n=[],o=0,i=r;o<i.length;o++){var s=i[o],c=s.id,a=s.apiColumn;a.readOnly||(this.compareFields(a.type,t[c],e[c])||n.push({oldValue:t[c],newValue:e[c],column:s.apiColumn}))}return n},t.prototype.copyFields=function(t,e,r){for(var n=0,o=r;n<o.length;n++){var i=o[n],s=i.path;e[s]=this.clone(i.apiColumn.type,t[s])}return e},t.prototype.shallowCopyFields=function(t,e,r,n){for(var o=0,i=n;o<i.length;o++){var s=i[o],c=s.path;r[c]=void 0!==t[c]?t[c]:this.clone(s.apiColumn.type,e[c])}return r},t.prototype.setDefaultValues=function(t,e){for(var r=0,n=e;r<n.length;r++){var o=n[r];t[o.id]=this.getDefaultValue(o.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),o=Math.abs(t-e);return t===e||(0===t||0===e||o<Number.MIN_VALUE?o<1.19e-7*Number.MIN_VALUE:o/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 w(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}(),A=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,o){return this.processResponse(this.externalApiRequestService.create(t,e,r,n,o))},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}(),j=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.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.fetchValue=function(t,e,r){if(void 0!==this.items[t][e])return this.items[t][e].data[this.columnIndexMap[t][r]]},t.prototype.fetchDerivedObject=function(t,e,r){for(var n={},o=0,i=r;o<i.length;o++){var s=i[o];this.fetchDerivedValues(this.fetchValue(t,e,s.id),s,n)}return n},t.prototype.fetchDerivedValues=function(t,e,r){for(var n=0,o=e.children;n<o.length;n++){var i=o[n],s=void 0;null===t?(s=null,r[i.path]=this.apiFormatter.getDefaultValue(i.apiColumn.type)):(s=this.fetchValue(e.itemType,t,i.id),r[i.path]=s),i.isLeaf||this.fetchDerivedValues(s,i,r)}},t.prototype.fetchObject=function(t,e,r){if((void 0===r&&(r=!1),void 0!==this.items[t])&&void 0!==this.items[t][e]){for(var n=this.items[t][e].data,o={},i=0;i<n.length;i++)o[this.columns[t][i].id]=n[i];if(r){var s=this.items[t][e].links;for(var c in o.__links={},s)o.__links[c]=this.fetchObjectArray(c,r,s[c])}return o}},t.prototype.fetchObjectArray=function(t,e,r){var n=[];if(null===r){for(var o in this.items[t])n.push(this.fetchObject(t,o,e));return n}void 0===r&&(r=this.links[t]);for(var i=0,s=r;i<s.length;i++){o=s[i];n.push(this.fetchObject(t,o,e))}return n},t.prototype.fetchObjectMap=function(t,e,r,n){var o=this.columnIndexMap[t][e],i={},s=[];for(var c in this.items[t]){var a=this.items[t][c].data[o];s.push(a),i[a]=this.fetchObject(t,c,r)}return n?{result:i,keys:s}:i},t.prototype.fetchFieldMap=function(t,e){var r=this.columnIndexMap[t][e],n={};for(var o in this.items[t])n[o]=this.items[t][o].data[r];return n},t.prototype.fetchColumnArray=function(t){for(var e=[],r=0,n=this.columns[t];r<n.length;r++){var o=n[r];e.push(o)}return e},t.prototype.fetchColumnObject=function(t){return this.columnMap[t]},t.prototype.fetchColumnsObject=function(){return this.columnMap},t.prototype.createResource=function(t,e){return{object:this.fetchObject(t,e),links:this.items[t][e].links}},t.prototype.hasItems=function(t){for(var e in this.items[t])return!0;return!1},t.prototype.getIdArray=function(t){var e=[];for(var r in this.items[t])e.push(parseInt(r,10));return e},t}();!function(t){t.CACHED="cached",t.LOCAL="local",t.PROMISED="promised",t.EXPAND="expand",t.PROMISED_EXPAND="promised-expand",t.EXPAND_LOCAL="expand-local",t.PROMISED_EXPAND_LOCAL="promised-expand-local",t.RESOLVE="resolve",t.RESOLVE_VALUES="resolve-values"}(T||(T={}));var k,D=">",H=function(){function t(t,e,r,n){for(var o in this.promiseService=t,this.itemType=e,this.getItemId=r,this.getPromise=n,this.requestStatus=[T.RESOLVE,T.RESOLVE_VALUES,T.EXPAND,T.PROMISED_EXPAND],this.remoteExpandStatus=[T.EXPAND,T.PROMISED_EXPAND],this.localExpandStatus=[T.EXPAND_LOCAL,T.PROMISED_EXPAND_LOCAL],this.entries={},T)this.entries[T[o]]=[]}return t.prototype.add=function(t){this.entries[t.status].push(t.entry)},t.prototype.hasEntries=function(t){for(var e=0,r=t;e<r.length;e++){var n=r[e];if(this.entries[n].length>0)return!0}return!1},t.prototype.hasRequests=function(){return this.hasEntries(this.requestStatus)},t.prototype.forEachEntry=function(t,e){for(var r=0,n=t;r<n.length;r++)for(var o=n[r],i=0,s=this.entries[o];i<s.length;i++){var c=s[i];e(c,this.getItemId(c))}},t.prototype.reduceEntries=function(t,e,r){for(var n=0,o=t;n<o.length;n++)for(var i=o[n],s=0,c=this.entries[i];s<c.length;s++){var a=c[s];e(a,this.getItemId(a),r)}return r},t.prototype.reduceAllEntries=function(t,e){var r=this.entries;for(var n in r)for(var o=0,i=r[n];o<i.length;o++){var s=i[o];t(s,this.getItemId(s),e)}return e},t.prototype.getPromises=function(){var t=this;return this.promiseService.all(this.reduceEntries([T.PROMISED,T.PROMISED_EXPAND],function(e,r,n){n.push(t.getPromise(e))},[]))},t.prototype.getItemIds=function(t){return this.reduceEntries(t,function(t,e,r){r.push(e)},[])},t.prototype.getRequestIds=function(){return this.getItemIds(this.requestStatus)},t.prototype.getArray=function(t){var e=function(t,e,r){r.push(t)};return void 0===t?this.reduceAllEntries(e,[]):this.reduceEntries(t,e,[])},t.prototype.getMap=function(){return this.reduceAllEntries(function(t,e,r){r[e]=t},{})},t}(),P=function(){function t(t,e,r,n){this.collectionCacheFactory=t,this.keyService=e,this.singleItems=r,this.compilation={create:{},delete:{},update:{},move:{}},this.moveArray=[],this.deleteMap={},this.collections=this.collectionCacheFactory.construct(),this.processSingleItems(),this.processCollections(n),this.postProcess()}return t.prototype.getDefaultParent=function(){return{itemType:"Void",itemId:0}},t.prototype.addMoveEntry=function(t){this.moveArray.push(t)},t.prototype.addDeleteEntry=function(t,e){p(this.deleteMap,[t.itemType,t.itemId],[{},{item:t,parent:e}])},t.prototype.addUpdateEntry=function(t){p(this.compilation.update,[t.itemType,t.itemId],[{},t])},t.prototype.addCreateEntry=function(t){var e=t.parent;null===e&&(e=this.getDefaultParent()),p(this.compilation.create,[e.itemType,e.itemId,t.itemType,t.itemId],[{},{},{},t])},t.prototype.containsCreateEntry=function(t,e){var r=this.compilation.create;for(var n in r)for(var o in r[n]){var i=r[n][o][t];if(void 0!==i)for(var s in i)if(i[s].itemId===e)return!0}return!1},t.prototype.createDeleteCompilation=function(){var t=this.deleteMap,e=this.compilation.delete;for(var r in t)for(var n in t[r]){var o=t[r][n].item;void 0===e[r]&&(e[r]=[]),e[r].push(o)}},t.prototype.postProcess=function(){for(var t=this.deleteMap,e=0,r=this.moveArray;e<r.length;e++){var n=r[e],o=f(t,[n.itemType,n.itemId]);if(void 0!==o){var i=n.parent,s=i.itemType,c=i.itemId;!this.keyService.isLocalId(c)||this.containsCreateEntry(s,c)?(p(this.compilation.move,[s,c],[{},[]]).push(o),delete t[n.itemType][n.itemId]):n.parent=o.parent}}this.createDeleteCompilation()},t.prototype.processSingleItems=function(){for(var t=0,e=this.singleItems;t<e.length;t++){var r=e[t];r.isLocal()?this.addCreateEntry(r):r.hasChanges()&&this.addUpdateEntry(r)}},t.prototype.processCollections=function(t){for(var e=0,r=t;e<r.length;e++){var n=r[e];if(this.collections.add(n),!n.isDeferred()){var o=void 0,i=void 0;n.isLocal()?(o=n.items,i=[]):n.hasEditResources?(o=n.getAddedItems(),i=n.getRemovedItems()):(o=[],i=[]);for(var s=0,c=o;s<c.length;s++){var a=c[s];a.isLocal()?this.addCreateEntry(a):this.addMoveEntry(a)}for(var u=0,l=i;u<l.length;u++){var h=l[u];this.addDeleteEntry(h,n.parent)}if(n.hasItemEditResources)for(var p=0,f=n.getUpdatedItems();p<f.length;p++){var d=f[p];this.addUpdateEntry(d)}}}},t}(),_=function(){function t(t,e,r,n,o,i,s,c,a,u,l){this.apiFormatter=t,this.apiRequestService=e,this.changesCompilationFactory=r,this.collectionEntryService=n,this.collectionHandler=o,this.columnExpansionFactory=i,this.createRequestFactory=s,this.errorHandler=c,this.itemHandler=a,this.promiseService=u,this.requestColumnExpansionFactory=l}return t.prototype.buildMoveRequest=function(t){for(var e={},r=0,n=t;r<n.length;r++){var o=n[r].item,i=o.itemType;void 0===e[i]&&(e[i]=[]),e[i].push(o.itemId)}return e},t.prototype.getMapValue=function(t,e,r){if(void 0!==r&&void 0!==r[t])return r[t][e]},t.prototype.executeCreateRequests=function(t,e,r,n,o){for(var i=[],s=0,c=this.createRequestFactory.construct(t.compilation.create,t.collections,e,n).run();s<c.length;s++){var a=c[s];i.push(this.executeCreateRequest(a,r).then(u))}return this.promiseService.all(i).then(function(){return r},this.errorHandler.reject);function u(t){return void 0!==o&&o(r),t}},t.prototype.executeCreateRequest=function(t,e){var r=this;return this.apiRequestService.requestSkeleton(t.request).then(function(n){var o=n.map,i=n.fetchColumnsObject(),s=t.items;for(var c in s){var a=r.columnExpansionFactory.construct(c,t.request.columns[c],i);for(var u in s[c]){var l=s[c][u],h=r.getMapValue(c,parseInt(u,10),o);if(void 0!==h){var p=n.fetchObject(c,h),f=a.run(l.columns);l.itemId=h,l.updateFields(p,n.fetchDerivedObject(c,h,l.columns.root)),null!==f&&l.expand(p,n.fetchDerivedObject(c,h,f.difference.root),f),r.itemHandler.entries.add(l)}else console.warn("Create failed!",l)}}for(var c in t.collections.addToCollections(),o)for(var u in void 0===e[c]&&(e[c]={}),o[c])e[c][parseInt(u,10)]=o[c][u]},this.errorHandler.reject)},t.prototype.executeUpdateRequests=function(t,e){var r=[];for(var n in t)r.push(this.executeUpdateRequest(n,t[n],e));return this.promiseService.all(r)},t.prototype.executeUpdateRequest=function(t,e,r){var n=this,o={},i=this.requestColumnExpansionFactory.construct(),s=this.collectionHandler.getCollectionMatcher();for(var c in o[t]={},e){var a=e[c],u=o[t][c]={},l=f(r,[t,c]);u.values=a.formatRequest(),void 0!==l&&(u.parameters=l),i.expand(a.columns),s.expand(a)}for(var h=0,p=s.getCollectionsWithFittingItems();h<p.length;h++){var d=p[h];i.expand(d.columns)}return this.apiRequestService.updateItems(t,o,i.get()).then(function(r){var o=n.columnExpansionFactory.construct(t,i.get()[t],r.fetchColumnsObject());for(var c in e){var a=e[c],u=r.fetchObject(t,c);if(void 0!==u){var l=n.apiFormatter.copyFields(a.initial,{},a.columns.main);a.updateFields(u,r.fetchDerivedObject(t,c,a.columns.root)).callOnChange(l);var h=o.run(a.columns);null!==h&&a.expand(u,r.fetchDerivedObject(t,c,h.difference.root),h)}else console.warn("Update failed!",a)}s.removeFromAndAddToCollections()},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){for(var r=this,n=[],o=0,i=e;o<i.length;o++){var s=i[o];n.push(s.itemId)}return this.apiRequestService.delete(t,n).then(function(t){for(var n=t.items,o=r.collectionHandler.getCollectionMatcher(),i=0,s=e;i<s.length;i++){var c=s[i];a(c.itemId,n)||console.warn("Delete failed!",c),o.expand(c)}o.removeFromCollections()},this.errorHandler.reject)},t.prototype.executeMoveRequests=function(t,e){var r=this,n=[];for(var o in t)for(var i in t[o])s(o,+i);return this.promiseService.all(n);function s(o,i){var s=t[o][i],c=r.getMapValue(o,i,e);n.push(r.apiRequestService.moveItems(o,void 0!==c?c:i,r.buildMoveRequest(s)).then(function(){r.processMoveResponse(s)},r.errorHandler.reject))}},t.prototype.processMoveResponse=function(t){for(var e=[],r={},n={},o=0,i=t;o<i.length;o++){var s=i[o],c=s.item;this.addCollectionMapEntry(r,s.parent.itemId,c,c.itemId),this.addCollectionMapEntry(n,c.parent.itemId,c,c),e.push(c)}this.forEachCollection(r,function(t,e){t.removeItems(e,null,!0)}),this.forEachCollection(n,function(t,e){t.addItems(e,null,!0)})},t.prototype.addCollectionMapEntry=function(t,e,r,n){p(t,[r.parent.itemType,e,r.itemType],[{},{},[]]).push(n)},t.prototype.forEachCollection=function(t,e){for(var r in t)for(var n in t[r])for(var o in t[r][n]){var i=this.collectionHandler.entries.getByParent(r,+n,o);null!==i&&e(i,t[r][n][o])}},t.prototype.onItemsCreated=function(t,e,r){if(s(t)){for(var n=0,o=r;n<o.length;n++){var i=o[n],c=i.parent,a=i.getUpdatedItemColumns(t);if(null!==c)void 0!==(d=this.getMapValue(c.itemType,c.itemId,t))&&(c.itemId=d,i.query=this.collectionEntryService.createQuery(i.options),this.collectionHandler.entries.add(i));if(s(a)){void 0!==a.id&&i.onItemsCreated(t[i.itemType]);for(var u=0,l=i.items;u<l.length;u++){(f=l[u]).updateItemFields(t)}}}for(var h=0,p=e;h<p.length;h++){var f,d,m=(f=p[h]).parent;if(f.updateItemFields(t),null!==m)void 0!==(d=this.getMapValue(m.itemType,m.itemId,t))&&(m.itemId=d)}}},t.prototype.execute=function(t,e,r,n,o){var i=this;void 0===r&&(r={});var s=this.errorHandler,c=this.changesCompilationFactory.construct(t,e),a=c.compilation,u={};return this.executeCreateRequests(c,r,u,n,o).then(function(){return i.onItemsCreated(u,t,e),i.executeMoveRequests(a.move,u)},function(r){return i.onItemsCreated(u,t,e),s.reject(r)}).then(function(){return i.executeUpdateRequests(a.update,r)},s.reject).then(function(){return i.executeDeleteRequests(a.delete)},s.reject).then(function(){return u},s.reject)},t}();!function(t){t.MAYBE="maybe"}(k||(k={}));var V,N,B=function(){function t(t,e){this.collectionResourceFactory=t,this.queryMatcherFactory=e,this.entries={}}return 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 o in n)if(this.matchParent(n[o],t,e))return n[o];return null},t.prototype.getResourceByParent=function(t,e,r){var n=this.getByParent(t,e,r);return null===n?null:this.collectionResourceFactory.cache.getLatest(n)},t.prototype.getCollectionsByParent=function(t,e){var r=this.entries,n=[];for(var o in r)for(var i in r[o]){var s=r[o][i];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 o in r){var i=r[o];void 0!==i.getItemById(e)&&n.push(i)}return n},t.prototype.getByFittingItem=function(t,e,r){var n=this.entries[t],o={fitting:[],notfitting:[],maybe:[]};if(void 0===n)return o;var i=this.queryMatcherFactory.construct(t,e,r);for(var s in n){var c=n[s],a=i.matchQuery(c.query.object);!0===a?o.fitting.push(c):a===k.MAYBE?o.maybe.push(c):o.notfitting.push(c)}return o},t.prototype.getByQuery=function(t,e){var r=this.entries[t];if(void 0===r)return null;for(var n in r){var o=r[n];if(o.query.string===e.string)return o}return null},t.prototype.getByKey=function(t,e){var r=this.entries[t],n=[];if(void 0===r)return n;for(var o in r){var i=r[o];i.options.entryKey===e&&n.push(i)}return n},t.prototype.getResourceByKey=function(t,e){var r=this.entries[t],n=[];if(void 0===r)return n;for(var o in r)for(var i=0,s=this.collectionResourceFactory.cache.get(r[o]);i<s.length;i++){var c=s[i];c.options.resourceKey===e&&n.push(c)}return n},t}(),U=function(){return function(t){this.columns=!0,this.parent=null,this.templateOptions={},this.templateColumns={},this.deferRequest=!1,this.isDuplicate=!1,o(this,t)}}(),Q=function(){return function(t){this.edit=!1,this.remote=!1,this.onChange=ve,o(this,t)}}(),Y=0,X=function(){function t(t,e,r,n){this.factory=t,this.itemType=e,this.itemId=r,this.columns=n,this.id=++Y,this.reloadQueued=!1,this.deferRequest=!1,this.parent=null}return t.prototype.getResources=function(){return this.factory.itemResourceFactory.cache.get(this)},t.prototype.queueReload=function(){return this.reloadQueued=!0,this},t.prototype.defer=function(t){return void 0===t&&(t=!1),this.deferred=this.factory.promiseService.defer(),this.deferRequest=t,this},t.prototype.getPromise=function(){var t=this.deferred;return void 0===t?this.factory.promiseService.when(this):t.promise},t.prototype.resolve=function(){var t=this.deferred;return void 0===t?this:(delete this.deferred,delete this.deferRequest,t.resolve(this),this)},t.prototype.resolveDeferred=function(t,e,r){return this.columns=r,this.setFields(t,e),this.resolve()},t.prototype.isDeferred=function(){return void 0!==this.deferred},t.prototype.reject=function(t){void 0===t&&(t=this.factory.itemEntryService.createUnfoundRemoteItemError());var e=this.deferred;return void 0===e?this:(e.reject(t),delete this.deferred,delete this.deferRequest,this)},t.prototype.setFields=function(t,e){var r=this.factory.apiFormatter,n=this.columns.formatted;return this.initial=r.formatResponse(t,n.main),this.derived=r.formatResponse(e,n.derived),this},t.prototype.setLocalFields=function(t,e,r){void 0===r&&(r=this.columns);for(var n=this.factory,o=n.itemEntryService.getLocalDefaultValues(),i=0,s=r.main;i<s.length;i++){var c=s[i].id;o[c]=t[c]}return this.initial=n.apiFormatter.formatResponse(o,r.formatted.main),this.derived={"creator>displayname":n.authInterface.getUserDisplayname()},this.updateItemFields(e)},t.prototype.clone=function(t){void 0===t&&(t={});var e=this.factory,r=e.apiFormatter,n=e.itemEntryService,o=this.columns,i=this.parent,s=n.expandConversionMap(this,t),c=e.construct(s,r.copyFields(this.getFields(),{},o.main),r.copyFields(this.derived,{},o.derived),o);if(c.updateItemFields(t),c.modified=r.copyFields(c.initial,{},o.main),null===i)return c;var a=n.getConversionValue(i.itemType,i.itemId,t);return c.setParent(i.itemType,void 0===a?i.itemId:a),c},t.prototype.resetDerived=function(t){for(var e=this,r=[],n=0,o=this.columns.root;n<o.length;n++){var i=o[n];-1!==t.indexOf(i.id)&&r.push(i)}return function t(r){for(var n=0,o=r;n<o.length;n++){var i=o[n];i.isLeaf||t(i.children),delete e.derived[i.path]}}(r),this},t.prototype.getFields=function(){return void 0!==this.modified?this.modified:this.initial},t.prototype.expand=function(t,e,r){var n=this.factory.apiFormatter,o=r.difference;return this.columns=r.merged,n.expandResponse(this.initial,t,o.main),n.expandResponse(this.derived,e,o.derived),void 0===this.modified?this:(n.expandResponse(this.modified,t,o.main),this)},t.prototype.expandLocal=function(t){var e=t.difference.main;return this.columns=t.merged,0===e.length?this:(this.setLocalValues(this.initial,e),void 0===this.modified?this:(this.setLocalValues(this.modified,e),this))},t.prototype.setLocalValues=function(t,e){for(var r=this.factory,n=this.parent,o=0,i=e;o<i.length;o++){var s=i[o],c=s.id;if(void 0===t[c]){var a=s.apiColumn.type;t[c]="link"===a&&null!==n?n.itemId:r.apiFormatter.getDefaultValue(a)}}},t.prototype.updateFields=function(t,e,r){void 0===e&&(e=null),void 0===r&&(r=!0);var n=this.factory.apiFormatter,o=this.columns.main,i=this.initial,s=this.modified;if(void 0!==s)for(var c=0,a=o;c<a.length;c++){var u=(f=a[c]).id,l=f.apiColumn.type;(r||n.compareFields(l,i[u],s[u]))&&(s[u]=n.formatResponseValue(l,t[u]))}for(var h=0,p=o;h<p.length;h++){var f;i[u=(f=p[h]).id]=n.formatResponseValue(f.apiColumn.type,t[u])}return null!==e&&this.setDerived(e),this},t.prototype.updateItemValues=function(t,e,r){for(var n=this.factory.itemEntryService,o=this.parent,i=0,s=e;i<s.length;i++){var c=s[i],a=c.id,u=c.apiColumn,l=void 0;"link"===u.type&&void 0===t[a]?null!==o&&(l=o.itemId):l=n.getConversionValue(u.itemType,t[a],r),void 0!==l&&(t[a]=l)}},t.prototype.updateItemFields=function(t,e){void 0===e&&(e=this.columns);var r=e.item,n=this.modified;return this.updateItemValues(this.initial,r,t),void 0===n?this:(this.updateItemValues(n,r,t),this)},t.prototype.formatRequest=function(){var t=this.factory.apiFormatter,e=this.columns.main;return this.isLocal()?t.formatRequestLocal(this.getFields(),e):void 0===this.modified?{}:t.formatRequest(this.initial,this.modified,e)},t.prototype.setDisplayName=function(){if(void 0===this.modified)return this;var t=this.getDisplayName();return t&&(this.modified.displayname=t),this},t.prototype.getDisplayName=function(){var t=this.factory.itemEntryService,e=this.getFields();switch(this.itemType){case"Contact":return"bedrijf"===e.type?e.bedrijf:t.getFullName(e.voornaam,e.tussenvoegsel,e.naam);case"Medewerker":case"Person":return t.getFullName(e.voornaam,e.tussenvoegsel,e.achternaam);case"Reparatie":return this.derived["materiaal>naam"];default:return e[t.getTitleField(this.itemType)]}},t.prototype.getChanges=function(t){return void 0===t&&(t=!1),void 0!==this.modified||t?this.factory.apiFormatter.getChanges(this.initial,t?{}:this.modified,this.columns.main):[]},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.hasChanges=function(){return void 0!==this.modified&&this.factory.apiFormatter.hasChanges(this.initial,this.modified,this.columns.main)},t.prototype.resetModified=function(){var t=this.columns.main;if(void 0===this.modified)return this;for(var e=0,r=t;e<r.length;e++){var n=r[e];this.modified[n.id]=this.factory.apiFormatter.clone(n.apiColumn.type,this.initial[n.id])}return this},t.prototype.setInitial=function(t,e){void 0===e&&(e=!1);var r,n=this.factory.apiFormatter;for(var o in t)this.initial[o]=t[o];if(void 0===this.modified)return e&&this.callOnChange(n.copyFields(this.initial,{},this.columns.main)),this;for(var o in r=n.copyFields(this.modified,{},this.columns.main),t)this.modified[o]=t[o];return e&&this.callOnChange(r),this},t.prototype.setModified=function(t){var e=this.factory,r=e.apiFormatter,n=this.columns,o=n.response[this.itemType];if(void 0===this.modified){var i=this.initial,s=this.modified=this.isLocal()?e.itemEntryService.getLocalDefaultValues():{};if(void 0===t)r.copyFields(i,s,n.main);else for(var c in r.shallowCopyFields(t,i,s,n.main),t)void 0===o[c]&&(s[c]=t[c]);for(var a=0,u=this.getResources();a<u.length;a++){var l=u[a];l instanceof ht&&(l.fields=s)}return this}if(void 0===t)return this;for(var c in t)this.modified[c]=t[c];return this},t.prototype.setDerived=function(t){for(var e in t)this.derived[e]=t[e];return this},t.prototype.setParent=function(t,e){return this.parent={itemType:t,itemId:e},this},t.prototype.callOnChange=function(t){for(var e=0,r=this.getResources();e<r.length;e++){var n=r[e];try{n.options.onChange(n,t)}catch(t){this.factory.exceptionHandler(t)}}return this},t.prototype.toJSON=function(){return{id:this.id,parent:this.parent,initial:this.initial,modified:this.modified,derived:this.derived,columns:this.columns}},t}(),W=function(){function t(t,e,r,n,o){this.factory=t,this.entry=e,this.options=r,this._isNew=n,this.localCache=o,this.derived=e.derived,this.columns=e.columns.response[e.columns.itemType]}return t.prototype.isNew=function(){return this._isNew},t.prototype.isLocal=function(){return this.entry.isLocal()},t.prototype.clearResource=function(){this.factory.cache.clearResource(this)},t.prototype.deactivate=function(){null!==this.localCache&&this.localCache.onDeactivateItem(this.entry)},t.prototype.toJSON=function(){var t=[];for(var e in this.columns)t.push(e);return{columns:t,fields:this.fields,derived:this.derived,entry:this.entry}},t}(),J=(V=function(t,e){return(V=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}V(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),K=function(t){function e(e,r,n,o,i){return t.call(this,e,r,n,o,i)||this}return J(e,t),e}(W),z=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)}}(),G=function(t){function e(e,r,n,o,i){var s=t.call(this,e,r,n,o,i)||this;return s.localCopies=[],s.transactions=0,r.setModified(),s.fields=r.modified,s}return z(e,t),e.prototype.isNew=function(){return this._isNew&&0===this.transactions},e.prototype.start=function(){return void 0===this.localCopies&&(this.localCopies=[]),this.localCopies.push(this.copyFields()),this},e.prototype.rollback=function(){var t=this.entry;return this.factory.apiFormatter.copyFields(this.localCopies.pop(),t.modified,t.columns.main),this.isNew()&&0===this.localCopies.length&&null!==this.localCache&&this.localCache.onDeactivateItem(this.entry),this},e.prototype.commit=function(t){void 0===t&&(t=!0);var e=this.localCopies.pop();return t&&this.callOnChange(e),this.transactions++,this},e.prototype.getLocalCopy=function(){var t=this.localCopies;return void 0===t?null:0===t.length?null:t[t.length-1]},e.prototype.copyFields=function(t){void 0===t&&(t={});var e=this.entry;return this.factory.apiFormatter.copyFields(e.modified,t,e.columns.main)},e.prototype.setFields=function(t,e){void 0===e&&(e=!0);var r,n=this.columns,o=this.fields,i=!1;for(var s in e&&(r=this.copyFields()),t){var c=n[s];void 0!==c?this.factory.apiFormatter.compareFields(c.type,o[s],t[s])||(o[s]=t[s],i=!0):console.warn("setFields: no column found for",s)}return e&&i&&this.callOnChange(r),this},e.prototype.callOnChange=function(t){return this.entry.callOnChange(t),this},e.prototype.save=function(t){var e=this,r=this.factory,n=this.entry,o={};return void 0!==t&&p(o,[n.itemType,n.itemId],[{},t]),(n.isLockable()?r.lockService.fetchLock(n):r.promiseService.when()).then(function(){return r.changesProcessor.execute([n],[],o)},r.errorHandler.reject).then(function(){return e},r.errorHandler.reject)},e}(W),Z=function(){return function(t){this.columns=[],this.query=null,this.queryParams={},this.parent=null,this.deferRequest=!1,this.limit=null,this.entryKey=null,o(this,t)}}(),$=function(){return function(t){this.editItems=!1,this.remoteItems=!1,this.editCollection=!1,this.modInstant=!1,this.enableSave=!0,this.onItemsCreated=ve,this.onChange=ve,this.onAdd=ve,this.onRemove=ve,this.onAddInitial=ve,this.onRemoveInitial=ve,this.resourceKey=null,this.custom=null,o(this,t)}}(),tt=0,et=function(){function t(t,e,r){this.factory=t,this.itemType=e,this.options=r,this.id=tt++,this.parent=null,this.templateColumns=null,this.initial=[],this.items=[],this.reloadQueued=!1,this.hasEditResources=!1,this.hasItemEditResources=!1,this.parent=r.parent,this.query=t.collectionEntryService.createQuery(r),this.columns=t.columnSetFactory.constructStub(e,r.columns),this.defer()}return t.prototype.getResources=function(){return this.factory.collectionResourceFactory.cache.get(this)},t.prototype.defer=function(){return this.isDeferred()?this:(this.deferred=this.factory.promiseService.defer(),this.promise=this.deferred.promise,this)},t.prototype.isDeferred=function(){return void 0!==this.promise},t.prototype._resolve=function(){var t=this.deferred;return void 0===t?this:(delete this.deferred,delete this.promise,t.resolve(this),this)},t.prototype.resolve=function(t){var e=t.initial,r=t.modified;return this.columns=t.columns,this.initial=e,this.items=void 0!==r?r:e.slice(),this._resolve()},t.prototype.isLocal=function(){var t=this.parent;return null!==t&&this.factory.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.forEach=function(t){for(var e=0,r=this.items;e<r.length;e++){t(r[e])}},t.prototype.getItemById=function(t){for(var e=0,r=this.items;e<r.length;e++){var n=r[e];if(n.itemId===t)return n}},t.prototype.getIdArray=function(t){return void 0===t&&(t=[]),this.factory.collectionEntryService.getIdArray(this.items,t)},t.prototype.createItems=function(t){var e,r=this,n=this.factory,o=this.columns;return n.itemHandler.fetchTemplate(this.itemType).then(function(i){e=i;var s=[];null===r.templateColumns&&(r.templateColumns=e.columns.merge(o));for(var c=0,a=t;c<a.length;c++){var u=a[c];s.push(n.itemEntryFactory.constructLocal(n.keyService.getLocalId(),e,u,{},r.parent,r.templateColumns))}return s},n.errorHandler.reject)},t.prototype.resolveDerivedValues=function(t,e){return this.factory.itemHandler.resolveDerivedValues(t,this.columns.root,e)},t.prototype.addItems=function(t,e,r,n,o){if(void 0===r&&(r=!1),0===t.length)return[];var i=this.items,s=this.parent,c=this.columns.link,a=[],u=[];if(r)for(var l=this.initial,h=0,p=t;h<p.length;h++){var f=p[h];-1===l.indexOf(f)&&(l.push(f),a.push(f))}for(var d=0,m=t;d<m.length;d++){f=m[d];-1===i.indexOf(f)&&(null!==s&&(f.parent=s,null!==c&&void 0!==f.modified&&(f.modified[c.id]=s.itemId)),i.push(f),u.push(f))}return this.handleAddedItemCallbacks(a,u,e,n,o)},t.prototype.handleAddedItemCallbacks=function(t,e,r,n,o){void 0===r&&(r=null),void 0===n&&(n=!0),void 0===o&&(o=!0);var i,s,c=this.getResources();if(t.length>0&&this.onAddInitial(t),0===e.length||0===c.length)return null===r?null:[];for(var a=0,u=c;a<u.length;a++){var l=u[a];null!==l.localCache&&(i=l.localCache);var h=l.addItemResources(e);l===r?(s=h,n&&l.callOnAdd(h)):l.callOnAdd(h)}if(o&&void 0!==i)for(var p=0,f=e;p<f.length;p++){var d=f[p];i.onActivateItem(d)}return void 0!==s?s:null===r?null:[]},t.prototype.removeItems=function(t,e,r,n){return 0===t.length?[]:this.handleRemovedItems(function(e){return!a(e.itemId,t)},e,r,n)},t.prototype.clear=function(t,e,r){return this.handleRemovedItems(function(){return!1},t,e,r)},t.prototype.handleRemovedItems=function(t,e,r,n){void 0===r&&(r=!1);var o,i=this.factory.collectionEntryService,s=i.filterArray(this.items,t);if(r)o=i.filterArray(this.initial,t);else{for(var c=[],a=0,u=s;a<u.length;a++){var l=u[a];l.isLocal()&&c.push(l)}o=c.length>0?i.filterArray(this.initial,function(t){return-1===c.indexOf(t)}):[]}return this.handleRemovedItemCallbacks(o,s,e,n)},t.prototype.handleRemovedItemCallbacks=function(t,e,r,n){void 0===n&&(n=!0);var o,i,s=this.getResources();if(t.length>0&&this.onRemoveInitial(t),0===e.length||0===s.length)return null===r?null:[];for(var c=0,a=s;c<a.length;c++){var u=a[c];null!==u.localCache&&(o=u.localCache);var l=u.removeItemResources(e);u===r?(i=l,n&&u.callOnRemove(l)):u.callOnRemove(l)}if(void 0!==o)for(var h=0,p=e;h<p.length;h++){var f=p[h];o.onDeactivateItem(f)}return void 0!==i?i:null===r?null:[]},t.prototype.createBatchStatus=function(t,e,r){return this.factory.itemHandler.createBatchStatus(this.itemType,t,this.parent,e,!1,r,!1).batchStatus},t.prototype.expandLocal=function(t,e){var r=this,n=this.factory,o=n.errorHandler,i=this.itemType;return n.columnHandler.fetch(i,t).then(function(s){var c=n.columnExpansionFactory.construct(i,t,s),a=r.createBatchStatus(r.getIdArray(),t,e);return a.getPromises().then(function(){return n.itemHandler.handleBatchResponse(a,e,t,null,s,c)},o.reject).then(function(){return c},o.reject)},o.reject)},t.prototype.expandRemote=function(t,e){var r=this,n=this.factory,o=n.errorHandler,i=this.itemType;return n.itemRequestService.requestItems(this,void 0,t).then(function(s){var c=s.fetchColumnsObject(),a=n.columnExpansionFactory.construct(i,t,c),u=r.createBatchStatus(s.links[i],t,e);return u.getPromises().then(function(){return n.itemHandler.handleBatchResponse(u,e,t,s,c,a)},o.reject).then(function(){var t=s.items[i];return r.handleRemovedItems(function(e){return void 0!==t[e.itemId]||e.isLocal()},null,!0,!0),r.addItems(u.getArray([T.RESOLVE]),null,!0,!0,!1),a},o.reject)},o.reject)},t.prototype.expand=function(t,e){var r=this,n=this.columns.mergeRequestColumns(t),o=n.merged,i=n.difference;return!0!==i&&0===i.length?this.factory.promiseService.when(this):(this.isLocal()?this.expandLocal(i,e):this.expandRemote(o,e)).then(function(t){return r.expandColumns(t),r})},t.prototype.extendQuery=function(t){var e=this.options;return void 0===t?this.query:(e.queryParams=t(e.queryParams),this.query=this.factory.collectionEntryService.createQuery(e))},t.prototype.extend=function(t,e,r){var n=this,o=this.factory,i=o.errorHandler,s=this.extendQuery(t).object,c=o.queryService.addAndCondition(s,o.queryService.createNotIn(this.getIdArray())),a=o.itemRequestService.requestItems(this,null!==this.options.limit?s:c).then(function(t){return o.itemRequestService.processResponse(t,t.links[n.itemType],n.parent,n.columns)},i.reject).then(function(t){return delete n.promise,n.addItems(t,e,!0,r,!1)},i.reject);return this.promise=a.then(function(){return n},i.reject),a},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.templateColumns=null,this.options.columns=this.columns.request)},t.prototype.expandRequestColumns=function(t){this.columns.expandRequestColumns(t),this.options.columns=this.columns.request},t.prototype.getAddedItems=function(t){void 0===t&&(t=!1);for(var e=this.initial,r=[],n=0,o=this.items;n<o.length;n++){var i=o[n];-1===e.indexOf(i)&&r.push(t?i.itemId:i)}return r},t.prototype.getRemovedItems=function(t){void 0===t&&(t=!1);for(var e=this.initial,r=this.items,n=[],o=0,i=e;o<i.length;o++){var s=i[o];-1===r.indexOf(s)&&n.push(t?s.itemId:s)}return n},t.prototype.getUpdatedItems=function(){for(var t=[],e=0,r=this.items;e<r.length;e++){var n=r[e];!n.isLocal()&&n.hasChanges()&&t.push(n)}return t},t.prototype.hasAddedItems=function(){return this.items.length>this.initial.length},t.prototype.hasRemovedItems=function(){return this.initial.length>this.items.length},t.prototype.hasUpdatedItems=function(){for(var t=0,e=this.items;t<e.length;t++){if(e[t].hasChanges())return!0}return!1},t.prototype.revertChanges=function(){var t=this.getAddedItems(),e=this.getRemovedItems();this.items=this.initial.slice(),this.handleAddedItemCallbacks([],e),this.handleRemovedItemCallbacks([],t)},t.prototype.onItemsCreated=function(t){for(var e=0,r=this.getResources();e<r.length;e++){var n=r[e];n.rebuildMap();try{n.options.onItemsCreated(t)}catch(t){this.factory.exceptionHandler(t)}}},t.prototype.onAddInitial=function(t){for(var e=0,r=this.getResources();e<r.length;e++){var n=r[e];try{n.options.onAddInitial(t,this)}catch(t){this.factory.exceptionHandler(t)}}},t.prototype.onRemoveInitial=function(t){for(var e=0,r=this.getResources();e<r.length;e++){var n=r[e];try{n.options.onRemoveInitial(t,this)}catch(t){this.factory.exceptionHandler(t)}}},t.prototype.getUpdatedItemColumns=function(t){for(var e={},r=0,n=this.columns.item;r<n.length;r++){var o=n[r];void 0!==t[o.apiColumn.itemType]&&(e[o.id]=o)}return e},t.prototype.clone=function(t,e){for(var r=this.factory,n=r.itemEntryService.batchClone(this.items,e),o=0,i=n;o<i.length;o++){i[o].parent=t}return r.construct(this.itemType,r.collectionEntryService.cloneOptions(this.options,t)).resolve({columns:this.columns,initial:n})},t}(),rt=function(){function t(t,e,r,n,o){var i=this;this.factory=t,this.entry=e,this.options=r,this.level=n,this.localCache=o,this.itemIdMap={},this.items=[],this.itemIdMap={},this.columns=e.columns.response,this.onChange=function(t,e){i.options.onChange(t,e)},this.addItemResources(e.items)}return t.prototype.getItemById=function(t){return this.itemIdMap[t]},t.prototype.rebuildMap=function(){for(var t={},e=0,r=this.items;e<r.length;e++){var n=r[e];t[n.entry.itemId]=n}this.itemIdMap=t},t.prototype.addItemResources=function(t){if(0===t.length)return[];for(var e=[],r=this.options,n=this.items,o=this.itemIdMap,i=this.factory.itemResourceFactory.getConstructor({edit:r.editItems,onChange:this.onChange},this.level,this.localCache),s=0,c=t;s<c.length;s++){var a=c[s],u=a.itemId,l=void 0;void 0===o[u]?(l=i(a),n.push(l),o[u]=l):l=o[u],e.push(l)}return e},t.prototype.removeItemResources=function(t){var e=this,r=[];return u(this.items,function(n){for(var o=0,i=t;o<i.length;o++){var s=i[o];if(n.entry===s)return r.push(n),delete e.itemIdMap[s.itemId],!1}return!0}),r},t.prototype.callOnAdd=function(t){try{this.options.onAdd(t,this)}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 o=n[r];t(o)&&e.push(o)}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)for(var n=0,o=e;n<o.length;n++){void 0===r[a=(c=o[n]).fields[t]]&&(r[a]=[]),r[a].push(c)}if("function"==typeof t)for(var i=0,s=e;i<s.length;i++){var c,a;null!==(a=t(c=s[i]))&&(void 0===r[a]&&(r[a]=[]),r[a].push(c))}return r},t.prototype.map=function(t){var e=this.items,r=e.length,n=new Array(r);if("string"==typeof t)for(var o=0;o<r;o++)n[o]=e[o].fields[t];if("function"==typeof t)for(o=0;o<r;o++)n[o]=t(e[o]);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,e,r){var n=this;return void 0===e&&(e=!1),this.entry.extend(t,this,r).then(function(t){return e?n.items:t})},t.prototype.clearResource=function(){this.factory.cache.clearResource(this)},t.prototype.deactivate=function(){null!==this.localCache&&this.localCache.clearCollection(this)},t}(),nt=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,o,i){return t.call(this,e,r,n,o,i)||this}return nt(e,t),e}(rt),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)}}(),st=function(t){function e(e,r,n,o,i){return t.call(this,e,r,n,o,i)||this}return it(e,t),e.prototype.save=function(){if(!this.options.enableSave)throw new Error("collectionResourceService: Saving disabled");var t=this.factory,e=this.entry,r=e.parent;return null!==r&&t.keyService.isLocalId(r.itemId)?t.promiseService.when():t.changesProcessor.execute([],[e])},e.prototype.moveItems=function(t,e,r){var n=this.entry,o=this.options;if(o.enableSave||o.modInstant)throw new Error("collectionResourceService: Cannot move items: saving enabled");if(n.itemType!==e.entry.itemType)throw new Error("collectionResourceService: Cannot move items: itemType mismatch");var i=n.removeItems(t,this,!1,r),s=[];if(null!==i){for(var c=0,a=i;c<a.length;c++){var u=a[c];s.push(u.entry)}e.entry.addItems(s,e,!1,r)}return i},e.prototype.removeItems=function(t,e){var r=this;void 0===e&&(e=!0);var n=this.entry.removeItems(t,this,!1,!1);return null===n?this.factory.promiseService.when([]):this.options.modInstant?this.save().then(function(){return e&&r.callOnRemove(n),n}):(e&&this.callOnRemove(n),this.factory.promiseService.when(n))},e.prototype.removeItem=function(t,e){return this.removeItems([t],e).then(function(t){return t[0]},this.factory.errorHandler.reject)},e.prototype.addItems=function(t,e,r){var n=this;void 0===e&&(e=!0);var o=this.factory,i=this.options.modInstant;return this.entry.createItems(t).then(function(t){return i||null===n.localCache?t:n.entry.resolveDerivedValues(t,n.localCache.items)}).then(function(t){var s=n.entry.addItems(t,n,!1,!1,r);return null===s?[]:i?n.save().then(function(){return e&&n.callOnAdd(s),s},o.errorHandler.reject):(e&&n.callOnAdd(s),s)},o.errorHandler.reject)},e.prototype.addItem=function(t,e,r){return this.addItems([t],e,r).then(function(t){return t[0]},this.factory.errorHandler.reject)},e.prototype.clear=function(t){return this.entry.clear(this,!1,t)},e}(rt),ct=function(){return function(t,e,r,n){this.itemType=e,this.response=r,this.fields=r.fetchObject(e,r.links[e][0]),this.responseColumns=t.columnUtil.mergeResponseColumns(r.fetchColumnsObject(),n).merged,this.columns=t.columnSetFactory.construct(e,!0,this.responseColumns)}}(),at=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,o,i){var s=t.call(this,e,r,n,o,i)||this;return s.fields=r.initial,s}return at(e,t),e}(K),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,o,i){var s=t.call(this,e,r,n,o,i)||this;return s.fields=void 0===r.modified?r.initial:r.modified,s}return lt(e,t),e}(K),pt=function(){function t(t,e){this.queryParserFactory=t,this.queryService=e}return t.prototype.cloneOptions=function(t,e){var r=new Z(t);return r.queryParams=this.cloneQueryParams(t.queryParams),r.parent=e,r},t.prototype.processOptions=function(t){return new Z(t)},t.prototype.cloneQueryParams=function(t){var e={};for(var r in t){var o=t[r],i=void 0;i=Array.isArray(o)?o.slice():n.isMoment(o)?o.clone():o,e[r]=i}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 o=this.queryParserFactory.construct(e,t.queryParams).parse();return{object:o[0],string:o[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 o=n[r];e.push(o.itemId)}return e},t.prototype.filterArray=function(t,e){for(var r=[],n=[],o=0,i=t;o<i.length;o++){var s=i[o];(e(s)?r:n).push(s)}if(0===n.length)return n;t.length=r.length;for(var c=0;c<t.length;c++)t[c]=r[c];return n},t}(),ft=function(){function t(t,e,r,n,o,i,s,c,a,u,l,h,p,f){this.batchStatusFactory=t,this.collectionCacheFactory=e,this.collectionEntryFactory=r,this.collectionEntryService=n,this.collectionMatcherFactory=o,this.columnHandler=i,this.columnSetFactory=s,this.errorHandler=c,this.itemHandler=a,this.itemRequestService=u,this.keyService=l,this.promiseService=h,this.queryParserFactory=p,this.queryService=f,this.entries=this.collectionCacheFactory.construct()}return t.prototype.removeFromAndAddToCollections=function(t){for(var e in t){var r=t[e],n=r.collection;n.removeItems(r.notfitting,null,!0),n.addItems(r.fitting,null,!0),r.maybe.length>0&&n.extend(ge,null,!0)}},t.prototype.getCollectionMatcher=function(){return this.collectionMatcherFactory.construct([this.entries],!0,!0,!0)},t.prototype.removeFromCollections=function(t,e,r){var n;for(var o in void 0===r&&(r=null),t){for(var i=t[o],s=i.fitting,c=i.maybe,a=i.collection,u=[],l=0,h=s;l<h.length;l++){var p=h[l];u.push(p.itemId)}for(var f=0,d=c;f<d.length;f++){var m=d[f];u.push(m)}null!==r&&a===r.entry?n=a.removeItems(u,r,e):a.removeItems(u,null,e)}return n},t.prototype.addToCollections=function(t,e,r){var n;for(var o in void 0===r&&(r=null),t){var i=t[o],s=i.collection;s.isDeferred()||(null!==r&&s===r.entry?n=s.addItems(i.fitting,r,e):s.addItems(i.fitting,null,e),e&&i.maybe.length>0&&s.extend(ge,null,!0,e))}return n},t.prototype.batchExpand=function(t,e,r,n){var o=this;if(0===n.length)return this.promiseService.when(r);var i=[],s=[];for(var c in r){var a=r[c].entry;a.defer(),i.push(a.parent.itemId),s=s.concat(a.items)}return this.itemRequestService.requestLinkItems(t,i,e,null,n).then(function(t){for(var c=o.itemRequestService.processExpansion(n,t,e,s),a=0,u=i;a<u.length;a++){var l=u[a],h=r[l].entry;h.expandColumns(c),h._resolve()}return r})},t.prototype.batchExtend=function(t,e,r,n,o,i,c){var a=this;if(void 0===i&&(i=!1),!s(o))return this.promiseService.when({});var u=[],l=[];for(var h in r.queryParams=n(r.queryParams),o){var p=o[h].entry;p.extendQuery(n),u.push(p.parent.itemId),l=l.concat(p.getIdArray())}return this.itemRequestService.requestLinkItems(t,u,e,this.queryService.addAndCondition(this.collectionEntryService.createQuery(r).object,this.queryService.createNotIn(l)),r.columns).then(function(n){return a.itemRequestService.processLinkResponse(n,t,u,e,r)},this.errorHandler.reject).then(function(t){for(var e={},r=0,n=u;r<n.length;r++){var s=n[r],a=o[s],l=a.entry.addItems(t.items[s],a,!0,c,!1);e[s]=i?a.items:l}return e},this.errorHandler.reject)},t.prototype.batchFetch=function(t,e,r,n,o,i,s){var c=this,a=this.errorHandler,u=this.batchStatusFactory.construct(r,function(t){return t.parent.itemId},function(t){return t.promise});E(e)&&(e=e());for(var l=0,h=e;l<h.length;l++){var p=h[l];u.add(this.getEntryStatus(r,this.collectionEntryService.cloneOptions(n,{itemType:t,itemId:p}),i,s))}return u.getPromises().then(function(){var i,s,l=u.getRequestIds();if(null===n.query)s=null;else{var h=c.queryParserFactory.construct(n.query,n.queryParams).parse();s={object:h[0],string:h[1]}}if(l.length>0)i=c.itemRequestService.requestLinkItems(t,l,r,null===s?null:s.object,n.columns).then(function(e){return c.itemRequestService.processLinkResponse(e,t,l,r,n)},a.reject);else{if(!u.hasEntries([T.LOCAL]))return u.getMap();i=c.columnHandler.fetch(r,n.columns).then(function(t){return{columns:c.columnSetFactory.construct(r,n.columns,t,!1)}},a.reject)}return i.then(function(n){var i=o.batchGetLocalByParent(t,e,r,s),l=[];for(var h in i)l=l.concat(i[h]);return c.expandLocalItemEntries(r,l,n.columns,o).then(function(){return c.handleBatchResponse(u,n,i)},a.reject)},a.reject)},a.reject)},t.prototype.handleBatchResponse=function(t,e,r){var n={};return t.forEachEntry([T.CACHED],function(t,e){n[e]=t}),t.forEachEntry([T.RESOLVE],function(t,o){var i=e.items[o];n[o]=t.resolve({initial:i,modified:i.concat(r[o]),columns:e.columns})}),t.forEachEntry(t.remoteExpandStatus,function(t,r){t.expandColumns(e.columnExpansion),n[r]=t._resolve()}),t.forEachEntry([T.LOCAL],function(t,o){n[o]=t.resolve({initial:r[o],columns:e.columns})}),n},t.prototype.fetch=function(t,e,r,n,o){var i=this.getEntryStatus(t,e,n,o);return this.resolveCached(i.entry,i.status,e,r,n,o)},t.prototype.resolveCached=function(t,e,r,n,o,i){var s=this,c=this.errorHandler;switch(e){case T.CACHED:return this.promiseService.when(t);case T.PROMISED:return t.promise;case T.EXPAND:return t.expand(r.columns,n).then(function(){return t._resolve()},c.reject);case T.PROMISED_EXPAND:return t.promise.then(function(){return s.resolveCached(t,s.getCachedEntryStatus(t,r),r,n,o,i)},c.reject);case T.LOCAL:return this.resolveLocal(t,n);default:return this.resolveRemote(t,n)}},t.prototype.getCachedEntryStatus=function(t,e){return t.columns.isSupersetOf(e.columns)?t.isDeferred()?T.PROMISED:t.reloadQueued?(t.reloadQueued=!1,t.isLocal()?T.CACHED:(t.defer(),T.RESOLVE)):T.CACHED:t.isDeferred()?T.PROMISED_EXPAND:(t.defer(),T.EXPAND)},t.prototype.getDeferredEntryStatus=function(t,e,r,n){var o;return e.deferRequest?null!==(o=n.getByQuery(t,r))?(o.expandRequestColumns(e.columns),{entry:o,isDeferred:!1}):(o=this.collectionEntryFactory.construct(t,e),{entry:n.add(o),isDeferred:!0}):{entry:o=this.collectionEntryFactory.construct(t,e),isDeferred:!1}},t.prototype.getEntryStatus=function(t,e,r,n){var o,i,s,c=this.collectionEntryService.createQuery(e);return this.isLocal(e)?null!==(s=r.getByQuery(t,c))?{entry:s,status:this.getCachedEntryStatus(s,e)}:(s=(o=this.getDeferredEntryStatus(t,e,c,n)).entry,o.isDeferred?{entry:s,status:T.PROMISED}:{entry:r.add(s),status:T.LOCAL}):null!==(s=this.entries.getByQuery(t,c))?{entry:r.add(s),status:this.getCachedEntryStatus(s,e)}:(s=(i=this.getDeferredEntryStatus(t,e,c,n)).entry,i.isDeferred?{entry:s,status:T.PROMISED}:(r.add(s),this.entries.add(s),{entry:s,status:T.RESOLVE}))},t.prototype.resolveLocal=function(t,e){var r=this,n=t.itemType,o=t.options.columns;return this.columnHandler.fetch(n,o).then(function(i){var s=r.columnSetFactory.construct(n,o,i,!1);return r.expandLocalItemEntries(n,e.getLocalByQuery(n,t.query),s,e).then(function(e){return t.resolve({initial:e,columns:s})},r.errorHandler.reject)},this.errorHandler.reject)},t.prototype.resolveRemote=function(t,e){var r,n=this,o=this.errorHandler,i=t.itemType;return this.itemRequestService.requestItems(t).then(function(e){return r=n.columnSetFactory.construct(i,t.options.columns,e.fetchColumnsObject()),n.itemRequestService.processResponse(e,e.links[i],t.parent,r)},o.reject).then(function(s){return n.expandLocalItemEntries(i,e.getLocalByQuery(i,t.query),r,e).then(function(e){return t.resolve({initial:s,modified:s.concat(e),columns:r})},o.reject)},o.reject)},t.prototype.isLocal=function(t){var e=t.parent;return null!==e&&this.keyService.isLocalId(e.itemId)},t.prototype.expandLocalItemEntries=function(t,e,r,n){return this.itemHandler.expandLocalEntries(t,e,r.request,r.response,n)},t}(),dt=function(){function t(t,e,r,n,o){this.queryMatcherFactory=t,this.collectionCaches=e,this.updateInitial=r,this.callOnAdd=n,this.callOnActivate=o,this.map={}}return t.prototype.expand=function(t){var e=this.queryMatcherFactory.construct(t.itemType,t.getFields(),t.parent);return this._expand(t,function(t){return e.matchQuery(t.query.object)})},t.prototype._expand=function(t,e){for(var r=this.map,n=t.itemId,o=0,i=this.collectionCaches;o<i.length;o++)for(var s=0,c=i[o].getByItemType(t.itemType);s<c.length;s++){var a=c[s],u=a.id,l=void 0;void 0===r[u]&&(r[u]={collection:a,matches:{}}),void 0===(l=r[u].matches)[n]&&(l[n]={item:t,isMatch:e(a)})}return this},t.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},t.prototype.addToCollections=function(t){var e;for(var r in void 0===t&&(t=null),this.map){var n=this.map[r],o=n.collection,i=this.groupItemEntries(n.matches),s=i.fitting;o.isDeferred()||(null!==t&&o===t.entry?e=o.addItems(s,t,this.updateInitial,this.callOnAdd,this.callOnActivate):o.addItems(s,null,this.updateInitial,this.callOnAdd,this.callOnActivate),this.updateInitial&&i.maybe.length>0&&o.extend(ge,null,!0))}return void 0!==e?e:null!==t?[]:null},t.prototype.removeFromCollections=function(t){void 0===t&&(t=null);var e=null;for(var r in this.map){var n=this.map[r],o=n.collection,i=this.groupItemIds(n.matches).fitting;null===t||o!==t.entry?e=o.removeItems(i,t,this.updateInitial):o.removeItems(i,null,this.updateInitial)}return e},t.prototype.removeFromAndAddToCollections=function(){for(var t in this.map){var e=this.map[t],r=e.collection,n=this.groupItemEntries(e.matches);r.removeItems(n.notFitting,null,this.updateInitial),r.addItems(n.fitting,null,this.updateInitial),this.updateInitial&&n.maybe.length>0&&r.extend(ge,null,!0)}},t.prototype.groupItemEntries=function(t){var e=[],r=[],n=[];for(var o in t){var i=t[o],s=i.item,c=i.isMatch;!0===c?e.push(s):!1===c?r.push(s.itemId):n.push(s)}return{fitting:e,notFitting:r,maybe:n}},t.prototype.groupItemIds=function(t){var e=[],r=[];for(var n in t){var o=t[n];(!1===o.isMatch?r:e).push(o.item.itemId)}return{fitting:e,notFitting:r}},t.prototype.hasFittingItems=function(t){for(var e in t)if(!0===t[e].isMatch)return!0;return!1},t}(),mt=function(){function t(){}return t.prototype.processOptions=function(t){return new $(t)},t.prototype.getIdArray=function(t){for(var e=[],r=0,n=t;r<n.length;r++){var o=n[r];e.push(o.entry.itemId)}return e},t}(),yt=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],o=e.id;return void 0===n[o]&&(n[o]=e),n[o]},t.prototype.setColumns=function(t,e,r){var n={};for(var o in r){var i=r[o];for(var s in n[o]={},i)n[o][s]=this.setColumn(o,i[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 o=0,i=e;o<i.length;o++){var s=i[o];this.retrieveColumn(t,s,r,n)}},t.prototype.retrieveColumn=function(t,e,r,n){var o,i=this.columnUtil.parseRequestColumn(e),s=this.getColumn(t,i.id);if(void 0!==s){if(void 0===n[t]&&(n[t]={}),n[t][i.id]=s,0!==i.children.length){var c=[];this.retrieveColumns(s.itemType,i.children,c,n),0!==c.length&&r.push(((o={})[i.id]=c,o))}}else r.push(e)},t.prototype.getColumn=function(t,e){var r=this.cache[t];if(void 0!==r)return r[e]},t}(),vt=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 o in this.requestColumnsTrue=!0,this.requestColumns=[],n[e])this.requestColumns.push(o);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[c(t)];return null!==e?e.difference.root:[]}var r={};for(var n in t){var o=t[n];null!==o&&this.expandRootColumnMap(o.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 o=n[r],i=o.id;void 0===e[i]&&(e[i]={apiColumn:o.apiColumn,children:{}}),this.expandRootColumnMap(o.children,e[i].children)}},t}(),gt=function(){function t(t,e,r,n,o){this.apiRequestService=t,this.errorHandler=e,this.promiseService=r,this.cache=n,this.columnUtil=o}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 o=n[r];e[o]=this.fetch(o,["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,o=this;return void 0===r&&(r={filter:!1}),this.apiRequestService.columns(t,(n={},n[t]=e,n),r).then(function(r){return o.cache.setColumns(t,e,r.fetchColumnsObject())},this.errorHandler.reject)},t.prototype.fetch=function(t,e,r){var n=this,o=this.cache.retrieve(t,e);return!0!==o.missing&&0===o.missing.length?this.promiseService.when(o.cached):this.request(t,o.missing,r).then(function(t){return n.columnUtil.mergeResponseColumns(t,o.cached).merged})},t.prototype.fetchAll=function(t){return this.cache.containsAll(t)?this.promiseService.when(this.cache.getColumns(t)):this.request(t,!0)},t}(),Ct=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+D+r,this.tailPath=0===e.level?r:e.tailPath+D+r)}return t.prototype.setChildren=function(t,e){return this.itemType=t,this.children=e,this.isLeaf=!1,this},t}(),It={},St=0,Rt=function(){function t(t,e,r,n,o,i){this.columnHandler=t,this.columnUtil=e,this.columnInfoFactory=r,this.columnSetFactory=n,this.itemType=o,this.request=i,this.id=++St,this.response=It,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=[],this.requestColumnsTrue=!0===this.request}return 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.resolve=function(t,e,r){return void 0===e&&(e=!0),void 0===r&&(r=!0),this.requestColumnsTrue?this.processResponseColumns(t,e):this.processRequestColumns(t,e,r),this},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,o=t;n<o.length;n++){var i=o[n];if(!e.containsColumn(i,r))return!1}return!0},t.prototype.processResponseColumns=function(t,e){var r=this.itemType;for(var n in this.request=[],this.response=e?this.columnHandler.setColumns(this.itemType,!0,t):t,t[r])this.groupColumnInfo(this.columnInfoFactory.construct(t[r][n],null)),this.request.push(n)},t.prototype.processRequestColumns=function(t,e,r){var n=this.itemType,o={};this.createRootColumnMap(this.request,n,t,o,e),r&&this.createRootColumnMap(["id"],n,t,o,e),this.response={},this.processColumnInfo(this.columnInfoFactory.constructFromRootMap(o),n)},t.prototype.processColumnInfo=function(t,e){var r=this.response;void 0===r[e]&&(r[e]={});for(var n=0,o=t;n<o.length;n++){var i=o[n];r[e][i.id]=i.apiColumn,this.groupColumnInfo(i),i.isLeaf||this.processColumnInfo(i.children,i.itemType)}},t.prototype.createRootColumnMap=function(t,e,r,n,o){for(var i=0,s=t;i<s.length;i++){var c=s[i],a=this.columnUtil.parseRequestColumn(c),u=a.id,l=a.children,h=void 0;void 0!==r[e]&&(h=r[e][u]),void 0!==h?(o&&(h=this.columnHandler.setColumn(e,h)),void 0===n[u]&&(n[u]={apiColumn:h,children:{}}),0!==l.length&&this.createRootColumnMap(l,h.itemType,r,n[u].children,o)):console.warn("No api column for request column",u,"for itemType",e)}},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.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),o=this.mergeResponseColumns(r);return{merged:this.getMergedColumnSet(n,o,e),difference:this.columnSetFactory.construct(this.itemType,n.difference,o,!1,!1)}},t}(),Et=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}(),Ft=function(){function t(){}return t.prototype.getColumnPath=function(t,e){for(var r="",n="",o=0,i=t;o<i.length;o++){n+=r+i[o].id,r=D}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 o=0,i=r.children;o<i.length;o++){var s=i[o];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,o=e;n<o.length;n++){var i,s=o[n],c=this.parseRequestColumn(s),a=c.children,u=r[t];if(void 0===u)return!1;if(void 0===(i=u[c.id]))return!1;if(a.length>0&&!this.responseColumnsAvailable(i.itemType,a,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 o=n[r];e.push(this.copyRequestColumn(o))}return e},t.prototype.copyRequestColumn=function(t){var e,r=this.parseRequestColumn(t);if(0===r.children.length)return r.id;for(var n=[],o=0,i=r.children;o<i.length;o++){var s=i[o];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=[],o=0,i=e;o<i.length;o++){var s=i[o],c=this.mergeRequestColumn(s,r);null!==c&&n.push(c)}return{merged:r,difference:n}},t.prototype.mergeRequestColumn=function(t,e){var r,n,o=this.parseRequestColumn(t),i=this.findRequestColumn(o.id,e);if(-1===i)return e.push(t),t;if(0===o.children.length)return null;"string"==typeof e[i]&&(e[i]=((r={})[o.id]=[],r));for(var s=[],c=0,a=o.children;c<a.length;c++){var u=a[c],l=this.mergeRequestColumn(u,e[i][o.id]);null!==l&&s.push(l)}return 0===s.length?null:((n={})[o.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 o in t)if(void 0!==e[o]){var i=this.mergeResponseColumnMap(t[o],e[o]);r[o]=i.merged,n[o]=i.difference}else r[o]=t[o];for(var o in e)void 0===t[o]&&(r[o]=e[o],n[o]=e[o]);return{merged:r,difference:n}},t.prototype.mergeResponseColumnMap=function(t,e){var r={},n={};for(var o in t)r[o]=t[o];for(var o in e)L(t[o])||(r[o]=e[o],n[o]=e[o]);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 o=n[r];this.isLocalColumnId(o)||this.processConfigColumn(this.parseConfigColumn(o),e)}return e},t.prototype.parseConfigColumn=function(t){return t.split(":")[0].split(D)},t.prototype.processConfigColumn=function(t,e){var r,n,o=t[0],i=1===t.length,s=this.findRequestColumn(o,e);i?-1===s&&e.push(o):(-1===s?s=e.push(((r={})[o]=[],r))-1:"string"==typeof e[s]&&(e[s]=((n={})[o]=[],n)),this.processConfigColumn(t.slice(1),e[s][o]))},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}(),qt=function(){function t(t,e,r,n,o,i,s,c){void 0===c&&(c=!1),this.collectionHandler=t,this.collectionMatcherFactory=e,this.keyService=r,this.requestColumnExpansionFactory=n,this.compilation=o,this.localCollectionCache=i,this.parameterMap=s,this.breakupByParent=c,this.requests=[]}return t.prototype.finalizeRequest=function(t){for(var e=t.collections.getCollectionsWithFittingItems(),r=t.columns,n=0,o=e;n<o.length;n++){var i=o[n];r.expand(i.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 o=this.initializeRequest();this.extendRequest(r[n],this.setRequestParent(e,o)?+n:null,o),this.requests.push(this.finalizeRequest(o))}}else for(var e in t){r=t[e],o=this.initializeRequest();var i=this.setRequestParent(e,o),s=!1;for(var n in r)this.keyService.isLocalId(n)||(this.extendRequest(r[n],i?+n:null,o),s=!0);s&&this.requests.push(this.finalizeRequest(o))}return this.requests},t.prototype.initializeRequest=function(){return{request:{requestType:"create",items:{},columns:{}},columns:this.requestColumnExpansionFactory.construct(),items:{},collections:this.collectionMatcherFactory.construct([this.localCollectionCache,this.collectionHandler.entries],!0,!0,!1)}},t.prototype.extendRequest=function(t,e,r){var n=r.request,o=r.items;for(var i in t)for(var s in void 0===n.itemType&&(n.itemType=i),void 0===o[i]&&(o[i]={},n.items[i]={}),t[i]){var c=t[i][s],a=f(this.compilation,[i,s]),u=n.items[i][s]={},l=f(this.parameterMap,[i,s]);if(null!==e&&(n.parentId[s]=e),r.columns.expand(c.columns),r.collections.expand(c),o[i][s]=c,u.values=c.formatRequest(),u.parameters=l,void 0!==a){var h=u.links={};for(var p in a)for(var d in h[p]=[],a[p])h[p].push(parseInt(d,10));this.extendRequest(a,null,r)}}},t}(),bt=function(){function t(t,e,r,n,o,i,s,c,a,u,l,h,p,f,d){this.apiRequestService=t,this.authInterface=e,this.collectionHandler=r,this.collectionMatcherFactory=n,this.collectionResourceFactory=o,this.columnSetFactory=i,this.errorHandler=s,this.itemHandler=c,this.itemRequestService=a,this.itemResourceFactory=u,this.keyService=l,this.localCacheManager=h,this.moduleChangesCompilationFactory=p,this.promiseInterface=f,this.queryService=d}return t.prototype.invalidateCache=function(){this.itemHandler.entries.forEach(function(t){return t.queueReload()}),this.collectionHandler.entries.forEach(function(t){return t.queueReload()})},t.prototype.clearResources=function(t){this.itemResourceFactory.cache.clearResources(t),this.collectionResourceFactory.cache.clearResources(t)},t.prototype.getCollectionMatcher=function(t,e,r){void 0===e&&(e=!0),void 0===r&&(r=!0);for(var n=this.getLocalCache(),o=this.collectionMatcherFactory.construct([n.collections],!1,r,!0),i=0,s=t;i<s.length;i++){var c=s[i];e&&n.items.add(c),o.expand(c)}return o},t.prototype.fetchTitle=function(t,e,r){return this.itemHandler.fetchTitle(t,e,r,this.getLocalCache().items)},t.prototype.getItemById=function(t,e,r,n,o){void 0===r&&(r={});var i=this.getLocalCache();return this.itemHandler.fetchItem(t,e,new U(r),i.items).then(function(t){return i.createItemResource(t,r,n,o)},this.errorHandler.reject)},t.prototype.getItemsById=function(t,e,r,n){void 0===r&&(r={});var o=this.getLocalCache();return this.itemHandler.fetchItems(t,e,new U(r),o.items).then(function(t){return o.createItemResources(t,r,n)},this.errorHandler.reject)},t.prototype.getItemsByQuery=function(t,e,r,n){var o,i=this;void 0===r&&(r={});var s=this.getLocalCache(),c=new U(r);return this.apiRequestService.query(t,this.queryService.addParentCondition(e,c.parent),(o={},o[t]=c.columns,o)).then(function(e){return i.itemRequestService.processResponse(e,e.links[t],c.parent,i.columnSetFactory.construct(t,c.columns,e.fetchColumnsObject()))},this.errorHandler.reject).then(function(t){return s.createItemResources(t,r,n)},this.errorHandler.reject)},t.prototype.getNewResource=function(t,e,r,n,o){var i=this;void 0===e&&(e={}),void 0===r&&(r=!1);var s=this.getLocalCache();return e.edit=!0,this.itemHandler.fetchNewItem(t,new U(e),s.items).then(function(t){var c=s.createItemResource(t.main,e,n,o,!0),a=i.processLinkedItems(t.linked,e,n,!0);return r?{main:c,linked:a}:c},this.errorHandler.reject)},t.prototype.getDuplicateById=function(t,e,r,n,o,i){return void 0===r&&(r={}),r.isDuplicate=!0,void 0===r.templateOptions&&(r.templateOptions={}),void 0===r.templateOptions.item&&(r.templateOptions.item=e),this.getNewResource(t,r,o,n,i)},t.prototype.getItemByState=function(t,e,r,n,o){void 0===r&&(r={});var i=this.keyService.parseStateKey(e);if(null===i){var s=e;if(!this.keyService.isLocalId(s)||this.getLocalCache().items.contains(t,s))return this.getItemById(t,s,r,n,o)}else if("duplicate"===i.type)return this.getDuplicateById(t,i.itemId,r,n,!1,o);return this.getNewResource(t,r,!1,n,o)},t.prototype.getCollectionDef=function(t,e){return{itemType:t,options:{entry:new Z(e),resource:new $(e)}}},t.prototype.getLinkCollectionsDef=function(t,e,r){return{itemType:t,linkField:e,options:{entry:new Z(r),resource:new $(r)}}},t.prototype.getCollection=function(t,e,r){var n=this.getLocalCache();return this.collectionHandler.fetch(t,new Z(e),n.items,n.collections,n.deferredCollections).then(function(t){return n.createCollectionResource(t,new $(e),r)},this.errorHandler.reject)},t.prototype.getCollectionFromDef=function(t,e){var r=this.getLocalCache();return this.collectionHandler.fetch(t.itemType,t.options.entry,r.items,r.collections,r.deferredCollections).then(function(n){return r.createCollectionResource(n,t.options.resource,e)},this.errorHandler.reject)},t.prototype.getLinkCollections=function(t,e,r,n,o){var i=this.getLocalCache();return this.collectionHandler.batchFetch(t,e,r,new Z(n),i.items,i.collections,i.deferredCollections).then(function(t){return i.createCollectionResources(t,n,o)},this.errorHandler.reject)},t.prototype.getLinkCollectionsFromDef=function(t,e,r,n){var o=this.getLocalCache();return this.collectionHandler.batchFetch(t,e,r.itemType,r.options.entry,o.items,o.collections,o.deferredCollections).then(function(t){return o.createCollectionResources(t,r.options.resource,n)},this.errorHandler.reject)},t.prototype.getAllLinkCollections=function(t,e,r,n){var o=this;return this.apiRequestService.query(t,{},{}).then(function(i){return o.getLinkCollections(t,i.links[t],e,r,n)},this.errorHandler.reject)},t.prototype.cloneItem=function(t,e,r){return this.addSingleItem(t.entry.clone(),e,r,!1)},t.prototype.cloneCollection=function(t,e,r,n){var o=e.parent;return void 0===o&&(o=null),this.addCollection(t.entry.clone(o,r),e,n)},t.prototype.saveCurrentLocalCache=function(t,e,r,n){return this.getLocalCache().save(t,e,r,n)},t.prototype.getCurrentCollections=function(){return this.getLocalCache().collections},t.prototype.getCurrentItems=function(){return this.getLocalCache().items},t.prototype.getModuleChanges=function(t){if(void 0===t&&(t=this.getLocalCache()),void 0===t.rootItem)throw new Error("itemAdministrator: No root item for local cache "+t.id);return this.moduleChangesCompilationFactory.construct(t.rootItem,t.items,t.collections).process()},t.prototype.addSingleItem=function(t,e,r,n,o){return void 0===e&&(e={}),void 0===o&&(o=this.getLocalCache()),o.createItemResource(o.items.add(t),e,r,n)},t.prototype.addSingleItems=function(t,e,r){for(var n=this.getLocalCache(),o=[],i=0,s=t;i<s.length;i++){var c=s[i];o.push(this.addSingleItem(c,e,r,!1,n))}return o},t.prototype.addCollection=function(t,e,r){var n=this.getLocalCache();return n.collections.add(t),n.createCollectionResource(t,e,r)},t.prototype.createItemResources=function(t,e,r,n,o){for(var i=[],s=0,c=e;s<c.length;s++){var a=c[s];i.push(o.createItemResource(a,r,n)),"Projectnotitie"===t&&p(o.tabRequestParameters,[a.itemType,a.itemId],[{},{no_notification:!0}])}return i},t.prototype.processLinkedItems=function(t,e,r,n){void 0===n&&(n=!0);for(var o=this.getLocalCache(),i={},s=0,c=t;s<c.length;s++){i[(l=c[s]).itemType]=this.createItemResources(l.itemType,l.itemEntries,e,r,o)}if(!n)return i;for(var a=0,u=t;a<u.length;a++){var l=u[a];this.getCollectionMatcher(l.itemEntries,!1).addToCollections()}return i},t.prototype.expandProcessLinkedItems=function(t,e,r){for(var n=this.getLocalCache(),o=this.promiseInterface.when({}),i=0,s=t;i<s.length;i++){var c=s[i];o=o.then(this.constructOnItemsExpanded(c.itemType,c.itemEntries,r,e,n),this.errorHandler.reject)}return o},t.prototype.constructOnItemsExpanded=function(t,e,r,n,o){var i=this;return function(s){return i.expandAddToCollections(t,e,null,o).then(function(){return s[t]=i.createItemResources(t,e,r,n,o),s},i.errorHandler.reject)}},t.prototype.expandAddToCollections=function(t,e,r,n){void 0===r&&(r=null),void 0===n&&(n=this.getLocalCache());for(var o=this.collectionMatcherFactory.construct([n.collections],!1,!0,!1),i=0,s=e;i<s.length;i++){var c=s[i];o.expand(c)}var a=this.getColumnSuperset(o.getCollectionsWithFittingItems());return null===a?this.promiseInterface.when(null===rt?null:[]):this.itemHandler.expandLocalEntries(t,e,a.request,a.response,n.items).then(function(){return o.addToCollections(r)},this.errorHandler.reject)},t.prototype.getColumnSuperset=function(t){var e={};if(0===t.length)return null;for(var r=t[0].columns,n=1;n<t.length;n++){var o=t[n].columns;!0!==e[o.id]&&(e[o.id]=!0,r=r.merge(o))}return r},t.prototype.getLocalCache=function(){return this.localCacheManager.getCurrentLocalCache(this.authInterface.getUniqueUserId())},t.prototype.addToCollections=function(t,e,r){return void 0===r&&(r=!0),this.getCollectionMatcher(t,!0,r).addToCollections(e)},t.prototype.removeFromCollections=function(t,e){return this.getCollectionMatcher(t,!1).removeFromCollections(e)},t.prototype.saveLocal=function(t){var e=t.entry;return e.setDisplayName(),this.addToCollections([e]),this.promiseInterface.when(t)},t.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])}},t.prototype.createCollectionResource=function(t,e,r){return this.addCollection(t,e,r)},t.prototype.createItemResource=function(t,e,r,n){return this.addSingleItem(t,e,r,n)},t.prototype.onBeforeSave=function(t,e,r){return this.getLocalCache().onBeforeSave(t,e,r)},t.prototype.onSaveSuccess=function(t,e,r){return this.getLocalCache().onSaveSuccess(t,e,r)},t}(),Ot=function(){function t(t){this.queryMatcherFactory=t,this.entries={}}return 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 o in r){var i=r[o];i.isDeferred()||this.matchQuery(i,e)&&n.push(i)}return n},t.prototype.getLocalByQuery=function(t,e){var r=this.entries[t],n=[];if(void 0===r)return n;for(var o in r){var i=r[o];i.isLocal()&&(this.matchQuery(i,e)&&n.push(i))}return n},t.prototype.getByParent=function(t,e,r){var n=this.entries[r],o=[];if(void 0===n)return o;for(var i in n){var s=n[i],c=s.parent;null!==c&&(c.itemType===t&&c.itemId==e&&o.push(s))}return o},t.prototype.batchGetLocalByParent=function(t,e,r,n){for(var o=this.entries[r],i={},s=0,c=e;s<c.length;s++){i[c[s]]=[]}if(void 0===o)return i;for(var a in o){var u=o[a],l=u.parent;null!==l&&(l.itemType===t&&void 0!==i[l.itemId]&&u.isLocal()&&(null===n||this.matchQuery(u,n))&&i[l.itemId].push(u))}return i},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.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={},!0):this.clearByItemId(t.itemType,t.itemId)},t.prototype.clearByItemId=function(t,e){var r=this.entries[t];return void 0!==r&&delete r[e]},t.prototype.matchQuery=function(t,e){return!0===this.queryMatcherFactory.construct(t.itemType,t.getFields(),t.parent).matchQuery(e.object)},t}(),Lt=function(){function t(t,e){this.authInterface=t,this.keyService=e}return t.prototype.processOptions=function(t){return new U(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.createLocalConversionMap=function(t,e,r,n){void 0===r&&(r=!1);var o=n.links[t][0],i={};return i[t]={},i[t][o]=e,r&&this.expandLocalConversionMap(t,o,n,i),i},t.prototype.expandLocalConversionMap=function(t,e,r,n){var o=r.items[t][e].links;for(var i in o){var s=o[i];void 0===n[i]&&(n[i]={});for(var c=0,a=s;c<a.length;c++){var u=a[c];n[i][u]=this.keyService.getLocalId(),this.expandLocalConversionMap(i,u,r,n)}}},t.prototype.expandConversionMap=function(t,e,r){var n,o=t.itemType,i=t.itemId;return void 0===e[o]&&(e[o]={}),void 0!==(n=e[o])[i]?n[i]:(void 0===r&&(r=this.keyService.getLocalId()),n[i]=r)},t.prototype.batchExpandConversionMap=function(t,e){for(var r=0,n=t;r<n.length;r++){var o=n[r];this.expandConversionMap(o,e)}return e},t.prototype.getConversionValue=function(t,e,r){if(void 0!==r[t])return r[t][e]},t.prototype.batchClone=function(t,e){void 0===e&&(e={});var r=[];this.batchExpandConversionMap(t,e);for(var n=0,o=t;n<o.length;n++){var i=o[n];r.push(i.clone(e))}return r},t.prototype.getFullName=function(t,e,r){return t.trim().concat(" ",e).trim().concat(" ",r)},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.prototype.hasLocalDefaultValue=function(t){switch(t){case"permissions":case"creator":case"created":return!0;default:return!1}},t}(),Mt=function(){function t(t,e,r,n,o,i,s,c,a,u,l,h,p,f,d){this.apiFormatter=t,this.apiRequestService=e,this.batchStatusFactory=r,this.columnExpansionFactory=n,this.columnHandler=o,this.columnSetFactory=i,this.columnSubsetCacheFactory=s,this.columnUtil=c,this.errorHandler=a,this.itemCacheFactory=u,this.itemEntryFactory=l,this.itemEntryService=h,this.keyService=p,this.promiseService=f,this.templateFactory=d,this.templates={},this.entries=this.itemCacheFactory.construct()}return t.prototype.fetchItem=function(t,e,r,n){var o=this.getEntryStatus(t,e,r.parent,r.deferRequest,n,!0,this.columnSubsetCacheFactory.construct(r.columns));return null===o?this.errorHandler.reject(this.itemEntryService.createUnfoundLocalItemError(t)):this.resolveCached(o.entry,o.status,r,n)},t.prototype.fetchNewItem=function(t,e,r){var n=this,o=r.add(this.itemEntryFactory.constructDeferred(t,e.isDuplicate?this.keyService.getLocalDuplicateId():this.keyService.getLocalId(),!0,!1));return this.fetchTemplate(t,e.templateOptions,e.templateColumns).then(function(t){return n.resolveLocal(o,e.parent,t,r)},function(t){return o.reject(t),n.errorHandler.reject(t)})},t.prototype.createBatchStatus=function(t,e,r,n,o,i,s){for(var c=this.columnSubsetCacheFactory.construct(n),a=this.batchStatusFactory.construct(t,function(t){return t.itemId},function(t){return t.getPromise()}),u=!0,l=0,h=e;l<h.length;l++){var p=h[l],f=this.getEntryStatus(t,p,r,o,i,s,c);null!==f?a.add(f):u=!1}return{batchStatus:a,success:u}},t.prototype.fetchItems=function(t,e,r,n){var o,i,s=this,c=this.errorHandler,a=r.columns,u=this.createBatchStatus(t,e,r.parent,a,r.deferRequest,n,!0),l=u.batchStatus,h=u.success;return l.hasRequests()?i=(o=this.requestItems(t,l.getRequestIds(),a)).then(function(t){return t.fetchColumnsObject()},function(t){return l.forEachEntry([T.RESOLVE],function(t){return s.clearItem(t,n)}),c.reject(t)}):l.hasEntries(l.localExpandStatus)?(o=null,i=this.columnHandler.fetch(t,a)):(o=null,i=null),this.promiseService.all({entries:l.getPromises(),response:o,columns:i}).then(function(t){return s.handleBatchResponse(l,n,a,t.response,t.columns)},c.reject).then(function(t){return t&&h?l.getArray():c.reject()},c.reject)},t.prototype.handleBatchResponse=function(t,e,r,n,o,i){var s=this,c=t.itemType,a=!0;if(t.hasEntries([T.RESOLVE])){var u=this.columnSetFactory.construct(c,r,o);t.forEachEntry([T.RESOLVE],function(t){s.resolveRemote(t,u,n,e)||(a=!1)})}return t.forEachEntry([T.RESOLVE_VALUES],function(t){s.resolveRemoteValues(t,n)||(a=!1)}),t.hasEntries(t.remoteExpandStatus)&&(void 0===i&&(i=this.columnExpansionFactory.construct(c,r,o)),t.forEachEntry(t.remoteExpandStatus,function(t){return s.resolveExpansion(t,i,n)})),t.hasEntries(t.localExpandStatus)?this.expandLocalEntries(c,t.getArray(t.localExpandStatus),r,o,e).then(function(t){for(var e=0,r=t;e<r.length;e++){r[e].resolve()}return a},this.errorHandler.reject):this.promiseService.when(a)},t.prototype.resolveCached=function(t,e,r,n){var o,i=this,s=this.errorHandler,c=function(e){t.reject(e)};switch(e){case T.LOCAL:case T.CACHED:return this.promiseService.when(t);case T.PROMISED:return t.getPromise();case T.EXPAND:return o=this.getColumnDifference(t,r.columns),this.requestItem(t,o).then(function(e){i.resolveExpansion(t,i.columnExpansionFactory.construct(t.itemType,o,e.fetchColumnsObject()),e)},s.reject).catch(c),t.getPromise();case T.EXPAND_LOCAL:return o=this.getColumnDifference(t,r.columns),this.columnHandler.fetch(t.itemType,o).then(function(e){return i.expandLocalEntries(t.itemType,[t],o,e,n).then(function(){return t.resolve()},c)},c),t.getPromise();case T.PROMISED_EXPAND:case T.PROMISED_EXPAND_LOCAL:return t.getPromise().then(function(){return i.resolveCached(t,i.getCachedEntryStatus(t,i.columnSubsetCacheFactory.construct(r.columns)),r,n)},s.reject);case T.RESOLVE_VALUES:return this.requestItem(t).then(function(e){i.resolveRemoteValues(t,e)},s.reject).catch(c),t.getPromise();case T.RESOLVE:return this.requestItem(t).then(function(e){i.resolveRemote(t,t.columns.resolve(e.fetchColumnsObject()),e,n)},s.reject).catch(function(e){i.clearItem(t,n),t.reject(e)}),t.getPromise()}},t.prototype.getColumnDifference=function(t,e){return this.columnUtil.mergeRequestColumns(t.columns.request,e).difference},t.prototype.resolveLocal=function(t,e,r,n){var o=t.itemType,i=t.itemId,s=this.itemEntryService.createLocalConversionMap(o,i,!0,r.response);return t.columns=r.columns,null!==e&&t.setParent(e.itemType,e.itemId),t.setLocalFields(r.fields,s).resolve(),{main:t,linked:this.createLocalEntries(o,i,r,s,n)}},t.prototype.resolveExpansion=function(t,e,r){var n=t.itemType,o=t.itemId,i=e.run(t.columns);return null===i?t:(t.expand(r.fetchObject(n,o),r.fetchDerivedObject(n,o,i.difference.root),i),t.resolve())},t.prototype.clearItem=function(t,e){this.entries.clear(t),e.clear(t)},t.prototype.resolveRemote=function(t,e,r,n){var o=this.getResponseFields(t,e,r);return null===o?(this.clearItem(t,n),t.reject(),!1):(t.resolveDeferred(o.initial,o.derived,e),!0)},t.prototype.resolveRemoteValues=function(t,e){var r=this.getResponseFields(t,t.columns,e);return null===r?(t.reject(),!1):(t.updateFields(r.initial,r.derived,!1).resolve(),!0)},t.prototype.getResponseFields=function(t,e,r){var n=t.itemType,o=t.itemId,i=r.fetchObject(n,o);return void 0===i?null:{initial:i,derived:r.fetchDerivedObject(n,o,e.root)}},t.prototype.fetchTemplate=function(t,e,r){var n=this;void 0===e&&(e={}),void 0===r&&(r={});var o=s(e),i=c(r);if(!o){var a=this.templates[t];if(void 0!==a&&(null===i||this.columnUtil.responseColumnsAvailable(i,r[i],a.responseColumns)))return this.promiseService.when(a)}return this.promiseService.all({template:this.apiRequestService.template(t,e),additionalColumns:null===i?{}:this.columnHandler.fetch(i,r[i])}).then(function(e){var r=e.template,i=n.templateFactory.construct(t,r,e.additionalColumns);return!o&&r.cacheable&&(n.templates[t]=i),i},this.errorHandler.reject)},t.prototype.getEntryStatus=function(t,e,r,n,o,i,s){var c;return this.keyService.isLocalId(e)?void 0!==(c=o.get(t,e))?{entry:c,status:this.getCachedEntryStatus(c,s)}:null:void 0!==(c=this.entries.get(t,e))?{entry:i?o.add(c):c,status:this.getCachedEntryStatus(c,s)}:(c=this.itemEntryFactory.constructDeferred(t,e,s.requestColumns,n),null!==r&&c.setParent(r.itemType,r.itemId),i&&o.add(c),this.entries.add(c),{entry:c,status:n?T.PROMISED:T.RESOLVE})},t.prototype.getCachedEntryStatus=function(t,e){var r=t.columns;return t.isDeferred()?t.deferRequest?(r.expandRequestColumns(e.requestColumns),T.RESOLVE):e.run(r)?T.PROMISED:t.isLocal()?T.PROMISED_EXPAND_LOCAL:T.PROMISED_EXPAND:e.run(r)?t.reloadQueued?(t.reloadQueued=!1,t.isLocal()?T.CACHED:(t.defer(),T.RESOLVE_VALUES)):T.CACHED:(t.defer(),t.isLocal()?T.EXPAND_LOCAL:T.EXPAND)},t.prototype.fetchTitle=function(t,e,r,n){void 0===r&&(r=!0);var o=this.itemEntryService.getTitleField(t);return this.fetchItem(t,e,new U({columns:[o],deferRequest:r}),n).then(function(t){return t.getFields()[o]},this.errorHandler.reject)},t.prototype.createLocalEntries=function(t,e,r,n,o,i){var s=this;void 0===i&&(i=function(){return!0});var c=r.response,a={},u={},l=[],h=function(t,e,p){var f={itemType:t,itemId:e},d=c.items[t][p].links;for(var m in d)if(d.hasOwnProperty(m)){void 0===a[m]&&l.push({itemType:m,itemEntries:a[m]=[],columnSet:u[m]=s.columnSetFactory.construct(m,!0,r.responseColumns)});for(var y=0,v=d[m];y<v.length;y++){var g=v[y],C=n[m][g],I=s.itemEntryFactory.constructLocalLinked(m,C,c.fetchObject(m,g),f,u[m],n);i(I)&&(o.add(I),a[m].push(I),h(m,C,g))}}};return h(t,e,c.links[t][0]),l},t.prototype.expandLocalEntries=function(t,e,r,n,o){if(0===e.length)return this.promiseService.when(e);for(var i=this.columnExpansionFactory.construct(t,r,n),s=0,c=e;s<c.length;s++){var a=c[s],u=i.run(a.columns);null!==u&&a.expandLocal(u)}return this.resolveDerivedValues(e,i.aggregateRootColumns(),o)},t.prototype.resolveDerivedValues=function(t,e,r){for(var n=[],o=0,i=e;o<i.length;o++){var s=i[o];n.push(this.fetchDerivedValuesByColumn(t,s,r))}return this.promiseService.all(n).then(function(){return t},this.errorHandler.reject)},t.prototype.setDefaultValuesByColumn=function(t,e){var r=e.children;if(0!==r.length)for(var n=0,o=r;n<o.length;n++)for(var i=o[n],s=0,c=t;s<c.length;s++){c[s].derived[i.path]=this.apiFormatter.getDefaultValue(i.apiColumn.type)}},t.prototype.getItemIdByColumn=function(t,e){return 0===e.level?"link"===e.apiColumn.type&&null!==t.parent?t.parent.itemId:t.getFields()[e.path]:t.derived[e.path]},t.prototype.fetchDerivedValuesByColumn=function(t,e,r){var n=this,o=e.children;if(0===o.length)return this.promiseService.when();var i=o[0];if(1===o.length&&"id"===i.apiColumn.type){for(var s=0,c=t;s<c.length;s++){(h=c[s]).derived[i.path]=this.getItemIdByColumn(h,e)}return this.promiseService.when()}for(var a={},u=0,l=t;u<l.length;u++){var h=l[u],p=this.getItemIdByColumn(h,e);void 0===a[p]&&(a[p]=[]),a[p].push(h)}void 0!==a.null&&this.setDefaultValuesByColumn(a.null,e);var f=[];for(var p in a)"null"!==p&&f.push(+p);if(0===f.length)return this.promiseService.when();for(var d=[],m=0,y=o;m<y.length;m++){var v=y[m];d.push(v.id)}return this.fetchItems(e.itemType,f,new U({columns:d}),r).then(function(e){for(var i=0,s=e;i<s.length;i++)for(var c=s[i],u=c.getFields(),l=0,h=a[c.itemId];l<h.length;l++)for(var p=h[l],f=0,d=o;f<d.length;f++){var m=d[f];p.derived[m.path]=u[m.id]}return n.resolveDerivedValues(t,o,r)},this.errorHandler.reject)},t.prototype.requestItem=function(t,e){return void 0===e&&(e=t.columns.request),this.requestItems(t.itemType,[t.itemId],e)},t.prototype.requestItems=function(t,e,r){var n;return this.apiRequestService.query(t,{id:e},((n={})[t]=r,n))},t}(),wt=function(){function t(t,e,r,n,o,i,s,c){this.apiRequestService=t,this.errorHandler=e,this.itemHandler=r,this.columnExpansionFactory=n,this.columnSetFactory=o,this.itemEntryFactory=i,this.queryService=s,this.promiseService=c}return t.prototype.requestItem=function(t,e,r){var n,o=((n={})[t]=r,n);return this.apiRequestService.query(t,{id:e},o)},t.prototype.requestItems=function(t,e,r){var n;void 0===e&&(e=t.query.object),void 0===r&&(r=t.options.columns);var o=t.itemType;return this.apiRequestService.requestSkeleton({requestType:"query",itemType:o,columns:(n={},n[o]=r,n),query:e,limit:t.options.limit})},t.prototype.requestLinkItems=function(t,e,r,n,o){var i,s=((i={})[r]=o,i);return null===n?this.apiRequestService.query(t,{id:e},s):this.apiRequestService.query(r,this.queryService.addAndCondition(n,{linkedTo:t,query:{id:e}}),s)},t.prototype.processExpansion=function(t,e,r,n){for(var o=this.columnExpansionFactory.construct(r,t,e.fetchColumnsObject()),i=0,s=n;i<s.length;i++){var c=s[i];c.isLocal()||this.handleCachedItem(c,e,o)}return o},t.prototype.processResponse=function(t,e,r,n,o){var i=this;void 0===o&&(o=this.columnExpansionFactory.construct(n.itemType,!!n.requestColumnsTrue||n.request,n.response));for(var s=this.itemHandler,c=n.itemType,a=n.root,u=[],l=[],h=0,p=e;h<p.length;h++){var f=p[h],d=s.entries.get(c,f);void 0===d?(d=this.itemEntryFactory.construct(f,t.fetchObject(c,f),t.fetchDerivedObject(c,f,a),n),s.entries.add(d),u.push(d)):d.isDeferred()?d.deferRequest?u.push(d.resolveDeferred(t.fetchObject(c,f),t.fetchDerivedObject(c,f,a),n)):l.push(d.getPromise()):d.reloadQueued?(d.reloadQueued=!1,d.updateFields(t.fetchObject(c,f),t.fetchDerivedObject(c,f,a),!1),u.push(d)):u.push(this.handleCachedItem(d,t,o)),null!==r&&(d.parent=r)}return this.promiseService.all(l).then(function(e){for(var r=0,n=e;r<n.length;r++){var s=n[r];u.push(i.handleCachedItem(s,t,o))}return u},this.errorHandler.reject)},t.prototype.handleCachedItem=function(t,e,r){var n=r.run(t.columns);return null===n?t:t.expand(e.fetchObject(t.itemType,t.itemId),e.fetchDerivedObject(t.itemType,t.itemId,n.difference.root),n)},t.prototype.processLinkResponse=function(t,e,r,n,o){for(var i=t.fetchColumnsObject(),s=this.columnSetFactory.construct(n,o.columns,i),c=this.columnExpansionFactory.construct(n,o.columns,i),a=t.items[e],u={},l=0,p=r;l<p.length;l++){var f=p[l];u[f]=h(a,[f,"links",n])?this.processResponse(t,a[f].links[n],{itemType:e,itemId:f},s,c):[]}return this.promiseService.all(u).then(function(t){return{items:t,columns:s,columnExpansion:c}},this.errorHandler.reject)},t}(),Tt=function(){function t(){this.separator=":"}return t.prototype.getSingleKey=function(t,e){return t+this.separator+e},t.prototype.getCssKey=function(){return Array.prototype.join.call(arguments,"_")},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}();!function(t){t.Always="always",t.OnClose="onClose",t.SkipOnClose="skipOnClose"}(N||(N={}));var xt,At,jt,kt,Dt=function(){function t(t,e,r,n,o,i,s,c,a,u,l){this.changesProcessor=t,this.collectionCacheFactory=e,this.collectionResourceFactory=r,this.errorHandler=n,this.exceptionHandler=o,this.itemCacheFactory=i,this.itemResourceFactory=s,this.lockService=c,this.promiseService=a,this.id=u,this.defaultResourceLevel=l,this.tabRequestParameters={},this.isSaving=!1,this.callbacks={onBeforeSave:{always:{},onClose:{},skipOnClose:{}},onSaveSuccess:{always:{},onClose:{},skipOnClose:{}}},this.changesInterval=null,this.hasChanges=!1,this.items=this.itemCacheFactory.construct(),this.collections=this.collectionCacheFactory.construct(),this.deferredCollections=this.collectionCacheFactory.construct()}return t.prototype.createItemResource=function(t,e,r,n,o){return void 0===r&&(r=this.defaultResourceLevel),void 0===n&&(n=!1),n&&(this.rootItem=t),this.itemResourceFactory.construct(t,e,r,this,o)},t.prototype.createItemResources=function(t,e,r){void 0===r&&(r=this.defaultResourceLevel);for(var n=this.itemResourceFactory.getConstructor(e,r,this),o=[],i=0,s=t;i<s.length;i++){var c=s[i];o.push(n(c))}return o},t.prototype.createCollectionResource=function(t,e,r){return void 0===r&&(r=this.defaultResourceLevel),this.collectionResourceFactory.construct(t,e,r,this)},t.prototype.createCollectionResources=function(t,e,r){var n={};for(var o in t)n[o]=this.createCollectionResource(t[o],e,r);return n},t.prototype.clearItem=function(t){this.clearItemEntry(t.entry)},t.prototype.clearItemEntry=function(t){this.items.clear(t),this.itemResourceFactory.cache.clearEntry(t)},t.prototype.clearCollection=function(t){var e=t.entry;this.collections.clear(e),this.collectionResourceFactory.cache.clearEntry(e)},t.prototype.clearDeferredCollections=function(){this.deferredCollections.clear()},t.prototype.updateSingleItems=function(t){for(var e in t)for(var r in t[e]){var n=this.items.get(e,parseInt(r,10));void 0!==n&&this.items.updateItemId(n,parseInt(r,10))}},t.prototype.revertChanges=function(){var t=this;return this.items.forEach(function(t){return t.resetModified()}),this.collections.forEach(function(e){return t.resetCollection(e)}),this.hasChanges=!1,this.isLockable()?this.lockService.deleteLock(this.rootItem):this.promiseService.when()},t.prototype.resetCollection=function(t){if(t.items=t.initial.slice(),t.hasItemEditResources)for(var e=0,r=t.items;e<r.length;e++){r[e].resetModified()}},t.prototype.detectChanges=function(){var t=this;return!!this.hasChanges||(this.items.some(function(t){return t.hasChanges()})?this.hasChanges=!0:this.hasChanges=this.collections.some(function(e){return t.collectionHasChanges(e)}))},t.prototype.collectionHasChanges=function(t){return!(!t.hasEditResources||!t.hasAddedItems()&&!t.hasRemovedItems())||t.hasItemEditResources&&t.hasUpdatedItems()},t.prototype.isLockable=function(){return void 0!==this.rootItem&&this.rootItem.isLockable()},t.prototype.save=function(t,e,r,n){var 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.executeCallbackEvent(o.callbacks.onBeforeSave,function(t){return t(o)},t)},this.errorHandler.reject).then(function(){var t=m({},o.tabRequestParameters,e);return o.tabRequestParameters={},o.changesProcessor.execute(o.items.toArray(),o.collections.toArray(),t,r,n)},this.errorHandler.reject).then(function(e){return o.isLockable()&&o.lockService.clearLock(o.rootItem),o.hasChanges=!1,t||o.updateSingleItems(e),o.executeCallbackEvent(o.callbacks.onSaveSuccess,function(t){return t(o,e)},t).then(function(){return t||o.enableChangesWatcher(),o.isSaving=!1,e},o.errorHandler.reject)},this.errorHandler.reject).catch(function(t){return o.isSaving=!1,o.errorHandler.reject(t)}))},t.prototype.onBeforeSave=function(t,e,r){void 0===r&&(r=N.Always);var n=this.callbacks.onBeforeSave[r];return n[t]=e,function(){return delete n[t]}},t.prototype.onSaveSuccess=function(t,e,r){void 0===r&&(r=N.Always);var n=this.callbacks.onSaveSuccess[r];return n[t]=e,function(){return delete n[t]}},t.prototype.executeCallbackEvent=function(t,e,r){var n=this;return this.executeCallbacks(t[N.Always],e).then(function(){return n.executeCallbacks(t[r?N.OnClose:N.SkipOnClose],e)},this.errorHandler.reject)},t.prototype.executeCallbacks=function(t,e){var r={};for(var n in t)try{r[n]=e(t[n])}catch(t){this.exceptionHandler(t)}return this.promiseService.all(r)},t.prototype.enableChangesWatcher=function(){var t=this;null!==this.changesInterval&&(console.warn("Changes watcher already running!",this),this.disableChangesWatcher()),this.changesInterval=setInterval(function(){t.detectChanges()&&(t.disableChangesWatcher(),t.isLockable()&&t.lockService.fetchLock(t.rootItem))},3e3)},t.prototype.disableChangesWatcher=function(){null!==this.changesInterval&&(clearInterval(this.changesInterval),this.changesInterval=null)},t.prototype.onDeactivateItem=function(t){this.clearItemEntry(t)},t.prototype.onActivateItem=function(t){this.items.add(t)},t}(),Ht=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.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.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 o=e[r][n];if(!o.isForeign&&o.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,o=this.apiRequestService.create("Locktoken",this.keyService.getLocalId(),{itemtype:r,item:n}).then(function(o){return delete e.promises[r][n],e.setValue(t,o.fetchObject("Locktoken",o.links.Locktoken[0]),e.lockItems)},function(o){return delete e.promises[r][n],301===o.code?e.setValue(t,{isForeign:!0,message:o.message},e.lockItems):e.errorHandler.reject(o)});return this.setValue(t,o,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}(),Pt={},_t=function(){function t(t,e,r){this.rootItemEntry=t,this.singleItemCache=e,this.collectionCache=r,this.parentMap={},this.destination={}}return t.prototype.process=function(){return this.parentMap=this.createParentMap(this.singleItemCache),this.processItems(this.rootItemEntry.itemType,[this.rootItemEntry],{}),{itemType:this.rootItemEntry.itemType,itemId:this.rootItemEntry.itemId,items:this.destination}},t.prototype.createParentMap=function(t){var e={};return t.forEach(function(t){var r=t.itemType,n=t.parent;if(null!==n){var o=n.itemType,i=n.itemId;void 0===e[o]&&(e[o]={}),void 0===e[o][i]&&(e[o][i]={}),void 0===e[o][i][r]&&(e[o][i][r]=[]),e[o][i][r].push(t)}}),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,o=e;n<o.length;n++){var i=o[n],s=i.itemId;void 0===this.destination[t][s]&&(r[t].push(s),this.destination[t][s]=this.processItem(i))}},t.prototype.processItem=function(t){var e=t.itemType,r=t.itemId,n=this.getItemsByParent(e,r),o=this.collectionCache.getCollectionsByParent(e,r),i=t.formatRequest(),c={};for(var a in n)this.processItems(a,n[a],c);for(var u=0,l=o;u<l.length;u++){var h=l[u];null===h.options.query&&this.processItems(h.itemType,h.items,c)}var p=s(i),f=s(c);return p&&f?{values:i,links:c}:p?{values:i}:f?{links:c}:Pt},t.prototype.getItemsByParent=function(t,e){var r=this.parentMap[t];return void 0===r?{}:void 0===r[e]?{}:r[e]},t}(),Vt="maybe",Nt=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 Vt;if(void 0!==t.custom)return Vt;if(void 0!==t.linkedTo)return this.matchLinkedToQuery(t);if(void 0!==t.query)return Vt;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 Vt;var e,r=this.parent;return(e=null!==r&&(t.linkedTo===r.itemType&&this.matchSimpleQuery(r.itemId,t.query)))===Vt?Vt: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 o=0,i=n;o<i.length;o++){var s=i[o],c=this.matchQuery(s);if(c===r)return t.not?!r:r;c===Vt&&(e=Vt)}return e===Vt?Vt:t.not?!e:e},t.prototype.matchSimpleQuery=function(t,e){var r=e.key,o=e.value;if(!s(e))return!0;if(void 0===t)return console.warn("Required field",r,"not found for",this.itemType),Vt;switch("NOW"===o&&(o=n()),e.comparator){case"=":return this.compareValues(t,o);case"!=":return!this.compareValues(t,o);case"<":return t<o;case"<=":return t<=o;case">":return t>o;case">=":return t>=o;case"IN":var i=a(t,o);return e.not?!i:i;default:throw new Error("queryMatcher: Unsupported comparator: "+e.comparator+" in query "+e)}},t}();!function(t){t[t.OBJ=0]="OBJ",t[t.STR=1]="STR",t.SEP=":"}(At||(At={})),function(t){t.OR="OR",t.AND="AND"}(jt||(jt={})),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"}(kt||(kt={}));var Bt=Object.keys(kt).map(function(t){return kt[t]}),Ut=((xt={})[kt.EQUALS]=kt.NOT_EQUALS,xt[kt.NOT_EQUALS]=kt.EQUALS,xt[kt.MORE_THAN]=kt.LESS_OR_EQUAL_THAN,xt[kt.LESS_THAN]=kt.EQUAL_OR_MORE_THAN,xt[kt.LESS_OR_EQUAL_THAN]=kt.MORE_THAN,xt[kt.EQUAL_OR_MORE_THAN]=kt.LESS_THAN,xt[kt.IN]=kt.IN,xt),Qt=function(){function t(t,e){this.query=t,this.parameters=e}return t.prototype.compareParsedQueries=function(t,e){return t[At.STR]===e[At.STR]?0:t[At.STR]>e[At.STR]?1:-1},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=c(t);if(null===e)return[{},"{}"];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.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+"]"]},t.prototype.parseSubFieldQuery=function(t,e,r,n,o){void 0===t&&(t=""),void 0===e&&(e=""),void 0===r&&(r=""),void 0===o&&(o=!1);var i=this.parse(n);return[{key:t,itemType:e,field:r,query:i[At.OBJ],not:o},"[subField"+At.SEP+t+At.SEP+e+At.SEP+r+At.SEP+i[At.STR]+At.SEP+o+"]"]},t.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+"]"]},t.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+"]"]},t.prototype.parseCustomParameters=function(t){for(var e=Object.keys(t).sort(),r={},n="",o=0;o<e.length;o++){var i=e[o],s=this.formatValue(t[i]);r[i]=s[At.OBJ],o>0&&(n+=At.SEP),n+=s[At.STR]}return[r,n]},t.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])?kt.IN:kt.EQUALS),-1===Bt.indexOf(r))throw new Error("Unknown comparator '"+r+"', it might be that the backend supports it but the frontend doesn't !");n&&(r=Ut[r]);var o=r===kt.IN&&n,i=[{key:t,value:e[At.OBJ],comparator:r,not:o},"["+r+At.SEP+t+At.SEP+e[At.STR]+"]"];return o&&(i[1]=i[1].slice(0,-1),i[1]+=At.SEP+n+"]"),i},t.prototype.parseLinkedToQuery=function(t,e,r,n){void 0===e&&(e={}),void 0===r&&(r=!1),void 0===n&&(n=!1);var o=this.parse(e);return[{linkedTo:t,query:o[At.OBJ],reverse:r,not:n},"[linkedTo"+At.SEP+t+At.SEP+o[At.STR]+At.SEP+r+At.SEP+n+"]"]},t.prototype.parseComplexQuery=function(t,e,r){void 0===e&&(e=jt.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+"]"]},t.prototype.parseConditions=function(t){for(var e=this,r=[],n=[],o="",i=0,s=t;i<s.length;i++){var c=s[i];r.push(this.parse(c))}for(var a=0,u=r=r.sort(function(t,r){return e.compareParsedQueries(t,r)});a<u.length;a++){var l=u[a];n.push(l[At.OBJ]),o+=l[At.STR]}return[n,o]},t.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]},t.prototype.processValue=function(t){return Array.isArray(t)?t.slice().sort():n.isMoment(t)?n(t):n.isDuration(t)?n.duration(t):t},t}(),Yt=function(){function t(){}return t.prototype.addAndCondition=function(t,e){return void 0===t.conditions||t.operator===jt.OR?{conditions:[t,e]}:{conditions:t.conditions.concat(e)}},t.prototype.addOrCondition=function(t,e){return t.operator===jt.OR?{conditions:t.conditions.concat(e)}:{conditions:[t,e],operator:jt.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:kt.IN,key:"id",value:t,not:!0}},t}(),Xt=function(){function t(){this.cache=[]}return t.prototype.set=function(t,e){var r=t.entry.id,n=this.getCacheLevel(e)[1];return void 0===n[r]&&(n[r]=[]),n[r].push(t),t},t.prototype.getCacheLevel=function(t){for(var e=this.cache,r=e.length-1;r>=0;r--){var n=e[r];if(n[0]===t)return n;if(n[0]<t)return this.createCacheLevel(r+1,t)}return this.createCacheLevel(0,t)},t.prototype.createCacheLevel=function(t,e){var r=[e,{}];return this.cache.splice(t,0,r),r},t.prototype.hasResources=function(t){for(var e=this.cache,r=e.length-1;r>=0;r--)if(void 0!==e[r][1][t.id])return!0;return!1},t.prototype.get=function(t){for(var e=[],r=0,n=this.cache;r<n.length;r++){var o=n[r][1][t.id];if(void 0!==o)for(var i=0,s=o;i<s.length;i++){var c=s[i];e.push(c)}}return e},t.prototype.getLatest=function(t){for(var e=this.cache,r=e.length-1;r>=0;r--){var n=e[r][1][t.id];if(void 0!==n)return n[n.length-1]}return null},t.prototype.clearResource=function(t){for(var e=this.cache,r=t.entry.id,n=-1,o=e.length;-1===n&&o>0;){var i=e[--o][1][r];void 0!==i&&(n=i.indexOf(t))}if(-1===n)return!1;var s=e[o][1];return 1===s[r].length?delete s[r]:s[r].splice(n,1),!0},t.prototype.clearResources=function(t){for(var e=this.cache,r=e.length;r>0&&e[r-1][0]>=t;)r--;e.length=r},t.prototype.clearEntry=function(t){for(var e=0,r=this.cache;e<r.length;e++){delete r[e][t.id]}},t}(),Wt=function(){function t(t){this.columnUtil=t,this.columns={},this.columnSetIdMap={}}return 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}(),Jt=function(){function t(t,e,r,n,o,i,s,c,a,u,l){this.apiFormatter=t,this.apiRequestService=e,this.collectionHandler=r,this.columnExpansionFactory=n,this.columnSetFactory=o,this.errorHandler=i,this.itemEntryFactory=s,this.itemHandler=c,this.localCacheManager=a,this.promiseService=u,this.requestColumnExpansionFactory=l}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.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={};for(var o in e){var i=e[o],s=null!==i.parent?i.parent:{};n[o]=this.collectionHandler.entries.getByFittingItem(t,this.formatMessageValues(i.values,r),s)}return n},t.prototype.groupByCollectionId=function(t,e){var r={};for(var n in e){var o=e[n];for(var i in o)for(var s=0,c=o[i];s<c.length;s++){var a=c[s],u=a.id;void 0===r[u]&&(r[u]={collection:a,fitting:[],notfitting:[],maybe:[]}),r[u][i].push("fitting"===i?this.itemHandler.entries.get(t,n):n)}}return r},t.prototype.getRequestColumns=function(t,e){var r=this.requestColumnExpansionFactory.construct();for(var n in e){for(var o=e[n].fitting,i=this.itemHandler.entries.get(t,n),s=0,c=o;s<c.length;s++){var a=c[s];r.expand(a.columns)}void 0!==i&&r.expand(i.columns)}return r.get()},t.prototype.deferEntry=function(t){var e=t.deferred;return void 0===e?t.defer():e.promise.then(this.deferEntry.bind(this),this.errorHandler.reject)},t.prototype.processMessage=function(t){var e=this,r=t.itemType,n=this.createCollectionMap(r,t.items[r],t.columns[r]),o=this.getRequestColumns(r,n),i=[],s=[];for(var c in n){var a=this.itemHandler.entries.get(r,c),u=+c;void 0===a?0!==n[u].fitting.length&&(this.itemHandler.entries.add(this.itemEntryFactory.constructDeferred(r,u,o[r],!1)),s.push(u)):(i.push(this.deferEntry(a)),s.push(u))}return 0===s.length?this.promiseService.when(this.groupByCollectionId(r,n)):this.promiseService.all(i).then(function(){return e.apiRequestService.query(r,{id:s},o)},this.errorHandler.reject).then(function(t){return e.handleResponse(r,s,o[r],t,n)},this.errorHandler.reject)},t.prototype.processFunctionChangesResolve=function(t){var e=this,r=t.items.FunctionChangesResolve,n=[],o=[];for(var i in r){var s=r[i].parent.itemId,c=this.itemHandler.entries.get("Functie",s);void 0!==c&&void 0!==c.columns.response.Functie.newchanges&&(n.push(this.deferEntry(c)),o.push(s))}return 0===o.length?this.promiseService.when():this.promiseService.all(n).then(function(){return e.apiRequestService.query("Functie",{id:o},{Functie:["newchanges"]})},this.errorHandler.reject).then(function(t){for(var r=0,n=t.links.Functie;r<n.length;r++){var o=n[r],i=e.itemHandler.entries.get("Functie",o),s=e.apiFormatter.copyFields(i.getFields(),{},i.columns.main),c=t.fetchValue("Functie",o,"newchanges");c!==s.newchanges&&i.setInitial({newchanges:c},!0).callOnChange(s).resolve()}},this.errorHandler.reject).catch(this.errorHandler.notifyError)},t.prototype.handleResponse=function(t,e,r,n,o){for(var i=n.fetchColumnsObject(),s=this.columnSetFactory.construct(t,r,i),c=this.columnExpansionFactory.construct(t,r,i),a=0,u=e;a<u.length;a++){var l=u[a],h=this.itemHandler.entries.get(t,l),p=void 0===h.initial,f=n.fetchObject(t,l);if(void 0!==f){var d=n.fetchDerivedObject(t,l,s.root);if(p)h.resolveDeferred(f,d,s);else{var m=c.run(h.columns),y=this.apiFormatter.copyFields(h.getFields(),{},h.columns.main);null!==m&&h.expand(f,d,m),h.updateFields(f,d,!1).callOnChange(y).resolve()}}else h.reject(),p&&this.itemHandler.entries.clear(h),delete o[l]}return this.groupByCollectionId(t,o)},t.prototype.isFunctionChangesResolveMessage=function(t){return"FunctionChangesResolve"===t.body.itemType},t.prototype.handleCreate=function(t){var e=this,r=t.body;return this.isFunctionChangesResolveMessage(t)?this.processFunctionChangesResolve(r):this.processMessage(r).then(function(t){return e.collectionHandler.addToCollections(t,!0)},this.errorHandler.reject).catch(this.errorHandler.notifyError)},t.prototype.handleUpdate=function(t){var e=this;return this.processMessage(t.body).then(function(t){return e.collectionHandler.removeFromAndAddToCollections(t)},this.errorHandler.reject).catch(this.errorHandler.notifyError)},t.prototype.handleDelete=function(t){for(var e=t.body,r=e.itemType,n=this.localCacheManager.getAllLocalCaches(),o={},i=0,s=e.items;i<s.length;i++){for(var c=s[i],a=0,u=this.collectionHandler.entries.getByContainingItem(r,c);a<u.length;a++){var l=u[a];void 0===o[f=l.id]&&(o[f]={collection:l,items:[]}),o[f].items.push(c)}this.itemHandler.entries.clearByItemId(r,c);for(var h=0,p=n;h<p.length;h++){p[h].items.clearByItemId(r,c)}}for(var f in o){var d=o[f];d.collection.removeItems(d.items,null,!0)}return this.promiseService.when()},t.prototype.handleLinkMove=function(){return this.promiseService.when()},t}(),Kt=function(){function t(t){this.apiFormatter=t}return t.prototype.construct=function(t){return new j(this.apiFormatter,t)},t}(),zt=function(){function t(t){this.promiseService=t}return t.prototype.construct=function(t,e,r){return new H(this.promiseService,t,e,r)},t}(),Gt=function(){function t(t,e){this.collectionCacheFactory=t,this.keyService=e}return t.prototype.construct=function(t,e){return new P(this.collectionCacheFactory,this.keyService,t,e)},t}(),Zt=function(){function t(t,e){this.collectionResourceFactory=t,this.queryMatcherFactory=e}return t.prototype.construct=function(){return new B(this.collectionResourceFactory,this.queryMatcherFactory)},t}(),$t=function(){function t(t,e,r,n,o,i,s,c,a,u,l,h,p,f){this.collectionEntryService=t,this.collectionResourceFactory=e,this.columnExpansionFactory=r,this.columnHandler=n,this.columnSetFactory=o,this.errorHandler=i,this.exceptionHandler=s,this.itemEntryFactory=c,this.itemEntryService=a,this.itemHandler=u,this.itemRequestService=l,this.keyService=h,this.promiseService=p,this.queryService=f}return t.prototype.construct=function(t,e){return new et(this,t,new Z(e))},t}(),te=function(){function t(t){this.queryMatcherFactory=t}return t.prototype.construct=function(t,e,r,n){return new dt(this.queryMatcherFactory,t,e,r,n)},t}(),ee=function(){function t(t,e,r,n,o,i){this.errorHandler=t,this.exceptionHandler=e,this.itemResourceFactory=r,this.changesProcessor=n,this.keyService=o,this.promiseService=i,this.cache=new Xt}return t.prototype.construct=function(t,e,r,n){void 0===n&&(n=null);var o=new $(e);return o.editItems&&(t.hasItemEditResources=!0),o.editCollection?(t.hasEditResources=!0,this.cache.set(new st(this,t,o,r,n),r)):this.cache.set(new ot(this,t,o,r,n),r)},t}(),re=function(){function t(t){this.columnInfoFactory=t}return t.prototype.construct=function(t,e,r){return new vt(this.columnInfoFactory,t,e,r)},t}(),ne=function(){function t(){}return t.prototype.construct=function(t,e){return new Ct(t,e)},t.prototype.constructFromRootMap=function(t,e){void 0===e&&(e=null);var r=[];for(var n in t){var o=t[n],i=this.construct(o.apiColumn,e),s=this.constructFromRootMap(o.children,i);s.length>0&&i.setChildren(i.apiColumn.itemType,s),r.push(i)}return r},t}(),oe=function(){function t(t,e,r){this.columnHandler=t,this.columnUtil=e,this.columnInfoFactory=r}return t.prototype.constructStub=function(t,e){return new Rt(this.columnHandler,this.columnUtil,this.columnInfoFactory,this,t,e)},t.prototype.construct=function(t,e,r,n,o){return this.constructStub(t,e).resolve(r,n,o)},t}(),ie=function(){function t(){}return t.prototype.construct=function(t){return new Et(t)},t}(),se=function(){function t(t,e,r,n){this.collectionHandler=t,this.collectionMatcherFactory=e,this.keyService=r,this.requestColumnExpansionFactory=n}return t.prototype.construct=function(t,e,r,n){return new qt(this.collectionHandler,this.collectionMatcherFactory,this.keyService,this.requestColumnExpansionFactory,t,e,r,n)},t}(),ce=function(){function t(t){this.queryMatcherFactory=t}return t.prototype.construct=function(){return new Ot(this.queryMatcherFactory)},t}(),ae=function(){function t(t,e,r,n,o,i,s,c){this.authInterface=t,this.apiFormatter=e,this.columnSetFactory=r,this.exceptionHandler=n,this.itemEntryService=o,this.itemResourceFactory=i,this.keyService=s,this.promiseService=c}return t.prototype.constructStub=function(t,e,r){return new X(this,t,e,r)},t.prototype.constructLocalLinked=function(t,e,r,n,o,i){var s=this.constructStub(t,e,o);return s.parent=n,s.setLocalFields(r,i)},t.prototype.constructLocal=function(t,e,r,n,o,i,s){void 0===o&&(o=null),void 0===i&&(i=e.columns);var c=e.columns.itemType;void 0===s&&(s=this.itemEntryService.createLocalConversionMap(c,t,!0,e.response));var a=this.constructStub(c,t,i);return a.parent=o,a.setLocalFields(e.fields,s,e.columns).setModified(r).setDerived(n)},t.prototype.constructDeferred=function(t,e,r,n){var o=this.constructStub(t,e,this.columnSetFactory.constructStub(t,r));return o.defer(n),o},t.prototype.construct=function(t,e,r,n){return this.constructStub(n.itemType,t,n).setFields(e,r)},t}(),ue=function(){function t(t,e,r,n,o){this.apiFormatter=t,this.lockService=e,this.changesProcessor=r,this.errorHandler=n,this.promiseService=o,this.cache=new Xt}return t.prototype.getConstructor=function(t,e,r){var n=this,o=new Q(t);return function(t){return n.constructWithOptions(t,o,e,r)}},t.prototype.construct=function(t,e,r,n,o){return this.constructWithOptions(t,new Q(e),r,n,o)},t.prototype.constructWithOptions=function(t,e,r,n,o){return void 0===n&&(n=null),void 0===o&&(o=!1),this.cache.set(e.edit?new G(this,t,e,o,n):e.remote?new ut(this,t,e,o,n):new ht(this,t,e,o,n),r)},t}(),le=function(){function t(t,e,r,n,o,i,s,c,a){this.changesProcessor=t,this.collectionCacheFactory=e,this.collectionResourceFactory=r,this.errorHandler=n,this.exceptionHandler=o,this.itemCacheFactory=i,this.itemResourceFactory=s,this.lockService=c,this.promiseService=a}return t.prototype.construct=function(t,e){return new Dt(this.changesProcessor,this.collectionCacheFactory,this.collectionResourceFactory,this.errorHandler,this.exceptionHandler,this.itemCacheFactory,this.itemResourceFactory,this.lockService,this.promiseService,t,e)},t}(),he=function(){function t(){}return t.prototype.construct=function(t,e,r){return new _t(t,e,r)},t}(),pe=function(){function t(t){this.apiFormatter=t}return t.prototype.construct=function(t,e,r){return new Nt(this.apiFormatter,t,e,r)},t}(),fe=function(){function t(){}return t.prototype.construct=function(t,e){return new Qt(t,e)},t}(),de=function(){function t(t){this.columnUtil=t}return t.prototype.construct=function(){return new Wt(this.columnUtil)},t}(),me=function(){function t(t,e){this.columnSetFactory=t,this.columnUtil=e}return t.prototype.construct=function(t,e,r){return new ct(this,t,e,r)},t}(),ye=function(){return function(t,e,r,n,o,i){this.noop=ve,this.version="1.7.1",this.apiFormatter=new x,this.apiResponseProcessorFactory=new Kt(this.apiFormatter),this.apiRequestService=new A(t,this.apiResponseProcessorFactory),this.batchStatusFactory=new zt(i),this.keyService=new Tt,this.queryMatcherFactory=new pe(this.apiFormatter),this.queryParserFactory=new fe,this.queryService=new Yt,this.columnUtil=new Ft,this.columnCache=new yt(this.columnUtil),this.columnHandler=new gt(this.apiRequestService,r,i,this.columnCache,this.columnUtil),this.columnInfoFactory=new ne,this.columnExpansionFactory=new re(this.columnInfoFactory),this.columnSetFactory=new oe(this.columnHandler,this.columnUtil,this.columnInfoFactory),this.columnSubsetCacheFactory=new ie,this.lockService=new Ht(this.apiRequestService,r,this.keyService,i),this.templateFactory=new me(this.columnSetFactory,this.columnUtil),this.itemEntryService=new Lt(e,this.keyService),this.itemCacheFactory=new ce(this.queryMatcherFactory),this.itemResourceFactory=new ue(this.apiFormatter,this.lockService,this.changesProcessor,r,i),this.collectionResourceFactory=new ee(r,n,this.itemResourceFactory,this.changesProcessor,this.keyService,i),this.itemEntryFactory=new ae(e,this.apiFormatter,this.columnSetFactory,n,this.itemEntryService,this.itemResourceFactory,this.keyService,i),this.collectionEntryService=new pt(this.queryParserFactory,this.queryService),this.collectionResourceService=new mt,this.itemHandler=new Mt(this.apiFormatter,this.apiRequestService,this.batchStatusFactory,this.columnExpansionFactory,this.columnHandler,this.columnSetFactory,this.columnSubsetCacheFactory,this.columnUtil,r,this.itemCacheFactory,this.itemEntryFactory,this.itemEntryService,this.keyService,i,this.templateFactory),this.itemRequestService=new wt(this.apiRequestService,r,this.itemHandler,this.columnExpansionFactory,this.columnSetFactory,this.itemEntryFactory,this.queryService,i),this.collectionEntryFactory=new $t(this.collectionEntryService,this.collectionResourceFactory,this.columnExpansionFactory,this.columnHandler,this.columnSetFactory,r,n,this.itemEntryFactory,this.itemEntryService,this.itemHandler,this.itemRequestService,this.keyService,i,this.queryService),this.collectionCacheFactory=new Zt(this.collectionResourceFactory,this.queryMatcherFactory),this.collectionMatcherFactory=new te(this.queryMatcherFactory),this.collectionHandler=new ft(this.batchStatusFactory,this.collectionCacheFactory,this.collectionEntryFactory,this.collectionEntryService,this.collectionMatcherFactory,this.columnHandler,this.columnSetFactory,r,this.itemHandler,this.itemRequestService,this.keyService,i,this.queryParserFactory,this.queryService),this.requestColumnExpansionFactory=new de(this.columnUtil),this.createRequestFactory=new se(this.collectionHandler,this.collectionMatcherFactory,this.keyService,this.requestColumnExpansionFactory),this.changesCompilationFactory=new Gt(this.collectionCacheFactory,this.keyService),this.changesProcessor=new _(this.apiFormatter,this.apiRequestService,this.changesCompilationFactory,this.collectionEntryService,this.collectionHandler,this.columnExpansionFactory,this.createRequestFactory,r,this.itemHandler,i,this.requestColumnExpansionFactory),this.localCacheFactory=new le(this.changesProcessor,this.collectionCacheFactory,this.collectionResourceFactory,r,n,this.itemCacheFactory,this.itemResourceFactory,this.lockService,i),this.moduleChangesCompilationFactory=new he,this.itemAdministrator=new bt(this.apiRequestService,e,this.collectionHandler,this.collectionMatcherFactory,this.collectionResourceFactory,this.columnSetFactory,r,this.itemHandler,this.itemRequestService,this.itemResourceFactory,this.keyService,o,this.moduleChangesCompilationFactory,i,this.queryService),this.socketMessageHandler=new Jt(this.apiFormatter,this.apiRequestService,this.collectionHandler,this.columnExpansionFactory,this.columnSetFactory,r,this.itemEntryFactory,this.itemHandler,o,i,this.requestColumnExpansionFactory)}}();function ve(){}function ge(t){return t}r.d(e,"RmCore",function(){return ye}),r.d(e,"noop",function(){return ve}),r.d(e,"identity",function(){return ge}),r.d(e,"ENTRY_STATUS",function(){return T}),r.d(e,"ALL_PERMISSIONS",function(){return"7"}),r.d(e,"COLUMN_SEPERATOR",function(){return D}),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 U}),r.d(e,"ItemResourceOptions",function(){return Q}),r.d(e,"ItemEntry",function(){return X}),r.d(e,"ItemResource",function(){return W}),r.d(e,"ViewResource",function(){return K}),r.d(e,"EditResource",function(){return G}),r.d(e,"CollectionEntryOptions",function(){return Z}),r.d(e,"CollectionResourceOptions",function(){return $}),r.d(e,"CollectionEntry",function(){return et}),r.d(e,"CollectionResource",function(){return rt}),r.d(e,"CollectionViewResource",function(){return ot}),r.d(e,"CollectionEditResource",function(){return st}),r.d(e,"Template",function(){return ct}),r.d(e,"RemoteViewResource",function(){return ut}),r.d(e,"LocalViewResource",function(){return ht}),r.d(e,"ApiFormatter",function(){return x}),r.d(e,"ApiRequestService",function(){return A}),r.d(e,"ApiResponseProcessor",function(){return j}),r.d(e,"BatchStatus",function(){return H}),r.d(e,"ChangesCompilation",function(){return P}),r.d(e,"ChangesProcessor",function(){return _}),r.d(e,"CollectionCache",function(){return B}),r.d(e,"CollectionEntryService",function(){return pt}),r.d(e,"CollectionHandler",function(){return ft}),r.d(e,"CollectionMatcher",function(){return dt}),r.d(e,"CollectionResourceService",function(){return mt}),r.d(e,"ColumnCache",function(){return yt}),r.d(e,"ColumnExpansion",function(){return vt}),r.d(e,"ColumnHandler",function(){return gt}),r.d(e,"ColumnInfo",function(){return Ct}),r.d(e,"ColumnSet",function(){return Rt}),r.d(e,"ColumnSubsetCache",function(){return Et}),r.d(e,"ColumnUtil",function(){return Ft}),r.d(e,"CreateRequest",function(){return qt}),r.d(e,"ItemAdministrator",function(){return bt}),r.d(e,"ItemCache",function(){return Ot}),r.d(e,"ItemEntryService",function(){return Lt}),r.d(e,"ItemHandler",function(){return Mt}),r.d(e,"ItemRequestService",function(){return wt}),r.d(e,"KeyService",function(){return Tt}),r.d(e,"LocalCache",function(){return Dt}),r.d(e,"LockService",function(){return Ht}),r.d(e,"ModuleChangesCompilation",function(){return _t}),r.d(e,"QueryMatcher",function(){return Nt}),r.d(e,"OPERATORS",function(){return jt}),r.d(e,"COMPARATORS",function(){return kt}),r.d(e,"QueryParser",function(){return Qt}),r.d(e,"QueryService",function(){return Yt}),r.d(e,"ResourceCache",function(){return Xt}),r.d(e,"RequestColumnExpansion",function(){return Wt}),r.d(e,"SocketMessageHandler",function(){return Jt}),r.d(e,"instantiateOptions",function(){return o}),r.d(e,"shallowMerge",function(){return i}),r.d(e,"hasProperties",function(){return s}),r.d(e,"getFirstProperty",function(){return c}),r.d(e,"inArray",function(){return a}),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 f}),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 S}),r.d(e,"isArray",function(){return R}),r.d(e,"isFunction",function(){return E}),r.d(e,"isRegExp",function(){return F}),r.d(e,"isBoolean",function(){return q}),r.d(e,"isElement",function(){return b}),r.d(e,"isWindow",function(){return O}),r.d(e,"isDefined",function(){return L}),r.d(e,"equals",function(){return M}),r.d(e,"copy",function(){return w}),r.d(e,"ApiResponseProcessorFactory",function(){return Kt}),r.d(e,"BatchStatusFactory",function(){return zt}),r.d(e,"ChangesCompilationFactory",function(){return Gt}),r.d(e,"CollectionCacheFactory",function(){return Zt}),r.d(e,"CollectionEntryFactory",function(){return $t}),r.d(e,"CollectionMatcherFactory",function(){return te}),r.d(e,"CollectionResourceFactory",function(){return ee}),r.d(e,"ColumnExpansionFactory",function(){return re}),r.d(e,"ColumnInfoFactory",function(){return ne}),r.d(e,"ColumnSetFactory",function(){return oe}),r.d(e,"ColumnSubsetCacheFactory",function(){return ie}),r.d(e,"CreateRequestFactory",function(){return se}),r.d(e,"ItemCacheFactory",function(){return ce}),r.d(e,"ItemEntryFactory",function(){return ae}),r.d(e,"ItemResourceFactory",function(){return ue}),r.d(e,"LocalCacheFactory",function(){return le}),r.d(e,"ModuleChangesCompilationFactory",function(){return he}),r.d(e,"QueryMatcherFactory",function(){return pe}),r.d(e,"QueryParserFactory",function(){return fe}),r.d(e,"RequestColumnExpansionFactory",function(){return de}),r.d(e,"TemplateFactory",function(){return me}),r.d(e,"LocalCacheCallbackCondition",function(){return N})}])});