2014-12-01 06:39:11 -05:00
|
|
|
var LabsController = Ember.Controller.extend(Ember.Evented, {
|
2014-04-07 17:01:46 -05:00
|
|
|
uploadButtonText: 'Import',
|
2014-07-28 16:41:45 -05:00
|
|
|
importErrors: '',
|
2014-06-23 09:24:37 -05:00
|
|
|
|
2014-04-07 17:01:46 -05:00
|
|
|
actions: {
|
2014-06-23 09:24:37 -05:00
|
|
|
onUpload: function (file) {
|
|
|
|
var self = this,
|
|
|
|
formData = new FormData();
|
|
|
|
|
2014-04-07 17:01:46 -05:00
|
|
|
this.set('uploadButtonText', 'Importing');
|
2014-12-11 11:55:14 -05:00
|
|
|
this.set('importErrors', '');
|
2014-07-28 16:41:45 -05:00
|
|
|
this.notifications.closePassive();
|
2014-06-23 09:24:37 -05:00
|
|
|
|
|
|
|
formData.append('importfile', file);
|
|
|
|
|
2014-07-12 23:01:26 -05:00
|
|
|
ic.ajax.request(this.get('ghostPaths.url').api('db'), {
|
2014-06-23 09:24:37 -05: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-28 16:41:45 -05:00
|
|
|
if (response && response.jqXHR && response.jqXHR.responseJSON && response.jqXHR.responseJSON.errors) {
|
|
|
|
self.set('importErrors', response.jqXHR.responseJSON.errors);
|
|
|
|
}
|
2014-10-24 16:09:50 -05:00
|
|
|
|
2014-07-28 16:41:45 -05:00
|
|
|
self.notifications.showError('Import Failed');
|
2014-06-23 09:24:37 -05:00
|
|
|
}).finally(function () {
|
|
|
|
self.set('uploadButtonText', 'Import');
|
|
|
|
self.trigger('reset');
|
|
|
|
});
|
2014-04-07 17:01:46 -05:00
|
|
|
},
|
2014-06-23 09:24:37 -05:00
|
|
|
|
|
|
|
exportData: function () {
|
2014-07-25 10:14:48 -05:00
|
|
|
var iframe = $('#iframeDownload'),
|
|
|
|
downloadURL = this.get('ghostPaths.url').api('db') +
|
|
|
|
'?access_token=' + this.get('session.access_token');
|
2014-06-23 09:24:37 -05:00
|
|
|
|
2014-07-25 10:14:48 -05:00
|
|
|
if (iframe.length === 0) {
|
2014-10-24 16:09:50 -05:00
|
|
|
iframe = $('<iframe>', {id: 'iframeDownload'}).hide().appendTo('body');
|
2014-07-25 10:14:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
iframe.attr('src', downloadURL);
|
2014-06-23 09:24:37 -05:00
|
|
|
},
|
|
|
|
|
2014-04-07 17:01:46 -05:00
|
|
|
sendTestEmail: function () {
|
2014-06-23 09:24:37 -05:00
|
|
|
var self = this;
|
|
|
|
|
2014-07-12 23:01:26 -05:00
|
|
|
ic.ajax.request(this.get('ghostPaths.url').api('mail', 'test'), {
|
2014-07-01 04:39:01 -05:00
|
|
|
type: 'POST'
|
2014-06-23 09:24:37 -05:00
|
|
|
}).then(function () {
|
2014-08-10 20:52:40 -05: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 09:24:37 -05:00
|
|
|
});
|
2014-04-07 17:01:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-12-01 06:39:11 -05:00
|
|
|
export default LabsController;
|