evil-blocks icon indicating copy to clipboard operation
evil-blocks copied to clipboard

Dynamic roles

Open vforvova opened this issue 9 years ago • 3 comments

Hi, @ai ! Is there any way to change roles dynamically? For example, I have table cell with a form inside of it:

<%= form_for model.name.downcase, url: adminushka_engine.items_path, method: method, class: 'form-inline', data: { role: 'cell' } do |f| %>
  <span data-role='value'><%= value %></span>
  <div class="input-group hidden" data-role="form">
    <%= f.text_field attribute, value: value, class: 'form-control' %>
    <span class="input-group-btn">
      <button class="btn btn-success" type="submit" data-role="update">
        <span class="glyphicon glyphicon-ok"></span>
      </button>
      <button class="btn btn-danger" type="button" data-role="cancel">
        <span class="glyphicon glyphicon-remove"></span>
      </button>
    </span>
  </div>
<% end %>

I have triggers to switch between form and value views:

evil.block '@@item',
  addHiddenFor: (items) -> items.addClass _hiddenClass
  removeHiddenFrom: (items) -> items.removeClass _hiddenClass

  defaults: ->
    @close $ '@@items'
    return

  open: (cells) ->
    @addHiddenFor cells.find '@value'
    @removeHiddenFrom cells.find '@form'
    cells.data 'role', 'activeCell'
    # evil.block.vitalize cells

  close: (cells) ->
    @addHiddenFor cells.find '@form'
    @removeHiddenFrom cells.find '@value'
    cells.data 'role', 'cell'
    # evil.block.vitalize cells

  'click on @cell': (e) ->
    @defaults()
    @open e.el
    return

  'click on @cancel': (e) ->
    @close e.el.closest '@activeCell'
    return

After I select form view everything goes ok, but when I try to close form view via @cancel button nothing happens. Actually form view had been closed but it was opened again because of click on @cancel and click on @cell both were triggered by click on @cancel button. I tried to resolve it via change role to @activeCell but it was not help. So what do you think, may be you can suggest me another way to resolve my problem?

vforvova avatar Feb 03 '15 06:02 vforvova

You can add custom filter, which will add @rebindRoles method to every block.

ai avatar Feb 03 '15 06:02 ai

Or you can send PR with evil.block.rebindRoles(@) method.

ai avatar Feb 03 '15 06:02 ai

Ok, I'll have a look

vforvova avatar Feb 03 '15 06:02 vforvova