{if $upload_mode eq 'multiple'} {combine_script id='jquery.jgrowl' load='footer' require='jquery' path='themes/default/js/plugins/jquery.jgrowl_minimized.js' } {combine_script id='jquery.uploadify' load='footer' require='jquery' path='admin/include/uploadify/jquery.uploadify.v3.0.0.min.js' } {combine_script id='jquery.ui.progressbar' load='footer'} {combine_css path="admin/themes/default/uploadify.jGrowl.css"} {combine_css path="admin/include/uploadify/uploadify.css"} {/if} {combine_script id='jquery.colorbox' load='footer' require='jquery' path='themes/default/js/plugins/jquery.colorbox.min.js'} {combine_css path="themes/default/js/plugins/colorbox/style2/colorbox.css"} {footer_script}{literal} jQuery(document).ready(function(){ function sprintf() { var i = 0, a, f = arguments[i++], o = [], m, p, c, x, s = ''; while (f) { if (m = /^[^\x25]+/.exec(f)) { o.push(m[0]); } else if (m = /^\x25{2}/.exec(f)) { o.push('%'); } else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) { if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) { throw('Too few arguments.'); } if (/[^s]/.test(m[7]) && (typeof(a) != 'number')) { throw('Expecting number but found ' + typeof(a)); } switch (m[7]) { case 'b': a = a.toString(2); break; case 'c': a = String.fromCharCode(a); break; case 'd': a = parseInt(a); break; case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break; case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break; case 'o': a = a.toString(8); break; case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break; case 'u': a = Math.abs(a); break; case 'x': a = a.toString(16); break; case 'X': a = a.toString(16).toUpperCase(); break; } a = (/[def]/.test(m[7]) && m[2] && a >= 0 ? '+'+ a : a); c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' '; x = m[5] - String(a).length - s.length; p = m[5] ? str_repeat(c, x) : ''; o.push(s + (m[4] ? a + p : p + a)); } else { throw('Huh ?!'); } f = f.substring(m[0].length); } return o.join(''); } function checkUploadStart() { var nbErrors = 0; jQuery("#formErrors").hide(); jQuery("#formErrors li").hide(); if (jQuery("#albumSelect option:selected").length == 0) { jQuery("#formErrors #noAlbum").show(); nbErrors++; } var nbFiles = 0; if (jQuery("#uploadBoxes").size() == 1) { jQuery("input[name^=image_upload]").each(function() { if (jQuery(this).val() != "") { nbFiles++; } }); } else { nbFiles = jQuery(".uploadifyQueueItem").size(); } if (nbFiles == 0) { jQuery("#formErrors #noPhoto").show(); nbErrors++; } if (nbErrors != 0) { jQuery("#formErrors").show(); return false; } else { return true; } } function humanReadableFileSize(bytes) { var byteSize = Math.round(bytes / 1024 * 100) * .01; var suffix = 'KB'; if (byteSize > 1000) { byteSize = Math.round(byteSize *.001 * 100) * .01; suffix = 'MB'; } var sizeParts = byteSize.toString().split('.'); if (sizeParts.length > 1) { byteSize = sizeParts[0] + '.' + sizeParts[1].substr(0,2); } else { byteSize = sizeParts[0]; } return byteSize+suffix; } function fillCategoryListbox(selectId, selectedValue) { jQuery.getJSON( "ws.php?format=json&method=pwg.categories.getList", { recursive: true, fullname: true, format: "json", }, function(data) { jQuery.each( data.result.categories, function(i,category) { var selected = null; if (category.id == selectedValue) { selected = "selected"; } jQuery("") .attr("value", category.id) .attr("selected", selected) .text(category.name) .appendTo("#"+selectId) ; } ); } ); } jQuery(".addAlbumOpen").colorbox({ inline:true, href:"#addAlbumForm", onComplete:function(){ jQuery("input[name=category_name]").focus(); } }); jQuery("#addAlbumForm form").submit(function(){ jQuery("#categoryNameError").text(""); jQuery.ajax({ url: "ws.php?format=json&method=pwg.categories.add", data: { parent: jQuery("select[name=category_parent] option:selected").val(), name: jQuery("input[name=category_name]").val(), }, beforeSend: function() { jQuery("#albumCreationLoading").show(); }, success:function(html) { jQuery("#albumCreationLoading").hide(); var newAlbum = jQuery.parseJSON(html).result.id; jQuery(".addAlbumOpen").colorbox.close(); jQuery("#albumSelect").find("option").remove(); fillCategoryListbox("albumSelect", newAlbum); jQuery(".albumSelection").show(); /* we hide the ability to create another album, this is different from the admin upload form */ /* in Community, it's complicated to refresh the list of parent albums */ jQuery("#linkToCreate").hide(); return true; }, error:function(XMLHttpRequest, textStatus, errorThrows) { jQuery("#albumCreationLoading").hide(); jQuery("#categoryNameError").text(errorThrows).css("color", "red"); } }); return false; }); jQuery("#hideErrors").click(function() { jQuery("#formErrors").hide(); return false; }); jQuery("#uploadWarningsSummary a.showInfo").click(function() { jQuery("#uploadWarningsSummary").hide(); jQuery("#uploadWarnings").show(); }); jQuery("#showPermissions").click(function() { jQuery(this).parent(".showFieldset").hide(); jQuery("#permissions").show(); }); jQuery("#showPhotoProperties").click(function() { jQuery(this).parent(".showFieldset").hide(); jQuery("#photoProperties").show(); jQuery("input[name=set_photo_properties]").prop('checked', true); }); {/literal} {if $upload_mode eq 'html'} {if isset($limit_nb_photos)} var limit_nb_photos = {$limit_nb_photos}; {/if} {literal} function addUploadBox() { var uploadBox = '
'; jQuery(uploadBox).appendTo("#uploadBoxes"); if (typeof limit_nb_photos != 'undefined') { if (jQuery("input[name^=image_upload]").size() >= limit_nb_photos) { jQuery("#addUploadBox").hide(); } } } addUploadBox(); jQuery("#addUploadBox A").click(function () { if (typeof limit_nb_photos != 'undefined') { if (jQuery("input[name^=image_upload]").size() >= limit_nb_photos) { alert('tu rigoles mon gaillard !'); return false; } } addUploadBox(); }); jQuery("#uploadForm").submit(function() { return checkUploadStart(); }); {/literal} {elseif $upload_mode eq 'multiple'} var uploadify_path = '{$uploadify_path}'; var upload_id = '{$upload_id}'; var session_id = '{$session_id}'; var pwg_token = '{$pwg_token}'; var buttonText = "{'Select files'|@translate}"; var sizeLimit = Math.round({$upload_max_filesize} / 1024); /* in KBytes */ var sumQueueFilesize = 0; {if isset($limit_storage)} var limit_storage = {$limit_storage}; {/if} {literal} jQuery("#uploadify").uploadify({ 'uploader' : uploadify_path + '/uploadify.php', 'langFile' : uploadify_path + '/uploadifyLang_en.js', 'swf' : uploadify_path + '/uploadify.swf', buttonCursor : 'pointer', 'buttonText' : buttonText, 'width' : 300, 'cancelImage' : uploadify_path + '/cancel.png', 'queueID' : 'fileQueue', 'auto' : false, 'multi' : true, 'fileTypeDesc' : 'Photo files', 'fileTypeExts' : '*.jpg;*.JPG;*.jpeg;*.JPEG;*.png;*.PNG;*.gif;*.GIF', 'fileSizeLimit' : sizeLimit, 'progressData' : 'percentage', {/literal} {if isset($limit_nb_photos)} 'queueSizeLimit' : {$limit_nb_photos}, {/if} {literal} requeueErrors : false, 'onSelect' : function(file) { console.log('filesize = '+file.size+'bytes'); if (typeof limit_storage != 'undefined') { if (sumQueueFilesize + file.size > limit_storage) { jQuery.jGrowl( ''+sprintf( '{/literal}{'File %s too big (%uMB), quota of %uMB exceeded'|@translate}{literal}', file.name, Math.round(file.size/(1024*1024)), limit_storage/(1024*1024) ), { theme: 'error', header: 'ERROR', life: 4000, sticky: false } ); jQuery('#uploadify').uploadifyCancel(file.id); return false; } else { sumQueueFilesize += file.size; } } jQuery("#fileQueue").show(); }, 'onCancel' : function(file) { console.log('The file ' + file.name + ' was cancelled ('+file.size+')'); }, 'onQueueComplete' : function(stats) { jQuery("input[name=submit_upload]").click(); }, onUploadError: function (file,errorCode,errorMsg,errorString,swfuploadifyQueue) { /* uploadify calls the onUploadError trigger when the user cancels a file! */ /* There no error so we skip it to avoid panic. */ if ("Cancelled" == errorString) { return false; } var msg = file.name+', '+errorString; /* Let's put the error message in the form to display once the form is */ /* performed, it makes support easier when user can copy/paste the error */ /* thrown. */ jQuery("#uploadForm").append(''); jQuery.jGrowl( 'onUploadError '+msg, { theme: 'error', header: 'ERROR', life: 4000, sticky: false } ); return false; }, onUploadSuccess: function (file,data,response) { var data = jQuery.parseJSON(data); jQuery("#uploadedPhotos").parent("fieldset").show(); /* Let's display the thumbnail of the uploaded photo, no need to wait the */ /* end of the queue */ jQuery("#uploadedPhotos").prepend(' '); }, onUploadComplete: function(file,swfuploadifyQueue) { var max = parseInt(jQuery("#progressMax").text()); var next = parseInt(jQuery("#progressCurrent").text())+1; var addToProgressBar = 2; if (next <= max) { jQuery("#progressCurrent").text(next); } else { addToProgressBar = 1; } jQuery("#progressbar").progressbar({ value: jQuery("#progressbar").progressbar("option", "value") + addToProgressBar }); } }); jQuery("input[type=button]").click(function() { if (!checkUploadStart()) { return false; } jQuery("#uploadify").uploadifySettings( 'postData', { 'category_id' : jQuery("select[name=category] option:selected").val(), 'level' : jQuery("select[name=level] option:selected").val(), 'upload_id' : upload_id, 'session_id' : session_id, 'pwg_token' : pwg_token, } ); nb_files = jQuery(".uploadifyQueueItem").size(); jQuery("#progressMax").text(nb_files); jQuery("#progressbar").progressbar({max: nb_files*2, value:1}); jQuery("#progressCurrent").text(1); jQuery("#uploadProgress").show(); jQuery("#uploadify").uploadifyUpload(); }); {/literal} {/if} }); {/footer_script} {literal} {/literal}