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