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

Last change on this file since 19804 was 19804, checked in by mistic100, 8 years ago

add plugin URL Uploader

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