Skip to content

Instantly share code, notes, and snippets.

@rpip
Last active December 19, 2015 02:19
Show Gist options
  • Save rpip/5882449 to your computer and use it in GitHub Desktop.
Save rpip/5882449 to your computer and use it in GitHub Desktop.
The responses attached to the examples were taken from the Params part of the events method arguments
in the controller as in:
event({_Event, Params, _TriggerId, _TargetId}, Context) ->
io:format("Mod_Buffer Event params : ~p", [Params]).
# 1
{% wire id="delete-{{ buffer.id }}" action={growl text="buffer deleted"} %}
<a id="delete-{{ buffer.id }}" href="#delete-{{ buffer.id }}"><i class="icon-trash"></i>Delete</a>
RESPONSE : Nothing happens.
# 2
{% wire id="deletenow-{{ buffer.id }}" postback="ajaxevent" postback={myevent foo=1 bar=2} %}
<a id="deletenow-{{ buffer.id }}" href="#deletenow-{{ buffer.id }}"><i class="icon-trash"></i>Delete Now</a>
RESPONSE : Nothing happens.
# 3
<a id="delete-{{ buffer.id }}" href="#delete/{{ buffer.id }}"><i class="icon-trash"></i>
{% button text="Delete" class="buffer-action-btn" title="Delete this buffer" action={postback postback="{delete_buffer, {{ buffer.id }} }"} %}</a>
RESPONSE : This is able to send a postback event, but could not parse the {{ buffer.id }} in the postback params, but instead presented as it is '{delete_buffer, {{ buffer.id }} }' .
# 4
{% button text="Postback" postback={my_postback arg1=1 arg2=2 buffer_id="{{ buffer.id }}"} %}
RESPONSE: {my_postback,[{arg1,1},{arg2,2},{buffer_id,"{{ buffer.id }}"}]}
# 5
{% button action={notify message="{delete_buffer, {{ buffer.id }} }"} %}
RESPONSE : Nothing.
# 6
{% button title="Go" action={postback postback="{buffer_delete, {{ buffer.id }}}" action={growl text="sent message"}} %}
RESPONSE : '{buffer_delete, {{ buffer.id }}}'
@kaos
Copy link

kaos commented Jun 28, 2013

Maybe it's right in your code, but on line 5, the format args need to be in a list:
io:format("Mod_Buffer Event params : ~p", [Params]).

OK, a few observations:

  • Why do you set the href attribute on the anchor tags?
  • I'm not sure, but I think that the dash ( - ) in the id may trip you up.. try remove it.
  • Also, for id's, we usually use the auto id on that to help make them unique in a loop, like this:
    {% wire id=#foo.id ... %}<a id="{{ #foo.id }}" ...
    But I'd have to see the rendered result to see if this really is an issue in this case.. (or take a closer look at the code)
  • in #3, your postback is a string, and you get a string. It's tricky, but the the postback is defined in template code (in contrast to template text), i.e. within a set of {% and %} tags, so postback="..." is simply a string, whatever is inside that string is not parsed further.. drop the quotes and it'll work.
  • #4, same thing as in #3, if you wanted the buffer.id value and not the string {{ buffer.id }}.
  • #5, Will have to look at the notify action to see how it is supposed to be working.. never used that one myself.
  • #6, same as #3, #4, drop the quotes on the postback value and you'll get a tuple instead of a string.

Conclusion:
You're close.
Two things (that I can think of) has tripped you up, first, the difference in getting at template values in text vs tags, in tags, you simply write the vars and attributes and construct tuples as needed, i.e. {% tag ..stuff... {foo bar=1 baz=id.title} ... %} where as in normal text it would need to be ..normal text, like html and stuff... {{ {foo bar=1 baz=id.title} }}..... Second, I suspect that DOM id's and dashes don't play nice together..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment