Created
June 12, 2012 18:40
-
-
Save mlynch/2919301 to your computer and use it in GitHub Desktop.
resources
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
initialize: function() { | |
this._fdb = new Firebase('http://gamma.firebase.com/opencountmadison/'); | |
this._resources = this._fdb.child('resources'); | |
}, | |
// Add a new resource | |
_addResource: function(tag, name, max, count) { | |
var self = this, now = new Date(); | |
var resourceData = { | |
tag: tag, | |
name: name, | |
max: max, | |
count: count, | |
added: now.getTime(), | |
last_modified: now.getTime() | |
}; | |
// Check to see if the resource already exists in firebase, otherwise create it | |
this._resources.child(tag).transaction(function(currentEntry) { | |
if(currentEntry === null) { | |
// Return the data we want Firebase to store | |
return resourceData; | |
} | |
// We'll return undefined if the entry already exists | |
}, function(success) { | |
if(!success) { | |
// Did not create it, it already exists | |
$(document).trigger('resource.alreadyExists', resourceData); | |
} else { | |
// We created it | |
$(document).trigger('resource.created', resourceData); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment