|
Lines 48-53
export default {
Link Here
|
| 48 |
name: this.add_component, |
48 |
name: this.add_component, |
| 49 |
}) |
49 |
}) |
| 50 |
}, |
50 |
}, |
|
|
51 |
/** |
| 52 |
* Navigates to the list page of the given resource. |
| 53 |
* |
| 54 |
* @return {void} |
| 55 |
*/ |
| 56 |
goToResourceList: function () { |
| 57 |
this.$router.push({ |
| 58 |
name: this.list_component, |
| 59 |
}) |
| 60 |
}, |
| 61 |
/** |
| 62 |
* Resource deletion handler. |
| 63 |
* Accepts an optional callback function to run after deletion. |
| 64 |
* If no callback is provided, does the following: |
| 65 |
* - If deleting from show component, navigates to resource list component. |
| 66 |
* - If deleting from resource list component, redraws the table. |
| 67 |
* |
| 68 |
* @param {Object} resource - The resource to delete (optional) |
| 69 |
* @param {Object} callback - Callback to call after deletion (optional) |
| 70 |
* @return {void} |
| 71 |
*/ |
| 72 |
doResourceDelete: function (resource, callback) { |
| 73 |
let resource_id = resource |
| 74 |
? resource[this.id_attr] |
| 75 |
: this[this.resource_name][this.id_attr] |
| 76 |
let resource_name = resource |
| 77 |
? resource[this.name_attr] |
| 78 |
: this[this.resource_name][this.name_attr] |
| 79 |
|
| 80 |
this.setConfirmationDialog( |
| 81 |
{ |
| 82 |
title: this.$__( |
| 83 |
"Are you sure you want to remove this %s?" |
| 84 |
).format(this.i18n.display_name.toLowerCase()), |
| 85 |
message: resource_name, |
| 86 |
accept_label: this.$__("Yes, delete"), |
| 87 |
cancel_label: this.$__("No, do not delete"), |
| 88 |
}, |
| 89 |
() => { |
| 90 |
this.api_client.delete(resource_id).then( |
| 91 |
success => { |
| 92 |
this.setMessage( |
| 93 |
this.$__("%s %s deleted").format( |
| 94 |
this.i18n.display_name, |
| 95 |
resource_name |
| 96 |
), |
| 97 |
true |
| 98 |
) |
| 99 |
if (typeof callback === "function") { |
| 100 |
callback() |
| 101 |
} else { |
| 102 |
if ( |
| 103 |
this.$options.name === this.list_component |
| 104 |
) { |
| 105 |
this.$refs.table.redraw(this.table_url()) |
| 106 |
} else if ( |
| 107 |
this.$options.name === this.show_component |
| 108 |
) { |
| 109 |
this.goToResourceList() |
| 110 |
} |
| 111 |
} |
| 112 |
}, |
| 113 |
error => {} |
| 114 |
) |
| 115 |
} |
| 116 |
) |
| 117 |
}, |
| 51 |
}, |
118 |
}, |
| 52 |
name: "BaseResource", |
119 |
name: "BaseResource", |
| 53 |
props: { |
120 |
props: { |