Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 30de4cb054d74793ff6c87e66e77c48f266f0b6f 1 parent 10858dd
Dave Cross authored February 08, 2014
20  lib/Lystyng.pm
@@ -44,6 +44,24 @@ get '/user/:username' => sub {
44 44
   }
45 45
 };
46 46
 
  47
+get '/user/:username/list/add' => sub {
  48
+  redirect '/login' unless session->{user};
  49
+
  50
+  template 'addlist';
  51
+};
  52
+
  53
+post '/user/:username/list/add' => sub {
  54
+  redirect '/login' unless session->{user};
  55
+
  56
+  session->{user}->add_to_lists({
  57
+    title       => params->{list_title},
  58
+    slug        => params->{list_slug},
  59
+    description => params->{list_description},
  60
+  });
  61
+
  62
+  redirect '/user/' . session->{user}->username;
  63
+};
  64
+
47 65
 get '/user/:username/list/:list' => sub {
48 66
   my $user;
49 67
   unless ($user = resultset('User')->find({
@@ -105,7 +123,7 @@ post '/login' => sub {
105 123
   my ($user) = $user_rs->find({ username => param('username') });
106 124
   if ($user && $user->check_password(param('password'))) {
107 125
     session user => $user;
108  
-    redirect '/';
  126
+    redirect '/user/' . $user->username;
109 127
   } else {
110 128
     template 'login', {
111 129
       error    => 1,
30  views/addlist.tt
... ...
@@ -0,0 +1,30 @@
  1
+[% fields = [ {
  2
+  name  => 'list_title',
  3
+  label => 'List Title',
  4
+  placeholder => 'title',
  5
+}, {
  6
+  name  => 'list_slug',
  7
+  label => 'Slug',
  8
+  placeholder => 'slug',
  9
+}, {
  10
+  name  => 'list_description',
  11
+  label => 'Description',
  12
+  placeholder => 'description',
  13
+} ] -%]
  14
+
  15
+<h2>Add List</h2>
  16
+  <form role="form" class="form-horizontal" method="post" action="/user/[% session.user.username %]/list/add">
  17
+[% FOREACH field IN fields -%]
  18
+    <div class="form-group">
  19
+      <label class="col-md-2 control-label" for="[% field.name %]">[% field.label %]</label>
  20
+      <div class="col-md-6">
  21
+        <input type="text" class="form-control" id="[% field.name %]" name="[% field.name %]" value="[% params.${field.name} %]" placeholder="[% field.placeholder %]">
  22
+      </div>
  23
+    </div>
  24
+[% END -%]
  25
+    <div class="form-group">
  26
+      <div class="col-md-offset-2 col-md-4">
  27
+        <button type="submit" class="btn btn-primary btn-block">Add</button>
  28
+      </div>
  29
+    </div>
  30
+  </form>
2  views/list.tt
... ...
@@ -1,5 +1,5 @@
1 1
 <h2>[% list.title %]</h2>
2  
-<p>By <a href="">[% list.user.username %]</a></p>
  2
+<p>By <a href="/user/[% list.user.username %]">[% list.user.username %]</a></p>
3 3
 <p>[% list.description %]</p>
4 4
 [% IF list.list_items.size -%]
5 5
 <ul>
7  views/user.tt
@@ -7,4 +7,9 @@
7 7
 [%   END -%]
8 8
 [% ELSE -%]
9 9
 <p>User has no lists</p>
10  
-[% END -%]
  10
+[% END -%]
  11
+[% IF session.user AND session.user.username == user.username -%]
  12
+<a href="/user/[% user.username %]/list/add"><button type="button" class="btn btn-default btn-lg">
  13
+  <span class="glyphicon glyphicon-plus"></span> Add List
  14
+</button></a>
  15
+[% END -%]

0 notes on commit 30de4cb

Please sign in to comment.
Something went wrong with that request. Please try again.