/** 基础流程类型 */

  
  var angular = require('angular');
  require('../modules');
  require('../../flow/services/WorkflowTransfer');
  
  var module = angular.module('flowmodulebutton.directives');
  
  /**
      <sino-flow-base-flow-button
          name="" 按钮的名称
          tag="" 按钮的提示
          subflag-value="" 流程状态
      ></sino-flow-base-flow-button>
   */
  module.directive('sinoFlowBaseFlowButton', function(WorkflowTransfer) {
      
      return {
          restrict: 'E',
          require: '^sinoFlowButtonBar',
          link: function(scope, element, attrs, ctrl) {
              
              ctrl.button(function(){
                  return {
                      id: attrs.buttonId,
                      name: attrs.name,
                      show: attrs.show ? scope.$eval(attrs.show) : true,
                      warrant: true,
                      onClick: function() {
                          var promise = scope.$eval(attrs.onClick, {
                              flowType: ctrl.getAttr(attrs, 'flowType'),
                              recordId: ctrl.getAttr(attrs, 'recordId')
                          }).then(function(data) {
                            ctrl.updateSubflag(scope, attrs, attrs.subflagValue);
                            return data;
                          });
                          return ctrl.successCallFnInAlert(promise, attrs.tag);
                      }
                  }
              });
          }   
      };
  });
