Sha256: 4bbf3b7a77f43ce13e4bdcb569f9f2174327a73bd3a5656bb73f29d6e090e886

Contents?: true

Size: 963 Bytes

Versions: 2

Compression:

Stored size: 963 Bytes

Contents

$ ->
  # Integrates a mediabrowser based editor for reference CMS attributes.

  scrivito.on 'editing', ->
    $('body').on 'click', '[data-scrivito-field-type="reference"]:not([data-editor]), [data-editor="reference"]', (event) ->
      event.preventDefault()

      cmsField = $(event.currentTarget)
      selected = [cmsField.scrivito('content')].filter (element) -> element
      filters = cmsField.data('filters') || cmsField.data('filter')

      # Open mediabrowser with current reference selected and restrict selection to one reference.
      Mediabrowser.open
        selection: selected
        filters: filters

        onSave: (selection) =>
          onMediabrowserSave(selection, cmsField)

    # Save single reference when media browser calls "save".
    onMediabrowserSave = (selection, cmsField) ->
      value = selection[0] || null

      cmsField.scrivito('save', value)
      .done ->
        cmsField.trigger('scrivito_reload')

      true

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
scrivito_editors-0.0.9 app/assets/javascripts/scrivito_editors/reference_editor.js.coffee
scrivito_editors-0.0.8 app/assets/javascripts/scrivito_editors/reference_editor.js.coffee