mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
mujma: ENHANCEMENTS: Added comments.
(merged from branches/gsoc) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@42067 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
a218320f42
commit
9fcd82f172
@ -1,3 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* If one of methods is not commented look for comment in Upload.js
|
||||||
|
*/
|
||||||
CMSMain_upload = Class.create();
|
CMSMain_upload = Class.create();
|
||||||
CMSMain_upload.prototype = {
|
CMSMain_upload.prototype = {
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
@ -18,6 +21,10 @@ CMSMain_upload.prototype = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds UI, called only when Upload object will be able to create flash uploader.
|
||||||
|
*/
|
||||||
|
|
||||||
extendForm: function() {
|
extendForm: function() {
|
||||||
if(this.iframe.contentDocument == undefined) this.iframe.contentDocument = document.frames[0].document;//IE HACK
|
if(this.iframe.contentDocument == undefined) this.iframe.contentDocument = document.frames[0].document;//IE HACK
|
||||||
element = this.iframe.contentDocument.getElementById('Form_UploadForm');
|
element = this.iframe.contentDocument.getElementById('Form_UploadForm');
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* If one of methods is not commented look for comment in Upload.js.
|
||||||
|
*/
|
||||||
TinyMCEImageEnhancement = Class.create();
|
TinyMCEImageEnhancement = Class.create();
|
||||||
TinyMCEImageEnhancement.prototype = {
|
TinyMCEImageEnhancement.prototype = {
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
@ -31,6 +34,10 @@ TinyMCEImageEnhancement.prototype = {
|
|||||||
Event.observe($('UploadFiles'),'click',this.onUpload.bind(this));
|
Event.observe($('UploadFiles'),'click',this.onUpload.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method creates HTML element, only reason for this method is DRY.
|
||||||
|
*/
|
||||||
|
|
||||||
addElement: function(tag, className, parent, properties) {
|
addElement: function(tag, className, parent, properties) {
|
||||||
var e = document.createElement(tag);
|
var e = document.createElement(tag);
|
||||||
Element.addClassName(e,className);
|
Element.addClassName(e,className);
|
||||||
@ -41,8 +48,6 @@ TinyMCEImageEnhancement.prototype = {
|
|||||||
|
|
||||||
onUpload: function(event) {
|
onUpload: function(event) {
|
||||||
Event.stop(event);
|
Event.stop(event);
|
||||||
|
|
||||||
|
|
||||||
if(!this.processInProgress) {
|
if(!this.processInProgress) {
|
||||||
if(this.getParentID() != 'root') {
|
if(this.getParentID() != 'root') {
|
||||||
this.upload.browse();
|
this.upload.browse();
|
||||||
@ -52,6 +57,10 @@ TinyMCEImageEnhancement.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when user clicks "add folder" anchor.
|
||||||
|
*/
|
||||||
|
|
||||||
onAddFolder: function(event) {
|
onAddFolder: function(event) {
|
||||||
Event.stop(event);
|
Event.stop(event);
|
||||||
Element.hide('AddFolder');
|
Element.hide('AddFolder');
|
||||||
@ -59,6 +68,10 @@ TinyMCEImageEnhancement.prototype = {
|
|||||||
this.applyIE6Hack();
|
this.applyIE6Hack();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when user clicks "ok" anchor/ adds folder with given name.
|
||||||
|
*/
|
||||||
|
|
||||||
onFolderOk: function(event) {
|
onFolderOk: function(event) {
|
||||||
Event.stop(event);
|
Event.stop(event);
|
||||||
var folderName = $('NewFolderName').value;
|
var folderName = $('NewFolderName').value;
|
||||||
@ -75,6 +88,10 @@ TinyMCEImageEnhancement.prototype = {
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method retrieves folder id and sends request which changes folder name.
|
||||||
|
*/
|
||||||
|
|
||||||
onFolderGetSuccess: function(transport) {
|
onFolderGetSuccess: function(transport) {
|
||||||
var t1 = transport.responseText.indexOf('TreeNode(');
|
var t1 = transport.responseText.indexOf('TreeNode(');
|
||||||
var t2 = transport.responseText.indexOf(',');
|
var t2 = transport.responseText.indexOf(',');
|
||||||
@ -99,6 +116,10 @@ TinyMCEImageEnhancement.prototype = {
|
|||||||
new Ajax.Request('admin/assets/index/' + this.getParentID() + '?executeForm=EditForm', options);
|
new Ajax.Request('admin/assets/index/' + this.getParentID() + '?executeForm=EditForm', options);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When folder name has been changed we need to refresh folder list and return to initial state of UI.
|
||||||
|
*/
|
||||||
|
|
||||||
onFolderAddSuccess: function(transport) {
|
onFolderAddSuccess: function(transport) {
|
||||||
statusMessage('Creating new folder');
|
statusMessage('Creating new folder');
|
||||||
document.getElementsBySelector("div.TreeDropdownField.single")[2].itemTree = null;
|
document.getElementsBySelector("div.TreeDropdownField.single")[2].itemTree = null;
|
||||||
@ -108,6 +129,10 @@ TinyMCEImageEnhancement.prototype = {
|
|||||||
this.removeIE6Hack();
|
this.removeIE6Hack();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If user doesn't want to add folder return to default UI.
|
||||||
|
*/
|
||||||
|
|
||||||
onFolderCancel: function(event) {
|
onFolderCancel: function(event) {
|
||||||
Event.stop(event);
|
Event.stop(event);
|
||||||
$('NewFolderName').value = '';
|
$('NewFolderName').value = '';
|
||||||
@ -116,7 +141,9 @@ TinyMCEImageEnhancement.prototype = {
|
|||||||
this.removeIE6Hack();
|
this.removeIE6Hack();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called on window.onload
|
||||||
|
*/
|
||||||
|
|
||||||
onWindowLoad: function() {
|
onWindowLoad: function() {
|
||||||
if($('FolderID') != null) {
|
if($('FolderID') != null) {
|
||||||
@ -155,6 +182,12 @@ TinyMCEImageEnhancement.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterates over all uploaded images and add them to TinyMCE editor
|
||||||
|
*
|
||||||
|
* @param transport object
|
||||||
|
*/
|
||||||
|
|
||||||
insertImages: function(transport) {
|
insertImages: function(transport) {
|
||||||
//HACK FOR STRANGE ERROR OCCURING UNDER SAFARI
|
//HACK FOR STRANGE ERROR OCCURING UNDER SAFARI
|
||||||
if(transport.responseText == '') {
|
if(transport.responseText == '') {
|
||||||
@ -172,6 +205,13 @@ TinyMCEImageEnhancement.prototype = {
|
|||||||
this.processInProgress = false;
|
this.processInProgress = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
addToTinyMCE: function(target) {
|
addToTinyMCE: function(target) {
|
||||||
var formObj = $('Form_EditorToolbarImageForm');
|
var formObj = $('Form_EditorToolbarImageForm');
|
||||||
var altText = formObj.elements.AltText.value;
|
var altText = formObj.elements.AltText.value;
|
||||||
@ -192,6 +232,11 @@ TinyMCEImageEnhancement.prototype = {
|
|||||||
TinyMCE_AdvancedTheme._insertImage(relativeHref, altText, 0, null, null, destWidth, destHeight, null, null, cssClass);
|
TinyMCE_AdvancedTheme._insertImage(relativeHref, altText, 0, null, null, destWidth, destHeight, null, null, cssClass);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Under IE6 when we click on "add folder" anchor, rest of anchors loose their correct position
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
applyIE6Hack: function() {
|
applyIE6Hack: function() {
|
||||||
if(BrowserDetect.browser == 'Explorer') {
|
if(BrowserDetect.browser == 'Explorer') {
|
||||||
elements = [$('FolderOk'),$('FolderCancel'),$('UploadFiles'),$('PipeSeparator')];
|
elements = [$('FolderOk'),$('FolderCancel'),$('UploadFiles'),$('PipeSeparator')];
|
||||||
@ -211,6 +256,11 @@ TinyMCEImageEnhancement.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns id of upload folder.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
getParentID: function() {
|
getParentID: function() {
|
||||||
return $('Form_EditorToolbarImageForm_FolderID').value == '' ? 'root' : $('Form_EditorToolbarImageForm_FolderID').value;
|
return $('Form_EditorToolbarImageForm_FolderID').value == '' ? 'root' : $('Form_EditorToolbarImageForm_FolderID').value;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
Upload = Class.create();
|
Upload = Class.create();
|
||||||
Upload.prototype = {
|
Upload.prototype = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets configuration data provided from user if smth is missing sets default value.
|
||||||
|
*
|
||||||
|
* @param params object contains all configuration data for upload.
|
||||||
|
*/
|
||||||
initialize: function(params) {
|
initialize: function(params) {
|
||||||
this.filesUploaded = 0;
|
this.filesUploaded = 0;
|
||||||
this.filesToUpload = 0;
|
this.filesToUpload = 0;
|
||||||
@ -20,14 +26,18 @@ Upload.prototype = {
|
|||||||
this.onLoad();
|
this.onLoad();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates SWFUpload object for uploading files.
|
||||||
|
*
|
||||||
|
*/
|
||||||
onLoad: function() {
|
onLoad: function() {
|
||||||
path = this.getBasePath();
|
path = this.getBasePath();
|
||||||
sessId = this.getSessionId();
|
sessId = this.getSessionId();//Because flash doesn't send proper cookies, we need to set session id in URL.
|
||||||
this.swfu = new SWFUpload({
|
this.swfu = new SWFUpload({
|
||||||
upload_target_url: path + '/assets/index/root?executeForm=UploadForm&PHPSESSID=' + sessId, // Relative to the SWF file
|
upload_target_url: path + '/assets/index/root?executeForm=UploadForm&PHPSESSID=' + sessId, // Relative to the SWF file
|
||||||
file_post_name: 'Files',
|
file_post_name: 'Files',
|
||||||
file_size_limit : this.fileSizeLimit, // 30 MB
|
file_size_limit : this.fileSizeLimit,
|
||||||
file_types : this.fileTypes, // or you could use something like: '*.doc;*.wpd;*.pdf',
|
file_types : this.fileTypes,
|
||||||
file_types_description : this.fileTypesDescription,
|
file_types_description : this.fileTypesDescription,
|
||||||
file_upload_limit : this.fileUploadLimit,
|
file_upload_limit : this.fileUploadLimit,
|
||||||
begin_upload_on_queue : this.beginUploadOnQueue,
|
begin_upload_on_queue : this.beginUploadOnQueue,
|
||||||
@ -42,23 +52,28 @@ Upload.prototype = {
|
|||||||
file_validation_handler : Prototype.emptyFunction,
|
file_validation_handler : Prototype.emptyFunction,
|
||||||
file_cancelled_handler: Prototype.emptyFunction,
|
file_cancelled_handler: Prototype.emptyFunction,
|
||||||
|
|
||||||
ui_container_id: 'abc1',
|
|
||||||
degraded_container_id: 'abc2',
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
flash_url : 'jsparty/SWFUpload/SWFUpload.swf', // Relative to this file
|
flash_url : 'jsparty/SWFUpload/SWFUpload.swf', // Relative to this file
|
||||||
ui_function: this.buildUI.bind(this),
|
ui_function: this.buildUI.bind(this),
|
||||||
debug: false
|
debug: false
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves base path from URL.
|
||||||
|
* TODO: Use base tag.
|
||||||
|
*/
|
||||||
|
|
||||||
getBasePath: function() {
|
getBasePath: function() {
|
||||||
var path = 'http://' + window.location.host + window.location.pathname;
|
var path = 'http://' + window.location.host + window.location.pathname;
|
||||||
if(path[path.length-1] == '/') path = path.substring(0,path.length-1);
|
if(path[path.length-1] == '/') path = path.substring(0,path.length-1);
|
||||||
return path;
|
return path;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves sessionId from cookie.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
getSessionId: function() {
|
getSessionId: function() {
|
||||||
var start = document.cookie.indexOf('PHPSESSID')+10;
|
var start = document.cookie.indexOf('PHPSESSID')+10;
|
||||||
var end = document.cookie.indexOf(';',start);
|
var end = document.cookie.indexOf(';',start);
|
||||||
@ -66,16 +81,35 @@ Upload.prototype = {
|
|||||||
return document.cookie.substring(start,end);
|
return document.cookie.substring(start,end);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls method defined by user, method should create user interface.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
buildUI: function() {
|
buildUI: function() {
|
||||||
this.customBuildUI();
|
this.customBuildUI();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when new file is added to the queue
|
||||||
|
*
|
||||||
|
* @param file object
|
||||||
|
* @param queueLength int
|
||||||
|
*/
|
||||||
|
|
||||||
uploadFileQueuedCallback: function(file,queueLength) {
|
uploadFileQueuedCallback: function(file,queueLength) {
|
||||||
this.filesToUpload++;
|
this.filesToUpload++;
|
||||||
this.fileQueued(file, queueLength);
|
this.fileQueued(file, queueLength);
|
||||||
this.addFileParam(file);
|
this.addFileParam(file);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when uploading of particular file has finished
|
||||||
|
*
|
||||||
|
* @param file object
|
||||||
|
* @param servedData string
|
||||||
|
*/
|
||||||
|
|
||||||
uploadFileCompleteCallback: function(file,serverData) {
|
uploadFileCompleteCallback: function(file,serverData) {
|
||||||
this.filesUploaded++;
|
this.filesUploaded++;
|
||||||
var toEval = serverData.substr(serverData.indexOf('<script'));
|
var toEval = serverData.substr(serverData.indexOf('<script'));
|
||||||
@ -85,11 +119,22 @@ Upload.prototype = {
|
|||||||
this.fileComplete(file, serverData);
|
this.fileComplete(file, serverData);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called during uploading file.
|
||||||
|
*
|
||||||
|
* @param file object
|
||||||
|
* @param bytes_complete int
|
||||||
|
*/
|
||||||
|
|
||||||
uploadFileProgressCallback: function(file, bytes_complete) {
|
uploadFileProgressCallback: function(file, bytes_complete) {
|
||||||
this.uploadInProgress = true;
|
this.uploadInProgress = true;
|
||||||
this.fileProgress(file, bytes_complete);
|
this.fileProgress(file, bytes_complete);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when whole queue has been uploaded or cancelled.
|
||||||
|
*/
|
||||||
|
|
||||||
uploadQueueCompleteCallback: function() {
|
uploadQueueCompleteCallback: function() {
|
||||||
this.queueComplete();
|
this.queueComplete();
|
||||||
this.uploadInProgress = false;
|
this.uploadInProgress = false;
|
||||||
@ -97,6 +142,13 @@ Upload.prototype = {
|
|||||||
this.filesToUpload = 0;
|
this.filesToUpload = 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called on error.
|
||||||
|
* @param error_code int
|
||||||
|
* @param file object
|
||||||
|
* @param message string
|
||||||
|
*/
|
||||||
|
|
||||||
uploadErrorCallback: function(error_code, file, message) {
|
uploadErrorCallback: function(error_code, file, message) {
|
||||||
this.swfu.cancelQueue();
|
this.swfu.cancelQueue();
|
||||||
switch(error_code) {
|
switch(error_code) {
|
||||||
@ -129,6 +181,13 @@ Upload.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Because we are on top of standard upload we need to add some POST vars that
|
||||||
|
* normally are being sent as part of form.
|
||||||
|
*
|
||||||
|
* @param file object
|
||||||
|
*/
|
||||||
|
|
||||||
addFileParam: function(file) {
|
addFileParam: function(file) {
|
||||||
this.swfu.addFileParam(file.id,'ID',this.folderID);
|
this.swfu.addFileParam(file.id,'ID',this.folderID);
|
||||||
this.swfu.addFileParam(file.id,'action_doUpload','1');
|
this.swfu.addFileParam(file.id,'action_doUpload','1');
|
||||||
@ -136,19 +195,36 @@ Upload.prototype = {
|
|||||||
this.swfu.addFileParam(file.id,'MAX_FILE_SIZE','31457280');
|
this.swfu.addFileParam(file.id,'MAX_FILE_SIZE','31457280');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts file explorer.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
browse: function() {
|
browse: function() {
|
||||||
this.swfu.browse();
|
this.swfu.browse();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts upload
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
startUpload: function() {
|
startUpload: function() {
|
||||||
this.swfu.startUpload();
|
this.swfu.startUpload();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancels uploading of file.
|
||||||
|
*/
|
||||||
|
|
||||||
cancelUpload: function(fileId) {
|
cancelUpload: function(fileId) {
|
||||||
this.filesToUpload--;
|
this.filesToUpload--;
|
||||||
this.swfu.cancelUpload(fileId);
|
this.swfu.cancelUpload(fileId);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Getters and setters.
|
||||||
|
*/
|
||||||
setFolderID: function(id) {
|
setFolderID: function(id) {
|
||||||
this.folderID = id;
|
this.folderID = id;
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user