2015-02-13 05:22:32 +01:00
|
|
|
import Ember from 'ember';
|
2015-05-27 02:41:12 +02:00
|
|
|
import {request as ajax} from 'ic-ajax';
|
|
|
|
|
2015-06-13 16:34:09 +02:00
|
|
|
export default Ember.Controller.extend({
|
2014-04-08 00:01:46 +02:00
|
|
|
uploadButtonText: 'Import',
|
2014-07-28 23:41:45 +02:00
|
|
|
importErrors: '',
|
2015-05-26 04:10:50 +02:00
|
|
|
|
|
|
|
ghostPaths: Ember.inject.service('ghost-paths'),
|
|
|
|
notifications: Ember.inject.service(),
|
|
|
|
|
2015-01-01 20:09:55 +01:00
|
|
|
labsJSON: Ember.computed('model.labs', function () {
|
|
|
|
return JSON.parse(this.get('model.labs') || {});
|
|
|
|
}),
|
2014-06-23 16:24:37 +02:00
|
|
|
|
2014-12-14 18:56:04 +01:00
|
|
|
saveLabs: function (optionName, optionValue) {
|
2015-01-01 20:09:55 +01:00
|
|
|
var self = this,
|
|
|
|
labsJSON = this.get('labsJSON');
|
2014-12-14 18:56:04 +01:00
|
|
|
|
|
|
|
// Set new value in the JSON object
|
|
|
|
labsJSON[optionName] = optionValue;
|
|
|
|
|
2015-01-01 20:09:55 +01:00
|
|
|
this.set('model.labs', JSON.stringify(labsJSON));
|
2014-12-14 18:56:04 +01:00
|
|
|
|
|
|
|
this.get('model').save().catch(function (errors) {
|
|
|
|
self.showErrors(errors);
|
|
|
|
self.get('model').rollback();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-04-08 00:01:46 +02:00
|
|
|
actions: {
|
2014-06-23 16:24:37 +02:00
|
|
|
onUpload: function (file) {
|
|
|
|
var self = this,
|
2015-05-26 04:10:50 +02:00
|
|
|
formData = new FormData(),
|
|
|
|
notifications = this.get('notifications');
|
2014-06-23 16:24:37 +02:00
|
|
|
|
2014-04-08 00:01:46 +02:00
|
|
|
this.set('uploadButtonText', 'Importing');
|
2014-12-11 17:55:14 +01:00
|
|
|
this.set('importErrors', '');
|
2015-05-26 04:10:50 +02:00
|
|
|
notifications.closePassive();
|
2014-06-23 16:24:37 +02:00
|
|
|
|
|
|
|
formData.append('importfile', file);
|
|
|
|
|
2015-05-27 02:41:12 +02:00
|
|
|
ajax(this.get('ghostPaths.url').api('db'), {
|
2014-06-23 16:24:37 +02:00
|
|
|
type: 'POST',
|
|
|
|
data: formData,
|
|
|
|
dataType: 'json',
|
|
|
|
cache: false,
|
|
|
|
contentType: false,
|
|
|
|
processData: false
|
|
|
|
}).then(function () {
|
2015-01-08 14:42:45 +01:00
|
|
|
// Clear the store, so that all the new data gets fetched correctly.
|
|
|
|
self.store.unloadAll('post');
|
|
|
|
self.store.unloadAll('tag');
|
|
|
|
self.store.unloadAll('user');
|
|
|
|
self.store.unloadAll('role');
|
|
|
|
self.store.unloadAll('setting');
|
|
|
|
self.store.unloadAll('notification');
|
2015-05-26 04:10:50 +02:00
|
|
|
notifications.showSuccess('Import successful.');
|
2014-06-23 16:24:37 +02:00
|
|
|
}).catch(function (response) {
|
2014-07-28 23:41:45 +02:00
|
|
|
if (response && response.jqXHR && response.jqXHR.responseJSON && response.jqXHR.responseJSON.errors) {
|
|
|
|
self.set('importErrors', response.jqXHR.responseJSON.errors);
|
|
|
|
}
|
2014-10-24 23:09:50 +02:00
|
|
|
|
2015-05-26 04:10:50 +02:00
|
|
|
notifications.showError('Import Failed');
|
2014-06-23 16:24:37 +02:00
|
|
|
}).finally(function () {
|
|
|
|
self.set('uploadButtonText', 'Import');
|
|
|
|
});
|
2014-04-08 00:01:46 +02:00
|
|
|
},
|
2014-06-23 16:24:37 +02:00
|
|
|
|
|
|
|
exportData: function () {
|
2014-07-25 17:14:48 +02:00
|
|
|
var iframe = $('#iframeDownload'),
|
|
|
|
downloadURL = this.get('ghostPaths.url').api('db') +
|
2015-05-24 16:37:53 +02:00
|
|
|
'?access_token=' + this.get('session.secure.access_token');
|
2014-06-23 16:24:37 +02:00
|
|
|
|
2014-07-25 17:14:48 +02:00
|
|
|
if (iframe.length === 0) {
|
2014-10-24 23:09:50 +02:00
|
|
|
iframe = $('<iframe>', {id: 'iframeDownload'}).hide().appendTo('body');
|
2014-07-25 17:14:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
iframe.attr('src', downloadURL);
|
2014-06-23 16:24:37 +02:00
|
|
|
},
|
|
|
|
|
2014-04-08 00:01:46 +02:00
|
|
|
sendTestEmail: function () {
|
2015-05-26 04:10:50 +02:00
|
|
|
var notifications = this.get('notifications');
|
2014-06-23 16:24:37 +02:00
|
|
|
|
2015-05-27 02:41:12 +02:00
|
|
|
ajax(this.get('ghostPaths.url').api('mail', 'test'), {
|
2014-07-01 11:39:01 +02:00
|
|
|
type: 'POST'
|
2014-06-23 16:24:37 +02:00
|
|
|
}).then(function () {
|
2015-05-26 04:10:50 +02:00
|
|
|
notifications.showSuccess('Check your email for the test message.');
|
2014-08-11 03:52:40 +02:00
|
|
|
}).catch(function (error) {
|
|
|
|
if (typeof error.jqXHR !== 'undefined') {
|
2015-05-26 04:10:50 +02:00
|
|
|
notifications.showAPIError(error);
|
2014-08-11 03:52:40 +02:00
|
|
|
} else {
|
2015-05-26 04:10:50 +02:00
|
|
|
notifications.showErrors(error);
|
2014-08-11 03:52:40 +02:00
|
|
|
}
|
2014-06-23 16:24:37 +02:00
|
|
|
});
|
2014-04-08 00:01:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|