Documentation

include MVC MVC.Animate MVC.Class MVC.Controller MVC.Controller.Action MVC.Controller.Action.Drag MVC.Controller.Action.Drop MVC.Controller.Action.EnterLeave MVC.Controller.Action.Event MVC.Controller.Action.Hover MVC.Controller.Action.Lasso MVC.Controller.Action.Selectable MVC.Controller.Action.Subscribe MVC.Controller.Comet MVC.Controller.Params MVC.Controller.Params.Drag MVC.Controller.Params.Drop MVC.Controller.Stateful MVC.Delegator MVC.Doc MVC.Element MVC.Event MVC.File MVC.History MVC.IO MVC.IO.Ajax MVC.IO.Comet MVC.IO.JsonP MVC.IO.WindowName MVC.IO.XDoc MVC.Model MVC.Model.Ajax MVC.Model.Cookie MVC.Model.JsonP MVC.Model.JsonRest MVC.Model.WindowName MVC.Model.XmlRest MVC.Native MVC.Native.Array MVC.Native.Date MVC.Native.Function MVC.Native.Number MVC.Native.Object MVC.Native.String MVC.Options MVC.Store MVC.SyntheticEvent MVC.Test MVC.Test.Assertions MVC.Test.Controller MVC.Test.Functional MVC.Test.Runner MVC.Test.Unit MVC.Timer MVC.Timer.Easings MVC.Vector MVC.View MVC.View.Helpers OpenAjax

MVC.Model.JsonRest

Inherits: MVC.Model.Ajax
Model for accessing JSON rest resources.


To create a new JSONModel:
 Todo = JSONRestModel.extend('todos')
To change the find url:
 Todo = JSONRestModel.extend('todos',{
   find_all_get_url: "application/todos.json"
},{})
Examples of how data should be returned to use JSONModel
 // /recipes.json should return 
    [ 
       {attributes: 
           {title: "Chicken Soup", id: "48", 
            instructions: "Call Mom!\nBring chicken",
            id: 1}  }, 
       {attributes: 
           {title: "Toast", id: "49", 
            instructions: "Heat Bread",
            id: 1}  } 
     ]

// /recipes/1.json should return {attributes: {title: "Chicken Soup", id: "48", instructions: "Call Mom!\nBring chicken", id: 1} }


Static Methods

create_request

create_request(attributes) -> undefined
Posts attributes to /plural_name.json.
{Object} -

create_success

create_success(transport, callback, instance) -> jsonmodel
After a successful create request, this gets the id from the header and returns the new instance.
{Object} -
{Object} - success callback passed into create
{Object} - the instance this call is creating
{jsonmodel} - a new instance

destroy_delete_url

destroy_delete_url(id) -> String
Returns the delete url
{Object} -
{String} - /plural_name/id.xml

find_all_get_success

find_all_get_success(transport) -> Array
When a find comes back successful, callsback with the data converted into instances of this class
{Object} -
{Array} - Array of json model instances that get passed to the callback

find_all_get_url

find_all_get_url() -> undefined
Returns the URL for find all requests @retunn {String}

update_request

update_request(id, attributes) -> undefined
Posts data to /plural_name/id.json
{Number} - the id of the instance we are updating
{Object} - updated attributes