allow editing image tags on the big image tool page
authorTony Cook <tony@develop-help.com>
Fri, 8 May 2015 09:03:32 +0000 (19:03 +1000)
committerTony Cook <tony@develop-help.com>
Mon, 18 May 2015 09:08:24 +0000 (19:08 +1000)
site/cgi-bin/modules/BSE/Edit/Article.pm
site/htdocs/css/admin.css
site/templates/admin/article_img.tmpl
site/templates/preload.tmpl

index a9db59ed28e701b0e69b8f51f67948dddf2e04be..63d60fd46569e73daeb7898381fdc308dce7c73d 100644 (file)
@@ -16,7 +16,7 @@ use List::Util qw(first);
 use constant MAX_FILE_DISPLAYNAME_LENGTH => 255;
 use constant ARTICLE_CUSTOM_FIELDS_CFG => "article custom fields";
 
-our $VERSION = "1.056";
+our $VERSION = "1.057";
 
 =head1 NAME
 
@@ -3179,6 +3179,24 @@ sub save_image_changes {
        if length $image->{name};
     }
 
+    if ($cgi->param("_save_image_tags$image->{id}")) {
+      my @tags = $cgi->param("tags$image->{id}");
+      my @errors;
+      my $index = 0;
+      for my $tag (@tags) {
+       my $error;
+       if ($tag =~ /\S/
+           && !BSE::TB::Tags->valid_name($tag, \$error)) {
+         $errors[$index] = "msg:bse/admin/edit/tags/invalid/$error";
+         $errors{"tags$image->{id}"} = \@errors;
+       }
+       ++$index;
+      }
+      unless (@errors) {
+       $changes{$id}{tags} = [ grep /\S/, @tags ];
+      }
+    }
+
     my $filename = $cgi->param("image$id");
     if (defined $filename && length $filename) {
       my $in_fh = $cgi->upload("image$id");
@@ -3260,8 +3278,13 @@ sub save_image_changes {
     if ($changes{$id}) {
       my $changes = $changes{$id};
       ++$changes_found;
-      
+
       for my $field (keys %$changes) {
+       my $tags = delete $changes->{$field};
+       if ($tags) {
+         my $error;
+         $image->set_tags($tags, \$error);
+       }
        $image->{$field} = $changes->{$field};
       }
       $image->save;
index c47187e7f94f24f548459b99ac7b4ea1a6c38585..653a83a0ddadae60460820cd17766423cc753837 100644 (file)
@@ -140,6 +140,10 @@ table td {
   background-color: #FFF;
 }
 
+table td.col_tags {
+  vertical-align: top;
+}
+
 table tr.bad td {
   background-color: #FF8080;
 }
index b5e547bffc909267183a5c14e2238fcbe469d602..d525bafd1388ea7c48cda5ee6815af5ef3dfb822 100644 (file)
 <:.if images.size:><:.if article.id != -1
   and cfg.entry("basic", "auto_images", 1)-:>
 <tr> 
-            <th colspan="5">First Image Position</th>
+            <th colspan="6">First Image Position</th>
           </tr>
                  <tr> 
-            <td colspan="5"> 
+            <td colspan="6"> 
 <input type="radio" name="imagePos" value="tl" <:= article.imagePos eq "tl" ? "checked " : "":>/>Top Left &nbsp;
 <input type="radio" name="imagePos" value="tr" <:= article.imagePos eq "tr" ? "checked " : "":>/>Top Right &nbsp;
 <input type="radio" name="imagePos" value="bl" <:= article.imagePos eq "bl" ? "checked " : "":>/>Bottom Left &nbsp;
           <tr> 
             <th>Image</th>
             <th colspan="2"> &nbsp;</th>
+           <th class="col_tags">Tags</th>
             <th class="col_modify"> Modify</th>
            <th class="col_move"> Move</th>
           </tr>
             <td class="col_field"> 
               <:.if can_save:><input type="text" name="alt<:= image.id:>" value="<:.call "old", field:"alt" _ image.id, default: image.alt :>" size="32" /><:.else:><:= image.alt :><:.end if:>
             </td>
+           <td class="col_tags" rowspan="5">
+           <input type="hidden" name="_save_image_tags<:= image.id:>" value="1">
+           <div class="tags" data-name="tags<:= image.id :>">
+             <:.if cgi.param("_save_image_tags" _ image.id) -:>
+               <:.set image_tags = [ cgi.param("tags" _ image.id) ] -:>
+             <:.else -:>
+               <:.set image_tags = [ image.tags ] -:>
+               <:% image_tags.push("") -:>
+             <:.end if -:>
+             <:.for tag in image_tags :>
+             <div class="tag"><input type="text" name="tags<:= image.id :>" value="<:= tag :>"><:.call "error_img_n", field:"tags" _ image.id, index: loop.index :></div>
+             <:.end for :>
+           </div>
+           </td>
             <td class="col_modify" rowspan="5"> 
 <:.if can_delete -:>
   <b><a href="<:= cfg.admin_url("add", { id:article.id, "removeimg_" _ image.id:1, _t:"img", _csrfp: delete_token}):>" onClick="return window.confirm('Are you sure you want to delete this Image')">Delete</a></b>
 <:.end if:>
 <:.if can_save:>
           <tr> 
-            <td colspan="5" class="buttons"> 
+            <td colspan="6" class="buttons"> 
               <input type="submit" name="process" value="Save changes" />
             </td>
          </tr>
index 6fb9882b561bcf4c0596f573c3e95c62f5becdad..925d8d7e829c01ff5b68f64f693f39e1b99e6816 100644 (file)
@@ -106,10 +106,11 @@ Page <:= pages.page :> of <:= pages.pagecount :>
 </div>
 <:-.end define -:>
 
-<:.define old -:>
-<:# parameters: field, default -:>
-<:  .if cgi.param(field).defined -:>
-<:= cgi.param(field) -:>
+<:.define old; default: "", index: 0 -:>
+<:# parameters: field, default, index  -:>
+<:  .set vals = [ cgi.param(field) ] -:>
+<:  .if index < vals.size -:>
+<:= vals[index] -:>
 <:  .else -:>
 <:= default | html -:>
 <:  .end if -:>