Skip to content

Commit 8b25f8c

Browse files
committed
added implementation for action submit start event and defer
1 parent 3d7c1cd commit 8b25f8c

File tree

1 file changed

+120
-39
lines changed
  • app/concepts/matestack/ui/core/action

1 file changed

+120
-39
lines changed

app/concepts/matestack/ui/core/action/action.js

Lines changed: 120 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,51 +17,132 @@ const componentDef = {
1717
(self.componentConfig["confirm"] == undefined) || confirm(self.componentConfig["confirm_text"])
1818
)
1919
{
20-
axios({
20+
if (self.componentConfig["emit"] != undefined) {
21+
matestackEventHub.$emit(self.componentConfig["emit"]);
22+
}
23+
if (self.componentConfig["min_defer"] != undefined) {
24+
setTimeout(function () {
25+
self.sendRequest()
26+
}, parseInt(self.componentConfig["min_defer"]));
27+
} else {
28+
this.sendRequest()
29+
}
30+
}
31+
},
32+
sendRequest: function(){
33+
const self = this
34+
axios({
2135
method: self.componentConfig["method"],
2236
url: self.componentConfig["action_path"],
2337
data: self.componentConfig["data"],
2438
headers: {
2539
'X-CSRF-Token': document.getElementsByName("csrf-token")[0].getAttribute('content')
2640
}
27-
})
28-
.then(function(response){
29-
if (self.componentConfig["success"] != undefined && self.componentConfig["success"]["emit"] != undefined) {
30-
matestackEventHub.$emit(self.componentConfig["success"]["emit"], response.data);
31-
}
32-
if (self.componentConfig["success"] != undefined
33-
&& self.componentConfig["success"]["transition"] != undefined
34-
&& (
35-
self.componentConfig["success"]["transition"]["follow_response"] == undefined
36-
||
37-
self.componentConfig["success"]["transition"]["follow_response"] === false
38-
)
39-
&& self.$store != undefined
40-
) {
41-
let path = self.componentConfig["success"]["transition"]["path"]
42-
self.$store.dispatch('navigateTo', {url: path, backwards: false})
43-
return;
44-
}
45-
if (self.componentConfig["success"] != undefined
46-
&& self.componentConfig["success"]["transition"] != undefined
47-
&& self.componentConfig["success"]["transition"]["follow_response"] === true
48-
&& self.$store != undefined
49-
) {
50-
let path = response.data["transition_to"] || response.request.responseURL;
51-
self.$store.dispatch('navigateTo', {url: path, backwards: false});
52-
return;
53-
}
54-
})
55-
.catch(function(error){
56-
if (self.componentConfig["failure"] != undefined && self.componentConfig["failure"]["emit"] != undefined) {
57-
matestackEventHub.$emit(self.componentConfig["failure"]["emit"], error.response.data);
58-
}
59-
if (self.componentConfig["failure"] != undefined && self.componentConfig["failure"]["transition"] != undefined && self.$store != undefined) {
60-
let path = self.componentConfig["failure"]["transition"]["path"]
61-
self.$store.dispatch('navigateTo', {url: path, backwards: false})
62-
}
63-
})
64-
}
41+
}
42+
)
43+
.then(function(response){
44+
if (self.componentConfig["success"] != undefined && self.componentConfig["success"]["emit"] != undefined) {
45+
matestackEventHub.$emit(self.componentConfig["success"]["emit"], response.data);
46+
}
47+
48+
// transition handling
49+
if (self.componentConfig["success"] != undefined
50+
&& self.componentConfig["success"]["transition"] != undefined
51+
&& (
52+
self.componentConfig["success"]["transition"]["follow_response"] == undefined
53+
||
54+
self.componentConfig["success"]["transition"]["follow_response"] === false
55+
)
56+
&& self.$store != undefined
57+
) {
58+
let path = self.componentConfig["success"]["transition"]["path"]
59+
self.$store.dispatch('navigateTo', {url: path, backwards: false})
60+
return;
61+
}
62+
if (self.componentConfig["success"] != undefined
63+
&& self.componentConfig["success"]["transition"] != undefined
64+
&& self.componentConfig["success"]["transition"]["follow_response"] === true
65+
&& self.$store != undefined
66+
) {
67+
let path = response.data["transition_to"] || response.request.responseURL
68+
self.$store.dispatch('navigateTo', {url: path, backwards: false})
69+
return;
70+
}
71+
// redirect handling
72+
if (self.componentConfig["success"] != undefined
73+
&& self.componentConfig["success"]["redirect"] != undefined
74+
&& (
75+
self.componentConfig["success"]["redirect"]["follow_response"] == undefined
76+
||
77+
self.componentConfig["success"]["redirect"]["follow_response"] === false
78+
)
79+
&& self.$store != undefined
80+
) {
81+
let path = self.componentConfig["success"]["redirect"]["path"]
82+
window.location.href = path
83+
return;
84+
}
85+
if (self.componentConfig["success"] != undefined
86+
&& self.componentConfig["success"]["redirect"] != undefined
87+
&& self.componentConfig["success"]["redirect"]["follow_response"] === true
88+
&& self.$store != undefined
89+
) {
90+
let path = response.data["redirect_to"] || response.request.responseURL
91+
window.location.href = path
92+
return;
93+
}
94+
})
95+
.catch(function(error){
96+
if (self.componentConfig["failure"] != undefined && self.componentConfig["failure"]["emit"] != undefined) {
97+
matestackEventHub.$emit(self.componentConfig["failure"]["emit"], error.response.data);
98+
}
99+
// transition handling
100+
if (self.componentConfig["failure"] != undefined
101+
&& self.componentConfig["failure"]["transition"] != undefined
102+
&& (
103+
self.componentConfig["failure"]["transition"]["follow_response"] == undefined
104+
||
105+
self.componentConfig["failure"]["transition"]["follow_response"] === false
106+
)
107+
&& self.$store != undefined
108+
) {
109+
let path = self.componentConfig["failure"]["transition"]["path"]
110+
self.$store.dispatch('navigateTo', {url: path, backwards: false})
111+
return;
112+
}
113+
if (self.componentConfig["failure"] != undefined
114+
&& self.componentConfig["failure"]["transition"] != undefined
115+
&& self.componentConfig["failure"]["transition"]["follow_response"] === true
116+
&& self.$store != undefined
117+
) {
118+
let path = error.response.data["transition_to"] || response.request.responseURL
119+
self.$store.dispatch('navigateTo', {url: path, backwards: false})
120+
return;
121+
}
122+
// redirect handling
123+
if (self.componentConfig["failure"] != undefined
124+
&& self.componentConfig["failure"]["redirect"] != undefined
125+
&& (
126+
self.componentConfig["failure"]["redirect"]["follow_response"] == undefined
127+
||
128+
self.componentConfig["failure"]["redirect"]["follow_response"] === false
129+
)
130+
&& self.$store != undefined
131+
) {
132+
let path = self.componentConfig["failure"]["redirect"]["path"]
133+
window.location.href = path
134+
return;
135+
}
136+
if (self.componentConfig["failure"] != undefined
137+
&& self.componentConfig["failure"]["redirect"] != undefined
138+
&& self.componentConfig["failure"]["redirect"]["follow_response"] === true
139+
&& self.$store != undefined
140+
) {
141+
let path = error.response.data["redirect_to"] || response.request.responseURL
142+
window.location.href = path
143+
return;
144+
}
145+
})
65146
}
66147
}
67148
}

0 commit comments

Comments
 (0)