OWL ITS + 탐지시스템(인터넷 진흥원)
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
/**
 * 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 : "",  //  기본 값
                        defaultNumValue : "",  //  기본 값
                        defaultDateValue : "",  //  기본 값
                        defaultIpValue : "",  //  기본 값
                        defaultEmailValue : "",  //  기본 값
                        defaultTelValue : "",  //  기본 값
                        defaultSiteValue : "",  //  기본 값
                        options : [],   //  옵션
                        optionText : "",  //  옵션 값
                        numberType : "",
                        ipAddress : "",
                        email : "",
                        site : "",
                        tel : "",
                        requiredData : false
                    }
                };
 
                //  옵션 삭제
                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 = "";
                    $scope.vm.form.defaultNumValue = "";
                    $scope.vm.form.defaultDateValue = "";
                    $scope.vm.form.defaultIpValue = "";
                    $scope.vm.form.defaultEmailValue = "";
                    $scope.vm.form.defaultTelValue = "";
                    $scope.vm.form.defaultSiteValue = "";
                }
 
 
                //  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 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");  //  단축키 이벤트 제거
                }
            }]);
    });