/
dialog-import.js
82 lines (63 loc) · 1.42 KB
/
dialog-import.js
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
app.controller(DIALOG_IMPORT, function($scope, $http, ui)
{
$scope.apiToken = ''
$scope.loading = false
$scope.form = {
language: '',
format: '',
fileName: '',
fileContent: '',
replace: true
}
$scope.languages = {}
$scope.open = function(languages, token)
{
$scope.apiToken = token
$scope.loading = false
$scope.form.language = ''
$scope.form.format = ''
$scope.form.fileName = ''
$scope.form.fileContent = ''
$scope.form.replace = true
$scope.languages = languages
document.getElementById('input-browse').value= null;
ui.openDialog(DIALOG_IMPORT)
}
$scope.onFileSelected = function(input)
{
const file = input.files[0]
$scope.form.fileName = file.name
$scope.$applyAsync()
var reader = new FileReader();
reader.onload = function()
{
$scope.form.fileContent = reader.result
}
reader.readAsText(file);
}
$scope.onBrowse = function(target)
{
$('#input-browse').click()
target.blur()
}
$scope.onImport = function(form)
{
$scope.loading = true
const config = {
headers : {
'Content-Type': 'text/plain'
}
}
$http.put(`/api/import/${form.language}/${form.format}?replace=${form.replace}&token=${$scope.apiToken}`, form.fileContent, config)
.then(function(response)
{
ui.showSuccess('Import successful')
ui.closeDialog(DIALOG_IMPORT)
},
function(response)
{
ui.showError('Error importing file')
$scope.loading = false
})
}
})