(function(){"use strict";u8.Base.DataSource=function(e){$.extend(this,e);if(!this.data){this.data=new u8.Base.Model({defaultValue:null})}this.responses=this.data;if(!this.parameters){this.parameters=new u8.Base.Model({defaultValue:null,onPropertyChange:this._onParameterChange.bind(this)})}this.bind(e);this._isCreated=false;this._create()};u8.Base.DataSource.makeClass({name:"DataSource",events:["Create"]});$.extend(u8.Base.DataSource.prototype,{_create:function(){var e=[];var t={};for(var a in this.requests){var r=this._buildRequest(a);if(!r){continue}var s=e.indexWhere(function(e){return e.source==r.source&&e.parameters==r.parameters});if(s<0){e.push(r);s=e.length-1}t[a]=s}var n=this;u8.request("DataSourceChannel.GetItems",{requests:e},function(e,a){var r=a.response&&a.response.data;for(var s=0;r&&s<r.length;s++){for(var i in t){if(t[i]==s){n.data.set(i,r[s])}}}u8.tools.created(n)})},update:function(e){if(!e){this._create();return this}var t=this._buildRequest(e);if(!t){return this}var a=this;u8.request("DataSourceChannel.GetItems",{requests:[t]},function(t,r){var s=r.response&&r.response.data&&r.response.data[0];if(s){a.data.set(e,s)}});return this},_buildRequest:function(e){var t=this.requests[e].split(";");var a=true;var r=t[0];for(var s=0;s<t.length;s++){var n=t[s];if(n[0]!="$"){continue}var i=e+"."+n.substr(1);var u=this.parameters.get(i);if(u!==undefined&&u!==null){t[s]=u.toString()}else{a=false}}t.shift();return a?{source:r,parameters:t.join(";")}:null},_onParameterChange:function(e,t){var a=t.propertyName.indexOf(".");var r=t.propertyName.substring(0,a);this.update(r)}})})();