Created
November 20, 2009 01:08
-
-
Save ialexi/239190 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ========================================================================== | |
| // Project: RsvpClient.RsvpDataSource | |
| // Copyright: ©2009 My Company, Inc. | |
| // ========================================================================== | |
| /*globals RsvpClient */ | |
| sc_require("models/contact"); | |
| RsvpClient.SORT_PRIORITY = "isAttending DESC,hasResponded DESC,hasVisited DESC,lastName,firstName"; | |
| RsvpClient.SORT_LAST_MODIFIED = "lastModified DESC"; | |
| RsvpClient.DATA_QUERY = SC.Query.local(RsvpClient.Contact, { | |
| orderBy: RsvpClient.SORT_PRIORITY | |
| }); | |
| /** @class | |
| (Document Your Data Source Here) | |
| @extends SC.DataSource | |
| */ | |
| RsvpClient.RsvpDataSource = SC.DataSource.extend( | |
| /** @scope RsvpClient.RsvpDataSource.prototype */ { | |
| init: function() | |
| { | |
| sc_super(); | |
| this.thestral = Cornelius.Thestral.create({ | |
| connectUrl: "/server/:connect/", | |
| disconnectUrl: "/server/:connect/" | |
| }); | |
| this.thestral.connect(":data", this, "recordWasUpdated"); | |
| }, | |
| recordWasUpdated: function(path, message) | |
| { | |
| // TERRIBLE HACK HERE: | |
| var store = RsvpClient.store; | |
| SC.Request.getUrl("/server/:data").json().notify(this, "didFetchTasks", store, null).send(); | |
| return YES; | |
| }, | |
| // .......................................................... | |
| // QUERY SUPPORT | |
| // | |
| fetch: function(store, query) { | |
| if (!query) return NO; | |
| if (query.get("recordType") === RsvpClient.Contact) { | |
| if (this.get("hasFetchedContacts")) | |
| { | |
| store.dataSourceDidFetchQuery(query); | |
| return YES; | |
| } | |
| SC.Request.getUrl("/server/:data").json().notify(this, "didFetchTasks", store, query).send(); | |
| return YES; | |
| } | |
| return NO ; // return YES if you handled the query | |
| }, | |
| didFetchTasks: function(response, store, query) | |
| { | |
| if (SC.ok(response)) { | |
| this.set("hasFetchedContacts", YES); | |
| store.loadRecords(RsvpClient.Contact, response.get('body').content); | |
| if (query) store.dataSourceDidFetchQuery(query); | |
| } else if (query) store.dataSourceDidErrorQuery(query, response); | |
| }, | |
| // .......................................................... | |
| // RECORD SUPPORT | |
| // | |
| retrieveRecord: function(store, storeKey) { | |
| // TODO: Add handlers to retrieve an individual record's contents | |
| // call store.dataSourceDidComplete(storeKey) when done. | |
| return NO ; // return YES if you handled the storeKey | |
| }, | |
| createRecord: function(store, storeKey) { | |
| // TODO: Add handlers to submit new records to the data source. | |
| // call store.dataSourceDidComplete(storeKey) when done. | |
| return NO ; // return YES if you handled the storeKey | |
| }, | |
| updateRecord: function(store, storeKey) { | |
| // TODO: Add handlers to submit modified record to the data source | |
| // call store.dataSourceDidComplete(storeKey) when done. | |
| return NO ; // return YES if you handled the storeKey | |
| }, | |
| destroyRecord: function(store, storeKey) { | |
| // TODO: Add handlers to destroy records on the data source. | |
| // call store.dataSourceDidDestroy(storeKey) when done | |
| return NO ; // return YES if you handled the storeKey | |
| } | |
| }) ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment