Ghost/ghost/admin/controllers/debug.js

67 lines
2.1 KiB
JavaScript
Raw Normal View History

var DebugController = Ember.Controller.extend(Ember.Evented, {
uploadButtonText: 'Import',
exportPath: function () {
return this.get('ghostPaths').apiUrl('db');
}.property(),
actions: {
onUpload: function (file) {
var self = this,
formData = new FormData();
this.set('uploadButtonText', 'Importing');
formData.append('importfile', file);
ic.ajax.request(this.get('ghostPaths').apiUrl('db'), {
type: 'POST',
headers: {
'X-CSRF-Token': $('meta[name="csrf-param"]').attr('content')
},
data: formData,
dataType: 'json',
cache: false,
contentType: false,
processData: false
}).then(function () {
self.notifications.showSuccess('Import successful.');
}).catch(function (response) {
self.notifications.showErrors(response);
}).finally(function () {
self.set('uploadButtonText', 'Import');
self.trigger('reset');
});
},
exportData: function () {
var self = this;
ic.ajax.request(this.get('ghostPaths').apiUrl('db'), {
type: 'GET'
}).then(function () {
self.notifications.showSuccess('Data exported successfully.');
}).catch(function (response) {
self.notifications.showErrors(response);
});
},
sendTestEmail: function () {
var self = this;
ic.ajax.request(this.get('ghostPaths').apiUrl('mail', 'test'), {
type: 'POST',
headers: {
'X-CSRF-Token': $('meta[name="csrf-param"]').attr('content')
}
}).then(function () {
self.notifications.showSuccess('Check your email for the test message:');
}).catch(function (response) {
self.notifications.showErrors(response);
});
}
}
});
export default DebugController;