| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- /**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /**
- * @module link/ui/linkformview
- */
- import View from 'ckeditor5-ui/src/view';
- import Template from 'ckeditor5-ui/src/template';
- import ButtonView from 'ckeditor5-ui/src/button/buttonview';
- import LabeledInputView from 'ckeditor5-ui/src/labeledinput/labeledinputview';
- import InputTextView from 'ckeditor5-ui/src/inputtext/inputtextview';
- import submitHandler from 'ckeditor5-ui/src/bindings/submithandler';
- /**
- * The link form view controller class.
- *
- * See {@link module:link/ui/linkformview~LinkFormView}.
- *
- * @extends module:ui/view~View
- */
- export default class LinkFormView extends View {
- /**
- * @inheritDoc
- */
- constructor( locale ) {
- super( locale );
- /**
- * The url input view.
- *
- * @member {module:ui/labeledinput/labeledinputview~LabeledInputView}
- */
- this.urlInputView = this._createUrlInput();
- /**
- * The save button view.
- *
- * @member {module:ui/button/buttonview~ButtonView}
- */
- this.saveButtonView = this._createButton( 'Save' );
- this.saveButtonView.type = 'submit';
- /**
- * The cancel button view.
- *
- * @member {module:ui/button/buttonview~ButtonView}
- */
- this.cancelButtonView = this._createButton( 'Cancel', 'cancel' );
- /**
- * The unlink button view.
- *
- * @member {module:ui/button/buttonview~ButtonView}
- */
- this.unlinkButtonView = this._createButton( 'Unlink', 'unlink' );
- // Register child views.
- this.addChildren( [ this.urlInputView, this.saveButtonView, this.cancelButtonView, this.unlinkButtonView ] );
- Template.extend( this.saveButtonView.template, {
- attributes: {
- class: [
- 'ck-button-action'
- ]
- }
- } );
- this.template = new Template( {
- tag: 'form',
- attributes: {
- class: [
- 'ck-link-form',
- ]
- },
- children: [
- this.urlInputView,
- {
- tag: 'div',
- attributes: {
- class: [
- 'ck-link-form__actions'
- ]
- },
- children: [
- this.saveButtonView,
- this.cancelButtonView,
- this.unlinkButtonView
- ]
- }
- ]
- } );
- submitHandler( {
- view: this
- } );
- }
- /**
- * Create labeled input view.
- *
- * @private
- * @returns {module:ui/labeledinput/labeledinputview~LabeledInputView} Labeled input view instance.
- */
- _createUrlInput() {
- const t = this.locale.t;
- const labeledInput = new LabeledInputView( this.locale, InputTextView );
- labeledInput.label = t( 'Link URL' );
- return labeledInput;
- }
- /**
- * Creates button View.
- *
- * @private
- * @param {String} label Button label
- * @param {String} [eventName] Event name which ButtonView#execute event will be delegated to.
- * @returns {module:ui/button/buttonview~ButtonView} Button view instance.
- */
- _createButton( label, eventName ) {
- const t = this.locale.t;
- const button = new ButtonView( this.locale );
- button.label = t( label );
- button.withText = true;
- if ( eventName ) {
- button.delegate( 'execute' ).to( this, eventName );
- }
- return button;
- }
- }
- /**
- * Fired when the form view is submitted (when one of the child triggered submit event).
- * E.g. click on {@link #saveButtonView}.
- *
- * @event submit
- */
- /**
- * Fired when the form view is canceled, e.g. click on {@link #cancelButtonView}.
- *
- * @event cancel
- */
- /**
- * Fired when the {@link #unlinkButtonView} is clicked.
- *
- * @event unlink
- */
|