-
-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[5.x] Add ability to reset namespaced fieldsets (#9166)
Co-authored-by: Duncan McClean <duncan@duncanmcclean.com> Co-authored-by: Jason Varga <jason@pixelfear.com>
- Loading branch information
1 parent
7efe556
commit 0f04dfc
Showing
10 changed files
with
213 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<template> | ||
<confirmation-modal | ||
v-if="resetting" | ||
:title="modalTitle" | ||
:bodyText="modalBody" | ||
:buttonText="__('Reset')" | ||
:danger="true" | ||
@confirm="confirmed" | ||
@cancel="cancel" | ||
> | ||
</confirmation-modal> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
props: { | ||
resource: { | ||
type: Object | ||
}, | ||
resourceTitle: { | ||
type: String | ||
}, | ||
route: { | ||
type: String, | ||
}, | ||
redirect: { | ||
type: String | ||
}, | ||
reload: { | ||
type: Boolean | ||
} | ||
}, | ||
data() { | ||
return { | ||
resetting: false, | ||
redirectFromServer: null, | ||
} | ||
}, | ||
computed: { | ||
title() { | ||
return data_get(this.resource, 'title', this.resourceTitle); | ||
}, | ||
modalTitle() { | ||
return __('Reset :resource', {resource: this.title}); | ||
}, | ||
modalBody() { | ||
return __('Are you sure you want to reset this item?'); | ||
}, | ||
resetUrl() { | ||
let url = data_get(this.resource, 'reset_url', this.route); | ||
if (! url) console.error('FieldsetResetter cannot find reset url'); | ||
return url; | ||
}, | ||
redirectUrl() { | ||
return this.redirect || this.redirectFromServer; | ||
}, | ||
}, | ||
methods: { | ||
confirm() { | ||
this.resetting = true; | ||
}, | ||
confirmed() { | ||
this.$axios.delete(this.resetUrl) | ||
.then(response => { | ||
this.redirectFromServer = data_get(response, 'data.redirect'); | ||
this.success(); | ||
}) | ||
.catch(() => { | ||
this.$toast.error(__('Something went wrong')); | ||
}); | ||
}, | ||
success() { | ||
if (this.redirectUrl) { | ||
location.href = this.redirectUrl; | ||
return; | ||
} | ||
if (this.reload) { | ||
location.reload(); | ||
return; | ||
} | ||
this.$toast.success(__('Reset')); | ||
this.$emit('reset'); | ||
}, | ||
cancel() { | ||
this.resetting = false; | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Statamic\Events; | ||
|
||
use Statamic\Contracts\Git\ProvidesCommitMessage; | ||
|
||
class FieldsetReset extends Event implements ProvidesCommitMessage | ||
{ | ||
public $fieldset; | ||
|
||
public function __construct($fieldset) | ||
{ | ||
$this->fieldset = $fieldset; | ||
} | ||
|
||
public function commitMessage() | ||
{ | ||
return __('Fieldset reset', [], config('statamic.git.locale')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters