
var TaxiApp = angular.module('ContactUsList', ['ngStorage', 'ngDialog', 'ui.bootstrap'])
 

TaxiApp.controller('ContactUsListCtrl', ['$scope', '$http', '$sessionStorage', 'ngDialog', 

    function ($scope, $http, $sessionStorage, ngDialog) {
        Localization(sessionStorage.selectedLanguage, 'allreport', $scope, sessionStorage);
      
        $scope.selectInstitution = function () {
            SelectedEnterprise = $scope.selectedInstitution.BookingStatus;

        }
        $scope.VehicleCurrentLocation = [];
      
        $scope.loading = false;
        $scope.DisplayName = sessionStorage.UserName;       
        $scope.CompanyName = sessionStorage.value;
        $scope.DistrictOID = sessionStorage.DistrictOID;
        if (sessionStorage.length == (undefined || 0)) {
            window.parent.location.href = "../../Index.html";
        }
        else {
            $scope.Role = sessionStorage.RoleType;

            if (sessionStorage.RoleType == "Organization Admin") {
                $('.tele').show();
            }
            else {
                $('.tele').hide();
            }

            $scope.Role = sessionStorage.RoleType;

            $scope.User = sessionStorage.Username;

            selectedCompany = 'undefined';
            if (sessionStorage.CompanyOID != undefined || sessionStorage.ORGOID != undefined) {
                loadDropDownFromAppConfig("COMPANY", sessionStorage.UserOID, sessionStorage.CompanyOID, sessionStorage.ORGOID, 0, $scope);
            }
           
            function load() {
                $scope.FromDate = new Date();
                $scope.ToDate = new Date();
                //$scope.GetAllAcceptanceRecords();
            }
            load();

            function getFormattedFromDate(tDate) {

                var year = tDate.getFullYear();
                var month = (1 + tDate.getMonth()).toString();
                month = month.length > 1 ? month : '0' + month;
                var day = tDate.getDate().toString();
                day = day.length > 1 ? day : '0' + day;
                DatePart = year + month + day;
                return year + '-' + month + '-' + day;

            }


         
            function GetAllCodes() {
                var fdate = getFormattedFromDate($scope.FromDate);
            var todate = getFormattedFromDate($scope.ToDate);


                $.ajax({
                    cache: true,
                    url: ManagementServiceUrl + "GetContactUsList/"+sessionStorage.UserOID+"/"+sessionStorage.TokenID,
                    type: "GET",
                    contentType: "application/javascript",
                    dataType: "jsonp",

                    success: function (result) {
                        //var a = result;
                        $scope.loading = false;
                        var data = JSON.parse(result.GetContactUsListResult);
                            for (var i = 0 ; i < data.length; i++) {
                               
                                
                                var tempDate = data[i].ContactDateTime;
                                var res = tempDate.split("T");
                                var TempTime = res[1].substring(0, 5);
                                data[i].ContactDateTime = res[0] + " \xa0\xa0\xa0\xa0\xa0\xa0\xa0 " + TempTime;

                            }
                       
                        $scope.List = data;
                        $scope.$apply();
                    }
                });

            }
        GetAllCodes();

        $scope.changeStatus=function(oid) {
            $.ajax({
                cache: true,
                url: ManagementServiceUrl + "UpdateContactMsgAsResolved/" + oid,
                type: "GET",
                contentType: "application/javascript",
                dataType: "jsonp",

                success: function (result) {
                    //var a = result;
                    $scope.loading = false;
                    var data = JSON.parse(result.UpdateContactMsgAsResolvedResult);
                    GetAllCodes();
                  
                    $scope.$apply();
                }
            });




        }

        
        }
    
    }])
