OWL ITS + 탐지시스템(인터넷 진흥원)
이민희
2021-12-02 616d76059d929650113f8a4ec750d86c4647b064
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
/**
 * Created by wisestone on 2017-12-15.
 */
'use strict';
 
define([
        'app',
        'angular'
    ],
    function (app, angular) {
        app.controller('userModifyController', ['$scope', '$rootScope', '$log', '$resourceProvider', 'User', '$uibModalInstance', 'parameter', 'SweetAlert', '$timeout', '$filter',
            function ($scope, $rootScope, $log, $resourceProvider, User, $uibModalInstance, parameter, SweetAlert, $timeout, $filter) {
 
                $scope.fn = {
                    cancel: cancel, //  팝업 창 닫기
                    formSubmit: formSubmit, //  폼 전송
                    formCheck: formCheck,   //  폼 체크
                    detail: detail, //  상세 정보 조회
                    withDraw : withDraw, //  회원 탈퇴
                    onFileSelect : onFileSelect    //   프로필 업로드
                };
 
                $scope.vm = {
                    form: {
                        id: parameter.id,
                        account: "",
                        name: "",
                        phone: "",
                        reservationNotifyTime : "", //  이메일 알림 시간
                        realtimeNotify : "", // 이메일 실시간
                        profileImage : null, //   업로드하는 프로필
                        profileImageName : null  //  프로필 명
                    }
                };
 
                //  회원 탈퇴
                function withDraw() {
                    //  삭제 알림
                    SweetAlert.swal({
                            title : $filter("translate")("users.membershipWithdrawal"), //  회원 탈퇴
                            text : $filter("translate")("users.proceedWithMembershipWithdrawal"), //    회원 탈퇴를 진행하겠습니까? 회원 탈퇴를 하면 업무 공간의 모든 데이터가 사라지고 복구할 수 없습니다.
                            type : "warning",
                            showCancelButton : true,
                            confirmButtonColor : "#DD6B55",
                            confirmButtonText : $filter("translate")("users.withdrawal"), // "탈퇴"
                            cancelButtonText : $filter("translate")("common.cancel"), // "취소"
                            closeOnConfirm : false,
                            closeOnCancel : true
                        },
                        function (isConfirm) {
                            SweetAlert.close();
                            if (isConfirm) {
                                $rootScope.spinner = true;
 
                                User.withDraw($resourceProvider.getContent(
                                    {},
                                    $resourceProvider.getPageContent(0, 0))).then(function (result) {
                                    if (result.data.message.status === "success") {
                                        SweetAlert.success($filter("translate")("users.successWithdrawalFromMembership"), $filter("translate")("users.completedWithdrawalFromOwlITS")); // "회원 탈퇴 성공", "OWL ITS 에서 탈퇴가 완료되었습니다."
                                        //  로그아웃 실행 - common.controller.js $broadcast
                                        $rootScope.$broadcast("logout");
                                    }
                                    else {
                                        $timeout(function () {
                                            SweetAlert.error($filter("translate")("users.failedMemberWithdrawal"), result.data.message.message); // "회원 탈퇴 실패"
                                        }, 100);
                                    }
 
                                    $rootScope.spinner = false;
                                });
                            }
                        });
                }
 
                //  상세 정보 조회
                function detail() {
                    User.detail($resourceProvider.getContent(
                        {
                            id : $rootScope.user.id,
                            deep : "01"
                        },
                        $resourceProvider.getPageContent(0, 0))).then(function (result) {
                        if (result.data.message.status === "success") {
                            $scope.vm.form.name = result.data.data.name;
                            $scope.vm.form.account = result.data.data.account;
                            $scope.vm.form.phone = result.data.data.phone;
                            if(result.data.data.reservationNotifyTime === "realTime"){
                                $scope.vm.form.reservationNotifyTime = "";
                                $scope.vm.form.realtimeNotify = true;
                            }else{
                                $scope.vm.form.reservationNotifyTime = result.data.data.reservationNotifyTime;
                            }
                        }
                        else {
                            SweetAlert.swal($filter("translate")("users.failedToSelectUserDetail"), result.data.message.message, "error"); // "사용자 상세 정보 조회 실패"
                        }
                    });
                }
 
                //  프로필 업로드
                function onFileSelect($files) {
                    $scope.vm.form.profileImage = $files;
 
                    if ($rootScope.isDefined($files)) {
                        $scope.vm.form.profileImageName = $files[0].name;
                    }
                    else {
                        $scope.vm.form.profileImageName = "";
                    }
                }
 
                //  폼 체크
                function formCheck(formInvalid) {
                    if (formInvalid) {
                        return true;
                    }
 
                    return false;
                }
 
                //  폼 전송
                function formSubmit() {
                    $rootScope.spinner = true;
 
                    var content = angular.copy($scope.vm.form);
                    content.name = $rootScope.preventXss(content.name);
                    content.phone = $rootScope.preventXss(content.phone);
                    content.profile = $scope.vm.form.profileImageName;
                    if(content.realtimeNotify){
                        content.reservationNotifyTime = "realTime";
                    }else {
                        content.reservationNotifyTime = $scope.vm.form.reservationNotifyTime;
                    }
 
                    User.modify({
                            method : "POST",
                            file : $scope.vm.form.profileImage,
                            //      data 속성으로 별도의 데이터 전송
                            fields : {
                                content : content
                            },
                            fileFormDataName : "file"
                        })
                        .then(function (result) {
                            if (result.data.message.status === "success") {
                                User.getUserSession({}).then(function (result) {
                                    if (result.message.status === "success") {
                                        if (result.data != null) {
                                            $rootScope.user = result.data;  //  전역으로 사용하는 로그인 사용자 정보.
                                        }
                                        else {
                                            throw {message: $filter("translate")("users.notExistUserSession")}; // "사용자 세션이 존재하지 않습니다."
                                        }
                                    }
                                    else {
                                        throw {message: $filter("translate")("users.notExistUserSession")}; // "사용자 세션이 존재하지 않습니다."
                                    }
 
                                    $rootScope.spinner = false;
                                });
 
                                $scope.fn.cancel();
                            }
                            else {
                                SweetAlert.swal({
                                    title : $filter("translate")("users.failedToModifyUser"), // "사용자 수정 실패"
                                    text : result.data.message.message,
                                    type : "error"
                                });
 
                                $rootScope.spinner = false;
                            }
                        });
                }
 
                //  팝업 창 닫기
                function cancel() {
                    $rootScope.$broadcast("closeLayer");    //  팝업이 열리고 나서 js-multi, js-single 등에서 body 이벤트가 날아가는 현상 수정
                    $uibModalInstance.dismiss('cancel');
                    $(document).unbind("keydown");  //  단축키 이벤트 제거
                }
 
                $scope.fn.detail();
            }]);
    });