2015-01-01 19:09:55 +00:00
|
|
|
var LabsController = Ember.Controller.extend(Ember.Evented, {
|
2015-01-04 19:45:30 +00:00
|
|
|
needs: ['feature'],
|
|
|
|
|
2014-04-08 00:01:46 +02:00
|
|
|
uploadButtonText: 'Import',
|
2014-07-28 22:41:45 +01:00
|
|
|
importErrors: '',
|
2015-01-01 19:09:55 +00:00
|
|
|
labsJSON: Ember.computed('model.labs', function () {
|
|
|
|
return JSON.parse(this.get('model.labs') || {});
|
|
|
|
}),
|
2014-06-23 14:24:37 +00:00
|
|
|
|
2014-12-14 17:56:04 +00:00
|
|
|
saveLabs: function (optionName, optionValue) {
|
2015-01-01 19:09:55 +00:00
|
|
|
var self = this,
|
|
|
|
labsJSON = this.get('labsJSON');
|
2014-12-14 17:56:04 +00:00
|
|
|
|
|
|
|
// Set new value in the JSON object
|
|
|
|
labsJSON[optionName] = optionValue;
|
|
|
|
|
2015-01-01 19:09:55 +00:00
|
|
|
this.set('model.labs', JSON.stringify(labsJSON));
|
2014-12-14 17:56:04 +00:00
|
|
|
|
|
|
|
this.get('model').save().catch(function (errors) {
|
|
|
|
self.showErrors(errors);
|
|
|
|
self.get('model').rollback();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-01-01 19:09:55 +00:00
|
|
|
tagsUIFlag: Ember.computed.alias('config.tagsUI'),
|
|
|
|
codeUIFlag: Ember.computed.alias('config.codeInjectionUI'),
|
|
|
|
|
2015-01-04 19:45:30 +00:00
|
|
|
useTagsUI: Ember.computed('controllers.feature.tagsUI', function (key, value) {
|
2014-12-14 17:56:04 +00:00
|
|
|
// setter
|
|
|
|
if (arguments.length > 1) {
|
|
|
|
this.saveLabs('tagsUI', value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// getter
|
2015-01-04 19:45:30 +00:00
|
|
|
return this.get('controllers.feature.tagsUI') || false;
|
2014-12-14 17:56:04 +00:00
|
|
|
}),
|
|
|
|
|
2015-01-04 19:45:30 +00:00
|
|
|
useCodeInjectionUI: Ember.computed('controllers.feature.tagsUI', function (key, value) {
|
2014-12-14 17:56:04 +00:00
|
|
|
// setter
|
|
|
|
if (arguments.length > 1) {
|
|
|
|
this.saveLabs('codeInjectionUI', value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// getter
|
2015-01-04 19:45:30 +00:00
|
|
|
return this.get('controllers.feature.codeInjectionUI') || false;
|
2014-12-14 17:56:04 +00:00
|
|
|
}),
|
|
|
|
|
2014-04-08 00:01:46 +02:00
|
|
|
actions: {
|
2014-06-23 14:24:37 +00:00
|
|
|
onUpload: function (file) {
|
|
|
|
var self = this,
|
|
|
|
formData = new FormData();
|
|
|
|
|
2014-04-08 00:01:46 +02:00
|
|
|
this.set('uploadButtonText', 'Importing');
|
2014-12-11 16:55:14 +00:00
|
|
|
this.set('importErrors', '');
|
2014-07-28 22:41:45 +01:00
|
|
|
this.notifications.closePassive();
|
2014-06-23 14:24:37 +00:00
|
|
|
|
|
|
|
formData.append('importfile', file);
|
|
|
|
|
2014-07-13 00:01:26 -04:00
|
|
|
ic.ajax.request(this.get('ghostPaths.url').api('db'), {
|
2014-06-23 14:24:37 +00: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 22:41:45 +01:00
|
|
|
if (response && response.jqXHR && response.jqXHR.responseJSON && response.jqXHR.responseJSON.errors) {
|
|
|
|
self.set('importErrors', response.jqXHR.responseJSON.errors);
|
|
|
|
}
|
2014-10-24 21:09:50 +00:00
|
|
|
|
2014-07-28 22:41:45 +01:00
|
|
|
self.notifications.showError('Import Failed');
|
2014-06-23 14:24:37 +00:00
|
|
|
}).finally(function () {
|
|
|
|
self.set('uploadButtonText', 'Import');
|
|
|
|
self.trigger('reset');
|
|
|
|
});
|
2014-04-08 00:01:46 +02:00
|
|
|
},
|
2014-06-23 14:24:37 +00:00
|
|
|
|
|
|
|
exportData: function () {
|
2014-07-25 17:14:48 +02:00
|
|
|
var iframe = $('#iframeDownload'),
|
|
|
|
downloadURL = this.get('ghostPaths.url').api('db') +
|
|
|
|
'?access_token=' + this.get('session.access_token');
|
2014-06-23 14:24:37 +00:00
|
|
|
|
2014-07-25 17:14:48 +02:00
|
|
|
if (iframe.length === 0) {
|
2014-10-24 21:09:50 +00:00
|
|
|
iframe = $('<iframe>', {id: 'iframeDownload'}).hide().appendTo('body');
|
2014-07-25 17:14:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
iframe.attr('src', downloadURL);
|
2014-06-23 14:24:37 +00:00
|
|
|
},
|
|
|
|
|
2014-04-08 00:01:46 +02:00
|
|
|
sendTestEmail: function () {
|
2014-06-23 14:24:37 +00:00
|
|
|
var self = this;
|
|
|
|
|
2014-07-13 00:01:26 -04:00
|
|
|
ic.ajax.request(this.get('ghostPaths.url').api('mail', 'test'), {
|
2014-07-01 11:39:01 +02:00
|
|
|
type: 'POST'
|
2014-06-23 14:24:37 +00:00
|
|
|
}).then(function () {
|
2014-08-10 18:52:40 -07: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 14:24:37 +00:00
|
|
|
});
|
2014-04-08 00:01:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-12-01 11:39:11 +00:00
|
|
|
export default LabsController;
|