var Portal=Portal||{};Portal.MeetingTypeListEvents=Portal.MeetingTypeListEvents||{};Portal.MeetingTypeList=function(n){var s=n.trackerWindowClientId,it=n.titleContainerClientId,rt=n.descriptionContainerClientId,h=n.editPortalItemWindowClientId,i=n.titleTextBoxClientId,y=n.descriptionEditorClientId,r=n.otherCulture,ut=n.currentCulture,u=n.titleTextBoxOtherCultureClientId,p=n.descriptionOtherCultureEditorClientId,ft=n.editItemOtherCulture,et=n.editButtonClientId,bt=n.saveButtonClientId,ot=n.currentUserPublic,e=30,w=n.meetingTypeContainerClientId,c={titleTextTooLongWarning:n.localization.titleTextTooLongWarning,orderSaveSuccessMessage:n.localization.orderSaveSuccess,orderSaveFailMessage:n.localization.orderSaveFail},l=n.referenceNames,b=n.meetingTypePortalItems,d=n.portalItemId,f=n.boardApplicationTrackers,a=!1,o={title:"",summary:"",description:""},t=0,kt=function(n){$(document.getElementById(i)).prop("disabled","");r&&$(document.getElementById(u)).prop("disabled","");t=0;st();$(document.getElementById("title-count-container")).removeClass("hidden");$(document.getElementById("title-count-other-culture-container")).removeClass("hidden");g();n.preventDefault()},g=function(){var t=window.$find(h),i,n,u;if(t){for($("#"+ft).show(),v(t,r?Math.max($(window).width()*.9,660):650),t.show(),i=window.$telerik.radControls,n=0;n<i.length;n++)u=i[n],window.Telerik.Web.UI.RadEditor&&u instanceof window.Telerik.Web.UI.RadEditor&&u.onParentNodeChanged();wt()}},v=function(n,t){if(n){var i=$(window);n.set_height(Math.max(i.height()*.9,600));n.set_width(t)}},dt=function(n){$(document.getElementById(i)).prop("disabled","disabled");r&&$(document.getElementById(u)).prop("disabled","disabled");ht();t=parseInt($(n.target).attr("data-id"));nt(k(t));$(document.getElementById("title-count-container")).addClass("hidden");$(document.getElementById("title-count-other-culture-container")).addClass("hidden");g();n.preventDefault()},k=function(n){var i=null,t;if(n)for(t=0;t<b.length;t++)if(n===b[t].id){i=b[t];break}return i},nt=function(n){var t,f;n&&($(document.getElementById(i)).val(n.title),t=window.$find(y),t&&t.set_html(n.description),r&&($(document.getElementById(u)).val(n.titleOtherCulture),f=window.$find(p),f&&f.set_html(n.descriptionOtherCulture)))},st=function(){a&&(nt(o),a=!1)},gt=function(n){var f=$(document.getElementById(i)).val(),s=window.$find(y),o="",a,v,w,b;s&&s.set_html(o=Portal.MasterPagePage.fixEditorHtml(s.get_html(!0)));t>0?(a=k(t),a.title=f,a.description=o,v=$('span[data-id="'+t.toString()+'"]').closest(".item-template"),v.find(".meeting-type-item-title").text(f),v.find(".meeting-type-item-description").html(o)):($(document.getElementById(it)).text(f.length>0?f:c.defaultTitleText),$(document.getElementById(rt)).html(o));w=window.$find(h);w&&w.close();f.length>e&&t===0?alert(c.titleTextTooLongWarning):(b=[{Id:0,ReferenceName:l.title,Value:f},{Id:0,ReferenceName:l.description,Value:o}],$.ajax({url:"/Services/ItemsService.svc/items/"+(t>0?t:d).toString()+"/fieldupdate?culture="+ut,contentType:"application/json",dataType:"json",async:!0,type:"POST",timeout:3e4,data:JSON.stringify(b),success:function(){var f,s,e;if(r){var o=$(document.getElementById(u)).val(),n=window.$find(p),i="";n&&n.set_html(i=Portal.MasterPagePage.fixEditorHtml(n.get_html(!0)));t>0&&(f=k(t),f.titleOtherCulture=o,f.descriptionOtherCulture=i);s=[{Id:0,ReferenceName:l.title,Value:o},{Id:0,ReferenceName:l.description,Value:i}];$.ajax({url:"/Services/ItemsService.svc/items/"+(t>0?t:d).toString()+"/fieldupdate?culture="+r,contentType:"application/json",dataType:"json",async:!0,type:"POST",timeout:3e4,data:JSON.stringify(s),success:function(){var n=window.$find(h);n&&n.close()},error:function(){}})}else e=window.$find(h),e&&e.close();t=0},error:function(){}}));n.preventDefault()},ht=function(){var n,t;a||(o.title=$(document.getElementById(i)).val(),n=window.$find(y),n&&n.set_html(o.description=Portal.MasterPagePage.fixEditorHtml(n.get_html(!0))),r&&(o.titleOtherCulture=$(document.getElementById(u)).val(),t=window.$find(p),t&&t.set_html(o.descriptionOtherCulture=Portal.MasterPagePage.fixEditorHtml(t.get_html(!0)))),a=!0)},ct=function(){$("#orderSaveMessage").text(c.orderSaveSuccessMessage);$("#orderSaveMessage").show();window.setTimeout(function(){$("#orderSaveMessage").hide()},2e3)},lt=function(){$("#orderSaveMessage").text(c.orderSaveFailMessage);$("#orderSaveMessage").show();window.setTimeout(function(){$("#orderSaveMessage").hide()},2e3)},at=function(){var r=$(this).attr("data-meetingtype-id"),u,t,i,e,n;if(f&&f.length>1&&$("#board-application-trackers option").length==1){for(u=$(document.getElementById("board-application-trackers")).attr({"data-meetingtype-id":r}),$(document.getElementById("board-application-select-container")).removeClass("hidden"),t=0;t<f.length;t++)i=f[t],u.append($("<option>",{value:i.id}).html(i.name));n=window.$find(s);n&&($("#trackerWindowClientId").find("iframe").remove(),v(n,720),n.show())}else f&&f.length>0&&($(document.getElementById("board-application-select-container")).addClass("hidden"),e=f[0].id,n=window.$find(s),n&&(v(n,720),n.setUrl("/Items/Item/public.aspx?TypeId="+e.toString()+"&mtId="+r.toString()),n.show()))},vt=function(){var i=$(document.getElementById("board-application-trackers")).attr("data-meetingtype-id"),t=$(document.getElementById("board-application-trackers")).val(),n=window.$find(s);t>0&&n&&(v(n,720),n.setUrl("/Items/Item/public.aspx?TypeId="+t.toString()+"&mtId="+i.toString()),$(document.getElementById("board-application-select-container")).addClass("hidden"))};this.setBlocksHeight=function(){for(var i,r,t=$(".item-template:nth-child(odd)"),u=$(".item-template:nth-child(even)"),n=0;n<t.length;n++)i=$(t[n]).height(),r=$(u[n]).height(),i>r?$(u[n]).height(i):$(t[n]).height(r)};this.setPortalItemOrder=function(){for(var t,r=$("[id="+w+"]").find("[id$=PortalItemId]"),i=[],n=0;n<r.length;n++)t={},t.Id=Number(r[n].value),t.Order=n,i.push(t);i.length>0&&$.ajax({type:"POST",url:"/Services/ItemsService.svc/portal/setOrder",contentType:"application/json; charset=utf-8",dataType:"json",async:!0,data:JSON.stringify(i),success:function(){ct()},error:function(){lt()}})};this.PortalCloseRadTrackerWindow=function(){var n=window.$find(s);n&&n.setUrl("/Global/Images/indicator_medium.gif")};var yt=function(){$(".list-content").sortable({distance:15,helper:"clone",start:function(){$(".meeting-type-item-description").css({height:"10em",overflow:"hidden"});$(".item-template").css({height:"25em",width:$(document.getElementById(w)).width()*.49+"px"})},stop:function(){$(".meeting-type-item-description").css({height:"",overflow:""});$(".item-template").css({height:""});Portal.MeetingTypeListPage.events.setPortalItemOrder();Portal.MeetingTypeListPage.events.setBlocksHeight();tt()}});$(".list-content").disableSelection();$(".meeting-type-title").addClass("meeting-type-move")},pt=function(){for(var r,t=$(".portal-content").find(".item-title"),i=0,n=0;n<t.length;n++)if($(t[n]).height()>i&&(i=$(t[n]).height()),n>0&&n%2>0){for(r=n-1;r<n+1;r++)i>0&&($(t[r]).height(i),$(t[r]).find(".meeting-type-item-title").css({position:"absolute",top:"50%",left:"50%","margin-right":"-50%",transform:"translate(-50%, -50%)"}));i=0}},wt=function(){setTimeout(function(){var n=$(document.getElementById(i)).val();$(document.getElementById("tile-item-title-editor-characters")).text(e-n.length);$(document.getElementById(i)).off("keyup").on("keyup",function(){var n=e-$(document.getElementById(i)).val().length;$(document.getElementById("tile-item-title-editor-characters")).text(n);$(document.getElementById("tile-item-title-editor-characters")).css("color",n<0?"red":"")});if(r){n=$(document.getElementById(u)).val();$(document.getElementById("other-culture-tile-item-title-editor-characters")).text(e-n.length);$(document.getElementById(u)).off("keyup").on("keyup",function(){var n=e-$(document.getElementById(u)).val().length;$(document.getElementById("other-culture-tile-item-title-editor-characters")).text(n);$(document.getElementById("other-culture-tile-item-title-editor-characters")).css("color",n<0?"red":"")})}},0)},tt=function(){var n=$(".item-template");n.length%2!=0&&$(n[n.length-1]).width("100%")};(function(){if(CivicWeb.Portal&&CivicWeb.Portal.EditItemControl){$(document.getElementById(et)).off("click").on("click",CivicWeb.Portal.EditItemControl.openItem);var n=$(document.getElementById(w));n.find(".edit-button").off("click").on("click",CivicWeb.Portal.EditItemControl.openItem)}ot!==!0&&yt();$("button.apply-button").off("click").on("click",at);$(document.getElementById("board-application-trackers")).off("change").on("change",vt);pt();tt()})()};Portal.MeetingTypeListPage={instance:null,createInstance:function(n){this.instance&&delete this.instance;this.instance=new Portal.MeetingTypeList(n)},events:{setPortalItemOrder:function(){Portal.MeetingTypeListPage.instance.setPortalItemOrder()},setBlocksHeight:function(){Portal.MeetingTypeListPage.instance.setBlocksHeight()},OnClientPasteHtml:function(n,t){Portal.MeetingTypeListPage.instance.OnClientPasteHtml(n,t)},OnClientCloseRadTrackerWindow:function(){Portal.MeetingTypeListPage.instance.PortalCloseRadTrackerWindow()}}}