/
dialog-language.js
73 lines (59 loc) · 1.23 KB
/
dialog-language.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
app.controller(DIALOG_LANGUAGE, function($scope, database, ui)
{
$scope.form = {
id: '',
originalCode: '',
buttonDisabled: true
}
$scope.init = function()
{
const data = []
for (const locale in LOCALES)
{
data.push({
id: locale,
text: LOCALES[locale]
})
}
$scope.select().select2({
placeholder: 'Language',
data: data
})
}
$scope.openAdd = function()
{
open(null, '')
}
$scope.openEdit = function(language)
{
open(language.id, language.code)
}
function open(id, select)
{
$scope.form.id = id
$scope.form.originalCode = select
$scope.form.buttonDisabled = true
$scope.select().val(select).trigger('change.select2')
ui.openDialog(DIALOG_LANGUAGE)
}
$scope.select = function()
{
return $('.js-example-placeholder-single')
}
$scope.onLanguageSelected = function()
{
$scope.form.buttonDisabled = ($scope.select().val() == $scope.form.originalCode)
$scope.$applyAsync()
}
$scope.onAdd = function()
{
controller(CONTROLLER_LANGUAGES).addLanguage($scope.select().val())
ui.closeDialog(DIALOG_LANGUAGE)
}
$scope.onEdit = function(form)
{
controller(CONTROLLER_LANGUAGES).editLanguage(form.id, $scope.select().val())
ui.closeDialog(DIALOG_LANGUAGE)
}
$scope.init()
})