code-corps / code-corps/code-corps-ember

Create a mixin for confirmation dialogs when working with long forms

未关闭
#1,569 1 条评论 0 个 reaction 已指派 1 人 已被 @snewcomer 认领 在 GitHub 查看
Difficulty: Easy in progress Priority: Low Skill: Ember.js
主要语言
JavaScript
星标
120
派生
75
PR 合并指标
30 天内没有已合并 PR

描述

# Problem

We have a number of places where we ask a user to confirm before leaving the page. We could write a mixin to help clean up this logic.

```js
export default Ember.Mixin.extend({;
modelName: null,
message: 'You will lose any unsaved information if you leave this page. Are you sure?',

actions: {
willTransition() {
let modelName = get(this, 'modelName');
if (isPresent(modelName)) {
let model = get(this, modelName);
if (get(modelName, 'isNew') {
this._confirmTransition(transition, model);
}
} else {
this._confirmTransition(transition);
}
}
},

_confirmTransition(transition, model) {
let message = get(this, 'message');
if (window.confirm(message)) {
if isPresent(model) {
model.destroyRecord();
}
} else {
transition.abort();
}
}
})
```

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。