# ----------------------------------------------------------------------------- # Author: Alexander Kravets , # Slate Studio (http://www.slatestudio.com) # # Coding Guide: # https://github.com/thoughtbot/guides/tree/master/style/coffeescript # ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------- # Loft Asset Item # ----------------------------------------------------------------------------- class @LoftAssetItem extends Item constructor: (@module, @path, @object, @config) -> @$el =$ "
" @render() # PRIVATE =============================================== _bind_name_input: -> @$nameInput.on 'blur', (e) => @_update_name_if_changed() @$nameInput.on 'keyup', (e) => if e.keyCode == 13 then $(e.target).blur() if e.keyCode == 27 then @_cancel_name_change() _edit_name: (e) -> @$el.addClass('edit-name') @$nameInput.focus().select() _cancel_name_change: -> @$el.removeClass('edit-name') name = @$title.html() @$nameInput.val(name) _update_name_if_changed: -> @$el.removeClass('edit-name') name = @$nameInput.val() if name == @$title.html() then return @$title.html(name) @config.arrayStore.update @object._id, { '[name]': name }, onSuccess: (object) => onError: (errors) => # process errors # PUBLIC ================================================ render: -> @$el.html('').removeClass('item-folder has-subtitle has-thumbnail') @_render_title() @_render_subtitle() # asset icon with link @$link =$ "" @$el.prepend(@$link) # thumbnail for images if @object.type == 'image' && @object.grid_item_thumbnail != '' @$thumbnailSmall =$ "" @$thumbnailMedium =$ "" @$link.append @$thumbnailSmall @$link.append @$thumbnailMedium # checkbox for item selection @$checkbox =$ "
" @$checkboxInput =$ "" @$checkbox.append(@$checkboxInput) @$el.prepend(@$checkbox) # input for assets name name = @$title.text() @$name =$ "
" @$nameInput =$ "" @$name.append @$nameInput @$title.before @$name @_bind_name_input() # handler for asset name change on title click @$title.on 'click', (e) => @_edit_name(e)