diff options
author | Yorhel <git@yorhel.nl> | 2008-11-22 17:01:07 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2008-11-22 17:01:07 +0100 |
commit | f4e62131b577b740147d58d1d16a490ac2fc57aa (patch) | |
tree | 54d744562c0ad89fd802b56a0a265d3df0922ca0 /lib | |
parent | 0dd7477ce4334d04971e0fb1f29a34a1d097c7c9 (diff) |
Added category editor
Copied a lot from 1.x, doesn't look very nice, either...
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VNDB/Handler/VNEdit.pm | 24 | ||||
-rw-r--r-- | lib/VNDB/Util/FormHTML.pm | 38 | ||||
-rw-r--r-- | lib/VNDB/Util/LayoutHTML.pm | 3 |
3 files changed, 49 insertions, 16 deletions
diff --git a/lib/VNDB/Handler/VNEdit.pm b/lib/VNDB/Handler/VNEdit.pm index cc4f2107..1e5fd050 100644 --- a/lib/VNDB/Handler/VNEdit.pm +++ b/lib/VNDB/Handler/VNEdit.pm @@ -25,6 +25,7 @@ sub edit { my %b4 = !$vid ? () : ( (map { $_ => $v->{$_} } qw|title original desc alias length l_wp l_encubed l_renai l_vnn |), anime => join(' ', sort { $a <=> $b } map $_->{id}, @{$v->{anime}}), + categories => join(',', map $_->[0].$_->[1], sort { $a->[0] cmp $b->[0] } @{$v->{categories}}), ); my $frm; @@ -40,12 +41,15 @@ sub edit { { name => 'l_renai', required => 0, default => '', maxlength => 100 }, { name => 'l_vnn', required => 0, default => 0, template => 'int' }, { name => 'anime', required => 0, default => '' }, + { name => 'categories',required => 0, default => '', maxlength => 1000 }, { name => 'editsum', maxlength => 5000 }, ); if(!$frm->{_err}) { # parse and re-sort fields that have multiple representations of the same information my $anime = [ grep /^[0-9]+$/, split /[ ,]+/, $frm->{anime} ]; + my $categories = [ map { [ substr($_,0,3), substr($_,3,1) ] } split /,/, $frm->{categories} ]; + $frm->{anime} = join ' ', sort { $a <=> $b } @$anime; # nothing changed? just redirect @@ -55,16 +59,16 @@ sub edit { my %args = ( (map { $_ => $frm->{$_} } qw|title original alias desc length l_wp l_encubed l_renai l_vnn editsum|), anime => $anime, + categories => $categories, # copy these from $v, as we don't have a form interface for them yet - categories => $v->{categories}||[], image => $v->{image}||0, img_nsfw => $v->{img_nsfw}, screenshots => [ map [ $_->{id}, $_->{nsfw}, $_->{rid} ], @{$v->{screenshots}} ], relations => [ map [ $_->{relation}, $_->{id} ], @{$v->{relations}} ], ); - my $rev = 1; + $rev = 1; ($rev) = $self->dbVNEdit($vid, %args) if $vid; ($vid) = $self->dbVNAdd(%args) if !$vid; @@ -78,7 +82,7 @@ sub edit { !exists $frm->{$_} && ($frm->{$_} = $b4{$_}) for (keys %b4); $frm->{editsum} = sprintf 'Reverted to revision v%d.%d', $vid, $rev if $rev && !defined $frm->{editsum}; - $self->htmlHeader(title => $vid ? "Edit $v->{title}" : 'Add a new visual novel'); + $self->htmlHeader(js => 'forms', title => $vid ? "Edit $v->{title}" : 'Add a new visual novel'); $self->htmlMainTabs('v', $v, 'edit') if $vid; $self->htmlEditMessage('v', $v); _form($self, $v, $frm); @@ -122,6 +126,20 @@ sub _form { ], 'Categories' => [ + [ hidden => short => 'categories' ], + [ static => nolabel => 1, content => eval { + my $r = 'Please read the <a href="/d1">category descriptions</a> before modifying categories!<br /><br />' + .'<ul>'; + for my $c (qw| e g t p h l s |) { + $r .= ($c !~ /[thl]/ ? '<li>' : '<br />').$self->{categories}{$c}[0].'<a href="/d1#'.$self->{categories}{$c}[2].'" class="help">?</a><ul>'; + for (sort keys %{$self->{categories}{$c}[1]}) { + $r .= sprintf '<li><a href="#" id="cat_%1$s"><b id="b_%1$s">-</b> %2$s</a></li>', + $c.$_, $self->{categories}{$c}[1]{$_}; + } + $r .= '</ul>'.($c !~ /[gph]/ ? '</li>' : ''); + } + $r.'</ul>'; + }], ], 'Image' => [ diff --git a/lib/VNDB/Util/FormHTML.pm b/lib/VNDB/Util/FormHTML.pm index 4ab8aa9b..b808983f 100644 --- a/lib/VNDB/Util/FormHTML.pm +++ b/lib/VNDB/Util/FormHTML.pm @@ -89,11 +89,12 @@ sub htmlFormError { # A form part is a arrayref, with the first element being the type of the part, # and all other elements forming a hash with options specific to that type. # Type Options -# input short, name, width, pre, post +# hidden short, (value) +# input short, name, (width, pre, post) # passwd short, name -# static content, label +# static content, (label, nolabel) # check name, short, (value) -# select name, short, options, width +# select name, short, options, (width) # text name, short, (rows, cols) # part title # TODO: Find a way to write this function in a readable way... @@ -102,6 +103,15 @@ sub htmlFormPart { my($type, %o) = @$fp; local $_ = $type; + if(/hidden/) { + Tr class => 'hidden'; + td colspan => 2; + input type => 'hidden', id => $o{short}, name => $o{short}, value => $o{value}||$frm->{$o{short}}; + end; + end; + return + } + if(/part/) { Tr class => 'newpart'; td colspan => 2, $o{title}; @@ -126,16 +136,18 @@ sub htmlFormPart { } Tr $o{name}||$o{label} ? (class => 'newfield') : (); - td class => 'label'; - if($o{short} && $o{name}) { - label for => $o{short}, $o{name} ; - } elsif($o{label}) { - txt $o{label}; - } else { - lit ' '; - } - end; - td class => 'field'; + if(!$o{nolabel}) { + td class => 'label'; + if($o{short} && $o{name}) { + label for => $o{short}, $o{name} ; + } elsif($o{label}) { + txt $o{label}; + } else { + lit ' '; + } + end; + } + td class => 'field', $o{nolabel} ? (colspan => 2) : (); if(/input/) { lit $o{pre} if $o{pre}; input type => 'text', class => 'text', name => $o{short}, id => $o{short}, diff --git a/lib/VNDB/Util/LayoutHTML.pm b/lib/VNDB/Util/LayoutHTML.pm index 8c4ba7ef..6f873ba8 100644 --- a/lib/VNDB/Util/LayoutHTML.pm +++ b/lib/VNDB/Util/LayoutHTML.pm @@ -18,6 +18,9 @@ sub htmlHeader { # %options->{ title } title $o{title}; Link rel => 'shortcut icon', href => '/favicon.ico', type => 'image/x-icon'; Link rel => 'stylesheet', href => $self->{url_static}.'/f/style.css', type => 'text/css', media => 'all'; + if($o{js}) { + script type => 'text/javascript', src => $self->{url_static}.'/f/forms.js'; end; + } script type => 'text/javascript', src => $self->{url_static}.'/f/script.js'; # most browsers don't like a self-closing <script> tag... end; |