# ----------------------------------------------------------------------------- # Author: Alexander Kravets , # Slate Studio (http://www.slatestudio.com) # # Coding Guide: # https://github.com/thoughtbot/guides/tree/master/style/coffeescript # ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------- # LIST ITEM # ----------------------------------------------------------------------------- # # config options: # onItemRender # # public methods: # render() # destroy() # position() # # ----------------------------------------------------------------------------- class @Item constructor: (@module, @path, @object, @config, @type) -> @$el =$ """""" @render() # PRIVATE =============================================== _render_title: -> title = @object.__title__ # title for @config.items title ?= @object[@config.itemTitleField] title ?= @object['_list_item_title'] title ?= _firstNonEmptyValue(@object) title ?= "No Title" title = title.plainText() @$title =$ "
#{ title }
" @$el.append(@$title) _render_subtitle: -> subtitle = @object.__subtitle__ # subtitle for @config.items if @config.itemSubtitleField subtitle ?= @object[@config.itemSubtitleField] subtitle ?= @object['_list_item_subtitle'] if subtitle @$subtitle =$ "
#{ subtitle }
" @$el.append(@$subtitle) @$el.addClass 'has-subtitle' _render_thumbnail: -> imageUrl = @config.itemThumbnail?(@object) imageUrl ?= @object[@config.itemThumbnail] imageUrl ?= @object['_list_item_thumbnail'] if imageUrl # RAILS carrierwave fix, check if still required if not imageUrl.endsWith('_old_') @$thumbnail =$ "
" @$el.append(@$thumbnail) @$el.addClass 'has-thumbnail' # PUBLIC ================================================ render: -> @$el.html('').removeClass('has-subtitle has-thumbnail') @_render_title() @_render_subtitle() if @type == 'folder' @$el.append $("
") if @type == 'object' @_render_thumbnail() if @config.arrayStore and @config.arrayStore.reorderable @$el.addClass('reorderable') @$el.append $("
") if @type == 'object' @config.onItemRender?(this) destroy: -> @$el.remove() position: -> positionFieldName = @config.arrayStore.sortBy parseFloat(@object[positionFieldName])