2015-01-01 14:09:55 -05:00
|
|
|
var LabsController = Ember.Controller.extend(Ember.Evented, {
|
2015-01-04 14:45:30 -05:00
|
|
|
needs: ['feature'],
|
|
|
|
|
2014-04-07 17:01:46 -05:00
|
|
|
uploadButtonText: 'Import',
|
2014-07-28 16:41:45 -05:00
|
|
|
importErrors: '',
|
2015-01-01 14:09:55 -05:00
|
|
|
labsJSON: Ember.computed('model.labs', function () {
|
|
|
|
return JSON.parse(this.get('model.labs') || {});
|
|
|
|
}),
|
2014-06-23 09:24:37 -05:00
|
|
|
|
2014-12-14 12:56:04 -05:00
|
|
|
saveLabs: function (optionName, optionValue) {
|
2015-01-01 14:09:55 -05:00
|
|
|
var self = this,
|
|
|
|
labsJSON = this.get('labsJSON');
|
2014-12-14 12:56:04 -05:00
|
|
|
|
|
|
|
// Set new value in the JSON object
|
|
|
|
labsJSON[optionName] = optionValue;
|
|
|
|
|
2015-01-01 14:09:55 -05:00
|
|
|
this.set('model.labs', JSON.stringify(labsJSON));
|
2014-12-14 12:56:04 -05:00
|
|
|
|
|
|
|
this.get('model').save().catch(function (errors) {
|
|
|
|
self.showErrors(errors);
|
|
|
|
self.get('model').rollback();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-01-01 14:09:55 -05:00
|
|
|
codeUIFlag: Ember.computed.alias('config.codeInjectionUI'),
|
|
|
|
|
2014-12-31 07:57:00 -05:00
|
|
|
useCodeInjectionUI: Ember.computed('controllers.feature.codeInjectionUI', function (key, value) {
|
2014-12-14 12:56:04 -05:00
|
|
|
// setter
|
|
|
|
if (arguments.length > 1) {
|
|
|
|
this.saveLabs('codeInjectionUI', value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// getter
|
2015-01-04 14:45:30 -05:00
|
|
|
return this.get('controllers.feature.codeInjectionUI') || false;
|
2014-12-14 12:56:04 -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 () {
|
2015-01-08 08:42:45 -05: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 09:24:37 -05:00
|
|
|
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;
|