Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ###
  2.  * @tag models, home
  3.  * Wraps backend <%=underscore%> services.  Enables
  4.  * [<%=name%>.static.findAll retrieving],
  5.  * [<%=name%>.static.update updating],
  6.  * [<%=name%>.static.destroy destroying], and
  7.  * [<%=name%>.static.create creating] <%= plural %>.
  8. ###
  9. $.Model.extend "<%=name%>",
  10. # @Static
  11.  
  12.   ###
  13.      * Retrieves <%= plural %> data from your backend services.
  14.      * @param {Object} params params that might refine your results.
  15.      * @param {Function} success a callback function that returns wrapped <%=underscore%> objects.
  16.      * @param {Function} error a callback function for an error in the ajax request.
  17.   ###
  18.   findAll: (params, success, error) ->
  19.     $.ajax
  20.       url: "/<%= underscore %>"
  21.       type: "get"
  22.       dataType: "json"
  23.       data: params
  24.       success: @callback([ "wrapMany", success ])
  25.       error: error
  26.       fixture: "//<%= appPath %>/fixtures/<%= plural %>.json.get" # calculates the fixture path from the url and type.
  27.  
  28.   ###
  29.      * Updates a <%= underscore %>'s data.
  30.      * @param {String} id A unique id representing your <%= underscore %>.
  31.      * @param {Object} attrs Data to update your <%= underscore %> with.
  32.      * @param {Function} success a callback function that indicates a successful update.
  33.      * @param {Function} error a callback that should be called with an object of errors.
  34.   ###
  35.   update: (id, attrs, success, error) ->
  36.     $.ajax
  37.       url: "/<%= plural %>/" + id
  38.       type: "put"
  39.       dataType: "json"
  40.       data: attrs
  41.       success: success
  42.       error: error
  43.       fixture: "-restUpdate" # uses $.fixture.restUpdate for response.
  44.  
  45.   ###
  46.      * Destroys a <%= underscore %>'s data.
  47.      * @param {String} id A unique id representing your <%= underscore %>.
  48.      * @param {Function} success a callback function that indicates a successful destroy.
  49.      * @param {Function} error a callback that should be called with an object of errors.
  50.   ###
  51.   destroy: (id, success, error) ->
  52.     $.ajax
  53.       url: "/<%= plural %>/" + id
  54.       type: "delete"
  55.       dataType: "json"
  56.       success: success
  57.       error: error
  58.       fixture: "-restDestroy" # uses $.fixture.restDestroy for response.
  59.  
  60.   ###
  61.      * Creates a <%= underscore %>.
  62.      * @param {Object} attrs A <%= underscore %>'s attributes.
  63.      * @param {Function} success a callback function that indicates a successful create.  The data that comes back must have an ID property.
  64.      * @param {Function} error a callback that should be called with an object of errors.
  65.   ###
  66.   create: (attrs, success, error) ->
  67.     $.ajax
  68.       url: "/<%= plural %>"
  69.       type: "post"
  70.       dataType: "json"
  71.       success: success
  72.       error: error
  73.       data: attrs
  74.       fixture: "-restCreate" # uses $.fixture.restCreate for response.
  75. ,
  76. # @Prototype
  77. {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement