Permalink
Browse files

inplace elements restore orig value. js_escape "'"

  • Loading branch information...
1 parent 53867b3 commit 31a1231637d427a7908a75a9ce910bd585b05831 @choptastic choptastic committed Nov 11, 2012
@@ -20,7 +20,6 @@ render_element(Record) ->
TextBoxID = wf:temp_id(),
Tag = Record#inplace_textarea.tag,
- OriginalText = Record#inplace_textarea.text,
Delegate = Record#inplace_textarea.delegate,
HTMLEncode = Record#inplace_textarea.html_encode,
@@ -30,7 +29,6 @@ render_element(Record) ->
% Set up the events...
Controls = {ViewPanelID, LabelID, EditPanelID, TextBoxID},
OKEvent = #event { delegate=?MODULE, postback={ok, Delegate, Controls, Tag} },
- CancelEvent = #event { delegate=?MODULE, postback={cancel, Controls, Tag, OriginalText} },
StartMode = Record#inplace_textarea.start_mode,
@@ -66,7 +64,11 @@ render_element(Record) ->
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 } }
+ #button { id=CancelButtonID, text="Cancel", click=[
+ #hide{ target=EditPanelID },
+ #show{ target=ViewPanelID },
+ #script{ script=wf:f("obj('~s').value=obj('~s').defaultValue;",[TextBoxID, TextBoxID]) }
+ ]}
]
}
]
@@ -96,12 +98,7 @@ event({ok, Delegate, {ViewPanelID, LabelID, EditPanelID, TextBoxID}, Tag}) ->
wf:set(TextBoxID, Value1),
wf:wire(EditPanelID, #hide {}),
wf:wire(ViewPanelID, #show {}),
- ok;
-
-event({cancel, {ViewPanelID, _LabelID, EditPanelID, TextBoxID}, _Tag, OriginalText}) ->
- wf:set(TextBoxID, OriginalText),
- wf:wire(EditPanelID, #hide {}),
- wf:wire(ViewPanelID, #show {}),
+ wf:wire(wf:f("obj('~s').defaultValue = '~s';",[TextBoxID,wf:js_escape(Value1)])),
ok;
event(_Tag) -> ok.
@@ -19,13 +19,11 @@ render_element(Record) ->
MouseOverID = wf:temp_id(),
TextBoxID = wf:temp_id(),
Tag = Record#inplace_textbox.tag,
- OriginalText = Record#inplace_textbox.text,
Delegate = Record#inplace_textbox.delegate,
% Set up the events...
Controls = {ViewPanelID, LabelID, EditPanelID, TextBoxID},
OKEvent = #event { delegate=?MODULE, postback={ok, Delegate, Controls, Tag} },
- CancelEvent = #event { delegate=?MODULE, postback={cancel, Controls, Tag, OriginalText} },
% Create the view...
Text = Record#inplace_textbox.text,
@@ -51,7 +49,11 @@ render_element(Record) ->
#panel { id=EditPanelID, class="edit", body=[
#textbox { id=TextBoxID, text=Text, next=OKButtonID },
#button { id=OKButtonID, text="OK" },
- #button { id=CancelButtonID, text="Cancel" }
+ #button { id=CancelButtonID, text="Cancel", click=[
+ #hide{ target=EditPanelID },
+ #show{ target=ViewPanelID },
+ #script{ script=wf:f("obj('~s').value=obj('~s').defaultValue;",[TextBoxID, TextBoxID]) }
+ ]}
]}
]
},
@@ -64,7 +66,6 @@ render_element(Record) ->
wf:wire(TextBoxID, Script)
end,
- wf:wire(CancelButtonID, CancelEvent#event { type=click }),
wf:wire(OKButtonID, OKEvent#event { type=click }),
wf:wire(OKButtonID, TextBoxID, #validate { attach_to=CancelButtonID, validators=Record#inplace_textbox.validators }),
@@ -79,12 +80,7 @@ event({ok, Delegate, {ViewPanelID, LabelID, EditPanelID, TextBoxID}, Tag}) ->
wf:set(TextBoxID, Value1),
wf:wire(EditPanelID, #hide {}),
wf:wire(ViewPanelID, #show {}),
- ok;
-
-event({cancel, {ViewPanelID, _LabelID, EditPanelID, TextBoxID}, _Tag, OriginalText}) ->
- wf:set(TextBoxID, OriginalText),
- wf:wire(EditPanelID, #hide {}),
- wf:wire(ViewPanelID, #show {}),
+ wf:wire(wf:f("obj('~s').defaultValue = '~s';",[TextBoxID,wf:js_escape(Value1)])),
ok;
event(_Tag) -> ok.
@@ -175,6 +175,7 @@ js_escape(<<"\\", Rest/binary>>, Acc) -> js_escape(Rest, <<Acc/binary, "\\\\">>)
js_escape(<<"\r", Rest/binary>>, Acc) -> js_escape(Rest, <<Acc/binary, "\\r">>);
js_escape(<<"\n", Rest/binary>>, Acc) -> js_escape(Rest, <<Acc/binary, "\\n">>);
js_escape(<<"\"", Rest/binary>>, Acc) -> js_escape(Rest, <<Acc/binary, "\\\"">>);
+js_escape(<<"'",Rest/binary>>,Acc) -> js_escape(Rest, <<Acc/binary, "\\'">>);
js_escape(<<"<script", Rest/binary>>, Acc) -> js_escape(Rest, <<Acc/binary, "<scr\" + \"ipt">>);
js_escape(<<"script>", Rest/binary>>, Acc) -> js_escape(Rest, <<Acc/binary, "scr\" + \"ipt>">>);
js_escape(<<C, Rest/binary>>, Acc) -> js_escape(Rest, <<Acc/binary, C>>);

0 comments on commit 31a1231

Please sign in to comment.