Sha256: d11db4e4fc134c74c22f8454c38f2ff61b9e45a9b6413b3bb8aaf5d6a65e6042

Contents?: true

Size: 1.6 KB

Versions: 7

Compression:

Stored size: 1.6 KB

Contents

# ---------------------------------------------------------
# SETTINGS REDIRECTS
# ---------------------------------------------------------

@Character.Settings.RedirectsLayout = Character.Settings.DetailsLayout.extend
  _bindAdd: ->
    @ui.actionAdd.on 'click', (e) =>
      e.preventDefault()

      $item = @ui.template.clone()

      $item.removeAttr('id')

      objectId = new Date().getTime()
      $item.find('[name]').each (idx, el) ->
        newName = $(el).attr('name').replace(/objects\[\]\[\]/g, "objects[][#{ objectId }]")
        $(el).attr('name', newName)

      @ui.template.before($item)

      $item.find('.action_add').hide()
      $item.find('.action_delete').show()

  _bindDelete: ->
    @ui.content.on 'click', '.action_delete', (e) ->
      itemCls = $(e.currentTarget).attr('data-item-class')
      item    = $(e.currentTarget).closest(".#{ itemCls }")

      # TODO: query could be optimized with one regex
      destroy_field = _.find item.find("input[type=hidden]"), (f) ->
        name = $(f).attr('name') ; _(name).endsWith('[_destroy]')

      if destroy_field
        $(destroy_field).attr('value', 'true')
        item.replaceWith(destroy_field)
      else
        item.remove()
      false

  afterRenderContent: ->
    @ui.template   = $('#template')
    @ui.actionAdd  = @ui.form.find('.action_add')

    @_bindAdd()
    @_bindDelete()

  afterOnClose: ->
    @ui.actionAdd.off 'click'

  beforeSave: ->
    @ui.template.remove()

chr.settingsRedirects = (titleMenu = 'Redirects') ->
  chr.settingsModule 'Redirects',
    titleMenu: titleMenu
    detailsViewClass: Character.Settings.RedirectsLayout

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
character-1.0.6 app/assets/javascripts/character/settings/_redirects.coffee
character-1.0.5 app/assets/javascripts/character/settings/_redirects.coffee
character-1.0.4 app/assets/javascripts/character/settings/_redirects.coffee
character-1.0.3 app/assets/javascripts/character/settings/_redirects.coffee
character-1.0.2 app/assets/javascripts/character/settings/_redirects.coffee
character-1.0.1 app/assets/javascripts/character/settings/_redirects.coffee
character-1.0.0 app/assets/javascripts/character/settings/_redirects.coffee