source: extensions/community/add_photos.tpl @ 10756

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

feature 2294 added: ability to define photo properties before upload (name/author/description).

Because this is more a workaround than a clean way to implement it, webmaster
has to set $confcommunity_ask_for_properties = true in is local configuration file.

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