# ----------------------------------------------------------------------------- # LIST # ----------------------------------------------------------------------------- class @List _loading: (callback) -> @$el.addClass 'list-loading' callback() _path: -> crumbs = [] ; l = this while l.parentList crumbs.push(l.name) ; l = l.parentList @module.name + ( if crumbs.length > 0 then '/' + crumbs.reverse().join('/') else '' ) _updateItemPosition: (item, position) -> position = @configItemsCount + position if position == 0 @$items.prepend(item.$el) else @$items.append(item.$el.hide()) $(@$items.children()[position - 1]).after(item.$el.show()) _addItem: (path, object, position, config) -> item = new Item(@module, path, object, config) @items[object._id] = item @_updateItemPosition(item, position) _processConfigItems: -> for slug, config of @config.items object = { _id: slug, _title: config.title ? slug.titleize() } if config.objectStore $.extend(object, config.objectStore.get()) if config.items or config.arrayStore @module.addNestedList(slug, config, this) @_addItem("#/#{ @path }/#{ slug }", object, 0, config) @configItemsCount += 1 _bindConfigObjectStore: -> _bindConfigArrayStore: -> # NOTE: starts data fetch @config.arrayStore.on 'object_added', (e, data) => @_addItem("#/#{ @path }/view/#{ data.object._id }", data.object, data.position, @config) data.callback?(data.object) @config.arrayStore.on 'object_changed', (e, data) => item = @items[data.object._id] item.render() @_updateItemPosition(item, data.position) data.callback?(data.object) @config.arrayStore.on 'object_removed', (e, data) => @items[data.object_id].destroy() delete @items[data.object_id] @config.arrayStore.on 'objects_added', (e, data) => @$el.removeClass 'list-loading' if @config.arrayStore.pagination _listBindScroll(this) if @config.arrayStore.searchable _listBindSearch(this) if @config.arrayStore.reorderable _listBindReorder(this) constructor: (@module, @name, @config, @parentList) -> @configItemsCount = 0 @path = @_path() @items = {} @title = @config.title ? @name.titleize() @$el =$ "