-
Notifications
You must be signed in to change notification settings - Fork 17
/
landing-page.js.es6
80 lines (67 loc) · 1.55 KB
/
landing-page.js.es6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import EmberObject from "@ember/object";
import { ajax } from "discourse/lib/ajax";
import { url } from "discourse/lib/computed";
import { popupAjaxError } from "discourse/lib/ajax-error";
const basePath = "/landing/page";
const LandingPage = EmberObject.extend({
exportUrl: url("id", `${basePath}/%@/export`),
savePage() {
const creating = this.creating;
let path = basePath;
if (!creating) {
path += `/${this.id}`;
}
let page = {
name: this.name,
path: this.path,
parent_id: this.parent_id,
category_id: this.category_id,
theme_id: this.theme_id,
group_ids: this.group_ids,
body: this.body,
menu: this.menu,
};
return ajax(path, {
type: creating ? "POST" : "PUT",
data: {
page,
},
});
},
destroyPage() {
return ajax(`${basePath}/${this.id}`, {
type: "DELETE",
}).catch(popupAjaxError);
},
exportPage() {
return ajax(this.exportUrl, {
type: "GET",
dataType: "binary",
xhrFields: {
responseType: "blob",
},
});
},
});
LandingPage.reopenClass({
all() {
return ajax(basePath).catch(popupAjaxError);
},
find(pageId) {
return ajax(`${basePath}/${pageId}`).catch(popupAjaxError);
},
create(props = {}) {
const page = this._super.apply(this);
page.setProperties(props);
return page;
},
import(data) {
return ajax(`${basePath}/upload`, {
type: "POST",
processData: false,
contentType: false,
data,
});
},
});
export default LandingPage;