Sha256: 445611039ed8470f325eb93e4e8cc5a8a41f93a549ea8b262b70177819e5eddd

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

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

  scrivito.on 'load', ->
    if scrivito.in_editable_view()
      $('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 resource browser with current reference selected.
        Resourcebrowser.open
          selection: selected
          filters: filters
          selectionMode: 'single'

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

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

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

        true

Version data entries

1 entries across 1 versions & 1 rubygems

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