controller entire support view instance

This commit is contained in:
Yuri Kuznetsov
2023-07-16 17:57:55 +03:00
parent aead8f6edd
commit 0c0a4da7d3
2 changed files with 34 additions and 9 deletions
+25 -2
View File
@@ -453,7 +453,7 @@ class Controller {
*/
/**
* Create a main view in the master.
* Create a main view in the master container and render it.
*
* @param {string|module:view} [view] A view name or view instance.
* @param {Object.<string, *>} [options] Options for a view.
@@ -643,7 +643,8 @@ class Controller {
}
/**
* Create a view in the BODY element.
* Create a view in the BODY element. Use for rendering separate pages without the default navbar and footer.
* If a callback is not passed, the view will be automatically rendered.
*
* @param {string|module:view} view A view name or view instance.
* @param {Object.<string, *>} [options] Options for a view.
@@ -659,12 +660,34 @@ class Controller {
this.set('master', null);
this.set('masterRendered', false);
if (typeof view === 'object') {
view.setElement('body');
this.viewFactory.prepare(view, () => {
if (!callback) {
view.render();
return;
}
callback(view);
});
return;
}
options = options || {};
options.fullSelector = 'body';
this.viewFactory.create(view, options, view => {
this.set('entire', view);
if (!callback) {
view.render();
return;
}
callback(view);
});
}
+9 -7
View File
@@ -127,14 +127,17 @@ class BaseController extends Controller {
});
}
// noinspection JSUnusedGlobalSymbols
actionLogin() {
this.login();
}
// noinspection JSUnusedGlobalSymbols
actionLogout() {
this.logout();
}
// noinspection JSUnusedGlobalSymbols
actionLogoutWait() {
this.entire('views/base', {template: 'logout-wait'}, view => {
view.render()
@@ -142,6 +145,7 @@ class BaseController extends Controller {
});
}
// noinspection JSUnusedGlobalSymbols
actionClearCache() {
this.clearCache();
}
@@ -150,20 +154,18 @@ class BaseController extends Controller {
* Error Not Found.
*/
error404() {
//const view = new BaseView();
const view = new BaseView({template: 'errors/404'});
this.entire('views/base', {template: 'errors/404'}, view => {
view.render();
});
this.entire(view);
}
/**
* Error Forbidden.
*/
error403() {
this.entire('views/base', {template: 'errors/403'}, view => {
view.render();
});
const view = new BaseView({template: 'errors/403'});
this.entire(view);
}
}