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

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

feature 2410 added: uploadify upgraded from version 2.1.0 to 3.0.0 (still beta,
but said as stable by users on uploadify forums)

bug 2411 fixed: thanks to uploadify 3.0.0, the "Browse" button is now localized
(text in any language)

bug 1653 fixed: if the selected file exceeds the upload_max_size (as defined in
the php.ini), an alert is shown and the file is not added to the queue.

bug 2412 fixed: ability to select GIF files with the Flash Uploader.

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