mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 12:21:36 +03:00
Fixed tag deletion
no issue - don't show "Delete tag" button when we're displaying a new/unsaved tag - refactor the `_deleteTag()` method to be more explicit and remove handling that is no longer required since the tag screen is not nested in the tags screen - revised the condition in `showUnsavedChangesModal()` method so that it's body doesn't fire twice when leaving the `tag` or `tag.new` route - revised the `showUnsavedChangesModal()` method body to look at the number of changed properties on the tag rather than relying on `tag.hasChangedAttributes` which is always `true` for new models
This commit is contained in:
parent
4496ea41c4
commit
c53e4f9cd7
@ -126,24 +126,10 @@ export default Controller.extend({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
_deleteTag() {
|
_deleteTag() {
|
||||||
let tag = this.tag;
|
return this.tag.destroyRecord().then(() => {
|
||||||
|
return this.transitionToRoute('tags');
|
||||||
return tag.destroyRecord().then(() => {
|
|
||||||
this._deleteTagSuccess();
|
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
this._deleteTagFailure(error);
|
return this.notifications.showAPIError(error, {key: 'tag.delete'});
|
||||||
});
|
});
|
||||||
},
|
|
||||||
|
|
||||||
_deleteTagSuccess() {
|
|
||||||
let currentRoute = this.router.currentRouteName || '';
|
|
||||||
|
|
||||||
if (currentRoute.match(/^tags/)) {
|
|
||||||
this.transitionToRoute('tags');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
_deleteTagFailure(error) {
|
|
||||||
this.notifications.showAPIError(error, {key: 'tag.delete'});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -38,15 +38,15 @@ export default AuthenticatedRoute.extend(CurrentUserSettings, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
showUnsavedChangesModal(transition) {
|
showUnsavedChangesModal(transition) {
|
||||||
if (transition.from && transition.from.name.match(/^tag$|^tag\.new$/) && transition.targetName) {
|
if (transition.from && transition.from.name === this.routeName && transition.targetName) {
|
||||||
let {controller} = this;
|
let {controller} = this;
|
||||||
|
|
||||||
if (!controller.tag.isDeleted && controller.tag.hasDirtyAttributes) {
|
// tag.changedAttributes is always true for new tags but number of changed attrs is reliable
|
||||||
|
if (!controller.tag.isDeleted && Object.keys(controller.tag.changedAttributes()).length > 0) {
|
||||||
transition.abort();
|
transition.abort();
|
||||||
controller.send('toggleUnsavedChangesModal', transition);
|
controller.send('toggleUnsavedChangesModal', transition);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -14,9 +14,12 @@
|
|||||||
setProperty=(action "setProperty")
|
setProperty=(action "setProperty")
|
||||||
showDeleteTagModal=(action "toggleDeleteTagModal")}}
|
showDeleteTagModal=(action "toggleDeleteTagModal")}}
|
||||||
</form>
|
</form>
|
||||||
<button class="gh-btn gh-btn-red gh-btn-icon mb15" {{action "toggleDeleteTagModal"}}>
|
|
||||||
<span>Delete tag</span>
|
{{#unless this.tag.isNew}}
|
||||||
</button>
|
<button class="gh-btn gh-btn-red gh-btn-icon mb15" {{action "toggleDeleteTagModal"}}>
|
||||||
|
<span>Delete tag</span>
|
||||||
|
</button>
|
||||||
|
{{/unless}}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
{{#if showUnsavedChangesModal}}
|
{{#if showUnsavedChangesModal}}
|
||||||
|
Loading…
Reference in New Issue
Block a user