/
app.js
147 lines (127 loc) · 4.05 KB
/
app.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
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
function isAuthenticated() {
const api_key = localStorage.getItem('backendaiconsole.api_key');
const secret_key = localStorage.getItem('backendaiconsole.secret_key');
const api_endpoint = localStorage.getItem('backendaiconsole.api_endpoint');
let authenticated = false;
if (api_key && secret_key && api_endpoint &&
api_key !== 'null' && secret_key !== 'null' && api_endpoint !== 'null') {
authenticated = true;
}
return authenticated;
}
function backToPreviousPage(e) {
window.history.back();
}
function setNotification(text) {
document.querySelector('#lablup-notification').text = text;
document.querySelector('#lablup-notification').show();
}
function setNotificationNavbar(text, timeout) {
document.querySelector('#lablup-notification-navbar').innerText = text;
if (timeout != 0) {
setTimeout(function () {
document.querySelector('#lablup-notification-navbar').innerText = '';
}, timeout);
}
}
function closeNotification() {
document.querySelector('#lablup-notification').visible = false;
}
function popAlert(html) {
var alert = document.querySelector('lablup-alert');
alert.text = html;
alert.show();
}
function closeAlert() {
document.getElementById('lablup-alert').close();
}
function activateSpinner() {
var spinner = document.querySelector('#lablup-loading-spinner');
spinner.style.display = 'block';
spinner.active = true;
}
function deactivateSpinner() {
var spinner = document.querySelector('#lablup-loading-spinner');
setTimeout(function () {
spinner.style.display = 'none';
}, 500);
spinner.active = false;
}
function toggleSpinner() {
var spinner = document.querySelector('#lablup-loading-spinner');
spinner.active = !spinner.active;
}
function confirmHrefAction(link, message) {
var dialog = document.querySelector('#confirmDialog');
dialog.querySelector('#confirmDialog-message').innerHTML = message;
dialog.querySelector('#confirmDialog-confirm').href = link;
dialog.open();
}
function confirmJSAction(js, message) {
var dialog = document.querySelector('#confirmDialog');
dialog.querySelector('#confirmDialog-message').innerHTML = message;
dialog.querySelector('#confirmDialog-confirm').setAttribute('onclick', js);
dialog.open();
}
function notificationDialog(message) {
var dialog = document.querySelector('#notificationDialog');
dialog.querySelector('#notificationDialog-message').innerHTML = message;
dialog.open();
}
function resetInputForm(event) {
Polymer.dom(event).localTarget.errorMessage = '';
Polymer.dom(event).localTarget.invalid = false;
}
function warnInputForm(response) {
if (!response.error_msg) {
for (var key in response) {
if (document.getElementById("id_" + key) != undefined) {
if (document.getElementById("id_" + key).errorMessage == undefined) {
document.getElementById("id_" + key).errorMessage = '';
}
for (var message in response[key]) {
document.getElementById("id_" + key).errorMessage = response[key][message].message;
document.getElementById("id_" + key).invalid = true;
}
}
}
}
return true;
}
function sendData(id) {
document.getElementById(id).submit();
}
function mapToggleButtonValue(e) {
if (Polymer.dom(e).localTarget.checked) {
Polymer.dom(e).localTarget.value = "checked";
} else {
Polymer.dom(e).localTarget.value = undefined;
}
}
function moveTo(url) {
activateSpinner();
window.location.href = url;
}
function toggleDisplayElement(e) {
var o = document.getElementById(e);
if (o.style.display == '' || o.style.display == undefined || o.style.display != 'block') {
o.style.display = 'block';
} else {
o.style.display = 'none';
}
}
function toggleVisibilityElement(e) {
var o = document.getElementById(e);
if (o.classList.contains('visible')) {
o.classList.remove('visible');
o.classList.add("invisible");
} else {
o.classList.remove("invisible");
o.classList.add('visible');
}
}
var forEach = function (array, callback, scope) {
for (var i = 0; i < array.length; i++) {
callback.call(scope, i, array[i]);
}
};