Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dom/route/route.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
18 changes: 13 additions & 5 deletions model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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")
}
},

Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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");
};
}
};
Expand Down
14 changes: 14 additions & 0 deletions model/test/qunit/model_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 4 additions & 0 deletions model/test/qunit/schools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[{
"id" : 1,
"name" : "Thing 1"
}]