Skip to content

Commit 5752433

Browse files
committed
#prompt{basic=true} is working. Now to add basic=false
1 parent 49ea5ad commit 5752433

6 files changed

Lines changed: 58 additions & 12 deletions

File tree

include/wf.hrl

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,12 +1064,6 @@
10641064
-record(alert, {?ACTION_BASE(action_alert),
10651065
text="" :: text()
10661066
}).
1067-
-record(confirm, {?ACTION_BASE(action_confirm),
1068-
text="" :: text(),
1069-
postback :: term(),
1070-
vessel :: id() | text(),
1071-
delegate :: module()
1072-
}).
10731067
-record(modal, {?ACTION_BASE(action_modal),
10741068
id :: undefined | id(),
10751069
text="" :: text() | undefined,
@@ -1079,13 +1073,32 @@
10791073
buttons=[] :: body() | undefined |
10801074
[#button{} |
10811075
{text(), Postback :: any()} |
1082-
{text(), Delegate :: module(), Postback :: any()}],
1076+
{text(), Postback :: any(), Delegate :: module()}],
10831077

10841078
close_text :: text() | undefined,
10851079
close_body :: body() | undefined,
10861080
show_close_button=true :: boolean(),
10871081
options=[] :: term()
10881082
}).
1083+
%% create #confirm{} from #modal{}
1084+
?WF_EXTEND(modal, confirm, action_confirm, [
1085+
{postback, undefined, "term()"},
1086+
{vessel, undefined, "id() | text()"},
1087+
{delegate, undefined, "module()"},
1088+
{basic, false, "boolean()"}
1089+
]).
1090+
1091+
%% Create #prompt{} from #modal{}
1092+
?WF_EXTEND(modal, prompt, action_prompt, [
1093+
%% `tag` used instead of `postback` because `postback` implies a call to
1094+
%% event/1, while `tag` implies a call to a different function
1095+
{tag, undefined, "term()"},
1096+
{vessel, undefined, "id() | text()"},
1097+
{delegate, undefined, "module()"},
1098+
{basic, false, "boolean()"},
1099+
{fields, [], "list()"},
1100+
{default, "", "text()"}
1101+
]).
10891102
-record(close_modal, {?ACTION_BASE(action_modal),
10901103
id :: undefined | id(),
10911104
options=[] :: term()

priv/www/nitrogen.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,6 @@ var page = document;
20382038

20392039
var Nitrogen = new NitrogenClass();
20402040

2041-
20422041
window.addEventListener('beforeunload', function() {
20432042
// Give a "redirect prompt" if presented to prevent such.
20442043
if(!Nitrogen.$allow_redirect) {

src/actions/action_confirm.erl

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
-module(action_confirm).
77
-include("wf.hrl").
88
-export([render_action/1]).
9+
-export([reflect/0]).
910

10-
render_action(Record) ->
11+
reflect() -> record_info(fields, confirm).
12+
13+
render_action(Record = #confirm{basic=true}) ->
1114
TriggerPath = Record#confirm.trigger,
1215
TargetPath = Record#confirm.target,
1316
Delegate = Record#confirm.delegate,
@@ -22,5 +25,33 @@ render_action(Record) ->
2225
},
2326
Record#confirm.actions,
2427
"}"
25-
].
28+
];
29+
render_action(Confirm = #confirm{basic=false}) ->
30+
OKButtonList = make_ok_button_list(Confirm),
31+
Confirm2 = maybe_set_close_text(Confirm),
32+
Modal = wf_utils:copy_fields(Confirm2, #modal{}),
33+
Buttons = Modal#modal.buttons ++ OKButtonList,
34+
Modal2 = Modal#modal{buttons=Buttons},
35+
Modal2.
36+
37+
maybe_set_close_text(C = #confirm{close_text=T, close_body=B})
38+
when ?WF_BLANK(T) andalso ?WF_BLANK(B) ->
39+
%% if the close button info isn't specified, override #modal's default of
40+
%% "Close" with "Cancel" (to more accurately match the way javascript's
41+
%% confirm() does it)"
42+
C#confirm{close_text="Cancel"};
43+
maybe_set_close_text(C) ->
44+
C.
2645

46+
make_ok_button_list(#confirm{postback=Postback, vessel=Vessel, delegate=Delegate, actions=Actions}) when not(?WF_BLANK(Postback)) ->
47+
[#button{
48+
text="OK",
49+
postback=Postback,
50+
vessel=Vessel,
51+
delegate=Delegate,
52+
%trigger=TriggerPath,
53+
%target=TargetPath,
54+
click=[Actions,#close_modal{}]
55+
}];
56+
make_ok_button_list(_) ->
57+
[].

src/actions/action_modal.erl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
-include("wf.hrl").
88
-export([render_action/1]).
99

10+
-export([reflect/0]).
11+
reflect() -> record_info(fields, modal).
12+
1013
render_action(Rec = #modal{}) ->
1114
modal_handler:render_open_action(Rec);
1215
render_action(Rec = #close_modal{}) ->

src/handlers/modal/default_modal_handler.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ process_buttons([X | Rest]) when ?WF_BLANK(X) ->
7777
process_buttons(Rest);
7878
process_buttons([{Text, Postback} | Rest]) ->
7979
[#button{text=Text, postback=Postback} | process_buttons(Rest)];
80-
process_buttons([{Text, Delegate, Postback} | Rest]) ->
80+
process_buttons([{Text, Postback, Delegate} | Rest]) ->
8181
[#button{text=Text, postback=Postback, delegate=Delegate} | process_buttons(Rest)];
8282
process_buttons([Button | Rest]) when ?IS_ELEMENT(Button) ->
8383
[Button | process_buttons(Rest)];

src/lib/wf_event.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ generate_postback_script(Postback, Vessel, Anchor, ValidationGroup, HandleInvali
7878
[
7979
wf:f("Nitrogen.$queue_event(~s, '~s', ", [VesselSelector, ValidationGroup]),
8080
OnInvalidScript,
81-
wf:f(", '~s', ~s);", [PickledPostbackInfo, ExtraParam])
81+
wf:f(", '~s', ~ts);", [PickledPostbackInfo, ExtraParam])
8282
].
8383

8484

0 commit comments

Comments
 (0)