From 69fbf3ab1b8743b42dbd7969c43ba2d9f052c9dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Wr=C3=B3bel?= Date: Thu, 6 Jul 2017 14:29:01 +0200 Subject: [PATCH 1/3] Switched LinkForm to the read-only mode when link and unlink commands are disabled. --- src/link.js | 9 ++++++++- tests/link.js | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/link.js b/src/link.js index e8543bb..e5d2203 100644 --- a/src/link.js +++ b/src/link.js @@ -87,8 +87,15 @@ export default class Link extends Plugin { _createForm() { const editor = this.editor; const formView = new LinkFormView( editor.locale ); + const linkCommand = editor.commands.get( 'link' ); + const unlinkCommand = editor.commands.get( 'unlink' ); + + formView.urlInputView.bind( 'value' ).to( linkCommand, 'value' ); - formView.urlInputView.bind( 'value' ).to( editor.commands.get( 'link' ), 'value' ); + // Switch form to the read-only mode when commands are disabled. + formView.urlInputView.inputView.bind( 'isReadOnly' ).to( linkCommand, 'isEnabled', value => !value ); + formView.saveButtonView.bind( 'isEnabled' ).to( linkCommand ); + formView.unlinkButtonView.bind( 'isEnabled' ).to( unlinkCommand ); // Execute link command after clicking on formView `Save` button. this.listenTo( formView, 'submit', () => { diff --git a/tests/link.js b/tests/link.js index 4b302d8..f393566 100644 --- a/tests/link.js +++ b/tests/link.js @@ -175,6 +175,28 @@ describe( 'Link', () => { sinon.assert.calledOnce( spy ); } ); + it( 'should disable #formView elements when link and unlink commands are disabled', () => { + setModelData( editor.document, 'f[o]o' ); + + linkFeature._showPanel(); + + editor.commands.get( 'link' ).isEnabled = true; + editor.commands.get( 'unlink' ).isEnabled = true; + + expect( formView.urlInputView.inputView.isReadOnly ).to.false; + expect( formView.saveButtonView.isEnabled ).to.true; + expect( formView.unlinkButtonView.isEnabled ).to.true; + expect( formView.cancelButtonView.isEnabled ).to.true; + + editor.commands.get( 'link' ).isEnabled = false; + editor.commands.get( 'unlink' ).isEnabled = false; + + expect( formView.urlInputView.inputView.isReadOnly ).to.true; + expect( formView.saveButtonView.isEnabled ).to.false; + expect( formView.unlinkButtonView.isEnabled ).to.false; + expect( formView.cancelButtonView.isEnabled ).to.true; + } ); + // https://github.com/ckeditor/ckeditor5-link/issues/53 it( 'should set formView.unlinkButtonView#isVisible depending on the selection in a link or not', () => { setModelData( editor.document, 'f[]oo' ); From 63ab7ce9999fd25fe8e85017350bc007ff140e97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Wr=C3=B3bel?= Date: Thu, 6 Jul 2017 15:22:59 +0200 Subject: [PATCH 2/3] Docs. --- src/link.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/link.js b/src/link.js index e5d2203..d7cba2a 100644 --- a/src/link.js +++ b/src/link.js @@ -92,7 +92,7 @@ export default class Link extends Plugin { formView.urlInputView.bind( 'value' ).to( linkCommand, 'value' ); - // Switch form to the read-only mode when commands are disabled. + // Form elements should be read-only when corresponding commands are disabled. formView.urlInputView.inputView.bind( 'isReadOnly' ).to( linkCommand, 'isEnabled', value => !value ); formView.saveButtonView.bind( 'isEnabled' ).to( linkCommand ); formView.unlinkButtonView.bind( 'isEnabled' ).to( unlinkCommand ); From a656200bd892a9f370d4e63e030a59a9809c5b4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Wr=C3=B3bel?= Date: Tue, 11 Jul 2017 08:34:01 +0200 Subject: [PATCH 3/3] Bound LabeledInputView#isReadOnly to the LinkCommand#isEnabled. --- src/link.js | 2 +- tests/link.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/link.js b/src/link.js index d7cba2a..b99ef9a 100644 --- a/src/link.js +++ b/src/link.js @@ -93,7 +93,7 @@ export default class Link extends Plugin { formView.urlInputView.bind( 'value' ).to( linkCommand, 'value' ); // Form elements should be read-only when corresponding commands are disabled. - formView.urlInputView.inputView.bind( 'isReadOnly' ).to( linkCommand, 'isEnabled', value => !value ); + formView.urlInputView.bind( 'isReadOnly' ).to( linkCommand, 'isEnabled', value => !value ); formView.saveButtonView.bind( 'isEnabled' ).to( linkCommand ); formView.unlinkButtonView.bind( 'isEnabled' ).to( unlinkCommand ); diff --git a/tests/link.js b/tests/link.js index f393566..999e970 100644 --- a/tests/link.js +++ b/tests/link.js @@ -183,7 +183,7 @@ describe( 'Link', () => { editor.commands.get( 'link' ).isEnabled = true; editor.commands.get( 'unlink' ).isEnabled = true; - expect( formView.urlInputView.inputView.isReadOnly ).to.false; + expect( formView.urlInputView.isReadOnly ).to.false; expect( formView.saveButtonView.isEnabled ).to.true; expect( formView.unlinkButtonView.isEnabled ).to.true; expect( formView.cancelButtonView.isEnabled ).to.true; @@ -191,7 +191,7 @@ describe( 'Link', () => { editor.commands.get( 'link' ).isEnabled = false; editor.commands.get( 'unlink' ).isEnabled = false; - expect( formView.urlInputView.inputView.isReadOnly ).to.true; + expect( formView.urlInputView.isReadOnly ).to.true; expect( formView.saveButtonView.isEnabled ).to.false; expect( formView.unlinkButtonView.isEnabled ).to.false; expect( formView.cancelButtonView.isEnabled ).to.true;