2014-02-27 06:44:09 +04:00
|
|
|
/*global Ghost, $ */
|
2013-07-11 23:02:18 +04:00
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
Ghost.Views.Debug = Ghost.View.extend({
|
|
|
|
events: {
|
2013-12-25 04:05:20 +04:00
|
|
|
"click .settings-menu a": "handleMenuClick",
|
2014-01-26 21:52:16 +04:00
|
|
|
"click #startupload": "handleUploadClick",
|
2014-04-04 05:59:09 +04:00
|
|
|
"click .js-delete": "handleDeleteClick",
|
|
|
|
"click #sendtestmail": "handleSendTestMailClick"
|
2013-07-11 23:02:18 +04:00
|
|
|
},
|
|
|
|
|
2014-01-06 18:05:31 +04:00
|
|
|
initialize: function () {
|
2014-01-26 21:52:16 +04:00
|
|
|
var view = this;
|
|
|
|
|
|
|
|
this.uploadButton = this.$el.find('#startupload');
|
|
|
|
|
2014-01-06 18:05:31 +04:00
|
|
|
// Disable import button and initizalize BlueImp file upload
|
2014-01-26 21:52:16 +04:00
|
|
|
this.uploadButton.prop('disabled', 'disabled');
|
2014-01-06 18:05:31 +04:00
|
|
|
$('#importfile').fileupload({
|
|
|
|
url: Ghost.paths.apiRoot + '/db/',
|
|
|
|
limitMultiFileUploads: 1,
|
|
|
|
replaceFileInput: false,
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-Token': $("meta[name='csrf-param']").attr('content')
|
|
|
|
},
|
|
|
|
dataType: 'json',
|
|
|
|
add: function (e, data) {
|
2014-02-27 06:44:09 +04:00
|
|
|
/*jshint unused:false*/
|
2014-01-26 21:52:16 +04:00
|
|
|
|
|
|
|
// Bind the upload data to the view, so it is
|
|
|
|
// available to the click handler, and enable the
|
|
|
|
// upload button.
|
|
|
|
view.fileUploadData = data;
|
|
|
|
data.context = view.uploadButton.removeProp('disabled');
|
2014-01-06 18:05:31 +04:00
|
|
|
},
|
|
|
|
done: function (e, data) {
|
2014-02-27 06:44:09 +04:00
|
|
|
/*jshint unused:false*/
|
2014-01-06 18:05:31 +04:00
|
|
|
$('#startupload').text('Import');
|
|
|
|
if (!data.result) {
|
|
|
|
throw new Error('No response received from server.');
|
|
|
|
}
|
|
|
|
if (!data.result.message) {
|
|
|
|
throw new Error('Unknown error');
|
|
|
|
}
|
|
|
|
|
|
|
|
Ghost.notifications.addItem({
|
|
|
|
type: 'success',
|
|
|
|
message: data.result.message,
|
|
|
|
status: 'passive'
|
|
|
|
});
|
|
|
|
},
|
|
|
|
error: function (response) {
|
|
|
|
$('#startupload').text('Import');
|
|
|
|
var responseJSON = response.responseJSON,
|
|
|
|
message = responseJSON && responseJSON.error ? responseJSON.error : 'unknown';
|
|
|
|
Ghost.notifications.addItem({
|
|
|
|
type: 'error',
|
|
|
|
message: ['A problem was encountered while importing new content to your blog. Error: ', message].join(''),
|
|
|
|
status: 'passive'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-07-11 23:02:18 +04:00
|
|
|
handleMenuClick: function (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
|
|
|
|
var $target = $(ev.currentTarget);
|
|
|
|
|
|
|
|
// Hide the current content
|
|
|
|
this.$(".settings-content").hide();
|
|
|
|
|
|
|
|
// Show the clicked content
|
|
|
|
this.$("#debug-" + $target.attr("class")).show();
|
|
|
|
|
|
|
|
return false;
|
2013-12-25 04:05:20 +04:00
|
|
|
},
|
2014-01-06 18:05:31 +04:00
|
|
|
|
2014-01-26 21:52:16 +04:00
|
|
|
handleUploadClick: function (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
|
|
|
|
if (!this.uploadButton.prop('disabled')) {
|
|
|
|
this.fileUploadData.context = this.uploadButton.text('Importing');
|
|
|
|
this.fileUploadData.submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent double post by disabling the button.
|
|
|
|
this.uploadButton.prop('disabled', 'disabled');
|
|
|
|
},
|
|
|
|
|
2013-12-25 04:05:20 +04:00
|
|
|
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'
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2014-02-22 23:13:51 +04:00
|
|
|
text: "Delete",
|
|
|
|
buttonClass: "button-delete"
|
2013-12-25 04:05:20 +04:00
|
|
|
},
|
|
|
|
reject: {
|
|
|
|
func: function () {
|
|
|
|
return true;
|
|
|
|
},
|
2014-02-22 23:13:51 +04:00
|
|
|
text: "Cancel",
|
|
|
|
buttonClass: "button"
|
2013-12-25 04:05:20 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
type: "action",
|
|
|
|
style: ["wide", "centered"],
|
|
|
|
animation: 'fade'
|
|
|
|
},
|
|
|
|
content: {
|
|
|
|
template: 'blank',
|
2013-12-27 17:50:47 +04:00
|
|
|
title: 'Would you really like to delete all content from your blog?',
|
|
|
|
text: '<p>This is permanent! No backups, no restores, no magic undo button. <br /> We warned you, ok?</p>'
|
2013-12-25 04:05:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
2014-04-04 05:59:09 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
handleSendTestMailClick: function (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: Ghost.paths.apiRoot + '/mail/test/',
|
|
|
|
type: 'POST',
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-Token': $("meta[name='csrf-param']").attr('content')
|
|
|
|
},
|
|
|
|
success: function onSuccess(response) {
|
|
|
|
Ghost.notifications.addItem({
|
|
|
|
type: 'success',
|
|
|
|
message: ['Check your email for the test message: ', response.message].join(''),
|
|
|
|
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 sending the test email: ', message].join(''),
|
|
|
|
status: 'passive'
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2013-07-11 23:02:18 +04:00
|
|
|
});
|
2014-01-26 21:52:16 +04:00
|
|
|
}());
|