Permalink
Browse files

add wf:short_if and modify textarea to use it

  • Loading branch information...
1 parent 5b67b89 commit a7ed77a8037544378028383805ee202a50b4b86f @choptastic choptastic committed Oct 26, 2011
Showing with 39 additions and 10 deletions.
  1. +20 −10 src/elements/forms/element_inplace_textarea.erl
  2. +14 −0 src/lib/wf_convert.erl
  3. +5 −0 src/wf.erl
@@ -31,17 +31,23 @@ render_element(Record) ->
OKEvent = #event { delegate=?MODULE, postback={ok, Delegate, Controls, Tag} },
CancelEvent = #event { delegate=?MODULE, postback={cancel, Controls, Tag, OriginalText} },
+ StartMode = Record#inplace_textarea.start_mode,
+
% Create the view...
Text = Record#inplace_textarea.text,
Terms = #panel {
class=[inplace_textbox, Record#inplace_textarea.class],
style=Record#inplace_textarea.style,
body = [
- #panel { id=ViewPanelID, class="view", body=[
+ #panel {
+ id=ViewPanelID,
+ class="view",
+ style = wf:short_if(StartMode==edit,"diplay:none"),
+ body=[
#span { id=LabelID, class="inplace_textarea", text=Text, html_encode=HTMLEncode, actions=[
#buttonize { target=ViewPanelID }
]},
- #span { id=MouseOverID, class="instructions", text="Click to edit", actions=#hide{} }
+ #span { id=MouseOverID, class="instructions", text="Click to edit", style="display:none" }
], actions = [
#event { type=click, actions=[
#hide { target=ViewPanelID },
@@ -51,18 +57,22 @@ render_element(Record) ->
#event { type=mouseover, target=MouseOverID, actions=#show{} },
#event { type=mouseout, target=MouseOverID, actions=#hide{} }
]},
- #panel { id=EditPanelID, class="edit", body=[
- #textarea { id=TextBoxID, text=Text },
- #button { id=OKButtonID, text="OK", actions=OKEvent#event { type=click } },
- #button { id=CancelButtonID, text="Cancel", actions=CancelEvent#event { type=click } }
- ]}
+ #panel {
+ id=EditPanelID,
+ class="edit",
+ style = wf:short_if(StartMode==view,"display:none"),
+ body=[
+ #textarea { id=TextBoxID, text=Text },
+ #button { id=OKButtonID, text="OK", actions=OKEvent#event { type=click } },
+ #button { id=CancelButtonID, text="Cancel", actions=CancelEvent#event { type=click } }
+ ]
+ }
]
},
- case Record#inplace_textarea.start_mode of
- view -> wf:wire(EditPanelID, #hide{});
+ case StartMode of
+ view -> ok; %% do nothing, as we already hide above in the style element
edit ->
- wf:wire(ViewPanelID, #hide{}),
Script = #script { script="obj('me').focus(); obj('me').select();" },
wf:wire(TextBoxID, Script)
end,
@@ -166,6 +166,20 @@ js_escape(<<"script>", Rest/binary>>, Acc) -> js_escape(Rest, <<Acc/binary, "scr
js_escape(<<C, Rest/binary>>, Acc) -> js_escape(Rest, <<Acc/binary, C>>);
js_escape(<<>>, Acc) -> Acc.
+%%% SHORT IF %%%
+
+short_if(true,IfTrue,_IfFalse) when is_function(IfTrue) ->
+ IfTrue();
+short_if(true,IfTrue,_IfFalse) ->
+ IfTrue;
+short_if(_,_IfTrue,IfFalse) when is_function(IfFalse) ->
+ IfFalse();
+short_if(_,_IfTrue,IfFalse) ->
+ IfFalse.
+
+short_if(Cond,IfTrue) ->
+ short_if(Cond,IfTrue,"").
+
%%% CODE BELOW IS FROM MOCHIWEB %%%
%% This is the MIT license.
View
@@ -116,6 +116,11 @@ hex_decode(S) ->
js_escape(String) ->
_String = wf_convert:js_escape(String).
+short_if(Cond,IfTrue) ->
+ _String = wf_convert:short_if(Cond,IfTrue).
+
+short_if(Cond,IfTrue,IfFalse) ->
+ _String = wf_convert:short_if(Cond,IfTrue,IfFalse).
%%% EXPOSE WF_BIND %%%
% TODO

0 comments on commit a7ed77a

Please sign in to comment.