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

43 lines
1.1 KiB
JavaScript
Raw Normal View History

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