@@ -19,83 +19,76 @@ function syncMessage(key) {
19
19
var el = document . getElementById ( key ) . getElementsByClassName ( "translation" ) ;
20
20
el [ 0 ] . innerHTML = getLoaderHTML ( ) ;
21
21
22
- Sfjs . request (
23
- translationSyncUrl ,
24
- function ( xhr ) {
25
- // Success
26
- el [ 0 ] . innerHTML = xhr . responseText ;
27
-
28
- if ( xhr . responseText !== "" ) {
29
- clearState ( key ) ;
30
- }
31
- } ,
32
- function ( xhr ) {
33
- // Error
34
- el [ 0 ] . innerHTML = "<span style='color:red;'>Error - Syncing message " + key + "</span>" ;
35
- } ,
36
- serializeQueryString ( { message_id : key } ) ,
37
- { method : 'POST' }
38
- ) ;
22
+ fetch ( translationSyncUrl , {
23
+ method : 'POST' ,
24
+ body : serializeQueryString ( { message_id : key } ) ,
25
+ headers : {
26
+ 'X-Requested-With' : 'XMLHttpRequest' ,
27
+ 'Content-Type' : 'application/x-www-form-urlencoded' ,
28
+ }
29
+ } ) . then ( res => res . text ( ) ) . then ( ( text ) => {
30
+ el [ 0 ] . innerHTML = text ;
31
+
32
+ if ( text !== "" ) {
33
+ clearState ( key ) ;
34
+ }
35
+ } ) . catch ( ( ) => {
36
+ el [ 0 ] . innerHTML = "<span style='color:red;'>Error - Syncing message " + key + "</span>" ;
37
+ } ) ;
39
38
}
40
39
41
40
function syncAll ( ) {
42
41
var el = document . getElementById ( "top-result-area" ) ;
43
42
el . innerHTML = getLoaderHTML ( ) ;
44
43
45
- Sfjs . request (
46
- translationSyncAllUrl ,
47
- function ( xhr ) {
48
- // Success
49
- el . innerHTML = xhr . responseText ;
50
- } ,
51
- function ( xhr ) {
52
- // Error
53
- el [ 0 ] . innerHTML = "<span style='color:red;'>Error - Syncing all messages</span>" ;
44
+ fetch ( translationSyncAllUrl , {
45
+ method : 'POST' ,
46
+ headers : {
47
+ 'X-Requested-With' : 'XMLHttpRequest' ,
48
+ 'Content-Type' : 'application/x-www-form-urlencoded' ,
54
49
} ,
55
- { } ,
56
- { method : 'POST' }
57
- ) ;
50
+ } ) . then ( res => res . text ( ) ) . then ( text => {
51
+ el . innerHTML = text ;
52
+ } ) . catch ( ( ) => {
53
+ el [ 0 ] . innerHTML = "<span style='color:red;'>Error - Syncing all messages</span>" ;
54
+ } ) ;
58
55
}
59
56
60
57
function getEditForm ( key ) {
61
58
var el = document . getElementById ( key ) . getElementsByClassName ( "translation" ) ;
62
59
el [ 0 ] . innerHTML = getLoaderHTML ( ) ;
63
60
64
- Sfjs . request (
65
- translationEditUrl + "?" + serializeQueryString ( { message_id : key } ) ,
66
- function ( xhr ) {
67
- // Success
68
- el [ 0 ] . innerHTML = xhr . responseText ;
61
+ fetch ( translationEditUrl + "?" + serializeQueryString ( { message_id : key } ) , {
62
+ headers : {
63
+ 'X-Requested-With' : 'XMLHttpRequest' ,
69
64
} ,
70
- function ( xhr ) {
71
- // Error
72
- el [ 0 ] . innerHTML = "<span style='color:red;'>Error - Getting edit form " + key + "</span>" ;
73
- } ,
74
- { method : 'GET' }
75
- ) ;
65
+ } ) . then ( res => res . text ( ) ) . then ( text => {
66
+ el [ 0 ] . innerHTML = text ;
67
+ } ) . catch ( ( ) => {
68
+ el [ 0 ] . innerHTML = "<span style='color:red;'>Error - Getting edit form " + key + "</span>" ;
69
+ } ) ;
76
70
}
77
71
78
72
function saveEditForm ( key , translation ) {
79
73
var el = document . getElementById ( key ) . getElementsByClassName ( "translation" ) ;
80
74
el [ 0 ] . innerHTML = getLoaderHTML ( ) ;
81
75
82
- Sfjs . request (
83
- translationEditUrl ,
84
- function ( xhr ) {
85
- // Success
86
- el [ 0 ] . innerHTML = xhr . responseText ;
87
-
88
- if ( xhr . responseText !== "" ) {
89
- clearState ( key ) ;
90
- }
91
- } ,
92
- function ( xhr ) {
93
- // Error
94
- el [ 0 ] . innerHTML = "<span style='color:red;'>Error - Saving edit form " + key + "</span>" ;
76
+ fetch ( translationEditUrl , {
77
+ method : 'POST' ,
78
+ body : serializeQueryString ( { message_id : key , translation :translation } ) ,
79
+ headers : {
80
+ 'X-Requested-With' : 'XMLHttpRequest' ,
81
+ 'Content-Type' : 'application/x-www-form-urlencoded' ,
95
82
} ,
96
- serializeQueryString ( { message_id : key , translation :translation } ) ,
97
- { method : 'POST' }
98
- ) ;
83
+ } ) . then ( res => res . text ( ) ) . then ( text => {
84
+ el [ 0 ] . innerHTML = text ;
85
+
86
+ if ( text !== "" ) {
87
+ clearState ( key ) ;
88
+ }
89
+ } ) . catch ( ( ) => {
90
+ el [ 0 ] . innerHTML = "<span style='color:red;'>Error - Saving edit form " + key + "</span>" ;
91
+ } )
99
92
100
93
return false ;
101
94
}
@@ -130,17 +123,6 @@ var serializeQueryString = function(obj, prefix) {
130
123
return str . join ( "&" ) ;
131
124
} ;
132
125
133
- // We need to hack a bit Sfjs.request because it does not support POST requests
134
- // May not work for ActiveXObject('Microsoft.XMLHTTP'); :(
135
- ( function ( open ) {
136
- XMLHttpRequest . prototype . open = function ( method , url , async , user , pass ) {
137
- open . call ( this , method , url , async , user , pass ) ;
138
- if ( method . toLowerCase ( ) === 'post' ) {
139
- this . setRequestHeader ( "Content-Type" , "application/x-www-form-urlencoded" ) ;
140
- }
141
- } ;
142
- } ) ( XMLHttpRequest . prototype . open ) ;
143
-
144
126
var saveTranslations = function ( form ) {
145
127
"use strict" ;
146
128
@@ -169,22 +151,22 @@ var saveTranslations = function(form) {
169
151
el . classList . remove ( 'status-error' ) ;
170
152
el . classList . remove ( 'status-success' ) ;
171
153
172
- Sfjs . request (
173
- form . action ,
174
- function ( xhr ) {
175
- // Success
176
- el . classList . add ( 'label' ) ;
177
- el . classList . add ( 'status-success' ) ;
178
- el . innerHTML = xhr . responseText ;
154
+ fetch ( form . action , {
155
+ method : 'POST' ,
156
+ body : serializeQueryString ( { selected : selected } ) ,
157
+ headers : {
158
+ 'X-Requested-With' : 'XMLHttpRequest' ,
159
+ 'Content-Type' : 'application/x-www-form-urlencoded' ,
179
160
} ,
180
- function ( xhr ) {
181
- // Error
182
- el . classList . add ( 'label' ) ;
183
- el . classList . add ( 'status-error' ) ;
184
- el . innerHTML = xhr . responseText ;
185
- } ,
186
- serializeQueryString ( { selected : selected } ) ,
187
- { method : 'POST' }
188
- ) ;
161
+ } ) . then ( res => res . text ( ) ) . then ( text => {
162
+ el . classList . add ( 'label' ) ;
163
+ el . classList . add ( 'status-success' ) ;
164
+ el . innerHTML = text ;
165
+ } ) . catch ( error => {
166
+ el . classList . add ( 'label' ) ;
167
+ el . classList . add ( 'status-error' ) ;
168
+ el . innerHTML = error ;
169
+ } )
170
+
189
171
return false ;
190
172
} ;
0 commit comments