OSDN Git Service

js: implement AD code related methods
[newslash/newslash.git] / src / newslash_web / public / js / newslash-admin.js
1 /* newslash-admin.js */
2
3 (function () {
4   var nsAdmin = new Newslash({ baseUrl: '/api/v1/admin', });
5   Newslash.prototype.admin = nsAdmin;
6
7   // Export/Import
8   nsAdmin.exportFeeds = function exportFeeds() {
9     return this.get("/repository/export?target=feeds");
10   };
11
12   nsAdmin.importFeeds = function importFeeds() {
13     return this.get("/repository/import?target=feeds");
14   };
15
16   nsAdmin.exportBoxes = function exportBoxes() {
17     return this.get("/repository/export?target=boxes");
18   };
19
20   nsAdmin.importBoxes = function importBoxes() {
21     return this.get("/repository/import?target=boxes");
22   };
23
24   // Blocking
25   nsAdmin.getBlockedItems = function getBlockedItems(type) {
26     return this.get("/blocking?type=" + type);
27   };
28
29   nsAdmin.blockItem = function blockItem(type, id) {
30     return this.post("/blocking", {action: "block", type: type, id: id});
31   };
32
33   nsAdmin.unblockItem = function blockItem(type, id) {
34     return this.post("/blocking", {action: "unblock", type: type, id: id});
35   };
36
37   // Boxes
38   nsAdmin.updateBox = function createBox(params) {
39     if (!params) return this.fail();
40     if (params.id) {
41       params.action = "update";
42     } else {
43       params.action = "create";
44     }
45     return this.post("/sidebar", params);
46   };
47
48   nsAdmin.deleteBox = function deleteBox(id) {
49     if (!id) return this.fail();
50     return this.post("/sidebar", { action: "delete", id: id });
51   };
52
53   nsAdmin.getBoxes = function getBoxes() {
54     return this.get("/sidebar");
55   };
56
57   nsAdmin.getBoxById = function getBoxById(id) {
58     if (!id) return this.fail();
59     return this.get("/sidebar?id=" + id);
60   };
61
62   // AD codes
63   nsAdmin.getADCodes = function getADCodes() {
64     return this.get("/ad/code");
65   };
66
67   nsAdmin.getADCodeById = function getADCodeById(id) {
68     if (!id) return this.fail();
69     return this.get("/ad/code?id=" + id);
70   };
71
72   nsAdmin.updateADCodes = function createADCode(params) {
73     if (!params) return this.fail();
74     if (params.id) {
75       params.action = "update";
76     } else {
77       params.action = "create";
78     }
79     return this.post("/ad/code", params);
80   };
81
82   nsAdmin.deleteADCodes = function deleteADCode(id) {
83     if (!id) return this.fail();
84     return this.post("/ad/code", { action: "delete", id: id });
85   };
86
87 }).apply();