/
formdialogformview.js
executable file
·239 lines (203 loc) · 6.05 KB
/
formdialogformview.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/
/**
* @module image/imagetextalternative/ui/textalternativeformview
*/
import View from '@ckeditor/ckeditor5-ui/src/view';
import Template from '@ckeditor/ckeditor5-ui/src/template';
import ViewCollection from '@ckeditor/ckeditor5-ui/src/viewcollection';
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
import LabeledInputView from '@ckeditor/ckeditor5-ui/src/labeledinput/labeledinputview';
import InputTextView from '@ckeditor/ckeditor5-ui/src/inputtext/inputtextview';
import submitHandler from '@ckeditor/ckeditor5-ui/src/bindings/submithandler';
import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
import FocusCycler from '@ckeditor/ckeditor5-ui/src/focuscycler';
import BoxedEditorUIView from "@ckeditor/ckeditor5-ui/src/editorui/boxed/boxededitoruiview";
import TextareaView from "../../textareaview";
/**
* The IntroSrcDialogFormView class.
*
* @extends module:ui/view~View
*/
export default class FormDialogFormView extends View {
/**
* @inheritDoc
*/
constructor( locale ) {
super( locale );
const t = this.locale.t;
/**
* Tracks information about DOM focus in the form.
*
* @readonly
* @member {module:utils/focustracker~FocusTracker}
*/
this.focusTracker = new FocusTracker();
/**
* An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
*
* @readonly
* @member {module:utils/keystrokehandler~KeystrokeHandler}
*/
this.keystrokes = new KeystrokeHandler();
/**
* A textarea with a label.
*
* @member {module:ui/labeledinput/labeledinputview~LabeledInputView} #labeledTextarea
*/
this.formIdInput = this._createFormIdInputView();
/**
* A textarea with a label.
*
* @member {module:ui/labeledinput/labeledinputview~LabeledInputView} #labeledTextarea
*/
this.onchangeInput = this._createOnchangeInputView();
/**
* A button used to submit the form.
*
* @member {module:ui/button/buttonview~ButtonView} #saveButtonView
*/
this.saveButtonView = this._createButton( t( 'Save' ) );
this.saveButtonView.type = 'submit';
/**
* A button used to cancel the form.
*
* @member {module:ui/button/buttonview~ButtonView} #cancelButtonView
*/
this.cancelButtonView = this._createButton( t( 'Cancel' ), 'cancel' );
/**
* A collection of views which can be focused in the form.
*
* @readonly
* @protected
* @member {module:ui/viewcollection~ViewCollection}
*/
this._focusables = new ViewCollection();
/**
* Helps cycling over {@link #_focusables} in the form.
*
* @readonly
* @protected
* @member {module:ui/focuscycler~FocusCycler}
*/
this._focusCycler = new FocusCycler( {
focusables: this._focusables,
focusTracker: this.focusTracker,
keystrokeHandler: this.keystrokes,
actions: {
// Navigate form fields backwards using the Shift + Tab keystroke.
focusPrevious: 'shift + tab',
// Navigate form fields forwards using the Tab key.
focusNext: 'tab'
}
} );
Template.extend( this.saveButtonView.template, {
attributes: {
class: [
'ck-button-action'
]
}
} );
this.template = new Template( {
tag: 'form',
attributes: {
class: [
'cke-formId-form',
],
// https://github.com/ckeditor/ckeditor5-image/issues/40
tabindex: '-1'
},
children: [
this.formIdInput,
{
tag: 'div',
attributes: {
class: [
'cke-formId-form__actions'
]
}
// ,
// children: [
// this.saveButtonView,
// this.cancelButtonView
// ]
},
this.onchangeInput,
{
tag: 'div',
attributes: {
class: [
'cke-onchangeInput-form__actions'
]
},
children: [
this.saveButtonView,
this.cancelButtonView
]
}
]
} );
submitHandler( {
view: this
} );
[ this.formIdInput, this.onchangeInput, this.saveButtonView, this.cancelButtonView ]
.forEach( v => {
// Register the view as focusable.
this._focusables.add( v );
// Register the view in the focus tracker.
this.focusTracker.add( v.element );
} );
}
/**
* @inheritDoc
*/
init() {
super.init();
this.keystrokes.listenTo( this.element );
}
/**
* Creates the button view.
*
* @private
* @param {String} label The button label
* @param {String} [eventName] The event name that the ButtonView#execute event will be delegated to.
* @returns {module:ui/button/buttonview~ButtonView} The button view instance.
*/
_createButton( label, eventName ) {
const button = new ButtonView( this.locale );
button.label = label;
button.withText = true;
if ( eventName ) {
button.delegate( 'execute' ).to( this, eventName );
}
return button;
}
/**
* Creates an input with a label.
*
* @private
* @return {module:ui/labeledinput/labeledinputview~LabeledInputView}
*/
_createFormIdInputView() {
const t = this.locale.t;
const formIdInput = new LabeledInputView( this.locale, InputTextView );
formIdInput.label = t( 'Form id' );
return formIdInput;
}
/**
* Creates an input with a label.
*
* @private
* @return {module:ui/labeledinput/labeledinputview~LabeledInputView}
*/
_createOnchangeInputView() {
const t = this.locale.t;
// const onchangeInput = new LabeledInputView( this.locale, InputTextView );
const onchangeInput = new LabeledInputView( this.locale, TextareaView );
onchangeInput.label = t( 'Onchange javascript' );
return onchangeInput;
}
}