From 0c0a4da7d36c654da8458dc407646541e560c89f Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Sun, 16 Jul 2023 17:57:55 +0300 Subject: [PATCH] controller entire support view instance --- client/src/controller.js | 27 +++++++++++++++++++++++++-- client/src/controllers/base.js | 16 +++++++++------- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/client/src/controller.js b/client/src/controller.js index af185b4a59..0b6e5f36cf 100644 --- a/client/src/controller.js +++ b/client/src/controller.js @@ -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.} [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.} [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); }); } diff --git a/client/src/controllers/base.js b/client/src/controllers/base.js index f95ae5340c..e728883f7b 100644 --- a/client/src/controllers/base.js +++ b/client/src/controllers/base.js @@ -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); } }