From 8f1ad84125e4c23dc5044f50ff92eaa7475dd45a Mon Sep 17 00:00:00 2001 From: hylom Date: Fri, 8 Jun 2018 20:31:11 +0900 Subject: [PATCH] implement AD code manager done --- src/newslash_web/public/js/ad-codes-editor.js | 81 +++++++++++++--------- .../templates/admin/ads/index.html.tt2 | 35 ++++++---- 2 files changed, 73 insertions(+), 43 deletions(-) diff --git a/src/newslash_web/public/js/ad-codes-editor.js b/src/newslash_web/public/js/ad-codes-editor.js index 58040a62..5fe93f25 100644 --- a/src/newslash_web/public/js/ad-codes-editor.js +++ b/src/newslash_web/public/js/ad-codes-editor.js @@ -7,43 +7,61 @@ editor.run = function run (params) { message: '', adCodes: [], selected: {}, + edited: true, }; + const watch = { + }; + const computed = {}; const methods = { - editItem: function editItem(item) { - item.editing = true; - item.edited = true; - }, - deleteItem: function deleteItem() { - const target = []; - for (var i = 0; i < this.boxItems.length; i++) { - if (this.boxItems[i].selected) { - target.push({id: this.boxItems[i].id, index: i}); + saveItem: function saveItem(target) { + if (!target.ad_id && target.ad_id !== 0) { + this.message = "save_failed"; + return; + } + + const reqData = { + name: target.name, + description: target.description, + status: target.status, + content: target.content, + }; + if (target.ad_id) { + reqData.ad_id = target.ad_id; + } + + newslash.admin.updateADCodes(reqData).then( + (resp) => { // success + target.ad_id = resp.id; + this.message = "saved"; + }, + (resp) => { // fail + this.message = "save_failed"; } - } - if (target.length == 0) { + ); + }, + + deleteItem: function deleteItem(target) { + if (!target.ad_id && target.ad_id !== 0) { + this.message = "save_failed"; return; } - const msg = "delete " + target.length + " item(s)?"; - const result = window.confirm(msg); - if (result) { - // delete items - target.reverse(); - target.forEach(item => { - newslash.admin.deleteBox(item.id).then( - (response) => { // success - if (response.error) { - this.message = "error: " + response.message; - return; - } - this.boxItems.splice(item.index, 1); - }, - (response) => { // fail - this.message = "error"; - } - ); - }); + const pos = this.adCodes.indexOf(target); + if (target.ad_id === 0) { + this.adCodes.splice(pos, 1); + this.message = "deleted"; + return; } + + newslash.admin.deleteADCodes(target.ad_id).then( + (resp) => { // success + this.adCodes.splice(pos, 1); + this.message = "deleted"; + }, + (resp) => { // fail + this.message = "delete_failed"; + } + ); }, addItem: function addItem() { const item = { @@ -54,7 +72,7 @@ editor.run = function run (params) { status: 'enabled', content: '', }; - const it = this.adCodes.push(item); + this.adCodes.push(item); }, }; @@ -68,6 +86,7 @@ editor.run = function run (params) { data: data, computed: computed, methods: methods, + watch: watch, created: function onCreate() { newslash.admin.getADCodes().then( diff --git a/src/newslash_web/templates/admin/ads/index.html.tt2 b/src/newslash_web/templates/admin/ads/index.html.tt2 index 1e6c3745..e37db131 100644 --- a/src/newslash_web/templates/admin/ads/index.html.tt2 +++ b/src/newslash_web/templates/admin/ads/index.html.tt2 @@ -2,37 +2,48 @@

AD Code Manager

-
-
-
+ +
保存に失敗しました
+
保存しました
+
削除に失敗しました
+
削除しました
+
エラー
+ +
- + - + +
- +
- +
- +
- +
- +
-- 2.11.0