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

Last change on this file since 26387 was 26387, checked in by mistic100, 10 years ago

update for 2.6

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