From 0c20e80f70c6ae5d441050d114d79c217626e4bf Mon Sep 17 00:00:00 2001 From: Sebastian Gierlinger Date: Wed, 25 Dec 2013 01:05:20 +0100 Subject: [PATCH] Delete all content (posts and tags) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #1445 - added delete button to ‚ugly debug tools‘ - added api call to delete all content - added /db to cache invalidation routes --- ghost/admin/views/debug.js | 66 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/ghost/admin/views/debug.js b/ghost/admin/views/debug.js index 21839a8aa0..eaa12ade95 100644 --- a/ghost/admin/views/debug.js +++ b/ghost/admin/views/debug.js @@ -4,7 +4,8 @@ Ghost.Views.Debug = Ghost.View.extend({ events: { - "click .settings-menu a": "handleMenuClick" + "click .settings-menu a": "handleMenuClick", + "click .js-delete": "handleDeleteClick" }, handleMenuClick: function (ev) { @@ -19,7 +20,68 @@ this.$("#debug-" + $target.attr("class")).show(); return false; + }, + handleDeleteClick: function (ev) { + ev.preventDefault(); + this.addSubview(new Ghost.Views.Modal({ + model: { + options: { + close: true, + confirm: { + accept: { + func: function () { + $.ajax({ + url: Ghost.paths.apiRoot + '/db/', + type: 'DELETE', + headers: { + 'X-CSRF-Token': $("meta[name='csrf-param']").attr('content') + }, + success: function onSuccess(response) { + if (!response) { + throw new Error('No response received from server.'); + } + if (!response.message) { + throw new Error(response.detail || 'Unknown error'); + } + + Ghost.notifications.addItem({ + type: 'success', + message: response.message, + status: 'passive' + }); + + }, + error: function onError(response) { + var responseText = JSON.parse(response.responseText), + message = responseText && responseText.error ? responseText.error : 'unknown'; + Ghost.notifications.addItem({ + type: 'error', + message: ['A problem was encountered while deleting content from your blog. Error: ', message].join(''), + status: 'passive' + }); + + } + }); + }, + text: "Yes" + }, + reject: { + func: function () { + return true; + }, + text: "No" + } + }, + type: "action", + style: ["wide", "centered"], + animation: 'fade' + }, + content: { + template: 'blank', + title: 'Would you really like to delete all content from your blog?' + } + } + })); } }); - }()); \ No newline at end of file