(function(){var e={};var t;var r=1024;var a=1024*r;page.using={texts:["upgrade_doc"]};page.onLoad=function(){u8.request("MailMergeChannel.GetDocumentCacheState",null,function(e,r){t=r.response?r.response.documentCacheState:{};d()})};function d(){var r=[$t("TXT_upgrade_doc_6"),$t("TXT_upgrade_doc_19"),$t("TXT_upgrade_doc_7"),$t("TXT_upgrade_doc_8"),$t("TXT_upgrade_doc_9"),$t("TXT_upgrade_doc_11"),$t("TXT_upgrade_doc_15"),$t("TXT_upgrade_doc_16"),$t("TXT_upgrade_doc_12")];var a="<table cellpadding='3' cellspacing='1' class='clsCaption' border='0'><tr style='background-color:gray'>";for(var d=0;d<r.length;d++){a+="<td class='clsListHeader' style='padding-left:4px; padding-right:10px'><b>"+r[d]+"</b></td>"}a+="</tr>";var i,s=false;var l=t.documentGroups;for(d=0;d<l.length;d++){var f=l[d];var m=f.documents;for(var g=0;g<m.length;g++){var p=m[g];var _=m[g].languageFormatNames||[];for(var v=0;v<_.length;v++){var T=_[v];var h=true;if(v>0){for(var b=0;h&&b<v;b++){if(_[b].crmFormatName==T.crmFormatName){h=false}}}if(!h){continue}var X=o(T.crmFormatName);if(!X){continue}if(s){i="<tr class='clsListLine'><td>";s=false}else{i="<tr class='clsListLine2'><td>";s=true}if(g==0){i+=f.infoAreaId+"</td><td>"+f.name}else{i+="</td><td>"}i+="</td><td>";if(v==0){i+=p.label}i+="</td><td>"+T.crmFormatName+"</td><td>";var F=u8.Base.Dom.uniqueId();e[F]=X;i+=(X.documentKey||"")+"</td><td>"+u8.services.typeConverter.dateToString(X.lastWriteTime,"Date Time")+"</td><td><div id='"+F+"_state'";if(X.state=="Equal"){i+=" class='u8-updatedocuments-equal'>"+$t("TXT_upgrade_doc_17")}else if(X.state=="Different"){i+=" class='u8-updatedocuments-diff'>"+$t("TXT_upgrade_doc_18")}else{i+=" class='u8-updatedocuments-missing'>"+$t("TXT_upgrade_doc_20")}i+="</div></td><td align='right'>";i+=n(X.sizeInBytes);i+="</td><td>";if(X.formatRecordId){i+="<input type='checkbox' id='"+F+"'";if(X.state!="Equal"){i+=" checked"}i+=" />"}i+="</td></tr>";a+=i}}}a+="</table><br /><br />";a+="<button id='buttonUpdate'></button>";$("#list").html(a);$("#list").find("input:checkbox").click(u);var N=new u8.Base.Widgets.Button($("#buttonUpdate")[0],{onClick:c,text:$t("TXT_upgrade_doc_2"),parent:page})}function n(e){if(!e){return""}else if(e>=a){return Math.round(e/a)+"MB"}else if(e>=r){return Math.round(e/r)+"KB"}return e+"B"}function o(e){var r=t.items;for(var a=0;a<r.length;a++){if(r[a].crmFormatName==e){return r[a]}}return null}function u(t){var r=$(t.currentTarget).is(":checked");var a=e[t.currentTarget.id];for(var d in e){var n=e[d];if(n.crmFormatName!=a.crmFormatName){continue}$("#"+d).prop("checked",r)}}var i=true;function c(t,r){if(!i){return}i=false;t.setDisabled(true);for(var a in e){e[a].isUpgrading=0}s()}function s(){for(var t in e){var r=e[t];if(r.isUpgrading!==0){continue}if(!r.formatRecordId){continue}var a=$("#"+t).is(":checked");if(!a){continue}r.isUpgrading=1;u8.request("MailMergeChannel.UpdateTemplateDocumentInCache",{mailingFormatRecordId:r.formatRecordId},function(e,r){f(t,r.error?true:false);s()});return}l()}function l(){$widget("buttonUpdate").setDisabled(false);i=true}function f(t,r){var a=e[t];for(t in e){var d=e[t];if(d.crmFormatName!=a.crmFormatName){continue}$("#"+t).remove();$("#"+t+"_state").attr("className",r?"u8-updatedocuments-equal":"u8-updatedocuments-error").text($(r?"TXT_upgrade_doc_17":"TXT_upgrade_doc_21"))}}})();