Sha256: 274547242c3e2cb30ac1e7da87637166ac920f680c9513a1dda3825d5df697c5

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

return if !scrivito?

scrivito.content_browser._inspector = do ->
  inspectorSelector: '.scrivito-content-browser-inspector'
  contentSelector: '.inspector-content'
  inspector: undefined
  objectId: undefined

  _initializeBindings: ->
    @modal.on 'click', 'li.content-browser-item', (event) =>
      @_onInspect(event)

    @inspector = @modal.find(@inspectorSelector)
    @inspector.hide()

  _onInspect: (event) ->
    if $(event.target).hasClass('scrivito-content-browser-inspect')
      currentTarget = $(event.currentTarget)
      id = currentTarget.data('id')

      if id
        @open(id)
        @_highlightItem(currentTarget)

  _renderLoading: ->
    @inspector.html(@_loadingTemplate())

  _loadingTemplate: ->
    icon = $('<i></i>')
      .addClass('scrivito-content-browser-icon scrivito-content-browser-icon-refresh')

    $('<div></div>')
      .addClass('scrivito-content-browser-loading')
      .html(icon)

  _highlightItem: (element) ->
    @modal.find('li.content-browser-item.active').removeClass('active')
    element.addClass('active')

  init: (modal) ->
    @modal = modal
    @_initializeBindings()

  # Opens the inspector section in the content browser for the given object ID and displays its edit
  # view.
  open: (objectId) ->
    @objectId = objectId

    @inspector.show()
    @_renderLoading()

    $.ajax
      url: '/scrivito_content_browser/inspector'
      dataType: 'json'
      data:
        id: @objectId
      success: (json) =>
        @inspector.html(json.content)
        scrivito.trigger('new_content', @inspector)

      error: =>
        @inspector.empty()

  # Closes the inspector section of the content browser.
  close: ->
    @inspector.empty()
    @inspector.hide()

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
scrivito_content_browser-0.30.0 app/assets/javascripts/scrivito_content_browser/inspector.js.coffee
scrivito_content_browser-0.1.0 app/assets/javascripts/scrivito_content_browser/inspector.js.coffee