Skip to content

@mren /gist:fe25760ca44414ab2707 secret
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
// This model allows to change the id, but save/put the model to the old Id
var ChangeableIdModel = Backbone.Model.extend({
set: function(attr, options) {
if (attr && attr['id'] && !this.oldId ) this.oldId = this.get('id');
Backbone.Model.prototype.set.call(this, attr, options);
return this;
},
url: function() {
var base = getUrl(this.collection) || this.urlRoot || urlError();
if (this.isNew()) return base;
return base + (base.charAt(base.length - 1) == '/' ? '' : '/') + encodeURIComponent(this.oldId || this.id);
},
save: function(attr, options) {
options || (options = {});
var model = this;
var success = options.success;
options.success = function(resp, status, xhr) {
if (model.changedId) delete model.oldId;
if (success) success(model, resp, xhr);
};
Backbone.Model.prototype.save.call(this, attr, options);
}
});
var getUrl = function(object) {
if (!(object && object.url)) return null;
return _.isFunction(object.url) ? object.url() : object.url;
};
@mpadronm90

Men, can you share function urlError(). ty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.