var angular = require('angular');
var _ = require('jsUtil');
require('../modules');
require('../services/DbsyService');
'use strict';

var module = angular.module('dbsy');

module.controller('DbsyGroupCtrl', function($state, $toast, dbsyService, AppConfig) {
  var ctrl = this;

  ctrl.todos = dbsyService.todos;
  ctrl.relatedList = dbsyService.relatedList;
  ctrl.toDetail = toDetail;


  function toDetail(item) {
    var module = AppConfig.getModuleConfigByFlowType(item.type);
    if (module) {
      var detailState = module.detailState,
        params = _.clone(detailState.params);
      for (var key in params) {
        if (params.hasOwnProperty(key)) {
          params[key] = params[key].replace(/\$\{(.+?)\}/g, function(match, key) {
            return item[key];
          });
        }
      }

      $state.go(detailState.state, params);
    } else {
      $toast.showLongCenter(item.typeName+'请在pc端办理！');
    }
  };

});
