3vot-model
Version:
3VOT Model based on SpineJS
40 lines (34 loc) • 1.11 kB
text/coffeescript
_3Model = require("3vot-model")
class AjaxUtils
: (object) ->
object.url?() or object.url
= (object) ->
object.scope?() or object.scope
= (object, args...) ->
if object.className
collection = object.className.toLowerCase() + 's'
scope = AjaxUtils.getScope(object)
else
if typeof object.constructor.url is 'string'
collection = object.constructor.url
else
collection = object.constructor.className.toLowerCase() + 's'
scope = AjaxUtils.getScope(object) or AjaxUtils.getScope(object.constructor)
args.unshift(collection)
args.unshift(scope)
# construct and clean url
path = args.join('/')
path = path.replace /(\/\/)/g, "/"
path = path.replace /^\/|\/$/g, ""
# handle relative urls vs those that use a host
if path.indexOf("../") isnt 0
_3Model.Model.host + "/" + path
else
path
= (object) ->
if object
if typeof object.url is "function"
AjaxUtils.generateURL(object)
else
object.url
module.exports = AjaxUtils