Skip to content

Commit 7dd2c29

Browse files
committed
[hooks] Disable auto close on drawer submission
1 parent edab460 commit 7dd2c29

4 files changed

Lines changed: 48 additions & 24 deletions

File tree

plugins/hooks/frontend/public/javascripts/countly.models.js

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -274,20 +274,29 @@
274274
saveHook: function(context, record) {
275275
delete record._canUpdate;
276276
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+
});
291300
});
292301
},
293302
deleteHook: function(context, id) {
@@ -326,7 +335,15 @@
326335
});
327336
context.commit("setTestResult", res.result);
328337
}
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+
},
330347
});
331348
},
332349
resetTestResult: function(context) {

plugins/hooks/frontend/public/javascripts/countly.views.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,14 @@
800800
}
801801
},
802802
methods: {
803-
onSubmit: function(doc) {
804-
this.$store.dispatch("countlyHooks/saveHook", doc);
803+
onSubmit: function(doc, callback) {
804+
this.$store.dispatch("countlyHooks/saveHook", doc)
805+
.then(function() {
806+
callback();
807+
})
808+
.catch(function(err) {
809+
callback(err);
810+
});
805811
},
806812
onClose: function($event) {
807813
this.$emit("close", $event);
@@ -822,7 +828,6 @@
822828
removeEffect: function(index) {
823829
this.$refs.drawerData.editedObject.effects.splice(index, 1);
824830
},
825-
826831
testHook: function() {
827832
var hookData = this.$refs.drawerData.editedObject;
828833
this.$data.newTest = true;

plugins/hooks/frontend/public/localization/hooks.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ hooks.effects-intro = Select the actions the hook will perform upon being trigge
114114
hooks.test-hook = HOOK TESTING
115115
hooks.test-hook-intro = Test your hooks to verify payloads or check if your hook setup is working properly before taking it live.
116116
hooks.test-hook-button = Test your hook setup
117+
hooks.test-hook-failed = Hook test failed.
117118
hooks.remove-action = Remove action
118119
hooks.send-email = Email addresses to send the data to
119120
hooks.http-intro = Query string (for GET) or request body (for POST)

plugins/hooks/frontend/public/templates/vue-drawer.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<cly-drawer
2-
@submit="onSubmit"
3-
@close="onClose"
4-
@copy="onCopy"
2+
@submit="onSubmit"
3+
@close="onClose"
4+
@copy="onCopy"
55
:size="6"
6-
:title="title"
6+
:title="title"
7+
:requiresAsyncSubmit="true"
78
ref="drawerData"
8-
:saveButtonLabel="saveButtonLabel"
9+
:saveButtonLabel="saveButtonLabel"
910
toggle-transition="stdt-fade"
10-
v-bind="$props.controls">
11+
v-bind="$props.controls">
1112
<template v-slot:default="drawerScope" >
1213
<cly-form-step id="step1" :name="i18n('hooks.step1')">
1314
<cly-form-field name="hooksName" :label="i18n('hooks.name')" rules="required">

0 commit comments

Comments
 (0)