angular.module("app",["ngRoute","ngAnimate","ngSanitize","ui.bootstrap","ui.utils","angulartics","angulartics.google.tagmanager","app.activate","app.common","app.config","app.error","app.feature","app.landing","app.login","app.logout","app.recover","app.service","app.terms"]).config(["$routeProvider","$locationProvider","$analyticsProvider","EnableGoogleAnalytics","isGDPREnabled","$provide",function(n,t,i,r,u){n.when("/",{controller:"LandingController",templateUrl:"/scripts/app/landing/landing.html"});n.when("/login",{controller:"LoginController",controllerAs:"login",templateUrl:"/templates/_login.html"});n.when("/login/terms",{controller:"LoginTermsController",controllerAs:"terms",templateUrl:"/templates/_login.terms.html"});n.when("/login/restaurant",{controller:"LoginRestaurantController",templateUrl:"/templates/_login.restaurant.html",resolve:{restaurantListModel:["$location","LoginRestaurantService",function(n,t){return t.get().then(function(n){return n})["catch"](function(){n.path("/error")})}]}});n.when("/logout",{controller:"LogoutController",controllerAs:"logout",templateUrl:"/templates/_logout.html"});n.when("/logout-restaurant",{redirectTo:"/login/restaurant"});n.when("/recover/username",{controller:"RecoverUsernameController",templateUrl:"/templates/_recover.username.html"});n.when("/recover/password",{controller:"RecoverPasswordController",templateUrl:"/templates/_recover.password.html"});n.when("/recover/newpassword",{controller:"RecoverNewPasswordController",templateUrl:"/templates/_recover.newpassword.html"});n.when("/activate/getcode",{controller:"GetActivationCodeController",templateUrl:"/templates/_getcode.html"});n.when("/activate/entercode",{controller:"EnterActivationCodeController",controllerAs:"code",templateUrl:"/templates/_activate.enter-code.html"});n.when("/activate/partner",{controller:"ActivatePartnerController",controllerAs:"partner",templateUrl:"/templates/_activate.partner.html",resolve:{codedata:["$location","ValidateCodeService",function(n,t){return t.get().then(function(n){return n})["catch"](function(){n.path("/error")})}]}});n.when("/help/terms",{templateUrl:"/scripts/app/help/terms.html",controller:"TermsController"});u&&n.when("/help/privacy_policy",{templateUrl:"/scripts/app/help/privacy_policy.html"});n.when("/empty",{templateUrl:"/scripts/app/test/empty.html"});n.when("/error",{controller:"ErrorController",controllerAs:"error",templateUrl:"/templates/_error.html"});n.when("/error/notfound",{controller:"ErrorNotFoundController",controllerAs:"error",templateUrl:"/templates/_error.notfound.html"});n.when("/error/forbidden",{controller:"ErrorForbiddenController",controllerAs:"error",templateUrl:"/templates/_error.forbidden.html"});n.otherwise({redirectTo:"/error/notfound"});t.html5Mode(!0);i.virtualPageviews(r)}]);angular.module("app.service",[]).factory("AuthorizeService",["$window","$location",function(n,t){var i=function(n){return t.search().redirect_uri?n+"/api/authorize?"+$.param(t.search()):t.search().returnUrl?t.search().returnUrl:n+"/api/authorize/default"};return{redirect:function(){var u="https://"+t.host(),r=t.port(),f;r&&r!==80&&r!==443&&(u+=":"+t.port());f=i(u);n.location=f}}}]);angular.module("app.config",[]).constant("EnableGoogleAnalytics",!0).constant("JustEatNewsFeed","http://www.just-eat.com/feed/").constant("DefaultRedirectUri","https://partner.just-eat.es").constant("ContactNumber","910507395").constant("Tenant","es").constant("isGDPREnabled",!0);angular.module("app.feature",[]).constant("FeatureToggle",{disableActivation:!1,disableUsernameRecovery:!1,disablePasswordRecovery:!1});angular.module("app.activate",["app.activate.entercode","app.activate.getcode","app.activate.partner"]);angular.module("app.activate.entercode",[]).controller("EnterActivationCodeController",["$http","$location","MessageState","restaurantDecorator","$window",function(n,t,i,r,u){u.dataLayer.push({event:"trackPageview"});var f=this;this.activationCode="";this.isInProgress=!1;this.isSubmitted=!1;this.showCodeError=!1;this.showExpiredError=!1;this.showRestaurantError=!1;this.showCodeSentMessage=i.getActivationCodeSent();this.showCodeRequiredError=function(){return this.activateAccountForm.activationCode.$error.required&&(this.activateAccountForm.activationCode.$dirty||this.isSubmitted)};this.onResendSms=function(){t.path("/activate/getcode")};this.onSubmit=function(){this.restaurants?this.onSubmitRestaurants():this.onSubmitCode()};this.onSubmitCode=function(){if(this.isSubmitted=!0,this.showCodeSentMessage=!1,this.showExpiredError=!1,this.showCodeError=!1,!this.activateAccountForm.$invalid){this.isInProgress=!0;var t={code:this.activationCode};n.post("/api/activationcode/validate",t).success(function(n){f.onCodeValidated(n.restaurants)}).error(function(n,t){f.showCodeSentMessage=!1;f.showExpiredError=t===400&&n&&n.message&&n.message==="expired code";f.showCodeError=!f.showExpiredError;f.isInProgress=!1})}};this.onSubmitRestaurants=function(){if(this.isSubmitted=!0,this.isSubmitted&&this.restaurants&&_.every(this.restaurants,function(n){return!n.isSelected})){this.showRestaurantError=!0;return}this.isInProgress=!0;var n=_.where(this.restaurants,function(n){return n.isSelected});t.search("restaurants",_.pluck(n,"id").join(",")).search("code",f.activationCode).path("/activate/partner")};this.onCodeValidated=function(n){n.length===1?t.search("restaurants",n[0].id).search("code",f.activationCode).path("/activate/partner"):(_.each(n,function(n){n.isSelected=!0}),f.isSubmitted=!1,f.isInProgress=!1,f.restaurants=r.extend(n))}}]);angular.module("app.activate.getcode",[]).controller("GetActivationCodeController",["$scope","$http","$location","MessageState","$window",function(n,t,i,r,u){u.dataLayer.push({event:"trackPageview"});n.data={mobile:"",isInProgress:!1,isSubmitted:!1,showNoRestauarnatActivationMessage:!1,getCodeError:!1,showMobileRequiredError:function(){return n.getActivationCodeForm.mobile.$error.required&&(n.getActivationCodeForm.mobile.$dirty||n.data.isSubmitted)},onSubmit:function(){if(n.data.isSubmitted=!0,!n.getActivationCodeForm.$invalid){n.data.isInProgress=!0;var u={mobileNo:n.data.mobile};t.post("/api/activationcode/create",u).success(function(){r.setActivationCodeSent();i.path("/activate/entercode")}).error(function(t,i){n.data.showNoRestauarnatActivationMessage=i===400&&t&&t.message&&t.message==="no restaurants";n.data.getCodeError=!n.data.showNoRestauarnatActivationMessage;n.data.isInProgress=!1})}}}}]);angular.module("app.activate.partner",["app.activate.partner.service"]).controller("ActivatePartnerController",["$http","$location","codedata","MessageState",function(n,t,i,r){var u=this;this.restaurants=i.restaurants;this.users=i.users;this.username="";this.password="";this.password1="";this.password2="";this.isInProgress=!1;this.isSubmitted=!1;this.accountOption="create";this.hasExistindUsers=this.users.length>0;this.showUsernameRequiredError=function(){return this.partnerForm.username.$error.required&&(this.partnerForm.username.$dirty||this.isSubmitted)};this.showPassword1RequiredError=function(){return this.partnerForm.password1.$error.required&&(this.partnerForm.password1.$dirty||this.isSubmitted)};this.showPassword2MatchError=function(){return this.partnerForm.password2.$error.match&&this.isSubmitted};this.doPasswordsMatch=function(n){return n===this.password1||this.password1===""};this.isAccountOptionSelected=function(n){return n===this.accountOption};this.showPasswordRequiredError=function(){return this.partnerForm.password.$error.required&&(this.partnerForm.password.$dirty||this.isSubmitted)};this.showSelectPartnerRequiredError=function(){return this.partnerForm.user.$error.required&&(this.partnerForm.user.$dirty||this.isSubmitted)};this.clearErrors=function(){this.showAuthenticationError=!1;this.invalidCodeError=!1;this.expiredCodeError=!1;this.partnerUniqueError=!1;this.invalidUsernameError=!1;this.invalidPasswordError=!1;this.lockOutError=!1;this.partnerError=!1};this.onCreateSubmit=function(){if(this.isSubmitted=!0,this.clearErrors(),!this.partnerForm.$invalid){this.isInProgress=!0;var i={username:this.username,password:this.password1,code:t.search().code,restaurantIds:_.pluck(this.restaurants,"id")};n.post("/api/partner/create",i).success(function(){r.setAccountCreated();delete t.search().code;delete t.search().restaurants;t.path("/login")}).error(function(n,t){u.isInProgress=!1;u.invalidCodeError=t===400&&n&&n.message&&n.message==="invalid-code";u.expiredCodeError=t===400&&n&&n.message&&n.message==="code-expired";u.partnerUniqueError=t===400&&n&&n.message&&n.message==="partner-not-unique";u.invalidUsernameError=t===400&&n&&n.message&&n.message==="invalid-username";u.invalidPasswordError=t===400&&n&&n.message&&n.message==="invalid-password";u.partnerError=!u.invalidCodeError&&!u.expiredCodeError&&!u.partnerUniqueError&&!u.invalidUsernameError&&!u.invalidPasswordError})}};this.onLinkSubmit=function(){if(this.isSubmitted=!0,this.clearErrors(),!this.partnerForm.$invalid){this.isInProgress=!0;var i={userid:this.linkedUser.id,username:this.linkedUser.username,password:this.password,code:t.search().code,restaurantIds:_.pluck(this.restaurants,"id")};n.post("/api/partner/link",i).success(function(){r.setAccountLinked();delete t.search().code;delete t.search().restaurants;t.path("/login")}).error(function(n,t){u.isInProgress=!1;u.showAuthenticationError=t===401;u.invalidCodeError=t===400&&n&&n.message&&n.message==="invalid-code";u.expiredCodeError=t===400&&n&&n.message&&n.message==="code-expired";u.lockOutError=t===400&&n&&n.message&&n.message==="lock-out";u.partnerError=!u.showAuthenticationError&&!u.invalidCodeError&&!u.expiredCodeError&&!u.lockOutError})}}}]);angular.module("app.activate.partner.service",[]).factory("ValidateCodeService",["$http","$q","$location","restaurantDecorator",function(n,t,i,r){function u(){return i.search().code}function f(){return i.search().restaurants?i.search().restaurants.split(","):[]}function e(n){var t=f(),i=_.filter(n.restaurants,function(n){return _.contains(t,n.id)});return r.extend(i)}function o(n){return n.users}return{get:function(){var i=t.defer(),r={code:u()};return n.post("/api/activationcode/validate",r).success(function(n){var t={restaurants:e(n),users:o(n)};i.resolve(t)}).error(function(n){i.reject(n)}),i.promise}}}]);angular.module("app.common.autofillfix",[]).directive("jeAutoFillFix",[function(){return{link:function(n,t,i){var r=function(){var r=t.closest("form");r.find("input[type='text'], input[type='password']").trigger("input").trigger("change");n.$apply(i.jeAutoFillFix)};t.click(r)}}}]);angular.module("app.common",["app.common.autofillfix","app.common.loginlink","app.common.lockoutalert","app.common.notification","app.common.passwordvalidation","app.common.placeholder","app.common.terms","app.common.privacypolicy"]).factory("restaurantDecorator",["$location",function(n){return{extend:function(t){var i=function(t){return t.logoUrl=n.protocol()+":"+t.logoUrl,t};return _.isArray(t)?_.each(t,function(n){i(n)}):i(t),t}}}]).factory("MessageState",[function(){var n=!1,t=!1,i=!1,r=!1,u=!1,f=!1;return{setActivationCodeSent:function(){n=!0},setResetCodeSent:function(){t=!0},setPasswordChanged:function(){i=!0},setUsernameRecovered:function(){r=!0},setAccountCreated:function(){u=!0},setAccountLinked:function(){f=!0},getActivationCodeSent:function(){var t=n;return n=!1,t},getResetCodeSent:function(){var n=t;return t=!1,n},getPasswordChanged:function(){var n=i;return i=!1,n},getUsernameRecovered:function(){var n=r;return r=!1,n},getAccountCreated:function(){var n=u;return u=!1,n},getAccountLinked:function(){var n=f;return f=!1,n}}}]);angular.module("app.common.lockoutalert",[]).directive("jeLockOutAlert",["ContactNumber",function(n){return{restrict:"E",templateUrl:"/Templates/_LockOutAlert.html",replace:!0,link:function(t){t.contactNumber=n}}}]);angular.module("app.common.loginlink",[]).directive("jeLoginLink",["$location","$window",function(n,t){return{restrict:"E",templateUrl:"/templates/_loginlink.html",replace:!0,scope:{onClick:"&"},link:function(i){i.navigateToLogin=function(){i.onClick();n.path("/login");t.dataLayer.push({event:"trackPageview"})}}}}]);angular.module("app.common.notification",[]).factory("notificationService",["$location",function(){return{getContent:function(){return null}}}]).directive("jeNotification",["notificationService",function(n){return{restrict:"E",templateUrl:"/scripts/app/common/notification.html",replace:!0,link:function(t){t.content=null;t.onContentChanged=function(n){t.content=n};t.$watch(n.getContent,t.onContentChanged)}}}]);angular.module("app.common.passwordvalidation",[]).directive("jePasswordValidationAlert",[function(){return{restrict:"E",templateUrl:"/templates/_recover.passwordhint.html",replace:!0}}]);angular.module("app.common.placeholder",[]).directive("placeholder",[function(){return{restrict:"A",scope:{},link:function(n,t,i){if(!("placeholder"in document.createElement("input"))){n.element=t;n.postitionPlaceholder=function(){n.placeholder.offset(n.element.position())};n.showOrHidePlaceholder=function(){n.element.val()?n.hidePlaceholder():n.showPlaceholder()};n.showOrHidePlaceholderThenFocus=function(){n.showOrHidePlaceholder();t.focus()};n.showPlaceholder=function(){n.placeholder.show()};n.hidePlaceholder=function(){n.placeholder.hide()};n.placeholder=$("<span><\/span>").hide().addClass("-placeholder").text(i.placeholder);n.element.parent().append(n.placeholder);n.postitionPlaceholder();n.showOrHidePlaceholder();n.element.on("keyup",n.showOrHidePlaceholder);n.element.on("keyDown",n.showOrHidePlaceholder);n.element.on("blur",n.showOrHidePlaceholder);n.element.on("focus",n.showOrHidePlaceholder);n.element.on("click",n.showOrHidePlaceholder);n.placeholder.on("click",n.showOrHidePlaceholderThenFocus)}}}}]);angular.module("app.common.privacypolicy",[]).directive("jePrivacyPolicy",["$location","$anchorScroll",function(n,t){return{restrict:"E",templateUrl:"/scripts/app/common/es/privacy_policy.html",replace:!0,link:function(i){i.goto=function(i){n.hash()!==i?n.hash(i):t()};t()}}}]);angular.module("app.common.terms",[]).directive("jeTerms",["$location","$anchorScroll",function(n,t){return{restrict:"E",templateUrl:"/scripts/app/common/es/terms.html",replace:!0,link:function(i){i.goto=function(i){n.hash()!==i?n.hash(i):t()};t()}}}]);angular.module("app.error",["app.error.notFound","app.error.forbidden"]).controller("ErrorController",["$window",function(n){this.onBack=function(){n.history.back()}}]);angular.module("app.error.forbidden",[]).controller("ErrorForbiddenController",[function(){}]);angular.module("app.error.notFound",[]).controller("ErrorNotFoundController",[function(){}]);angular.module("app.terms",[]).controller("TermsController",["$location","isGDPREnabled",function(n,t){n.hash()==="privacy_policy"&&t&&n.path("/help/privacy_policy").hash("")}]);angular.module("app.landing",[]).controller("LandingController",["$window","DefaultRedirectUri",function(n,t){n.location=t}]);angular.module("app.login",["app.login.restaurant","app.login.terms"]).controller("LoginController",["$http","$location","AuthorizeService","MessageState","FeatureToggle","Tenant",function(n,t,i,r,u){var f=this;this.featureToggle=u;this.username="";this.password="";this.isPersistent=!1;this.isInProgress=!1;this.isSubmitted=!1;this.showAuthenticationError=!1;this.showAccountError=!1;this.showLoginError=!1;this.showPasswordChangedMessage=r.getPasswordChanged();this.showRecoverUsernameMessage=r.getUsernameRecovered();this.showAccountCreatedMessage=r.getAccountCreated();this.showAccountLinkedMessage=r.getAccountLinked();this.showUsernameRequiredError=function(){return this.loginForm.username.$error.required&&(this.loginForm.username.$dirty||this.isSubmitted)};this.showPasswordRequiredError=function(){return this.loginForm.password.$error.required&&(this.loginForm.password.$dirty||this.isSubmitted)};this.onSubmit=function(){if(this.showPasswordChangedMessage=!1,this.showRecoverUsernameMessage=!1,this.showAccountCreatedMessage=!1,this.showAccountLinkedMessage=!1,this.isSubmitted=!0,!this.loginForm.$invalid){this.isInProgress=!0;var t={username:this.username,password:this.password,isPersistent:this.isPersistent};n.post("/api/account/login",t).success(function(){i.redirect()}).error(function(n,t){f.showAuthenticationError=t===401;f.showLockOutError=t===400&&n&&n.message&&n.message==="lock-out";f.showAccountError=t===400&&!f.showLockOutError;f.showLoginError=!f.showAuthenticationError&&!f.showAccountError&&!f.showLockOutError;f.isInProgress=!1})}};this.onRecoverUsername=function(){t.path("/recover/username")};this.onRecoverPassword=function(){t.path("/recover/password")};this.onActivateAccount=function(){t.path("/activate/getcode")}}]);angular.module("app.login.restaurant",[]).controller("LoginRestaurantController",["$scope","$http","$timeout","AuthorizeService","$window","LoginRestaurantService","$location","restaurantListModel",function(n,t,i,r,u,f,e,o){var s=function(n){u.dataLayer.push({event:"trackEvent",eventCategory:"engagement",eventAction:"form_change_restaurant",eventLabel:n})};s("start");n.data={showErrorMessage:!1,isInProgress:!1,showRestaurantList:!1,selectRestaurant:function(i){if(i){n.data.isInProgress=!0;n.data.showErrorMessage=!1;var u={id:i.id};t.post("/api/account/restaurants",u).success(function(){s("confirm");r.redirect()}).error(function(){n.data.isInProgress=!1;n.data.showErrorMessage=!0})}}};o.isJustEatUser?r.redirect():(i(function(){n.data.restaurants=o.restaurants},100),n.data.showRestaurantList=!o.isJustEatUser)}]).factory("LoginRestaurantService",["$http","$q","restaurantDecorator",function(n,t,i){return{get:function(){var r=t.defer();return n.get("/api/account/restaurants").success(function(n){n.restaurants=i.extend(n.restaurants);r.resolve(n)}).error(function(n){r.reject(n)}),r.promise}}}]);angular.module("app.login.terms",[]).controller("LoginTermsController",["$http","AuthorizeService",function(n,t){var i=this;this.isInProgress=!1;this.onSubmit=function(){this.isInProgress=!0;n.post("/api/account/acceptterms").success(function(){t.redirect()}).error(function(){i.isInProgress=!1;i.showTermsError=!0})}}]);angular.module("app.logout",[]).controller("LogoutController",["DefaultRedirectUri",function(n){this.logoutRedirectUrl=n}]).controller("LogoutRestaurantController",[function(){}]).directive("jeSingleSignOut",["$http","$timeout","$sce","$location","$window",function(n,t,i){return{restrict:"E",templateUrl:"/scripts/app/logout/single-sign-out.html",replace:!0,scope:{},link:function(r,u,f){r.url=f.restaurant===undefined?"/api/account/logout":"/api/account/logoutrestaurant";r.logout=function(){n.post(r.url).success(function(n){n=_.map(n,function(n){return i.trustAsResourceUrl(n)});r.signOutUrls=n}).error(function(){})};t(r.logout,100)}}}]);angular.module("app.recover.newpassword",[]).controller("RecoverNewPasswordController",["$scope","$http","$location","MessageState",function(n,t,i,r){n.data={code:"",password1:"",password2:"",isInProgress:!1,isSubmitted:!1,showResetError:!1,showExpiredError:!1,showValidationError:!1,showCodeSentMessage:r.getResetCodeSent(),showCodeRequiredError:function(){return n.newPasswordForm.code.$error.required&&(n.newPasswordForm.code.$dirty||n.data.isSubmitted)},showPassword1RequiredError:function(){return n.newPasswordForm.password1.$error.required&&(n.newPasswordForm.password1.$dirty||n.data.isSubmitted)},showPassword2MatchError:function(){return n.newPasswordForm.password2.$error.match&&n.data.isSubmitted},doPasswordsMatch:function(t){return t===n.data.password1||n.data.password1===""},onSubmit:function(){if(n.data.showCodeSentMessage=!1,n.data.isSubmitted=!0,!n.newPasswordForm.$invalid){n.data.isInProgress=!0;var u={code:n.data.code,password:n.data.password1};t.post("/api/forgotten/passwordreset",u).success(function(){r.setPasswordChanged();i.path("/login")}).error(function(t,i){n.data.showValidationError=i===400&&t&&t.message&&t.message==="password validation";n.data.showExpiredError=i===400&&t&&t.message&&t.message==="expired code";n.data.showResetError=!n.data.showValidationError&&!n.data.showExpiredError;n.data.isInProgress=!1})}}}}]);angular.module("app.recover.password",[]).controller("RecoverPasswordController",["$scope","$http","$location","MessageState","$window",function(n,t,i,r,u){u.dataLayer.push({event:"trackPageview"});var f=function(n){u.dataLayer.push({event:"trackEvent",eventCategory:"engagement",eventAction:"form_forgotten_password",eventLabel:n})};f("start");n.pushCancelEvent=function(){f("cancel")};n.data={mobile:"",username:"",isInProgress:!1,isSubmitted:!1,showRecoverError:!1,showUsernameRequiredError:function(){return n.passwordForm.username.$error.required&&(n.passwordForm.username.$dirty||n.data.isSubmitted)},showMobileRequiredError:function(){return n.passwordForm.mobile.$error.required&&(n.passwordForm.mobile.$dirty||n.data.isSubmitted)},onSubmit:function(){if(f("confirm"),n.data.isSubmitted=!0,n.passwordForm.$invalid){n.data.showUsernameRequiredError()&&f("error_usernameRequired");n.data.showMobileRequiredError()&&f("error_mobileRequired");return}n.data.isInProgress=!0;var u={username:n.data.username,mobileNo:n.data.mobile};t.post("/api/forgotten/password",u).success(function(){r.setResetCodeSent();i.path("/recover/newpassword")}).error(function(){f("error_invalidUsernameMobile");n.data.isInProgress=!1;n.data.showRecoverError=!0})}}}]);angular.module("app.recover",["app.recover.username","app.recover.password","app.recover.newpassword"]);angular.module("app.recover.username",[]).controller("RecoverUsernameController",["$scope","$http","$location","MessageState","$window",function(n,t,i,r,u){u.dataLayer.push({event:"trackPageview"});n.data={mobile:"",isInProgress:!1,isSubmitted:!1,showRecoverError:!1,showMobileRequiredError:function(){return n.usernameForm.mobile.$error.required&&(n.usernameForm.mobile.$dirty||n.data.isSubmitted)},onSubmit:function(){if(n.data.isSubmitted=!0,!n.usernameForm.$invalid){n.data.isInProgress=!0;var u={mobileNo:n.data.mobile};t.post("/api/forgotten/username",u).success(function(){r.setUsernameRecovered();i.path("/login")}).error(function(){n.data.isInProgress=!1;n.data.showRecoverError=!0})}}}}])