|
195 | 195 | // there is only root |
196 | 196 | this._setCurrentDir('/', false); |
197 | 197 |
|
198 | | - if (!this._isOverview) { |
199 | | - if (this._showDeleted) { |
200 | | - var shares = $.ajax({ |
201 | | - url: OC.linkToOCS('apps/files_sharing/api/v1', 2) + 'deletedshares', |
202 | | - /* jshint camelcase: false */ |
203 | | - data: { |
204 | | - format: 'json', |
205 | | - include_tags: true |
206 | | - }, |
207 | | - type: 'GET', |
208 | | - beforeSend: function (xhr) { |
209 | | - xhr.setRequestHeader('OCS-APIREQUEST', 'true'); |
210 | | - }, |
211 | | - }); |
212 | | - } else { |
213 | | - var shares = $.ajax({ |
214 | | - url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares', |
215 | | - /* jshint camelcase: false */ |
216 | | - data: { |
217 | | - format: 'json', |
218 | | - shared_with_me: !!this._sharedWithUser, |
219 | | - include_tags: true |
220 | | - }, |
221 | | - type: 'GET', |
222 | | - beforeSend: function (xhr) { |
223 | | - xhr.setRequestHeader('OCS-APIREQUEST', 'true'); |
224 | | - }, |
225 | | - }); |
226 | | - } |
227 | | - var promises = []; |
228 | | - promises.push(shares); |
229 | | - |
230 | | - if (!!this._sharedWithUser) { |
231 | | - var remoteShares = $.ajax({ |
232 | | - url: OC.linkToOCS('apps/files_sharing/api/v1') + 'remote_shares', |
233 | | - /* jshint camelcase: false */ |
234 | | - data: { |
235 | | - format: 'json', |
236 | | - include_tags: true |
237 | | - }, |
238 | | - type: 'GET', |
239 | | - beforeSend: function (xhr) { |
240 | | - xhr.setRequestHeader('OCS-APIREQUEST', 'true'); |
241 | | - }, |
242 | | - }); |
243 | | - promises.push(remoteShares); |
244 | | - } else { |
245 | | - //Push empty promise so callback gets called the same way |
246 | | - promises.push($.Deferred().resolve()); |
247 | | - } |
248 | | - |
249 | | - this._reloadCall = $.when.apply($, promises); |
250 | | - var callBack = this.reloadCallback.bind(this); |
251 | | - return this._reloadCall.then(callBack, callBack); |
| 198 | + var promises = []; |
| 199 | + |
| 200 | + var deletedShares = { |
| 201 | + url: OC.linkToOCS('apps/files_sharing/api/v1', 2) + 'deletedshares', |
| 202 | + /* jshint camelcase: false */ |
| 203 | + data: { |
| 204 | + format: 'json', |
| 205 | + include_tags: true |
| 206 | + }, |
| 207 | + type: 'GET', |
| 208 | + beforeSend: function (xhr) { |
| 209 | + xhr.setRequestHeader('OCS-APIREQUEST', 'true'); |
| 210 | + }, |
| 211 | + }; |
| 212 | + |
| 213 | + var shares = { |
| 214 | + url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares', |
| 215 | + /* jshint camelcase: false */ |
| 216 | + data: { |
| 217 | + format: 'json', |
| 218 | + shared_with_me: this._sharedWithUser !== false, |
| 219 | + include_tags: true |
| 220 | + }, |
| 221 | + type: 'GET', |
| 222 | + beforeSend: function (xhr) { |
| 223 | + xhr.setRequestHeader('OCS-APIREQUEST', 'true'); |
| 224 | + }, |
| 225 | + }; |
| 226 | + |
| 227 | + var remoteShares = { |
| 228 | + url: OC.linkToOCS('apps/files_sharing/api/v1') + 'remote_shares', |
| 229 | + /* jshint camelcase: false */ |
| 230 | + data: { |
| 231 | + format: 'json', |
| 232 | + include_tags: true |
| 233 | + }, |
| 234 | + type: 'GET', |
| 235 | + beforeSend: function (xhr) { |
| 236 | + xhr.setRequestHeader('OCS-APIREQUEST', 'true'); |
| 237 | + }, |
| 238 | + }; |
| 239 | + |
| 240 | + // Add the proper ajax requests to the list and run them |
| 241 | + // and make sure we have 2 promises |
| 242 | + if (this._showDeleted) { |
| 243 | + promises.push($.ajax(deletedShares)); |
252 | 244 | } else { |
253 | | - var promises = []; |
254 | | - var sharedWith = $.ajax({ |
255 | | - url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares', |
256 | | - /* jshint camelcase: false */ |
257 | | - data: { |
258 | | - format: 'json', |
259 | | - shared_with_me: true, |
260 | | - include_tags: true |
261 | | - }, |
262 | | - type: 'GET', |
263 | | - beforeSend: function (xhr) { |
264 | | - xhr.setRequestHeader('OCS-APIREQUEST', 'true'); |
265 | | - }, |
266 | | - }); |
267 | | - promises.push(sharedWith); |
268 | | - |
269 | | - var sharedBy = $.ajax({ |
270 | | - url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares', |
271 | | - /* jshint camelcase: false */ |
272 | | - data: { |
273 | | - format: 'json', |
274 | | - shared_with_me: false, |
275 | | - include_tags: true |
276 | | - }, |
277 | | - type: 'GET', |
278 | | - beforeSend: function (xhr) { |
279 | | - xhr.setRequestHeader('OCS-APIREQUEST', 'true'); |
280 | | - }, |
281 | | - }); |
282 | | - promises.push(sharedBy); |
283 | | - |
284 | | - var remoteShares = $.ajax({ |
285 | | - url: OC.linkToOCS('apps/files_sharing/api/v1') + 'remote_shares', |
286 | | - /* jshint camelcase: false */ |
287 | | - data: { |
288 | | - format: 'json', |
289 | | - include_tags: true |
290 | | - }, |
291 | | - type: 'GET', |
292 | | - beforeSend: function (xhr) { |
293 | | - xhr.setRequestHeader('OCS-APIREQUEST', 'true'); |
294 | | - }, |
295 | | - }); |
296 | | - promises.push(remoteShares); |
| 245 | + promises.push($.ajax(shares)); |
297 | 246 |
|
298 | | - this._reloadCall = $.when.apply($, promises); |
299 | | - var callBack = this.reloadOverviewCallBack().bind(this); |
300 | | - return this._reloadCall.then(callBack, callBack, callBack); |
| 247 | + if (this._sharedWithUser !== false || this._isOverview) { |
| 248 | + promises.push($.ajax(remoteShares)); |
| 249 | + } |
| 250 | + if (this._isOverview) { |
| 251 | + shares.data.shared_with_me = !shares.data.shared_with_me |
| 252 | + promises.push($.ajax(shares)); |
| 253 | + } |
301 | 254 | } |
302 | | - }, |
303 | | - |
304 | | - reloadOverviewCallBack: function(sharedWith, sharedBy, remote) { |
305 | | - delete this._reloadCall; |
306 | | - this.hideMask(); |
307 | 255 |
|
308 | | - alert('foo'); |
| 256 | + this._reloadCall = $.when.apply($, promises); |
| 257 | + var callBack = this.reloadCallback.bind(this); |
| 258 | + return this._reloadCall.then(callBack, callBack); |
309 | 259 | }, |
310 | 260 |
|
311 | | - reloadCallback: function(shares, remoteShares) { |
| 261 | + reloadCallback: function(shares, remoteShares, additionnalShares) { |
312 | 262 | delete this._reloadCall; |
313 | 263 | this.hideMask(); |
314 | 264 |
|
|
318 | 268 |
|
319 | 269 | var files = []; |
320 | 270 |
|
321 | | - if (shares[0].ocs && shares[0].ocs.data) { |
322 | | - files = files.concat(this._makeFilesFromShares(shares[0].ocs.data)); |
| 271 | + // make sure to use the same format |
| 272 | + if(shares[0] && shares[0].ocs) { |
| 273 | + shares = shares[0]; |
| 274 | + } |
| 275 | + |
| 276 | + if (shares.ocs && shares.ocs.data) { |
| 277 | + files = files.concat(this._makeFilesFromShares(shares.ocs.data)); |
| 278 | + } |
| 279 | + |
| 280 | + if (remoteShares && remoteShares.ocs && remoteShares.ocs.data) { |
| 281 | + files = files.concat(this._makeFilesFromRemoteShares(remoteShares.ocs.data)); |
323 | 282 | } |
324 | 283 |
|
325 | | - if (remoteShares && remoteShares[0].ocs && remoteShares[0].ocs.data) { |
326 | | - files = files.concat(this._makeFilesFromRemoteShares(remoteShares[0].ocs.data)); |
| 284 | + if (additionnalShares[0] && additionnalShares[0].ocs && additionnalShares[0].ocs.data) { |
| 285 | + files = files.concat(this._makeFilesFromShares(additionnalShares[0].ocs.data)); |
327 | 286 | } |
328 | 287 |
|
329 | 288 | this.setFiles(files); |
|
0 commit comments