{"size": 1341, "ext": "js", "max_stars_repo_path": "modules/adminlogs/client/controllers/adminlogs.client.controller.js", "max_stars_repo_name": "ireneegarcia/geoatencion", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "modules/adminlogs/client/controllers/adminlogs.client.controller.js", "max_issues_repo_name": "ireneegarcia/geoatencion", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "modules/adminlogs/client/controllers/adminlogs.client.controller.js", "max_forks_repo_name": "ireneegarcia/geoatencion", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.8333333333, "max_line_length": 101, "alphanum_fraction": 0.5988068606}
(function () {
  'use strict';

  // Adminlogs controller
  angular
    .module('adminlogs')
    .controller('AdminlogsController', AdminlogsController);

  AdminlogsController.$inject = ['$scope', '$state', '$window', 'Authentication', 'adminlogResolve'];

  function AdminlogsController ($scope, $state, $window, Authentication, adminlog) {
    var vm = this;

    vm.authentication = Authentication;
    vm.adminlog = adminlog;
    vm.error = null;
    vm.form = {};
    vm.remove = remove;
    vm.save = save;

    // Remove existing Adminlog
    function remove() {
      if ($window.confirm('Are you sure you want to delete?')) {
        vm.adminlog.$remove($state.go('adminlogs.list'));
      }
    }

    // Save Adminlog
    function save(isValid) {
      if (!isValid) {
        $scope.$broadcast('show-errors-check-validity', 'vm.form.adminlogForm');
        return false;
      }

      // TODO: move create/update logic to service
      if (vm.adminlog._id) {
        vm.adminlog.$update(successCallback, errorCallback);
      } else {
        vm.adminlog.$save(successCallback, errorCallback);
      }

      function successCallback(res) {
        $state.go('adminlogs.view', {
          adminlogId: res._id
        });
      }

      function errorCallback(res) {
        vm.error = res.data.message;
      }
    }
  }
}());
