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

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

upload form: automatically focus on the album name when opening the create album form

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