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

Last change on this file since 19805 was 19805, checked in by mistic100, 11 years ago

convert textarea liner to jquery

File size: 13.4 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, $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, 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      $(this)
226      );
227  });
228   
229  return false;
230});
231
232$("textarea#urls").textareaLinesNumbers({
233  lines:999,
234  trailing:'.'
235});
236{/literal}
237
238
239{* <!-- SINGLE UPLOAD --> *}
240{else}
241{literal}
242function checkUploadStart() {
243  var nbErrors = 0;
244 
245  jQuery("#formErrors").hide();
246  jQuery("#formErrors li").hide();
247
248  if (jQuery("#albumSelect option:selected").length == 0) {
249    jQuery("#formErrors #noAlbum").show();
250    nbErrors++;
251  }
252 
253  if (jQuery("input[name='file_url']").val() == "") {
254    jQuery("#formErrors #urlEmpty").show();
255    nbErrors++;
256  }
257  else {
258    uri = new URI(jQuery("input[name='file_url']").val());
259    if (uri.is('relative')) {
260      jQuery("#formErrors #urlError").show();
261      nbErrors++;
262    }
263    else if (allowed_extensions.indexOf(uri.suffix().toLowerCase()) == -1) {
264      jQuery("#formErrors #typeError").show();
265      nbErrors++;
266    }
267  }
268
269  if (nbErrors != 0) {
270    jQuery("#formErrors").show();
271    return false;
272  }
273  else {
274    return true;
275  }
276}
277
278jQuery("input[name='submit_upload']").click(function() {
279  return checkUploadStart();
280});
281{/literal}
282{/if}
283
284{/footer_script}
285
286
287{html_head}{literal}
288<style type="text/css">
289a.delete {
290  background:url('admin/include/uploadify/cancel.png');
291}
292</style>
293{/literal}{/html_head}
294
295
296<div class="titrePage">
297  <h2>{'Upload Photos'|@translate} {$TABSHEET_TITLE}</h2>
298</div>
299
300<div id="photosAddContent">
301
302{if count($setup_errors) > 0}
303<div class="errors">
304  <ul>
305  {foreach from=$setup_errors item=error}
306    <li>{$error}</li>
307  {/foreach}
308  </ul>
309</div>
310{else}
311
312  {if count($setup_warnings) > 0}
313<div class="warnings">
314  <ul>
315    {foreach from=$setup_warnings item=warning}
316    <li>{$warning}</li>
317    {/foreach}
318  </ul>
319  <div class="hideButton" style="text-align:center"><a href="{$hide_warnings_link}">{'Hide'|@translate}</a></div>
320</div>
321  {/if}
322 
323{if !empty($thumbnails)}
324<fieldset>
325  <legend>{'Uploaded Photos'|@translate}</legend>
326  <div>
327  {foreach from=$thumbnails item=thumbnail}
328    <a href="{$thumbnail.link}" class="externalLink">
329      <img src="{$thumbnail.src}" alt="{$thumbnail.file}" title="{$thumbnail.title}" class="thumbnail">
330    </a>
331  {/foreach}
332  </div>
333  <p id="batchLink"><a href="{$batch_link}">{$batch_label}</a></p>
334</fieldset>
335<p style="margin:10px"><a href="{$another_upload_link}">{'Add another set of photos'|@translate}</a></p>
336{else}
337
338<div id="formErrors" class="errors" style="display:none">
339  <ul>
340    <li id="noAlbum">{'Select an album'|@translate}</li>
341    <li id="noPhoto">{'Select at least one photo'|@translate}</li>
342    <li id="urlEmpty">{'File URL is empty'|@translate}</li>
343    <li id="urlError">{'Invalid file URL'|@translate}</li>
344    <li id="typeError">{'Invalid file type'|@translate}</li>
345  </ul>
346  <div class="hideButton" style="text-align:center"><a href="#" id="hideErrors">{'Hide'|@translate}</a></div>
347</div>
348
349<form id="uploadForm" enctype="multipart/form-data" method="post" action="{$form_action}" class="properties">
350    <fieldset>
351      <legend>{'Drop into album'|@translate}</legend>
352
353      <span id="albumSelection"{if count($category_options) == 0} style="display:none"{/if}>
354      <select id="albumSelect" name="category">
355        {html_options options=$category_options selected=$category_options_selected}
356      </select>
357      <br>{'... or '|@translate}</span><a href="#" class="addAlbumOpen" title="{'create a new album'|@translate}">{'create a new album'|@translate}</a>
358     
359    </fieldset>
360
361    <fieldset>
362      <legend>{'Select files'|@translate}</legend>
363     
364      <p id="uploadWarningsSummary">
365        {'Allowed file types: %s.'|@translate|@sprintf:$upload_file_types}
366      {if isset($max_upload_resolution)}
367        {$max_upload_resolution}Mpx
368        <a class="showInfo" title="{'Learn more'|@translate}">i</a>
369      {/if}
370      </p>
371
372      <p id="uploadWarnings">
373        {'Allowed file types: %s.'|@translate|@sprintf:$upload_file_types}
374      {if isset($max_upload_resolution)}
375        {'Approximate maximum resolution: %dM pixels (that\'s %dx%d pixels).'|@translate|@sprintf:$max_upload_resolution:$max_upload_width:$max_upload_height}
376      {/if}
377      </p>
378
379{* <!-- SINGLE UPLOAD --> *}
380{if $upload_mode == 'single'}
381      <ul>
382        <li>
383          <label>
384            <span class="property">{'File URL'|@translate}</span>
385            <input type="text" name="file_url" size="70">
386          </label>
387        </li>
388        <li>
389          <label>
390            <span class="property">{'Photo name'|@translate}</span>
391            <input type="text" name="photo_name" size="40">
392          </label>
393        </li>
394      </ul>     
395     
396      <p id="uploadModeInfos">{'Want to upload many files? Try the <a href="%s">multiple uploader</a> instead.'|@translate|@sprintf:$switch_url}</p>
397
398{* <!-- MULTIPLE UPLOAD --> *}
399{else}
400
401      <table id="links" class="table2" style="display:none;">
402        <thead>
403          <tr class="throw">
404            <th style="width:150px;">{'Photo name'|@translate}</th>
405            <th>{'File URL'|@translate}</th>
406            <th style="width:150px;">{'Status'|@translate}</th>
407            <th style="width:20px;"></th>
408          </tr>
409        </thead>
410        <tbody>
411        </tbody>
412      </table>
413     
414      <p>
415        {'One link by line, separate photo name and url with a &laquo; | &raquo;. Photo name is optional.'|@translate}
416        <br>
417        <textarea id="urls"></textarea>
418      </p>
419      <input type="submit" name="add_links" value="{'Add links'|@translate}">
420     
421      <p id="uploadModeInfos">{'Multiple uploader doesn\'t work? Try the <a href="%s">single uploader</a> instead.'|@translate|@sprintf:$switch_url}</p>
422{/if}
423    </fieldset>
424
425    <p class="showFieldset"><a id="showPermissions" href="#">{'Manage Permissions'|@translate}</a></p>
426
427    <fieldset id="permissions" style="display:none">
428      <legend>{'Who can see these photos?'|@translate}</legend>
429
430      <select name="level" size="1">
431        {html_options options=$level_options selected=$level_options_selected}
432      </select>
433    </fieldset>
434   
435    <p>
436      <input class="submit" type="submit" name="submit_upload" value="{'Start Upload'|@translate}">
437    </p>
438</form>
439
440<div id="uploadProgress" style="display:none">
441{'Photo %s of %s'|@translate|@sprintf:'<span id="progressCurrent">1</span>':'<span id="progressMax">10</span>'}
442<br>
443<div id="progressbar"></div>
444</div>
445
446<fieldset style="display:none">
447  <legend>{'Uploaded Photos'|@translate}</legend>
448  <div id="uploadedPhotos"></div>
449</fieldset>
450
451{/if} {* empty($thumbnails) *}
452{/if} {* $setup_errors *}
453
454<br>
455</div> <!-- photosAddContent -->
Note: See TracBrowser for help on using the repository browser.