1
|
|
|
/* |
2
|
|
|
* MikoPBX - free phone system for small business |
3
|
|
|
* Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov |
4
|
|
|
* |
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU General Public License as published by |
7
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
8
|
|
|
* (at your option) any later version. |
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 General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
16
|
|
|
* If not, see <https://www.gnu.org/licenses/>. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
/* global PbxApi, globalTranslate */ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* This module encapsulates a collection of functions related to Users. |
23
|
|
|
* |
24
|
|
|
* @module UsersAPI |
25
|
|
|
*/ |
26
|
|
|
const UsersAPI = { |
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Checks if the new email is available. |
29
|
|
|
* @param {string} oldEmail - The original email. |
30
|
|
|
* @param {string} newEmail - The new email to check. |
31
|
|
|
* @param {string} cssClassName - The CSS class name for the input element. |
32
|
|
|
* @param {string} userId - The ID of the user associated with the extension. |
33
|
|
|
*/ |
34
|
|
|
checkAvailability(oldEmail, newEmail, cssClassName = 'email', userId = '') { |
35
|
|
|
if (oldEmail === newEmail || newEmail.length===0) { |
36
|
|
|
$(`.ui.input.${cssClassName}`).parent().removeClass('error'); |
37
|
|
|
$(`#${cssClassName}-error`).addClass('hidden'); |
38
|
|
|
return; |
39
|
|
|
} |
40
|
|
|
$.api({ |
41
|
|
|
url: PbxApi.usersAvailable, |
42
|
|
|
stateContext: `.ui.input.${cssClassName}`, |
43
|
|
|
on: 'now', |
44
|
|
|
urlData: { |
45
|
|
|
email: newEmail |
46
|
|
|
}, |
47
|
|
|
successTest: PbxApi.successTest, |
48
|
|
|
onSuccess(response) { |
49
|
|
|
if (response.data['available']===true) { |
50
|
|
|
$(`.ui.input.${cssClassName}`).parent().removeClass('error'); |
51
|
|
|
$(`#${cssClassName}-error`).addClass('hidden'); |
52
|
|
|
} else if (userId.length > 0 && response.data['userId'] === userId) { |
53
|
|
|
$(`.ui.input.${cssClassName}`).parent().removeClass('error'); |
54
|
|
|
$(`#${cssClassName}-error`).addClass('hidden'); |
55
|
|
|
} else { |
56
|
|
|
$(`.ui.input.${cssClassName}`).parent().addClass('error'); |
57
|
|
|
let message =`${globalTranslate.ex_ThisEmailAlreadyRegisteredForOtherUser}: `; |
58
|
|
|
if (globalTranslate[response.data['represent']]!==undefined){ |
59
|
|
|
message = globalTranslate[response.data['represent']]; |
60
|
|
|
} else { |
61
|
|
|
message +=response.data['represent']; |
62
|
|
|
} |
63
|
|
|
$(`#${cssClassName}-error`).removeClass('hidden').html(message); |
64
|
|
|
} |
65
|
|
|
}, |
66
|
|
|
}); |
67
|
|
|
}, |
68
|
|
|
} |