OWL ITS + 탐지시스템(인터넷 진흥원)
wyu
2021-11-29 5637a6a2fe52c61a46c057961f7caec99fdf2415
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
/**
 * Created by wisestone on 2018-05-08.
 */
'use strict';
 
define([
        'app', 'angular'
    ],
    function (app, angular) {
        app.controller('customFieldAddController', ['$scope', '$rootScope', '$log', '$resourceProvider', 'User', '$uibModalInstance', 'CustomField', 'SweetAlert', '$timeout', '$filter',
            function ($scope, $rootScope, $log, $resourceProvider, User, $uibModalInstance, CustomField, SweetAlert, $timeout, $filter) {
 
                $scope.fn = {
                    cancel : cancel,    //  팝업 창 닫기
                    formSubmit : formSubmit,    //  폼 전송
                    formCheck : formCheck,  //  폼 체크
                    addOption : addOption,   //  옵션 값 추가하기
                    removeOption : removeOption,    //  옵션 삭제
                    changeFieldType : changeFieldType,   //  필드 유형 변경
                };
 
                $scope.vm = {
                    form : {
                        name : "",  //  사용자 정의 필드 명
                        customFieldType : "INPUT",    //  사용자 정의 필드 유형
                        defaultValue : "",  //  기본 값
                        options : [],   //  옵션
                        optionText : "",  //  옵션 값
                        numberType : "",
                        ipAdress : "",
                        email : "",
                        site : "",
                        tel : ""
                    }
                };
 
                //  옵션 삭제
                function removeOption(index) {
                    $scope.vm.form.options.splice(index, 1);
                }
 
                //  필드 유형을 변경 했을 때 문자열 필드일 경우에는 옵션 값을 초기화해준다.
                function changeFieldType() {
                    // if ($scope.vm.form.customFieldType === "INPUT") {
                    $scope.vm.form.name = "";
                    $scope.vm.form.options = [];
                    $scope.vm.form.optionText = "";
 
                    $scope.vm.form.defaultValue = "";
                }
 
 
                //  Select 옵션 값 추가하기
                function addOption() {
                    //  문자열일 때 button 요소가 enter 키에 작동하는 것 방지
                    if ($scope.vm.form.customFieldType === "INPUT") {
                        return;
                    }
 
                    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.warning($filter("translate")("customField.duplicateInputValue"),
                            $filter("translate")("customField.alreadyAddedValue")); // "입력 값 중복 알림", "입력한 값이 이미 추가되어 있습니다."
                    }
                }
 
                // function chkPhoneType(type) {
                //     var input = $scope.vm.form.tel
                //
                //     //focus out인 경우
                //     //input type을 text로 바꾸고 '-'추가
                //     if(type == 'blur'){
                //         $scope.vm.form.tel;
                //         var phone = chkItemPhone(input);
                //     }
                //
                //     //focus인 경우
                //     //input type을 number로 바꾸고 '-' 제거
                //     if(type == 'focus'){
                //         var phone = input.replace( /-/gi, '');
                //         $scope.vm.form.tel('type', 'number');
                //     }
                //
                //     $scope.vm.form.tel(phone);
                // }
                //
                // function chkItemPhone(temp) {
                //     var number = temp.replace(/[^0-9]/g, "");
                //     var phone = "";
                //
                //     if (number.length < 9) {
                //         return number;
                //     } else if (number.length < 10) {
                //         phone += number.substr(0, 2);
                //         phone += "-";
                //         phone += number.substr(2, 3);
                //         phone += "-";
                //         phone += number.substr(5);
                //     } else if (number.length < 11) {
                //         phone += number.substr(0, 3);
                //         phone += "-";
                //         phone += number.substr(3, 3);
                //         phone += "-";
                //         phone += number.substr(6);
                //     } else {
                //         phone += number.substr(0, 3);
                //         phone += "-";
                //         phone += number.substr(3, 4);
                //         phone += "-";
                //         phone += number.substr(7);
                //     }
                //
                //     return phone;
                // }
 
                //  폼 체크
                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);
 
 
                    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;
                    }
 
                    CustomField.add($resourceProvider.getContent(
                        content,
                        $resourceProvider.getPageContent(0, 10))).then(function (result) {
 
                        if (result.data.message.status === "success") {
                            $scope.fn.cancel();
                            //  목록 화면 갱신
                            $rootScope.$broadcast("getCustomFieldList", {});
                        }
                        else {
                            SweetAlert.error($filter("translate")("customField.failedToCreateUserDefinedFields"), result.data.message.message); // "사용자 정의 필드 생성 실패"
                        }
 
                        $rootScope.spinner = false;
                    });
                }
 
                //  팝업 창 닫기
                function cancel() {
                    $rootScope.$broadcast("closeLayer");    //  팝업이 열리고 나서 js-multi, js-single 등에서 body 이벤트가 날아가는 현상 수정
                    $uibModalInstance.dismiss('cancel');
                    $(document).unbind("keydown");  //  단축키 이벤트 제거
                }
            }]);
    });