Skip to content

Commit

Permalink
Display dialog when unauthorized requests are performed.
Browse files Browse the repository at this point in the history
Changed more name parts of dyn_dialog to dialog.
  • Loading branch information
jadahl committed Oct 15, 2010
1 parent e480071 commit 4e8f327
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 37 deletions.
8 changes: 4 additions & 4 deletions include/ui.hrl
Expand Up @@ -27,7 +27,7 @@


-record(strong, {?ELEMENT_BASE(element_typeface), body = "", text = "", html_encode = true}). -record(strong, {?ELEMENT_BASE(element_typeface), body = "", text = "", html_encode = true}).
-record(state_panel, {?ELEMENT_BASE(element_state_panel), bodies, inline = false, visible = false, init_state}). -record(state_panel, {?ELEMENT_BASE(element_state_panel), bodies, inline = false, visible = false, init_state}).
-record(dialog, {?ELEMENT_BASE(element_dialog), corner = close, title = "", body = ""}). -record(dialog, {?ELEMENT_BASE(element_dialog), corner = close, title = "", title_class = [], body = ""}).


-record(ext_link, {?ELEMENT_BASE(element_ext_link), url, type, rel, title}). -record(ext_link, {?ELEMENT_BASE(element_ext_link), url, type, rel, title}).


Expand All @@ -41,9 +41,9 @@
-record(state_panel_show, {?ACTION_BASE(action_state_panel), key}). -record(state_panel_show, {?ACTION_BASE(action_state_panel), key}).
-record(state_panel_hide, {?ACTION_BASE(action_state_panel)}). -record(state_panel_hide, {?ACTION_BASE(action_state_panel)}).


-record(dyn_dialog_back, {?ACTION_BASE(action_dialog)}). -record(dialog_back, {?ACTION_BASE(action_dialog)}).
-record(dyn_dialog_set, {?ACTION_BASE(action_dialog), title, body}). -record(dialog_set, {?ACTION_BASE(action_dialog), title, body}).
-record(dyn_dialog_corner, {?ACTION_BASE(action_dialog), corner}). -record(dialog_corner, {?ACTION_BASE(action_dialog), corner}).


-record(dialog_show, {?ACTION_BASE(action_dialog)}). -record(dialog_show, {?ACTION_BASE(action_dialog)}).
-record(dialog_hide, {?ACTION_BASE(action_dialog)}). -record(dialog_hide, {?ACTION_BASE(action_dialog)}).
Expand Down
2 changes: 1 addition & 1 deletion include/utils.hrl
Expand Up @@ -95,7 +95,7 @@
% %
% AUTH(Statement) -> Statement % AUTH(Statement) -> Statement
% %
-define(AUTH(Statement), ?WHEN(session:authenticated(), (fun() -> session:env(), Statement end)())). -define(AUTH(Statement), ?EITHER(session:authenticated(), (fun() -> session:env(), Statement end)(), session:unauthorized_request())).


% %
% Logging % Logging
Expand Down
5 changes: 4 additions & 1 deletion res/translations/en_US.res
Expand Up @@ -40,5 +40,8 @@
{msg_id_post_remove, "Remove post"}, {msg_id_post_remove, "Remove post"},
{msg_id_post_title, "Post content"}, {msg_id_post_title, "Post content"},
{msg_id_post_untitled, "(untitled)"}, {msg_id_post_untitled, "(untitled)"},
{msg_id_posts_empty, "No posts..."} {msg_id_posts_empty, "No posts..."},
{msg_id_reload, "Reload"},
{msg_id_reload_page, "Page needs to be reloaded"},
{msg_id_unauthorized_request, "Unauthorized request"}
]. ].
5 changes: 4 additions & 1 deletion res/translations/sv_SE.res
Expand Up @@ -40,5 +40,8 @@
{msg_id_post_remove, "Ta bort"}, {msg_id_post_remove, "Ta bort"},
{msg_id_post_title, "Titel"}, {msg_id_post_title, "Titel"},
{msg_id_post_untitled, "(ingen titel)"}, {msg_id_post_untitled, "(ingen titel)"},
{msg_id_posts_empty, "Inga inlägg"} {msg_id_posts_empty, "Inga inlägg"},
{msg_id_reload, "Sidan behöver laddas om"},
{msg_id_reload_page, "Ladda om"},
{msg_id_unauthorized_request, "Åtkomst förbjuden"}
]. ].
16 changes: 8 additions & 8 deletions src/actions/action_dialog.erl
Expand Up @@ -34,17 +34,17 @@ render_action(#dialog_show{target = Target}) ->
render_action(#dialog_hide{target = Target}) -> render_action(#dialog_hide{target = Target}) ->
#js_call{fname = "$Site.$dialog_hide", args = [Target]}; #js_call{fname = "$Site.$dialog_hide", args = [Target]};


render_action(#dyn_dialog_back{target = Id}) -> render_action(#dialog_back{target = Id}) ->
#jquery_cast{anchor = Id, target = corner_link, cast = click}; #jquery_cast{anchor = Id, target = corner_link, cast = click};


render_action(#dyn_dialog_corner{ render_action(#dialog_corner{
target = Target, target = Target,
corner = Corner, corner = Corner,
actions = Actions actions = Actions
}) -> }) ->
#update{anchor = Target, target = corner, elements = element_dialog:render_corner(Corner, Actions)}; #update{anchor = Target, target = corner, elements = element_dialog:render_corner(Corner, Actions)};


render_action(#dyn_dialog_set{ render_action(#dialog_set{
target = Target, target = Target,
title = Title, title = Title,
body = Body}) -> body = Body}) ->
Expand All @@ -61,16 +61,16 @@ hide(Id) ->


reset_actions(Id, Title, Body, Corner, Actions) -> reset_actions(Id, Title, Body, Corner, Actions) ->
[ [
#dyn_dialog_corner{target = Id, corner = Corner, actions = Actions}, #dialog_corner{target = Id, corner = Corner, actions = Actions},
#dyn_dialog_set{target = Id, title = Title, body = Body} #dialog_set{target = Id, title = Title, body = Body}
]. ].


set(Id, Title, Body) -> set(Id, Title, Body) ->
wf:wire(#dyn_dialog_set{target = Id, title = Title, body = Body}). wf:wire(#dialog_set{target = Id, title = Title, body = Body}).


corner(Id, Corner, Actions) -> corner(Id, Corner, Actions) ->
wf:wire(#dyn_dialog_corner{target = Id, corner = Corner, actions = Actions}). wf:wire(#dialog_corner{target = Id, corner = Corner, actions = Actions}).


back(Id) -> back(Id) ->
wf:wire(#dyn_dialog_back{target = Id}). wf:wire(#dialog_back{target = Id}).


2 changes: 1 addition & 1 deletion src/cms/cms_admin_view.erl
Expand Up @@ -34,7 +34,7 @@ set_body_close(Title, Body) ->
action_dialog:corner(?DIALOG_ID, close, #dialog_hide{target = ?DIALOG_ID}). action_dialog:corner(?DIALOG_ID, close, #dialog_hide{target = ?DIALOG_ID}).


back_action() -> back_action() ->
#dyn_dialog_back{target = ?DIALOG_ID}. #dialog_back{target = ?DIALOG_ID}.


back() -> back() ->
action_dialog:back(?DIALOG_ID). action_dialog:back(?DIALOG_ID).
Expand Down
1 change: 0 additions & 1 deletion src/dialog.erl
Expand Up @@ -31,6 +31,5 @@ show(Dialog, ContentFun) ->
Class = Dialog#dialog.class, Class = Dialog#dialog.class,
wf:update(dialogs, Dialog#dialog{class = lists:flatten([top_dialog, Class])}), wf:update(dialogs, Dialog#dialog{class = lists:flatten([top_dialog, Class])}),
ContentFun(), ContentFun(),
io:format("show ing dialog ~p~n", [Id]),
wf:wire(Id, #dialog_show{}). wf:wire(Id, #dialog_show{}).


10 changes: 8 additions & 2 deletions src/elements/element_dialog.erl
Expand Up @@ -43,15 +43,21 @@ render_corner(Corner, Actions) ->
}. }.


-spec render_element(dialog()) -> term(). -spec render_element(dialog()) -> term().
render_element(#dialog{id = Id, class = Class, title = Title, body = Body}) -> render_element(#dialog{
id = Id,
class = Class,
title = Title,
title_class = TitleClass,
body = Body}) ->
Corner = #panel{id = corner}, Corner = #panel{id = corner},
FinalTitleClass = lists:flatten([TitleClass, dyn_dialog_title]),


#panel{ #panel{
class = [dialog, Class], class = [dialog, Class],
id = Id, id = Id,
style = ?HIDDEN, style = ?HIDDEN,
body = [ body = [
#panel{class = dyn_dialog_title, body = [#h2{id = title, text = Title}, Corner]}, #panel{class = FinalTitleClass, body = [#h2{id = title, text = Title}, Corner]},
#hr{}, #hr{},
#panel{id = body, body = Body} #panel{id = body, body = Body}
] ]
Expand Down
33 changes: 17 additions & 16 deletions src/session.erl
Expand Up @@ -18,12 +18,14 @@


-module(session). -module(session).
-include_lib("nitrogen/include/wf.inc"). -include_lib("nitrogen/include/wf.inc").
-export([authenticated/0, event/1, env/0, language/1, page_init/0]). -export([authenticated/0, event/1, env/0, language/1, page_init/0, unauthorized_request/0]).


-include("include/config.hrl"). -include("include/config.hrl").
-include("include/utils.hrl"). -include("include/utils.hrl").
-include("include/ui.hrl"). -include("include/ui.hrl").


-include_lib("nitrogen/include/wf.hrl").

% %
% Constants % Constants
% %
Expand Down Expand Up @@ -112,8 +114,7 @@ event(do_logout) ->
session:env(), session:env(),


wf:clear_session(), wf:clear_session(),
wf:wire(admin_panel, #fade{actions = #update{type = remove}}), session_view:logged_out();
wf:wire(#state_panel_set{target = login_link, key = anonymous});


event(Event) -> event(Event) ->
?LOG_WARNING("Unhandled event \"~p\".~n", [Event]). ?LOG_WARNING("Unhandled event \"~p\".~n", [Event]).
Expand All @@ -123,13 +124,8 @@ event(Event) ->
% %


page_init() -> page_init() ->
case wf:user() of User = wf:user(),
undefined -> session_view:page_init(User).
ok;
_ ->
wf:insert_top(menu_bar_center, session_view:admin_panel()),
wf:wire(#show{target = admin_panel})
end.


% %
% Login % Login
Expand All @@ -144,13 +140,10 @@ login() ->
% Set session user value % Set session user value
wf:user(Username), wf:user(Username),


% Update elements % Update view
wf:wire(#state_panel_set{target = login_link, key = authenticated}), session_view:logged_in();
wf:wire(#state_panel_set{target = login_dialog, animate = true, key = success, actions = #focus{target = login_dialog_close_button}}),
wf:insert_bottom(menu_bar_center, session_view:admin_panel()),
wf:wire(#appear{target = admin_panel, speed = "slow"});
_ -> _ ->
wf:wire(#state_panel_set{target = login_dialog, animate = true, key = fail}) session_view:login_failed()
end. end.




Expand Down Expand Up @@ -182,3 +175,11 @@ authenticate1(Username, Password) ->
_ -> _ ->
denied denied
end. end.

%
% Timeout
%

unauthorized_request() ->
session_view:unauthorized_request().

47 changes: 46 additions & 1 deletion src/session_view.erl
Expand Up @@ -17,7 +17,11 @@
% %


-module(session_view). -module(session_view).
-export([login_dialog/0, login_panel/0, admin_panel/0]). -export([
login_dialog/0, login_panel/0, admin_panel/0,
logged_out/0, logged_in/0, login_failed/0, page_init/1,
unauthorized_request/0
]).


-include_lib("nitrogen/include/wf.hrl"). -include_lib("nitrogen/include/wf.hrl").
-include("include/utils.hrl"). -include("include/utils.hrl").
Expand Down Expand Up @@ -177,3 +181,44 @@ admin_panel() ->
] ]
}. }.


logged_out() ->
wf:wire(admin_panel, #fade{actions = #update{type = remove}}),
wf:wire(#state_panel_set{target = login_link, key = anonymous}).

logged_in() ->
% Update elements
wf:wire(#state_panel_set{target = login_link, key = authenticated}),
wf:wire(#state_panel_set{target = login_dialog, animate = true, key = success, actions = #focus{target = login_dialog_close_button}}),
wf:insert_bottom(menu_bar_center, admin_panel()),
wf:wire(#appear{target = admin_panel, speed = "slow"}).

login_failed() ->
wf:wire(#state_panel_set{target = login_dialog, animate = true, key = fail}).

page_init(undefined) ->
ok;
page_init(_User) ->
wf:insert_top(menu_bar_center, admin_panel()),
wf:wire(#show{target = admin_panel}).

unauthorized_request() ->
% display logged out dialog
Dialog = #dialog{
id = unauthorized_request_dialog,
title = ?T(msg_id_unauthorized_request),
title_class = [center, warning],
body = #panel{
class = center,
body = [
% TODO add ability to login
% TODO add reason: session timed out/other (?)
#p{body = ?T(msg_id_reload_page)},
#button{
text = ?T(msg_id_reload),
actions = #event{type = click, actions = #script{script = "location.reload();"}}
}
]
}
},
wf:wire(#site_cast{cast = overlay_inhibit_hide}),
dialog:show(Dialog).
4 changes: 4 additions & 0 deletions wwwroot/jabber.se/jabber.se.css
Expand Up @@ -72,6 +72,10 @@ ul.contact {
text-align: center; text-align: center;
} }


.warning {
color: rgb(245, 100, 100);
}

/* /*
* Basic elements * Basic elements
*/ */
Expand Down
6 changes: 5 additions & 1 deletion wwwroot/jabber.se/jabber.se.js
Expand Up @@ -227,7 +227,7 @@ Site.prototype.$dialog_show = function(dialog_id, callback) {
if (this.active_dialog) if (this.active_dialog)
{ {
this.active_dialog = null; this.active_dialog = null;
dialog.fadeIn('fast', function() { $Site.show_dialog(dialog_id, callback); }); dialog.fadeIn('fast', function() { $Site.$dialog_show(dialog_id, callback); });
} }
else else
{ {
Expand All @@ -247,6 +247,10 @@ Site.prototype.$overlay_hide = function(callback) {
} }
} }


Site.prototype.$overlay_inhibit_hide = function() {
this.overlay.unbind('click');
}

Site.prototype.$set_overlay_size = function() { Site.prototype.$set_overlay_size = function() {
this.overlay.height($(document).height()); this.overlay.height($(document).height());
this.overlay.width($(document).width()); this.overlay.width($(document).width());
Expand Down

0 comments on commit 4e8f327

Please sign in to comment.