1 line
2.6 KiB
JavaScript
1 line
2.6 KiB
JavaScript
(function(n,t,i){i(function(){let u=null;const r=i("#Document_Generation_Container"),f=r.find("#Document_Generate"),e=r.attr("data-targetid"),y=r.attr("data-targettype"),h=r.attr("data-generatepdfurl"),c=r.attr("data-generatepackageurl"),l=r.attr("data-handlerspresent")==="true",a=r.attr("data-handlersurl");let n=null,o=null;const s=function(n){let f=h;n.lastIndexOf("Package:",0)===0&&(n+n.substring(8),f=c);u||(u=i("<iframe>").attr("title","Document Generation Host").addClass("hidden").appendTo("body").contents(),u[0].body.innerHTML='<form method="post"><input type="hidden" name="__RequestVerificationToken" value="'+t.body.dataset.antiforgery+'"><input type="hidden" name="id"><input type="hidden" name="targetId"><\/form>');const r=u[0].forms[0];r.action=f;r.id.value=n;r.targetId.value=e;r.submit()},v=function(r){const f=n.find(".handlerPicker"),o=n.find("#Document_Generation_Dialog_Handlers_Loading");f.find("div.handler").remove();o.show();var u=new FormData;u.append("__RequestVerificationToken",t.body.dataset.antiforgery);u.append("templateId",decodeURI(r));u.append("targetId",decodeURI(e));fetch(a,{method:"POST",body:u}).then(n=>n.json()).then(n=>{o.hide(),i.each(n.Handlers,(n,t)=>{i('<div class="handler">').text(t.Title).attr({"data-id":t.Id,"data-uiurl":t.UiUrl}).prepend(i('<i class="fa fa-fw fa-lg">').addClass("fa-"+t.Icon)).appendTo(f)})})};f.change(function(){var u=f.val();if(u){if(o=u,l){if(!n){n=r.find("#Document_Generation_Dialog");n.dialog({width:750,height:500,resizable:!1,modal:!0,autoOpen:!1,buttons:{Cancel:function(){i(this).dialog("close")}}});n.find("#Document_Generation_Dialog_Download").click(t=>(t.preventDefault(),s(o),n.dialog("close"),!1));const f=n.find(".handlerPicker"),e=n.find("#Document_Generation_Dialog_Download_Container"),u=n.find("#Document_Generation_Dialog_HandlerUI");f.on("click","div[data-id]",n=>{f.find("div").removeClass("selected");const r=i(n.currentTarget);r.addClass("selected");const o=r.attr("data-id");if(o==="download")e.show(),u.hide(),u.empty();else{e.hide();u.empty();u.show();const i=r.attr("data-uiurl"),n=new FormData;n.append("__RequestVerificationToken",t.body.dataset.antiforgery);fetch(i,{method:"POST",body:n}).then(n=>n.text()).then(n=>{u.html(n)})}})}const e=n.find(".handlerPicker"),c=n.find("#Document_Generation_Dialog_Download_Container"),h=n.find("#Document_Generation_Dialog_HandlerUI");e.find("div").removeClass("selected");e.find("div[data-id=download]").addClass("selected");c.show();h.hide();h.empty();n.dialog("option","title","Generate Document: "+f[0].selectedOptions[0].label);n.dialog("open");v(u)}else s(u);f.val("").blur()}})})})(window,document,$); |