2 /*global tizen, $, app */
4 * @class TemplateManager
6 function TemplateManager() {
11 (function () { // strict mode wrapper
13 TemplateManager.prototype = {
21 * UI module initialisation
23 init: function init() {
28 * Returns template html (from cache)
30 get: function TemplateManager_get(tplName, tplParams) {
31 if (this.cache[tplName] !== undefined) {
32 return this.getCompleted(this.cache[tplName], tplParams);
38 * Load templates to cache
40 loadToCache: function TemplateManager_loadToCache(tplNames, onSuccess) {
46 if ($.isArray(tplNames)) {
49 $.each(tplNames, function (index, fileName) {
51 // cache template html
52 if (self.cache[fileName] === undefined) {
53 tplName = [fileName, app.config.get('templateExtension')].join('');
54 tplPath = [app.config.get('templateDir'), tplName].join('/');
61 success: function (data) {
66 self.cache[fileName] = data;
68 // if all templates are cached launch callback
69 if (cachedTemplates >= tplNames.length && typeof onSuccess === 'function') {
73 error: function (jqXHR, textStatus, errorThrown) {
74 console.error('templateManagerError: ' + errorThrown);
78 // template is already cached
80 // if all templates are cached launch callback
81 if (cachedTemplates >= tplNames.length && typeof onSuccess === 'function') {
91 * Returns template completed by specified params
93 getCompleted: function TemplateManager_getCompleted(tplHtml, tplParams) {
94 var tplParam, replaceRegExp;
96 for (tplParam in tplParams) {
97 if (tplParams.hasOwnProperty(tplParam)) {
98 replaceRegExp = new RegExp(['%', tplParam, '%'].join(''), 'g');
99 tplHtml = tplHtml.replace(replaceRegExp, tplParams[tplParam]);