Permalink
Browse files

Display dialog when unauthorized requests are performed.

Changed more name parts of dyn_dialog to dialog.
  • Loading branch information...
1 parent e480071 commit 4e8f32752f7333308e6cfa54f7b958a9426d1320 @jadahl jadahl committed Oct 15, 2010
View
@@ -27,7 +27,7 @@
-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(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}).
@@ -41,9 +41,9 @@
-record(state_panel_show, {?ACTION_BASE(action_state_panel), key}).
-record(state_panel_hide, {?ACTION_BASE(action_state_panel)}).
--record(dyn_dialog_back, {?ACTION_BASE(action_dialog)}).
--record(dyn_dialog_set, {?ACTION_BASE(action_dialog), title, body}).
--record(dyn_dialog_corner, {?ACTION_BASE(action_dialog), corner}).
+-record(dialog_back, {?ACTION_BASE(action_dialog)}).
+-record(dialog_set, {?ACTION_BASE(action_dialog), title, body}).
+-record(dialog_corner, {?ACTION_BASE(action_dialog), corner}).
-record(dialog_show, {?ACTION_BASE(action_dialog)}).
-record(dialog_hide, {?ACTION_BASE(action_dialog)}).
View
@@ -95,7 +95,7 @@
%
% 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
@@ -40,5 +40,8 @@
{msg_id_post_remove, "Remove post"},
{msg_id_post_title, "Post content"},
{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"}
].
@@ -40,5 +40,8 @@
{msg_id_post_remove, "Ta bort"},
{msg_id_post_title, "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"}
].
@@ -34,17 +34,17 @@ render_action(#dialog_show{target = Target}) ->
render_action(#dialog_hide{target = 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};
-render_action(#dyn_dialog_corner{
+render_action(#dialog_corner{
target = Target,
corner = Corner,
actions = Actions
}) ->
#update{anchor = Target, target = corner, elements = element_dialog:render_corner(Corner, Actions)};
-render_action(#dyn_dialog_set{
+render_action(#dialog_set{
target = Target,
title = Title,
body = Body}) ->
@@ -61,16 +61,16 @@ hide(Id) ->
reset_actions(Id, Title, Body, Corner, Actions) ->
[
- #dyn_dialog_corner{target = Id, corner = Corner, actions = Actions},
- #dyn_dialog_set{target = Id, title = Title, body = Body}
+ #dialog_corner{target = Id, corner = Corner, actions = Actions},
+ #dialog_set{target = Id, title = Title, body = 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) ->
- wf:wire(#dyn_dialog_corner{target = Id, corner = Corner, actions = Actions}).
+ wf:wire(#dialog_corner{target = Id, corner = Corner, actions = Actions}).
back(Id) ->
- wf:wire(#dyn_dialog_back{target = Id}).
+ wf:wire(#dialog_back{target = Id}).
@@ -34,7 +34,7 @@ set_body_close(Title, Body) ->
action_dialog:corner(?DIALOG_ID, close, #dialog_hide{target = ?DIALOG_ID}).
back_action() ->
- #dyn_dialog_back{target = ?DIALOG_ID}.
+ #dialog_back{target = ?DIALOG_ID}.
back() ->
action_dialog:back(?DIALOG_ID).
View
@@ -31,6 +31,5 @@ show(Dialog, ContentFun) ->
Class = Dialog#dialog.class,
wf:update(dialogs, Dialog#dialog{class = lists:flatten([top_dialog, Class])}),
ContentFun(),
- io:format("show ing dialog ~p~n", [Id]),
wf:wire(Id, #dialog_show{}).
@@ -43,15 +43,21 @@ render_corner(Corner, Actions) ->
}.
-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},
+ FinalTitleClass = lists:flatten([TitleClass, dyn_dialog_title]),
#panel{
class = [dialog, Class],
id = Id,
style = ?HIDDEN,
body = [
- #panel{class = dyn_dialog_title, body = [#h2{id = title, text = Title}, Corner]},
+ #panel{class = FinalTitleClass, body = [#h2{id = title, text = Title}, Corner]},
#hr{},
#panel{id = body, body = Body}
]
View
@@ -18,12 +18,14 @@
-module(session).
-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/utils.hrl").
-include("include/ui.hrl").
+-include_lib("nitrogen/include/wf.hrl").
+
%
% Constants
%
@@ -112,8 +114,7 @@ event(do_logout) ->
session:env(),
wf:clear_session(),
- wf:wire(admin_panel, #fade{actions = #update{type = remove}}),
- wf:wire(#state_panel_set{target = login_link, key = anonymous});
+ session_view:logged_out();
event(Event) ->
?LOG_WARNING("Unhandled event \"~p\".~n", [Event]).
@@ -123,13 +124,8 @@ event(Event) ->
%
page_init() ->
- case wf:user() of
- undefined ->
- ok;
- _ ->
- wf:insert_top(menu_bar_center, session_view:admin_panel()),
- wf:wire(#show{target = admin_panel})
- end.
+ User = wf:user(),
+ session_view:page_init(User).
%
% Login
@@ -144,13 +140,10 @@ login() ->
% Set session user value
wf:user(Username),
- % 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, session_view:admin_panel()),
- wf:wire(#appear{target = admin_panel, speed = "slow"});
+ % Update view
+ session_view:logged_in();
_ ->
- wf:wire(#state_panel_set{target = login_dialog, animate = true, key = fail})
+ session_view:login_failed()
end.
@@ -182,3 +175,11 @@ authenticate1(Username, Password) ->
_ ->
denied
end.
+
+%
+% Timeout
+%
+
+unauthorized_request() ->
+ session_view:unauthorized_request().
+
View
@@ -17,7 +17,11 @@
%
-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("include/utils.hrl").
@@ -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).
@@ -72,6 +72,10 @@ ul.contact {
text-align: center;
}
+.warning {
+ color: rgb(245, 100, 100);
+}
+
/*
* Basic elements
*/
@@ -227,7 +227,7 @@ Site.prototype.$dialog_show = function(dialog_id, callback) {
if (this.active_dialog)
{
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
{
@@ -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() {
this.overlay.height($(document).height());
this.overlay.width($(document).width());

0 comments on commit 4e8f327

Please sign in to comment.