Namdak Tonpa 9 years ago
parent
commit
436c1c2f57

+ 1 - 0
include/nitro.hrl

@@ -181,6 +181,7 @@
 -record(wire,    {?ACTION_BASE(action_wire)}).
 -record(api,     {?ACTION_BASE(action_api), name, tag, delegate }).
 -record(event,   {?ACTION_BASE(action_event), type=default, postback, delegate, validation=[]}).
+-record(bind,    {?ACTION_BASE(action_bind), type=click, postback=[]}).
 -record(alert,   {?ACTION_BASE(action_alert), text}).
 -record(confirm, {?ACTION_BASE(action_confirm), text, postback, delegate}).
 -record(jq,      {?ACTION_BASE(action_jq), property, method, args=[], right, format="~s"}).

+ 7 - 0
src/actions/action_bind.erl

@@ -0,0 +1,7 @@
+-module(action_bind).
+-author('Maxim Sokhatsky').
+-include_lib("nitro/include/nitro.hrl").
+-compile(export_all).
+
+render_action(#bind{postback=Code,target=Control,type=Type}) ->
+    [list_to_binary(nitro:f("{ var x=qi('~w'); if(x)x.addEventListener('~w', function(e) { ~s }); }",[Control,Type,Code]))].

+ 0 - 6
src/actions/action_event.erl

@@ -4,12 +4,6 @@
 -compile(export_all).
 
 render_action(#event{source=undefined}) -> [];
-
-render_action(#event{postback={bin,Value},target=Control,type=Type}) ->
-    PostbackBin = wf_event:new(bin,Value),
-    [list_to_binary([<<"qi('">>,nitro:to_binary(Control),<<"').addEventListener('">>,
-        nitro:to_binary(Type),<<"',function (event){">>,PostbackBin,<<"});">>])];
-
 render_action(#event{postback=Postback,actions=_Actions,source=Source,target=Control,type=Type,delegate=Delegate,validation=Validation}) ->
     Element = nitro:to_list(Control),
     Data=list_to_binary([<<"[tuple(tuple(utf8_toByteArray('">>,Element,<<"'),bin('detail')),[])">>,

+ 3 - 0
src/elements/element_button.erl

@@ -6,6 +6,7 @@
 render_element(Record) ->
     Id = case Record#button.postback of
         undefined -> Record#button.id;
+        [] -> Record#button.id;
         Postback ->
           ID = case Record#button.id of undefined -> nitro:temp_id(); I -> I end,
           nitro:wire(#event{type=click, postback=Postback, target=ID,
@@ -17,5 +18,7 @@ render_element(Record) ->
         {<<"name">>, Record#button.name},
         {<<"class">>, Record#button.class},
         {<<"style">>, Record#button.style},
+        {<<"onchange">>, Record#button.onchange},
+        {<<"onclick">>, Record#button.onclick},
         {<<"disabled">>, if Record#button.disabled == true -> "disabled"; true -> undefined end},
         {<<"value">>, Record#button.value}  | Record#button.data_fields ]).

+ 1 - 0
src/elements/element_input.erl

@@ -5,6 +5,7 @@
 render_element(Record) ->
     Id = case Record#input.postback of
         undefined -> Record#input.id;
+        [] -> Record#input.id;
         Postback ->
           ID = case Record#input.id of
             undefined -> nitro:temp_id();