(function(){var adjustScrollTop=function(){var controlMenu;var controlMenuId;var controlMenuScroll;var errorFieldLabel;var labelScroll;errorFieldLabel=document.querySelector(".form-group.has-error .control-label");if(errorFieldLabel){labelScroll=errorFieldLabel.clientHeight||0;window.scrollBy(0,-labelScroll)}if(Liferay.ControlMenu){controlMenuId=Liferay.ControlMenu._namespace+"ControlMenu";controlMenu=document.getElementById(controlMenuId);if(controlMenu){controlMenuScroll=controlMenu.offsetHeight||
0;window.scrollBy(0,-controlMenuScroll)}}};var handleFormRegistered=function(event){if(event.form&&event.form.formValidator)AUI().Do.after(adjustScrollTop,event.form.formValidator,"focusInvalidField")};Liferay.on("form:registered",handleFormRegistered)})();
$(document).ready(function(){$(document).on("change","#addressPicker-address-propertyId",function(){if($(this).val())$("#registration-terms-submit").show();else $("#registration-terms-submit").hide()});$(document).on("focus",".input-checkbox-wrapper input",function(){$(this).parents(".input-checkbox-wrapper").addClass("labelfocus")});$(document).on("focusout",".input-checkbox-wrapper input",function(){$(this).parents(".input-checkbox-wrapper").removeClass("labelfocus")});$(document).on("click",".input-checkbox-wrapper input",
function(){if(this.checked){$(this).parents(".input-checkbox-wrapper").removeClass("labelfocus");$(this).parents(".input-checkbox-wrapper").addClass("focusBorder");$(this).parents(".input-checkbox-wrapper").removeClass("has-error");$(this).parents(".input-checkbox-wrapper").children(".help-block").remove()}else{$(this).parents(".input-checkbox-wrapper").removeClass("focusBorder");$(this).parents(".input-checkbox-wrapper").removeClass("labelfocus")}});$(document).on("mousedown","#uk-gov-camden-registration .btn-primary",
function(){$("#uk-gov-camden-registration .btn-primary").click()});$(document).on("focusin","#uk-gov-camden-registration .btn-primary",function(){$("#uk-gov-camden-registration .has-error input.field").first().focus()});$(document).on("cut copy paste","#uk-gov-camden-registration .email-address-2-wrapper input",function(e){e.preventDefault()});if($("#addressPicker-address-propertyId").val())$("#registration-terms-submit").show()});
$(document).ready(function(){$(document).on("click",".btn-find-address",function(){var id="#"+$(this).attr("data-address-picker-id");var postcode=$(id+"-postcodeDivId input").val();var buildingName=$(id+"-buildingNumberDivId input").val();var resourceUrl=$(id+"-searchResourceUrl").val();var source=$(id+"-source").val();$(this).blur();if(validateFields(postcode,buildingName,id))$.ajax({url:resourceUrl,data:{"_uk_gov_camden_address_lookup_web_AddressLookupPortlet_postcode":postcode,"_uk_gov_camden_address_lookup_web_AddressLookupPortlet_buildingName":buildingName,
"_uk_gov_camden_address_lookup_web_AddressLookupPortlet_source":source},dataType:"json",method:"GET",success:function(result){var exception=result.exception;if(typeof exception!=="undefined"){var html='\x3cdiv class\x3d"portlet-msg-info"\x3e'+exception+"\x3c/div\x3e";$(id+" .addressSelect").empty().hide();$(id+" .addressException").html(html)}else{var html="";for(i=0;i<result.length;i++){var address=result[i];var propertyId=address.propertyId?address.propertyId:"";var addressId=address.addressId?
address.addressId:"";var addressSource=address.addressSource?address.addressSource:"";html+='\x3cli\x3e\x3ca href\x3d"" data-address-property-id\x3d"'+propertyId+'" data-address-address-id\x3d"'+addressId+'" data-address-source\x3d"'+addressSource+'" \x3e'+address.addressFull+"\x3c/a\x3e\x3c/li\x3e"}$(id+" .addressSelect").html(html).show();$(id+" .addressException").empty()}$(id+" .addressList").show();$(id+" .addressList").focus()}})});function validateFields(postcode,buildingName,id){var valid=
true;if(!postcode){$(id+" .postcodeError").show();$(id+"-postcodeDivId").addClass("has-error");$(id+"-postcodeDivId input").focus();valid=false}else{$(id+" .postcodeError").hide();$(id+"-postcodeDivId").removeClass("has-error")}if(!buildingName){$(id+" .buildingNumberError").show();$(id+"-buildingNumberDivId").addClass("has-error");if(valid)$(id+"-buildingNumberDivId input").focus();valid=false}else{$(id+" .buildingNumberError").hide();$(id+"-buildingNumberDivId").removeClass("has-error")}return valid}
function removeAddresspickerHack(addressPickerId){inputHack=$(".addressPickerHack");parentForm=inputHack.length>0?inputHack[0].form:$();Liferay.Form.get(parentForm.name).formValidator.get("rules")[inputHack[0].name].required=false}function addAddresspickerHack(addressPickerId){inputHack=$(".addressPickerHack");parentForm=inputHack.length>0?inputHack[0].form:$();Liferay.Form.get(parentForm.name).formValidator.get("rules")[inputHack[0].name].required=true}$(document).on("click",".addressSelect a",function(){var propertyId=
$(this).attr("data-address-property-id");var addressId=$(this).attr("data-address-address-id");var id="#"+$(this).parents(".addressSelect").attr("data-address-picker-id");var addressSource=$(this).attr("data-address-source");var source=$(id+"-source").val();var resourceUrl=$(id+"-retrievalResourceUrl").val();var namespace="#"+$(id+"-namespace").val();$.ajax({url:resourceUrl,data:{"_uk_gov_camden_address_lookup_web_AddressLookupPortlet_propertyId":propertyId,"_uk_gov_camden_address_lookup_web_AddressLookupPortlet_source":source,
"_uk_gov_camden_address_lookup_web_AddressLookupPortlet_addressId":addressId,"_uk_gov_camden_address_lookup_web_AddressLookupPortlet_addressSource":addressSource},dataType:"json",method:"GET",success:function(result){var exception=result.exception;if(typeof exception!=="undefined"){var html='\x3cdiv class\x3d"portlet-msg-info"\x3e'+exception+"\x3c/div\x3e";$(id+" .addressSelect").empty().hide();$(id+" .addressException").html(html)}else{var propertyId=result.propertyId?result.propertyId:"";var addressId=
result.addressId?result.addressId:"";var addressFull=result.addressFull?result.addressFull:"";var line1=result.line1?result.line1:"";var line2=result.line2?result.line2:"";var city=result.city?result.city:"";var postcode=result.postcode?result.postcode:"";var addressSource=result.addressSource?result.addressSource:"";$(id+" .address-line-1").html(line1);$(id+" .address-line-2").html(line2);$(id+" .address-city").html(city);$(id+" .address-postcode").html(postcode);$(id+" .address-source").html(addressSource);
$(id+"-address-propertyId").val(propertyId).change();$(id+"-address-addressId").val(addressId).change();$(id+"-address-full").val(addressFull).change();$(id+"-address-line1").val(line1).change();$(id+"-address-line2").val(line2).change();$(id+"-address-city").val(city).change();$(id+"-address-postcode").val(postcode).change();$(id+"-address-source").val(addressSource).change();$(id+" .addressPickerControls").hide();$(id+" .addressDisplay").show();removeAddresspickerHack(id)}}});return false});$(document).on("click",
".address-picker-change-address",function(){var id="#"+$(this).attr("data-address-picker-id");var namespace="#"+$(id+"-namespace").val();$(id+"-postcodeDivId input").val("");$(id+"-buildingNumberDivId input").val("");$(id+" .address-line-1").empty();$(id+" .address-line-2").empty();$(id+" .address-town").empty();$(id+" .address-postcode").empty();$(id+" .address-source").empty();$(id+"-address-propertyId").val("").change();$(id+"-address-addressId").val("").change();$(id+"-address-full").val("").change();
$(id+"-address-line1").val("").change();$(id+"-address-line2").val("").change();$(id+"-address-city").val("").change();$(id+"-address-postcode").val("").change();$(id+"-address-source").val("").change();$(id+" .addressPickerControls").show();$(id+" .addressList").hide();$(id+" .addressDisplay").hide();$(id+"-postcodeDivId input").focus();addAddresspickerHack(id);return false})});
AUI.add("com-placecube-casemanagement-frontend-taglib-caseactionbutton",function(A){A.CaseActionButton=A.Component.create({NAME:"com-placecube-casemanagement-frontend-taglib-caseactionbutton",EXTENDS:A.Component,ATTRS:{comments:{}},prototype:{openCommentDialog:function(commentsFieldId,randomId,url,title,mandatoryValue){var instance=this;var commentsEnabled=false;var form=A.Node.create("\x3cform /\x3e");form.setAttribute("action",url);form.setAttribute("method","POST");var comments=A.one("#div_"+commentsFieldId);
if(comments&&!instance._attrs.comments[randomId])instance._attrs.comments[randomId]=comments;else if(!comments&&instance._attrs.comments[randomId])comments=instance._attrs.comments[randomId];if(comments){form.append(comments);comments.show();commentsEnabled=true}var dialog=Liferay.Util.Window.getWindow({dialog:{bodyContent:form,destroyOnHide:true,height:400,resizable:false,toolbars:{footer:[{cssClass:"btn-lg btn-primary",label:"Done",on:{click:function(){var showAlert=false;if(commentsEnabled){var selectedValue=
A.one("#"+commentsFieldId).val();if(mandatoryValue=="true"&&(selectedValue==undefined||selectedValue.length<=0))showAlert=true}if(showAlert)alert("Comments are mandatory");else submitForm(form)}}},{cssClass:"btn-lg btn-cancel btn-link",label:"Cancel",on:{click:function(){dialog.hide()}}}],header:[{cssClass:"close",discardDefaultButtonCssClasses:true,labelHTML:"\x3cspan\x3e \u00d7 \x3c/span\x3e",on:{click:function(event){dialog.hide()}}}]},width:896},title:A.Lang.String.escapeHTML(title)})}}})},"",
{requires:["liferay-util-window"]});
AUI.add("com-placecube-casemanagement-frontend-caselisting",function(A){var CaseListing={init:function(){$(document).on("click",".case-listing-entry",function(e){A.CaseListing.openCaseEntryDetailPopUp(e)})},getRenderUrl:function(ppid,mvcRenderCommandName,windowState,parameters){var renderURL=Liferay.PortletURL.createRenderURL();renderURL.setPortletId(ppid);renderURL.setParameter("mvcRenderCommandName",mvcRenderCommandName);renderURL.setWindowState(windowState);renderURL.setParameters(parameters);
return renderURL},openCaseEntryDetailPopUp:function(e){var caseListing=$(e.currentTarget).closest(".case-management .case-listing");var ppid=$(caseListing).attr("data-ppid");var mvcRenderCommandName=$(caseListing).attr("data-mvc-render-command-name");var entryId=$(e.currentTarget).attr("data-entry-id");var parameters={entryId:entryId};var renderURL=this.getRenderUrl(ppid,mvcRenderCommandName,"pop_up",parameters);Liferay.Util.openWindow({dialog:{destroyOnHide:true,plugins:[Liferay.WidgetZIndex]},id:ppid+
"_Dialog",title:"",uri:renderURL.toString()})}};A.CaseListing=CaseListing},"",{requires:["liferay-portlet-url","liferay-util-window"]});
AUI.add("com-placecube-casemanagement-datastructureupdate",function(A){var ENTRY_OPTION_TEMPLATE='\x3coption value\x3d"{optionValue}"\x3e{optionValue}\x3c/option\x3e';var DataStructureUpdate={init:function(){var instance=this;$(".data-structure-update").on("change",function(e){var selectedDataStructurekey=$(this).attr("data-dataStructureKey");var dropdownSelectToUpdate=$('.data-structure-update[data-parentDataStructureKey\x3d"'+selectedDataStructurekey+'"]')[0];if(dropdownSelectToUpdate!==undefined){var optionSelectedParam=
document.getElementById(this.id).value;instance._retrieveValuesForSelectedParentDataStructure(selectedDataStructurekey,optionSelectedParam,dropdownSelectToUpdate)}})},_retrieveValuesForSelectedParentDataStructure:function(parentDataStructureKeyParam,optionSelectedParam,dropdownSelectToUpdate){var datastructurekeyParam=$(dropdownSelectToUpdate).attr("data-dataStructureKey");Liferay.Service("/casemanagement_datastructure.datastructureentry/get-linked-data-structure-entries",{parentStructureKey:parentDataStructureKeyParam,
parentStructureName:optionSelectedParam,dataStructureKey:datastructurekeyParam},function(data){var dataStructureEntiresFound=data;$(dropdownSelectToUpdate).html("");$.each(dataStructureEntiresFound,function(key,value){var entryValue=A.Lang.sub(ENTRY_OPTION_TEMPLATE,{optionValue:value.name});$(dropdownSelectToUpdate).append(entryValue)})})}};A.DataStructureUpdate=DataStructureUpdate},"",{requires:["liferay-portlet-url"]});
