1
|
|
|
/** |
2
|
|
|
* Nextcloud - passman |
3
|
|
|
* |
4
|
|
|
* @copyright Copyright (c) 2016, Sander Brand ([email protected]) |
5
|
|
|
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected]) |
6
|
|
|
* @license GNU AGPL version 3 or any later version |
7
|
|
|
* |
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License as |
10
|
|
|
* published by the Free Software Foundation, either version 3 of the |
11
|
|
|
* License, or (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Affero General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public License |
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
function C_Promise(workload, context) { |
24
|
|
|
this.parent = context; |
25
|
|
|
|
26
|
|
|
this.update = null; |
27
|
|
|
this.finally = null; |
28
|
|
|
this.error_function = null; |
29
|
|
|
this.then = function (callback) { |
30
|
|
|
this.finally = callback; |
31
|
|
|
return this; |
32
|
|
|
}; |
33
|
|
|
this.progress = function (callback) { |
34
|
|
|
this.update = callback; |
35
|
|
|
return this; |
36
|
|
|
}; |
37
|
|
|
this.error = function (callback) { |
38
|
|
|
this.error_function = callback; |
39
|
|
|
return this; |
40
|
|
|
}; |
41
|
|
|
this.call_then = function (data) { |
42
|
|
|
if (this.finally !== null) { |
43
|
|
|
this.finally(data); |
44
|
|
|
} |
45
|
|
|
}; |
46
|
|
|
this.call_progress = function (data) { |
47
|
|
|
if (this.update !== null) { |
48
|
|
|
this.update(data); |
49
|
|
|
} |
50
|
|
|
}; |
51
|
|
|
this.call_error = function (data) { |
52
|
|
|
if (this.error_function !== null) { |
53
|
|
|
this.error_function(data); |
54
|
|
|
} |
55
|
|
|
}; |
56
|
|
|
|
57
|
|
|
setTimeout(workload.bind(this), 100); |
58
|
|
|
} |