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 console.log('TemplateManager_get:' + tplName);
33 if (this.cache[tplName] !== undefined) {
34 return this.getCompleted(this.cache[tplName], tplParams);
36 console.warn('Template "' + tplName + '" not found in cache');
42 * Load templates to cache
44 loadToCache: function TemplateManager_loadToCache(tplNames, onSuccess) {
50 if ($.isArray(tplNames)) {
53 $.each(tplNames, function (index, fileName) {
55 // cache template html
56 if (typeof self.cache[fileName] === 'undefined') {
57 tplName = [fileName, app.config.get('templateExtension')].join('');
58 tplPath = [app.config.get('templateDir'), tplName].join('/');
65 success: function (data) {
70 self.cache[fileName] = data;
71 console.log('Cached template: ' + fileName);
73 // if all templates are cached launch callback
74 if (cachedTemplates >= tplNames.length && typeof onSuccess === 'function') {
78 error: function (jqXHR, textStatus, errorThrown) {
83 // template is already cached
85 // if all templates are cached launch callback
86 if (cachedTemplates >= tplNames.length && typeof onSuccess === 'function') {
96 * Returns template completed by specified params
98 getCompleted: function TemplateManager_getCompleted(tplHtml, tplParams) {
99 var tplParam, replaceRegExp;
101 for (tplParam in tplParams) {
102 if (tplParams.hasOwnProperty(tplParam)) {
103 replaceRegExp = new RegExp(['%', tplParam, '%'].join(''), 'g');
104 tplHtml = tplHtml.replace(replaceRegExp, tplParams[tplParam]);