{"size": 2281, "ext": "js", "max_stars_repo_path": "public/js/controller/app_detail_ctrl.js", "max_stars_repo_name": "ppxpp/6in4res", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "public/js/controller/app_detail_ctrl.js", "max_issues_repo_name": "ppxpp/6in4res", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "public/js/controller/app_detail_ctrl.js", "max_forks_repo_name": "ppxpp/6in4res", "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": 29.2435897436, "max_line_length": 111, "alphanum_fraction": 0.4445418676}
'use strict';

/* Controllers */

angular.module('myApp').
    controller('appDetailCtrl', ['$scope', '$location', '$routeParams',
      '$http', '$log', '$uibModal', 'authService', 'AUTH_EVENT', 'USER_ROLES',
      function ($scope, $location, $routeParams, $http, $log, $uibModal, authService, AUTH_EVENT, USER_ROLES) {

        var user = authService.getUser();
        $scope.isAdmin = false;

        if(user.role == USER_ROLES.admin){
          $scope.isAdmin = true;
        }

        var id = $routeParams.id || 1;
        $log.debug('id = ' + id);

        $scope.user = authService.getUser();
        $scope.item = null;

        loadData();
        function loadData(){
          $http({
            url:'/api/check/app/detail',
            method:'GET',
            params:{
              'id': id,
              'token':$scope.user.token
            }
          }).success(function(data,header,config,status){
            //响应成功
            $log.debug(data);
            if(data.errno == 0){
              $scope.item = data.item;
            }else{
              //$location.path("/check/app/undo/1");
            }
          }).error(function(data,header,config,status){
            //处理响应失败
          });
        };

        $scope.action = function(actionCode){
          $log.debug('action = ' + actionCode);
          //$log.debug(item);
          var action = '';
          if(actionCode == 0){
            action = 'pass';
          }else if(actionCode == 1){
            action = 'reject';
          }else if(actionCode == 2){
            action = 'delete';
          }
          var postData = {
            'id': id,
            'action': action
          };
          $http.post('/api/check/app/action?token='+$scope.user.token, postData).
              success(function (data, status, headers, config) {
                $log.debug(data);
                if (data.errno === 0) {
                  if ($scope.isAdmin) {
                    $location.path('/check/app/undo/1');
                  }else{
                    $location.path('/res/app/list/1');
                  }
                }
              }).
              error(function (data, status, headers, config) {
                console.log('error');
              });
        };


      }]);
