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C7C,CAAC;IACL,CAAC,EA/EgB,uBAAuB,GAAvB,+BAAuB,KAAvB,+BAAuB,QA+EvC","file":"ConfigurableTextService.js","sourcesContent":["import * as $ from \"jquery\";\r\nimport * as _ from \"underscore\";\r\nimport * as globalConfig from \"globalConfig\";\r\n\r\nexport namespace ConfigurableTextService {\r\n const ConfigurableTextCacheDetails = {} as any;\r\n\r\n export function RetrieveTextSync(stockTextKey: string, locationId: number = null): string {\r\n let stockText = null as string;\r\n\r\n RetrieveText(stockTextKey, false, locationId)\r\n .done((response: string) => {\r\n stockText = response;\r\n });\r\n\r\n return stockText;\r\n }\r\n\r\n export function RetrieveTextAsync(stockTextKey: string, locationId: number = null): Promise {\r\n return new Promise((resolve, reject) => {\r\n RetrieveText(stockTextKey, true, locationId)\r\n .then(resolve)\r\n .fail(reject);\r\n });\r\n }\r\n\r\n export function SetTextAsync(stockTextKey: string, callback: any, locationId: number = null): void {\r\n RetrieveText(stockTextKey, false, locationId)\r\n .then((response: string) => {\r\n callback(response);\r\n });\r\n }\r\n\r\n\r\n type StringDictionary = { [key:string] : T }\r\n export function RetrieveBulkTextAsync(stockTextKeys: Array, locationId: number = null): Promise> {\r\n const op = RetrieveText(stockTextKeys.join(';'), true, locationId);\r\n\r\n var promise = new Promise((done, reject) => {\r\n op.then(done).fail(reject)\r\n });\r\n\r\n return promise.then((data) => {\r\n var output: StringDictionary = {};\r\n\r\n _.each(data, (value, key) => {\r\n output[key] = value;\r\n })\r\n\r\n return output;\r\n });\r\n }\r\n\r\n //This method can't currently be converted over to native promises due to the comment below and the use of non-async code in this method via the isAsync flag.\r\n function RetrieveText(stockTextKey: string, isAsync = false, locationId: number = null): JQueryDeferred {\r\n let key = `${stockTextKey}-ASYNC-${isAsync}`;\r\n\r\n let url = globalConfig.Urls.ConfigurableText.Get\r\n .replace(\"{macroName}\", stockTextKey);\r\n\r\n if (locationId) {\r\n url += `?locationId=${locationId}`;\r\n key += `-locationId-${locationId}`;\r\n }\r\n\r\n if (!ConfigurableTextCacheDetails[key]) {\r\n // Important : We shouldn't really be doing any synchronous calls via an AJAX request, all of them should be\r\n // asynchronous. v1.8 of jQuery deprecated this when dealing with deferred called using the `then`\r\n // callback. The only way to get around this in v3.* and onwards is to use `done` instead, however\r\n // this goes against the promise pipeline and standards. At some point in the future this is going\r\n // to need refactoring to be fully asyncronous.\r\n // Source : https://jquery.com/upgrade-guide/3.0/#callback-invocation\r\n ConfigurableTextCacheDetails[key] = $.ajax({\r\n type: \"GET\",\r\n url: url,\r\n dataType: \"JSON\",\r\n async: isAsync,\r\n cache: true\r\n });\r\n }\r\n\r\n return ConfigurableTextCacheDetails[key];\r\n }\r\n}"]}