/**
|
* Created by wisestone on 2018-05-08.
|
*/
|
'use strict';
|
|
define([
|
'app',
|
'angular'
|
],
|
function (app, angular) {
|
app.controller('workflowAddController', ['$scope', '$rootScope', '$log', '$resourceProvider', 'User', '$uibModalInstance', 'Workflow', 'SweetAlert', 'IssueStatus', '$filter', '$injector','$controller',
|
function ($scope, $rootScope, $log, $resourceProvider, User, $uibModalInstance, Workflow, SweetAlert, IssueStatus, $filter) {
|
|
$scope.fn = {
|
cancel : cancel, // 팝업 창 닫기
|
formSubmit : formSubmit, // 폼 전송
|
formCheck : formCheck, // 폼 체크
|
getDepartments : getDepartments // 부서 목록 가져오기
|
};
|
|
$scope.vm = {
|
form : {
|
name : "", // 워크플로우 명
|
issueStatusVos : [], // 다이어그램에서 만들어진 이슈 상태 모음
|
WorkflowDepartmentVos : [
|
{
|
departmentVo : null
|
}
|
]
|
},
|
issueStatusVos : [], // 다이어그램 에디터에서 이 값을 감지하면서 조회가 시작된다.
|
step : "01",
|
isolationWorkflow : true, // 워크플로우에 고립된 이슈 상태가 있는지 여부를 체크한다.
|
firstStatusExist : true, // 워크플로우에 상태 속성 '대기'인 상태가 존재하는지 체크한다.
|
middleStatusExist : true, // 워크플로우에 상태 속성 '진행'인 상태가 존재하는지 체크한다.
|
lastStatusExist : true, // 워크플로우에 상태 속성 '종료'인 상태가 존재하는지 체크한다.
|
departments : [] // 부서 목록
|
};
|
|
|
|
// 폼 체크
|
function formCheck(formInvalid) {
|
if (formInvalid) {
|
return true;
|
}
|
|
return false;
|
}
|
|
// 부서 목록 가져오기
|
function getDepartments() {
|
var content = {
|
// 추후 변경을 위함
|
};
|
|
Workflow.findDepartments($resourceProvider.getContent(
|
content,
|
$resourceProvider.getPageContent(0, 1000))).then(function (result) {
|
|
if (result.data.message.status === "success") {
|
$scope.vm.departments = result.data.data;
|
}
|
else {
|
SweetAlert.error($filter("translate")("managementWorkflow.failedToSelectWorkspaceFullDepartmentList"), result.data.message.message); // 부서 목록 조회 실패
|
}
|
});
|
|
}
|
|
// 폼 전송
|
function formSubmit() {
|
$rootScope.spinner = true;
|
|
var content = {
|
name : $rootScope.preventXss($scope.vm.form.name),
|
issueStatusVos : $scope.vm.form.issueStatusVos,
|
nodes : (function () {
|
var keys = Object.keys($scope.vm.form.nodes);
|
var nodes = [];
|
|
angular.forEach(keys, function (key) {
|
var node = $scope.vm.form.nodes[key];
|
|
if ($rootScope.isDefined(node)) {
|
nodes.push(node);
|
}
|
});
|
|
return nodes;
|
})(),
|
links : $scope.vm.form.links
|
};
|
|
Workflow.add($resourceProvider.getContent(
|
content,
|
$resourceProvider.getPageContent(0, 0))).then(function (result) {
|
|
if (result.data.message.status === "success") {
|
$scope.fn.cancel();
|
// 목록 화면 갱신
|
$rootScope.$broadcast("getWorkflowList", {});
|
}
|
else {
|
SweetAlert.error($filter("translate")("managementWorkflow.failedCreateWorkflow"), result.data.message.message); // 워크플로우 생성 실패
|
}
|
|
$rootScope.spinner = false;
|
});
|
}
|
|
// 팝업 창 닫기
|
function cancel() {
|
$rootScope.$broadcast("closeLayer"); // 팝업이 열리고 나서 js-multi, js-single 등에서 body 이벤트가 날아가는 현상 수정
|
$uibModalInstance.dismiss('cancel');
|
$(document).unbind("keydown"); // 단축키 이벤트 제거
|
}
|
|
$scope.fn.getDepartments();
|
}]);
|
});
|