From ca194cca5f370bef00a3ed7d691e3141aa82c74f Mon Sep 17 00:00:00 2001 From: David Luecke Date: Sat, 24 Dec 2011 10:45:07 -0700 Subject: [PATCH 1/3] Added resource URI parameter to model --- model/model.js | 10 +++++----- model/test/qunit/model_test.js | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/model/model.js b/model/model.js index 043d83cb..9ea22315 100644 --- a/model/model.js +++ b/model/model.js @@ -541,7 +541,7 @@ steal('jquery/class', 'jquery/lang/string', function() { * @param {Function} error a function to callback if something goes wrong. */ return function( attrs, success, error ) { - return ajax(str || this._shortName, attrs, success, error, fixture(this, "Create", "-restCreate")) + return ajax( (str || this.uri || this._shortName), attrs, success, error, fixture(this, "Create", "-restCreate")) }; }, update: function( str ) { @@ -616,7 +616,7 @@ steal('jquery/class', 'jquery/lang/string', function() { * @param {Function} error a function to callback if something goes wrong. */ return function( id, attrs, success, error ) { - return ajax( str || this._shortName+"/{"+this.id+"}", addId(this, attrs, id), success, error, fixture(this, "Update", "-restUpdate"), "put") + return ajax( str || (this.uri || this._shortName) + "/{"+this.id+"}", addId(this, attrs, id), success, error, fixture(this, "Update", "-restUpdate"), "put") } }, destroy: function( str ) { @@ -650,7 +650,7 @@ steal('jquery/class', 'jquery/lang/string', function() { return function( id, success, error ) { var attrs = {}; attrs[this.id] = id; - return ajax( str || this._shortName+"/{"+this.id+"}", attrs, success, error, fixture(this, "Destroy", "-restDestroy"), "delete") + return ajax( str || (this.uri || this._shortName) + "/{"+this.id+"}", attrs, success, error, fixture(this, "Destroy", "-restDestroy"), "delete") } }, @@ -690,7 +690,7 @@ steal('jquery/class', 'jquery/lang/string', function() { * @param {Function} error */ return function( params, success, error ) { - return ajax( str || this._shortName, params, success, error, fixture(this, "s"), "get", "json " + this._shortName + ".models"); + return ajax( str || this.uri || this._shortName, params, success, error, fixture(this, "s"), "get", "json " + this._shortName + ".models"); }; }, findOne: function( str ) { @@ -726,7 +726,7 @@ steal('jquery/class', 'jquery/lang/string', function() { * @param {Function} error */ return function( params, success, error ) { - return ajax(str || this._shortName+"/{"+this.id+"}", params, success, error, fixture(this), "get", "json " + this._shortName + ".model"); + return ajax(str || (this.uri || this._shortName) + "/{"+this.id+"}", params, success, error, fixture(this), "get", "json " + this._shortName + ".model"); }; } }; diff --git a/model/test/qunit/model_test.js b/model/test/qunit/model_test.js index b9ffac43..66f99561 100644 --- a/model/test/qunit/model_test.js +++ b/model/test/qunit/model_test.js @@ -307,6 +307,20 @@ test("auto methods",function(){ }) }) +test("auto uri", function() { + //turn off fixtures + $.fixture.on = false; + var School = $.Model.extend("Jquery.Model.Models.School",{ + uri : steal.root.join("jquery/model/test") + "/schools.json" + },{}) + stop(); + School.findAll({type:"schools"}, function(schools){ + ok(schools,"findAll Got some data back"); + equals(schools[0].constructor.shortName,"School","there are schools"); + start(); + }) +}); + test("isNew", function(){ var p = new Person(); ok(p.isNew(), "nothing provided is new"); From 4472aac1c6f27116e48e39f7fc1753d4945a0722 Mon Sep 17 00:00:00 2001 From: David Luecke Date: Sat, 24 Dec 2011 10:51:55 -0700 Subject: [PATCH 2/3] Added test json and documentation --- model/model.js | 8 ++++++++ model/test/qunit/schools.json | 4 ++++ 2 files changed, 12 insertions(+) create mode 100644 model/test/qunit/schools.json diff --git a/model/model.js b/model/model.js index 9ea22315..07c4f36f 100644 --- a/model/model.js +++ b/model/model.js @@ -212,6 +212,14 @@ steal('jquery/class', 'jquery/lang/string', function() { * destroy: 'DELETE /todos/{id}.json' * },{}); * + * You can also initialize the model by passing a resource URI. + * + * $.Model('Todo', { + * uri : '/todos' + * }, {}); + * + * Which will talk to /todos and /todos/{id}. + * * This lets you create, retrieve, update, and delete * todos programatically: * diff --git a/model/test/qunit/schools.json b/model/test/qunit/schools.json new file mode 100644 index 00000000..8dc242fa --- /dev/null +++ b/model/test/qunit/schools.json @@ -0,0 +1,4 @@ +[{ + "id" : 1, + "name" : "Thing 1" +}] From 7b2508b7d1486ddc830c05771cca7f8c21b3c6df Mon Sep 17 00:00:00 2001 From: David Luecke Date: Mon, 16 Jan 2012 18:43:39 -0700 Subject: [PATCH 3/3] $.route needs to steal $.Observe.prototype.delegate --- dom/route/route.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom/route/route.js b/dom/route/route.js index 4159adec..5c0fb1e9 100644 --- a/dom/route/route.js +++ b/dom/route/route.js @@ -1,4 +1,4 @@ -steal('jquery/lang/observe', 'jquery/event/hashchange', 'jquery/lang/string/deparam', +steal('jquery/lang/observe/delegate', 'jquery/event/hashchange', 'jquery/lang/string/deparam', function( $ ) { // Helper methods used for matching routes.