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
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
239
240
241
242
243
244
245
246
247
/**
 * Created by wisestone on 2018-05-08.
 */
'use strict';
 
define([
        'app',
        'angular'
    ],
    function (app, angular) {
        app.controller('hostingFieldModifyController', ['$scope', '$rootScope', '$log', '$resourceProvider', '$uibModalInstance', 'HostingField', 'parameter', 'SweetAlert', '$filter', '$q',
            function ($scope, $rootScope, $log, $resourceProvider, $uibModalInstance, HostingField, parameter, SweetAlert, $filter, $q) {
 
                $scope.fn = {
                    detail : detail,  //  상세 조회
                    cancel : cancel,    //  팝업 창 닫기
                    formSubmit : formSubmit,    //  폼 전송
                    formCheck : formCheck,  //  폼 체크
                    addTel : addTel,
                    addMail : addMail,
                    removeTelInput : removeTelInput,
                    removeMailInput : removeMailInput
                };
 
                $scope.vm = {
                    id : parameter.id,
                    form : {
                        code : "",  //코드
                        name : "",  //호스팅명
                        manager : "",   //담당자
                        tel : "",  //전화번호
                        email : "",  //이메일
                        url : "", // url
                        memo : "",  //메모(비고)
                        inputTels : [0],
                        tels : {},
                        inputMails : [0],
                        emails : {}
                    }
                };
 
                // 폼 체크
                function formCheck(formInvalid) {
                    if (formInvalid) {
                        return true;
                    }
 
                    return false;
                }
 
                //  폼 전송
                function formSubmit() {
                    $rootScope.spinner = true;
 
                    var content = {
                        id : parameter.id,
                        code : $rootScope.preventXss($scope.vm.form.code),
                        name : $rootScope.preventXss($scope.vm.form.name),
                        manager : $rootScope.preventXss($scope.vm.form.manager),
                        tels : (function () {
                            var telList = [];
                            if ($scope.vm.form.tels != null) {
                                angular.forEach($scope.vm.form.tels, function (tel) {
                                    telList.push(tel);
                                });
                                telList  = telList.filter(function(item) { //쓰레기 데이터 필터링
                                    return item !== null && item !== undefined && item !== '';
                                });
                                telList  = telList.filter(function(item, idx){
                                    return telList.findIndex(function(item2, idx2){
                                        return item === item2
                                    }) == idx;
                                });
                            }
                            return telList;
                        })(),
                        emails : (function () {
                            var emailList = [];
                            if ($scope.vm.form.emails != null) {
                                angular.forEach($scope.vm.form.emails, function (email) {
                                    emailList.push(email);
                                });
                                emailList  = emailList.filter(function(item) { //쓰레기 데이터 필터링
                                    return item !== null && item !== undefined && item !== '';
                                });
                                emailList  = emailList.filter(function(item, idx){
                                    return emailList.findIndex(function(item2, idx2){
                                        return item === item2
                                    }) == idx;
                                });
                            }
                            return emailList;
                        })(),
                        url : $rootScope.preventXss($scope.vm.form.url), // url
                        memo : $rootScope.preventXss($scope.vm.form.memo)
                    };
 
                    HostingField.modify($resourceProvider.getContent(
                        content,
                        $resourceProvider.getPageContent(0, 0))).then(function (result) {
 
                        if (result.data.message.status === "success") {
                            $scope.fn.cancel();
 
                            //  목록 화면 갱신
                            $rootScope.$broadcast("getPageList", {});
                        }
                        else {
                            SweetAlert.error($filter("translate")("hostingField.failedHostingFieldRegistration"), result.data.message.message); //등록 실패
                        }
 
                        $rootScope.spinner = false;
                    });
 
                }
 
                // 메일 주소 input 창 추가 버튼
                function addTel() {
                    var arrayFull = true;      // 배열이 가득 차 있는지 여부
                    var index = 0;
                    $scope.vm.form.inputTels.forEach(function (tel) {
                        if (!$rootScope.isDefined($scope.vm.form.tels[index])) {
                            arrayFull = false;
                        }
                        index++;
                    });
 
                    if (arrayFull) {
                        $scope.vm.form.inputTels.push(index);
                        $scope.vm.form.tels[index] = "";
                    } else {
                        SweetAlert.warning($filter("translate")("companyField.writeCompanyTel"), $filter("translate")("companyField.writeTel")); // 추가버튼 경고
                    }
                }
 
                // 메일 주소 input 창 추가 버튼
                function addMail() {
                    var arrayFull = true;      // 배열이 가득 차 있는지 여부
                    var index = 0;
                    $scope.vm.form.inputMails.forEach(function (email) {
                        if (!$rootScope.isDefined($scope.vm.form.emails[index])) {
                            arrayFull = false;
                        }
                        index++;
                    });
 
                    if (arrayFull) {
                        $scope.vm.form.inputMails.push(index);
                        $scope.vm.form.emails[index] = ""
                    } else {
                        SweetAlert.warning($filter("translate")("issue.writeIssueMail"), $filter("translate")("issue.writeMail")); // 추가버튼 경고
                    }
                }
 
                // 연락처 input 삭제
                function removeTelInput(index) {
                    $scope.vm.form.inputTels.splice(index, 1);
                }
 
                // 이메일 주소 input 삭제
                function removeMailInput(index) {
                    $scope.vm.form.inputMails.splice(index, 1);
                }
 
                //  팝업 창 닫기
                function cancel() {
                    $rootScope.$broadcast("closeLayer");    //  팝업이 열리고 나서 js-multi, js-single 등에서 body 이벤트가 날아가는 현상 수정
                    $uibModalInstance.dismiss('cancel');
                    $(document).unbind("keydown");  //  단축키 이벤트 제거
                }
 
                //  상세 정보
                function detail() {
                    var deferred = $q.defer();
 
                    var conditions = {
                        id : parameter.id
                    }
 
                    HostingField.detail($resourceProvider.getContent(
                        conditions,
                        $resourceProvider.getPageContent(0, 1))).then(function (result) {
 
                        if (result.data.message.status === "success") {
                            if (result.data.content != null) {
                                $scope.vm.form.code = result.data.content.code;
                                $scope.vm.form.name = result.data.content.name;
                                $scope.vm.form.manager = result.data.content.manager;
 
                                if (result.data.content.tel != null) {
                                    var inputTels = $scope.vm.form.inputTels;
                                    var tels = result.data.content.tel;
                                    if (result.data.content.tel.indexOf("[") !== -1){
                                        tels = result.data.content.tel.substr(1, result.data.content.tel.indexOf("]")-1);
                                    }
                                    var telArr = tels.split(",");
                                    angular.forEach(telArr, function (tel) {
                                        var tell = tel.trim();
                                        inputTels.push(tell);
                                    });
                                    inputTels  = inputTels.filter(function(item) {
                                        return item !== null && item !== undefined && item !== '';
                                    });
                                    if (inputTels[0] === 0 || inputTels[0] === "") {
                                        inputTels.shift();
                                    }
                                    inputTels.push("");
                                    $scope.vm.form.tels = angular.copy(inputTels);
                                }
 
                                if (result.data.content.email != null) {
                                    var inputMails = $scope.vm.form.inputMails;
                                    var emails = result.data.content.email
                                    if (result.data.content.email.indexOf("[") !== -1){
                                        emails = result.data.content.email.substr(1, result.data.content.email.indexOf("]")-1);
                                    }
                                    var emailArr = emails.split(",");
                                    angular.forEach(emailArr, function (email) {
                                        var mail = email.trim();
                                        inputMails.push(mail);
                                    });
                                    inputMails  = inputMails.filter(function(item) {
                                        return item !== null && item !== undefined && item !== '';
                                    });
                                    if(inputMails[0] === 0 || inputMails[0] === "") { // 첫번째 배열은 공백으로
                                        inputMails.shift();
                                    }
                                    inputMails.push("");
                                    $scope.vm.form.emails = angular.copy(inputMails);
                                }
 
                                $scope.vm.form.url = result.data.content.url;
                                $scope.vm.form.memo = result.data.content.memo;
                            }
                        }
                        else {
                            SweetAlert.swal($filter("translate")("hostingField.failedToDetailHostingFieldModify"), result.data.message.message, "error"); // "상세 정보 조회 실패"
                        }
                        deferred.resolve(result.data.data);
                    });
                    return deferred.promise;
                }
 
                $scope.fn.detail();
 
            }]);
    });