swap

An article by Gaspard Bucher

Changes attribute values from a list. Must be used inside an ajaxable context (group, each).

  1. action
    1. action
    2. login_link
    3. swap
    4. visitor_link
  2. ajax
  3. API
  4. classes
  5. common attributes
  6. conditions
  7. context
  8. dates
  9. display
  10. forms
  11. i18n
  12. meta
  13. SQLiss
  14. urls

Changes attribute values from a list. Must be used inside an ajaxable context (group, each).

  • publish Set whether to auto-publish node after save.
  • states list of states the swap should loop in.
  • attr attribute to change.
  • update remote block to update (can be ‘_page’)
see publish, zena 1.0

The ‘swap’ method is used to loop through a list of values by repeatedly clicking on a link.

In this first example, the ajax call replaces the whole “each” block after ‘flag’ value changes.

When the ‘update’ argument is omitted, the closest block or each loop is used.

<ul do='tasks from project'>
  <li do='each' class='#{flag}'>
    <r:swap attr='flag' states='todo,done,alert'/><r:link/>
  </li>
</ul>

In this second example, only the defined “block” is changed.

<ul do='tasks from project'>
  <li do='each'>
    <span do='block' class='#{flag}'>
      <r:swap attr='flag' states='todo,done,alert'/><r:flag/></span><r:link/>
  </li>
</ul>

This example uses the integer field “custom_a” and the states includes the nil value.

<div id='swap' class='orange' do='block' green_if='custom_a == 100'>
  <span do='swap' states='100, ' attr='status' publish='true' do='t("img_status#{status}")'/> <r:title/>
</div>

advanced

In case you want to change more then one argument or need other settings, you can use pure rubyless to achieve the same result with the “next_in_list” method and setting ‘update’ as link parameter:

<r:link action='update' update='_page' node[flag]='#{next_in_list(flag, "todo,done")}'/>