Ignore:
Timestamp:
May 27, 2014, 4:11:23 PM (10 years ago)
Author:
plg
Message:

feature 2616: HTML5 upload (with plupload 2.1.2). First basic implementation. Needs customization.

Chunked upload + Drag & drop (no more Flash)

use a new specific API method pwg.images.upload

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/themes/default/template/photos_add_direct.tpl

    r28542 r28545  
    1 {if $upload_mode eq 'multiple'}
    2 {combine_script id='jquery.jgrowl' load='footer' require='jquery' path='themes/default/js/plugins/jquery.jgrowl_minimized.js' }
    3 {combine_script id='jquery.uploadify' load='footer' require='jquery' path='admin/include/uploadify/jquery.uploadify.v3.0.0.min.js' }
     1{combine_script id='jquery.jgrowl' load='footer' require='jquery' path='themes/default/js/plugins/jquery.jgrowl_minimized.js'}
     2{combine_script id='jquery.plupload' load='footer' require='jquery' path='themes/default/js/plugins/plupload/plupload.full.min.js'}
     3{combine_script id='jquery.plupload.queue' load='footer' require='jquery' path='themes/default/js/plugins/plupload/jquery.plupload.queue/jquery.plupload.queue.min.js'}
    44{combine_script id='jquery.ui.progressbar' load='footer'}
     5
    56{combine_css path="themes/default/js/plugins/jquery.jgrowl.css"}
    6 {combine_css path="admin/include/uploadify/uploadify.css"}
    7 {/if}
     7{combine_css path="themes/default/js/plugins/plupload/jquery.plupload.queue/css/jquery.plupload.queue.css"}
    88
    99{include file='include/colorbox.inc.tpl'}
     
    3636jQuery('[data-add-album]').pwgAddAlbum({ cache: categoriesCache });
    3737
     38var uploadify_path = '{$uploadify_path}';
     39var upload_id = '{$upload_id}';
     40var session_id = '{$session_id}';
     41var pwg_token = '{$pwg_token}';
     42var buttonText = "{'Select files'|@translate}";
     43var sizeLimit = Math.round({$upload_max_filesize} / 1024); /* in KBytes */
    3844
    3945{literal}
     
    113119  });
    114120
     121        jQuery("#uploader").pluploadQueue({
     122                // General settings
     123                // runtimes : 'html5,flash,silverlight,html4',
     124                runtimes : 'html5',
     125
     126                // url : '../upload.php',
     127                url : 'ws.php?method=pwg.images.upload&format=json',
     128
     129                // User can upload no more then 20 files in one go (sets multiple_queues to false)
     130                max_file_count: 100,
     131               
     132                chunk_size: '500kb',
     133               
     134                filters : {
     135                        // Maximum file size
     136                        max_file_size : '1000mb',
     137                        // Specify what files to browse for
     138                        mime_types: [
     139                                {title : "Image files", extensions : "jpeg,jpg,gif,png"},
     140                                {title : "Zip files", extensions : "zip"}
     141                        ]
     142                },
     143
     144                // Rename files by clicking on their titles
     145                // rename: true,
     146               
     147                // Sort files
     148                sortable: true,
     149
     150                // Enable ability to drag'n'drop files onto the widget (currently only HTML5 supports that)
     151                dragdrop: true,
     152
     153    init : {
     154      BeforeUpload: function(up, file) {
     155        console.log('[BeforeUpload]', file);
     156
     157        // You can override settings before the file is uploaded
     158        // up.setOption('url', 'upload.php?id=' + file.id);
     159        up.setOption(
     160          'multipart_params',
     161          {
     162            category : jQuery("select[name=category] option:selected").val(),
     163            level : jQuery("select[name=level] option:selected").val(),
     164            pwg_token : pwg_token
     165            // name : file.name
     166          }
     167        );
     168      },
     169
     170      FileUploaded: function(up, file, info) {
     171        // Called when file has finished uploading
     172        console.log('[FileUploaded] File:', file, "Info:", info);
     173     
     174        var data = jQuery.parseJSON(info.response);
     175     
     176        jQuery("#uploadedPhotos").parent("fieldset").show();
     177     
     178        html = '<a href="admin.php?page=photo-'+data.result.image_id+'" target="_blank">';
     179        html += '<img src="'+data.result.src+'" class="thumbnail">';
     180        html += '</a> ';
     181     
     182        jQuery("#uploadedPhotos").prepend(html);
     183      }
     184    }
     185        });
     186
    115187{/literal}
    116 {if $upload_mode eq 'html'}
    117 {literal}
    118   function addUploadBox() {
    119     var uploadBox = '<p class="file"><input type="file" size="60" name="image_upload[]"></p>';
    120     jQuery(uploadBox).appendTo("#uploadBoxes");
    121   }
    122 
    123   addUploadBox();
    124 
    125   jQuery("#addUploadBox A").click(function () {
    126     addUploadBox();
    127   });
    128 
    129   jQuery("#uploadForm").submit(function() {
    130     return checkUploadStart();
    131   });
    132 {/literal}
    133 {elseif $upload_mode eq 'multiple'}
    134 
    135 var uploadify_path = '{$uploadify_path}';
    136 var upload_id = '{$upload_id}';
    137 var session_id = '{$session_id}';
    138 var pwg_token = '{$pwg_token}';
    139 var buttonText = "{'Select files'|@translate}";
    140 var sizeLimit = Math.round({$upload_max_filesize} / 1024); /* in KBytes */
    141 
    142 {literal}
    143   jQuery("#uploadify").uploadify({
    144     'uploader'       : uploadify_path + '/uploadify.php',
    145     'langFile'       : uploadify_path + '/uploadifyLang_en.js',
    146     'swf'            : uploadify_path + '/uploadify.swf',
    147     'checkExisting'  : false,
    148 
    149     buttonCursor     : 'pointer',
    150     'buttonText'     : buttonText,
    151     'width'          : 300,
    152     'cancelImage'    : uploadify_path + '/cancel.png',
    153     'queueID'        : 'fileQueue',
    154     'auto'           : false,
    155     'multi'          : true,
    156     'fileTypeDesc'   : 'Photo files',
    157     'fileTypeExts'   : '*.jpg;*.JPG;*.jpeg;*.JPEG;*.png;*.PNG;*.gif;*.GIF;{/literal}{if $tif_enabled}*.tif;*.TIF;*.tiff;*.TIFF{/if}{literal}',
    158     'fileSizeLimit'  : sizeLimit,
    159     'progressData'   : 'percentage',
    160     requeueErrors   : false,
    161     'onSelect'       : function(event,ID,fileObj) {
    162       jQuery("#fileQueue").show();
    163     },
    164     'onQueueComplete'  : function(stats) {
    165       jQuery("input[name=submit_upload]").click();
    166     },
    167     onUploadError: function (file,errorCode,errorMsg,errorString,swfuploadifyQueue) {
    168       /* uploadify calls the onUploadError trigger when the user cancels a file! */
    169       /* There no error so we skip it to avoid panic.                            */
    170       if ("Cancelled" == errorString) {
    171         return false;
    172       }
    173 
    174       var msg = file.name+', '+errorString;
    175 
    176       /* Let's put the error message in the form to display once the form is     */
    177       /* performed, it makes support easier when user can copy/paste the error   */
    178       /* thrown.                                                                 */
    179       jQuery("#uploadForm").append('<input type="hidden" name="onUploadError[]" value="'+msg+'">');
    180 
    181       jQuery.jGrowl(
    182         '<p></p>onUploadError '+msg,
    183         {
    184           theme:  'error',
    185           header: 'ERROR',
    186           life:   4000,
    187           sticky: false
    188         }
    189       );
    190 
    191       return false;
    192     },
    193     onUploadSuccess: function (file,data,response) {
    194       var data = jQuery.parseJSON(data);
    195       jQuery("#uploadedPhotos").parent("fieldset").show();
    196 
    197       /* Let's display the thumbnail of the uploaded photo, no need to wait the  */
    198       /* end of the queue                                                        */
    199       jQuery("#uploadedPhotos").prepend('<img src="'+data.thumbnail_url+'" class="thumbnail"> ');
    200     },
    201     onUploadComplete: function(file,swfuploadifyQueue) {
    202       var max = parseInt(jQuery("#progressMax").text());
    203       var next = parseInt(jQuery("#progressCurrent").text())+1;
    204       var addToProgressBar = 2;
    205       if (next <= max) {
    206         jQuery("#progressCurrent").text(next);
    207       }
    208       else {
    209         addToProgressBar = 1;
    210       }
    211 
    212       jQuery("#progressbar").progressbar({
    213         value: jQuery("#progressbar").progressbar("option", "value") + addToProgressBar
    214       });
    215     }
    216   });
    217 
    218   jQuery("input[type=button]").click(function() {
    219     if (!checkUploadStart()) {
    220       return false;
    221     }
    222 
    223     jQuery("#uploadify").uploadifySettings(
    224       'postData',
    225       {
    226         'category_id' : jQuery("select[name=category]").val(),
    227         'level' : jQuery("select[name=level] option:selected").val(),
    228         'upload_id' : upload_id,
    229         'session_id' : session_id,
    230         'pwg_token' : pwg_token
    231       }
    232     );
    233 
    234     nb_files = jQuery(".uploadifyQueueItem").size();
    235     jQuery("#progressMax").text(nb_files);
    236     jQuery("#progressbar").progressbar({max: nb_files*2, value:1});
    237     jQuery("#progressCurrent").text(1);
    238 
    239     jQuery("#uploadProgress").show();
    240 
    241     jQuery("#uploadify").uploadifyUpload();
    242   });
    243 
    244 {/literal}
    245 {/if}
    246188});
    247189{/footer_script}
     
    314256    </fieldset>
    315257
     258    <p class="showFieldset"><a id="showPermissions" href="#">{'Manage Permissions'|@translate}</a></p>
     259
     260    <fieldset id="permissions" style="display:none">
     261      <legend>{'Who can see these photos?'|@translate}</legend>
     262
     263      <select name="level" size="1">
     264        {html_options options=$level_options selected=$level_options_selected}
     265      </select>
     266    </fieldset>
     267
    316268    <fieldset>
    317269      <legend>{'Select files'|@translate}</legend>
     
    330282
    331283
    332 
    333 {if $upload_mode eq 'html'}
    334       <div id="uploadBoxes"></div>
    335       <div id="addUploadBox">
    336         <a href="javascript:">{'+ Add an upload box'|@translate}</a>
    337       </div>
    338 
    339     <p id="uploadModeInfos">{'You are using the Browser uploader. Try the <a href="%s">Flash uploader</a> instead.'|@translate:$switch_url}</p>
    340 
    341 {elseif $upload_mode eq 'multiple'}
    342     <div id="uploadify">You've got a problem with your JavaScript</div>
    343 
    344     <div id="fileQueue" style="display:none"></div>
    345 
    346     <p id="uploadModeInfos">{'You are using the Flash uploader. Problems? Try the <a href="%s">Browser uploader</a> instead.'|@translate:$switch_url}</p>
    347 
    348 {/if}
     284        <div id="uploader">
     285                <p>Your browser doesn't have Flash, Silverlight or HTML5 support.</p>
     286        </div>
     287
    349288    </fieldset>
    350289
    351     <p class="showFieldset"><a id="showPermissions" href="#">{'Manage Permissions'|@translate}</a></p>
    352 
    353     <fieldset id="permissions" style="display:none">
    354       <legend>{'Who can see these photos?'|@translate}</legend>
    355 
    356       <select name="level" size="1">
    357         {html_options options=$level_options selected=$level_options_selected}
    358       </select>
    359     </fieldset>
    360 
    361 {if $upload_mode eq 'html'}
    362     <p>
    363       <input class="submit" type="submit" name="submit_upload" value="{'Start Upload'|@translate}">
    364     </p>
    365 {elseif $upload_mode eq 'multiple'}
    366     <p style="margin-bottom:1em">
    367       <input class="submit" type="button" value="{'Start Upload'|@translate}">
    368       <input type="submit" name="submit_upload" style="display:none">
    369     </p>
    370 {/if}
    371290</form>
    372291
Note: See TracChangeset for help on using the changeset viewer.