source: extensions/url_uploader/template/photos_add.tpl @ 26033

Last change on this file since 26033 was 20407, checked in by mistic100, 12 years ago

option to save website URL in photo description

File size: 13.9 KB
Line 
1{combine_css path=$URLUPLOADER_PATH|@cat:"template/style.css"}
2{combine_script id="URI" load="footer" path=$URLUPLOADER_PATH|@cat:"template/URI.min.js"}
3{combine_css path=$URLUPLOADER_PATH|@cat:"template/jquery.textarea-lines-numbers.css"}
4{combine_script id="createTextareaWithLines" load="footer" require="jquery.ui.resizable" path=$URLUPLOADER_PATH|@cat:"template/jquery.textarea-lines-numbers.js"}
5
6{if $upload_mode == 'multiple'}
7{combine_script id='jquery.ajaxmanager' load='footer' path='themes/default/js/plugins/jquery.ajaxmanager.js'}
8{combine_script id='jquery.jgrowl' load='footer' require='jquery' path='themes/default/js/plugins/jquery.jgrowl_minimized.js' }
9{combine_script id='jquery.ui.progressbar' load='footer'}
10{combine_css path="admin/themes/default/uploadify.jGrowl.css"}
11{/if}
12
13{include file='include/colorbox.inc.tpl'}
14{include file='include/add_album.inc.tpl'}
15
16
17{footer_script}
18var allowed_extensions = new Array('jpeg','jpg','png','gif');
19var errorHead   = '{'ERROR'|@translate|@escape:'javascript'}';
20var errorMsg    = '{'an error happened'|@translate|@escape:'javascript'}';
21
22var lang = new Array();
23lang['Invalid file URL'] = '{'Invalid file URL'|@translate|@escape:'javascript'}';
24lang['Invalid file type'] = '{'Invalid file type'|@translate|@escape:'javascript'}';
25lang['File URL is empty'] = '{'File URL is empty'|@translate|@escape:'javascript'}';
26lang['Unable to download file'] = '{'Unable to download file'|@translate|@escape:'javascript'}';
27lang['Pending'] = '{'Pending'|@translate|@escape:'javascript'}';
28lang['Delete this item'] = '{'Delete this item'|@translate|@escape:'javascript'}';
29
30{literal}
31jQuery("#hideErrors").click(function() {
32    jQuery("#formErrors").hide();
33    return false;
34  });
35 
36jQuery("#uploadWarningsSummary a.showInfo").click(function() {
37    jQuery("#uploadWarningsSummary").hide();
38    jQuery("#uploadWarnings").show();
39    return false;
40  });
41 
42jQuery("#showPermissions").click(function() {
43    jQuery(this).parent(".showFieldset").hide();
44    jQuery("#permissions").show();
45    return false;
46  });
47{/literal}
48
49
50{* <!-- MULTIPLE UPLOAD --> *}
51{if $upload_mode == 'multiple'}
52{literal}
53function checkUploadStart() {
54  var nbErrors = 0;
55 
56  jQuery("#formErrors").hide();
57  jQuery("#formErrors li").hide();
58
59  if (jQuery("#albumSelect option:selected").length == 0) {
60    jQuery("#formErrors #noAlbum").show();
61    nbErrors++;
62  }
63 
64  var nbFiles = jQuery("table#links tr.pending").length;
65 
66  if (nbFiles == 0) {
67    jQuery("#formErrors #noPhoto").show();
68    nbErrors++;
69  }
70
71  if (nbErrors != 0) {
72    jQuery("#formErrors").show();
73    return false;
74  }
75  else {
76    return true;
77  }
78}
79
80function trim (myString) {
81  return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
82}
83
84jQuery("input[name='add_links']").click(function() {
85  $input = jQuery("textarea#urls");
86 
87  if ($input.val() != "") {
88    jQuery("table#links").show();
89   
90    lines = $input.val().split('\n');
91    $input.val("");
92   
93    for (i in lines) {
94      line = lines[i].split('|');
95      item = new Array;
96     
97      // no name given
98      if (line.length == 1) {
99        uri = new URI(trim(line[0]));
100        item['name'] = "";
101      }
102      // name given
103      else {
104        uri = new URI(trim(line[1]));
105        item['name']= trim(line[0]);
106      }
107     
108      uri.fragment("");
109      item['url'] = uri.href();
110      item['short_url'] = item['url'];
111     
112      // shortened url for display
113      if (item['url'].length > 40) {
114        item['short_url'] = item['url'].substring(0, 17) + ' ... ' + item['url'].substring(item['url'].length-17);
115      }
116     
117      // check if consistent url
118      if (uri.is("relative")) {
119        item['status'] = 'error';
120        item['info'] = lang['Invalid file URL'];
121      }
122      else {
123        // check if good extension
124        if (allowed_extensions.indexOf(uri.suffix().toLowerCase()) == -1) {
125          item['status'] = 'error';
126          item['info'] = lang['Invalid file type'];
127        }
128        else {
129          item['status'] = 'pending';
130          item['info'] = lang['Pending'];
131        }
132      }
133     
134      // add link to table
135      jQuery("table#links tbody").append('<tr class="'+ item['status'] + '" data-name="'+ item['name'] +'" data-url="'+ item['url'] +'">'+
136        '<td>'+ item['name'] +'</td>'+
137        '<td><a href="'+ item['url'] +'">'+ item['short_url'] +'</a></td>'+
138        '<td>'+ item['info'] +'</td>'+
139        '<td><a class="delete" title="'+ lang['Delete this item'] +'">&nbsp;</a></td>'+
140      '</tr>');
141    }
142  }
143 
144  $input.focus();
145  return false;
146});
147
148jQuery("table#links").on("click", "a.delete", function() {
149  $(this).parents("tr").remove();
150  jQuery("textarea#urls").focus();
151});
152
153/* <!-- AJAX MANAGER --> */
154var import_done = 0;
155var import_selected = 0;
156var queuedManager = jQuery.manageAjax.create('queued', {
157  queue: true, 
158  maxRequests: 1
159});
160
161function performImport(file_url, category, name, level, url_in_comment, $target) {
162  queuedManager.add({
163    type: 'GET',
164    dataType: 'json',
165    url: 'ws.php',
166    data: { method: 'pwg.images.addRemote', file_url: file_url, category: category, name: name, level: level, url_in_comment: url_in_comment, format: 'json' },
167    success: function(data) {
168      if (data['stat'] == 'ok') {
169        $target.remove();
170        jQuery("#uploadedPhotos").parent("fieldset").show();
171        jQuery("#uploadedPhotos").prepend('<img src="'+ data['result']['thumbnail_url'] +'" class="thumbnail"> ');
172        jQuery("#uploadForm").append('<input type="hidden" name="imageIds[]" value="'+ data['result']['image_id'] +'">');
173      }
174      else {
175        jQuery.jGrowl(name +' : '+ lang[data['message']], {
176          theme: 'error',
177          header: errorHead,
178          sticky: true
179          });
180         
181        $target.children("td:nth-child(3)").html(lang[data['message']]);
182        jQuery("#uploadForm").append('<input type="hidden" name="onUploadError[]" value="'+ file_url +' : '+ lang[data['message']] +'">');
183      }
184     
185      import_done++;
186      jQuery("#progressbar").progressbar({value: import_done});
187      jQuery("#progressCurrent").text(import_done);
188     
189      if (import_done == import_selected) {
190        $("#uploadForm").submit();
191      }
192    },
193    error: function(data) {
194      jQuery.jGrowl(name +' : '+ errorMsg, {
195        theme: 'error',
196        header: errorHead,
197        sticky: true
198        });
199     
200      $target.children("td:nth-child(3)").html(errorMsg);
201    }
202  });
203}
204
205jQuery("input[name='submit_upload']").click(function() {
206  if (!checkUploadStart()) {
207    return false;
208  }
209 
210  import_selected = jQuery("table#links tr.pending").length;
211 
212  jQuery("table#links a.delete").hide();
213 
214  jQuery("#progressbar").progressbar({max: import_selected, value:0});
215  jQuery("#progressMax").text(import_selected);
216  jQuery("#progressCurrent").text(0);
217  jQuery("#uploadProgress").show();
218 
219  jQuery("table#links tr.pending").each(function() {
220    performImport(
221      $(this).data('url'),
222      $("select[name=category] option:selected").val(),
223      $(this).data('name'),
224      $("select[name=level] option:selected").val(),
225      $("input[name=url_in_comment]").is(":checked"),
226      $(this)
227      );
228  });
229   
230  return false;
231});
232
233$("textarea#urls").textareaLinesNumbers({
234  lines:999,
235  trailing:'.'
236});
237{/literal}
238
239
240{* <!-- SINGLE UPLOAD --> *}
241{else}
242{literal}
243function checkUploadStart() {
244  var nbErrors = 0;
245 
246  jQuery("#formErrors").hide();
247  jQuery("#formErrors li").hide();
248
249  if (jQuery("#albumSelect option:selected").length == 0) {
250    jQuery("#formErrors #noAlbum").show();
251    nbErrors++;
252  }
253 
254  if (jQuery("input[name='file_url']").val() == "") {
255    jQuery("#formErrors #urlEmpty").show();
256    nbErrors++;
257  }
258  else {
259    uri = new URI(jQuery("input[name='file_url']").val());
260    if (uri.is('relative')) {
261      jQuery("#formErrors #urlError").show();
262      nbErrors++;
263    }
264    else if (allowed_extensions.indexOf(uri.suffix().toLowerCase()) == -1) {
265      jQuery("#formErrors #typeError").show();
266      nbErrors++;
267    }
268  }
269
270  if (nbErrors != 0) {
271    jQuery("#formErrors").show();
272    return false;
273  }
274  else {
275    return true;
276  }
277}
278
279jQuery("input[name='submit_upload']").click(function() {
280  return checkUploadStart();
281});
282{/literal}
283{/if}
284
285{/footer_script}
286
287
288{html_head}{literal}
289<style type="text/css">
290a.delete {
291  background:url('admin/include/uploadify/cancel.png');
292}
293</style>
294{/literal}{/html_head}
295
296
297<div class="titrePage">
298  <h2>{'Upload Photos'|@translate} {$TABSHEET_TITLE}</h2>
299</div>
300
301<div id="photosAddContent">
302
303{if count($setup_errors) > 0}
304<div class="errors">
305  <ul>
306  {foreach from=$setup_errors item=error}
307    <li>{$error}</li>
308  {/foreach}
309  </ul>
310</div>
311{else}
312
313  {if count($setup_warnings) > 0}
314<div class="warnings">
315  <ul>
316    {foreach from=$setup_warnings item=warning}
317    <li>{$warning}</li>
318    {/foreach}
319  </ul>
320  <div class="hideButton" style="text-align:center"><a href="{$hide_warnings_link}">{'Hide'|@translate}</a></div>
321</div>
322  {/if}
323 
324{if !empty($thumbnails)}
325<fieldset>
326  <legend>{'Uploaded Photos'|@translate}</legend>
327  <div>
328  {foreach from=$thumbnails item=thumbnail}
329    <a href="{$thumbnail.link}" class="externalLink">
330      <img src="{$thumbnail.src}" alt="{$thumbnail.file}" title="{$thumbnail.title}" class="thumbnail">
331    </a>
332  {/foreach}
333  </div>
334  <p id="batchLink"><a href="{$batch_link}">{$batch_label}</a></p>
335</fieldset>
336<p style="margin:10px"><a href="{$another_upload_link}">{'Add another set of photos'|@translate}</a></p>
337{else}
338
339<div id="formErrors" class="errors" style="display:none">
340  <ul>
341    <li id="noAlbum">{'Select an album'|@translate}</li>
342    <li id="noPhoto">{'Select at least one photo'|@translate}</li>
343    <li id="urlEmpty">{'File URL is empty'|@translate}</li>
344    <li id="urlError">{'Invalid file URL'|@translate}</li>
345    <li id="typeError">{'Invalid file type'|@translate}</li>
346  </ul>
347  <div class="hideButton" style="text-align:center"><a href="#" id="hideErrors">{'Hide'|@translate}</a></div>
348</div>
349
350<form id="uploadForm" enctype="multipart/form-data" method="post" action="{$form_action}" class="properties">
351    <fieldset>
352      <legend>{'Drop into album'|@translate}</legend>
353
354      <span id="albumSelection"{if count($category_options) == 0} style="display:none"{/if}>
355      <select id="albumSelect" name="category">
356        {html_options options=$category_options selected=$category_options_selected}
357      </select>
358      <br>{'... or '|@translate}</span><a href="#" class="addAlbumOpen" title="{'create a new album'|@translate}">{'create a new album'|@translate}</a>
359     
360    </fieldset>
361
362    <fieldset>
363      <legend>{'Select files'|@translate}</legend>
364     
365      <p id="uploadWarningsSummary">
366        {'Allowed file types: %s.'|@translate|@sprintf:$upload_file_types}
367      {if isset($max_upload_resolution)}
368        {$max_upload_resolution}Mpx
369        <a class="showInfo" title="{'Learn more'|@translate}">i</a>
370      {/if}
371      </p>
372
373      <p id="uploadWarnings">
374        {'Allowed file types: %s.'|@translate|@sprintf:$upload_file_types}
375      {if isset($max_upload_resolution)}
376        {'Approximate maximum resolution: %dM pixels (that\'s %dx%d pixels).'|@translate|@sprintf:$max_upload_resolution:$max_upload_width:$max_upload_height}
377      {/if}
378      </p>
379
380{* <!-- SINGLE UPLOAD --> *}
381{if $upload_mode == 'single'}
382      <ul>
383        <li>
384          <label>
385            <span class="property">{'File URL'|@translate}</span>
386            <input type="text" name="file_url" size="70">
387          </label>
388        </li>
389        <li>
390          <label>
391            <span class="property">{'Photo name'|@translate}</span>
392            <input type="text" name="photo_name" size="40">
393          </label>
394        </li>
395        <li>
396          <label>
397            <span class="property"><input type="checkbox" name="url_in_comment" checked="checked"></span>
398            {'Add website URL in photo description'|@translate}
399          </label>
400        </li>
401      </ul>     
402     
403      <p id="uploadModeInfos">{'Want to upload many files? Try the <a href="%s">multiple uploader</a> instead.'|@translate|@sprintf:$switch_url}</p>
404
405{* <!-- MULTIPLE UPLOAD --> *}
406{else}
407
408      <table id="links" class="table2" style="display:none;">
409        <thead>
410          <tr class="throw">
411            <th style="width:150px;">{'Photo name'|@translate}</th>
412            <th>{'File URL'|@translate}</th>
413            <th style="width:150px;">{'Status'|@translate}</th>
414            <th style="width:20px;"></th>
415          </tr>
416        </thead>
417        <tbody>
418        </tbody>
419        <tfoot>
420          <tr><th colspan="4">
421          <label>
422            <input type="checkbox" name="url_in_comment" checked="checked">
423            {'Add website URL in photo description'|@translate}
424          </label>
425          </th></tr>
426        </tfoot>
427      </table>
428     
429      <p>
430        {'One link by line, separate photo name and url with a &laquo; | &raquo;. Photo name is optional.'|@translate}
431        <br>
432        <textarea id="urls"></textarea>
433      </p>
434      <input type="submit" name="add_links" value="{'Add links'|@translate}">
435     
436      <p id="uploadModeInfos">{'Multiple uploader doesn\'t work? Try the <a href="%s">single uploader</a> instead.'|@translate|@sprintf:$switch_url}</p>
437{/if}
438    </fieldset>
439
440    <p class="showFieldset"><a id="showPermissions" href="#">{'Manage Permissions'|@translate}</a></p>
441
442    <fieldset id="permissions" style="display:none">
443      <legend>{'Who can see these photos?'|@translate}</legend>
444
445      <select name="level" size="1">
446        {html_options options=$level_options selected=$level_options_selected}
447      </select>
448    </fieldset>
449   
450    <p>
451      <input class="submit" type="submit" name="submit_upload" value="{'Start Upload'|@translate}">
452    </p>
453</form>
454
455<div id="uploadProgress" style="display:none">
456{'Photo %s of %s'|@translate|@sprintf:'<span id="progressCurrent">1</span>':'<span id="progressMax">10</span>'}
457<br>
458<div id="progressbar"></div>
459</div>
460
461<fieldset style="display:none">
462  <legend>{'Uploaded Photos'|@translate}</legend>
463  <div id="uploadedPhotos"></div>
464</fieldset>
465
466{/if} {* empty($thumbnails) *}
467{/if} {* $setup_errors *}
468
469<br>
470</div> <!-- photosAddContent -->
Note: See TracBrowser for help on using the repository browser.