1
|
|
|
/* |
2
|
|
|
* MikoPBX - free phone system for small business |
3
|
|
|
* Copyright (C) 2017-2020 Alexey Portnov and Nikolay Beketov |
4
|
|
|
* |
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU General Public License as published by |
7
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* |
10
|
|
|
* This program is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
* GNU General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
16
|
|
|
* If not, see <https://www.gnu.org/licenses/>. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
/* global UserMessage, globalTranslate, PbxApi, upgradeStatusLoopWorker */ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Process push to button install new module from ZIP file |
23
|
|
|
* |
24
|
|
|
* @type {{checkStatusFileMerging(*=): void, uploadInProgress: boolean, initialize(): void, $uploadButton: (*|jQuery|HTMLElement), $progressBar: (*|jQuery|HTMLElement), $progressBarLabel: (*|jQuery), cbResumableUploadFile(*, *): void}} |
25
|
|
|
*/ |
26
|
|
|
const addNewExtension = { |
27
|
|
|
$uploadButton: $('#add-new-button'), |
28
|
|
|
$progressBar: $('#upload-progress-bar'), |
29
|
|
|
$progressBarLabel: $('#upload-progress-bar').find('.label'), |
30
|
|
|
uploadInProgress: false, |
31
|
|
|
initialize() { |
32
|
|
|
addNewExtension.$progressBar.hide(); |
33
|
|
|
PbxApi.SystemUploadFileAttachToBtn('add-new-button',['zip'], addNewExtension.cbResumableUploadFile); |
34
|
|
|
}, |
35
|
|
|
/** |
36
|
|
|
* Upload file by chunks |
37
|
|
|
* @param action |
38
|
|
|
* @param params |
39
|
|
|
*/ |
40
|
|
|
cbResumableUploadFile(action, params){ |
41
|
|
|
switch (action) { |
42
|
|
|
case 'fileSuccess': |
43
|
|
|
addNewExtension.checkStatusFileMerging(params.response); |
44
|
|
|
break; |
45
|
|
|
case 'uploadStart': |
46
|
|
|
addNewExtension.uploadInProgress = true; |
47
|
|
|
addNewExtension.$uploadButton.addClass('loading'); |
48
|
|
|
addNewExtension.$progressBar.show(); |
49
|
|
|
addNewExtension.$progressBarLabel.text(globalTranslate.ext_UploadInProgress); |
50
|
|
|
break; |
51
|
|
|
case 'progress': |
52
|
|
|
addNewExtension.$progressBar.progress({ |
53
|
|
|
percent: parseInt(params.percent, 10), |
54
|
|
|
}); |
55
|
|
|
break; |
56
|
|
|
case 'error': |
57
|
|
|
addNewExtension.$progressBarLabel.text(globalTranslate.ext_UploadError); |
58
|
|
|
addNewExtension.$uploadButton.removeClass('loading'); |
59
|
|
|
UserMessage.showMultiString(globalTranslate.ext_UploadError); |
60
|
|
|
break; |
61
|
|
|
default: |
62
|
|
|
} |
63
|
|
|
}, |
64
|
|
|
/** |
65
|
|
|
* Wait for file ready to use |
66
|
|
|
* |
67
|
|
|
* @param response ответ функции /pbxcore/api/upload/status |
68
|
|
|
*/ |
69
|
|
|
checkStatusFileMerging(response) { |
70
|
|
|
if (response === undefined || PbxApi.tryParseJSON(response) === false) { |
71
|
|
|
UserMessage.showMultiString(`${globalTranslate.ext_UploadError}`); |
72
|
|
|
return; |
73
|
|
|
} |
74
|
|
|
const json = JSON.parse(response); |
75
|
|
|
if (json === undefined || json.data === undefined) { |
76
|
|
|
UserMessage.showMultiString(`${globalTranslate.ext_UploadError}`); |
77
|
|
|
return; |
78
|
|
|
} |
79
|
|
|
const fileID = json.data.upload_id; |
80
|
|
|
const filePath = json.data.filename; |
81
|
|
|
mergingCheckWorker.initialize(fileID, filePath); |
|
|
|
|
82
|
|
|
}, |
83
|
|
|
|
84
|
|
|
}; |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
$(document).ready(() => { |
88
|
|
|
addNewExtension.initialize(); |
89
|
|
|
}); |
90
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.