Skip to content

Instantly share code, notes, and snippets.

@deitch
Last active August 29, 2015 13:56
Show Gist options
  • Save deitch/9170318 to your computer and use it in GitHub Desktop.
Save deitch/9170318 to your computer and use it in GitHub Desktop.
factory('Resource',['$resource',function ($resource) {
return function(url,params,methods){
var defaults = {
update: { method: 'put', isArray: false },
patch: { method: 'patch', isArray: false },
create: { method: 'post' }
}, resource = $resource(url,params,angular.extend(defaults,methods)), urlParams = {};
// need to change $save *after* creating $resource
resource.prototype.$save = function() {
return this.id ? this.$update.apply(this,arguments) : this.$create.apply(this,arguments);
};
resource.prototype.patch = function() {
// get the changed fields - HOW DO I DO THIS?
var that = this, fields = this.getChangedField();
// create a new object of this type with just these changed fields
var obj = new this.constructor(fields);
// call $patch
obj.$patch().then(function () {
// clear dirty - HOW DO I DO THIS?
that.resetDirty();
});
// return myself
return(this);
};
resource.prototype.getChangedFields = function () {
};
return(resource);
};
}]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment