Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added facility to add a list (but no list items)

  • Loading branch information...
commit 30de4cb054d74793ff6c87e66e77c48f266f0b6f 1 parent 10858dd
Dave Cross authored
20 lib/Lystyng.pm
View
@@ -44,6 +44,24 @@ get '/user/:username' => sub {
}
};
+get '/user/:username/list/add' => sub {
+ redirect '/login' unless session->{user};
+
+ template 'addlist';
+};
+
+post '/user/:username/list/add' => sub {
+ redirect '/login' unless session->{user};
+
+ session->{user}->add_to_lists({
+ title => params->{list_title},
+ slug => params->{list_slug},
+ description => params->{list_description},
+ });
+
+ redirect '/user/' . session->{user}->username;
+};
+
get '/user/:username/list/:list' => sub {
my $user;
unless ($user = resultset('User')->find({
@@ -105,7 +123,7 @@ post '/login' => sub {
my ($user) = $user_rs->find({ username => param('username') });
if ($user && $user->check_password(param('password'))) {
session user => $user;
- redirect '/';
+ redirect '/user/' . $user->username;
} else {
template 'login', {
error => 1,
30 views/addlist.tt
View
@@ -0,0 +1,30 @@
+[% fields = [ {
+ name => 'list_title',
+ label => 'List Title',
+ placeholder => 'title',
+}, {
+ name => 'list_slug',
+ label => 'Slug',
+ placeholder => 'slug',
+}, {
+ name => 'list_description',
+ label => 'Description',
+ placeholder => 'description',
+} ] -%]
+
+<h2>Add List</h2>
+ <form role="form" class="form-horizontal" method="post" action="/user/[% session.user.username %]/list/add">
+[% FOREACH field IN fields -%]
+ <div class="form-group">
+ <label class="col-md-2 control-label" for="[% field.name %]">[% field.label %]</label>
+ <div class="col-md-6">
+ <input type="text" class="form-control" id="[% field.name %]" name="[% field.name %]" value="[% params.${field.name} %]" placeholder="[% field.placeholder %]">
+ </div>
+ </div>
+[% END -%]
+ <div class="form-group">
+ <div class="col-md-offset-2 col-md-4">
+ <button type="submit" class="btn btn-primary btn-block">Add</button>
+ </div>
+ </div>
+ </form>
2  views/list.tt
View
@@ -1,5 +1,5 @@
<h2>[% list.title %]</h2>
-<p>By <a href="">[% list.user.username %]</a></p>
+<p>By <a href="/user/[% list.user.username %]">[% list.user.username %]</a></p>
<p>[% list.description %]</p>
[% IF list.list_items.size -%]
<ul>
7 views/user.tt
View
@@ -7,4 +7,9 @@
[% END -%]
[% ELSE -%]
<p>User has no lists</p>
-[% END -%]
+[% END -%]
+[% IF session.user AND session.user.username == user.username -%]
+<a href="/user/[% user.username %]/list/add"><button type="button" class="btn btn-default btn-lg">
+ <span class="glyphicon glyphicon-plus"></span> Add List
+</button></a>
+[% END -%]
Please sign in to comment.
Something went wrong with that request. Please try again.