Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###
- * @tag models, home
- * Wraps backend <%=underscore%> services. Enables
- * [<%=name%>.static.findAll retrieving],
- * [<%=name%>.static.update updating],
- * [<%=name%>.static.destroy destroying], and
- * [<%=name%>.static.create creating] <%= plural %>.
- ###
- $.Model.extend "<%=name%>",
- # @Static
- ###
- * Retrieves <%= plural %> data from your backend services.
- * @param {Object} params params that might refine your results.
- * @param {Function} success a callback function that returns wrapped <%=underscore%> objects.
- * @param {Function} error a callback function for an error in the ajax request.
- ###
- findAll: (params, success, error) ->
- $.ajax
- url: "/<%= underscore %>"
- type: "get"
- dataType: "json"
- data: params
- success: @callback([ "wrapMany", success ])
- error: error
- fixture: "//<%= appPath %>/fixtures/<%= plural %>.json.get" # calculates the fixture path from the url and type.
- ###
- * Updates a <%= underscore %>'s data.
- * @param {String} id A unique id representing your <%= underscore %>.
- * @param {Object} attrs Data to update your <%= underscore %> with.
- * @param {Function} success a callback function that indicates a successful update.
- * @param {Function} error a callback that should be called with an object of errors.
- ###
- update: (id, attrs, success, error) ->
- $.ajax
- url: "/<%= plural %>/" + id
- type: "put"
- dataType: "json"
- data: attrs
- success: success
- error: error
- fixture: "-restUpdate" # uses $.fixture.restUpdate for response.
- ###
- * Destroys a <%= underscore %>'s data.
- * @param {String} id A unique id representing your <%= underscore %>.
- * @param {Function} success a callback function that indicates a successful destroy.
- * @param {Function} error a callback that should be called with an object of errors.
- ###
- destroy: (id, success, error) ->
- $.ajax
- url: "/<%= plural %>/" + id
- type: "delete"
- dataType: "json"
- success: success
- error: error
- fixture: "-restDestroy" # uses $.fixture.restDestroy for response.
- ###
- * Creates a <%= underscore %>.
- * @param {Object} attrs A <%= underscore %>'s attributes.
- * @param {Function} success a callback function that indicates a successful create. The data that comes back must have an ID property.
- * @param {Function} error a callback that should be called with an object of errors.
- ###
- create: (attrs, success, error) ->
- $.ajax
- url: "/<%= plural %>"
- type: "post"
- dataType: "json"
- success: success
- error: error
- data: attrs
- fixture: "-restCreate" # uses $.fixture.restCreate for response.
- ,
- # @Prototype
- {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement