OWL ITS + 탐지시스템(인터넷 진흥원)
wyu
2022-01-07 911e65ca7d4f47ec18212375b4eb479c1c40acbe
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
/**
 * Created by wisestone on 2018-02-19.
 */
'use strict';
 
define([
        'app'
    ],
    function (app) {
        app.controller('ispFieldAddController', ['$scope', '$rootScope', '$log', '$resourceProvider', 'SweetAlert', '$uibModal', '$uibModalInstance', '$state', 'IspField', '$filter',
            function ($scope, $rootScope, $log, $resourceProvider, SweetAlert, $uibModal, $uibModalInstance, $state, IspField, $filter) {
 
                $scope.fn = {
                    cancel : cancel,    //  팝업 창 닫기
                    formSubmit : formSubmit,    //  폼 전송
                    formCheck : formCheck,   //  폼 체크
                    autoHyphenPhone : autoHyphenPhone // 연락처 입력시 하이픈 자동 입력
                };
 
                $scope.vm = {
                    form : {
                        code : "",  //코드
                        name : "",  //ISP명
                        manager : "",   //담당자
                        tel : "",  //전화번호
                        email : "",  //이메일
                        url : "", // url
                        memo : ""  //비고
                    }
                };
 
                //  폼 체크
                function formCheck(formInvalid) {
                    if (formInvalid) {
                        return true;
                    }
                    return false;
                }
 
                //  연락처 입력시 하이픈 자동 입력
                function autoHyphenPhone() {
                    let phone = $scope.vm.form.tel
                    let seoul = $scope.vm.form.tel
 
                    // 핸드폰 및 지방 지역번호 조건
                    phone.replace(/^[0-9]/g, '');
                    // 서울 지역번호 조건
                    seoul.replace(/^[0-9]/g, '');
                    var tmp = '';
 
                    if (phone.length < 4) {
                        return phone;
                    } else if (phone.length < 7) {
                        tmp += phone.substr(0, 3);
                        tmp += '-';
                        tmp += phone.substr(3);
                        $scope.vm.form.tel = tmp;
                    } else if (seoul.substring(0, 2) === "02" && seoul.length === 9) {    // 서울 지역번호 조건
                        tmp += seoul.substring(0, 2);
                        tmp += '-';
                        tmp += seoul.substring(2, 5);
                        tmp += '-';
                        tmp += seoul.substr(5);
                        $scope.vm.form.tel = tmp;
                    } else if (seoul.substring(0, 2) === "02" && seoul.length === 10) {   // 서울 지역번호 조건
                        tmp += seoul.substring(0, 2);
                        tmp += '-';
                        tmp += seoul.substring(2, 6);
                        tmp += '-';
                        tmp += seoul.substr(6);
                        $scope.vm.form.tel = tmp;
                    } else if (phone.length < 11) {     // 핸드폰 및 지방 지역번호 조건
                        tmp += phone.substr(0, 3);
                        tmp += '-';
                        tmp += phone.substr(3, 3);
                        tmp += '-';
                        tmp += phone.substr(6);
                        $scope.vm.form.tel = tmp;
                    } else {                           // 핸드폰 및 지방 지역번호 조건
                        tmp += phone.substr(0, 3);
                        tmp += '-';
                        tmp += phone.substr(3, 4);
                        tmp += '-';
                        tmp += phone.substr(7);
                        $scope.vm.form.tel = tmp;
                    }
                    return phone;
                }
 
                //  폼 전송
                function formSubmit(condition) {
                    $rootScope.spinner = true;
                    $scope.vm.form.tel = $scope.vm.form.tel.replace(/\-/g,'');  // 전화번호를 보낼땐 하이픈을 제거해서 DB에 저장
 
                    var content = {
                        code : $rootScope.preventXss($scope.vm.form.code),  //코드
                        name : $rootScope.preventXss($scope.vm.form.name),    //  ISP명
                        manager : $scope.vm.form.manager,   //담당자
                        tel : $scope.vm.form.tel,  //전화번호
                        email : $scope.vm.form.email,  //이메일
                        url : $scope.vm.form.url, // url
                        memo : $scope.vm.form.memo  //비고
                    };
 
                    IspField.add($resourceProvider.getContent(content,
                        $resourceProvider.getPageContent(0, 10))).then(function (result) {
 
                        if (result.data.message.status === "success") {
                            $scope.fn.cancel();
                            //  목록 화면 갱신
                            $rootScope.$broadcast("getPageList", {});
                        }
                        else {
                            SweetAlert.error($filter("translate")("ispField.failedToSelectIspFieldFullList"), result.data.message.message);
                        }
 
                        $rootScope.spinner = false;
                    });
 
                }
 
                //  팝업 창 닫기
                function cancel() {
                    $rootScope.$broadcast("closeLayer");    //  팝업이 열리고 나서 js-multi, js-single 등에서 body 이벤트가 날아가는 현상 수정
                    $uibModalInstance.dismiss('cancel');
                    $(document).unbind("keydown");  //  단축키 이벤트 제거
                }
 
            }
 
        ]);
    }
);