Sha256: 3cf633192c630830b7bad9c722dd22ba7a69ee5e1800d99a889d1ae6182408ff

Contents?: true

Size: 891 Bytes

Versions: 14

Compression:

Stored size: 891 Bytes

Contents

class @TypeStation.Store
  constructor: (@id = null) ->
    @STORE = {}
  get: (key) -> @STORE[key]
  set: (key, value) -> @STORE[key] = value

  each: (callback) ->
    for key, value of @STORE
      callback?(key, value)

class @TypeStation.Model extends @TypeStation.Store

  constructor: (@id = null) ->
    super
    @DIRTY = {}

  set: (key, value) ->
    super key, value
    @DIRTY[key] = 1

  changedKeys: -> Object.keys(@DIRTY)
  isChanged: -> @changedKeys().length > 0

  _reset: ->
    @STORE = {}
    @DIRTY = {}

  save: (callback = ->) ->
    self = @
    data = []

    for key, value of @STORE
      data.push(value)

    $.ajax
      type: "PATCH"
      url: self.id
      dataType: 'json'
      contentType: 'application/json'
      data: JSON.stringify({contents: data})
      success: (data) ->
        self._reset() #reset model to a clean state
        callback(data)

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
type_station-0.4.4 app/assets/javascripts/type_station/lib/models.js.coffee
type_station-0.4.3 app/assets/javascripts/type_station/lib/models.js.coffee
type_station-0.4.2 app/assets/javascripts/type_station/lib/models.js.coffee
type_station-0.4.1 app/assets/javascripts/type_station/lib/models.js.coffee
type_station-0.4.0 app/assets/javascripts/type_station/lib/models.js.coffee
type_station-0.3.4 app/assets/javascripts/type_station/lib/models.js.coffee
type_station-0.3.3 app/assets/javascripts/type_station/lib/models.js.coffee
type_station-0.3.2 app/assets/javascripts/type_station/lib/models.js.coffee
type_station-0.3.1 app/assets/javascripts/type_station/lib/models.js.coffee
type_station-0.3.0 app/assets/javascripts/type_station/lib/models.js.coffee
type_station-0.2.3 app/assets/javascripts/type_station/lib/models.js.coffee
type_station-0.2.2 app/assets/javascripts/type_station/lib/models.js.coffee
type_station-0.2.1 app/assets/javascripts/type_station/lib/models.js.coffee
type_station-0.2.0 app/assets/javascripts/type_station/lib/models.js.coffee