ReportTaskCommands.js 5.04 KB
Newer Older
YazhouChen's avatar
YazhouChen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
import Vue from 'vue'
import uniqueId from 'lodash'
import {i18n} from '../main'
import AuthorityFilter from '../commands/AuthorityFilter'
import CreateAndCopyReportTaskDialog from '@/components/DialogComponents/ReportTaskDialog/CreateAndCopyReportTaskDialog.vue'
import DeleteReportTaskDialog from '@/components/DialogComponents/ReportTaskDialog/DeleteReportTaskDialog.vue'
import UpdateReportTaskDialog from '@/components/DialogComponents/ReportTaskDialog/UpdateReportTaskDialog.vue'
import CopyReportTaskDialog from '@/components/DialogComponents/ReportTaskDialog/CopyReportTaskDialog.vue'
import DetailCollTaskDialog from '@/components/DialogComponents/CollectTaskDialog/DetailCollTaskDialog.vue'

Vue.component('CreateAndCopyReportTaskDialog', CreateAndCopyReportTaskDialog)
Vue.component('CopyReportTaskDialog', CopyReportTaskDialog)
Vue.component('DeleteReportTaskDialog', DeleteReportTaskDialog)
Vue.component('UpdateReportTaskDialog', UpdateReportTaskDialog)
Vue.component('DetailCollTaskDialog', DetailCollTaskDialog)

let CommandTypes = {
  CREATE_COPY_REPORT_TASK_CMD: {
    type: 'CreateAndCopyReportTaskDialog',
    executeComponent: 'CreateAndCopyReportTaskDialog',
    registerComponent: CreateAndCopyReportTaskDialog
  },
  COPY_REPORT_TASK_CMD: {
    type: 'CopyReportTaskDialog',
    executeComponent: 'CopyReportTaskDialog',
    registerComponent: CopyReportTaskDialog
  },
  DELETE_REPORT_TASK_CMD: {
    type: 'DeleteReportTaskDialog',
    executeComponent: 'DeleteReportTaskDialog',
    registerComponent: DeleteReportTaskDialog
  },
  UPDATE_REPORT_TASK_CMD: {
    type: 'UpdateReportTaskDialog',
    executeComponent: 'UpdateReportTaskDialog',
    registerComponent: UpdateReportTaskDialog
  },
  SHOW_COLL_TASK_CMD: {
    type: 'DetailCollTaskDialog',
    executeComponent: 'DetailCollTaskDialog',
    registerComponent: DetailCollTaskDialog
  }
}

class ReportTaskCommands {
  static createAndCopyCommand (title, colTask, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.CREATE_COPY_REPORT_TASK_CMD.type),
      visible: true,
      disabled: false,
      target: colTask,
      title: title,
      executeComponent: CommandTypes.CREATE_COPY_REPORT_TASK_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('ReportTask.createReportTask')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.reportTaskAuthorityFilter(command)
  }

  static copyCommand (colTask, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.COPY_REPORT_TASK_CMD.type),
      visible: true,
      disabled: false,
      target: colTask,
      executeComponent: CommandTypes.COPY_REPORT_TASK_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('ReportTask.createReportTask')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.reportTaskAuthorityFilter(command)
  }

  static deleteReportTaskCommand (colTask, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.DELETE_REPORT_TASK_CMD.type),
      visible: true,
      disabled: false,
      target: colTask,
      executeComponent: CommandTypes.DELETE_REPORT_TASK_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('ReportTask.createReportTask')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.reportTaskAuthorityFilter(command)
  }

  static updateReportTaskCommand (colTask, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.UPDATE_REPORT_TASK_CMD.type),
      visible: true,
      disabled: false,
      target: colTask,
      executeComponent: CommandTypes.UPDATE_REPORT_TASK_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('ReportTask.createReportTask')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.reportTaskAuthorityFilter(command)
  }

  static showCollectTaskDetailCommand (colTask, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.SHOW_COLL_TASK_CMD.type),
      visible: true,
      disabled: false,
      target: colTask,
      executeComponent: CommandTypes.SHOW_COLL_TASK_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('CollecTaskCommands.viewCollectTask')
    };
    command.execute = function () {
      Vue.set(commandContext, command.id, command);
    };
    command.done = function () {
      Vue.delete(commandContext, command.id)
    };
    return command
  }
}

ReportTaskCommands.CommandTypes = CommandTypes

export default ReportTaskCommands