-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathsymfonyProfiler.js
172 lines (147 loc) · 5.03 KB
/
symfonyProfiler.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/**
* Clear the state field and remove the checkbox
* @param key
*/
function clearState(key) {
var row = document.getElementById(key);
// disable the checkbox
var inputs = row.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == "checkbox" && inputs[i].name == "translationKey") {
inputs[i].checked = false;
inputs[i].disabled = true;
}
}
}
function syncMessage(key) {
var el = document.getElementById(key).getElementsByClassName("translation");
el[0].innerHTML = getLoaderHTML();
fetch(translationSyncUrl, {
method: 'POST',
body: serializeQueryString({message_id: key}),
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded',
}
}).then(res => res.text()).then((text) => {
el[0].innerHTML = text;
if (text !== "") {
clearState(key);
}
}).catch(() => {
el[0].innerHTML = "<span style='color:red;'>Error - Syncing message " + key + "</span>";
});
}
function syncAll() {
var el = document.getElementById("top-result-area");
el.innerHTML = getLoaderHTML();
fetch(translationSyncAllUrl, {
method: 'POST',
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded',
},
}).then(res => res.text()).then(text => {
el.innerHTML = text;
}).catch(() => {
el[0].innerHTML = "<span style='color:red;'>Error - Syncing all messages</span>";
});
}
function getEditForm(key) {
var el = document.getElementById(key).getElementsByClassName("translation");
el[0].innerHTML = getLoaderHTML();
fetch(translationEditUrl + "?" + serializeQueryString({message_id: key}), {
headers: {
'X-Requested-With': 'XMLHttpRequest',
},
}).then(res => res.text()).then(text => {
el[0].innerHTML = text;
}).catch(() => {
el[0].innerHTML = "<span style='color:red;'>Error - Getting edit form " + key + "</span>";
});
}
function saveEditForm(key, translation, additionalData = {}) {
var el = document.getElementById(key).getElementsByClassName("translation");
el[0].innerHTML = getLoaderHTML();
fetch(translationEditUrl, {
method: 'POST',
body: serializeQueryString(Object.assign({message_id: key, translation:translation}, additionalData)),
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded',
},
}).then(res => res.text()).then(text => {
el[0].innerHTML = text;
if (text !== "") {
clearState(key);
}
}).catch(() => {
el[0].innerHTML = "<span style='color:red;'>Error - Saving edit form " + key + "</span>";
})
return false;
}
function cancelEditForm(key, orgMessage) {
var el = document.getElementById(key).getElementsByClassName("translation");
el[0].innerHTML = orgMessage;
}
function toggleCheckAll(controller) {
var checkboxes = document.querySelectorAll('.translation-key-checkbox');
for (var i = 0; i < checkboxes.length; i++) {
checkboxes[i].checked = controller.checked;
}
}
function getLoaderHTML() {
var loader = document.getElementById('svg-loader');
return loader.outerHTML;
}
var serializeQueryString = function(obj, prefix) {
var str = [];
for(var p in obj) {
if (obj.hasOwnProperty(p)) {
var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
str.push(typeof v == "object" ? serializeQueryString(v, k) : encodeURIComponent(k) + "=" + encodeURIComponent(v));
}
}
return str.join("&");
};
var saveTranslations = function(form) {
"use strict";
if (typeof(form.translationKey) === 'undefined') {
return false;
}
var inputs = form.translationKey;
var selected = [];
if (!inputs.value) {
for (var val in inputs) {
if (inputs.hasOwnProperty(val) && inputs[val].value) {
if (inputs[val].checked) {
selected.push(inputs[val].value);
}
}
}
} else if (inputs.checked) {
selected.push(inputs.value);
}
var el = document.getElementById('translationResult');
el.innerHTML = getLoaderHTML();
el.classList.remove('label');
el.classList.remove('status-error');
el.classList.remove('status-success');
fetch(form.action, {
method: 'POST',
body: serializeQueryString({selected: selected}),
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded',
},
}).then(res => res.text()).then(text => {
el.classList.add('label');
el.classList.add('status-success');
el.innerHTML = text;
}).catch(error => {
el.classList.add('label');
el.classList.add('status-error');
el.innerHTML = error;
})
return false;
};