OWL ITS + 탐지시스템(인터넷 진흥원)
jhjang
2021-12-07 30ddd2cf095d2857ba1134fb3deaf51392ef1030
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/**
 * Created by wisestone on 2018-05-08.
 */
'use strict';
 
define([
        'app',
        'angular'
    ],
    function (app, angular) {
        app.controller('customFieldModifyController', ['$scope', '$rootScope', '$log', '$resourceProvider', '$uibModalInstance', 'CustomField', 'parameter', 'SweetAlert', '$timeout', '$filter',
            function ($scope, $rootScope, $log, $resourceProvider, $uibModalInstance, CustomField, parameter, SweetAlert, $timeout, $filter) {
 
                $scope.fn = {
                    cancel : cancel,    //  팝업 창 닫기
                    formSubmit : formSubmit,    //  폼 전송
                    formCheck : formCheck,  //  폼 체크
                    detail : detail,    //  상세 정보
                    addOption : addOption,   //  옵션 값 추가하기
                    removeOption : removeOption,    //  옵션 삭제
                    checkModifyOptions : checkModifyOptions,    //  옵션 값 변경 확인
                    changeCustomFieldType : changeCustomFieldType,  //  사용자 정의 필드 유형이 변경될 때 기본 값 초기화
                };
 
                $scope.vm = {
                    search : {
                        id : parameter.id,
                        deep : "01"    //  사용자 정의 필드 연관된 모든 정보를 어느정도까지 가져올지 결정, 01 - 일반 정보, 연관된 정보
                    },
                    form : {
                        id : parameter.id,
                        name : "",
                        customFieldType : "INPUT",    //  사용자 정의 필드 유형
                        defaultValue : "",  //  기본 값
                        options : [],  //  옵션
                        optionText : "",   //  옵션 값
                        useCustomFieldValue : false, //  이슈에서 사용되고 있는지 여부 확인
                        numberType : "",
                        ipAdress : "",
                        email : "",
                        site : "",
                        tel : "",
                        requiredData: ""
                    },
                    origin : {
                        options : []    //  옵션 값 변경 여부 확인을 위해 서버에서 내려올 때 원본 값을 따로 관리한다.
                    }
                };
 
                //  사용자 정의 필드 유형이 변경될 때 기본 값 초기화
                function changeCustomFieldType() {
                    //$scope.vm.form.name = "";
                    $scope.vm.form.defaultValue = "";
                }
 
                //  옵션 삭제
                function removeOption(index) {
                    $scope.vm.form.options.splice(index, 1);
                }
 
                //  옵션 값이 변경되었는지 확인한다.
                function checkModifyOptions() {
                    //  필드 유형이 문자열일 경우는 바로 종료
                    if ($scope.vm.form.customFieldType === "INPUT") {
                        return false;
                    }
 
                    //  옵션 갯수가 달라졌을 경우
                    if ($scope.vm.form.options.length !== $scope.vm.origin.options.length) {
                        return true;
                    }
 
                    //  갯수가 같을 경우 모든 옵션 값이 같아야 한다. 다를 경우 true 리턴.
                    var checkOptionCompare = false;
 
                    for (var originOptionCount in $scope.vm.origin.options) {
                        var originOption = $scope.vm.origin.options[originOptionCount];
                        var existOption = false;
 
                        for (var optionCount in $scope.vm.form.options) {
                            var option = $scope.vm.form.options[optionCount];
 
                            if (originOption === option) {
                                existOption = true;
                                break;
                            }
                        }
 
                        if (!existOption) {
                            checkOptionCompare = true;
                        }
                    }
 
                    return checkOptionCompare;
                }
 
                //  Select 옵션 값 추가하기
                function addOption() {
                    //  문자열일 때 button 요소가 enter 키에 작동하는 것 방지
                    if ($scope.vm.form.customFieldType === "INPUT") {
                        return;
                    }
                    // $scope.vm.form.customFieldType == "NUMBER" 존재한다
 
                    var duplication = false;
                    //  해시 태그는 입력 금지 - 공백 치환
                    $scope.vm.form.optionText = $rootScope.preventXss($scope.vm.form.optionText.replace(/#/gi, ""));
 
                    //  중복 여부 체크
                    for (var count in $scope.vm.form.options) {
                        var option = $scope.vm.form.options[count];
 
                        if (option === $scope.vm.form.optionText) {
                            duplication = true;
                            break;
                        }
                    }
 
                    //  중복이 아닐 경우
                    if (!duplication) {
                        if (!$rootScope.isDefined($scope.vm.form.optionText)) {
                            $scope.vm.form.optionText = "";
                            SweetAlert.warning($filter("translate")("customField.emptyInputValue"), $filter("translate")("customField.emptyAddValue")); //  입력 값 확인 알림, 입력한 값이 없습니다.
                            return;
                        }
 
                        $scope.vm.form.options.push($scope.vm.form.optionText);
                        $scope.vm.form.options.sort();
                        $scope.vm.form.optionText = "";
 
                        $timeout(function () {
                            $("#optionAdd").trigger("focus")
                        }, 200);
                    }
                    else {
                        SweetAlert.swal($filter("translate")("customField.duplicateInputValue"), $filter("translate")("customField.alreadyAddedValue"), "warning"); // "입력 값 중복 알림", "입력한 값이 이미 추가되어 있습니다."
                    }
                }
 
                //  폼 체크
                function formCheck(formInvalid) {
                    if (formInvalid) {
                        return true;
                    }
 
                    //  다중, 단일 선택일 경우에
                    if ($scope.vm.form.customFieldType === "MULTI_SELECT" || $scope.vm.form.customFieldType === "SINGLE_SELECT") {
                        //  옵션이 1개 이하일 경우에는 셀렉트 태그를 만들 수 없다.
                        if ($scope.vm.form.options.length < 1) {
                            return true;
                        }
                    }
 
                    return false;
                }
 
                //  폼 전송
                function formSubmit() {
                    $rootScope.spinner = true;
 
                     var content = angular.copy($scope.vm.form);
                     content.name = $rootScope.preventXss(content.name);
                     content.numberType =$scope.vm.form.numberType;
                     content.ipAdress = $scope.vm.form.ipAdress;
                     content.email = $scope.vm.form.email;
                     content.site = $scope.vm.form.site;
                     content.tel =$scope.vm.form.tel;
 
                    if ($scope.vm.form.customFieldType === 'MULTI_SELECT'|| $scope.vm.form.customFieldType === "SINGLE_SELECT") {
                        var convertDefaultValues = "";
 
                        angular.forEach(content.defaultValue.split("#"), function (value) {
                            if ($rootScope.isDefined(value)) {
                                convertDefaultValues += "#" + value.trim();
                            }
                        });
 
                        content.defaultValue = convertDefaultValues;
                    }
                    else {
                        //  문자열 필드일 때 옵션 값 제거
                        content.options = [];
                    }
 
                    CustomField.modify($resourceProvider.getContent(
                        content,
                        $resourceProvider.getPageContent(0, 0))).then(function (result) {
 
                        if (result.data.message.status === "success") {
                            $scope.fn.cancel();
                            //  목록 화면 갱신
                            $rootScope.$broadcast("getCustomFieldList", {});
                        }
                        else {
                            SweetAlert.error($filter("translate")("customField.failedToModifyUserDefinedFields"), result.data.message.message); // "사용자 정의 필드 수정 실패"
                        }
 
                        $rootScope.spinner = false;
                    });
                }
 
                //  폼 닫기
                function cancel() {
                    $rootScope.$broadcast("closeLayer");    //  팝업이 열리고 나서 js-multi, js-single 등에서 body 이벤트가 날아가는 현상 수정
                    $uibModalInstance.dismiss('cancel');
                    $(document).unbind("keydown");  //  단축키 이벤트 제거
                }
 
                //  상세 정보
                function detail() {
                    CustomField.detail($resourceProvider.getContent(
                        $scope.vm.search,
                        $resourceProvider.getPageContent(0, 1))).then(function (result) {
 
                        if (result.data.message.status === "success") {
                            if (angular.isDefined(result.data.data)) {
                                $scope.vm.form.name = result.data.data.name;
                                $scope.vm.form.customFieldType = result.data.data.customFieldType;
                                $scope.vm.form.defaultValue = result.data.data.defaultValue;
                                $scope.vm.form.useCustomFieldValue = result.data.data.useCustomFieldValue;
                                $scope.vm.form.requiredData = result.data.data.requiredData;
 
                                angular.forEach(result.data.data.customFieldValueVos, function (customFieldValueVo) {
                                    $scope.vm.form.options.push(customFieldValueVo.value);
                                });
                                //  옵션 값 원본 저장
                                $scope.vm.origin.options = angular.copy($scope.vm.form.options.sort());
                            }
                        }
                        else {
                            SweetAlert.swal($filter("translate")("customField.failedToDetailUserDefinedFields"), result.data.message.message, "error"); // "사용자 정의 필드 상세 정보 조회 실패"
                        }
                    });
                }
 
                $scope.fn.detail();
            }]);
    });