Skip to content

Commit a9b9a03

Browse files
committed
implementing confirm option for action component
#257
1 parent 1653b95 commit a9b9a03

File tree

4 files changed

+61
-51
lines changed

4 files changed

+61
-51
lines changed

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

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,37 @@ const componentDef = {
1414
methods: {
1515
perform: function(){
1616
const self = this
17-
axios({
18-
method: self.componentConfig["method"],
19-
url: self.componentConfig["action_path"],
20-
data: self.componentConfig["data"],
21-
headers: {
22-
'X-CSRF-Token': document.getElementsByName("csrf-token")[0].getAttribute('content')
23-
}
24-
})
25-
.then(function(response){
26-
if (self.componentConfig["success"] != undefined && self.componentConfig["success"]["emit"] != undefined) {
27-
matestackEventHub.$emit(self.componentConfig["success"]["emit"], response.data);
28-
}
29-
if (self.componentConfig["success"] != undefined && self.componentConfig["success"]["transition"] != undefined && self.$store != undefined) {
30-
let path = self.componentConfig["success"]["transition"]["path"]
31-
self.$store.dispatch('navigateTo', {url: path, backwards: false})
32-
}
33-
})
34-
.catch(function(error){
35-
if (self.componentConfig["failure"] != undefined && self.componentConfig["failure"]["emit"] != undefined) {
36-
matestackEventHub.$emit(self.componentConfig["failure"]["emit"], error.response.data);
37-
}
38-
if (self.componentConfig["failure"] != undefined && self.componentConfig["failure"]["transition"] != undefined && self.$store != undefined) {
39-
let path = self.componentConfig["failure"]["transition"]["path"]
40-
self.$store.dispatch('navigateTo', {url: path, backwards: false})
41-
}
42-
})
17+
if (
18+
(self.componentConfig["confirm"] == undefined) || confirm(self.componentConfig["confirm_text"])
19+
)
20+
{
21+
axios({
22+
method: self.componentConfig["method"],
23+
url: self.componentConfig["action_path"],
24+
data: self.componentConfig["data"],
25+
headers: {
26+
'X-CSRF-Token': document.getElementsByName("csrf-token")[0].getAttribute('content')
27+
}
28+
})
29+
.then(function(response){
30+
if (self.componentConfig["success"] != undefined && self.componentConfig["success"]["emit"] != undefined) {
31+
matestackEventHub.$emit(self.componentConfig["success"]["emit"], response.data);
32+
}
33+
if (self.componentConfig["success"] != undefined && self.componentConfig["success"]["transition"] != undefined && self.$store != undefined) {
34+
let path = self.componentConfig["success"]["transition"]["path"]
35+
self.$store.dispatch('navigateTo', {url: path, backwards: false})
36+
}
37+
})
38+
.catch(function(error){
39+
if (self.componentConfig["failure"] != undefined && self.componentConfig["failure"]["emit"] != undefined) {
40+
matestackEventHub.$emit(self.componentConfig["failure"]["emit"], error.response.data);
41+
}
42+
if (self.componentConfig["failure"] != undefined && self.componentConfig["failure"]["transition"] != undefined && self.$store != undefined) {
43+
let path = self.componentConfig["failure"]["transition"]["path"]
44+
self.$store.dispatch('navigateTo', {url: path, backwards: false})
45+
}
46+
})
47+
}
4348
}
4449
}
4550
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ def setup
1919
if options[:notify].nil?
2020
@component_config[:notify] = true
2121
end
22+
if @component_config[:confirm] = options[:confirm]
23+
@component_config[:confirm_text] = options[:confirm].try(:[], :text) || "Are you sure?"
24+
end
2225
end
2326

2427
def action_path

vendor/assets/javascripts/matestack-ui-core.js

Lines changed: 26 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/assets/javascripts/matestack-ui-core.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)