matestack-ui-core 0.7.5 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/concepts/matestack/ui/core/action/action.js +120 -39
- data/app/concepts/matestack/ui/core/action/action.rb +21 -0
- data/app/concepts/matestack/ui/core/app/app.js +3 -3
- data/app/concepts/matestack/ui/core/app/app.rb +1 -0
- data/app/concepts/matestack/ui/core/app/store.js +1 -1
- data/app/concepts/matestack/ui/core/async/async.js +25 -3
- data/app/concepts/matestack/ui/core/form/form.js +245 -116
- data/app/concepts/matestack/ui/core/form/form.rb +22 -0
- data/app/concepts/matestack/ui/core/form/input/input.haml +9 -1
- data/app/concepts/matestack/ui/core/form/input/input.rb +2 -2
- data/app/concepts/matestack/ui/core/form/select/select.haml +14 -10
- data/app/concepts/matestack/ui/core/form/select/select.rb +10 -0
- data/app/concepts/matestack/ui/core/page/page.rb +5 -1
- data/app/concepts/matestack/ui/core/transition/transition.js +16 -1
- data/app/concepts/matestack/ui/core/transition/transition.rb +1 -1
- data/app/helpers/matestack/ui/core/application_helper.rb +2 -1
- data/lib/matestack/ui/core/version.rb +1 -1
- data/vendor/assets/javascripts/dist/manifest.json +6 -10
- data/vendor/assets/javascripts/dist/matestack-ui-core.js +406 -158
- data/vendor/assets/javascripts/dist/matestack-ui-core.js.map +1 -1
- data/vendor/assets/javascripts/dist/matestack-ui-core.min.js +1 -1
- data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.gz +0 -0
- data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.map +1 -1
- data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.map.gz +0 -0
- metadata +4 -6
- data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.br +0 -0
- data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.map.br +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c4bb181fa03aec3eb151af547eec43d6f12f692c8cdfa0dfe70a6e963ede262
|
4
|
+
data.tar.gz: 24088d7379448e215604593de26c89d8a026bbef1054c7d3cb78e22f01803f22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee17b5c4423b505a5a6dacb837fe44987ce8fc26f1569314d7b7afbcdcb1c0feaadbf436ccf901583b94e9d1161f81ba99a6cab6237f48cd5854b685685fb1ca
|
7
|
+
data.tar.gz: 677a09c88813b82d2c2cbf32885f90845b0e3a24739c1fd3ebe0b371b8a2e2208df7a3b0cdb9d8b83368eb34480edc769250cc932dc5fb6c645a2de0896ce007
|
@@ -17,51 +17,132 @@ const componentDef = {
|
|
17
17
|
(self.componentConfig["confirm"] == undefined) || confirm(self.componentConfig["confirm_text"])
|
18
18
|
)
|
19
19
|
{
|
20
|
-
|
20
|
+
if (self.componentConfig["emit"] != undefined) {
|
21
|
+
matestackEventHub.$emit(self.componentConfig["emit"]);
|
22
|
+
}
|
23
|
+
if (self.componentConfig["delay"] != undefined) {
|
24
|
+
setTimeout(function () {
|
25
|
+
self.sendRequest()
|
26
|
+
}, parseInt(self.componentConfig["delay"]));
|
27
|
+
} else {
|
28
|
+
this.sendRequest()
|
29
|
+
}
|
30
|
+
}
|
31
|
+
},
|
32
|
+
sendRequest: function(){
|
33
|
+
const self = this
|
34
|
+
axios({
|
21
35
|
method: self.componentConfig["method"],
|
22
36
|
url: self.componentConfig["action_path"],
|
23
37
|
data: self.componentConfig["data"],
|
24
38
|
headers: {
|
25
39
|
'X-CSRF-Token': document.getElementsByName("csrf-token")[0].getAttribute('content')
|
26
40
|
}
|
27
|
-
}
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
self
|
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
|
+
})
|
65
146
|
}
|
66
147
|
}
|
67
148
|
}
|
@@ -9,12 +9,18 @@ module Matestack::Ui::Core::Action
|
|
9
9
|
unless options[:success][:transition].nil?
|
10
10
|
@component_config[:success][:transition][:path] = transition_path options[:success]
|
11
11
|
end
|
12
|
+
unless options[:success][:redirect].nil?
|
13
|
+
@component_config[:success][:redirect][:path] = redirect_path options[:success]
|
14
|
+
end
|
12
15
|
end
|
13
16
|
@component_config[:failure] = options[:failure]
|
14
17
|
unless options[:failure].nil?
|
15
18
|
unless options[:failure][:transition].nil?
|
16
19
|
@component_config[:failure][:transition][:path] = transition_path options[:failure]
|
17
20
|
end
|
21
|
+
unless options[:failure][:redirect].nil?
|
22
|
+
@component_config[:failure][:redirect][:path] = redirect_path options[:failure]
|
23
|
+
end
|
18
24
|
end
|
19
25
|
if options[:notify].nil?
|
20
26
|
@component_config[:notify] = true
|
@@ -51,5 +57,20 @@ module Matestack::Ui::Core::Action
|
|
51
57
|
end
|
52
58
|
end
|
53
59
|
|
60
|
+
def redirect_path callback_options
|
61
|
+
begin
|
62
|
+
if callback_options[:redirect][:path].is_a?(Symbol)
|
63
|
+
return ::Rails.application.routes.url_helpers.send(
|
64
|
+
callback_options[:redirect][:path],
|
65
|
+
callback_options[:redirect][:params]
|
66
|
+
)
|
67
|
+
else
|
68
|
+
return callback_options[:redirect][:path]
|
69
|
+
end
|
70
|
+
rescue
|
71
|
+
raise "Redirect path not found"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
54
75
|
end
|
55
76
|
end
|
@@ -16,15 +16,15 @@ const componentDef = {
|
|
16
16
|
}),
|
17
17
|
mounted: function(){
|
18
18
|
const self = this;
|
19
|
-
window.
|
19
|
+
window.addEventListener("popstate", (event) => {
|
20
20
|
if (isNavigatingToAnotherPage({
|
21
21
|
origin: self.currentOrigin,
|
22
22
|
pathName: self.currentPathName,
|
23
23
|
search: self.currentSearch
|
24
24
|
}, document.location)){
|
25
|
-
self.$store.dispatch("navigateTo", {url: document.location.pathname, backwards: true} );
|
25
|
+
self.$store.dispatch("navigateTo", { url: document.location.pathname + document.location.search, backwards: true } );
|
26
26
|
}
|
27
|
-
}
|
27
|
+
})
|
28
28
|
},
|
29
29
|
components: {
|
30
30
|
VRuntimeTemplate: VRuntimeTemplate
|
@@ -4,6 +4,7 @@ module Matestack::Ui::Core::App
|
|
4
4
|
include Matestack::Ui::Core::Cell
|
5
5
|
include Matestack::Ui::Core::ApplicationHelper
|
6
6
|
include Matestack::Ui::Core::ToCell
|
7
|
+
include Matestack::Ui::Core::HasViewContext
|
7
8
|
|
8
9
|
view_paths << "#{Matestack::Ui::Core::Engine.root}/app/concepts"
|
9
10
|
|
@@ -53,7 +53,7 @@ const store = new Vuex.Store({
|
|
53
53
|
setTimeout(function () {
|
54
54
|
resolve(response["data"])
|
55
55
|
commit('setPageTemplate', response["data"])
|
56
|
-
commit('setCurrentLocation', { path: url, search: document.location.search, origin: document.location.origin })
|
56
|
+
commit('setCurrentLocation', { path: url.split("?")[0], search: document.location.search, origin: document.location.origin })
|
57
57
|
matestackEventHub.$emit("page_loaded", url);
|
58
58
|
if (typeof matestackUiCoreTransitionSuccess !== 'undefined') {
|
59
59
|
matestackUiCoreTransitionSuccess(url);
|
@@ -45,9 +45,19 @@ const componentDef = {
|
|
45
45
|
},
|
46
46
|
created: function () {
|
47
47
|
const self = this
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
if(this.componentConfig["show_on"] != undefined){
|
49
|
+
this.showing = false
|
50
|
+
var show_events = this.componentConfig["show_on"].split(",")
|
51
|
+
show_events.forEach(show_event => matestackEventHub.$on(show_event.trim(), self.show));
|
52
|
+
}
|
53
|
+
if(this.componentConfig["hide_on"] != undefined){
|
54
|
+
var hide_events = this.componentConfig["hide_on"].split(",")
|
55
|
+
hide_events.forEach(hide_event => matestackEventHub.$on(hide_event.trim(), self.hide));
|
56
|
+
}
|
57
|
+
if(this.componentConfig["rerender_on"] != undefined){
|
58
|
+
var rerender_events = this.componentConfig["rerender_on"].split(",")
|
59
|
+
rerender_events.forEach(rerender_event => matestackEventHub.$on(rerender_event.trim(), self.rerender));
|
60
|
+
}
|
51
61
|
if(this.componentConfig["show_on"] != undefined){
|
52
62
|
this.showing = false
|
53
63
|
}
|
@@ -68,6 +78,18 @@ const componentDef = {
|
|
68
78
|
matestackEventHub.$off(this.componentConfig["rerender_on"], self.rerender);
|
69
79
|
matestackEventHub.$off(this.componentConfig["show_on"], self.show);
|
70
80
|
matestackEventHub.$off(this.componentConfig["hide_on"], self.hide);
|
81
|
+
if(this.componentConfig["show_on"] != undefined){
|
82
|
+
var shown_events = this.componentConfig["show_on"].split(",")
|
83
|
+
shown_events.forEach(show_event => matestackEventHub.$off(show_event.trim(), self.show));
|
84
|
+
}
|
85
|
+
if(this.componentConfig["hide_on"] != undefined){
|
86
|
+
var hiden_events = this.componentConfig["hide_on"].split(",")
|
87
|
+
hiden_events.forEach(hide_event => matestackEventHub.$off(hide_event.trim(), self.hide));
|
88
|
+
}
|
89
|
+
if(this.componentConfig["rerender_on"] != undefined){
|
90
|
+
var rerender_events = this.componentConfig["rerender_on"].split(",")
|
91
|
+
rerender_events.forEach(rerender_event => matestackEventHub.$off(rerender_event.trim(), self.rerender));
|
92
|
+
}
|
71
93
|
},
|
72
94
|
}
|
73
95
|
|
@@ -1,35 +1,35 @@
|
|
1
|
-
import Vue from
|
2
|
-
import Vuex from
|
3
|
-
import axios from
|
1
|
+
import Vue from "vue/dist/vue.esm";
|
2
|
+
import Vuex from "vuex";
|
3
|
+
import axios from "axios";
|
4
4
|
|
5
|
-
import matestackEventHub from
|
6
|
-
import componentMixin from
|
5
|
+
import matestackEventHub from "../js/event-hub";
|
6
|
+
import componentMixin from "../component/component";
|
7
7
|
|
8
8
|
const componentDef = {
|
9
9
|
mixins: [componentMixin],
|
10
|
-
data: function(){
|
10
|
+
data: function () {
|
11
11
|
return {
|
12
12
|
data: {},
|
13
13
|
showInlineForm: false,
|
14
|
-
errors: {}
|
15
|
-
}
|
14
|
+
errors: {},
|
15
|
+
};
|
16
16
|
},
|
17
17
|
methods: {
|
18
|
-
initDataKey: function(key, initValue){
|
18
|
+
initDataKey: function (key, initValue) {
|
19
19
|
this.data[key] = initValue;
|
20
20
|
},
|
21
|
-
inputChanged: function(key){
|
22
|
-
this.resetErrors(key)
|
21
|
+
inputChanged: function (key) {
|
22
|
+
this.resetErrors(key);
|
23
23
|
},
|
24
|
-
updateFormValue: function(key, value){
|
24
|
+
updateFormValue: function (key, value) {
|
25
25
|
this.data[key] = value;
|
26
26
|
},
|
27
|
-
resetErrors: function(key){
|
28
|
-
if (this.errors[key]){
|
27
|
+
resetErrors: function (key) {
|
28
|
+
if (this.errors[key]) {
|
29
29
|
this.errors[key] = null;
|
30
30
|
}
|
31
31
|
},
|
32
|
-
launchInlineForm: function(key, value){
|
32
|
+
launchInlineForm: function (key, value) {
|
33
33
|
this.showInlineForm = true;
|
34
34
|
this.data[key] = value;
|
35
35
|
const self = this;
|
@@ -37,136 +37,265 @@ const componentDef = {
|
|
37
37
|
self.$refs.inlineinput.focus();
|
38
38
|
}, 300);
|
39
39
|
},
|
40
|
-
closeInlineForm: function(){
|
40
|
+
closeInlineForm: function () {
|
41
41
|
this.showInlineForm = false;
|
42
42
|
},
|
43
|
-
setProps: function(flat, newVal){
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
43
|
+
setProps: function (flat, newVal) {
|
44
|
+
for (var i in flat) {
|
45
|
+
if (flat[i] === null){
|
46
|
+
flat[i] = newVal;
|
47
|
+
} else if (flat[i] instanceof File){
|
48
|
+
flat[i] = newVal;
|
49
|
+
this.$refs["input."+i].value = newVal
|
50
|
+
} else if (flat[i] instanceof Array) {
|
51
|
+
if(flat[i][0] instanceof File){
|
52
|
+
flat[i] = newVal
|
53
|
+
this.$refs["input."+i].value = newVal
|
54
|
+
}
|
55
|
+
} else if (typeof flat[i] === "object" && !(flat[i] instanceof Array)) {
|
56
|
+
setProps(flat[i], newVal);
|
57
|
+
} else {
|
58
|
+
flat[i] = newVal;
|
59
|
+
}
|
51
60
|
}
|
52
61
|
},
|
53
|
-
|
62
|
+
filesAdded: function (key) {
|
63
|
+
const dataTransfer = event.dataTransfer || event.target;
|
64
|
+
const files = dataTransfer.files;
|
65
|
+
if (event.target.attributes.multiple) {
|
66
|
+
this.data[key] = [];
|
67
|
+
for (let index in files) {
|
68
|
+
if (files[index] instanceof File) {
|
69
|
+
this.data[key].push(files[index]);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
} else {
|
73
|
+
this.data[key] = files[0];
|
74
|
+
}
|
75
|
+
},
|
76
|
+
initValues: function () {
|
54
77
|
let self = this;
|
55
|
-
let data = {}
|
78
|
+
let data = {};
|
56
79
|
for (let key in self.$refs) {
|
57
|
-
let initValue = self.$refs[key]["attributes"]["init-value"]
|
58
|
-
let valueType = self.$refs[key]["attributes"]["value-type"]
|
80
|
+
let initValue = self.$refs[key]["attributes"]["init-value"];
|
81
|
+
let valueType = self.$refs[key]["attributes"]["value-type"];
|
59
82
|
|
60
|
-
if (key.startsWith("input.")){
|
61
|
-
if(initValue){
|
62
|
-
data[key.replace(
|
63
|
-
}else{
|
64
|
-
data[key.replace(
|
83
|
+
if (key.startsWith("input.")) {
|
84
|
+
if (initValue) {
|
85
|
+
data[key.replace("input.", "")] = initValue["value"];
|
86
|
+
} else {
|
87
|
+
data[key.replace("input.", "")] = null;
|
65
88
|
}
|
66
89
|
}
|
67
|
-
if (key.startsWith("select.")){
|
68
|
-
if (key.startsWith("select.multiple.")){
|
69
|
-
if(initValue){
|
70
|
-
data[key.replace(
|
71
|
-
}else{
|
72
|
-
data[key.replace(
|
90
|
+
if (key.startsWith("select.")) {
|
91
|
+
if (key.startsWith("select.multiple.")) {
|
92
|
+
if (initValue) {
|
93
|
+
data[key.replace("select.multiple.", "")] = JSON.parse(initValue["value"]);
|
94
|
+
} else {
|
95
|
+
data[key.replace("select.multiple.", "")] = [];
|
73
96
|
}
|
74
|
-
}else{
|
75
|
-
if(initValue){
|
76
|
-
if(valueType && valueType["value"] == "Integer")
|
77
|
-
|
78
|
-
|
79
|
-
data[key.replace('select.', '')] = initValue["value"]
|
97
|
+
} else {
|
98
|
+
if (initValue) {
|
99
|
+
if (valueType && valueType["value"] == "Integer") data[key.replace("select.", "")] = parseInt(initValue["value"]);
|
100
|
+
else {
|
101
|
+
data[key.replace("select.", "")] = initValue["value"];
|
80
102
|
}
|
81
|
-
}else{
|
82
|
-
data[key.replace(
|
103
|
+
} else {
|
104
|
+
data[key.replace("select.", "")] = null;
|
83
105
|
}
|
84
106
|
}
|
85
|
-
|
86
107
|
}
|
87
108
|
}
|
88
109
|
self.data = data;
|
89
110
|
},
|
90
111
|
shouldResetFormOnSuccessfulSubmit() {
|
91
|
-
const self = this
|
92
|
-
if (self.componentConfig[
|
93
|
-
return self.componentConfig[
|
112
|
+
const self = this;
|
113
|
+
if (self.componentConfig["success"] != undefined && self.componentConfig["success"]["reset"] != undefined) {
|
114
|
+
return self.componentConfig["success"]["reset"];
|
94
115
|
} else {
|
95
|
-
return self.shouldResetFormOnSuccessfulSubmitByDefault()
|
116
|
+
return self.shouldResetFormOnSuccessfulSubmitByDefault();
|
96
117
|
}
|
97
118
|
},
|
98
119
|
shouldResetFormOnSuccessfulSubmitByDefault() {
|
99
|
-
const self = this
|
120
|
+
const self = this;
|
100
121
|
if (self.componentConfig["method"] == "put") {
|
101
|
-
return false
|
122
|
+
return false;
|
102
123
|
} else {
|
103
|
-
return true
|
124
|
+
return true;
|
104
125
|
}
|
105
126
|
},
|
106
127
|
perform: function(){
|
107
128
|
const self = this
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
}
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
&& self.componentConfig["success"]["transition"]["follow_response"] === true
|
138
|
-
&& self.$store != undefined
|
139
|
-
) {
|
140
|
-
let path = response.data["transition_to"] || response.request.responseURL
|
141
|
-
self.$store.dispatch('navigateTo', {url: path, backwards: false})
|
142
|
-
return;
|
143
|
-
}
|
144
|
-
if (self.shouldResetFormOnSuccessfulSubmit())
|
145
|
-
{
|
146
|
-
self.setProps(self.data, null);
|
147
|
-
self.initValues();
|
148
|
-
}
|
149
|
-
self.showInlineForm = false;
|
150
|
-
})
|
151
|
-
.catch(function(error){
|
152
|
-
if(error.response && error.response.data && error.response.data.errors){
|
153
|
-
self.errors = error.response.data.errors;
|
154
|
-
}
|
155
|
-
if (self.componentConfig["failure"] != undefined && self.componentConfig["failure"]["emit"] != undefined) {
|
156
|
-
matestackEventHub.$emit(self.componentConfig["failure"]["emit"], error.response.data);
|
157
|
-
}
|
158
|
-
if (self.componentConfig["failure"] != undefined && self.componentConfig["failure"]["transition"] != undefined && self.$store != undefined) {
|
159
|
-
let path = self.componentConfig["failure"]["transition"]["path"]
|
160
|
-
self.$store.dispatch('navigateTo', {url: path, backwards: false})
|
129
|
+
if (self.componentConfig["emit"] != undefined) {
|
130
|
+
matestackEventHub.$emit(self.componentConfig["emit"]);
|
131
|
+
}
|
132
|
+
if (self.componentConfig["delay"] != undefined) {
|
133
|
+
setTimeout(function () {
|
134
|
+
self.sendRequest()
|
135
|
+
}, parseInt(self.componentConfig["delay"]));
|
136
|
+
} else {
|
137
|
+
this.sendRequest()
|
138
|
+
}
|
139
|
+
},
|
140
|
+
sendRequest: function(){
|
141
|
+
const self = this;
|
142
|
+
let payload = {};
|
143
|
+
payload[self.componentConfig["for"]] = self.data;
|
144
|
+
let axios_config = {};
|
145
|
+
if (self.componentConfig["multipart"] == true ) {
|
146
|
+
let form_data = new FormData();
|
147
|
+
for (let key in self.data) {
|
148
|
+
if (key.endsWith("[]")) {
|
149
|
+
for (let i in self.data[key]) {
|
150
|
+
let file = self.data[key][i];
|
151
|
+
form_data.append(self.componentConfig["for"] + "[" + key.slice(0, -2) + "][]", file);
|
152
|
+
}
|
153
|
+
} else {
|
154
|
+
if (self.data[key] != null){
|
155
|
+
form_data.append(self.componentConfig["for"] + "[" + key + "]", self.data[key]);
|
156
|
+
}
|
157
|
+
}
|
161
158
|
}
|
162
|
-
|
163
|
-
|
159
|
+
axios_config = {
|
160
|
+
method: self.componentConfig["method"],
|
161
|
+
url: self.componentConfig["submit_path"],
|
162
|
+
data: form_data,
|
163
|
+
headers: {
|
164
|
+
"X-CSRF-Token": document.getElementsByName("csrf-token")[0].getAttribute("content"),
|
165
|
+
"Content-Type": "multipart/form-data",
|
166
|
+
},
|
167
|
+
};
|
168
|
+
} else {
|
169
|
+
axios_config = {
|
170
|
+
method: self.componentConfig["method"],
|
171
|
+
url: self.componentConfig["submit_path"],
|
172
|
+
data: payload,
|
173
|
+
headers: {
|
174
|
+
"X-CSRF-Token": document.getElementsByName("csrf-token")[0].getAttribute("content"),
|
175
|
+
"Content-Type": "application/json",
|
176
|
+
},
|
177
|
+
};
|
178
|
+
}
|
179
|
+
axios(axios_config)
|
180
|
+
.then(function (response) {
|
181
|
+
if (self.componentConfig["success"] != undefined && self.componentConfig["success"]["emit"] != undefined) {
|
182
|
+
matestackEventHub.$emit(self.componentConfig["success"]["emit"], response.data);
|
183
|
+
}
|
184
|
+
// transition handling
|
185
|
+
if (self.componentConfig["success"] != undefined
|
186
|
+
&& self.componentConfig["success"]["transition"] != undefined
|
187
|
+
&& (
|
188
|
+
self.componentConfig["success"]["transition"]["follow_response"] == undefined
|
189
|
+
||
|
190
|
+
self.componentConfig["success"]["transition"]["follow_response"] === false
|
191
|
+
)
|
192
|
+
&& self.$store != undefined
|
193
|
+
) {
|
194
|
+
let path = self.componentConfig["success"]["transition"]["path"]
|
195
|
+
self.$store.dispatch('navigateTo', {url: path, backwards: false})
|
196
|
+
return;
|
197
|
+
}
|
198
|
+
if (self.componentConfig["success"] != undefined
|
199
|
+
&& self.componentConfig["success"]["transition"] != undefined
|
200
|
+
&& self.componentConfig["success"]["transition"]["follow_response"] === true
|
201
|
+
&& self.$store != undefined
|
202
|
+
) {
|
203
|
+
let path = response.data["transition_to"] || response.request.responseURL
|
204
|
+
self.$store.dispatch('navigateTo', {url: path, backwards: false})
|
205
|
+
return;
|
206
|
+
}
|
207
|
+
// redirect handling
|
208
|
+
if (self.componentConfig["success"] != undefined
|
209
|
+
&& self.componentConfig["success"]["redirect"] != undefined
|
210
|
+
&& (
|
211
|
+
self.componentConfig["success"]["redirect"]["follow_response"] == undefined
|
212
|
+
||
|
213
|
+
self.componentConfig["success"]["redirect"]["follow_response"] === false
|
214
|
+
)
|
215
|
+
&& self.$store != undefined
|
216
|
+
) {
|
217
|
+
let path = self.componentConfig["success"]["redirect"]["path"]
|
218
|
+
window.location.href = path
|
219
|
+
return;
|
220
|
+
}
|
221
|
+
if (self.componentConfig["success"] != undefined
|
222
|
+
&& self.componentConfig["success"]["redirect"] != undefined
|
223
|
+
&& self.componentConfig["success"]["redirect"]["follow_response"] === true
|
224
|
+
&& self.$store != undefined
|
225
|
+
) {
|
226
|
+
let path = response.data["redirect_to"] || response.request.responseURL
|
227
|
+
window.location.href = path
|
228
|
+
return;
|
229
|
+
}
|
230
|
+
|
231
|
+
if (self.shouldResetFormOnSuccessfulSubmit())
|
232
|
+
{
|
233
|
+
self.setProps(self.data, null);
|
234
|
+
self.initValues();
|
235
|
+
}
|
236
|
+
self.showInlineForm = false;
|
237
|
+
})
|
238
|
+
.catch(function (error) {
|
239
|
+
if (error.response && error.response.data && error.response.data.errors) {
|
240
|
+
self.errors = error.response.data.errors;
|
241
|
+
}
|
242
|
+
if (self.componentConfig["failure"] != undefined && self.componentConfig["failure"]["emit"] != undefined) {
|
243
|
+
matestackEventHub.$emit(self.componentConfig["failure"]["emit"], error.response.data);
|
244
|
+
}
|
245
|
+
// transition handling
|
246
|
+
if (self.componentConfig["failure"] != undefined
|
247
|
+
&& self.componentConfig["failure"]["transition"] != undefined
|
248
|
+
&& (
|
249
|
+
self.componentConfig["failure"]["transition"]["follow_response"] == undefined
|
250
|
+
||
|
251
|
+
self.componentConfig["failure"]["transition"]["follow_response"] === false
|
252
|
+
)
|
253
|
+
&& self.$store != undefined
|
254
|
+
) {
|
255
|
+
let path = self.componentConfig["failure"]["transition"]["path"]
|
256
|
+
self.$store.dispatch('navigateTo', {url: path, backwards: false})
|
257
|
+
return;
|
258
|
+
}
|
259
|
+
if (self.componentConfig["failure"] != undefined
|
260
|
+
&& self.componentConfig["failure"]["transition"] != undefined
|
261
|
+
&& self.componentConfig["failure"]["transition"]["follow_response"] === true
|
262
|
+
&& self.$store != undefined
|
263
|
+
) {
|
264
|
+
let path = error.response.data["transition_to"] || response.request.responseURL
|
265
|
+
self.$store.dispatch('navigateTo', {url: path, backwards: false})
|
266
|
+
return;
|
267
|
+
}
|
268
|
+
// redirect handling
|
269
|
+
if (self.componentConfig["failure"] != undefined
|
270
|
+
&& self.componentConfig["failure"]["redirect"] != undefined
|
271
|
+
&& (
|
272
|
+
self.componentConfig["failure"]["redirect"]["follow_response"] == undefined
|
273
|
+
||
|
274
|
+
self.componentConfig["failure"]["redirect"]["follow_response"] === false
|
275
|
+
)
|
276
|
+
&& self.$store != undefined
|
277
|
+
) {
|
278
|
+
let path = self.componentConfig["failure"]["redirect"]["path"]
|
279
|
+
window.location.href = path
|
280
|
+
return;
|
281
|
+
}
|
282
|
+
if (self.componentConfig["failure"] != undefined
|
283
|
+
&& self.componentConfig["failure"]["redirect"] != undefined
|
284
|
+
&& self.componentConfig["failure"]["redirect"]["follow_response"] === true
|
285
|
+
&& self.$store != undefined
|
286
|
+
) {
|
287
|
+
let path = error.response.data["redirect_to"] || response.request.responseURL
|
288
|
+
window.location.href = path
|
289
|
+
return;
|
290
|
+
}
|
291
|
+
});
|
292
|
+
},
|
293
|
+
},
|
294
|
+
mounted: function () {
|
295
|
+
this.initValues();
|
164
296
|
},
|
165
|
-
|
166
|
-
this.initValues()
|
167
|
-
}
|
168
|
-
}
|
297
|
+
};
|
169
298
|
|
170
|
-
let component = Vue.component(
|
299
|
+
let component = Vue.component("matestack-ui-core-form", componentDef);
|
171
300
|
|
172
|
-
export default componentDef
|
301
|
+
export default componentDef;
|