Sha256: 7fd011292171e04fc71658f9f0dff6bec9e2ab823581e7c231060dce7f9a0e51

Contents?: true

Size: 1.47 KB

Versions: 6

Compression:

Stored size: 1.47 KB

Contents

class @GalleryImageView extends Backbone.View

  events :
    'click .remove-ico' : 'remove'
    'click [data-crop]' : 'crop'

  initialize : () ->
    @model.on 'image-removed', @_onImageRemove
    @_initCrop()

  remove : () ->
    @model.remove() if confirm I18n.t('rademade_admin.image_remove_confirm')

  crop : () ->
    @cropper.setOriginalDimensions @model.get('originalDimensions')
    @cropper.show @model.get('fullUrl')
    @$el.closest('.input-holder').append @cropper.$el

  _initCrop : () ->
    @_findCrop()
    if @$crop.length > 0
      @_updateModelCropData()
      @cropper = new Cropper()
      @cropper.on 'crop-image', @_cropImage

  _cropImage : (cropData) =>
    @model.crop @$crop.data('url'), cropData, (data) =>
      @$el.find('img').attr('src', data.gallery_image_url)
      @_updateCropHtml(data.crop_button_html)
      @_updateModelCropData()

  _updateModelCropData : () ->
    @model.set
      fullUrl : @$crop.data('fullUrl')
      originalDimensions : @$crop.data('originalDimensions').split(',')

  _updateCropHtml : (html) ->
    @$crop.replaceWith(html)
    @_findCrop()

  _findCrop : () ->
    @$crop = @$el.find('[data-crop]')

  _onImageRemove : () =>
    fadeTime = 300
    @$el.fadeOut fadeTime
    setTimeout () =>
      @$el.remove()
    , fadeTime

  @init : ($el) ->
    model = new GalleryImageModel
      imageId : $el.data('id')
      removeUrl : $el.find('.remove-ico').data('url')
    new GalleryImageView
      model : model
      el : $el
    model

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rademade_admin-0.2.2 app/assets/javascripts/rademade_admin/app/gallery/image/view.coffee
rademade_admin-0.2.1 app/assets/javascripts/rademade_admin/app/gallery/image/view.coffee
rademade_admin-0.2.0 app/assets/javascripts/rademade_admin/app/gallery/image/view.coffee
rademade_admin-0.1.6 app/assets/javascripts/rademade_admin/app/gallery/image/view.coffee
rademade_admin-0.1.5 app/assets/javascripts/rademade_admin/app/gallery/image/view.coffee
rademade_admin-0.1.4 app/assets/javascripts/rademade_admin/app/gallery/image/view.coffee