File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/javascript/admin.imagemanager.js
var imageManager = {
imageRow: '',
maxFileSize: '',
phpSessionId: '',
originalTextValue: '',
flashUploadObject: {},
fileCount: 1,
requiredFlashMajorVersion: 8,
requiredFlashMinorVersion: 0,
requiredFlashRevision: 0,
totalItemsToUpload: 0,
noflashTotalUploads: 0,
percentIncrementNonFlash: 0,
totalPercentNonFlash: 0,
totalFieldsNonFlash: 0,
currentFieldNonFlash: 0,
uploadErrorFiles: [],
uploadDuplicateFiles: [],
/**
* Flash object related functions
*/
hasRequestedFlashVersion: function(){
return DetectFlashVer(imageManager.requiredFlashMajorVersion, imageManager.requiredFlashMinorVersion, imageManager.requiredFlashRevision);
},
loadFlashObject : function () {
imageManager.flashUploadObject = new SWFUpload({
// Backend Settings
upload_url: iwp.config.get('appPath') + iwp.config.get('adminPath') + "/remote.php?section=imagemanager&action=upload", // Relative to the SWF file or absolute
// File Upload Settings
file_size_limit : "2 MB", // 2MB
file_types : "*.jpg;*.gif;*.png;*.tiff,*.bmp,*.jpeg",
post_params : {"PHPSESSID": imageManager.phpSessionId},
file_types_description : " Images",
file_upload_limit : "0",
// Event Handler Settings
file_queue_error_handler : imageManager.fileQueueError,
file_dialog_complete_handler : imageManager.fileDialogComplete,
upload_progress_handler : imageManager.uploadProgress,
upload_error_handler : imageManager.uploadError,
upload_success_handler : imageManager.uploadSuccess,
upload_complete_handler : imageManager.uploadComplete,
// Button Settings
button_placeholder_id : "spanButtonPlaceholder",
button_width: 130,
button_height: 22,
button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
button_cursor: SWFUpload.CURSOR.HAND,
// Flash Settings
flash_url : iwp.config.get('appPath') + iwp.config.get('adminPath') + "/images/swfupload.swf",
custom_settings : {
upload_target : "divFileProgressContainer"
},
// Debug Settings
debug: false
});
},
/**
* Helper functions
*/
removeExtension: function (name){
var varFile = name.split('.');
var userFriendlyName = '';
for(i in varFile) {
if(i == (varFile.length - 1)){
break;
}
userFriendlyName += varFile[i];
}
return userFriendlyName;
},
checkDelete: function() {
if (!$('#imagesList .ManageImageBox').exists()) {
$('#hasImages').hide();
$('#hasNoImages').show();
$('#deleteButton').hide();
} else {
$('#hasImages').show();
$('#hasNoImages').hide();
$('#deleteButton').show();
}
},
checkAllCheckBoxes: function(checkBox){
if($('#toggleAllChecks').attr('checked')){
$('#imagesList input:checkbox').attr('checked', 'checked');
}else{
$('#imagesList input:checkbox').removeAttr('checked');
}
},
addImage: function(name, url, size, displaywidth, displayheight, dimensions, id){
$('#hasImages').show();
$('#hasNoImages').hide();
$('#deleteButton').show();
var html = imageManager.imageRow;
var varFile = name.split('.');
var extension = varFile[ varFile.length -1 ];
var userFriendlyName = '';
for(i in varFile) {
if(i == (varFile.length - 1)){
break;
}
userFriendlyName += varFile[i];
}
html = html.replace(/%%image_name%%/g, userFriendlyName);
html = html.replace(/%%image_realname%%/g, name);
html = html.replace(/%%image_id%%/g, id);
html = html.replace(/%%image_url%%/g, url);
html = html.replace(/%%image_size%%/g, size);
html = html.replace(/%%image_width%%/g, displaywidth);
html = html.replace(/%%image_height%%/g, displayheight);
html = html.replace(/%%image_dimensions%%/g, dimensions);
$(html).appendTo('#imagesList');
$('#'+id+'_delete').bind('click',
function () {
var idBits = this.id.split('_');
var id = idBits[0];
var confirmMessage = iwp.lang.get('imageManagerDeleteImageSpecific').replace('%s', $('#'+id+'_name').val());
if (confirm(confirmMessage)) {
var sendPOST = '';
sendPOST = 'deleteimages[]=' + $('#'+id+'_realname').val();
$.post('remote.php?section=imagemanager&action=delete', sendPOST,
function(result){
if(result.success){
for(i in result.successimages) {
var imageName = result.successimages[i];
imageName = imageManager.removeExtension(imageName);
$('input:checkbox[value=' + imageName + ']').removeAttr('checked');
$('input:text[value=' + imageName + ']').parent().hide('slow');
$('input:text[value=' + imageName + ']').parent().remove();
}
$('#MainMessage').successMessage(result.message);
imageManager.checkDelete();
}else{
$('#MainMessage').errorMessage(result.message);
}
}, 'json');
}
}
);
$('#'+id+'_name').bind('mouseover',
function () {
if(!$(this).hasClass("inPlaceFieldFocus")) {
$(this).addClass("inPlaceImageBoxFieldHover");
}
}
);
$('#'+id+'_name').bind('mouseout',
function () {
$(this).removeClass("inPlaceImageBoxFieldHover");
}
);
$('#'+id+'_name').bind('keypress', function(e) {
if (e.which == 32 // space
|| (48 <= e.which && e.which <= 57) // numbers
|| (65 <= e.which && e.which <= 90) // lowercase latin letters
|| (97 <= e.which && e.which <= 122) // uppercase latin letters
|| e.which == 95 // underscore
|| e.which == 46 // period
|| e.which == 13 // enter
) {
// no problem
} else {
e.preventDefault();
}
});
$('#'+id+'_name').bind('focus',
function () {
$('.inPlaceFieldFocus').each(function(){
imageManager.cancelEditName($(this));
$(this).removeClass('inPlaceFieldFocus');
});
$(this).removeClass("inPlaceImageBoxFieldHover");
$(this).addClass("inPlaceFieldFocus");
imageManager.originalTextValue = this.value;
this.select();
$('<div style="background-color: #F9F9F9; width: 205px; position: absolute; padding: 5px; top: 30px; left: 2px;" id="EditNameButtons"><input type="button" class="Button" name="saveEdit" value="' + iwp.lang.get('SaveOnly') + '" style="float: right;" onclick="imageManager.saveEditName($(\'#' + this.id + '\'));" /><input type="button" class="Button" name="cancelEdit" value="' + iwp.lang.get('Cancel') + '" style="float: left;" onclick="imageManager.cancelEditName($(\'#' + this.id + '\'));" /> </div>').insertAfter(this);
}
);
if ($.browser.mozilla) {
var event = "keypress";
} else {
var event = "keydown";
}
$('#'+id+'_name').bind(event, function(e) {
if (e.keyCode == 13) {
$('#'+id+'_name').blur();
}
});
},
uploadNonFlashImages: function() {
imageManager.totalItemsToUpload = 0;
imageManager.uploadErrorFiles = new Array();
imageManager.uploadDuplicateFiles = new Array();
imageManager.fileCount = 0;
$('#uploadFormNoFlash').hide();
$('#noFlashProgressWindow').show();
imageManager.noflashTotalUploads = $('.noflashUploadField').size() -2 ; //remove the blank field from the count
imageManager.percentIncrementNonFlash = parseInt((100 / imageManager.noflashTotalUploads));
imageManager.totalPercentNonFlash = 0;
imageManager.totalFieldsNonFlash = $('.noflashUploadField').size()-2;
imageManager.currentFieldNonFlash = 0;
imageManager.runNextUploadNonFlash();
},
runNextUploadNonFlash: function(){
var tmpCounter = 0;
$('.noflashUploadField').each(function() {
if($(this).val() == '') {
return true;
}
if(tmpCounter != imageManager.currentFieldNonFlash){
if(tmpCounter > imageManager.totalFieldsNonFlash){
return false;
}
tmpCounter++;
return true;
}
var thisId = $(this).attr('id');
$.ajaxFileUpload ({
url: 'remote.php?section=imagemanager&action=upload&unique=' + iwp.util.randomString(10),
secureuri: false,
fileElementId: thisId,
dataType: 'json',
beforeSend: function (){
var name = $('#' + this.fileElementId).val().replace(/\\/g, '/');
name = name.split('/');
var pos = name.length;
var fileName = name[pos-1];
$('.progressBarStatus').html(iwp.lang.get('imUploadingxImageOf').replace('{totalimages}', imageManager.noflashTotalUploads).replace('{imagenumber}', imageManager.fileCount));
$('.ProgressBarText').html(' ' + fileName + '...');
},
success: function (result)
{
imageManager.totalPercentNonFlash = imageManager.totalPercentNonFlash + imageManager.percentIncrementNonFlash;
$('.progressBarPercentage').css('width', imageManager.totalPercentNonFlash + "%");
$('.progressPercent').html(imageManager.totalPercentNonFlash + "%");
imageManager.fileCount++;
if(result.Filedata.duplicate){
imageManager.uploadDuplicateFiles.push(result.Filedata.name);
}else if(result.Filedata.errorfile != ''){
imageManager.uploadErrorFiles.push(result.Filedata.name);
}else if(result.Filedata.error == 0){
// success!
imageManager.addImage(result.Filedata.name, '../images/' + result.Filedata.name, result.Filedata.filesize, result.Filedata.width, result.Filedata.height, result.Filedata.origwidth + ' x ' + result.Filedata.origheight, result.Filedata.id);
}
imageManager.currentFieldNonFlash++;
if(imageManager.currentFieldNonFlash > imageManager.totalFieldsNonFlash){
imageManager.uploadNonFlashFinished();
}else{
imageManager.runNextUploadNonFlash();
}
}
});
return false;
});
},
uploadNonFlashFinished: function(){
$.iModal.close();
var imageList = '',
thisImage = '';
if(imageManager.uploadErrorFiles.length > 0){
for(i in imageManager.uploadErrorFiles){
thisImage = imageManager.uploadErrorFiles[i];
imageList += '<li>' + $('<p>' + thisImage + '</p>').text() + '</li>'; // strips out any html
}
if(imageManager.uploadErrorFiles.length == imageManager.totalItemsToUpload){
$('#MainMessage').errorMessage(iwp.lang.get('imageManagerFilesNotValid') + ' <ul>' + imageList + '</ul>');
}else{
$('#MainMessage').warningMessage(iwp.lang.get('imageManagerFilesNotValidSomeSuccess') + '<ul>' + imageList + '</ul>');
}
}else if(imageManager.uploadDuplicateFiles.length > 0){
for(i in imageManager.uploadDuplicateFiles){
thisImage = imageManager.uploadDuplicateFiles[i];
imageList += '<li>' + $('<p>' + thisImage + '</p>').text() + '</li>'; // strips out any html
}
$('#MainMessage').warningMessage(iwp.lang.get("imageManagerFilesDuplicates") + '<ul>' + imageList + '</ul>');
}else{
// The 4 selected images have been uploaded and are shown below
// The selected image has been uploaded and is shown below.
if(imageManager.fileCount == 1){
$('#MainMessage').successMessage(iwp.lang.get('imageManagerUploadedSingular'));
}else{
$('#MainMessage').successMessage(iwp.lang.get('imageManagerUploadedMulti').replace('%s', imageManager.fileCount));
}
}
},
/**
* Saves any changes to an image name.
* @param field jQuery Object
*/
saveEditName: function (field) {
$(field).attr('disabled', true);
var id = '';
var idBits = '';
idBits = field.attr('id');
idBits = idBits.split('_');
id = idBits[0];
$('#EditNameButtons').remove();
field.removeClass("inPlaceFieldFocus");
if(field.val() != imageManager.originalTextValue){
$.post('remote.php?section=imagemanager&action=rename', 'fromName=' + escape($('#' + id + '_realname').val()) + '&toName=' + escape(field.val()),
function(result){
if (result.success) {
var message = iwp.lang.get('fileRenamedSuccess');
message = message.replace('%from%', imageManager.originalTextValue);
message = message.replace('%to%', result.newname);
// we need real spaces in the URL, as it's not a query string
result.newurl = result.newurl.replace(/\+/g, " ");
$('#' + id + '_image').attr('src', result.newurl);
$('.' + id + '_url').attr('href', result.newurl);
$('#' + id + '_url').attr('href', result.newurl);
$('#' + id + '_realname').val(result.newrealname);
} else {
$('#MainMessage').errorMessage(iwp.lang.get('fileRenamedError') + result.message);
$('#'+id+'_name').val(imageManager.originalTextValue);
}
}, 'json');
}
$(field).attr('disabled', false);
},
cancelEditName: function (field) {
$(field).val(imageManager.originalTextValue);
$(field).removeClass("inPlaceFieldFocus");
$('#EditNameButtons').remove();
},
changeImageManagerPaging: function (object, pagenumber) {
pagingId = object.selectedIndex;
pagingamount = object[pagingId].value;
window.location = 'index.php?section=imagemanager&action=view&page=' + pagenumber + '&perpage='+ pagingamount;
},
changeImageManagerSorting: function (object, pagenumber) {
pagingId = object.selectedIndex;
var sortby = object[pagingId].value;
window.location = 'index.php?section=imagemanager&action=view&page=' + pagenumber + '&sortby='+ sortby;
},
fileQueueError: function (file, errorCode, message) {
var errorName = "";
if (errorCode === SWFUpload.errorCode_QUEUE_LIMIT_EXCEEDED) {
errorName = iwp.lang.get('imTooManyFiles');
}
if (errorName !== "") {
alert(errorName);
return;
}
switch (errorCode) {
case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
alert(iwp.lang.get('imNotUploadedNoContent') + "\n\n" + file.name);
break;
case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
alert(iwp.lang.get('imMaxFileSizeError').replace('%s', imageManager.getMaxFileSize()) + "\n\n" + file.name);
break;
case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
default:
alert(iwp.lang.get('imOnlyValidImagesAllowed') + "\n\n" + file.name);
break;
}
},
fileDialogComplete : function (numFilesSelected, numFilesQueued) {
if (numFilesQueued < 1){
return;
}
$.iModal({ width: 500, title: 'Uploading Images',
data: $('#ProgressWindow').html(),
buttons: ''});
imageManager.totalItemsToUpload = numFilesQueued;
imageManager.fileCount = 1;
imageManager.uploadErrorFiles = new Array();
imageManager.uploadDuplicateFiles = new Array();
$('.progressBarStatus').html(iwp.lang.get('imUploading1ImageOf').replace('%s', numFilesQueued));
try {
if (numFilesQueued > 0) {
this.startUpload();
}
} catch (ex) {
this.debug(ex);
}
},
uploadProgress: function (file, bytesLoaded) {
var percent = Math.ceil((bytesLoaded / file.size) * 100);
$('.progressBarPercentage').css('width', parseInt(percent) + "%");
$('.progressPercent').html(percent+ "%");
},
uploadSuccess: function (file, serverData) {
var result = $.evalJSON(serverData);
if(result.Filedata.duplicate){
imageManager.uploadDuplicateFiles.push(result.Filedata.name);
return;
}
if(result.Filedata.errorfile != ''){
imageManager.uploadErrorFiles.push(result.Filedata.name);
}else if(result.Filedata.error == 0){
// success!
imageManager.addImage( result.Filedata.name, '../images/' + result.Filedata.name, result.Filedata.filesize, result.Filedata.width, result.Filedata.height, result.Filedata.origwidth + ' x ' + result.Filedata.origheight, result.Filedata.id);
}
},
uploadComplete :function (file) {
if (this.getStats().files_queued > 0) {
$('.progressBarPercentage').css('width', "0%");
$('.progressPercent').html("0%");
imageManager.fileCount++;
$('.progressBarStatus').html(iwp.lang.get('imUploadingxImageOf').replace('{totalimages}', imageManager.totalItemsToUpload).replace('{imagenumber}', imageManager.fileCount));
$('.ProgressBarText').html(' ' + file.name + '...');
this.startUpload();
} else {
$.iModal.close();
if(imageManager.uploadErrorFiles.length > 0){
var imageList = '';
var thisImage = '';
for(i in imageManager.uploadErrorFiles){
thisImage = imageManager.uploadErrorFiles[i];
imageList += '<li>' + $('<p>' + thisImage + '</p>').text() + '</li>'; // strips out any html
}
if(imageManager.uploadErrorFiles.length == imageManager.totalItemsToUpload){
$('#MainMessage').errorMessage(iwp.lang.get('imageManagerFilesNotValid') + ' <ul>' + imageList + '</ul>');
}else{
$('#MainMessage').warningMessage(iwp.lang.get('imageManagerFilesNotValidSomeSuccess') + '<ul>' + imageList + '</ul>');
}
}else if(imageManager.uploadDuplicateFiles.length > 0){
var imageList = '';
var thisImage = '';
for(i in imageManager.uploadDuplicateFiles){
thisImage = imageManager.uploadDuplicateFiles[i];
imageList += '<li>' + $('<p>' + thisImage + '</p>').text() + '</li>'; // strips out any html
}
$('#MainMessage').warningMessage(iwp.lang.get("imageManagerFilesDuplicates") + '<ul>' + imageList + '</ul>');
}else{
// The 4 selected images have been uploaded and are shown below
// The selected image has been uploaded and is shown below.
if(imageManager.fileCount == 1){
$('#MainMessage').successMessage(iwp.lang.get('imageManagerUploadedSingular'));
}else{
$('#MainMessage').successMessage(iwp.lang.get('imageManagerUploadedMulti').replace('%s', imageManager.fileCount));
}
}
}
},
uploadError: function (file, errorCode, message) {
var imageName = "error.gif";
var progress;
switch (errorCode) {
case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
try {
progress = new FileProgress(file, this.customSettings.upload_target);
progress.setCancelled();
progress.setStatus("Cancelled");
progress.toggleCancel(false);
}
catch (ex1) {
this.debug(ex1);
}
break;
case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
try {
progress = new FileProgress(file, this.customSettings.upload_target);
progress.setCancelled();
progress.setStatus("Stopped");
progress.toggleCancel(true);
}
catch (ex2) {
this.debug(ex2);
}
case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
imageName = "uploadlimit.gif";
break;
default:
alert(message);
break;
}
},
getMaxFileSize: function (){
filesize = iwp.util.defaultVal(imageManager.maxFileSize, '2MB');
return filesize;
}
};