var app=angular.module("app",["ngTable","ui.bootstrap.datetimepicker","ngI18n","ngSanitize","ui.bootstrap"]);app.value("ngI18nConfig",{defaultLocale:"en",supportedLocales:["en","es","fr","pt"],basePath:"scripts/App/json/bundle",cache:!0}),app.directive("accessibleForm",function(){return{restrict:"A",link:function(n,t){t.on("submit",function(){var n=t[0].querySelector(".ng-invalid");n&&n.focus()})}}}),app.factory("picFormFactory",["$http",function(n){var t={};return t.getDropdownData=function(t){var i="api/picformdropdowndata/";return n({url:i,method:"POST",data:t,headers:{"Content-Type":"application/json"}})},t.getTopicTip=function(t){var i="api/picformtopictips/";return n({url:i,method:"POST",data:t,headers:{"Content-Type":"application/json"}})},t.postJsonCaptchaInit=function(){var t="home/jsoncaptchainit/";return n({url:t,method:"POST",data:"",headers:{"Content-Type":"application/json"}})},t.postRequest=function(t){var i="api/picformrequest/";return n({url:i,method:"POST",data:t,headers:{"Content-Type":"application/json",__RequestVerificationToken:t.__RequestVerificationToken,"X-XSRF-Token":t.__RequestVerificationToken,"X-Requested-With":"XMLHttpRequest"}})},t.postServiceNow=function(t){var i="api/picformservicenow/";return n({url:i,method:"POST",data:t,headers:{"Content-Type":"application/json",__RequestVerificationToken:t.__RequestVerificationToken,"X-XSRF-Token":t.__RequestVerificationToken,"X-Requested-With":"XMLHttpRequest"}})},t.postRequestBeta=function(t){console.log("request",t);var i="api/picServicenow/";return n({url:i,method:"POST",data:t,headers:{"Content-Type":"application/json"}})},t}]),app.factory("publicDocsFactory",["$http","$rootScope",function(n,t){var i={};return i.getDocs=function(t){var i="api/publicdocs";return n({url:i,method:"POST",data:t,headers:{"Content-Type":"application/json"}})},i.postAnalytics=function(t){var i="api/analytics";return n({url:i,method:"POST",data:t,headers:{"Content-Type":"application/json"}})},i.getDocPubDate=function(t){var i="api/publicdocspublished/"+t;return n({url:i,method:"GET",headers:{"Content-Type":"application/json"}})},i.filtros="",i.prepForBroadcast=function(n){this.filtros=n,this.broadcastItem()},i.broadcastItem=function(){t.$broadcast("handleBroadcast")},i}]),app.controller("picFormCtrl",["$scope","$modal","picFormFactory","ngI18nResourceBundle","ngI18nConfig",function(n,t,i,r,u){n.comboTopics=[],n.comboCountry=[],n.comboAffiliation=[],n.ticket={number:!1,error:!1,captcha:!1},n.languages=[{locale:"en"},{locale:"es"},{locale:"fr"},{locale:"pt"}],n.supportedLocales=u.supportedLocales,n.defaultLocale=u.defaultLocale,n.basePath=u.basePath,n.cache=u.cache,n.i18n={language:n.languages[0]},n.$watch("i18n.language",function(t){r.get({locale:t.locale}).success(function(t){n.resourceBundle=t})}),n.init=function(t){n.language=t,n.i18n.language={locale:t},n.params={lang:t,option:"TOPICS"},i.getDropdownData(n.params).success(function(t){n.comboTopics=t}).error(function(){}),n.params={lang:t,option:"COUNTRY"},i.getDropdownData(n.params).success(function(t){n.comboCountry=t}).error(function(){}),n.params={lang:t,option:"AFFILIATION"},i.getDropdownData(n.params).success(function(t){n.comboAffiliation=t}).error(function(){})},n.updateCaptchaCall=function(){i.postJsonCaptchaInit().success(function(t){n.captchaImageUrl=t.imageUrl,n.captchaToken=t.tokenValue,n.captcha=""})},n.updateCaptchaCall(),n.reset=function(){n.request_form.reset()},n.sendRequest=function(t){if(console.log(n.model),n.request_form.$valid){if(t.email!==t.confirmEmail)return n.IsMatch=!1,!1;n.IsMatch=!0,n.open("md","Procesing... wait for your ticket confirmation number"),n.model={},n.request_form.$setPristine(),n.request_form.$setUntouched(),t.language=n.language,t.captchaToken=n.captchaToken,t.__RequestVerificationToken=angular.element('input[name="__RequestVerificationToken"]')[0].defaultValue,i.postRequest(t).then(function(t){n.ticket.number=t.data.number,n.ticket.error=t.data.error,n.ticket.captcha=t.data.captcha,n.ticket.captcha&&(n.request_form.captcha.$invalid=!0,n.updateCaptchaCall())})}else n.request_form.submitted=!0},n.gettip=function(){var t={lang:n.language,option:n.model.topic.Name};console.log(t),i.getTopicTip(t).then(function(t){t.data.message&&n.open("md",t.data.message)})},n.animationsEnabled=!0,n.open=function(i,r){var u=t.open({animation:n.animationsEnabled,templateUrl:"topicTip.html",controller:"modalInstanceCtrl",size:i,resolve:{tip:function(){return r}}});u.result.then(function(t){n.selected=t})}}]),app.controller("modalInstanceCtrl",["$scope","$modalInstance","tip",function(n,t,i){n.tip=i,n.ok=function(){t.close()},n.cancel=function(){t.dismiss("cancel")}}]),app.controller("picFormBetaCtrl",["$scope","$modal","picFormFactory","ngI18nResourceBundle","ngI18nConfig",function(n,t,i,r,u){n.comboTopics=[],n.comboCountry=[],n.comboAffiliation=[],n.ticket={number:!1,error:!1,captcha:!1},n.languages=[{locale:"en"},{locale:"es"},{locale:"fr"},{locale:"pt"}],n.supportedLocales=u.supportedLocales,n.defaultLocale=u.defaultLocale,n.basePath=u.basePath,n.cache=u.cache,n.i18n={language:n.languages[0]},n.$watch("i18n.language",function(t){r.get({locale:t.locale}).success(function(t){n.resourceBundle=t})}),n.init=function(t){n.language=t,n.i18n.language={locale:t},n.params={lang:t,option:"TOPICS"},i.getDropdownData(n.params).success(function(t){function r(n){if(n.Name!=="Accessing Bank Grants"&&n.Name!=="Accessing Bank Loans"&&n.Name!=="Career Opportunities"&&n.Name!=="Procurement Opportunities")return n}var u=t.filter(r);n.comboTopics=u}).error(function(){}),n.params={lang:t,option:"COUNTRY2"},i.getDropdownData(n.params).success(function(t){n.comboCountry=t}).error(function(){}),n.params={lang:t,option:"AFFILIATION"},i.getDropdownData(n.params).success(function(t){n.comboAffiliation=t}).error(function(){})},n.updateCaptchaCall=function(){i.postJsonCaptchaInit().success(function(t){n.captchaImageUrl=t.imageUrl,n.captchaToken=t.tokenValue,n.captcha=""})},n.updateCaptchaCall(),n.reset=function(){n.request_form.reset()},n.sendRequest=function(t){if(console.log("model",t,n.model),n.request_form.$valid){if(t.u_email!=t.confirmEmail)return n.IsMatch=!1,!1;n.IsMatch=!0,n.open("md",n.resourceBundle.waitModal),n.model={},n.request_form.$setPristine(),n.request_form.$setUntouched(),t.u_language=n.language,t.captchaToken=n.captchaToken,t.__RequestVerificationToken=angular.element('input[name="__RequestVerificationToken"]')[0].defaultValue,i.postRequestBeta(t).then(function(t){setTimeout(function(){$(".close").click()},100),n.ticket.number=t.data.result[0].display_value,n.ticket.error=t.data.result[0].status==="inserted"?!1:!0,n.ticket.captcha=!1,n.ticket.captcha&&(n.request_form.captcha.$invalid=!0,n.updateCaptchaCall())})}else n.request_form.submitted=!0},n.gettip=function(){var t={lang:n.language,option:n.model.u_topic.Name};console.log(t),i.getTopicTip(t).then(function(t){t.data.message&&n.open("md",t.data.message)})},n.animationsEnabled=!0,n.open=function(i,r){var u=t.open({animation:n.animationsEnabled,templateUrl:"topicTip.html",controller:"modalInstanceCtrl",size:i,resolve:{tip:function(){return r}}});u.result.then(function(t){n.selected=t})}}]),app.controller("publicDocsCtrl",["$scope","$filter","publicDocsFactory","ngTableParams","$q","$interval","ngI18nResourceBundle","ngI18nConfig",function(n,t,i,r,u,f,e){n.resourceBundle={lblRecordsShowingInfo:null},n.i18n={language:null},n.$watch("i18n.language",function(t){e.get({locale:t.locale}).success(function(t){n.resourceBundle=t})});var s=[],h=function(t){n.i18n.language={locale:t.language},n.loading=!0,i.getDocs(t).then(function(t){s=t.data,n.arr=[];var r=0,e=u.defer(),l=function(n,t,u){return i.getDocPubDate(n).then(function(n){u.PUBLISHED=n.data.PUBLISHED?moment(n.data.PUBLISHED).format("L"):t,r--})},o=function(t){var i={DOCNUM:t.DOCNUM,DOCNAME:t.DOCNAME,CREATION_DATE:moment(t.NEW_CREATION_DATE).toDate(),LANGUAGE:t.LANGUAGE,APP_ID:t.APP_ID,PUBLISHED:moment(t.NEW_AUTHORIZED_DATE).toDate()};r--,n.arr.push(i)},c=f(function(){r<=0&&(e.resolve(),f.cancel(c))},1e3),h=function(){s=n.arr,n.tableParams.reload(),n.loading=!1};s||h(),$.isArray(s)?(r=s.length,angular.forEach(s,function(n){o(n)})):(r=1,o(s)),e.promise.then(function(){h()},function(){})})};n.tableParams=new r({page:1,count:25,sorting:{PUBLISHED:"desc",CREATION_DATE:"desc"}},{total:s.length,getData:function(i,r){r.total(s.length);var u=r.sorting()?t("orderBy")(s,r.orderBy()):s;i.resolve(n.users=u.slice((r.page()-1)*r.count(),r.page()*r.count())),n.records=sprintf(new String(n.resourceBundle.lblRecordsShowingInfo),r.page()*r.count()-(r.count()-1),r.page()*r.count(),s.length)}}),n.saveInformation=function(n){var t=i.filtros.searchByTitle==null?"":i.filtros.searchByTitle,r={documentName:n.DOCNAME,documentNumber:n.DOCNUM,category:i.filtros.category,language:n.LANGUAGE,published:n.PUBLISHED,fromDate:$("input")[0].value,toDate:$("input")[1].value,searchByTitle:t};i.postAnalytics(r).then(function(){})},n.$on("handleBroadcast",function(){h(i.filtros)})}]),app.controller("publicDocsFiltersCtrl",["$scope","publicDocsFactory","ngI18nResourceBundle","ngI18nConfig",function(n,t,i){n.i18n={language:null},n.init=function(t,i){n.i18n.language={locale:t},n.data.category=i,n.data.language=t},n.$watch("i18n.language",function(t){i.get({locale:t.locale}).success(function(t){n.resourceBundle=t})});var u=new Date,f=new Date(u);f.setDate(u.getDate()-15),moment.locale("en"),n.data={dateFrom:f,dateTo:u,searchByTitle:""},n.checkboxOnTimeSet=function(){n.data.checked=!1},n.getLocale=function(){return moment.locale()},n.setLocale=function(n){moment.locale(n)},n.guardianOnSetTime=function(n){angular.element("#guardian"+n).dropdown("toggle")},n.beforeRender=function(n){var t=Math.floor(Math.random()*n.length);n[t].selectable=!1},n.config={datetimePicker:{startView:"year"}},n.configFunction=function(){return{startView:"month"}},n.handleSearch=function(){t.prepForBroadcast(n.data)},n.$watch("data.category",function(){n.handleSearch()}),n.$on("handleBroadcast",function(){n.data=t.filtros})}])