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. diff --git a/model/model.js b/model/model.js index d193445d..60b16e2c 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: * @@ -543,7 +551,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 ) { @@ -614,7 +622,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 ) { @@ -646,7 +654,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") } }, @@ -685,7 +693,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 ) { @@ -721,7 +729,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 d2ad9091..29b47a9f 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"); 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" +}]