{"version":3,"sources":["Honeywell.ClientModel.TemplateService.ts"],"names":["TemplateService","viewName","this","templatePath","queryString","cacheName","prototype","getTemplate","getCachedTemplate","undefined","Handlebars","templates","Q","$","ajax","url","then","data","compile","resolve","exports"],"mappings":"6HAIA,IAAAA,GAAA,WAGI,QAAAA,GAAmBC,GAAAC,KAAAD,SAAAA,EACfC,KAAKC,aAAe,8DAA8DF,EAAQ,IAAIG,YAC9FF,KAAKG,UAAYJ,EAwBzB,MAjBID,GAAAM,UAAAC,YAAA,WAEI,MAAOL,MAAKM,kBAAkBN,KAAKC,aAAcD,KAAKG,YAG1DL,EAAAM,UAAAE,kBAAA,SAAkBL,EAAcE,GAC5B,WAA6BI,KAAzBC,EAAWC,eAA+DF,KAApCC,EAAWC,UAAUN,GACpDO,EAAEC,EAAEC,MAAOC,IAAKZ,KAAiBa,KAAK,SAACC,GAG1C,MAFMP,GAAYC,UAAYD,EAAWC,cACzCD,EAAWC,UAAUN,GAAaK,EAAWQ,QAAQD,GAC9CP,EAAWC,UAAUN,KAIzBO,EAAEO,QAAQT,EAAWC,UAAUN,KAGlDL,IA7BaoB,GAAApB,gBAAAA","file":"Honeywell.ClientModel.TemplateService.js","sourcesContent":["import * as Q from \"q\";\r\nimport * as Handlebars from \"handlebars\";\r\ndeclare var queryString: string;\r\n\r\nexport class TemplateService {\r\n public templatePath: string;\r\n public cacheName: string;\r\n constructor(public viewName: string) {\r\n this.templatePath = `/_layouts/15/Honeywell.EmeaMost.Commerce.SP.Farm/templates/${viewName}?${queryString}`;\r\n this.cacheName = viewName;\r\n }\r\n\r\n /**\r\n * Get a template as string.\r\n * Returns a Promise\r\n */\r\n getTemplate(): Q.Promise {\r\n //Q() will convert JQueryXHR to a Promise. So this method is really a one-liner\r\n return this.getCachedTemplate(this.templatePath, this.cacheName);\r\n }\r\n\r\n getCachedTemplate(templatePath, cacheName) {\r\n if (Handlebars.templates === undefined || Handlebars.templates[cacheName] === undefined) {\r\n return Q($.ajax({ url: templatePath })).then((data) => {\r\n (Handlebars).templates = Handlebars.templates || {};\r\n Handlebars.templates[cacheName] = Handlebars.compile(data);\r\n return Handlebars.templates[cacheName];\r\n });\r\n }\r\n else {\r\n return Q.resolve(Handlebars.templates[cacheName]);\r\n }\r\n }\r\n}\r\n"]}