Skip to content

Instantly share code, notes, and snippets.

@akb
Forked from dmuskat/image-model
Created August 2, 2012 18:16
Show Gist options
  • Save akb/3239303 to your computer and use it in GitHub Desktop.
Save akb/3239303 to your computer and use it in GitHub Desktop.
ORIGINAL SCHEMA image.json :
{
"type":"object",
"id":"#image",
"properties":{
"name": { "type":"string"},
"encoding": { "type":"string"},
"drcid": { "type":"string"},
"type": { "type":"string"},
"environment": { "type":"string"},
"content": { "type":"string"}
}
}
MODEL COFFEE FILE image.coffee :
window.models = {} unless window.models?
imageSchema =
"type":"object"
"id":"#image"
"properties":
"name": { "type":"string" }
"encoding": { "type":"string" }
...
class models.Image extends Backbone.Model
idAttribute: "name"
urlRoot: "/images"
defaults:
name: ""
encoding: ""
drcid: ""
type: ""
environment: ""
validate: (attrs) ->
unless typeof attrs.encoding is "string"
return "Encoding must be a string."
unless typeof attrs.drcid is "string"
return "Drcid must be a string."
unless typeof attrs.type is "string"
return "Type must be a string."
unless typeof attrs.environment is "string"
return "Environment must be a string."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment