Sha256: 544fa1f9bb11e2df80a69fdbe2517b49ca42a43545a82467ad34dc44f346ae5c

Contents?: true

Size: 1.07 KB

Versions: 4

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

4 entries across 4 versions & 1 rubygems

Version Path
scrivito_editors-0.0.16 app/assets/javascripts/scrivito_editors/reference_editor.js.coffee
scrivito_editors-0.0.15 app/assets/javascripts/scrivito_editors/reference_editor.js.coffee
scrivito_editors-0.0.14 app/assets/javascripts/scrivito_editors/reference_editor.js.coffee
scrivito_editors-0.0.13 app/assets/javascripts/scrivito_editors/reference_editor.js.coffee