source: trunk/admin/themes/default/template/photos_add_direct.tpl @ 11966

Last change on this file since 11966 was 11966, checked in by plg, 13 years ago

feature 2407 added: display upload limitations before file selection (file
maximum size, maximum dimensions, allowed file types). The maximum dimensions
are calculated for GD only (because Imagick and External ImageMagick are not
using PHP memory as far as I could find on the web).

bug 2408 fixed: change term "old style form" into "browser uploader" and
"multiple file form" into "Flash Uploader" (based on WordPress user interface)

File size: 12.8 KB
Line 
1{if $upload_mode eq 'multiple'}
2{combine_script id='jquery.jgrowl' load='footer' require='jquery' path='themes/default/js/plugins/jquery.jgrowl_minimized.js' }
3{combine_script id='swfobject' load='footer' path='admin/include/uploadify/swfobject.js'}
4{combine_script id='jquery.uploadify' load='footer' require='jquery' path='admin/include/uploadify/jquery.uploadify.v2.1.0.min.js' }
5{combine_css path="admin/themes/default/uploadify.jGrowl.css"}
6{combine_css path="admin/include/uploadify/uploadify.css"}
7{/if}
8
9{include file='include/colorbox.inc.tpl'}
10
11{footer_script}{literal}
12jQuery(document).ready(function(){
13  function checkUploadStart() {
14    var nbErrors = 0;
15    jQuery("#formErrors").hide();
16    jQuery("#formErrors li").hide();
17
18    var nbFiles = 0;
19    if (jQuery("#uploadBoxes").size() == 1) {
20      jQuery("input[name^=image_upload]").each(function() {
21        if (jQuery(this).val() != "") {
22          nbFiles++;
23        }
24      });
25    }
26    else {
27      nbFiles = jQuery(".uploadifyQueueItem").size();
28    }
29
30    if (nbFiles == 0) {
31      jQuery("#formErrors #noPhoto").show();
32      nbErrors++;
33    }
34
35    if (nbErrors != 0) {
36      jQuery("#formErrors").show();
37      return false;
38    }
39    else {
40      return true;
41    }
42
43  }
44
45  function humanReadableFileSize(bytes) {
46    var byteSize = Math.round(bytes / 1024 * 100) * .01;
47    var suffix = 'KB';
48
49    if (byteSize > 1000) {
50      byteSize = Math.round(byteSize *.001 * 100) * .01;
51      suffix = 'MB';
52    }
53
54    var sizeParts = byteSize.toString().split('.');
55    if (sizeParts.length > 1) {
56      byteSize = sizeParts[0] + '.' + sizeParts[1].substr(0,2);
57    }
58    else {
59      byteSize = sizeParts[0];
60    }
61
62    return byteSize+suffix;
63  }
64
65  function fillCategoryListbox(selectId, selectedValue) {
66    jQuery.getJSON(
67      "ws.php?format=json&method=pwg.categories.getList",
68      {
69        recursive: true,
70        fullname: true,
71        format: "json",
72      },
73      function(data) {
74        jQuery.each(
75          data.result.categories,
76          function(i,category) {
77            var selected = "";
78            if (category.id == selectedValue) {
79              selected = "selected";
80            }
81           
82            jQuery("<option/>")
83              .attr("value", category.id)
84              .attr("selected", selected)
85              .text(category.name)
86              .appendTo("#"+selectId)
87              ;
88          }
89        );
90      }
91    );
92  }
93
94/*
95  jQuery("#albumSelect").find("option").remove();
96  fillCategoryListbox("albumSelect");
97  fillCategoryListbox("category_parent");
98*/
99 
100  jQuery(".addAlbumOpen").colorbox({inline:true, href:"#addAlbumForm"});
101
102  jQuery("#addAlbumForm form").submit(function(){
103      jQuery("#categoryNameError").text("");
104
105      jQuery.ajax({
106        url: "ws.php?format=json&method=pwg.categories.add",
107        data: {
108          parent: jQuery("select[name=category_parent] option:selected").val(),
109          name: jQuery("input[name=category_name]").val(),
110        },
111        beforeSend: function() {
112          jQuery("#albumCreationLoading").show();
113        },
114        success:function(html) {
115          jQuery("#albumCreationLoading").hide();
116
117          var newAlbum = jQuery.parseJSON(html).result.id;
118          jQuery(".addAlbumOpen").colorbox.close();
119
120          jQuery("#albumSelect").find("option").remove();
121          fillCategoryListbox("albumSelect", newAlbum);
122
123          /* we refresh the album creation form, in case the user wants to create another album */
124          jQuery("#category_parent").find("option").remove();
125          fillCategoryListbox("category_parent", newAlbum);
126
127          jQuery("#addAlbumForm form input[name=category_name]").val('');
128
129          return true;
130        },
131        error:function(XMLHttpRequest, textStatus, errorThrows) {
132            jQuery("#albumCreationLoading").hide();
133            jQuery("#categoryNameError").text(errorThrows).css("color", "red");
134        }
135      });
136
137      return false;
138  });
139
140  jQuery("#hideErrors").click(function() {
141    jQuery("#formErrors").hide();
142    return false;
143  });
144
145  jQuery("#uploadWarningsSummary a.showInfo").click(function() {
146    jQuery("#uploadWarningsSummary").hide();
147    jQuery("#uploadWarnings").show();
148  });
149
150{/literal}
151{if $upload_mode eq 'html'}
152{literal}
153  function addUploadBox() {
154    var uploadBox = '<p class="file"><input type="file" size="60" name="image_upload[]"></p>';
155    jQuery(uploadBox).appendTo("#uploadBoxes");
156  }
157
158  addUploadBox();
159
160  jQuery("#addUploadBox A").click(function () {
161    addUploadBox();
162  });
163
164  jQuery("#uploadForm").submit(function() {
165    return checkUploadStart();
166  });
167{/literal}
168{elseif $upload_mode eq 'multiple'}
169
170var uploadify_path = '{$uploadify_path}';
171var upload_id = '{$upload_id}';
172var session_id = '{$session_id}';
173var pwg_token = '{$pwg_token}';
174var buttonText = 'Browse';
175var sizeLimit = {$upload_max_filesize};
176
177{literal}
178  jQuery("#uploadify").uploadify({
179    'uploader'       : uploadify_path + '/uploadify.swf',
180    'script'         : uploadify_path + '/uploadify.php',
181    'scriptData'     : {
182      'upload_id' : upload_id,
183      'session_id' : session_id,
184      'pwg_token' : pwg_token,
185    },
186    'cancelImg'      : uploadify_path + '/cancel.png',
187    'queueID'        : 'fileQueue',
188    'auto'           : false,
189    'buttonText'     : buttonText,
190    'multi'          : true,
191    'fileDesc'       : 'Photo files (*.jpg,*.jpeg,*.png)',
192    'fileExt'        : '*.jpg;*.JPG;*.jpeg;*.JPEG;*.png;*.PNG',
193    'sizeLimit'      : sizeLimit,
194    'onSelect'       : function(event,ID,fileObj) {
195      jQuery("#fileQueue").show();
196    },
197    'onAllComplete'  : function(event, data) {
198      if (data.errors) {
199        return false;
200      }
201      else {
202        jQuery("input[name=submit_upload]").click();
203      }
204    },
205    onError: function (event, queueID ,fileObj, errorObj) {
206      var msg;
207
208      if (errorObj.type === "HTTP") {
209        if (errorObj.info === 404) {
210          alert('Could not find upload script.');
211          msg = 'Could not find upload script.';
212        }
213        else {
214          msg = errorObj.type+": "+errorObj.info;
215        }
216      }
217      else if (errorObj.type ==="File Size") {
218        msg = "File too big";
219        msg = msg + '<br>'+fileObj.name+': '+humanReadableFileSize(fileObj.size);
220        msg = msg + '<br>Limit: '+humanReadableFileSize(sizeLimit);
221      }
222      else {
223        msg = errorObj.type+": "+errorObj.info;
224      }
225
226      jQuery.jGrowl(
227        '<p></p>'+msg,
228        {
229          theme:  'error',
230          header: 'ERROR',
231          sticky: true
232        }
233      );
234
235      jQuery("#fileUploadgrowl" + queueID).fadeOut(
236        250,
237        function() {
238          jQuery("#fileUploadgrowl" + queueID).remove()
239        }
240      );
241      return false;
242    },
243    onCancel: function (a, b, c, d) {
244      var msg = "Cancelled uploading: "+c.name;
245      jQuery.jGrowl(
246        '<p></p>'+msg,
247        {
248          theme:  'warning',
249          header: 'Cancelled Upload',
250          life:   4000,
251          sticky: false
252        }
253      );
254    },
255    onClearQueue: function (a, b) {
256      var msg = "Cleared "+b.fileCount+" files from queue";
257      jQuery.jGrowl(
258        '<p></p>'+msg,
259        {
260          theme:  'warning',
261          header: 'Cleared Queue',
262          life:   4000,
263          sticky: false
264        }
265      );
266    },
267    onComplete: function (a, b ,c, response, e) {
268      var size = Math.round(c.size/1024);
269
270      var response = jQuery.parseJSON(response);
271
272      jQuery("#uploadedPhotos").parent("fieldset").show();
273      jQuery("#uploadedPhotos").prepend('<img src="'+response.thumbnail_url+'" class="thumbnail"> ');
274
275      jQuery.jGrowl(
276        '<p></p>'+c.name+' - '+size+'KB',
277        {
278          theme:  'success',
279          header: 'Upload Complete',
280          life:   4000,
281          sticky: false
282        }
283      );
284    }
285  });
286
287  jQuery("input[type=button]").click(function() {
288    if (!checkUploadStart()) {
289      return false;
290    }
291
292    jQuery("#uploadify").uploadifySettings(
293      'scriptData',
294      {
295        'category_id' : jQuery("select[name=category] option:selected").val(),
296        'level' : jQuery("select[name=level] option:selected").val(),
297      }
298    );
299
300    jQuery("#uploadify").uploadifyUpload();
301  });
302
303{/literal}
304{/if}
305});
306{/footer_script}
307
308<div class="titrePage">
309  <h2>{'Upload Photos'|@translate}</h2>
310</div>
311
312<div id="photosAddContent">
313
314{if count($setup_errors) > 0}
315<div class="errors">
316  <ul>
317  {foreach from=$setup_errors item=error}
318    <li>{$error}</li>
319  {/foreach}
320  </ul>
321</div>
322{else}
323
324  {if count($setup_warnings) > 0}
325<div class="warnings">
326  <ul>
327    {foreach from=$setup_warnings item=warning}
328    <li>{$warning}</li>
329    {/foreach}
330  </ul>
331  <div class="hideButton" style="text-align:center"><a href="{$hide_warnings_link}">{'Hide'|@translate}</a></div>
332</div>
333  {/if}
334
335
336{if !empty($thumbnails)}
337<fieldset>
338  <legend>{'Uploaded Photos'|@translate}</legend>
339  <div>
340  {foreach from=$thumbnails item=thumbnail}
341    <a href="{$thumbnail.link}" class="externalLink">
342      <img src="{$thumbnail.src}" alt="{$thumbnail.file}" title="{$thumbnail.title}" class="thumbnail">
343    </a>
344  {/foreach}
345  </div>
346  <p id="batchLink"><a href="{$batch_link}">{$batch_label}</a></p>
347</fieldset>
348<p style="margin:10px"><a href="{$another_upload_link}">{'Add another set of photos'|@translate}</a></p>
349{else}
350
351<div id="formErrors" class="errors" style="display:none">
352  <ul>
353    <li id="noPhoto">{'Select at least one photo'|@translate}</li>
354  </ul>
355  <div class="hideButton" style="text-align:center"><a href="#" id="hideErrors">{'Hide'|@translate}</a></div>
356</div>
357
358<div style="display:none">
359  <div id="addAlbumForm" style="text-align:left;padding:1em;">
360    <form>
361      {'Parent album'|@translate}<br>
362      <select id ="category_parent" name="category_parent">
363        <option value="0">------------</option>
364        {html_options options=$category_parent_options selected=$category_parent_options_selected}
365      </select>
366
367      <br><br>{'Album name'|@translate}<br><input name="category_name" type="text"> <span id="categoryNameError"></span>
368      <br><br><br><input type="submit" value="{'Create'|@translate}"> <span id="albumCreationLoading" style="display:none"><img src="themes/default/images/ajax-loader-small.gif"></span>
369    </form>
370  </div>
371</div>
372
373<form id="uploadForm" enctype="multipart/form-data" method="post" action="{$form_action}" class="properties">
374{if $upload_mode eq 'multiple'}
375    <input name="upload_id" value="{$upload_id}" type="hidden">
376{/if}
377
378    <fieldset>
379      <legend>{'Drop into album'|@translate}</legend>
380
381      <select id="albumSelect" name="category">
382        {html_options options=$category_options selected=$category_options_selected}
383      </select>
384      <br>{'... or '|@translate}<a href="#" class="addAlbumOpen" title="{'create a new album'|@translate}">{'create a new album'|@translate}</a>
385     
386    </fieldset>
387
388    <fieldset>
389      <legend>{'Who can see these photos?'|@translate}</legend>
390
391      <select name="level" size="1">
392        {html_options options=$level_options selected=$level_options_selected}
393      </select>
394    </fieldset>
395
396    <fieldset>
397      <legend>{'Select files'|@translate}</legend>
398
399    <p id="uploadWarningsSummary">{$upload_max_filesize_shorthand}B. {$upload_file_types}. {if isset($max_upload_resolution)}{$max_upload_resolution}Mpx{/if} <a class="showInfo" title="{'Learn more'|@translate}">i</a></p>
400
401    <p id="uploadWarnings">
402{'Maximum file size: %sB.'|@translate|@sprintf:$upload_max_filesize_shorthand}
403{'Allowed file types: %s.'|@translate|@sprintf:$upload_file_types}
404  {if isset($max_upload_resolution)}
405{'Approximate maximum resolution: %dM pixels (that\'s %dx%d pixels).'|@translate|@sprintf:$max_upload_resolution:$max_upload_width:$max_upload_height}
406  {/if}
407    </p>
408
409{if $upload_mode eq 'html'}
410      <div id="uploadBoxes"></div>
411      <div id="addUploadBox">
412        <a href="javascript:">{'+ Add an upload box'|@translate}</a>
413      </div>
414
415    <p id="uploadModeInfos">{'You are using the Browser uploader. Try the <a href="%s">Flash uploader</a> instead.'|@translate|@sprintf:$switch_url}</p>
416   
417    </fieldset>
418
419    <p>
420      <input class="submit" type="submit" name="submit_upload" value="{'Start Upload'|@translate}">
421    </p>
422{elseif $upload_mode eq 'multiple'}
423
424    <p>
425      <input type="file" name="uploadify" id="uploadify">
426    </p>
427
428    <div id="fileQueue" style="display:none"></div>
429
430    <p id="uploadModeInfos">{'You are using the Flash uploader. Problems? Try the <a href="%s">Browser uploader</a> instead.'|@translate|@sprintf:$switch_url}</p>
431
432    </fieldset>
433    <p>
434      <input class="submit" type="button" value="{'Start Upload'|@translate}">
435      <input type="submit" name="submit_upload" style="display:none">
436    </p>
437{/if}
438</form>
439
440<fieldset style="display:none">
441  <legend>{'Uploaded Photos'|@translate}</legend>
442  <div id="uploadedPhotos"></div>
443</fieldset>
444
445{/if} {* empty($thumbnails) *}
446{/if} {* $setup_errors *}
447
448</div> <!-- photosAddContent -->
Note: See TracBrowser for help on using the repository browser.