2021-02-24 08:43:35 +01:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2020-11-09 04:32:36 +01:00
|
|
|
import EmberObject from "@ember/object";
|
|
|
|
|
|
|
|
const CustomWizardManager = EmberObject.extend();
|
|
|
|
|
|
|
|
const basePath = "admin/wizards/manager";
|
|
|
|
|
|
|
|
CustomWizardManager.reopenClass({
|
|
|
|
import($formData) {
|
|
|
|
return ajax(`/${basePath}/import`, {
|
2021-02-24 08:43:35 +01:00
|
|
|
type: "POST",
|
2020-11-09 04:32:36 +01:00
|
|
|
data: $formData,
|
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
|
|
|
}).catch(popupAjaxError);
|
|
|
|
},
|
2021-02-24 08:43:35 +01:00
|
|
|
|
2020-11-09 04:32:36 +01:00
|
|
|
export(wizardIds) {
|
|
|
|
let url = `${Discourse.BaseUrl}/${basePath}/export?`;
|
2021-02-24 08:43:35 +01:00
|
|
|
|
2020-11-09 04:32:36 +01:00
|
|
|
wizardIds.forEach((wizardId, index) => {
|
2021-02-24 08:43:35 +01:00
|
|
|
let step = "wizard_ids[]=" + wizardId;
|
2020-11-09 04:32:36 +01:00
|
|
|
if (index !== wizardIds[wizardIds.length - 1]) {
|
2021-02-24 08:43:35 +01:00
|
|
|
step += "&";
|
2020-11-09 04:32:36 +01:00
|
|
|
}
|
|
|
|
url += step;
|
|
|
|
});
|
|
|
|
|
|
|
|
location.href = url;
|
|
|
|
},
|
2021-02-24 08:43:35 +01:00
|
|
|
|
2020-11-09 04:32:36 +01:00
|
|
|
destroy(wizardIds) {
|
|
|
|
return ajax(`/${basePath}/destroy`, {
|
|
|
|
type: "DELETE",
|
|
|
|
data: {
|
2021-02-24 08:43:35 +01:00
|
|
|
wizard_ids: wizardIds,
|
|
|
|
},
|
2020-11-09 04:32:36 +01:00
|
|
|
}).catch(popupAjaxError);
|
2021-02-24 08:43:35 +01:00
|
|
|
},
|
2020-11-09 04:32:36 +01:00
|
|
|
});
|
|
|
|
|
2021-02-24 08:43:35 +01:00
|
|
|
export default CustomWizardManager;
|