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