modify the image editor page to use new style markup
authorTony Cook <tony@develop-help.com>
Fri, 8 May 2015 08:43:09 +0000 (18:43 +1000)
committerTony Cook <tony@develop-help.com>
Mon, 18 May 2015 09:08:23 +0000 (19:08 +1000)
site/cgi-bin/modules/BSE/Edit/Article.pm
site/templates/admin/article_img.tmpl

index 813876d487746cdb873968183755b59485a8523e..a9db59ed28e701b0e69b8f51f67948dddf2e04be 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.055";
+our $VERSION = "1.056";
 
 =head1 NAME
 
@@ -73,7 +73,8 @@ sub article_dispatch {
   my $action;
   my %actions = $self->article_actions;
   for my $check (keys %actions) {
-    if ($cgi->param($check) || $cgi->param("$check.x")) {
+    if ($cgi->param($check) || $cgi->param("$check.x")
+       || $cgi->param("a_$check") || $cgi->param("a_$check.x")) {
       $action = $check;
       last;
     }
@@ -1241,6 +1242,49 @@ sub _custom_fields {
   return \%active;
 }
 
+=back
+
+=head1 Common Edit Page Tags
+
+Variables:
+
+=over
+
+=item *
+
+C<article> - the article being edited.  This is a dummy article when a
+new article is being created.
+
+=item *
+
+C<isnew> - true if a new article is being created.
+
+=item *
+
+C<custom> - describes custom tags.
+
+=item *
+
+C<errors> - errors from the last submission of the page.
+
+=item *
+
+C<image_stores> - a function returning an array of possible image
+storages.
+
+=item *
+
+C<thumbs> - for the image list, whether thumbs should be displayed
+instead of full size images.
+
+=item *
+
+C<can_thumbs> - true if thumbnails are available.
+
+=back
+
+=cut
+
 sub low_edit_tags {
   my ($self, $acts, $request, $article, $articles, $msg, $errors) = @_;
 
@@ -1295,6 +1339,12 @@ sub low_edit_tags {
   $request->set_variable(errors => $errors || {});
   my $article_type = $cfg->entry('level names', $article->{level}, 'Article');
   $request->set_variable(article_type => $article_type);
+  $request->set_variable(thumbs => defined $thumbs_obj);
+  $request->set_variable(can_thumbs => defined $thumbs_obj_real);
+  $request->set_variable(image_stores =>
+                        sub {
+                          $self->iter_image_stores;
+                        });
 
   return
     (
@@ -2084,6 +2134,8 @@ sub save_new_more {
   # nothing to do here
 }
 
+=over
+
 =item save
 
 Error codes:
index e17b97bb9b341eb301e321c0eb309f14df6ebf2d..2b38bf65cc344a11b2f555b886cd28888bdda2bf 100644 (file)
@@ -1,29 +1,56 @@
-<:wrap admin/base.tmpl title=>"Image Wizard", js => "admin_edit.js" :>
-<h1><:ifEq [article id] "-1":>Global<:or:><: articleType :><:eif:> Image Wizard</h1>
-<:ifMessage:> 
-<p><b><:message:> </b></p>
-<:or:><:eif:>
-<p>| <a href="/cgi-bin/admin/menu.pl">Admin menu</a> | 
-<:switch:>
-<:case Match [article generator] "Product":><a href="/cgi-bin/admin/add.pl?id=<:article id:>">Edit
-    product</a> | <a href="/cgi-bin/admin/shopadmin.pl">Manage catalogs</a>
-<:case Eq [article id] [cfg articles shop]:><a href="/cgi-bin/admin/add.pl?id=<:article id:>">Edit shop</a>
-<:case Eq [article id] "-1":><a href="/cgi-bin/admin/add.pl?id=<:article id:>">Edit sections</a>
-<:case default:><a href="/cgi-bin/admin/add.pl?id=<:article id:>"><:ifMatch
-    [article generator] "Catalog":>Edit catalog<:or:>Edit article<:eif:></a>
-<:endswitch:>
-|
-<:if Thumbs:><a href="<:script:>?id=<:article id:>&amp;_t=img&amp;f_showfull=1">Full size images</a> |<:or Thumbs:><:ifCanThumbs:><a href="<:script:>?id=<:article id:>&amp;_t=img">With Thumbnails</a> |<:or:><:eif:><:eif Thumbs:>
+<:.set article_type = cfg.entry("level names", article.level, "Article") -:>
+<:.define image_move:>
+<:-.if images.size > 1 -:>
+<:.set up_url = loop.is_first ? ""
+  : cfg.admin_url2("add", "moveimgup", 
+                   { id: article.id,
+                     imageid: image.id,
+                    _t: "img",
+                    _csrfp: request.get_csrf_token("admin_move_image")
+                  }) -:>
+<:.set down_url = loop.is_last ? ""
+  : cfg.admin_url2("add", "moveimgdown", 
+                   { id: article.id,
+                     imageid: image.id,
+                    _t: "img",
+                    _csrfp: request.get_csrf_token("admin_move_image")
+                  }) -:>
+<:.call "make_arrows", down_url:down_url, up_url: up_url -:>
+<:-.end if -:>
+<:.end define:>
+<:.wrap "admin/base.tmpl", title:"Image Wizard", js:"admin_edit.js" :>
+<h1><:.if article.id == -1:>Global<:.else:><:= article_type :><:.end if:> Image Wizard</h1>
+
+<:.call "messages":>
+
+<p>| <a href="<:= cfg.admin_url("menu") :>">Admin menu</a> | 
+<:.if article.generator =~ /Product/ :>
+  <a href="<:= cfg.admin_url("add", { id: article.id }) :>">Edit product</a> |
+  <a href="<:= cfg.admin_url("shopadmin") :>">Manage catalogs</a> |
+<:.elsif article.id == cfg.entry("articles", "shop", 3) -:>
+  <a href="/cgi-bin/admin/add.pl?id=<:article id:>">Edit shop</a> |
+<:.elsif article.id == -1 -:>
+  <a href="/cgi-bin/admin/add.pl?id=<:article id:>">Edit sections</a> |
+<:.else -:>
+<a href="/cgi-bin/admin/add.pl?id=<:article id:>"><:.if article.generator =~ /Catalog/:>Edit catalog<:.else:>Edit article<:.end if:></a> |
+<:.end if :>
+
+<:.if thumbs -:>
+  <a href="<:= cfg.admin_url("add", {id:article.id, "_t": "img", f_showfull:1}) :>">Full size images</a> |
+<:.else -:>
+  <:.if can_thumbs -:>
+  <a href="<:= cfg.admin_url("add", {id:article.id, _t: "img"}):>">With Thumbnails</a> |
+  <:.end if :>
+<:.end if:>
 </p>
-<:if UserCan edit_images_add:article:>
+<:.if request.user_can("edit_images_add", article) -:>
 <h2>Add new image</h2>
 
 <form method="post" action="<:script:>" enctype="multipart/form-data" name="add">
 
-<input type="hidden" name="level" value="<: level :>" />
-<input type="hidden" name="id" value="<: article id :>" />
-<input type="hidden" name="parentid" value="<: article parentid :>" />
-<input type="hidden" name="imgtype" value="<: articleType :>" />
+<input type="hidden" name="level" value="<:= article.level :>" />
+<input type="hidden" name="id" value="<:= article.id :>" />
+<input type="hidden" name="parentid" value="<:= article.parentid :>" />
 <input type="hidden" name="_t" value="img" />
 <:csrfp admin_add_image hidden:>
         <table>
             <td> 
               <input type="file" name="image" /> 
             </td>
-            <td class="help"><:help image file:> <:error_img image:></td>
+            <td class="help"><:help image file:> <:.call "error_img", field: "image":></td>
           </tr>
           <tr> 
             <th>Alt text for image:</th>
             <td> 
-              <input type="text" name="altIn" value="<:old altIn:>" />
+              <input type="text" name="altIn" value="<:.call "old", field:"altIn":>" />
             </td>
-            <td class="help"><:help image alt:> <:error_img altIn:></td>
+            <td class="help"><:help image alt:> <:.call "error_img", field: "altIn":></td>
           </tr>
           <tr> 
             <th>URL for image:</th>
             <td> 
-              <input type="text" name="url" value="<:old url:>" />
+              <input type="text" name="url" value="<:.call "old", field: "url":>" />
             </td>
-            <td class="help"><:help image url:> <:error_img url:></td>
+            <td class="help"><:help image url:> <:.call "error_img", field: "url":></td>
           </tr>
           <tr> 
             <th>Identifier for image:</th>
             <td> 
-              <input type="text" name="name" value="<:old name:>" />
+              <input type="text" name="name" value="<:.call "old", field: "name":>" />
             </td>
-            <td class="help"><:help image name:> <:error_img name:></td>
+            <td class="help"><:help image name:> <:.call "error_img", field: "name":></td>
           </tr>
   <tr>
     <th>Tags</th>
@@ -65,7 +92,7 @@
         <:% tags.push("") :>
       <:- .end if :>
       <:.for tag in tags :>
-        <div class="tag"><input type="text" name="tags" value="<:= tag :>" /><:.call "error_img_n", "field":"tags", "index":loop.index :></div>
+        <div class="tag"><input type="text" name="tags" value="<:= tag :>" /><:.call "error_img_n", field:"tags", index:loop.index :></div>
       <:.end for:>
       </div>
     </td>
           </tr>
         </table>
 </form>
-<:or UserCan:><:eif UserCan:>
+<:.end if -:>
 
-<form method="post" action="<:script:>" enctype="multipart/form-data" name="manage">
-<input type="hidden" name="level" value="<: level :>" />
-<input type="hidden" name="id" value="<: article id :>" />
-<input type="hidden" name="parentid" value="<: article parentid :>" />
-<input type="hidden" name="imgtype" value="<: articleType :>" />
+<:.set images = [ article.images ] -:>
+<:.set can_save = request.user_can("edit_images_save", article) -:>
+<:.set can_delete = request.user_can("edit_images_delete", article) -:>
+<:.set delete_token = request.get_csrf_token("admin_remove_image") -:>
+
+<form method="post" action="<:= cfg.admin_url("add") :>" enctype="multipart/form-data" name="manage">
+<input type="hidden" name="level" value="<:= article.level :>" />
+<input type="hidden" name="id" value="<:= article.id :>" />
+<input type="hidden" name="parentid" value="<:= article.parentid :>" />
 <input type="hidden" name="_t" value="img" />
 <:csrfp admin_save_images hidden:>
   <h2>Manage images</h2>
-
         <table class="editform images">
-          <:if Images:><:if Eq [article id] "-1":><:or Eq:><:if Cfg basic auto_images 1:><tr> 
+<:.if images.size:><:.if article.id != -1
+  and cfg.entry("basic", "auto_images", 1)-:>
+<tr> 
             <th colspan="5">First Image Position</th>
           </tr>
                  <tr> 
             <td colspan="5"> 
-<input type="radio" name="imagePos" value="tl" <: ifEq [article imagePos] "tl":>checked<:eif:> />Top Left &nbsp;
-<input type="radio" name="imagePos" value="tr"  <: ifEq [article imagePos] "tr":>checked<:eif:> />Top Right &nbsp;
-<input type="radio" name="imagePos" value="bl"  <: ifEq [article imagePos] "bl":>checked<:eif:> />Bottom Left &nbsp;
-<input type="radio" name="imagePos" value="br"  <: ifEq [article imagePos] "br":>checked<:eif:> />Bottom Right
-<input type="radio" name="imagePos" value="xx"  <: ifEq [article imagePos] "xx":>checked<:eif:> />Don't automatically insert images
+<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;
+<input type="radio" name="imagePos" value="br" <:= article.imagePos eq "br" ? "checked " : "":>/>Bottom Right
+<input type="radio" name="imagePos" value="xx" <:= article.imagePos eq "xx" ? "checked " : "":>/>Don't automatically insert images
 
 <:help image position:>
 
            </td>
-          </tr><:eif Cfg:><:eif Eq:>
-<:if Thumbs:>
+          </tr>
+<:-.end if:>
+<:.if thumbs:>
           <tr> 
             <th>Image</th>
             <th colspan="2"> &nbsp;</th>
             <th class="col_modify"> Modify</th>
            <th class="col_move"> Move</th>
           </tr>
-<:iterator begin images:>
+<:.for image in images:>
        <tr>
-          <td rowspan="5" class="col_thumbnail"><a href="#" onclick="window.open('<:image src:>', 'fullimage', 'width=<:arithmetic [image width]+20:>,height=<:arithmetic [image height] + 30:>,location=no,status=no,menubar=no,scrollbars=yes'); return false;"><:thumbimage editor:></a></td>
+          <td rowspan="5" class="col_thumbnail"><a href="#" onclick="window.open('<:= image.src:>', 'fullimage', 'width=<:= 20 + image.width:>,height=<:= 30 + image.height:>,location=no,status=no,menubar=no,scrollbars=yes'); return false;"><:= image.thumb("geo", "editor") |raw:></a></td>
            <th>Alt text:</th>
             <td class="col_field"> 
-              <:ifUserCan edit_images_save:article:><input type="text" name="alt<:image id:>" value="<: oldi [concatenate alt [image id] ] 0 image alt :>" size="32" /><:or:><: image alt :><:eif:>
+              <:.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_modify" rowspan="5"> 
-              <:ifUserCan edit_images_delete:article:><b><a href="<:script:>?id=<:article id:>&amp;removeimg_<: image id :>=1&amp;_t=img&amp;_csrfp=<:csrfp admin_remove_image:>" onClick="return window.confirm('Are you sure you want to delete this Image')">Delete</a></b><:or:><:eif:>
-<:ifUserCan edit_images_save:article:><a href="<:script:>?a_edit_image=1&amp;id=<:article id:>&amp;image_id=<: image id :>">Edit</a><:or:><:eif:></td>
-            <td class="col_move" rowspan="5"><:imgmove:></td>
+<:.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 -:>
+<a href="<:= cfg.admin_url2("add", "edit_image", { id:article.id, image_id:image. id}):>">Edit</a>
+<:-.end if-:>
+</td>
+            <td class="col_move" rowspan="5">
+<:.call "image_move":></td>
          </tr>
          <tr>        
             <th>URL:</th>
             <td class="col_field"> 
-              <:ifUserCan edit_images_save:article:><input type="text" name="url<:image id:>" value="<: oldi [concatenate url [image id] ] 0 image url :>" size="32" /><:or:><: image url :><:eif:>
+              <:.if can_save :><input type="text" name="url<:= image.id :>" value="<:.call "old", field:"url" _ image.id, default:image.url :>" size="32" /><:.else:><:= image.url :><:.end if:>
             </td>
           </tr>
           <tr>
            <th>Identifier:</th>
             <td class="col_field"> 
-              <:ifUserCan edit_images_save:article:><input type="text" name="name<:image id:>" value="<: oldi [concatenate name [image id] ] 0 image name :>" size="32" /> <:error_img [concatenate "name" [image id] ]:><:or:><: image name :><:eif:>
+              <:.if can_save :><input type="text" name="name<:= image.id:>" value="<:.call "old", field: "name" _ image.id, default: image.name :>" size="32" /> <:.call "error_img", field: "name" _ image.id :><:.else:><:= image.name :><:.end if:>
             </td>
         </tr>
           <tr>
            <th>Image file:</th>
             <td class="col_field"> 
-              <:ifUserCan edit_images_save:article:><input type="file" name="image<:image id:>" size="32" /> <:error_img [concatenate "image" [image id] ]:><:or:><: image displayName :><:eif:>
+              <:.if can_save :><input type="file" name="image<:= image.id:>" size="32" /> <:.call "error_img", field: "image" _ image.id:><:.else:><:= image.displayName :><:.end if:>
             </td>
         </tr>
           <tr>
            <th>Stored:</th>
             <td class="col_field"> 
-              <:ifUserCan edit_images_save:article:><select name="storage<:image id:>">
+              <:.if can_save -:>
+<:.set stores = [ image_stores() ] -:>
+<:.set oldstore = cgi.param("storage").defined
+       ? cgi.param("storage") : image.storage -:>
+
+<select name="storage<:= image.id:>">
 <option value="">(Auto)</option>
-<:iterator begin image_stores:>
-<option value="<:image_store name:>" <:ifEq [oldi [concatenate storage [image id] ] 0 image storage] [image_store name]:>selected="selected"<:or:><:eif:>><:image_store description:></option>
-<:iterator end image_stores:>
-</select><:error_img [concatenate "storage" [image id] ]:><:or:><: image storage :><:eif:>
+<:.for store in stores :>
+<option value="<:= store.name:>"<:= oldstore eq store.name ? " selected" : "" :>><:= store.description:></option>
+<:.end for -:>
+</select><:.call "error_img", field: "storage" _ image.id:><:.else:><:= image.storage :><:.end if:>
             </td>
         </tr>
-<:iterator end images:>          
-<:or Thumbs:>
+<:.end for:>          
+<:.else :>
           <tr> 
             <th colspan="5">Image</th>
           </tr>
-          <: iterator begin images :> 
+          <:.for image in images :> 
           <tr> 
-            <td class="col_image" colspan="5"><:image:></td>
+            <td class="col_image" colspan="5"><:= image.inline("align", "center") |raw:></td>
           </tr>
           <tr> 
             <th> Alt Text</th>
           </tr>
           <tr> 
             <td> 
-              <:ifUserCan edit_images_save:article:><input type="text" name="alt<:image id:>" value="<: oldi [concatenate alt [image id] ] 0 image alt :>" size="32" /><:or:><: image alt :><:eif:>
+              <:.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_url"> 
-              <:ifUserCan edit_images_save:article:><input type="text" name="url<:image id:>" value="<: oldi [concatenate url [image id] ] 0 image url :>" size="32" /><:or:><: image url :><:eif:>
+              <:.if can_save:><input type="text" name="url<:=image.id:>" value="<:.call "old", field: "url" _ image.id, default: image.url :>" size="32" /><:.else:><:= image.url :><:.end if:>
             </td>
             <td class="col_identifier"> 
-              <:ifUserCan edit_images_save:article:><input type="text" name="name<:image id:>" value="<: oldi [concatenate name [image id] ] 0 image name :>" size="32" /> <:error_img [concatenate "name" [image id] ]:><:or:><: image name :><:eif:>
+              <:.if can_save:><input type="text" name="name<:= image.id:>" value="<:.call "old", field: "name" _ image.id, default: image.name:>" size="32" /> <:.call "error_img", field: "name" _ image.id :><:.else:><:= image.name :><:.end if:>
             </td>
             <td class="col_modify"> 
-              <:ifUserCan edit_images_delete:article:><b><a href="<:script:>?id=<:article id:>&amp;removeimg_<: image id :>=1&amp;_t=img&amp;_csrfp=<:csrfp admin_remove_image:>" onClick="return window.confirm('Are you sure you want to delete this Image')">Delete</a></b><:or:><:eif:></td>
-            <td class="col_move"><:imgmove:></td>
+              <:.if can_save:><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:></td>
+            <td class="col_move"><:.call "image_move":></td>
           </tr>
-          <: iterator separator images :> 
+          <:.if !loop.is_last :> 
           <tr> 
             <td colspan="5">&nbsp;</td>
           </tr>
-          <: iterator end images :> 
-<:eif Thumbs:>
-<:ifUserCan edit_images_save:article:>
+         <:.end if:>
+          <: .end for :> 
+<:.end if:>
+<:.if can_save:>
           <tr> 
             <td colspan="5" class="buttons"> 
               <input type="submit" name="process" value="Save changes" />
             </td>
          </tr>
-<:or:><:eif:>
-                 <:or Images:><tr><td colspan="5" align="center" bgcolor="#FFFFFF"><:if Eq [article id] "-1":>There are no global images<:or Eq:>No images
-                     are attached to this article<:eif Eq:></td>
-          </tr><:eif Images:>
+<:.end if:>
+<:.else-:>
+  <tr><td colspan="5" align="center" bgcolor="#FFFFFF">
+  <:-= article.id == -1 ? "There are no global images"
+                        : "No images are attached to this article" :></td>
+          </tr><:.end if:>
         </table>
 
-  <p>
-    <input type="submit" name="back" value=" &lt;&lt;  Back  " />
-  </p>
-
 </form>