2 * STANDARD_RIFT_IO_COPYRIGHT
4 import $ from 'jquery';
5 var Utils
= require('utils/utils.js');
6 let API_SERVER
= require('utils/rw.js').getSearchParams(window
.location
).api_server
;
8 let NODE_PORT
= require('utils/rw.js').getSearchParams(window
.location
).api_port
|| ((window
.location
.protocol
== 'https:') ? 8443 : 8000);
9 let DEV_MODE
= require('utils/rw.js').getSearchParams(window
.location
).dev_mode
|| false;
12 HOST
= window
.location
.protocol
+ '//' + window
.location
.hostname
;
16 let Users
= mockUsers();
19 module
.exports = function(Alt
) {
23 return new Promise(function(resolve
, reject
) {
24 // setTimeout(function() {
28 url
: `/user?api_server=${API_SERVER}`,
30 beforeSend
: Utils
.addAuthorizationStub
,
31 success: function(data
, textStatus
, jqXHR
) {
34 }).fail(function(xhr
){
35 //Authentication and the handling of fail states should be wrapped up into a connection class.
36 Utils
.checkAuthentication(xhr
.status
);
37 let msg
= xhr
.responseText
;
38 if(xhr
.errorMessage
) {
39 msg
= xhr
.errorMessage
45 interceptResponse
: interceptResponse({
46 'error': 'There was an error retrieving the resource orchestrator information.'
48 success
: Alt
.actions
.global
.getUsersSuccess
,
49 loading
: Alt
.actions
.global
.showScreenLoader
,
50 error
: Alt
.actions
.global
.showNotification
53 remote: function(state
, user
) {
54 return new Promise(function(resolve
, reject
) {
56 url
: `/user?api_server=${API_SERVER}`,
59 beforeSend
: Utils
.addAuthorizationStub
,
60 success: function(data
, textStatus
, jqXHR
) {
63 }).fail(function(xhr
){
64 //Authentication and the handling of fail states should be wrapped up into a connection class.
65 Utils
.checkAuthentication(xhr
.status
);
66 let msg
= xhr
.responseText
;
67 if(xhr
.errorMessage
) {
68 msg
= xhr
.errorMessage
74 interceptResponse
: interceptResponse({
75 'error': 'There was an error updating the user.'
77 success
: Alt
.actions
.global
.updateUserSuccess
,
78 loading
: Alt
.actions
.global
.showScreenLoader
,
79 error
: Alt
.actions
.global
.showNotification
82 remote: function(state
, user
) {
83 return new Promise(function(resolve
, reject
) {
84 // setTimeout(function() {
88 url
: `/user/${user['user-name']}/${user['user-domain']}?api_server=${API_SERVER}`,
91 beforeSend
: Utils
.addAuthorizationStub
,
92 success: function(data
, textStatus
, jqXHR
) {
95 }).fail(function(xhr
){
96 //Authentication and the handling of fail states should be wrapped up into a connection class.
97 Utils
.checkAuthentication(xhr
.status
);
98 let msg
= xhr
.responseText
;
99 if(xhr
.errorMessage
) {
100 msg
= xhr
.errorMessage
106 interceptResponse
: interceptResponse({
107 'error': 'There was an error deleting the user.'
109 success
: Alt
.actions
.global
.deleteUserSuccess
,
110 loading
: Alt
.actions
.global
.showScreenLoader
,
111 error
: Alt
.actions
.global
.showNotification
114 remote: function(state
, user
) {
116 return new Promise(function(resolve
, reject
) {
117 // setTimeout(function() {
121 url
: `/user?api_server=${API_SERVER}`,
124 beforeSend
: Utils
.addAuthorizationStub
,
125 success: function(data
, textStatus
, jqXHR
) {
128 }).fail(function(xhr
){
129 //Authentication and the handling of fail states should be wrapped up into a connection class.
130 Utils
.checkAuthentication(xhr
.status
);
131 let msg
= xhr
.responseText
;
132 if(xhr
.errorMessage
) {
133 msg
= xhr
.errorMessage
139 interceptResponse
: interceptResponse({
140 'error': 'There was an error updating the account.'
142 success
: Alt
.actions
.global
.createUserSuccess
,
143 loading
: Alt
.actions
.global
.showScreenLoader
,
144 error
: Alt
.actions
.global
.showNotification
149 function interceptResponse (responses
) {
150 return function(data
, action
, args
) {
151 if(responses
.hasOwnProperty(data
)) {
162 function mockUsers() {
165 for(let i
= 0; i
< 10; i
++) {
167 username
: `Tester ${i}`,
168 domain
: 'Some Domain',
171 platform_admin
: false,