define(['quote/quote'], function (quote) { quote.controller('GolfCart', ['$scope', '$http', '$q', 'VehicleHelpers', function ($scope, $http, $q, VehicleHelpers) { $scope.disableRegistration = false; $scope.SetStepHeader('

Golf cart information

'); //vehicleobject actions //when the currently selected Vehicle changes $scope.changeIndex = function (vehicle) { var index = VehicleHelpers.getVehicleIndex(vehicle); $scope.index = index; $scope.listIndex = VehicleHelpers.getLastVehicleIndexByType($scope.Vehicles[$scope.index], 'IsGolfCart'); $scope.Vehicles[index].HasSeen = true; }; //when a Vehicle is removed $scope.removeItem = function (vehicle) { var index = VehicleHelpers.getVehicleIndex(vehicle); VehicleHelpers.removeVehicle($scope, index, 'IsGolfCart'); }; //when a Vehicle is added $scope.addItem = function addItem() { VehicleHelpers.addVehicle($scope, { IsGolfCart: true, VehicleTypeInternal: "GC", Sasria: "Y", HailCover: "Y", isAdd: true }, 'IsGolfCart'); window.scrollTo(0, 0); }; $scope.fetchGolfCartMinMax = function () { $http({ method: 'POST', url: '/Quote/GolfCart/GetGolfCartMinMax' }).success(function (data) { $scope.GolfCartMinValue = data.Minimum; $scope.GolfCartMaxValue = data.Maximum; }); } $scope.fetchGolfCartMinMax(); $scope.Vehicles = $scope.Quote.Vehicles; VehicleHelpers.setupState($scope, 'IsGolfCart'); function setVehicleDescription() { if ($scope.Vehicles[$scope.index].VehicleDescription && $scope.Vehicles[$scope.index].VehicleDescription.Id && $scope.Vehicles[$scope.index].VehicleDescription.Year && $scope.Vehicles[$scope.index].isAdd) $scope.Vehicles[$scope.index].VehicleDescription.Description = getSelectedText('ddlGolfCartYear') + " " + getSelectedText('ddlGolfCartMake') + ' Golf Cart'; } $scope.$watch("Vehicles[index].VehicleDescription.Year", setVehicleDescription); $scope.$watch("Vehicles[index].VehicleDescription.Id", setVehicleDescription); $scope.$watch("Vehicles[index].VehicleFinanced", function (value) { if (value == "Y") { $scope.Vehicles[$scope.index].Sasria = "Y"; } }); function getSelectedText(elementId) { var elt = document.getElementById(elementId); if (elt.selectedIndex == -1) return null; return elt.options[elt.selectedIndex].text; } }]); });