2014-12-01 14:39:11 +03:00
|
|
|
var LabsController = Ember.Controller.extend(Ember.Evented, {
|
2014-04-08 02:01:46 +04:00
|
|
|
uploadButtonText: 'Import',
|
2014-07-29 01:41:45 +04:00
|
|
|
importErrors: '',
|
2014-06-23 18:24:37 +04:00
|
|
|
|
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);
|
|
|
|
|
2014-07-13 08:01:26 +04:00
|
|
|
ic.ajax.request(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 () {
|
|
|
|
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') +
|
|
|
|
'?access_token=' + this.get('session.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;
|
|
|
|
|
2014-07-13 08:01:26 +04:00
|
|
|
ic.ajax.request(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
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-12-01 14:39:11 +03:00
|
|
|
export default LabsController;
|