var selectedDriverVMap = "";
var showAssignDialog = true;
var AssignBookDialogIsShown = false;
var AssignBookingIsInProgress = false;


var TaxiApp = angular.module('DashBoardApp', ['ngStorage', 'ngDialog', 'angularSpinner',
    'angularUtils.directives.dirPagination', 'ui.bootstrap',  'angular-growl', 'ngAnimate', 'AxelSoft']);

TaxiApp.config(['growlProvider', function (growlProvider) {
    growlProvider.globalTimeToLive({ success: 1000, error: 2000, warning: 150000, info: 150000 });
}]);
TaxiApp.run(['customSelectDefaults', function (customSelectDefaults) {
    customSelectDefaults.displayText = 'الرجاء اختيار سائق ...';
}]);
TaxiApp.controller('DashBoardCtrl', ['$scope', '$http', '$sessionStorage', 'ngDialog', 'usSpinnerService', 'growl', 
    function ($scope, $http, $sessionStorage, ngDialog, usSpinnerService, growl) {

        jQuery.loadScript = function (url, callback) {
            jQuery.ajax({
                url: url,
                dataType: 'script',
                success: callback,
                async: true
            });
        }
      
        Localization(sessionStorage.selectedLanguage, 'dashboard', $scope, sessionStorage);


        $scope.AddNewBooking = function () {
            window.location.href = "CallCenter.html?f=dash";
            $sessionStorage.Dashaddbooking = true;
            document.getElementById("AddBooking");
        }
       
        if (sessionStorage.CompanyOID != undefined && sessionStorage.ORGOID != undefined) {
            loadDropDownFromAppConfig("COMPANY", sessionStorage.UserOID, sessionStorage.CompanyOID, sessionStorage.ORGOID, 0, $scope);
        }




       
        if (sessionStorage.length == (undefined || 0)) {
            window.parent.location.href = "../../Index.html";
        }
        else {

            function openDialog(text) {
                var dialog = ngDialog.open({
                    template:
                        '<p>' + text + '</p>' +
                        '<div class="ngdialog-buttons"><button type="button" class="ngdialog-button ngdialog-button-Success" ng-click="closeThisDialog(1)">Ok</button></div>',
                    plain: true
                });
                dialog.closePromise.then(function (data) {
                    console.log('ngDialog closed' + (data.value === 1 ? ' using the button' : '') + ' and notified by promise: ' + data.id);


                });
            }
            var OID = "0", outofnetwork;
            var TokenID = sessionStorage.TokenID;
            var orgOID = sessionStorage.ORGOID;
            var userOID = sessionStorage.UserOID;
            $scope.Role = sessionStorage.RoleType;
            $scope.RoleID = sessionStorage.RoleID;

            var roleID = sessionStorage.RoleID;
            var groupOID = 0, Index = 0, Status = "0,1", dashlist, pagination = "1", BkStatus, ClnStatus;
            var companyOID = sessionStorage.CompanyOID;
            $scope.logo = sessionStorage.Photo;
            $scope.DisplayName = sessionStorage.UserName;
            var OLDpswd = sessionStorage.password
            $scope.CompanyName = sessionStorage.value;
            var cityOID = sessionStorage.CityID;
            audiojs.events.ready(function () {
                var as = audiojs.createAll();
            });
    
            GetCompanyCityOID("CompanyCity", userOID, companyOID, orgOID, groupOID);
            if (companyOID == 0) {
                $('.CompanyList').hide();

            }
            else {
                $('.CompanyList').show();
            }
            //  $scope.startSpin();
            checkUserLogin(userOID, TokenID);


            $scope.selectCompanydetails = function (obj) {

                sessionStorage.CompanyOID = obj.OID;
                $scope.CompanyName = obj.Value;
                sessionStorage.value = obj.Value;
                loadonce = true;
                window.location.href = "Dashboard.html";
            }

            $scope.User = {
                changePassword: function () {
                    $('#ChangePassword').modal('toggle');
                    $scope.e_Password = '';
                    $scope.e_NewPassword = '';
                    $scope.e_RepeatPassword = '';
                },
                confirmNewPassword: function () {
                  

                    if ($scope.e_Password == '' || $scope.e_NewPassword == '' || $scope.e_RepeatPassword == '') {
                        alert('يجب ادخال جميع الحقول');
                        return;
                    }
                    if ($scope.e_NewPassword != $scope.e_RepeatPassword) {
                        alert('كلمة المرور الجديدة يجب ان تطابق تاكيد كلمة المرور الجديدة');
                        return;
                    }

                    if ($scope.e_NewPassword.length<5) {
                        alert('كلمة المرور يجب ان تتكون من خمسة حروف على الاقل');
                        return;
                    }

                    var userdata = {};
                    var usrobj = {
                        "OID": sessionStorage.UserOID,
                        "password": Base64.encode($scope.e_Password.toLowerCase()),
                        "newPassword": Base64.encode($scope.e_NewPassword.toLowerCase()),
                        "token": sessionStorage.TokenID,

                    };
                    userdata["obj"] = usrobj;

                    $scope.loading = true;
                    $.ajax({
                        type: "POST",
                        url: ComonServiceUrl + "ChangPassword",
                        data: JSON.stringify(userdata),
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        processData: true,
                        success: function (data) {
                        
                            var result = JSON.parse(data.ChangPasswordResult);
                            if (result == "0") {
                                openDialog("تم تغيير كلمة المرور");
                                $('#ChangePassword').modal('toggle');

                                location.replace("http://web.arttech.ps/rocab");


                                return;
                            }
                            openDialog("يرجى التاكد من المعلومات المدخلة");


                        },
                    });



                }
            }


     
          
         
        


        
     



        

        }
    }]);

