Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added editing of buckets and videos in the admin section

  • Loading branch information...
commit e0b7d153e1c679cd14a577238ba6289424455343 1 parent a15a0d2
@castaway authored
View
63 lib/PresentingPerl/Web/Controller/Admin.pm
@@ -60,18 +60,79 @@ sub all_buckets :Chained('buckets') :PathPart('') :Args(0) {
## admin/buckets/<slug>
sub bucket :Chained('buckets') :PathPart('') :CaptureArgs(1) {
- my ($self, $c, $bucket) = @_;
+ my ($self, $c, $bucket_slug) = @_;
## Find bucket by slug and add bucket object to stash
+ my $bucket = $c->stash->{buckets_rs}->find({ slug => $bucket_slug });
+ if(!$bucket) {
+ $c->stash('error', "Bucket $bucket_slug doesn't exist!");
+ $c->go($self->action_for('all_buckets'));
+ }
+
+ $c->stash('bucket' => $bucket);
}
## View/Edit single bucket/Add video
sub edit_bucket :Chained('bucket') :PathPart('') :Args(0) {
+ my ($self, $c) = @_;
+
+ $c->stash->{videos_rs} = $c->stash->{bucket}->videos_rs;
+
+ if($c->req->param) {
+ my $name = $c->req->param('new_name');
+ my $title = $c->req->param('title');
+ my $author = $c->req->param('author');
+ $c->stash($c->req->params);
+
+ if(!$name && !$title && !$author) {
+ $c->stash('error', 'Please fill in the bucket name or the add video form');
+ return;
+ }
+
+ if($c->req->param('name')) {
+ $c->stash->{bucket}->update({ name => $name });
+ } else {
+
+ ## This will currently fail as we have no announcement id!
+ (my $slug = lc $name) =~ s/ /-/g;
+ $c->stash->{videos_rs}->create({
+ author => $author,
+ name => $title,
+ slug => $slug,
+ });
+ }
+ }
+
}
## admin/buckets/<slug>/<video-slug>
sub edit_video :Chained('bucket') :PathPart('') :Args(1) {
my ($self, $c, $video_slug) = @_;
+
+ my $video = $c->stash->{bucket}->videos_rs->find({ slug => $video_slug });
+ if(!$video) {
+ $c->stash('error', "Video $video_slug doesn't exist!");
+ $c->go($self->action_for('bucket'), $c->stash->{bucket}->slug);
+ }
+
+ if($c->req->param) {
+ my ($title, $author) = ($c->req->param('title'),
+ $c->req->param('author') );
+ $c->stash($c->req->params);
+
+ if(!$title || !$author) {
+ $c->stash('error', 'Please fill in both an author and a title for the video');
+ return;
+ }
+
+ $c->stash->{video}->update({
+ name => $title,
+ author => $author,
+ });
+ }
+
+ $c->stash('video' => $video);
+
}
__PACKAGE__->meta->make_immutable;
View
45 lib/PresentingPerl/Web/View/Zoom/Admin.pm
@@ -10,7 +10,9 @@ sub wrap {
my @body;
$zoom->select('#main-content')->collect_content({into => \@body})->run;
-
+
+ print STDERR Dumper(\@body);
+
my $layout_zoom = HTML::Zoom->from_file($stash->{wrapper_template});
# This does *not* modify $layout_zoom, but rather returns the modified version!
return $layout_zoom->select('#main-content')->replace_content(\@body);
@@ -42,7 +44,48 @@ sub all_buckets {
$self->wrap($zoom, $stash);
+}
+
+sub edit_bucket {
+ my ($self, $stash) = @_;
+
+ my $error = $stash->{error} || '';
+ my $zoom = $_;
+ my $bucket = $stash->{bucket};
+
+ my $videos = [ map {
+ my $obj = $_;
+ sub {
+ $_->select('.video-name')->replace_content($obj->name)
+ ->select('.video-author')->replace_content($obj->author)
+ ->select('.video-link')->set_attribute(
+ href => $obj->slug.'/'
+ )
+ }
+ } ($stash->{videos_rs}->all) ];
+
+ $zoom = $zoom->select('#video-list')
+ ->repeat_content($videos)
+ ->select('.bucket-name')->replace_content($bucket->name)
+ ->select('.error-text')->replace_content($error);
+
+ $self->wrap($zoom, $stash);
+
+}
+
+sub edit_video {
+ my ($self, $stash) = @_;
+ my $error = $stash->{error} || '';
+ my $zoom = $_;
+ my $video = $stash->{video};
+
+ $zoom = $zoom->select('.video-name')->replace_content($video->name)
+ ->select('[name=title]')->add_to_attribute('value', $video->name)
+ ->select('[name=author]')->add_to_attribute('value', $video->author)
+ ->select('.error-text')->replace_content($error);
+
+ $self->wrap($zoom, $stash);
}
1;
View
39 root/admin/edit_bucket
@@ -0,0 +1,39 @@
+ <div id="main-content">
+
+ <div id="custom-html">
+ <h1>
+ Editing bucket <span class="bucket-name">THIS IZ MAI BUKKIT</span>
+ </h1>
+<!--
+ <form enctype="multipart/form-data" class="edit-bucket-form" action="" method="POST">
+-->
+ <form class="edit-bucket-form" action="" method="POST">
+ <label for="new_name">Enter a new name for this bucket</label> <input type="text" name="new_name"/>
+ <br /><br />
+<!--
+ <label for="new_file">Upload new file to bucket</label> <input type="file" name="new_file" accept="*.flv,*.m4v"/>
+ <br /><br />
+-->
+ <input type="submit" value="Modify"/>
+ </form>
+
+ <h2>Add new video</h2>
+ <form class="add-video-form" action="" method="POST">
+ <label for="title">Video Title: </label> <input type="text" name="title" id="title"/>
+ <br /><br />
+ <label for="author">Video author: </label> <input type="text" name="author" id="author"/>
+ <br /><br />
+ <input type="submit" value="Add Video"/>
+ </form>
+
+ <span class="error-text">Some error</span>
+ </div>
+ <ul id="video-list">
+ <li class="video">
+ <a class="video-link"><span class="video-name">Really Imaginative Video Name</span> (<span class="video-author">Some Guy</span>)</a>
+ </li>
+ </ul>
+
+<!-- END MAIN CONTENT -->
+ </div>
+
View
26 root/admin/edit_video
@@ -0,0 +1,26 @@
+ <div id="main-content">
+
+ <div id="custom-html">
+ <h1>
+ Editing video: <span class="video-name">THIS IZ MAI VIDEO</span>
+ </h1>
+<!--
+ <form enctype="multipart/form-data" class="edit-bucket-form" action="" method="POST">
+-->
+
+ <form class="edit-video-form" action="" method="POST">
+ <label for="title">Title: </label> <input type="text" name="title"/>
+ <br /><br />
+ <label for="author">Author: </label> <input type="text" name="author"/>
+ <br /><br />
+<!--
+ <label for="new_file">Upload new file to bucket</label> <input type="file" name="new_file" accept="*.flv,*.m4v"/>
+ <br /><br />
+-->
+ <input type="submit" value="Modify"/>
+ </form>
+ <span class="error-text">Some error</span>
+ </div>
+
+<!-- END MAIN CONTENT -->
+ </div>
Please sign in to comment.
Something went wrong with that request. Please try again.