Skip to content

Commit

Permalink
ref
Browse files Browse the repository at this point in the history
  • Loading branch information
yurikuzn committed Jun 20, 2023
1 parent 56dd0aa commit cc32089
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 22 deletions.
42 changes: 28 additions & 14 deletions client/src/view-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ class ViewHelper {
* A Markdown text to HTML (one-line).
*
* @param {string} text A text.
* @returns {string} HTML.
* @returns {Handlebars.SafeString} HTML.
*/
transformMarkdownInlineText(text) {
return this.transformMarkdownText(text, {inline: true});
Expand Down Expand Up @@ -751,7 +751,7 @@ class ViewHelper {
/**
* Sanitize HTML.
*
* @param {type} text HTML.
* @param {string} text HTML.
* @param {Object} [options] Options.
* @returns {string}
*/
Expand Down Expand Up @@ -898,32 +898,44 @@ class ViewHelper {
* @param {module:view} view A view.
* @param {string} type A view-setup-handler type.
* @param {string} [scope] A scope.
* @return Promise
*/
processSetupHandlers(view, type, scope) {
scope = scope || view.scope;
scope = scope || view.scope || view.entityType;

let handlerList = this.metadata.get(['clientDefs', 'Global', 'viewSetupHandlers', type]) || [];
let handlerIdList = this.metadata.get(['clientDefs', 'Global', 'viewSetupHandlers', type]) || [];

if (scope) {
handlerList = handlerList
handlerIdList = handlerIdList
.concat(
this.metadata.get(['clientDefs', scope, 'viewSetupHandlers', type]) || []
);
}

if (handlerList.length === 0) {
return;
if (handlerIdList.length === 0) {
return Promise.resolve();
}

for (let handlerClassName of handlerList) {
let promise = new Promise(function (resolve) {
Espo.loader.require(handlerClassName, Handler => {
/**
* @interface
* @name ViewHelper~Handler
*/

/**
* @function
* @name ViewHelper~Handler#process
* @param {module:view} [view] Deprecated.
*/

let promiseList = [];

for (let id of handlerIdList) {
let promise = new Promise(resolve => {
Espo.loader.require(id, /** typeof ViewHelper~Handler */Handler => {
let result = (new Handler(view)).process(view);

if (result && Object.prototype.toString.call(result) === '[object Promise]') {
result.then(() => {
resolve();
});
result.then(() => resolve());

return;
}
Expand All @@ -932,8 +944,10 @@ class ViewHelper {
});
});

view.wait(promise);
promiseList.push(promise);
}

return Promise.all(promiseList);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion client/src/views/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ class DetailView extends MainView {
setupFinal() {
super.setupFinal();

this.getHelper().processSetupHandlers(this, 'detail');
this.wait(
this.getHelper().processSetupHandlers(this, 'detail')
);
}

/** @private */
Expand Down
4 changes: 3 additions & 1 deletion client/src/views/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ class EditView extends MainView {
setupFinal() {
super.setupFinal();

this.getHelper().processSetupHandlers(this, 'edit');
this.wait(
this.getHelper().processSetupHandlers(this, 'edit')
);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion client/src/views/list-related.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ class ListRelatedView extends MainView {
this.keepCurrentRootUrl = true;
}

this.getHelper().processSetupHandlers(this, 'list');
this.wait(
this.getHelper().processSetupHandlers(this, 'list')
);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion client/src/views/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ class ListView extends MainView {
setupFinal() {
super.setupFinal();

this.getHelper().processSetupHandlers(this, 'list');
this.wait(
this.getHelper().processSetupHandlers(this, 'list')
);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion client/src/views/record/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,9 @@ class DetailRecordView extends BaseRecordView {
});
}

this.getHelper().processSetupHandlers(this, this.setupHandlerType);
this.wait(
this.getHelper().processSetupHandlers(this, this.setupHandlerType)
);

this.initInlineEditDynamicWithLogicInteroperability();

Expand Down
4 changes: 3 additions & 1 deletion client/src/views/record/kanban.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ class KanbanRecordView extends ListRecordView {

this.isCreatable = this.statusFieldIsEditable && this.getAcl().check(this.entityType, 'create');

this.getHelper().processSetupHandlers(this, 'record/kanban');
this.wait(
this.getHelper().processSetupHandlers(this, 'record/kanban')
);
}

afterRender() {
Expand Down
4 changes: 3 additions & 1 deletion client/src/views/record/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,9 @@ class ListRecordView extends View {
this.layoutName += 'Portal';
}

this.getHelper().processSetupHandlers(this, this.setupHandlerType);
this.wait(
this.getHelper().processSetupHandlers(this, this.setupHandlerType)
);

this.listenTo(this.collection, 'sync', (c, r, options) => {
if (this.hasView('modal') && this.getView('modal').isRendered()) {
Expand Down
4 changes: 3 additions & 1 deletion client/src/views/record/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ class SearchView extends View {
this.controlResetButtonVisibility();
});

this.getHelper().processSetupHandlers(this, 'record/search');
this.wait(
this.getHelper().processSetupHandlers(this, 'record/search')
);
}

setupViewModeDataList() {
Expand Down

0 comments on commit cc32089

Please sign in to comment.