discourse-data-explorer/assets/javascripts/discourse/controllers/import-query.js.es6

40 lines
1.0 KiB
Plaintext
Raw Normal View History

2015-06-25 16:26:31 -04:00
import ModalFunctionality from 'discourse/mixins/modal-functionality';
2015-06-30 15:52:17 -04:00
import { popupAjaxError } from 'discourse/lib/ajax-error';
2015-06-25 16:26:31 -04:00
export default Ember.Controller.extend(ModalFunctionality, {
notReady: Em.computed.not('ready'),
2017-04-04 04:37:07 -04:00
adminPluginsExplorer: Ember.inject.controller(),
2015-06-25 16:26:31 -04:00
ready: function() {
let parsed;
try {
parsed = JSON.parse(this.get('queryFile'));
} catch (e) {
return false;
}
return !!parsed["query"];
}.property('queryFile'),
actions: {
doImport: function() {
const self = this;
const object = JSON.parse(this.get('queryFile')).query;
// Slight fixup before creating object
object.id = 0; // 0 means no Id yet
2015-06-25 16:26:31 -04:00
this.set('loading', true);
this.store.createRecord('query', object).save().then(function(query) {
self.send('closeModal');
self.set('loading', false);
2017-04-04 04:37:07 -04:00
const parentController = self.get('adminPluginsExplorer');
2015-06-30 15:52:17 -04:00
parentController.addCreatedRecord(query.target);
}).catch(popupAjaxError);
2015-06-25 16:26:31 -04:00
}
}
});