diff --git a/app/assets/javascripts/app/lib/spine/ajax.coffee b/app/assets/javascripts/app/lib/spine/ajax.coffee index c3a213d20..1f55fdb13 100644 --- a/app/assets/javascripts/app/lib/spine/ajax.coffee +++ b/app/assets/javascripts/app/lib/spine/ajax.coffee @@ -212,7 +212,7 @@ class Singleton extends Base (data, status, xhr) => Ajax.disable => - unless Spine.isBlank(data) or @record.destroyed + unless data is undefined or Object.getOwnPropertyNames(data).length == 0 or @record.destroyed # Update with latest data @record.refresh(data) diff --git a/app/assets/javascripts/app/lib/spine/local.coffee b/app/assets/javascripts/app/lib/spine/local.coffee index ff3b688fe..63d2418f8 100644 --- a/app/assets/javascripts/app/lib/spine/local.coffee +++ b/app/assets/javascripts/app/lib/spine/local.coffee @@ -2,6 +2,13 @@ Spine = @Spine or require('spine') Spine.Model.Local = extended: -> + testLocalStorage = 'spine' + new Date().getTime() + try + localStorage.setItem(testLocalStorage, testLocalStorage) + localStorage.removeItem(testLocalStorage) + catch e + return + @change @saveLocal @fetch @loadLocal @@ -14,4 +21,4 @@ Spine.Model.Local = result = localStorage[@className] @refresh(result or [], options) -module?.exports = Spine.Model.Local \ No newline at end of file +module?.exports = Spine.Model.Local diff --git a/app/assets/javascripts/app/lib/spine/relation.coffee b/app/assets/javascripts/app/lib/spine/relation.coffee index 01bf47df3..99056cf99 100644 --- a/app/assets/javascripts/app/lib/spine/relation.coffee +++ b/app/assets/javascripts/app/lib/spine/relation.coffee @@ -1,5 +1,4 @@ Spine = @Spine or require('spine') -isArray = Spine.isArray class Collection extends Spine.Module constructor: (options = {}) -> @@ -42,7 +41,7 @@ class Collection extends Spine.Module for match, i in @model.records when match.id is record.id @model.records.splice(i, 1) break - values = [values] unless isArray(values) + values = [values] unless Array.isArray(values) for record in values record.newRecord = false record[@fkey] = @record.id @@ -104,7 +103,7 @@ underscore = (str) -> str.replace(/::/g, '/') .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2') .replace(/([a-z\d])([A-Z])/g, '$1_$2') - .replace(/-/g, '_') + .replace(/(-|\.)/g, '_') .toLowerCase() requireModel = (model) -> diff --git a/app/assets/javascripts/app/lib/spine/spine.coffee b/app/assets/javascripts/app/lib/spine/spine.coffee index 077065f73..95984d444 100644 --- a/app/assets/javascripts/app/lib/spine/spine.coffee +++ b/app/assets/javascripts/app/lib/spine/spine.coffee @@ -160,19 +160,22 @@ class Model extends Module @exists: (id) -> Boolean @irecords[id] - @addRecord: (record) -> + @addRecord: (record,idx) -> if root = @irecords[record.id or record.cid] root.refresh(record) else record.id or= record.cid @irecords[record.id] = @irecords[record.cid] = record - @records.push(record) + if idx isnt undefined + @records.splice(idx,0,record) + else + @records.push(record) record @refresh: (values, options = {}) -> @deleteAll() if options.clear records = @fromJSON(values) - records = [records] unless isArray(records) + records = [records] unless Array.isArray(records) @addRecord(record) for record in records @sort() @@ -256,7 +259,7 @@ class Model extends Module if typeof objects is 'string' objects = JSON.parse(objects) objects = @beforeFromJSON(objects) - if isArray(objects) + if Array.isArray(objects) for value in objects if value instanceof this value @@ -464,7 +467,7 @@ class Model extends Module @id or= @cid record = @dup(false) - @constructor.addRecord(record) + @constructor.addRecord(record,options.idx) @constructor.sort() clone = record.clone() @@ -610,14 +613,6 @@ createObject = Object.create or (o) -> Func.prototype = o new Func() -isArray = (value) -> - Object::toString.call(value) is '[object Array]' - -isBlank = (value) -> - return true unless value - return false for key of value - true - makeArray = (args) -> Array::slice.call(args, 0) @@ -626,9 +621,7 @@ makeArray = (args) -> Spine = @Spine = {} module?.exports = Spine -Spine.version = '1.4.1' -Spine.isArray = isArray -Spine.isBlank = isBlank +Spine.version = '1.5.0' Spine.$ = $ Spine.Events = Events Spine.Log = Log