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

Last change on this file since 29356 was 29356, checked in by plg, 10 years ago

bug 3127: during upload, warn user if she wants to leave the page (works fine on Firefox/Chrome)

File size: 9.3 KB
Line 
1{combine_script id='common' load='footer' path='admin/themes/default/js/common.js'}
2{combine_script id='jquery.jgrowl' load='footer' require='jquery' path='themes/default/js/plugins/jquery.jgrowl_minimized.js'}
3{combine_script id='jquery.plupload' load='footer' require='jquery' path='themes/default/js/plugins/plupload/plupload.full.min.js'}
4{combine_script id='jquery.plupload.queue' load='footer' require='jquery' path='themes/default/js/plugins/plupload/jquery.plupload.queue/jquery.plupload.queue.min.js'}
5{combine_script id='jquery.ui.progressbar' load='footer'}
6
7{combine_css path="themes/default/js/plugins/jquery.jgrowl.css"}
8{combine_css path="themes/default/js/plugins/plupload/jquery.plupload.queue/css/jquery.plupload.queue.css"}
9
10{assign var="plupload_i18n" value="themes/default/js/plugins/plupload/i18n/`$lang_info.plupload_code`.js"}
11{if "PHPWG_ROOT_PATH"|@constant|@cat:$plupload_i18n|@file_exists}
12  {combine_script id="plupload_i18n-`$lang_info.plupload_code`" load="footer" path=$plupload_i18n require="jquery.plupload.queue"}
13{/if}
14
15{include file='include/colorbox.inc.tpl'}
16{include file='include/add_album.inc.tpl'}
17
18{combine_script id='LocalStorageCache' load='footer' path='admin/themes/default/js/LocalStorageCache.js'}
19
20{assign var="selectizeTheme" value=($themeconf.name=='roma')|ternary:'dark':'default'}
21{combine_script id='jquery.selectize' load='footer' path='themes/default/js/plugins/selectize.min.js'}
22{combine_css id='jquery.selectize' path="themes/default/js/plugins/selectize.`$selectizeTheme`.css"}
23
24{footer_script}
25{* <!-- CATEGORIES --> *}
26var categoriesCache = new CategoriesCache({
27  serverKey: '{$CACHE_KEYS.categories}',
28  serverId: '{$CACHE_KEYS._hash}',
29  rootUrl: '{$ROOT_URL}'
30});
31
32categoriesCache.selectize(jQuery('[data-selectize=categories]'), {
33  filter: function(categories, options) {
34    if (categories.length > 0) {
35      jQuery("#albumSelection, .selectFiles, .showFieldset").show();
36    }
37   
38    return categories;
39  }
40});
41
42jQuery('[data-add-album]').pwgAddAlbum({ cache: categoriesCache });
43
44var pwg_token = '{$pwg_token}';
45var photosUploaded_label = "{'%d photos uploaded'|translate}";
46var batch_Label = "{'Manage this set of %d photos'|translate}";
47var albumSummary_label = "{'Album "%s" now contains %d photos'|translate|escape}";
48var uploadedPhotos = [];
49var uploadCategory = null;
50
51{literal}
52jQuery(document).ready(function(){
53  jQuery("#uploadWarningsSummary a.showInfo").click(function() {
54    jQuery("#uploadWarningsSummary").hide();
55    jQuery("#uploadWarnings").show();
56    return false;
57  });
58
59  jQuery("#showPermissions").click(function() {
60    jQuery(this).parent(".showFieldset").hide();
61    jQuery("#permissions").show();
62    return false;
63  });
64
65        jQuery("#uploader").pluploadQueue({
66                // General settings
67                // runtimes : 'html5,flash,silverlight,html4',
68                runtimes : 'html5',
69
70                // url : '../upload.php',
71                url : 'ws.php?method=pwg.images.upload&format=json',
72
73                // User can upload no more then 20 files in one go (sets multiple_queues to false)
74                max_file_count: 100,
75               
76                chunk_size: '500kb',
77               
78                filters : {
79                        // Maximum file size
80                        max_file_size : '1000mb',
81                        // Specify what files to browse for
82                        mime_types: [
83                                {title : "Image files", extensions : "{/literal}{$file_exts}{literal}"}
84                        ]
85                },
86
87                // Rename files by clicking on their titles
88                // rename: true,
89               
90                // Sort files
91                sortable: true,
92
93                // Enable ability to drag'n'drop files onto the widget (currently only HTML5 supports that)
94                dragdrop: true,
95
96    preinit: {
97      Init: function (up, info) {
98        jQuery('#uploader_container').removeAttr("title"); //remove the "using runtime" text
99      }
100    },
101
102    init : {
103      BeforeUpload: function(up, file) {
104        console.log('[BeforeUpload]', file);
105
106        // warn user if she wants to leave page while upload is running
107        jQuery(window).bind('beforeunload', function() {
108          return "{/literal}{'Upload in progress'|translate|escape}{literal}";
109        });
110
111        // no more change on category/level
112        jQuery("select[name=level]").attr("disabled", "disabled");
113
114        // You can override settings before the file is uploaded
115        // up.setOption('url', 'upload.php?id=' + file.id);
116        up.setOption(
117          'multipart_params',
118          {
119            category : jQuery("select[name=category] option:selected").val(),
120            level : jQuery("select[name=level] option:selected").val(),
121            pwg_token : pwg_token
122            // name : file.name
123          }
124        );
125      },
126
127      FileUploaded: function(up, file, info) {
128        // Called when file has finished uploading
129        console.log('[FileUploaded] File:', file, "Info:", info);
130     
131        var data = jQuery.parseJSON(info.response);
132     
133        jQuery("#uploadedPhotos").parent("fieldset").show();
134     
135        html = '<a href="admin.php?page=photo-'+data.result.image_id+'" target="_blank">';
136        html += '<img src="'+data.result.src+'" class="thumbnail" title="'+data.result.name+'">';
137        html += '</a> ';
138     
139        jQuery("#uploadedPhotos").prepend(html);
140
141        // do not remove file, or it will reset the progress bar :-/
142        // up.removeFile(file);
143        uploadedPhotos.push(parseInt(data.result.image_id));
144        uploadCategory = data.result.category;
145      },
146
147      UploadComplete: function(up, files) {
148        // Called when all files are either uploaded or failed
149        console.log('[UploadComplete]');
150
151        jQuery(".selectAlbum, .selectFiles, #permissions, .showFieldset").hide();
152
153        jQuery(".infos").append('<ul><li>'+sprintf(photosUploaded_label, uploadedPhotos.length)+'</li></ul>');
154
155        html = sprintf(
156          albumSummary_label,
157          '<a href="admin.php?page=album-'+uploadCategory.id+'">'+uploadCategory.label+'</a>',
158          parseInt(uploadCategory.nb_photos)
159        );
160
161        jQuery(".infos ul").append('<li>'+html+'</li>');
162
163        jQuery(".infos").show();
164
165        // TODO: use a new method pwg.caddie.empty +
166        // pwg.caddie.add(uploadedPhotos) instead of relying on huge GET parameter
167        // (and remove useless code from admin/photos_add_direct.php)
168
169        jQuery(".batchLink").attr("href", "admin.php?page=photos_add&section=direct&batch="+uploadedPhotos.join(","));
170        jQuery(".batchLink").html(sprintf(batch_Label, uploadedPhotos.length));
171
172        jQuery(".afterUploadActions").show();
173
174        // user can safely leave page without warning
175        jQuery(window).unbind('beforeunload');
176      }
177    }
178        });
179{/literal}
180});
181{/footer_script}
182
183<div class="titrePage">
184  <h2>{'Upload Photos'|@translate} {$TABSHEET_TITLE}</h2>
185</div>
186
187<div id="photosAddContent">
188
189<div class="infos" style="display:none"></div>
190
191<p class="afterUploadActions" style="margin:10px; display:none;"><a class="batchLink"></a> | <a href="">{'Add another set of photos'|@translate}</a></p>
192
193{if count($setup_errors) > 0}
194<div class="errors">
195  <ul>
196  {foreach from=$setup_errors item=error}
197    <li>{$error}</li>
198  {/foreach}
199  </ul>
200</div>
201{else}
202
203  {if count($setup_warnings) > 0}
204<div class="warnings">
205  <ul>
206    {foreach from=$setup_warnings item=warning}
207    <li>{$warning}</li>
208    {/foreach}
209  </ul>
210  <div class="hideButton" style="text-align:center"><a href="{$hide_warnings_link}">{'Hide'|@translate}</a></div>
211</div>
212  {/if}
213
214
215<form id="uploadForm" enctype="multipart/form-data" method="post" action="{$form_action}">
216    <fieldset class="selectAlbum">
217      <legend>{'Drop into album'|@translate}</legend>
218
219      <span id="albumSelection" style="display:none">
220      <select data-selectize="categories" data-value="{$selected_category|@json_encode|escape:html}"
221        data-default="first" name="category" style="width:400px"></select>
222      <br>{'... or '|@translate}</span>
223      <a href="#" data-add-album="category" title="{'create a new album'|@translate}">{'create a new album'|@translate}</a>
224    </fieldset>
225
226    <p class="showFieldset" style="display:none"><a id="showPermissions" href="#">{'Manage Permissions'|@translate}</a></p>
227
228    <fieldset id="permissions" style="display:none">
229      <legend>{'Who can see these photos?'|@translate}</legend>
230
231      <select name="level" size="1">
232        {html_options options=$level_options selected=$level_options_selected}
233      </select>
234    </fieldset>
235
236    <fieldset class="selectFiles" style="display:none">
237      <legend>{'Select files'|@translate}</legend>
238 
239    {if isset($original_resize_maxheight)}<p class="uploadInfo">{'The picture dimensions will be reduced to %dx%d pixels.'|@translate:$original_resize_maxwidth:$original_resize_maxheight}</p>{/if}
240
241    <p id="uploadWarningsSummary">{$upload_max_filesize_shorthand}B. {$upload_file_types}. {if isset($max_upload_resolution)}{$max_upload_resolution}Mpx{/if} <a class="icon-info-circled-1 showInfo" title="{'Learn more'|@translate}"></a></p>
242
243    <p id="uploadWarnings">
244{'Maximum file size: %sB.'|@translate:$upload_max_filesize_shorthand}
245{'Allowed file types: %s.'|@translate:$upload_file_types}
246  {if isset($max_upload_resolution)}
247{'Approximate maximum resolution: %dM pixels (that\'s %dx%d pixels).'|@translate:$max_upload_resolution:$max_upload_width:$max_upload_height}
248  {/if}
249    </p>
250
251
252        <div id="uploader">
253                <p>Your browser doesn't have HTML5 support.</p>
254        </div>
255
256    </fieldset>
257
258</form>
259
260<fieldset style="display:none">
261  <legend>{'Uploaded Photos'|@translate}</legend>
262  <div id="uploadedPhotos"></div>
263</fieldset>
264
265{/if} {* $setup_errors *}
266
267</div> <!-- photosAddContent -->
Note: See TracBrowser for help on using the repository browser.