define(["require","exports"],function(require,exports){Object.defineProperty(exports,"__esModule",{value:true});var Api_controller=(function(){function Api_controller(api,global_key){this._global_key=global_key;this.api=api;if(!window[global_key+"-api-controller-registry"]){window[global_key+"-api-controller-registry"]={};} this._endpoints=window[global_key+"-api-controller-registry"];if(!window[global_key+"-pending-changes"]){window[global_key+"-pending-changes"]={};}} Api_controller.prototype.pushPendingUpdatesToApi=function(api_args,updates,action,state_key,callback,error_callback){if(!window[this._global_key+"-pending-changes"][state_key]){window[this._global_key+"-pending-changes"][state_key]=[];} window[this._global_key+"-pending-changes"][state_key].push({api_args:api_args,updates:updates,action:action,state_key:state_key,callback:callback,error_callback:error_callback});if(window[this._global_key+"-pending-changes"][state_key].length==1){this._sendUpdatesToApi(state_key);}};Api_controller.prototype.getPendingUpdatesToApi=function(state_key){return window[this._global_key+"-pending-changes"][state_key];};Api_controller.prototype._sendUpdatesToApi=function(queue_state_key){var _this=this;var _a=window[this._global_key+"-pending-changes"][queue_state_key][0],api_args=_a.api_args,updates=_a.updates,action=_a.action,state_key=_a.state_key,callback=_a.callback,error_callback=_a.error_callback;this.performAction(action,state_key,function(data){window[_this._global_key+"-pending-changes"][queue_state_key].shift();callback(data);if(window[_this._global_key+"-pending-changes"][queue_state_key].length>0){_this._sendUpdatesToApi(queue_state_key);}},api_args,function(err,_error_action){var actions=[];window[_this._global_key+"-pending-changes"][queue_state_key].forEach(function(item){if(item.state_key!==state_key){actions.push(item);}});window[_this._global_key+"-pending-changes"][queue_state_key]=actions;if(window[_this._global_key+"-pending-changes"][queue_state_key].length>0){_this._sendUpdatesToApi(queue_state_key);} error_callback(err,_error_action);});};Api_controller.prototype.register=function(action,state_key_generic,callback){this._endpoints[action]=this._endpoints[action]||{};this._endpoints[action][state_key_generic]=callback;};Api_controller.prototype.performAction=function(action,lookup_key,callback,args,error_callback){lookup_key=lookup_key.replace("{","").replace("}","");if(lookup_key[0]=="/"){lookup_key=lookup_key.replace("/","");} var uri_parts=lookup_key.split("/");for(var key in this._endpoints[action]){var properties=[];var call_closure=true;var state_key_generic=key;if(state_key_generic[0]=="/"){state_key_generic=state_key_generic.replace("/","");} var generic_endpoint_parts=state_key_generic.split("/");if(lookup_key===state_key_generic){this._endpoints[action][key](properties,this.api,callback,args,error_callback);return true;} else{if(uri_parts.length===generic_endpoint_parts.length){for(var i=0;i