Created
July 13, 2011 10:46
-
-
Save Ziaw/1080078 to your computer and use it in GitHub Desktop.
This file contains 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
function DataGate() { | |
var loadOne = function (url, ctor, callback) { | |
$.getJSON(url, function (model) { | |
var result = new ctor(model); | |
callback(result); | |
}); | |
}; | |
var loadMany = function (url, ctor, callback) { | |
$.getJSON(url, function (model) { | |
var result = $.map(model, function (p) { return new ctor(p); }); | |
callback(result); | |
}); | |
}; | |
this.getProducts = function (callback) { | |
loadMany('/Products/Index/', Product, callback); | |
}; | |
this.getProduct = function (productId, callback) { | |
loadOne('/Products/Details/' + productId, Product, callback); | |
}; | |
this.getProductIssues = function (productId, callback) { | |
loadMany('/Issues/Index/' + productId, Issue, callback); | |
}; | |
this.getIssueStories = function (issueId, callback) { | |
loadMany('/Stories/Index/' + issueId, Story, callback); | |
}; | |
this.getStoryBlocks = function (storyId, callback) { | |
loadMany('/StoryBlocks/Index/' + storyId, StoryBlock, callback); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment