|
|
@@ -55,9 +55,10 @@ CKEDITOR.define( [
|
|
|
|
|
|
/**
|
|
|
* Initializes the controller instance. The process includes:
|
|
|
- * 1. Initialization of the child {@link #view}.
|
|
|
- * 2. Initialization of child controllers in {@link #collections}.
|
|
|
- * 3. Setting {@link #ready} flag `true`.
|
|
|
+ *
|
|
|
+ * 1. Initialization of the child {@link #view}.
|
|
|
+ * 2. Initialization of child controllers in {@link #collections}.
|
|
|
+ * 3. Setting {@link #ready} flag `true`.
|
|
|
*
|
|
|
* @returns {Promise} A Promise resolved when the initialization process is finished.
|
|
|
*/
|
|
|
@@ -79,45 +80,6 @@ CKEDITOR.define( [
|
|
|
} );
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Initializes the {@link #view} of this controller instance.
|
|
|
- *
|
|
|
- * @protected
|
|
|
- * @returns {Promise} A Promise resolved when initialization process is finished.
|
|
|
- */
|
|
|
- _initView() {
|
|
|
- let promise = Promise.resolve();
|
|
|
-
|
|
|
- if ( this.view ) {
|
|
|
- promise = promise.then( this.view.init.bind( this.view ) );
|
|
|
- }
|
|
|
-
|
|
|
- return promise;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Initializes the {@link #collections} of this controller instance.
|
|
|
- *
|
|
|
- * @protected
|
|
|
- * @returns {Promise} A Promise resolved when initialization process is finished.
|
|
|
- */
|
|
|
- _initCollections() {
|
|
|
- const promises = [];
|
|
|
- let collection, childController;
|
|
|
-
|
|
|
- for ( collection of this.collections ) {
|
|
|
- for ( childController of collection ) {
|
|
|
- if ( this.view, childController.view ) {
|
|
|
- this.view.addChild( collection.name, childController.view );
|
|
|
- }
|
|
|
-
|
|
|
- promises.push( childController.init() );
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return Promise.all( promises );
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Adds a child controller to one of the {@link #collections}.
|
|
|
* If this controller instance is ready, the child view will be initialized when added.
|
|
|
@@ -130,35 +92,8 @@ CKEDITOR.define( [
|
|
|
* @returns {Promise} A Promise resolved when the child is added.
|
|
|
*/
|
|
|
addChild( collectionName, childController, index ) {
|
|
|
- if ( !collectionName ) {
|
|
|
- /**
|
|
|
- * The name of the collection is required.
|
|
|
- *
|
|
|
- * @error ui-controller-addchild-badcname
|
|
|
- */
|
|
|
- throw new CKEditorError( 'ui-controller-addchild-badcname' );
|
|
|
- }
|
|
|
-
|
|
|
const collection = this.collections.get( collectionName );
|
|
|
|
|
|
- if ( !collection ) {
|
|
|
- /**
|
|
|
- * There is no collection of given name.
|
|
|
- *
|
|
|
- * @error ui-controller-addchild-nocol
|
|
|
- */
|
|
|
- throw new CKEditorError( 'ui-controller-addchild-nocol' );
|
|
|
- }
|
|
|
-
|
|
|
- if ( !childController ) {
|
|
|
- /**
|
|
|
- * Passed no controller.
|
|
|
- *
|
|
|
- * @error ui-controller-addchild-no-controller
|
|
|
- */
|
|
|
- throw new CKEditorError( 'ui-controller-addchild-no-controller' );
|
|
|
- }
|
|
|
-
|
|
|
// ChildController.init() returns Promise.
|
|
|
let promise = Promise.resolve();
|
|
|
|
|
|
@@ -189,35 +124,8 @@ CKEDITOR.define( [
|
|
|
* @returns {Controller} A child controller instance after removal.
|
|
|
*/
|
|
|
removeChild( collectionName, childController ) {
|
|
|
- if ( !collectionName ) {
|
|
|
- /**
|
|
|
- * Collection name is required.
|
|
|
- *
|
|
|
- * @error ui-controller-removechild-badcname
|
|
|
- */
|
|
|
- throw new CKEditorError( 'ui-controller-removechild-badcname' );
|
|
|
- }
|
|
|
-
|
|
|
const collection = this.collections.get( collectionName );
|
|
|
|
|
|
- if ( !collection ) {
|
|
|
- /**
|
|
|
- * There's no collection of given name.
|
|
|
- *
|
|
|
- * @error ui-controller-removechild-nocol
|
|
|
- */
|
|
|
- throw new CKEditorError( 'ui-controller-removechild-nocol' );
|
|
|
- }
|
|
|
-
|
|
|
- if ( !childController ) {
|
|
|
- /**
|
|
|
- * Passed no controller.
|
|
|
- *
|
|
|
- * @error ui-controller-removechild-no-controller
|
|
|
- */
|
|
|
- throw new CKEditorError( 'ui-controller-removechild-no-controller' );
|
|
|
- }
|
|
|
-
|
|
|
collection.remove( childController );
|
|
|
|
|
|
if ( this.ready && childController.view ) {
|
|
|
@@ -237,22 +145,14 @@ CKEDITOR.define( [
|
|
|
getChild( collectionName, index ) {
|
|
|
const collection = this.collections.get( collectionName );
|
|
|
|
|
|
- if ( !collection ) {
|
|
|
- /**
|
|
|
- * There's no collection of such name.
|
|
|
- *
|
|
|
- * @error ui-controller-getchild-nocol
|
|
|
- */
|
|
|
- throw new CKEditorError( 'ui-controller-getchild-nocol' );
|
|
|
- }
|
|
|
-
|
|
|
return collection.get( index );
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Destroys the controller instance. The process includes:
|
|
|
- * 1. Destruction of the child {@link #view}.
|
|
|
- * 2. Destruction of child controllers in {@link #collections}.
|
|
|
+ *
|
|
|
+ * 1. Destruction of the child {@link #view}.
|
|
|
+ * 2. Destruction of child controllers in {@link #collections}.
|
|
|
*
|
|
|
* @returns {Promise} A Promise resolved when the destruction process is finished.
|
|
|
*/
|
|
|
@@ -286,6 +186,45 @@ CKEDITOR.define( [
|
|
|
|
|
|
return Promise.all( promises );
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Initializes the {@link #view} of this controller instance.
|
|
|
+ *
|
|
|
+ * @protected
|
|
|
+ * @returns {Promise} A Promise resolved when initialization process is finished.
|
|
|
+ */
|
|
|
+ _initView() {
|
|
|
+ let promise = Promise.resolve();
|
|
|
+
|
|
|
+ if ( this.view ) {
|
|
|
+ promise = promise.then( this.view.init.bind( this.view ) );
|
|
|
+ }
|
|
|
+
|
|
|
+ return promise;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Initializes the {@link #collections} of this controller instance.
|
|
|
+ *
|
|
|
+ * @protected
|
|
|
+ * @returns {Promise} A Promise resolved when initialization process is finished.
|
|
|
+ */
|
|
|
+ _initCollections() {
|
|
|
+ const promises = [];
|
|
|
+ let collection, childController;
|
|
|
+
|
|
|
+ for ( collection of this.collections ) {
|
|
|
+ for ( childController of collection ) {
|
|
|
+ if ( this.view, childController.view ) {
|
|
|
+ this.view.addChild( collection.name, childController.view );
|
|
|
+ }
|
|
|
+
|
|
|
+ promises.push( childController.init() );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return Promise.all( promises );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return Controller;
|