Skip to content

Commit 7939340

Browse files
committed
Handle delete confirmation cancel.
Fix state issues and better naming. Fix update error. Allow overriding action when item created. Always return fetch promise from action.
1 parent 2019cfd commit 7939340

File tree

28 files changed

+112
-80
lines changed

28 files changed

+112
-80
lines changed

templates/quasar/common/components/ActionCell.vue

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,41 @@
1919
color="secondary"
2020
@click="confirmDelete = true"
2121
/>
22-
<ConfirmDelete v-if="handleDelete" :show="confirmDelete" :handle-delete="handleDelete" />
22+
<ConfirmDelete
23+
v-if="handleDelete"
24+
:show="confirmDelete"
25+
:handle-delete="handleDelete"
26+
:handle-cancel="() => (confirmDelete = false)"
27+
/>
2328
</q-td>
2429
</template>
2530

2631
<script>
27-
import ConfirmDelete from './ConfirmDelete';
32+
import ConfirmDelete from "./ConfirmDelete";
2833
2934
export default {
30-
name: 'ActionCell',
35+
name: "ActionCell",
3136
components: {
32-
ConfirmDelete,
37+
ConfirmDelete
3338
},
3439
data() {
3540
return {
36-
confirmDelete: false,
41+
confirmDelete: false
3742
};
3843
},
3944
props: {
4045
handleShow: {
4146
type: Function,
42-
required: false,
47+
required: false
4348
},
4449
handleEdit: {
4550
type: Function,
46-
required: false,
51+
required: false
4752
},
4853
handleDelete: {
4954
type: Function,
50-
required: false,
51-
},
52-
},
55+
required: false
56+
}
57+
}
5358
};
5459
</script>

templates/quasar/common/components/ConfirmDelete.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</q-card-section>
88

99
<q-card-actions align="right">
10-
<q-btn flat label="{{{labels.cancel}}}" color="primary" v-close-popup />
10+
<q-btn flat label="{{{labels.cancel}}}" color="primary" v-close-popup @click="handleCancel" />
1111
<q-btn flat label="{{{labels.delete}}}" color="primary" v-close-popup @click="handleDelete" />
1212
</q-card-actions>
1313
</q-card>
@@ -26,6 +26,10 @@ export default {
2626
type: Function,
2727
required: true,
2828
},
29+
handleCancel: {
30+
type: Function,
31+
required: false,
32+
},
2933
},
3034
};
3135
</script>

templates/quasar/common/components/Toolbar.vue

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
<slot name="left"></slot>
44
<q-space />
55
<div>
6-
<q-btn v-if="handleSubmit" :label="$t('{{{labels.submit}}}')" color="primary" @click="submitItem" />
6+
<q-btn
7+
v-if="handleSubmit"
8+
:label="$t('{{{labels.submit}}}')"
9+
color="primary"
10+
@click="submitItem"
11+
/>
712
<q-btn
813
v-if="handleReset"
914
:label="$t('{{{labels.reset}}}')"
@@ -22,40 +27,45 @@
2227
/>
2328
<q-btn v-if="handleAdd" flat round dense icon="add" @click="addItem" />
2429
</div>
25-
<ConfirmDelete v-if="handleDelete" :show="confirmDelete" :handle-delete="handleDelete" />
30+
<ConfirmDelete
31+
v-if="handleDelete"
32+
:show="confirmDelete"
33+
:handle-delete="handleDelete"
34+
:handle-cancel="() => (confirmDelete = false)"
35+
/>
2636
</q-toolbar>
2737
</template>
2838

2939
<script>
30-
import ConfirmDelete from './ConfirmDelete';
40+
import ConfirmDelete from "./ConfirmDelete";
3141
3242
export default {
33-
name: 'Toolbar',
43+
name: "Toolbar",
3444
components: {
35-
ConfirmDelete,
45+
ConfirmDelete
3646
},
3747
data() {
3848
return {
39-
confirmDelete: false,
49+
confirmDelete: false
4050
};
4151
},
4252
props: {
4353
handleSubmit: {
4454
type: Function,
45-
required: false,
55+
required: false
4656
},
4757
handleReset: {
4858
type: Function,
49-
required: false,
59+
required: false
5060
},
5161
handleDelete: {
5262
type: Function,
53-
required: false,
63+
required: false
5464
},
5565
handleAdd: {
5666
type: Function,
57-
required: false,
58-
},
67+
required: false
68+
}
5969
},
6070
methods: {
6171
addItem() {
@@ -72,7 +82,7 @@ export default {
7282
if (this.handleReset) {
7383
this.handleReset();
7484
}
75-
},
76-
},
85+
}
86+
}
7787
};
7888
</script>

templates/quasar/common/mixins/CreateMixin.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ import { error } from '../../utils/notify';
33
export default {
44
watch: {
55
created(created) {
6-
if (!created) {
7-
return;
6+
if (created) {
7+
this.onCreated(created);
88
}
9-
10-
this.$router.push({ name: `${this.$options.servicePrefix}Update`, params: { id: created['@id'] } });
119
},
1210

1311
error(message) {
@@ -16,6 +14,13 @@ export default {
1614
},
1715

1816
methods: {
17+
onCreated(item) {
18+
this.$router.push({
19+
name: `${this.$options.servicePrefix}Update`,
20+
params: { id: item['@id'] },
21+
});
22+
},
23+
1924
onSendForm() {
2025
this.$refs.createForm.$children[0].validate().then(success => {
2126
if (success) {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export default {
1+
export default () => ({
22
isLoading: false,
33
error: '',
44
created: null,
55
violations: null,
6-
};
6+
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export default {
1+
export default () => ({
22
isLoading: false,
33
error: '',
44
deleted: null,
5-
};
5+
});

templates/quasar/common/store/list/actions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fetch from '../../../utils/fetch';
22

33
export const getItemsCommon = ({ commit }, { page, params }, { types, hydraPrefix }) => {
44
commit(types.TOGGLE_LOADING);
5-
fetch(page, { params })
5+
return fetch(page, { params })
66
.then(response => response.json())
77
.then(data => {
88
commit(types.TOGGLE_LOADING);
@@ -18,7 +18,7 @@ export const getItemsCommon = ({ commit }, { page, params }, { types, hydraPrefi
1818

1919
export const getSelectItemsCommon = ({ commit }, { page, params }, { types, hydraPrefix }) => {
2020
commit(types.TOGGLE_LOADING);
21-
fetch(page, { params })
21+
return fetch(page, { params })
2222
.then(response => response.json())
2323
.then(data => {
2424
commit(types.TOGGLE_LOADING);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
export default {
1+
export default () => ({
22
error: '',
33
isLoading: false,
44
items: [],
55
view: [],
66
totalItems: 10,
77
selectItems: null,
88
selectItemsTemplate: '',
9-
};
9+
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export default {
1+
export default () => ({
22
error: '',
33
isLoading: false,
44
retrieved: null,
5-
};
5+
});

templates/quasar/common/store/update/actions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const updateCommon = ({ commit, state }, values, { types }) => {
2424
commit(types.SET_ERROR, '');
2525
commit(types.TOGGLE_LOADING);
2626

27-
return fetch(state.retrieved['@id'], {
27+
return fetch((state.retrieved && state.retrieved['@id']) || values['@id'], {
2828
method: 'PUT',
2929
headers: new Headers({ 'Content-Type': 'application/ld+json' }),
3030
body: JSON.stringify(values),
@@ -46,6 +46,6 @@ export const updateCommon = ({ commit, state }, values, { types }) => {
4646
}
4747

4848
// eslint-disable-next-line
49-
commit(types.SET_ERROR, e.errors._error);
49+
commit(types.SET_ERROR, e.message);
5050
});
5151
};

0 commit comments

Comments
 (0)