PageRenderTime 63ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/wdmmg/public/js/model.js

https://bitbucket.org/okfn/wdmmg/
JavaScript | 67 lines | 59 code | 7 blank | 1 comment | 4 complexity | c2ee8d984670d99d6c93ff32c4061f3e MD5 | raw file
  1. var OpenSpending = OpenSpending || {};
  2. OpenSpending.Model = function(customConfig) {
  3. var my = {
  4. config: {
  5. endpoint: "http://www.openspending.org/"
  6. }
  7. };
  8. if(customConfig){
  9. for(var key in customConfig){
  10. if(customConfig.hasOwnProperty(key)){
  11. my.config[key] = customConfig[key];
  12. }
  13. }
  14. }
  15. var datastore = OpenSpending.Datastore(my.config);
  16. var DataStoreModel = Backbone.Model.extend({
  17. url: function(){
  18. return my.config.endpoint + this.name + "/" + this.get("name");
  19. }
  20. });
  21. var DataStoreCollection = Backbone.Collection.extend({
  22. url: function(){
  23. return my.config.endpoint + this.name;
  24. },
  25. query: function(id, clb){
  26. var self = this;
  27. datastore.get(this.name, id, function(data){
  28. var obj = new self.model(data);
  29. self.add(obj);
  30. clb(obj);
  31. });
  32. }
  33. });
  34. // Model objects
  35. my.Dataset = DataStoreModel.extend({
  36. name: "dataset"
  37. });
  38. my.DatasetList = DataStoreCollection.extend({
  39. model: my.Dataset,
  40. name: "dataset"
  41. });
  42. my.Classifier = DataStoreModel.extend({
  43. name: "classifier",
  44. url: function(){
  45. return my.config.endpoint + this.name + "/" + this.get("taxonomy") + "/" + this.get("name");
  46. }
  47. });
  48. my.ClassifierList = DataStoreCollection.extend({
  49. model: my.Classifier,
  50. name: "classifier"
  51. });
  52. my.Entity = DataStoreModel.extend({
  53. name: "entity"
  54. });
  55. my.EntityList = DataStoreCollection.extend({
  56. model: my.Entity,
  57. name: "entity"
  58. });
  59. return my;
  60. };