/** 流程意见 */


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

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

/**
  <sino-flow-notion
    type="" 意见类型  例如mynotion
    title=""  意见名称 显示在意见列表中
    content="" 意见内容
    show="" 显示权限 默认false
    require-fn="" 必填权限 默认false
  ></sino-flow-notion>
 */
module.directive('sinoFlowNotion', function() {
  
  return {
    restrict: 'E',
    require: ['^sinoFlowNotionButton', '^sinoFlowButtonBar'],
    link: function(scope, element, attrs, ctrls) {
      var notionButtonBar = ctrls[0],
        flowButtonBar = ctrls[1];
      
      var tempNotion = {
        generateSign: attrs.generateSign,
        type: attrs.type,
        title: attrs.title,
        content: attrs.content,
        show: attrs.show ? scope.$eval(attrs.show) : true,
        requireFn: function() {
          return scope.$eval(attrs.requireFn, flowButtonBar.getActiveButtonLocals())
        }
      };
      notionButtonBar.addTempNotion(tempNotion);
      scope.$watch(function() {
        return scope.$eval(attrs.show);
      }, function(show) {
        tempNotion.type = attrs.type,
        tempNotion.title = attrs.title,
        tempNotion.content = attrs.content,
        tempNotion.show = attrs.show ? scope.$eval(attrs.show) : true,
        tempNotion.requireFn = function() {
          return scope.$eval(attrs.requireFn, flowButtonBar.getActiveButtonLocals())
        }
      });
    } 
  };
});
