SC.stringsFor("English",{});Roots=SC.Object.create({NAMESPACE:"Roots",VERSION:"0.1.0",});
Roots.Source=SC.DataSource.extend({map:{},firenzePort:4020,firenzePrefix:"comet/",firenzeProtocol:"http",rootPath:"",init:function(){arguments.callee.base.apply(this,arguments);
var a=this;this.firenze=Pomona.Firenze.create({prefix:this.firenzePrefix,port:this.firenzePort,protocol:this.firenzeProtocol,requestAttachments:function(c){for(var b=0;
b<c.length;b++){a.startAttach(c[b])}},requestDetachments:function(c){for(var b=0;
b<c.length;b++){a.stopAttach(c[b])}}});this._pendingQueries={};this._stores={};this._currentId=0
},_normalMap:function(){if(this._normal_map){return this._normal_map}this._normal_map={};
for(var b in this.map){var a=this.map[b];if(typeof a===SC.T_STRING){a=SC.objectForPropertyPath(a);
this._normal_map[b]=a}}this._reverse_map=null;return this._normal_map},_reverseMap:function(){if(this._reverse_map){return this._reverse_map
}var c=this._normalMap();this._reverse_map={};for(var b in c){var a=c[b];if(!a){continue
}this._reverse_map[SC.guidFor(a)]=b}return this._reverse_map},startAttach:function(b){var a=this.rootPath+"/"+b+"?did="+this.firenze.getDoloresId();
SC.Request.getUrl(a).json().notify(this,"didAttach",b).send()},endAttach:function(a){},didAttach:function(a,b){if(SC.ok(a)){this.receiveRecords(b,a.get("body"))
}},fetch:function(a,b){var d=this._reverseMap();var c=d[SC.guidFor(b.recordType)];
if(c){if(!this._pendingQueries[c]){this._pendingQueries[c]=[]}this._pendingQueries[c].push([a,b]);
if(!this._stores[c]){this._stores[c]=[]}this._stores[c].push(a);this.firenze.connect(c,this,"receiveRecordFromFirenze");
return YES}return NO},receiveRecords:function(m,c){var i=this._normalMap();var f=i[m];
if(!f){return}var l=this._stores[m],e=this._pendingQueries[m],k,h,b,a;h=c.length;
var d=[];var g=[];for(k=0;k<h;k++){a=c[k];a.guid=a.id;if(a.DELETE){g.push(a)}else{d.push(a)
}}if(l){h=l.length;for(k=0;k<h;k++){l[k].loadRecords(f,d);for(var j=0;j<g.length;
j++){l[k].pushDestroy(f,g[j]["guid"])}}}if(e){h=e.length;for(k=0;k<h;k++){b=e[k];
b[0].dataSourceDidFetchQuery(b[1])}delete this._pendingQueries[m]}},receiveRecordFromFirenze:function(b,a){var c;
if(a!==""){c=[JSON.parse(a)]}else{c=[]}this.receiveRecords(b,c)},retrieveRecord:function(a,b){console.error("RETRIEVE!");
var c={guid:a.idFor(b),DELETE:true};a.dataSourceDidComplete(b,c,c.guid);return YES
},createRecord:function(a,d){var g=this._reverseMap();var f=g[SC.guidFor(a.recordTypeFor(d))];
if(!f){return NO}var b=this.rootPath+"/"+f;var e=a.readEditableDataHash(d);var c=this.firenze.getDoloresId();
if(c=="NONE"){a.dataSourceDidError(d);return NO}e.guid=c+"-"+(++this._currentId);
e.id=e.guid;a.dataSourceDidComplete(d,e,e.guid);SC.Request.putUrl(b).json().notify(this,"didCreateRecord",a,d,f,a.recordTypeFor(d),e.guid).send([e]);
return YES},didCreateRecord:function(d,c,e,f,h,g){var a;if(SC.ok(d)&&(a=d.get("body"))&&a.length>0){this.receiveRecords(f,a)
}else{var b=c.find(h,g);b.set("syncError","CREATE")}},updateRecord:function(a,c){var f=this._reverseMap();
var e=f[SC.guidFor(a.recordTypeFor(c))];if(!e){return NO}var b=this.rootPath+"/"+e;
var d=a.readDataHash(c);a.dataSourceDidComplete(c,d);SC.Request.putUrl(b).json().notify(this,"didUpdateRecord",a,c,e,a.recordTypeFor(c),d.guid).send([d]);
return YES},didUpdateRecord:function(d,c,e,f,h,g){if(SC.ok(d)){var a=d.get("body");
this.receiveRecords(f,a)}else{var b=c.find(h,g);b.set("syncError","UPDATE")}},destroyRecord:function(a,c){var f=this._reverseMap();
var e=f[SC.guidFor(a.recordTypeFor(c))];if(!e){return NO}var b=this.rootPath+"/"+e;
var d=a.readDataHash(c);a.dataSourceDidDestroy(c);if(d){d.DELETE=YES}SC.Request.putUrl(b).json().notify(this,"didDestroyRecord",a,c,e,a.recordTypeFor(c),d.guid).send([d]);
return YES},didDestroyRecord:function(c,b,d,e,g,f){if(SC.ok(c)){var a=c.get("body");
this.receiveRecords(e,a)}else{}}});require("data_sources/source");Roots.Store=SC.Store.extend({map:{},rootPath:"",init:function(){arguments.callee.base.apply(this,arguments);
this.set("dataSource",Roots.Source.create({map:this.map,rootPath:this.rootPath}))
}});if((typeof SC!=="undefined")&&SC&&SC.bundleDidLoad){SC.bundleDidLoad("roots")
};
