Last active
August 29, 2015 13:56
-
-
Save deitch/9170318 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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