File upload plugin implemented as a toolbar command and added some multilanguage support. Completely removed the old FCKeditor from the source code.

This commit is contained in:
Dario Milicic
2014-08-08 15:42:40 +02:00
parent 25ed9017de
commit 89d9f7a6ed
15 changed files with 149 additions and 307 deletions
+1 -1
View File
@@ -7,5 +7,5 @@ CKEDITOR.editorConfig = function( config ) {
// Define changes to default configuration here. For example:
// config.language = 'fr';
// config.uiColor = '#AADC6E';
config.extraPlugins = 'abbr,timestamp,dndfiles,eqneditor';
config.extraPlugins = 'timestamp,dndfiles,eqneditor,fileupload';
};
@@ -1,83 +0,0 @@
/**
* The abbr dialog definition.
*
* Created out of the CKEditor Plugin SDK:
* http://docs.ckeditor.com/#!/guide/plugin_sdk_sample_1
*/
// Our dialog definition.
CKEDITOR.dialog.add( 'abbrDialog', function( editor ) {
return {
// Basic properties of the dialog window: title, minimum size.
title: 'Abbreviation Properties',
minWidth: 400,
minHeight: 200,
// Dialog window contents definition.
contents: [
{
// Definition of the Basic Settings dialog tab (page).
id: 'tab-basic',
label: 'Basic Settings',
// The tab contents.
elements: [
{
// Text input field for the abbreviation text.
type: 'text',
id: 'abbr',
label: 'Abbreviation',
// Validation checking whether the field is not empty.
validate: CKEDITOR.dialog.validate.notEmpty( "Abbreviation field cannot be empty" )
},
{
// Text input field for the abbreviation title (explanation).
type: 'text',
id: 'title',
label: 'Explanation',
validate: CKEDITOR.dialog.validate.notEmpty( "Explanation field cannot be empty" )
}
]
},
// Definition of the Advanced Settings dialog tab (page).
{
id: 'tab-adv',
label: 'Advanced Settings',
elements: [
{
// Another text field for the abbr element id.
type: 'text',
id: 'id',
label: 'Id'
}
]
}
],
// This method is invoked once a user clicks the OK button, confirming the dialog.
onOk: function() {
// The context of this function is the dialog object itself.
// http://docs.ckeditor.com/#!/api/CKEDITOR.dialog
var dialog = this;
// Creates a new <abbr> element.
var abbr = editor.document.createElement( 'abbr' );
// Set element attribute and text, by getting the defined field values.
abbr.setAttribute( 'title', dialog.getValueOf( 'tab-basic', 'title' ) );
abbr.setText( dialog.getValueOf( 'tab-basic', 'abbr' ) );
// Now get yet another field value, from the advanced tab.
var id = dialog.getValueOf( 'tab-adv', 'id' );
if ( id )
abbr.setAttribute( 'id', id );
// Finally, inserts the element at the editor caret position.
editor.insertElement( abbr );
}
};
});
Binary file not shown.

Before

Width:  |  Height:  |  Size: 622 B

@@ -0,0 +1,132 @@
/**
* The abbr dialog definition.
*
* Created out of the CKEditor Plugin SDK:
* http://docs.ckeditor.com/#!/guide/plugin_sdk_sample_1
*/
// Our dialog definition.
CKEDITOR.dialog.add( 'fileuploadDialog', function( editor ) {
var lang = editor.lang.image2;
console.log(editor.lang);
console.log(lang.btnUpload);
return {
// Basic properties of the dialog window: title, minimum size.
title: 'Upload file',
minWidth: 200,
minHeight: 150,
// Dialog window contents definition.
contents: [
{
// Definition of the Upload Settings dialog tab (page).
id: 'Upload',
label: lang.uploadTab,
// The tab contents.
elements: [
{
// File browser for selecting a file
type: 'file',
id: 'upload',
label: lang.btnUpload,
style: 'height:40px',
},
{
// Button for uploading the file.
type: 'fileButton',
id: 'uploadButton',
label: lang.btnUpload,
onLoad: function( a ) {
CKEDITOR.document.getById( this.domId ).on( 'click', function() {
// grab the file(s) from the file input tag and upload it using AJAX
var dialog = this.getDialog();
var files = dialog.getContentElement("Upload", "upload").getInputElement().$.files;
var formData = new FormData();
formData.append('drop-count', files.length); // number of files being uploaded
formData.append('acmd', "Upload"); // Command for the server to recognize this as an ajax upload
for (var i = 0; i < files.length; i++) {
formData.append('next_attachment', parent.next_attachment);
formData.append('encoding', "HTML");
formData.append('attfile', files[i]);
// Remember the original name of the file in a hidden text field
dialog.getContentElement( 'Upload', 'name' ).setValue( files[i].name );
}
var URL = '/' + parent.logbook + '/upload.html?next_attachment=' + parent.next_attachment;
$.ajax({
xhr: function()
{
var xhr = new window.XMLHttpRequest();
//Upload progress
xhr.upload.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
//Do something with upload progress
// console.log(percentComplete);
}
}, false);
return xhr;
},
contentType: false,
processData: false,
type: 'POST',
url: URL,
data: formData,
success: function(data) {
dialog.getContentElement( 'Upload', 'src' ).setValue( data.attachments[0].fullName );
},
fail: function() {
console.log("error");
}
});
// Do not call the built-in click command
return false;
}, this );
},
'for': [ 'Upload', 'upload' ]
},
{
// URL of the file
type: 'text',
id: 'src',
label: "URL",
// Validation checking whether the field is not empty.
validate: CKEDITOR.dialog.validate.notEmpty( "URL cannot be empty!" )
},
{
// Original name of the file, this field is hidden and only used to
// capture and display the original filename in the editor
type: 'text',
id: 'name',
hidden: true
}
]
}
],
// This method is invoked once a user clicks the OK button, confirming the dialog.
onOk: function() {
var dialog = this;
console.log(dialog.getValueOf( 'Upload', 'src' ));
console.log(dialog.getValueOf( 'Upload', 'name' ));
var file = editor.document.createElement( 'a' );
file.setAttribute( 'href', dialog.getValueOf( 'Upload', 'src' ) );
file.setText( dialog.getValueOf( 'Upload', 'name' ) );
editor.insertElement( file );
}
};
});
Binary file not shown.

After

Width:  |  Height:  |  Size: 620 B

@@ -6,32 +6,32 @@
*/
// Register the plugin within the editor.
CKEDITOR.plugins.add( 'abbr', {
CKEDITOR.plugins.add( 'fileupload', {
// Register the icons.
icons: 'abbr',
icons: 'fileupload',
// The plugin initialization logic goes inside this method.
init: function( editor ) {
// Define an editor command that opens our dialog.
editor.addCommand( 'abbr', new CKEDITOR.dialogCommand( 'abbrDialog' ) );
editor.addCommand( 'fileupload', new CKEDITOR.dialogCommand( 'fileuploadDialog' ) );
// Create a toolbar button that executes the above command.
editor.ui.addButton( 'Abbr', {
editor.ui.addButton( 'FileUpload', {
// The text part of the button (if available) and tooptip.
label: 'Insert Abbreviation',
label: 'Upload a file',
// The command to execute on click.
command: 'abbr',
command: 'fileupload',
// The button placement in the toolbar (toolbar group name).
toolbar: 'insert'
});
// Register our dialog file. this.path is the plugin folder path.
CKEDITOR.dialog.add( 'abbrDialog', this.path + 'dialogs/abbr.js' );
CKEDITOR.dialog.add( 'fileuploadDialog', this.path + 'dialogs/fileupload.js' );
}
});
Binary file not shown.
@@ -1,151 +0,0 @@
/*
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
* Copyright (C) 2003-2007 Frederico Caldeira Knabben
*
* == BEGIN LICENSE ==
*
* Licensed under the terms of any of the following licenses at your
* choice:
*
* - GNU General Public License Version 2 or later (the "GPL")
* http://www.gnu.org/licenses/gpl.html
*
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
* http://www.gnu.org/licenses/lgpl.html
*
* - Mozilla Public License Version 1.1 or later (the "MPL")
* http://www.mozilla.org/MPL/MPL-1.1.html
*
* == END LICENSE ==
*
* This plugin registers ELOG specific Toolbar items
*/
/*---- 'Submit' ----------------------------------------------------*/
// Register 'Submit' toolbar button
var oELOGSubmitItem = new FCKToolbarButton('ELOGSubmit', window.top.ELOGSubmitEntry, null, null, true, null, 3);
FCKToolbarItems.RegisterItem('ELOGSubmit', oELOGSubmitItem);
// Register 'Submit' command
var oELOGSubmitCommand = new Object();
oELOGSubmitCommand.Name = 'ELOGSubmit';
oELOGSubmitCommand.Execute = function()
{
window.top.document.form1.jcmd.value = "Submit";
if(window.top.chkform())
window.top.cond_submit();
}
oELOGSubmitCommand.GetState = function()
{
// This function is always enabled.
return FCK_TRISTATE_OFF ;
}
FCKCommands.RegisterCommand('ELOGSubmit', oELOGSubmitCommand);
/*---- 'ELOGImage' ------------------------------------------------*/
// Register 'ELOGImage' toolbar button
var oELOGImage = new FCKToolbarButton('ELOGImage', window.top.ELOGInsertImage, null, null, true, null, 37);
FCKToolbarItems.RegisterItem('ELOGImage', oELOGImage);
// Register 'ELOGImage' command
var oELOGImageCommand = new Object();
oELOGImageCommand.Name = 'ELOGImage';
oELOGImageCommand.Execute = function()
{
window.open('../../'+parent.logbook+'/upload.html?next_attachment='+parent.next_attachment, '',
'top=280,left=350,width=500,height=120,dependent=yes,menubar=no,status=no,scrollbars=no,location=no,resizable=yes');
}
oELOGImageCommand.GetState = function()
{
// This function is always enabled.
return FCK_TRISTATE_OFF ;
}
FCKCommands.RegisterCommand('ELOGImage', oELOGImageCommand);
/*---- 'InsertTime' ------------------------------------------------*/
// Create 'InsertTime' toolbar button
var oInsertTimeItem = new FCKToolbarButton('InsertTime', window.top.ELOGInsertDateTime, null, null, true, null, 4);
oInsertTimeItem.IconPath = FCKConfig.PluginsPath + 'elog/inserttime.gif' ;
FCKToolbarItems.RegisterItem('InsertTime', oInsertTimeItem);
// Register 'InsertTime' command
var oInsertTimeCommand = new Object();
oInsertTimeCommand.Name = 'InsertTime';
oInsertTimeCommand.Execute = function()
{
var xmlHttp;
try {
xmlHttp = new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
}
catch (e) {
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}
catch (e) {
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4) {
// Get the editor instance that we want to interact with.
var oEditor = FCKeditorAPI.GetInstance('Text') ;
// Insert the desired HTML.
oEditor.InsertHtml(xmlHttp.responseText);
}
}
xmlHttp.open("GET","../../?cmd=gettimedate",true);
xmlHttp.send(null);
}
oInsertTimeCommand.GetState = function()
{
// This function is always enabled.
return FCK_TRISTATE_OFF ;
}
FCKCommands.RegisterCommand('InsertTime', oInsertTimeCommand);
/*---- 'InsertLink' ------------------------------------------------*/
// Create 'InsertLink' toolbar button
var oInsertLinkItem = new FCKToolbarButton('InsertLink', window.top.ELOGInsertLink, null, null, true, null, 34);
FCKToolbarItems.RegisterItem('InsertLink', oInsertLinkItem);
// Register 'InsertLink' command
var oInsertLinkCommand = new Object();
oInsertLinkCommand.Name = 'InsertLink';
oInsertLinkCommand.Execute = function()
{
linkText = prompt(window.top.ELOGLinkTextPrompt, '');
linkURL = prompt(window.top.ELOGLinkURLPrompt, 'http://');
// Get the editor instance that we want to interact with.
var oEditor = FCKeditorAPI.GetInstance('Text') ;
// Insert the desired HTML.
oEditor.InsertHtml('<a href="'+linkURL+'">'+linkText+'</a>');
}
FCKCommands.RegisterCommand('InsertLink', oInsertLinkCommand);
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

-52
View File
@@ -1,52 +0,0 @@
/*
* ELOG specific FCKedit configuration
*/
FCKConfig.PluginsPath = FCKConfig.BasePath.substr(0, FCKConfig.BasePath.length - 7) + 'editor/plugins/';
FCKConfig.Plugins.Add('elog', null);
FCKConfig.FirefoxSpellChecker = true ;
FCKConfig.Plugins.Add('dragresizetable');
FCKConfig.ProtectedSource.Add( /<script[\s\S]*?<\/script>/gi ) ; // <SCRIPT> tags
FCKConfig.ProtectedSource.Add( /<(.*?)javascript\:(.*?)/gi ) ; // javascript: tags
FCKConfig.ProtectedSource.Add( /<(.*?)(?:on(blur|c(hange|lick)|dblclick|focus|keypress|(key|mouse)(down|up)|(un)?load|mouse(move|o(ut|ver))|reset|s(elect|ubmit)))=(.*?)(\s*?)(.*?)>/gi ) ; // events
FCKToolbarItems.RegisterItem('SourceSimple', new FCKToolbarButton( 'Source', window.top.ELOGSource, null, FCK_TOOLBARITEM_ONLYICON, true, true, 1));
FCKConfig.ToolbarSets["Default"] = [
['SourceSimple','FitWindow','ShowBlocks','-','ELOGSubmit','Preview'],
['Cut','Copy','Paste','PasteText','PasteWord','-','Print','SpellCheck'],
['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
['Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript'],
['OrderedList','UnorderedList','-','Outdent','Indent'],
['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull'],
['InsertLink','Unlink','Anchor'],
['ELOGImage','Table','Rule','Smiley','SpecialChar','InsertTime'],
['Style','FontFormat','FontName','FontSize'],
['TextColor','BGColor'],
['About']
] ;
FCKConfig.Keystrokes = [
[ CTRL + 65 /*A*/, true ],
[ CTRL + 67 /*C*/, true ],
[ CTRL + 70 /*F*/, true ],
[ CTRL + 88 /*X*/, true ],
[ CTRL + 86 /*V*/, 'Paste' ],
[ SHIFT + 45 /*INS*/, 'Paste' ],
[ CTRL + 90 /*Z*/, 'Undo' ],
[ CTRL + 89 /*Y*/, 'Redo' ],
[ CTRL + SHIFT + 90 /*Z*/, 'Redo' ],
[ CTRL + 76 /*L*/, 'Link' ],
[ CTRL + 66 /*B*/, 'Bold' ],
[ CTRL + 73 /*I*/, 'Italic' ],
[ CTRL + 85 /*U*/, 'Underline' ],
[ CTRL + 83 /*S*/, 'Save' ],
[ CTRL + ALT + 13 /*ENTER*/, 'FitWindow' ],
[ CTRL + 13 /*ENTER*/, 'ELOGSubmit' ],
[ CTRL + 9 /*TAB*/, 'Source' ]
] ;
FCKConfig.ContextMenu = ['Generic','Link','Anchor','Image','BulletedList','NumberedList','Table'];
+2 -2
View File
@@ -30,8 +30,8 @@ $(document).ready(function() {
var dialogDefinition = ev.data.definition;
// Check if the definition is from the dialog we're
// interested in (the 'image2' dialog).
if ( dialogName == 'image2' ) {
// interested in (the 'image2' and 'fileupload' dialog).
if ( dialogName == 'image2' || dialogName == 'fileupload') {
var dialogObj = dialogDefinition.dialog;
dialogObj.on("show", function() {
-4
View File
@@ -26358,16 +26358,12 @@ void show_uploader_json(LOGBOOK *lbs)
attch_count = MAX_FILE_COUNT;
}
printf("Uploading %ld attachments\n", attch_count);
rsprintf("{\r\n");
rsprintf(" \"attachments\" : [\r\n");
for(i = 0; i < attch_count; i++) {
sprintf(attchname, "attachment%d", i);
printf("%d %s\n", i, attchname);
rsprintf(" {\r\n");
rsprintf(" \"fullName\": \"%s\",\r\n", getparam(attchname));
+1 -1
View File
@@ -1 +1 @@
#define GIT_REVISION "Wed Aug 6 15:19:55 2014 +0200 - d05e601"
#define GIT_REVISION "Thu Aug 7 16:56:23 2014 +0200 - 25ed901"
@@ -10,11 +10,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "../src/elogd.c"
timestampString = "428941756.918921"
timestampString = "429197800.364771"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "26378"
endingLineNumber = "26378"
startingLineNumber = "26374"
endingLineNumber = "26374"
landmarkName = "load_password_file()"
landmarkType = "7">
</BreakpointContent>
@@ -26,11 +26,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "../src/elogd.c"
timestampString = "429029143.140329"
timestampString = "429197800.364771"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "26437"
endingLineNumber = "26437"
startingLineNumber = "26433"
endingLineNumber = "26433"
landmarkName = "load_password_file()"
landmarkType = "7">
</BreakpointContent>