source: extensions/community/add_photos.tpl @ 10171

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

make Community upload form compatible with Simple* and Stripped themes

File size: 10.6 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 P {
242  /* margin:0; */
243}
244
245#uploadBoxes P {
246  margin:0;
247  margin-bottom:2px;
248  padding:0;
249}
250
251#batchLink {
252  text-align:center;
253}
254
255.category_selection {
256  min-height:50px;
257  margin-top:5px;
258}
259
260.category_selection TABLE {
261  margin:0;
262}
263</style>
264{/literal}
265
266<div id="photosAddContent">
267
268  {if isset($errors)}
269  <div class="errors">
270    <ul>
271      {foreach from=$errors item=error}
272      <li>{$error}</li>
273      {/foreach}
274    </ul>
275  </div>
276  {/if}
277
278  {if isset($infos)}
279  <div class="infos">
280    <ul>
281      {foreach from=$infos item=info}
282      <li>{$info}</li>
283      {/foreach}
284    </ul>
285  </div>
286  {/if}
287
288
289{if count($setup_errors) > 0}
290<div class="errors">
291  <ul>
292  {foreach from=$setup_errors item=error}
293    <li>{$error}</li>
294  {/foreach}
295  </ul>
296</div>
297{else}
298
299  {if count($setup_warnings) > 0}
300<div class="warnings">
301  <ul>
302    {foreach from=$setup_warnings item=warning}
303    <li>{$warning}</li>
304    {/foreach}
305  </ul>
306  <div class="hideButton" style="text-align:center"><a href="{$hide_warnings_link}">{'Hide'|@translate}</a></div>
307</div>
308  {/if}
309
310
311{if !empty($thumbnails)}
312<fieldset>
313  <legend>{'Uploaded Photos'|@translate}</legend>
314  <div>
315  {foreach from=$thumbnails item=thumbnail}
316    <a href="{$thumbnail.link}" class="externalLink">
317      <img src="{$thumbnail.src}" alt="{$thumbnail.file}" title="{$thumbnail.title}" class="thumbnail">
318    </a>
319  {/foreach}
320  </div>
321</fieldset>
322<p><a href="{$another_upload_link}">{'Add another set of photos'|@translate}</a></p>
323{else}
324
325<div id="formErrors" class="errors" style="display:none">
326  <ul>
327    <li id="emptyCategoryName">{'The name of an album must not be empty'|@translate}</li>
328    <li id="noPhoto">{'Select at least one photo'|@translate}</li>
329  </ul>
330  <div class="hideButton" style="text-align:center"><a href="#" id="hideErrors">{'Hide'|@translate}</a></div>
331</div>
332
333<form id="uploadForm" enctype="multipart/form-data" method="post" action="{$form_action}" class="properties">
334    <fieldset>
335      <legend>{'Drop into album'|@translate}</legend>
336      {if $upload_mode eq 'multiple'}
337      <input name="upload_id" value="{$upload_id}" type="hidden">
338      {/if}
339
340{if $create_subcategories}
341      <label><input type="radio" name="category_type" value="existing"> {'existing album'|@translate}</label>
342      <label><input type="radio" name="category_type" value="new" checked="checked"> {'create a new album'|@translate}</label>
343{else}
344      <input name="category_type" value="existing" type="hidden">
345{/if}
346
347      <div id="category_type_existing" {if $create_subcategories}style="display:none" class="category_selection"{/if}>
348        <select class="categoryDropDown" name="category">
349          {html_options options=$category_options selected=$category_options_selected}
350        </select>
351      </div>
352
353{if $create_subcategories}
354      <div id="category_type_new" class="category_selection">
355        <table>
356          <tr>
357            <td>{'Parent album'|@translate}</td>
358            <td>
359              <select class="categoryDropDown" name="category_parent">
360{if $create_whole_gallery}
361                <option value="0">------------</option>
362{/if}
363                {html_options options=$category_parent_options selected=$category_parent_options_selected}
364              </select>
365            </td>
366          </tr>
367          <tr>
368            <td>{'Album name'|@translate}</td>
369            <td>
370              <input type="text" name="category_name" value="{$F_CATEGORY_NAME}" style="width:400px">
371            </td>
372          </tr>
373        </table>
374      </div>
375{/if}
376    </fieldset>
377
378    <fieldset>
379      <legend>{'Select files'|@translate}</legend>
380
381{if $upload_mode eq 'html'}
382    <p><a href="{$switch_url}">{'... or switch to the multiple files form'|@translate}</a></p>
383
384      <p>{'JPEG files or ZIP archives with JPEG files inside please.'|@translate}</p>
385
386      <div id="uploadBoxes"></div>
387      <div id="addUploadBox">
388        <a href="javascript:">{'+ Add an upload box'|@translate}</a>
389      </div>
390   
391    </fieldset>
392
393    <p>
394      <input class="submit" type="submit" name="submit_upload" value="{'Upload'|@translate}">
395    </p>
396{elseif $upload_mode eq 'multiple'}
397    <p>
398      <input type="file" name="uploadify" id="uploadify">
399    </p>
400
401    <p><a href="{$switch_url}">{'... or switch to the old style form'|@translate}</a></p>
402
403    <div id="fileQueue"></div>
404
405    </fieldset>
406    <p>
407      <input class="submit" type="button" value="{'Upload'|@translate}">
408      <input type="submit" name="submit_upload" style="display:none">
409    </p>
410{/if}
411</form>
412{/if} {* empty($thumbnails) *}
413{/if} {* $setup_errors *}
414
415</div> <!-- photosAddContent -->
Note: See TracBrowser for help on using the repository browser.