/** 重启流程按钮 */


var angular = require('angular');
require('../modules');
require('../../linker/services/UserChooser');

var module = angular.module('flowmodulebutton.directives');

/**
  <sino-flow-lxw-button
     flow-type=""
     record-id=""
     show="" 展示权限 默认false
     name="" 名称
   ></sino-flow-lxw-button>
 */
module.directive('sinoFlowLxwButton', function(DefaultWorkflowParam, $ionicPopup) {

  return {
    restrict: 'E',
    require: '^sinoFlowButtonBar',
    scope: {
      lxwFn: '&'
    },
    link: function(scope, element, attrs, ctrl) {
      var type = 'hqyjexpnotion',
      templxwnotion = attrs.templxwnotion || '按例行文处理';

      ctrl.button(function() {
        return {
          id: 'lxw',
          name: attrs.name,
          show: attrs.show ? scope.$parent.$eval(attrs.show) : false,
          onClick: setNotion
        }
      });

      function setNotion() {
        $ionicPopup.confirm({
          title: '提示',
          content: '您确定要按例行文处理吗？',
          okText: '确定',
          cancelText: '取消'
        }).then(function(res) {
          DefaultWorkflowParam.setTempNotion(type, templxwnotion);
          scope.lxwFn({lxw: true});
        });
      }

    }
  }
});
