Skip to content

Commit

Permalink
expand canDelete and canEdit per line fixes #44
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardovanlaarhoven committed May 22, 2019
1 parent 3d21efd commit 74fc1e7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,18 @@ example for crudActionsAfter slot:
canUpdate: {required: false, type: Boolean, default: true},
```
```
canUpdateResourceKey: {required: false, type: String, default: ''},
```
```
canAdd: {required: false, type: Boolean, default: true},
```
```
canDelete: {required: false, type: Boolean, default: true},
```
```
canDeleteResourceKey: {required: false, type: String, default: ''},
```
```
canSearch: {required: false, type: Boolean, default: false},
```
```
Expand Down
37 changes: 33 additions & 4 deletions src/VuetifyResource.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
fab
slot="activator"
small
v-if="canUpdate === true && selected.length === 1"
v-if="canUpdateResources(selected) && selected.length === 1"
v-on:click="openUpdateHandler()"
>
<v-icon>$vuetify.icons.edit</v-icon>
Expand Down Expand Up @@ -113,7 +113,7 @@
fab
slot="activator"
small
v-if="canDelete === true && selected.length >= 1"
v-if="canDeleteResources(selected) && selected.length >= 1"
v-on:click="deleteHandler()"
>
<v-icon>$vuetify.icons.delete</v-icon>
Expand Down Expand Up @@ -166,7 +166,7 @@
<span v-if="typeof item.columnType !== 'object'">{{ props.item[item.value] }}</span>
</td>
<td class="crud-actions">
<v-tooltip left v-if="canUpdate === true">
<v-tooltip left v-if="canUpdateResources([props.item])">
<v-btn
color="green"
flat
Expand All @@ -178,7 +178,7 @@
</v-btn>
<span>{{ lang('update') }}</span>
</v-tooltip>
<v-tooltip left v-if="canDelete === true">
<v-tooltip left v-if="canDeleteResources([props.item])">
<v-btn
color="red"
flat
Expand Down Expand Up @@ -393,8 +393,10 @@
*/
tableContent: {required: true, type: Array},
canUpdate: {required: false, type: Boolean, default: true},
canUpdateResourceKey: {required: false, type: String, default: ''},
canAdd: {required: false, type: Boolean, default: true},
canDelete: {required: false, type: Boolean, default: true},
canDeleteResourceKey: {required: false, type: String, default: ''},
canSearch: {required: false, type: Boolean, default: false},
useCheckboxes: {required: false, type: Boolean, default: true},
showSpeedDail: {required: false, type: Boolean},
Expand Down Expand Up @@ -738,6 +740,33 @@
return this.texts[t];
}
},
canDeleteResources(selected) {
let canDelete = this.canDelete;
if (this.canDeleteResourceKey !== '') {
selected.forEach((resource) => {
if (resource[this.canDeleteResourceKey] === false) {
canDelete = false;
return;
}
});
}
return canDelete;
},
canUpdateResources(selected) {
let canUpdate = this.canUpdate;
if (this.canUpdateResourceKey !== '') {
selected.forEach((resource) => {
if (resource[this.canUpdateResourceKey] === false) {
canUpdate = false;
return;
}
});
}
return canUpdate;
},
},
};
</script>
Expand Down

0 comments on commit 74fc1e7

Please sign in to comment.