File size: 5,823 Bytes
5586a08
 
 
 
 
 
9c86df2
 
f628a8a
 
5bd6539
cb10cfb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f628a8a
 
 
 
 
 
5bd6539
 
5586a08
 
 
 
d6901d9
 
 
 
 
 
 
 
 
 
 
 
5586a08
 
f628a8a
 
 
5586a08
9c86df2
 
f628a8a
 
 
 
5586a08
 
 
 
f628a8a
5bd6539
5586a08
 
 
 
 
 
5bd6539
9c86df2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5586a08
 
 
5bd6539
9c86df2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5586a08
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSV Upload</title>
    <!-- Подключение стилей Notyf -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/notyf/notyf.min.css">
    <!-- Подключение стилей Bootstrap -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
    <style>
        body {
            font-family: Arial, sans-serif;
            text-align: center;
            background-color: #f0f0f0;
            margin: 0;
            padding: 0;
        }
        h1 {
            background-color: #4CAF50;
            color: white;
            padding: 20px;
            margin: 0;
            border-bottom: 2px solid #388E3C;
        }
        .input-row {
            display: flex;
            justify-content: center;
            gap: 10px;
            margin-top: 20px;
        }
        .input-row input[type="file"] {
            padding: 10px;
            font-size: 16px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
        .input-row input[type="checkbox"] {
            margin-top: 5px;
        }
        .input-row label {
            display: flex;
            align-items: center;
            color: #4CAF50;
            font-size: 16px;
        }
        #uploadButton {
            color: white;
            background-color: #4CAF50;
            border: none;
            cursor: pointer;
            padding: 10px 20px;
            font-size: 16px;
            border-radius: 5px;
            margin-top: 20px;
        }
        #uploadButton:hover {
            background-color: #388E3C;
        }
        .center-spinner {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            z-index: 1000;
        }
    </style>
</head>
<body>
    <h1>Upload CSV File</h1>
    <form id="uploadForm" enctype="multipart/form-data" method="post">
        <div class="input-row">
            <input type="file" name="file" accept=".csv">
        </div>
        <div class="input-row">
            <label>
                <input type="checkbox" name="verify_phone" value="1"> Verify Phone
            </label>
            <label>
                <input type="checkbox" name="add_curator" value="1"> Add Curator
            </label>
        </div>
        <input id="uploadButton" type="submit" value="Upload">
    </form>
    <div id="result"></div>
    <div class="spinner-border text-success center-spinner" role="status" style="display: none;">
        <span class="sr-only">Loading...</span>
    </div>

    <!-- Подключение скрипта Notyf -->
    <script src="https://cdn.jsdelivr.net/npm/notyf/notyf.min.js"></script>
    <!-- Подключение скриптов Bootstrap -->
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        document.getElementById('uploadForm').addEventListener('submit', function(event) {
            event.preventDefault();
            const form = new FormData(this);
            const loader = document.querySelector('.spinner-border');
            loader.style.display = 'block'; // Показываем спиннер
            fetch('/upload_csv', {
                method: 'POST',
                body: form
            })
            .then(response => response.json())
            .then(data => {
                loader.style.display = 'none'; // Скрываем спиннер после завершения
                const notyf = new Notyf({
                    duration: 5000, // Длительность показа уведомления
                    position: {
                        x: 'right',
                        y: 'bottom'
                    },
                    types: [
                        {
                            type: 'success',
                            background: 'green',
                            icon: {
                                className: 'notyf__icon--success',
                                tagName: 'span',
                                text: ''
                            }
                        }
                    ]
                });
                notyf.success(data.message); // Показываем уведомление с сообщением от сервера
            })
            .catch(error => {
                console.error('Error:', error);
                loader.style.display = 'none'; // Скрываем спиннер в случае ошибки
                const notyf = new Notyf({
                    duration: 5000, // Длительность показа уведомления
                    position: {
                        x: 'right',
                        y: 'bottom'
                    },
                    types: [
                        {
                            type: 'error',
                            background: 'red',
                            icon: {
                                className: 'notyf__icon--error',
                                tagName: 'span',
                                text: ''
                            }
                        }
                    ]
                });
                notyf.error('An error occurred while uploading the file.'); // Показываем уведомление об ошибке
            });
        });
    </script>
</body>
</html>