|
1
|
|
|
/* |
|
2
|
|
|
* This file is part of the Sulu CMS. |
|
3
|
|
|
* |
|
4
|
|
|
* (c) MASSIVE ART WebServices GmbH |
|
5
|
|
|
* |
|
6
|
|
|
* This source file is subject to the MIT license that is bundled |
|
7
|
|
|
* with this source code in the file LICENSE. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
define(['jquery', 'services/husky/util'], function($, Util) { |
|
11
|
|
|
'use strict'; |
|
12
|
|
|
|
|
13
|
|
|
var templates = { |
|
14
|
|
|
url: _.template( |
|
|
|
|
|
|
15
|
|
|
'/admin/api/articles' + |
|
16
|
|
|
'<% if (typeof id !== "undefined") { %>/<%= id %><% } %>' + |
|
17
|
|
|
'<% if (typeof postfix !== "undefined") { %>/<%= postfix %><% } %>' + |
|
18
|
|
|
'<% if (typeof version !== "undefined") { %>/<%= version %><% } %>' + |
|
19
|
|
|
'?locale=<%= locale %>' + |
|
20
|
|
|
'<% if (typeof action !== "undefined") { %>&action=<%= action %><% } %>' + |
|
21
|
|
|
'<% if (typeof ids !== "undefined") { %>&ids=<%= ids.join(",") %><% } %>' |
|
22
|
|
|
), |
|
23
|
|
|
pageUrl: _.template( |
|
24
|
|
|
'/admin/api/articles/<%= articleId %>/pages' + |
|
25
|
|
|
'<% if (typeof pageId !== "undefined" && !!pageId) { %>/<%= pageId %><% } %>' + |
|
26
|
|
|
'?locale=<%= locale %>' + |
|
27
|
|
|
'<% if (typeof action !== "undefined") { %>&action=<%= action %><% } %>' |
|
28
|
|
|
) |
|
29
|
|
|
}; |
|
30
|
|
|
|
|
31
|
|
|
return { |
|
32
|
|
|
url: templates.url, |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Load article. |
|
36
|
|
|
* |
|
37
|
|
|
* @param {String} id |
|
38
|
|
|
* @param {String} locale |
|
39
|
|
|
*/ |
|
40
|
|
|
load: function(id, locale) { |
|
41
|
|
|
return Util.load(templates.url({id: id, locale: locale})); |
|
42
|
|
|
}, |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Load article synchronous. |
|
46
|
|
|
* |
|
47
|
|
|
* @param {String} id |
|
48
|
|
|
* @param {String} locale |
|
49
|
|
|
*/ |
|
50
|
|
|
loadSync: function(id, locale) { |
|
51
|
|
|
return Util.ajax({ |
|
52
|
|
|
url: templates.url({id: id, locale: locale}), |
|
53
|
|
|
dataType: 'json', |
|
54
|
|
|
async: false |
|
55
|
|
|
}); |
|
56
|
|
|
}, |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Save article. |
|
60
|
|
|
* |
|
61
|
|
|
* @param {Array} data |
|
62
|
|
|
* @param {String} id |
|
63
|
|
|
* @param {String} locale |
|
64
|
|
|
* @param {String} action |
|
65
|
|
|
*/ |
|
66
|
|
|
save: function(data, id, locale, action) { |
|
67
|
|
|
return Util.save(templates.url({id: id, locale: locale, action: action}), !id ? 'POST' : 'PUT', data); |
|
68
|
|
|
}, |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Save article-page. |
|
72
|
|
|
* |
|
73
|
|
|
* @param {Array} data |
|
74
|
|
|
* @param {String} articleId |
|
75
|
|
|
* @param {String} pageId |
|
76
|
|
|
* @param {String} locale |
|
77
|
|
|
* @param {String} action |
|
78
|
|
|
*/ |
|
79
|
|
|
savePage: function(data, articleId, pageId, locale, action) { |
|
80
|
|
|
return Util.save( |
|
81
|
|
|
templates.pageUrl({articleId: articleId, pageId: pageId, locale: locale, action: action}), |
|
82
|
|
|
pageId ? 'PUT' : 'POST', |
|
83
|
|
|
data |
|
84
|
|
|
); |
|
85
|
|
|
}, |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Remove article. |
|
89
|
|
|
* |
|
90
|
|
|
* @param {String|Array} id |
|
91
|
|
|
* @param {String} locale |
|
92
|
|
|
*/ |
|
93
|
|
|
remove: function(id, locale) { |
|
94
|
|
|
if (typeof id === 'string') { |
|
95
|
|
|
return Util.save(templates.url({id: id, locale: locale}), 'DELETE'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return Util.save(templates.url({ids: id, locale: locale}), 'DELETE'); |
|
99
|
|
|
}, |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Remove article-page. |
|
103
|
|
|
* |
|
104
|
|
|
* @param {String} articleId |
|
105
|
|
|
* @param {String} pageId |
|
106
|
|
|
* @param {String} locale |
|
107
|
|
|
*/ |
|
108
|
|
|
removePage: function(articleId, pageId, locale) { |
|
109
|
|
|
return Util.save(templates.pageUrl({articleId: articleId, pageId: pageId, locale: locale}), 'DELETE'); |
|
110
|
|
|
}, |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Unpublish article. |
|
114
|
|
|
* |
|
115
|
|
|
* @param {String} id |
|
116
|
|
|
* @param {String} locale |
|
117
|
|
|
*/ |
|
118
|
|
|
unpublish: function(id, locale) { |
|
119
|
|
|
return Util.save( |
|
120
|
|
|
templates.url({id: id, locale: locale, action: 'unpublish'}), |
|
121
|
|
|
'POST' |
|
122
|
|
|
); |
|
123
|
|
|
}, |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Remove article. |
|
127
|
|
|
* |
|
128
|
|
|
* @param {String} id |
|
129
|
|
|
* @param {String} locale |
|
130
|
|
|
*/ |
|
131
|
|
|
removeDraft: function(id, locale) { |
|
132
|
|
|
return Util.save( |
|
133
|
|
|
templates.url({id: id, locale: locale, action: 'remove-draft'}), |
|
134
|
|
|
'POST' |
|
135
|
|
|
); |
|
136
|
|
|
}, |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Restore article to given version. |
|
140
|
|
|
* |
|
141
|
|
|
* @param {String} id |
|
142
|
|
|
* @param {String} version |
|
143
|
|
|
* @param {String} locale |
|
144
|
|
|
*/ |
|
145
|
|
|
restoreVersion: function(id, version, locale) { |
|
146
|
|
|
return Util.save( |
|
147
|
|
|
templates.url({id: id, postfix: 'versions', locale: locale, version: version, action: 'restore'}), |
|
148
|
|
|
'POST' |
|
149
|
|
|
); |
|
150
|
|
|
}, |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Copy given article. |
|
154
|
|
|
* |
|
155
|
|
|
* @param {String} id |
|
156
|
|
|
* @param {String} locale |
|
157
|
|
|
*/ |
|
158
|
|
|
copy: function(id, locale) { |
|
159
|
|
|
return Util.save(templates.url({id: id, locale: locale, action: 'copy'}), 'POST'); |
|
160
|
|
|
}, |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Copy given article-pages. |
|
164
|
|
|
* |
|
165
|
|
|
* @param {String} id |
|
166
|
|
|
* @param {String[]} pages |
|
167
|
|
|
* @param {String} locale |
|
168
|
|
|
*/ |
|
169
|
|
|
orderPages: function(id, pages, locale) { |
|
170
|
|
|
return Util.save(templates.url({id: id, locale: locale, action: 'order'}), 'POST', {pages: pages}); |
|
171
|
|
|
}, |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Returns url for copy article from a given locale to a array of other locales url. |
|
175
|
|
|
* |
|
176
|
|
|
* @param {String} id |
|
177
|
|
|
* @param {String} src |
|
178
|
|
|
* @param {String[]} dest |
|
179
|
|
|
* |
|
180
|
|
|
* @returns {String} |
|
181
|
|
|
*/ |
|
182
|
|
|
getCopyLocaleUrl: function(id, src, dest) { |
|
183
|
|
|
return [ |
|
184
|
|
|
templates.url({id: id, locale: src, action: 'copy-locale'}), '&dest=', dest |
|
185
|
|
|
].join(''); |
|
186
|
|
|
}, |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Returns get versions url for given id and locale. |
|
190
|
|
|
* |
|
191
|
|
|
* @param {String} id |
|
192
|
|
|
* @param {String} locale |
|
193
|
|
|
* |
|
194
|
|
|
* @return {String} |
|
195
|
|
|
*/ |
|
196
|
|
|
getVersionsUrl: function(id, locale) { |
|
197
|
|
|
return templates.url({id: id, postfix: 'versions', locale: locale}); |
|
198
|
|
|
} |
|
199
|
|
|
}; |
|
200
|
|
|
}); |
|
201
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.