{"size": 1399, "ext": "js", "max_stars_repo_path": "app/assets/javascripts/components/scorer_listing/scorer_listing_controller.js", "max_stars_repo_name": "jacobgraves/quepid", "max_stars_repo_stars_event_min_datetime": "2021-03-27T22:49:08.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-27T22:49:08.000Z", "max_issues_repo_path": "app/assets/javascripts/components/scorer_listing/scorer_listing_controller.js", "max_issues_repo_name": "jacobgraves/quepid", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/assets/javascripts/components/scorer_listing/scorer_listing_controller.js", "max_forks_repo_name": "jacobgraves/quepid", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.9821428571, "max_line_length": 117, "alphanum_fraction": 0.5468191565}
'use strict';

/*jslint latedef:false*/

angular.module('QuepidApp')
  .controller('ScorerListingCtrl', [
    '$window',
    '$scope',
    'flash',
    'customScorerSvc',
    'teamSvc',
    function (
      $window,
      $scope,
      flash,
      customScorerSvc,
      teamSvc
    ) {
      var ctrl = this;
      console.log('About to set the team');
      ctrl.scorer = $scope.scorer;
      ctrl.team  = $scope.team;

      // Functions
      ctrl.deleteScorer = deleteScorer;
      ctrl.removeScorer = removeScorer;

      function deleteScorer() {
        var deleteScorer = $window.confirm('Are you absolutely sure you want to delete?');

        if (deleteScorer) {
          customScorerSvc.delete(ctrl.scorer)
            .then(function() {
              flash.success = 'Scorer deleted successfully';
            },
            function(response) {
              flash.error = response.data.error;
            });
        }
      }

      function removeScorer() {
        var removeScorer = $window.confirm('Are you absolutely sure you want to remove this scorer from this team?');

        if (removeScorer) {
          teamSvc.removeScorer(ctrl.team, ctrl.scorer)
            .then(function() {
              flash.success = 'Scorer removed from team';
            }, function(response) {
              flash.error = response.data.error;
            });
        }
      }
    }
  ]);
