|
274 | 274 | saveHook: function(context, record) { |
275 | 275 | delete record._canUpdate; |
276 | 276 | delete record._canDelete; |
277 | | - return CV.$.ajax({ |
278 | | - type: "POST", |
279 | | - url: countlyCommon.API_PARTS.data.w + "/hook/save?" + "app_id=" + record.apps[0], |
280 | | - data: { |
281 | | - "hook_config": JSON.stringify(record) |
282 | | - }, |
283 | | - dataType: "json", |
284 | | - success: function() { |
285 | | - context.dispatch("countlyHooks/table/fetchAll", null, {root: true}); |
286 | | - context.dispatch("countlyHooks/initializeDetail", record._id, {root: true}); |
287 | | - }, |
288 | | - error: function() { |
289 | | - CountlyHelpers.notify({type: "error", message: jQuery.i18n.map["hooks.trigger-save-failed"]}); |
290 | | - } |
| 277 | + return new Promise(function(resolve, reject) { |
| 278 | + CV.$.ajax({ |
| 279 | + type: 'POST', |
| 280 | + url: countlyCommon.API_PARTS.data.w + '/hook/save?' + 'app_id=' + record.apps[0], |
| 281 | + data: { |
| 282 | + 'hook_config': JSON.stringify(record) |
| 283 | + }, |
| 284 | + dataType: 'json', |
| 285 | + success: function() { |
| 286 | + context.dispatch('countlyHooks/table/fetchAll', null, {root: true}); |
| 287 | + context.dispatch('countlyHooks/initializeDetail', record._id, {root: true}); |
| 288 | + resolve(); |
| 289 | + }, |
| 290 | + error: function(err) { |
| 291 | + var msg = jQuery.i18n.map['hooks.trigger-save-failed']; |
| 292 | + if (err.responseJSON && err.responseJSON.result) { |
| 293 | + msg = err.responseJSON.result; |
| 294 | + } |
| 295 | + |
| 296 | + CountlyHelpers.notify({type: 'error', message: msg}); |
| 297 | + reject(err); |
| 298 | + }, |
| 299 | + }); |
291 | 300 | }); |
292 | 301 | }, |
293 | 302 | deleteHook: function(context, id) { |
|
326 | 335 | }); |
327 | 336 | context.commit("setTestResult", res.result); |
328 | 337 | } |
329 | | - } |
| 338 | + }, |
| 339 | + error: function(err) { |
| 340 | + var msg = jQuery.i18n.map['hooks.test-hook-failed']; |
| 341 | + if (err.responseJSON && err.responseJSON.result) { |
| 342 | + msg = err.responseJSON.result; |
| 343 | + } |
| 344 | + |
| 345 | + CountlyHelpers.notify({type: "error", message: msg}); |
| 346 | + }, |
330 | 347 | }); |
331 | 348 | }, |
332 | 349 | resetTestResult: function(context) { |
|
0 commit comments