!function(){"use strict";function MyShortlistCtrl($rootScope,shortlist,urlhelper){var vm=this;vm.properties=[],vm.initialized=!1,$rootScope.$on("shortlist:removed",(function(data,propertyId){var index=function(propertyId){for(var i=0;i=2?path[1]:null;urlShortlistId?(vm.isMyShortlist=urlShortlistId===cookieShortlistId,shortlist.canAdd=!0,shortlist.canRemove=vm.isMyShortlist,shortlist.canView=!vm.isMyShortlist,shortlist.getProperties(urlShortlistId).then((function(data){vm.properties=data,vm.initialized=!0}))):document.location=urlhelper.merge([document.location.href,cookieShortlistId])}))}angular.module("app").controller("MyShortlistCtrl",MyShortlistCtrl),MyShortlistCtrl.$inject=["$rootScope","shortlist","urlhelper"]}(),function(){"use strict";function shortlistApi($q,api){return{createShortlist:function(){return api.post("/api/shortlist/create",{})},getPropertyIds:function(shortlistId){return api.get("/api/shortlist/propertyids",{shortlistId:shortlistId||""}).then((function(data){return data||[]}))},getProperties:function(shortlistId){return api.get("/api/shortlist/properties",{shortlistId:shortlistId||""}).then((function(data){return data||[]}))},add:function(shortlistId,propertyId){return api.post("/api/shortlist/add",{shortlistId:shortlistId||null,propertyId:propertyId}).then((function(data){return data}))},remove:function(shortlistId,propertyId){return api.post("/api/shortlist/remove",{shortlistId:shortlistId||"",propertyId:propertyId}).then((function(data){return data}))}}}angular.module("app").factory("shortlistApi",shortlistApi),shortlistApi.$inject=["$q","cshApi"]}(),function(){"use strict";function ShortlistCtrl($scope,shortlist){this.shortlist=shortlist}angular.module("app").controller("ShortlistCtrl",ShortlistCtrl),ShortlistCtrl.$inject=["$scope","shortlist"]}(),function(){"use strict";function shortlist($rootScope,$q,cookie,api){var _deferred,service={add:add,canAdd:!1,canRemove:!1,canView:!1,contains:function(propertyId){return-1!==indexOf(propertyId)},count:function(){return(service.propertyIds||[]).length},getProperties:api.getProperties,getShortlistId:function(){if(_deferred)return _deferred.promise;_deferred=$q.defer(),service.shortlistId=service.shortlistId||cookie.get("shortlistId"),service.shortlistId?_deferred.resolve(service.shortlistId):api.createShortlist().then((function(shortlistId){_setShortlistId(shortlistId),_deferred.resolve(shortlistId)}));return _deferred.promise},propertyIds:[],remove:remove,toggle:function(propertyId){-1===indexOf(propertyId)?add(propertyId):remove(propertyId)}};return service.getShortlistId().then((function(shortlistId){api.getPropertyIds(shortlistId).then((function(propertyIds){service.propertyIds=propertyIds}))})),service;function _setShortlistId(shortlistId){cookie.set("shortlistId",shortlistId,30),service.shortlistId=shortlistId}function indexOf(propertyId){for(var i=0;i<(service.propertyIds||[]).length;i++)if(service.propertyIds[i]===propertyId)return i;return-1}function add(propertyId){if(-1===indexOf(propertyId))return $rootScope.$broadcast("shortlist:adding",propertyId),service.getShortlistId().then((function(shortlistId){return api.add(shortlistId,propertyId).then((function(newShortlistId){_setShortlistId(newShortlistId),service.propertyIds.push(propertyId),$rootScope.$broadcast("shortlist:added",propertyId)}))}))}function remove(propertyId){var index=indexOf(propertyId);return $rootScope.$broadcast("shortlist:removing",propertyId),service.getShortlistId().then((function(shortlistId){return api.remove(shortlistId,propertyId).then((function(newShortlistId){_setShortlistId(newShortlistId),service.propertyIds.splice(index,1),$rootScope.$broadcast("shortlist:removed",propertyId)}))}))}}angular.module("app").factory("shortlist",shortlist),shortlist.$inject=["$rootScope","$q","cookie","shortlistApi"]}();