2007-09-16 04:36:42 +02:00
|
|
|
/**
|
2007-10-03 01:08:38 +02:00
|
|
|
* This class is used for upload in TinyMCE editor.
|
2007-09-16 04:36:42 +02:00
|
|
|
* If one of methods is not commented look for comment in Upload.js.
|
|
|
|
*/
|
2007-09-16 04:21:47 +02:00
|
|
|
TinyMCEImageEnhancement = Class.create();
|
|
|
|
TinyMCEImageEnhancement.prototype = {
|
|
|
|
initialize: function() {
|
2007-11-15 23:31:57 +01:00
|
|
|
this.filesUploaded = 0;
|
2007-09-16 04:34:08 +02:00
|
|
|
this.processInProgress = false;
|
2007-09-16 04:21:47 +02:00
|
|
|
Event.observe(window,'load',this.onWindowLoad.bind(this));
|
|
|
|
},
|
|
|
|
|
2007-11-11 23:30:01 +01:00
|
|
|
addListeners: function() {
|
2007-11-12 22:47:45 +01:00
|
|
|
$('Form_EditorToolbarImageForm_FolderID').value = "";
|
|
|
|
|
|
|
|
Event.observe($('AddFolder'),'click',this.onAddFolder.bind(this));
|
|
|
|
Event.observe($('FolderOk'),'click',this.onFolderOk.bind(this));
|
2007-11-11 23:30:01 +01:00
|
|
|
Event.observe($('FolderCancel'),'click',this.onFolderCancel.bind(this));
|
2007-09-16 04:34:08 +02:00
|
|
|
Event.observe($('UploadFiles'),'click',this.onUpload.bind(this));
|
2007-09-16 04:21:47 +02:00
|
|
|
},
|
|
|
|
|
2007-09-16 04:36:42 +02:00
|
|
|
/**
|
|
|
|
* Method creates HTML element, only reason for this method is DRY.
|
|
|
|
*/
|
|
|
|
|
2007-09-16 04:34:08 +02:00
|
|
|
addElement: function(tag, className, parent, properties) {
|
|
|
|
var e = document.createElement(tag);
|
|
|
|
Element.addClassName(e,className);
|
|
|
|
parent.appendChild(e);
|
|
|
|
Object.extend(e,properties);
|
|
|
|
return e;
|
|
|
|
},
|
|
|
|
|
2007-09-16 04:21:47 +02:00
|
|
|
onUpload: function(event) {
|
|
|
|
Event.stop(event);
|
2007-09-16 04:34:08 +02:00
|
|
|
if(!this.processInProgress) {
|
|
|
|
if(this.getParentID() != 'root') {
|
|
|
|
this.upload.browse();
|
2007-09-16 04:21:47 +02:00
|
|
|
} else {
|
|
|
|
statusMessage("Please choose folder","bad");
|
|
|
|
}
|
2007-09-16 04:34:08 +02:00
|
|
|
}
|
2007-09-16 04:21:47 +02:00
|
|
|
},
|
|
|
|
|
2007-09-16 04:36:42 +02:00
|
|
|
/**
|
|
|
|
* Called when user clicks "add folder" anchor.
|
|
|
|
*/
|
|
|
|
|
2007-09-16 04:21:47 +02:00
|
|
|
onAddFolder: function(event) {
|
|
|
|
Event.stop(event);
|
|
|
|
Element.hide('AddFolder');
|
|
|
|
Element.show('NewFolderName','FolderOk','FolderCancel');
|
|
|
|
this.applyIE6Hack();
|
|
|
|
},
|
|
|
|
|
2008-10-24 03:21:12 +02:00
|
|
|
/**
|
|
|
|
* The user clicks the "ok" anchor link, the click event calls up
|
|
|
|
* this function which creates a new AJAX request to add a new folder
|
|
|
|
* using the addfolder function in AssetAdmin.php (admin/assets/addfolder).
|
|
|
|
*/
|
|
|
|
onFolderOk: function(event) {
|
|
|
|
Event.stop(event);
|
|
|
|
var folderName = $('NewFolderName').value;
|
|
|
|
var options = {
|
|
|
|
method: 'post',
|
|
|
|
postBody: 'ParentID=' + this.getParentID() + '&ajax=1&returnID=1' + ($('SecurityID') ? '&SecurityID=' + $('SecurityID').value : ''),
|
|
|
|
onSuccess: this.onFolderGetSuccess.bind(this),
|
|
|
|
onFailure: function(transport) {
|
|
|
|
errorMessage('Error: Folder not added', transport);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
new Ajax.Request('admin/assets/addfolder', options);
|
|
|
|
},
|
2007-09-16 04:21:47 +02:00
|
|
|
|
2008-10-24 03:21:12 +02:00
|
|
|
/**
|
|
|
|
* If the "addFolderOk" function does a successful AJAX post, call this
|
|
|
|
* function. Take the folder ID that was created in "addFolderOk"
|
|
|
|
* via ajax and send data to modify that folder record.
|
|
|
|
*/
|
|
|
|
onFolderGetSuccess: function(transport) {
|
|
|
|
var folderID = transport.responseText;
|
|
|
|
|
|
|
|
var date = new Date();
|
|
|
|
var year = date.getFullYear();
|
|
|
|
var month = date.getMonth() < 10 ? '0' + date.getMonth() : date.getMonth();
|
|
|
|
var day = date.getDay() < 10 ? '0' + date.getDay() : date.getDay();
|
|
|
|
var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
|
|
|
|
var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
|
|
|
|
var seconds = date.getSeconds() < 10 == 1 ? '0' + date.getSeconds() : date.getSeconds();
|
|
|
|
var currentDate = year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
|
|
|
|
|
|
|
|
var folderName = $('NewFolderName').value;
|
|
|
|
|
|
|
|
this.folderID = folderID;
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
method: 'post',
|
|
|
|
postBody: 'Created=' + currentDate + '&Name=' + folderName + '&ClassName=Folder&ID=' + folderID + '&ajax=1&action_save=1' + ($('SecurityID') ? '&SecurityID=' + $('SecurityID').value : ''),
|
|
|
|
onSuccess: this.onFolderAddSuccess.bind(this),
|
|
|
|
onFailure: function(transport) {
|
|
|
|
errorMessage('Error: Folder not added', transport);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
new Ajax.Request('admin/assets/EditForm', options);
|
2007-09-16 04:21:47 +02:00
|
|
|
},
|
|
|
|
|
2007-09-16 04:36:42 +02:00
|
|
|
/**
|
|
|
|
* When folder name has been changed we need to refresh folder list and return to initial state of UI.
|
|
|
|
*/
|
|
|
|
|
2007-09-16 04:21:47 +02:00
|
|
|
onFolderAddSuccess: function(transport) {
|
|
|
|
statusMessage('Creating new folder');
|
2008-06-25 06:11:58 +02:00
|
|
|
$('TreeDropdownField_Form_EditorToolbarImageForm_FolderID').itemTree = null;
|
2007-11-12 22:47:45 +01:00
|
|
|
$('TreeDropdownField_Form_EditorToolbarImageForm_FolderID').setValue(this.folderID);
|
2007-09-16 04:21:47 +02:00
|
|
|
$('NewFolderName').value = '';
|
|
|
|
Element.show('AddFolder');
|
|
|
|
Element.hide('NewFolderName','FolderOk','FolderCancel');
|
2007-11-12 22:47:45 +01:00
|
|
|
this.removeIE6Hack();
|
2007-09-16 04:21:47 +02:00
|
|
|
},
|
|
|
|
|
2007-09-16 04:36:42 +02:00
|
|
|
/**
|
|
|
|
* If user doesn't want to add folder return to default UI.
|
|
|
|
*/
|
|
|
|
|
2007-09-16 04:21:47 +02:00
|
|
|
onFolderCancel: function(event) {
|
|
|
|
$('NewFolderName').value = '';
|
|
|
|
Element.show('AddFolder');
|
|
|
|
Element.hide('NewFolderName','FolderOk','FolderCancel');
|
|
|
|
this.removeIE6Hack();
|
|
|
|
},
|
|
|
|
|
2007-09-16 04:36:42 +02:00
|
|
|
/**
|
|
|
|
* Called on window.onload
|
|
|
|
*/
|
2007-09-16 04:21:47 +02:00
|
|
|
|
2008-06-25 06:11:58 +02:00
|
|
|
onWindowLoad: function() {
|
|
|
|
// Due to a bug in the flash plugin on Linux and Mac, we need at least version 9.0.64 to use SWFUpload
|
|
|
|
if(navigator.appVersion.indexOf("Mac") != -1 || navigator.appVersion.indexOf("X11") != -1 || navigator.appVersion.indexOf("Linux") != -1) {
|
|
|
|
pv = getFlashPlayerVersion();
|
|
|
|
if(pv.major < 9 || (pv.major == 9 && pv.minor == 0 && pv.rev < 64)) {
|
2008-11-13 06:18:06 +01:00
|
|
|
if($('AddFolderGroup')) $('AddFolderGroup').style.display = 'none';
|
|
|
|
if($('PipeSeparator')) $('PipeSeparator').style.display = 'none';
|
|
|
|
if($('UploadGroup')) $('UploadGroup').style.display = 'none';
|
2008-06-25 06:11:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-11-15 23:31:57 +01:00
|
|
|
|
2007-09-16 04:21:47 +02:00
|
|
|
if($('FolderID') != null) {
|
2008-08-11 01:17:51 +02:00
|
|
|
if($('SecurityID')) var securityid=$('SecurityID').value;
|
|
|
|
else var securityid=null;
|
2007-09-16 04:34:08 +02:00
|
|
|
this.upload = new Upload(
|
|
|
|
{
|
2007-09-16 04:35:30 +02:00
|
|
|
fileTypes : '*.jpeg;*.jpg;*.jpe;*.png;*.gif;',
|
|
|
|
fileTypesDescription : 'Image files',
|
2007-11-12 22:47:45 +01:00
|
|
|
fileUploadLimit : '100',
|
2008-08-11 01:17:51 +02:00
|
|
|
securityID : securityid,
|
2007-09-16 04:35:30 +02:00
|
|
|
beginUploadOnQueue : true,
|
2007-11-11 23:30:01 +01:00
|
|
|
buildUI : this.addListeners.bind(this),
|
2007-09-16 04:35:30 +02:00
|
|
|
fileQueued : this.uploadFileQueuedCallback.bind(this),
|
|
|
|
fileComplete : this.uploadFileCompleteCallback.bind(this),
|
|
|
|
queueComplete : this.uploadQueueCompleteCallback.bind(this)
|
2007-09-16 04:34:08 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2007-09-16 04:21:47 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
uploadFileQueuedCallback: function(file,queueLength) {
|
2007-09-16 04:34:08 +02:00
|
|
|
this.processInProgress = true;
|
|
|
|
this.upload.setFolderID(this.getParentID());
|
|
|
|
$('UploadFiles').innerHTML = "Uploading ... 1/" + this.upload.getFilesToUpload();
|
2008-06-25 06:11:58 +02:00
|
|
|
this.upload.startUpload();
|
2007-09-16 04:21:47 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
uploadFileCompleteCallback: function(file,serverData) {
|
2007-09-16 04:34:08 +02:00
|
|
|
Element.addClassName($('UploadFiles'),'link');//Safari hack
|
|
|
|
$('UploadFiles').innerHTML = 'Uploading ... ' + this.upload.getFilesUploaded() + "/" + this.upload.getFilesToUpload();
|
2007-09-16 04:21:47 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
uploadQueueCompleteCallback: function() {
|
2007-09-16 04:34:08 +02:00
|
|
|
this.filesUploaded = this.upload.getFilesUploaded();
|
2007-09-16 04:21:47 +02:00
|
|
|
$('UploadFiles').innerHTML = "upload";
|
2007-09-16 04:34:08 +02:00
|
|
|
statusMessage('Uploaded ' + this.upload.getFilesUploaded() + ' files','good');
|
|
|
|
if(this.getParentID() != 'root') {
|
2008-11-13 06:18:06 +01:00
|
|
|
$('Image').ajaxGetFiles(this.getParentID(), null, this.insertImages.bind(this));
|
2007-09-16 04:21:47 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2007-09-16 04:36:42 +02:00
|
|
|
/**
|
|
|
|
* Iterates over all uploaded images and add them to TinyMCE editor
|
|
|
|
*
|
|
|
|
* @param transport object
|
|
|
|
*/
|
2007-09-16 04:34:08 +02:00
|
|
|
insertImages: function(transport) {
|
|
|
|
//HACK FOR STRANGE ERROR OCCURING UNDER SAFARI
|
|
|
|
if(transport.responseText == '') {
|
2008-11-13 06:18:06 +01:00
|
|
|
$('Image').ajaxGetFiles(this.getParentID(), null, this.insertImages.bind(this));
|
2007-09-16 04:34:08 +02:00
|
|
|
return;
|
2007-09-16 04:21:47 +02:00
|
|
|
}
|
2007-09-16 04:34:08 +02:00
|
|
|
//END OF HACK
|
2008-11-13 06:18:06 +01:00
|
|
|
|
2007-09-16 04:21:47 +02:00
|
|
|
$('Image').reapplyBehaviour();
|
2008-11-13 06:18:06 +01:00
|
|
|
|
2008-06-25 06:11:58 +02:00
|
|
|
this.addToTinyMCE = this.addToTinyMCE.bind(this);
|
2008-11-13 06:18:06 +01:00
|
|
|
|
|
|
|
this.processInProgress = false;
|
2007-09-16 04:21:47 +02:00
|
|
|
},
|
|
|
|
|
2007-09-16 04:36:42 +02:00
|
|
|
/**
|
|
|
|
* Adds particular image to TinyMCE. Most of code has been copied from tiny_mce_improvements.js / ImageThumbnail.onclick
|
|
|
|
* Sorry for not following DRY, I didn't want to break smth in tiny_mce_improvements.
|
|
|
|
*
|
|
|
|
* @param target object
|
|
|
|
*/
|
|
|
|
|
2007-09-16 04:21:47 +02:00
|
|
|
addToTinyMCE: function(target) {
|
|
|
|
var formObj = $('Form_EditorToolbarImageForm');
|
|
|
|
var altText = formObj.elements.AltText.value;
|
|
|
|
var cssClass = formObj.elements.CSSClass.value;
|
|
|
|
var baseURL = document.getElementsByTagName('base')[0].href;
|
|
|
|
var relativeHref = target.href.substr(baseURL.length)
|
|
|
|
if(!tinyMCE.selectedInstance) tinyMCE.selectedInstance = Toolbar.instance().editor;
|
|
|
|
if(tinyMCE.selectedInstance.contentWindow.focus) tinyMCE.selectedInstance.contentWindow.focus();
|
|
|
|
// Extract dest width and dest height from the class name
|
|
|
|
var destWidth = null;
|
|
|
|
var destHeight = null;
|
|
|
|
try {
|
|
|
|
var imgTag = target.getElementsByTagName('img')[0];
|
|
|
|
destWidth = imgTag.className.match(/destwidth=([0-9.\-]+)([, ]|$)/) ? RegExp.$1 : null;
|
|
|
|
destHeight = imgTag.className.match(/destheight=([0-9.\-]+)([, ]|$)/) ? RegExp.$1 : null;
|
|
|
|
} catch(er) {
|
|
|
|
}
|
|
|
|
TinyMCE_AdvancedTheme._insertImage(relativeHref, altText, 0, null, null, destWidth, destHeight, null, null, cssClass);
|
|
|
|
},
|
|
|
|
|
2007-09-16 04:36:42 +02:00
|
|
|
/**
|
|
|
|
* Under IE6 when we click on "add folder" anchor, rest of anchors loose their correct position
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-09-16 04:21:47 +02:00
|
|
|
applyIE6Hack: function() {
|
|
|
|
if(BrowserDetect.browser == 'Explorer') {
|
2007-11-12 22:47:45 +01:00
|
|
|
elements = [$('FolderOk'),$('FolderCancel'),$('UploadFiles')];
|
2007-09-16 04:21:47 +02:00
|
|
|
$A(elements).each(function(element) {
|
|
|
|
element.style.position = "relative";
|
|
|
|
element.style.top = "-3px";
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
removeIE6Hack: function() {
|
|
|
|
if(BrowserDetect.browser == 'Explorer') {
|
2007-11-12 22:47:45 +01:00
|
|
|
elements = [$('FolderOk'),$('FolderCancel'),$('UploadFiles')];
|
2007-09-16 04:21:47 +02:00
|
|
|
$A(elements).each(function(element) {
|
|
|
|
element.style.position = "";
|
|
|
|
});
|
|
|
|
}
|
2007-09-16 04:34:08 +02:00
|
|
|
},
|
|
|
|
|
2007-09-16 04:36:42 +02:00
|
|
|
/**
|
|
|
|
* Returns id of upload folder.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-09-16 04:34:08 +02:00
|
|
|
getParentID: function() {
|
|
|
|
return $('Form_EditorToolbarImageForm_FolderID').value == '' ? 'root' : $('Form_EditorToolbarImageForm_FolderID').value;
|
2007-09-16 04:21:47 +02:00
|
|
|
}
|
|
|
|
}
|
2007-11-12 22:47:45 +01:00
|
|
|
tinyMCEImageEnhancement = new TinyMCEImageEnhancement();
|