


var leasingApp = angular.module("leasingApp", []);

leasingApp.controller("leasingSearchController", ["$scope", "$http", function ($scope, $http) {
    $scope.customerSearch = { ESN: "", MDN: "" , FirstName: "", LastName: ""};
    $scope.GridData = [];
    $scope.baseUrl = "";
    $scope.ShowCustomerGrid = false;
    
    $scope.init = function(baseUrl) {
        $scope.baseUrl = baseUrl;
    };

    $scope.SearchLeasingCustomers = function () {
        // perfom json get with %http
        var getUrl = $scope.baseUrl + "/SearchLeasing/";
        
        $http({
            url: getUrl,
            method: "GET",
            params: { customerSearch : $scope.customerSearch }
        }).success(function(data, status, headers, config) {
            $scope.GridData = data;
            if (data.length > 0) {
                $scope.ShowCustomerGrid = true;
            }
        }).error(function(data, status, headers, config) {
            // log to console
        });
    };

    $scope.GetLeasingCustomer = function (customerId) {
        // perform json get for leasing customer
    };
    $scope.Clear = function () {
        $scope.customerSearch = { ESN: "", MDN: "", FirstName: "", LastName: "" };
        $scope.GridData = [];
    };

}]);

angular.element(document).ready(function () {
    //var template = document.getElementById("myTemplate");
    var appDiv = document.getElementById("leasingApp");
    setTimeout(function () {
        //appDiv.innerHTML = template.innerHTML;
        angular.bootstrap(angular.element(appDiv), ['leasingApp']);
    }, 1000);
});