Ver Fonte

Merge pull request #44 from ckeditor/t/43

Fix: Bound ImageUploadButton#isEnabled to ImageUploadCommand#isEnabled. Closes #43.
Piotr Jasiun há 8 anos atrás
pai
commit
48f3cfa335

+ 3 - 0
packages/ckeditor5-upload/src/imageuploadbutton.js

@@ -36,6 +36,7 @@ export default class ImageUploadButton extends Plugin {
 		// Setup `insertImage` button.
 		editor.ui.componentFactory.add( 'insertImage', locale => {
 			const view = new FileDialogButtonView( locale );
+			const command = editor.commands.get( 'imageUpload' );
 
 			view.set( {
 				label: t( 'Insert image' ),
@@ -45,6 +46,8 @@ export default class ImageUploadButton extends Plugin {
 				allowMultipleFiles: true
 			} );
 
+			view.bind( 'isEnabled' ).to( command );
+
 			view.on( 'done', ( evt, files ) => {
 				for ( const file of files ) {
 					editor.execute( 'imageUpload', { file } );

+ 13 - 0
packages/ckeditor5-upload/tests/imageuploadbutton.js

@@ -37,6 +37,19 @@ describe( 'ImageUploadButton', () => {
 		expect( button ).to.be.instanceOf( FileDialogButtonView );
 	} );
 
+	it( 'should be disabled while ImageUploadCommand is disabled', () => {
+		const button = editor.ui.componentFactory.create( 'insertImage' );
+		const command = editor.commands.get( 'imageUpload' );
+
+		command.isEnabled = true;
+
+		expect( button.isEnabled ).to.true;
+
+		command.isEnabled = false;
+
+		expect( button.isEnabled ).to.false;
+	} );
+
 	it( 'should execute imageUpload command', () => {
 		const executeStub = sinon.stub( editor, 'execute' );
 		const button = editor.ui.componentFactory.create( 'insertImage' );