diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2017-09-24 00:35:31 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2017-09-24 00:35:31 +0200 |
commit | 9f7af8715eab9d0be30f94158feb0bc20314a84b (patch) | |
tree | 0ba843ec601c1cebf6d9d494f6b74af6fe1f329b | |
parent | 1720ee3f71e761b188e9a6116da5115bab86313e (diff) | |
download | sourceyard-9f7af8715eab9d0be30f94158feb0bc20314a84b.tar.gz sourceyard-9f7af8715eab9d0be30f94158feb0bc20314a84b.tar.bz2 |
Further experiments on user/admin page
* lib/Sourceyard.pm: New helpers: opt_input, opt_button,
and theme_list. Handle post requests to user/
(_alt_tag): Add alt prefix only to the first of classes.
* templates/opt/button.false.html.ep: New file.
* templates/opt/button.true.html.ep: New file.
* templates/user/admin.html.ep: Implement "Secondary Arrangements"
-rw-r--r-- | lib/Sourceyard.pm | 66 | ||||
-rw-r--r-- | lib/Sourceyard/Controller/User.pm | 5 | ||||
-rw-r--r-- | templates/opt/button.false.html.ep | 3 | ||||
-rw-r--r-- | templates/opt/button.true.html.ep | 6 | ||||
-rw-r--r-- | templates/user/admin.html.ep | 88 |
5 files changed, 138 insertions, 30 deletions
diff --git a/lib/Sourceyard.pm b/lib/Sourceyard.pm index 1ae9405..73045eb 100644 --- a/lib/Sourceyard.pm +++ b/lib/Sourceyard.pm @@ -25,7 +25,10 @@ sub startup { $self->helper(top_menu_item => \&_top_menu_item); $self->helper(alt_tag => \&_alt_tag); - + $self->helper(opt_input => \&_opt_input); + $self->helper(opt_buttons => \&_opt_buttons); + $self->helper(theme_list => \&_theme_list); + # FIXME: Move to a plugin? $self->plugin('RemoteAddr'); $self->hook(before_dispatch => sub { @@ -59,6 +62,7 @@ sub startup { return 1; }); $auth->get(':action')->to(controller => 'user'); + $auth->post(':action')->to(controller => 'user'); } sub _top_menu_item { @@ -88,12 +92,70 @@ sub _alt_tag { if (@_ % 2 == 0) { local %_ = @_; my $n = delete $_{init} || $c->stash('sourceyard.alt'); + if ($n) { + my @classes = split(/\s+/, $_{class}); + $_{class} = join(' ', shift(@classes).'alt', @classes); + } $c->stash('sourceyard.alt' => !$n); - $_{class} .= 'alt' if $n; @_ = %_; } push @_, $last if defined($last); return $c->tag($tag, @_); } +# opt_input PARAM, NAME => VALUE, ATTR.... +sub _opt_input { + my ($c, $param, $name) = (shift, shift, shift); + + if ($c->param("change_$param")) { + return $c->text_field($name, @_); + } else { + my @args; + if (@_ % 2) { + push @args, shift; + } + %_ = @_; + delete $_{tabindex}; + push @args, %_; + return $c->tag('strong', @args); + } +} + +# opt_buttons SUFFIX +sub _opt_buttons { + my ($c, $suffix) = @_; + my $str; + + my $srx = qr($suffix); + my $disabled = (grep { /^change_(?!$srx)/ } @{$c->req->params->names}) + ? 'disabled' : ''; + return Mojo::ByteStream->new( + $c->render_to_string( + 'opt/'. + ($c->param("change_$suffix") ? 'button.true' : 'button.false'), + suffix => $suffix, + disabled => $disabled + )); +} + +sub _theme_list { + my ($c, $cur) = @_; + my $pubdir = ${$c->app->static->paths}[0]; + my $pfx = qr{$pubdir/css/}; + my @ret = sort + map { + (m{^$pfx(.*)\.css$} && -d "$pubdir/images/$1.theme") ? $1 : () + } glob "$pubdir/css/*.css"; + if ($cur) { + return map { + my @elt = ( $_ => $_ ); + push @elt, selected => 'selected' if ($_ eq $cur); + \@elt } @ret; + } + return @ret; +} + 1; + + + diff --git a/lib/Sourceyard/Controller/User.pm b/lib/Sourceyard/Controller/User.pm index 418fd5a..98d8f75 100644 --- a/lib/Sourceyard/Controller/User.pm +++ b/lib/Sourceyard/Controller/User.pm @@ -4,7 +4,10 @@ use Sourceyard::User; sub admin { my $self = shift; - print "ADMIN\n"; + if ($self->req->method eq 'POST') { + use Data::Dumper; + print Dumper([$self->req->params]); + } $self->render; } diff --git a/templates/opt/button.false.html.ep b/templates/opt/button.false.html.ep new file mode 100644 index 0000000..ed0b2f4 --- /dev/null +++ b/templates/opt/button.false.html.ep @@ -0,0 +1,3 @@ +<button class="btn" name="change_<%= $suffix %>" value="1" <%= $disabled %>> + Change +</button> diff --git a/templates/opt/button.true.html.ep b/templates/opt/button.true.html.ep new file mode 100644 index 0000000..627de72 --- /dev/null +++ b/templates/opt/button.true.html.ep @@ -0,0 +1,6 @@ +<button class="update" name="update_<%= $suffix %>" value="1"> + Update +</button> +<button class="cancel" name="cancel_<%= $suffix %>" value="1"> + Cancel +</button> diff --git a/templates/user/admin.html.ep b/templates/user/admin.html.ep index 3b8e226..855fdf9 100644 --- a/templates/user/admin.html.ep +++ b/templates/user/admin.html.ep @@ -42,51 +42,52 @@ <div class="box"> <div class="boxtitle">Identity Record</div> %= alt_tag div => (class => 'boxitem', init => 0) => begin - Account #<%= $user->user_id %> - <p class="smaller"> - Your login is <strong><%= $user->user_name %></strong>. - You registered your account on + Account #<strong><%= $user->user_id %></strong> +% end +%= alt_tag div => (class => 'boxitem', init => 0) => begin + Login name <strong><%= $user->user_name %></strong> +% end +%= alt_tag div => (class => 'boxitem', init => 0) => begin + Registered on % $user->add_date->set_time_zone('local'); <strong><%= $user->add_date->strftime('%a %d %b %Y %I:%M:%S %p %z') %></strong>. - </p> % end + %= alt_tag div => (class => 'boxitem') => begin - <a href="change.php?item=realname">Change Real Name</a> - <p class="smaller"> - You are <strong><%= $user->real_name %></strong>. - </p> + %= label_for realname => begin + Real Name + % end + %= opt_input 'signif', 'realname' => $user->real_name % end + %= alt_tag div => (class => 'boxitem') => begin - <a href="resume.php">Edit Resume and Skills</a> + <a href="resume">Edit Resume and Skills</a> <p class="smaller"> Details about your experience and skills will be available to logged in users in the hope they will be of interest. </p> % end %= alt_tag div => (class => 'boxitem') => begin - <a href="/users/gray">View your Public Profile</a> + <a href="/users/<%= $user->user_name %>">View your Public Profile</a> <p class="smaller"> Your profile can be viewed by everybody. </p> % end - + <div class="center"> + %= opt_buttons 'signif' + </div> </div><!-- end box --> <br /> <div class="box"> <div class="boxtitle">Mail Setup</div> -%= alt_tag div => (class => 'boxitem') => begin - <a href="change.php?item=email"> - Change Email Address - </a> - <p class="smaller"> - Your current address is - <strong><%= $user->email %></strong>. - It is essential to us that this address remains valid. Keep - it up to date. - </p> +%= alt_tag div => (class => 'boxitem') => begin + %= label_for email => begin + Email Address + % end + %= opt_input 'mail', 'email' => $user->email % end %= alt_tag div => (class => 'boxitem') => begin - <a href="change_notifications.php"> + <a href="change_notifications"> Edit Personal Notification Settings </a> <p class="smaller"> @@ -96,19 +97,52 @@ </p> % end %= alt_tag div => (class => 'boxitem') => begin - <a href="cc.php"> + <a href="cc"> Cancel Mail Notifications </a> <p class="smaller"> Here, you can cancel all mail notifications. </p> % end + <div class="center"> + %= opt_buttons 'mail' + </div> </div><!-- end box --> <br /> </div><!-- end splitleft --> - <div class="center"> - %= submit_button 'Update', (class => 'btn', tabindex => 1) - </div> + <h3>Secondary Arrangements</h3> + <div class="splitright"> + </div><!-- end splitright --> + <div class="splitleft"> + <div class="box"> + <div class="boxtitle">Preferences</div> +%= alt_tag div => (class => 'boxitem') => begin + %= label_for timezone => 'Time zone' +% if (param('change_2')) { +<% use DateTime::TimeZone; + my @zones = map { my @elt = ( $_ => $_ ); + push @elt, selected => 'selected' + if ($_ eq $user->timezone); + \@elt } DateTime::TimeZone->all_names; +%> + %= select_field timezone => [ @zones ] +% } else { + <strong><%= $user->timezone %></strong> +% } +% end +%= alt_tag div => (class => 'boxitem') => begin + %= label_for theme => 'Theme' +% if (param('change_2')) { + %= select_field theme => [ $self->theme_list($user->theme) ] +% } else { + <strong><%= $user->theme %></strong> +% } +% end + <div class="center"> + %= opt_buttons '2' + </div> + </div> <!-- box --> + </div> <!-- splitleft --> % end |