UNPKG

co2offset

Version:

Greenhouse Gas Accounting - ISO14064

1 lines 3.41 kB
void 0===window.app&&(window.app={});const app=async function(){$("#searchFrm").submit((function(e){window.app.renderSearchResults(),e.preventDefault()})),$("#hdrInfo").hide(),$(".hdrinfo").hide();const e=await widget_inventory(),c=await window.app.renderCertificates();let t="";for(const[c,a]of Object.entries(e))for(const[e,c]of Object.entries(a))t+="<li>"+e+"</li>";$("#includedEstimates").html(t);let a=await window.co2accounting.createViewAccount();$("#shareLink").val("https://co2offset.io/app/share.html?a="+a.view),$("#shareLinkCerts").val("https://co2offset.io/app/share.html?a="+a.view);let s=await window.co2accounting.keyValue();for(const[e,c]of Object.entries(s))$("#"+e).val(c);let o=await window.co2accounting.balance({subbalances:!0});void 0===o.isAlias&&window.co2accounting.isOnline?$("#viewOnlyAlert").hide():($("#viewOnlyAlert").show(),$("#accordionSidebar").hide(),$("#loginNav").show(),$("#navDashboard").show(),$("#navPledge").show());let i=0;void 0!==o.subbalances.scopes.scope_1&&(i+=1*o.subbalances.scopes.scope_1.liabilities,$("#chk_scope1included").attr("checked","checked"),$("#reportedCO2Scope1").val((1*o.subbalances.scopes.scope_1.liabilities/1e6).toFixed(2))),void 0!==o.subbalances.scopes.scope_2&&(i+=1*o.subbalances.scopes.scope_2.liabilities,$("#chk_scope2included").attr("checked","checked"),$("#reportedCO2Scope2").val((1*o.subbalances.scopes.scope_2.liabilities/1e6).toFixed(2))),void 0!==o.subbalances.scopes.scope_3&&(i+=1*o.subbalances.scopes.scope_3.liabilities,$("#chk_scope3included").attr("checked","checked"),$("#reportedCO2Scope2").val((1*o.subbalances.scopes.scope_3.liabilities/1e6).toFixed(2))),$("#reportedCO2eq").val((i/1e6).toFixed(2)),$(".metaInfo").change((async function(e){$("#saveBadge").show();let c={};c[$(this).attr("name")]=$(this).val(),"checkbox"==$(this).attr("type")&&($(this).is(":checked")||(c[$(this).attr("name")]="")),s=await window.co2accounting.keyValue(c),$("#saveBadge").hide()}));let n=$("input[type=checkbox]");for(let e=0;e<n.length;e++)void 0!==s[$(n[e]).attr("name")]&&s[$(n[e]).attr("name")].length>0?$(n[e]).attr("checked","checked"):$(n[e]).removeAttr("checked");n=$("input[type=radio]");for(let e=0;e<n.length;e++)void 0!==s[$(n[e]).attr("name")]&&s[$(n[e]).attr("name")]==$(n[e]).val()&&$(n[e]).attr("checked","checked");const l=function(){let e=$(".offsetSum"),c=0;for(let t=0;t<e.length;t++)c+=1*$(e[t]).val();$("#offset_TOTAL").val(c),c*=1e6,c>i?($("#scope1_offset").attr("checked","checked"),$("#scope2_offset").attr("checked","checked"),$("#scope3_offset").attr("checked","checked"),$("#scop3_offset_full").attr("checked","checked")):c>1*o.subbalances.scopes.scope_1.liabilities?$("#scope1_offset").attr("checked","checked"):c>1*o.subbalances.scopes.scope_2.liabilities?$("#scope2_offset").attr("checked","checked"):c>1*o.subbalances.scopes.scope_3.liabilities?$("#scop3_offset_full").attr("checked","checked"):$("#scope3_offset").attr("checked","checked")};if($(".offsetSum").change(l),0==c.length)$("#RadnoContrib").attr("checked","checked");else{$("#partComp").attr("checked","checked"),$("#chk_ch-10").attr("checked","checked"),$("#chk_ch-12").attr("checked","checked");let e=0,t=0;for(let a=0;a<c.length;a++)e+=1*c[a].co2requested,t+=1*c[a].co2;$("#offset_GS").val(e/1e6),$("#offset_OTHER").val(t/1e6),l()}$("#btnRefreshCache").click((async function(){await window.app.clearCache(),location.href="./index.html"}))};