/**
 * Created by shadeeka on 12/18/15.
 */
angular.module('app.controllers')
  .controller('AdminCtrl', function ($scope, $state, $cordovaFile, ionicMaterialInk, $ionicPopup, ionicMaterialMotion, $log, dataPersistenceService, $timeout, sparkDataService, $ionicLoading,auditProtocol) {
    var ImageLocation = cordova.file.dataDirectory + '/silhouetteList/';
    //var ImageLocation = cordova.file.externalRootDirectory + '/silhouetteList/';
    var _self = this;

    // A confirm dialog
    _self.showConfirm = function () {
      var confirmPopup = $ionicPopup.confirm({
        title: 'Disable Application !',
        template: 'Are you sure you want to disable the Application ?\n Restart is required !'
      });
      confirmPopup.then(function (res) {
        if (res) {
          dataPersistenceService.disableApp();
          ///////////////////audit//////////////////////
          var $audit = auditProtocol.getEvent("disableApp");
          sparkDataService.sendDataToServer($audit)
          //////////////////////////////////////////////

          window.close();
          ionic.Platform.exitApp();
        } else {
          console.log('You are not sure');
        }
      });
    };

    _self.disable = function () {
      $log.debug("Disable app");

      this.showConfirm();

    }


      $scope.$on('$ionicView.beforeEnter', function () {
        $scope.$parent.clearAllFabs();
      });

  });
