var angular = require('angular');
require('jsUtil');
require('../modules');

var module = angular.module('flow');
module.controller('SelectRoleCtrl', function($scope) {
  $scope.result = {};
  $scope.disable = true;
  $scope.seconds = 5;
  $scope.hasSend = false;

  $scope.$watch('result.selectedRole', function(item) {
    if (item) {
      _.each($scope.data.selectRoleMap, function(name, id) {
        if($scope.data.selectRoleMap.hasOwnProperty(id)) {
          if(name === item) {
            $scope.data.wfleveid = id;
            $scope.data.flag = 'selectoperate';
          }
        }
      });
      if($scope.disable) {
        $scope.disable = false;
      }
    }
  });

  /**
  * 监听被选中项
  **/
  $scope.selectRole = function() {
    $scope.disable = true;
    $scope.hasSend = true;
    $scope.closeRole(false);
  };

  $scope.closeRole = function(cancel) {
    $scope.onSelected(cancel);
  };
});
