units.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * Provides interface for unit apis.
  3. */
  4. (function() {
  5. var restResource = function($resource) {
  6. return function() {
  7. arguments[2]["create"] = {
  8. method: "PUT"
  9. };
  10. arguments[2]["update"] = {
  11. method: "POST"
  12. };
  13. var res = $resource.apply(null, arguments);
  14. res.prototype.$save = function() {
  15. return this[this.id? "$update":"$create"].apply(this, arguments);
  16. };
  17. return res;
  18. };
  19. };
  20. angular.module('Units', ['ngResource'])
  21. /*
  22. * Collection of unit apis.
  23. *
  24. * Methods:
  25. * get: Gets information for a unit by id
  26. * query: Get a list of all units
  27. * delete: Deletes a unit with an id
  28. * create: Creates a unit
  29. * update: Updates a unit
  30. * save: Creates a new unit or updates an existing unit
  31. */
  32. .factory('Unit', ['$resource', function($resource) {
  33. return restResource($resource)("unit/:id", {id: "@id"}, {
  34. "query": {
  35. method: 'GET',
  36. isArray: true,
  37. url: "unit/type/:type"
  38. },
  39. "primary": {
  40. method: 'GET',
  41. isArray: true,
  42. url: "unit/primary/:type"
  43. }
  44. });
  45. }]);
  46. })();