* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @module WoltLabSuite/Core/Media/Manager/Editor
*/
-define(['Core', 'Dictionary', 'Dom/Traverse', 'Language', 'Ui/Dialog', 'WoltLabSuite/Core/Controller/Clipboard', 'WoltLabSuite/Core/Media/Manager/Base'],
- function(Core, Dictionary, DomTraverse, Language, UiDialog, ControllerClipboard, MediaManagerBase) {
+define(['Core', 'Dictionary', 'Dom/Traverse', 'EventHandler', 'Language', 'Permission', 'Ui/Dialog', 'WoltLabSuite/Core/Controller/Clipboard', 'WoltLabSuite/Core/Media/Manager/Base'],
+ function(Core, Dictionary, DomTraverse, EventHandler, Language, Permission, UiDialog, ControllerClipboard, MediaManagerBase) {
"use strict";
/**
}
this._mediaToInsert = new Dictionary();
this._mediaToInsertByClipboard = false;
+ this._uploadData = null;
+ this._uploadId = null;
+
+ if (this._options.editor && !this._options.editor.opts.woltlab.attachments) {
+ var editorId = elData(this._options.editor.$editor[0], 'element-id');
+
+ var uuid1 = EventHandler.add('com.woltlab.wcf.redactor2', 'dragAndDrop_' + editorId, this._editorUpload.bind(this));
+ var uuid2 = EventHandler.add('com.woltlab.wcf.redactor2', 'pasteFromClipboard_' + editorId, this._editorUpload.bind(this));
+
+ EventHandler.add('com.woltlab.wcf.redactor2', 'destory_' + editorId, function() {
+ EventHandler.remove('com.woltlab.wcf.redactor2', 'dragAndDrop_' + editorId, uuid1);
+ EventHandler.remove('com.woltlab.wcf.redactor2', 'dragAndDrop_' + editorId, uuid2);
+ });
+
+ EventHandler.add('com.woltlab.wcf.media.upload', 'success', this._mediaUploaded.bind(this));
+ }
}
Core.inherit(MediaManagerEditor, MediaManagerBase, {
/**
}
},
+ /**
+ * @see WoltLabSuite/Core/Media/Manager/Base#_dialogShow
+ */
+ _dialogShow: function() {
+ MediaManagerEditor._super.prototype._dialogShow.call(this);
+
+ // check if data needs to be uploaded
+ if (this._uploadData) {
+ if (this._uploadData.file) {
+ this._upload.uploadFile(this._uploadData.file);
+ }
+ else {
+ this._uploadId = this._upload.uploadBlob(this._uploadData.blob);
+ }
+
+ this._uploadData = null;
+ }
+ },
+
+ /**
+ * Handles pasting and dragging and dropping files into the editor.
+ *
+ * @param {object} data data of the uploaded file
+ */
+ _editorUpload: function(data) {
+ this._uploadData = data;
+
+ UiDialog.open(this);
+ },
+
/**
* Returns the id of the insert dialog based on the media files to be inserted.
*
*
* @param {Event?} event
* @param {string?} thumbnailSize
+ * @param {boolean?} closeEditor
*/
- _insertMedia: function(event, thumbnailSize) {
+ _insertMedia: function(event, thumbnailSize, closeEditor) {
+ if (closeEditor === undefined) closeEditor = true;
+
var insertType = 'separate';
// update insert options with selected values if method is called by clicking on 'insert' button
this._mediaToInsertByClipboard = false;
// close manager dialog
- UiDialog.close(this);
+ if (closeEditor) {
+ UiDialog.close(this);
+ }
},
/**
}
},
+ /**
+ * Is called after media files are successfully uploaded to insert copied media.
+ *
+ * @param {object} data upload data
+ */
+ _mediaUploaded: function(data) {
+ if (this._uploadId !== null && this._upload === data.upload) {
+ if (this._uploadId === data.uploadId || (Array.isArray(this._uploadId) && this._uploadId.indexOf(data.uploadId) !== -1)) {
+ this._mediaToInsert = Dictionary.fromObject(data.media);
+ this._insertMedia(null, 'medium', false);
+
+ this._uploadId = null;
+ }
+ }
+ },
+
/**
* Handles clicking on the insert button.
*