diff --git a/app/controllers/review_offer.js b/app/controllers/review_offer.js index 5cace66ef..e6ec32d0f 100644 --- a/app/controllers/review_offer.js +++ b/app/controllers/review_offer.js @@ -97,6 +97,17 @@ export default Ember.Controller.extend(AsyncTasksMixin, { } }), + deleteOffer(offer, path = this.get("backLinkPath")) { + this.set("cancelByMe", true); + this.runTask(offer.destroyRecord()) + .then(() => this.transitionToRoute(path)) + .catch(error => { + offer.rollbackAttributes(); + throw error; + }) + .finally(() => this.set("cancelByMe", false)); + }, + actions: { toggleOfferOptions() { this.toggleProperty("displayOfferOptions"); @@ -133,25 +144,36 @@ export default Ember.Controller.extend(AsyncTasksMixin, { deleteOffer() { this.send("toggleOfferOptions"); - var offer = this.get("model"); + const offer = this.get("model"); this.get("messageBox").custom( this.get("i18n").t("delete_confirm"), this.get("i18n").t("review_offer.options.yes"), () => { - this.set("cancelByMe", true); - this.runTask(offer.destroyRecord()) - .then(() => this.transitionToRoute(this.get("backLinkPath"))) - .catch(error => { - offer.rollbackAttributes(); - throw error; - }) - .finally(() => this.set("cancelByMe", false)); + this.deleteOffer(offer); }, this.get("i18n").t("review_item.not_now"), null ); }, + transitionTo(path) { + const offer = this.get("model"); + const items = offer.get("items"); + if (!items.length) { + this.get("messageBox").custom( + this.get("i18n").t("review_offer.empty_offer_message"), + this.get("i18n").t("review_offer.options.yes"), + () => { + this.deleteOffer(offer, path); + }, + this.get("i18n").t("review_item.not_now"), + null + ); + } else { + this.transitionToRoute(path); + } + }, + reopenOffer() { this.runTask(async () => { await this.get("offerService").reopenOffer(this.get("model")); diff --git a/app/locales/en/translations.coffee b/app/locales/en/translations.coffee index aec54e05d..81ce409e2 100644 --- a/app/locales/en/translations.coffee +++ b/app/locales/en/translations.coffee @@ -252,6 +252,7 @@ I18nTranslationsEn = "close_offer_summary": "This will close the offer." "add_note": "Tap to add/edit sticky note" "tap_to_save": "tap to save" + "empty_offer_message": "This offer is empty. Do you want to delete it?" "donor": "offer_id": "Offer ID" @@ -320,6 +321,7 @@ I18nTranslationsEn = "assign": "Assign" "select_package_image": "Choose the favourite image for this package:" + "reject": "select_type": "Please choose Item Type first!" "option_error": "Please choose a reason." diff --git a/app/locales/zh-tw/translations.coffee b/app/locales/zh-tw/translations.coffee index 87105fe24..9df74c124 100644 --- a/app/locales/zh-tw/translations.coffee +++ b/app/locales/zh-tw/translations.coffee @@ -250,6 +250,7 @@ I18nTranslationsZhTw = "close_offer_summary": "這項捐贈項目將列為完成。" "add_note": "按下以增加/修改記事板" "tap_to_save": "按下以儲存" + "empty_offer_message": "這個捐贈沒有任何相關物資。你是否需要刪除" "donor": "offer_id": "捐贈項目號碼" diff --git a/app/templates/review_offer.hbs b/app/templates/review_offer.hbs index 31328034d..584e5fc4c 100644 --- a/app/templates/review_offer.hbs +++ b/app/templates/review_offer.hbs @@ -1,6 +1,6 @@