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

Revision 28554, 8.5 KB checked in by plg, 5 years ago (diff)

feature 2616: better behavior at the end of upload (more like with uploadify, but no page reload)

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