These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | /** |
||
2 | * @author Tahaa Karim <[email protected]> |
||
3 | * |
||
4 | * ownCloud - Mail |
||
5 | * |
||
6 | * This code is free software: you can redistribute it and/or modify |
||
7 | * it under the terms of the GNU Affero General Public License, version 3, |
||
8 | * as published by the Free Software Foundation. |
||
9 | * |
||
10 | * This program is distributed in the hope that it will be useful, |
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
13 | * GNU Affero General Public License for more details. |
||
14 | * |
||
15 | * You should have received a copy of the GNU Affero General Public License, version 3, |
||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/> |
||
17 | * |
||
18 | */ |
||
19 | |||
20 | define(function(require) { |
||
21 | 'use strict'; |
||
22 | |||
23 | var $ = require('jquery'); |
||
24 | var OC = require('OC'); |
||
25 | var Radio = require('radio'); |
||
26 | |||
27 | Radio.aliases.reply('entities', getAliasesEntities); |
||
28 | Radio.aliases.reply('save', saveAlias); |
||
29 | Radio.aliases.reply('delete', deleteAlias); |
||
30 | |||
31 | /** |
||
32 | * @param {Account} account |
||
33 | * @returns {Promise} |
||
34 | */ |
||
35 | function getAliasesEntities(account) { |
||
36 | var defer = $.Deferred(); |
||
37 | |||
38 | var url = OC.generateUrl('/apps/mail/accounts/{id}/aliases', { |
||
39 | id: account.get('accountId') |
||
40 | }); |
||
41 | var data = { |
||
42 | type: 'GET', |
||
43 | success: function(data) { |
||
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
44 | }, |
||
45 | error: function(xhr) { |
||
0 ignored issues
–
show
|
|||
46 | |||
47 | }, |
||
48 | data: { |
||
49 | accountId: account.get('accountId') |
||
50 | } |
||
51 | }; |
||
52 | var promise = $.ajax(url, data); |
||
53 | |||
54 | promise.done(function(data) { |
||
55 | defer.resolve(data); |
||
56 | }); |
||
57 | |||
58 | promise.fail(function() { |
||
59 | defer.reject(); |
||
60 | }); |
||
61 | |||
62 | return defer.promise(); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @param {Account} account |
||
67 | * @param alias |
||
68 | * @returns {undefined} |
||
69 | */ |
||
70 | function saveAlias(account, alias) { |
||
71 | var defer = $.Deferred(); |
||
72 | |||
73 | var url = OC.generateUrl('/apps/mail/accounts/{id}/aliases', { |
||
74 | id: account.get('accountId') |
||
75 | }); |
||
76 | var data = { |
||
77 | type: 'POST', |
||
78 | data: { |
||
79 | accountId: account.get('accountId'), |
||
80 | alias: alias.alias, |
||
81 | aliasName: alias.name |
||
82 | } |
||
83 | }; |
||
84 | var promise = $.ajax(url, data); |
||
85 | |||
86 | promise.done(function(data) { |
||
87 | defer.resolve(data); |
||
88 | }); |
||
89 | |||
90 | promise.fail(function() { |
||
91 | defer.reject(); |
||
92 | }); |
||
93 | |||
94 | return defer.promise(); |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * @param {Account} account |
||
99 | * @param aliasId |
||
100 | * @returns {undefined} |
||
101 | */ |
||
102 | function deleteAlias(account, aliasId) { |
||
103 | var defer = $.Deferred(); |
||
104 | |||
105 | var url = OC.generateUrl('/apps/mail/accounts/{id}/aliases/{aliasId}', { |
||
106 | id: account.get('accountId'), |
||
107 | aliasId: aliasId |
||
108 | }); |
||
109 | var data = { |
||
110 | type: 'DELETE' |
||
111 | }; |
||
112 | var promise = $.ajax(url, data); |
||
113 | |||
114 | promise.done(function(data) { |
||
0 ignored issues
–
show
|
|||
115 | defer.resolve(); |
||
116 | }); |
||
117 | |||
118 | promise.fail(function() { |
||
119 | defer.reject(); |
||
120 | }); |
||
121 | |||
122 | return defer.promise(); |
||
123 | } |
||
124 | |||
125 | }); |