You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
8.0 KiB

define(["core/mustache","jquery","core/ajax","core/str","core/notification","core/url","core/config","core/localstorage","core/icon_system","core/event","core/yui","core/log","core/truncate","core/user_date","core/pending"],function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o){var p=0,q={},r={},s={},t={},u=[],v=!1,w=function(a){if(a in r)return r[a];if(a in q)return r[a]=b.Deferred().resolve(q[a]).promise(),r[a];var c=h.get("core_template/"+a);return c?(q[a]=c,r[a]=b.Deferred().resolve(c).promise(),r[a]):null},x=function(){if(u.length&&!v){v=!0;var a=u.slice(),e=b.Deferred(),f=[],g=a.map(function(a){var c=a.component,i=a.name,j=a.searchKey,k=a.theme,l=a.deferred,m=null,n=w(j);if(n)m=n;else{f.push({methodname:"core_output_load_template_with_dependencies",args:{component:c,template:i,themename:k,lang:b("html").attr("lang").replace(/-/g,"_")}});var o=f.length-1;m=e.promise().then(function(a){return g[j]=a[o].then(function(a){var b=null;return a.templates.forEach(function(a){var d=[k,a.component,a.name].join("/");q[d]=a.value,h.set("core_template/"+d,a.value),a.component==c&&a.name==i&&(b=a.value)}),a.strings.length&&d.cache_strings(a.strings.map(function(a){return{component:a.component,key:a.name,value:a.value}})),b}),g[j]})}return m.then(function(a){return l.resolve(a)})["catch"](function(a){throw l.reject(a),a})});f.length?e.resolve(c.call(f,!0,!1)):e.resolve(),b.when.apply(null,g).then(function(){u.splice(0,a.length),v=!1,x()})["catch"](function(){u.splice(0,a.length),v=!1,x()})}},y=function(){this.requiredStrings=[],this.requiredJS=[],this.requiredDates=[],this.currentThemeName=""};y.prototype.requiredStrings=null,y.prototype.requiredDates=[],y.prototype.requiredJS=null,y.prototype.currentThemeName="",y.prototype.getTemplate=function(a){var c=this.currentThemeName,d=c+"/"+a,e=w(d);if(e)return e;var f=u.filter(function(a){return a.searchKey==d});if(f.length)return f[0].deferred.promise();var g=a.split("/"),h=g.shift(),i=g.shift(),j=b.Deferred();return u.push({component:h,name:i,theme:c,searchKey:d,deferred:j}),x(),j.promise()},y.prototype.partialHelper=function(a){var b=this.currentThemeName+"/"+a;return b in q||e.exception(new Error("Failed to pre-fetch the template: "+a)),q[b]},y.prototype.renderIcon=function(a,c,d){var f=g.iconsystemmodule,h=b.Deferred();return require([f],function(a){var b=new a;b instanceof i?(t=b,b.init().then(h.resolve)["catch"](e.exception)):h.reject("Invalid icon system specified"+g.iconsystemmodule)}),h.then(function(a){return this.getTemplate(a.getTemplateName())}.bind(this)).then(function(b){return t.renderIcon(a,c,d,b)})},y.prototype.pixHelper=function(a,b,c){var d=b.split(","),e="",f="",g="";d.length>0&&(e=c(d.shift().trim(),a)),d.length>0&&(f=c(d.shift().trim(),a)),d.length>0&&(g=c(d.join(",").trim(),a));var h=t.getTemplateName(),i=this.currentThemeName+"/"+h,j=q[i];return e=e.replace(/&#x2F;/gi,"/"),t.renderIcon(e,f,g,j)},y.prototype.jsHelper=function(a,b,c){return this.requiredJS.push(c(b,a)),""},y.prototype.stringHelper=function(a,b,c){var d=b.split(","),e="",f="",g="";d.length>0&&(e=d.shift().trim()),d.length>0&&(f=d.shift().trim()),d.length>0&&(g=d.join(",").trim()),""!==g&&(g=c(g,a)),0===g.indexOf("{")&&0!==g.indexOf("{{")&&(g=JSON.parse(g));var h=this.requiredStrings.length;return this.requiredStrings.push({key:e,component:f,param:g}),"[[_s"+h+"]]"},y.prototype.quoteHelper=function(a,b,c){var d=c(b.trim(),a);return d=d.replace('"','\\"').replace(/([\{\}]{2,3})/g,"{{=<% %>=}}$1<%={{ }}=%>"),'"'+d+'"'},y.prototype.shortenTextHelper=function(a,b,c){var d=/(.*?),(.*)/,e=b.match(d),f=e[1].trim(),g=e[2].trim(),h=c(g,a);return m.truncate(h,{length:f,words:!0,ellipsis:"..."})},y.prototype.userDateHelper=function(a,b,c){var d=/(.*?),(.*)/,e=b.match(d),f=c(e[1].trim(),a),g=c(e[2].trim(),a),h=this.requiredDates.length;return this.requiredDates.push({timestamp:f,format:g}),"[[_t_"+h+"]]"},y.prototype.addHelpers=function(a,b){this.currentThemeName=b,this.requiredStrings=[],this.requiredJS=[],a.uniqid=p++,a.str=function(){return this.stringHelper.bind(this,a)}.bind(this),a.pix=function(){return this.pixHelper