ajsfw
Version:
Ajs Framework
83 lines (82 loc) • 3.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var logger = require("ajsfw/dbg/logger");
var Template_1 = require("./Template");
var TemplateManager = (function () {
function TemplateManager(resourceManager) {
this.__resourceManager = resourceManager;
this.__templates = {};
this.__visualComponents = {};
}
TemplateManager.prototype.loadTemplates = function (paths, storageType, cachePolicy, loadingPreference) {
var _this = this;
logger.log(logger.LogType.Enter, 0, "ajs.templating", this);
logger.log(logger.LogType.Exit, 0, "ajs.templating", this);
if (!(paths instanceof Array)) {
paths = [];
}
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
var templates, resourcePromises, i, resources_1, styleSheetLoaders, i, template, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
templates = [];
_a.label = 1;
case 1:
_a.trys.push([1, 4, , 5]);
resourcePromises = [];
for (i = 0; i < paths.length; i++) {
resourcePromises.push(this.__resourceManager.getResource(paths[i], storageType, cachePolicy, loadingPreference));
}
return [4, Promise.all(resourcePromises)];
case 2:
resources_1 = _a.sent();
styleSheetLoaders = [];
for (i = 0; i < resources_1.length; i++) {
template = new Template_1.Template(this.__resourceManager, this, resources_1[i], storageType, cachePolicy, loadingPreference);
templates.push(template);
styleSheetLoaders.push(template.loadStyleSheets());
}
return [4, Promise.all(styleSheetLoaders)];
case 3:
_a.sent();
return [3, 5];
case 4:
e_1 = _a.sent();
reject(e_1);
return [3, 5];
case 5:
resolve(templates);
return [2];
}
});
}); });
};
TemplateManager.prototype.getTemplate = function (name) {
if (this.__templates.hasOwnProperty(name)) {
return this.__templates[name];
}
return null;
};
TemplateManager.prototype.registerVisualComponent = function (name, visualComponent) {
if (visualComponent && visualComponent !== null) {
this.__visualComponents[name] = visualComponent;
}
};
TemplateManager.prototype.getVisualComponent = function (name) {
if (this.__visualComponents.hasOwnProperty(name.toUpperCase())) {
return this.__visualComponents[name.toUpperCase()];
}
return null;
};
TemplateManager.prototype.getVisualComponentTemplate = function (name) {
if (this.__visualComponents.hasOwnProperty(name)) {
var templateName = this.__visualComponents[name].templateName;
var template = this.getTemplate(templateName);
return template;
}
return null;
};
return TemplateManager;
}());
exports.TemplateManager = TemplateManager;