3 * STANDARD_RIFT_IO_COPYRIGHT
5 var API_SERVER = require('utils/rw.js').getSearchParams(window.location).api_server;
7 var createConfigAgentAccountActions = require('./configAgentAccountActions.js');
8 var Utils = require('utils/utils.js');
9 import $ from 'jquery';
10 var createConfigAgentAccountSource = {
12 * Creates a new Config Agent Account
13 * @param {object} state Reference to parent store state.
14 * @param {object} configAgentAccount Config Agent Account payload. Should resemble the following:
16 * "name": "Config-Agent-Account-One",
17 * "config-agent-type":"type",
19 * "Type specific options"
22 * @return {[type]} [description]
27 remote: function(state, configAgentAccount) {
28 return new Promise(function(resolve, reject) {
30 url: '//' + window.location.hostname + ':3000/launchpad/config-agent-account?api_server=' + API_SERVER,
32 beforeSend: Utils.addAuthorizationStub,
33 data: JSON.stringify(configAgentAccount),
34 contentType: "application/json",
35 success: function(data) {
38 ,error: function(error) {
39 console.log("There was an error creating the config agent account: ", arguments);
42 }).fail(function(xhr){
43 console.log('checking authentication');
44 //Authentication and the handling of fail states should be wrapped up into a connection class.
45 Utils.checkAuthentication(xhr.status);
50 success: createConfigAgentAccountActions.createConfigAccountSuccess,
51 loading: createConfigAgentAccountActions.createConfigAccountLoading,
52 error: createConfigAgentAccountActions.createConfigAccountFailed
57 * Updates a Config Agent Account
58 * @param {object} state Reference to parent store state.
59 * @param {object} configAgentAccount Config Agent Account payload. Should resemble the following:
61 * "name": "Config-Agent-Account-One",
62 * "config-agent-type":"type",
64 * "Type specific options"
67 * @return {[type]} [description]
72 remote: function(state, configAgentAccount) {
73 return new Promise(function(resolve, reject) {
75 url: '//' + window.location.hostname + ':3000/launchpad/config-agent-account/' + configAgentAccount.name + '?api_server=' + API_SERVER,
77 beforeSend: Utils.addAuthorizationStub,
78 data: JSON.stringify(configAgentAccount),
79 contentType: "application/json",
80 success: function(data) {
83 error: function(error) {
84 console.log("There was an error updating the config agent account: ", configAgentAccount.name, error);
87 }).fail(function(xhr){
88 //Authentication and the handling of fail states should be wrapped up into a connection class.
89 Utils.checkAuthentication(xhr.status);
93 success: createConfigAgentAccountActions.updateSuccess,
94 loading: createConfigAgentAccountActions.updateLoading,
95 error: createConfigAgentAccountActions.updateFail
100 * Deletes a Config Agent Account
101 * @param {object} state Reference to parent store state.
102 * @param {object} configAgentAccount configAgentAccount to delete
103 * @return {[type]} [description]
108 remote: function(state, configAgentAccount, cb) {
109 return new Promise(function(resolve, reject) {
111 url: '//' + window.location.hostname + ':3000/launchpad/config-agent-account/' + configAgentAccount + '?api_server=' + API_SERVER,
113 beforeSend: Utils.addAuthorizationStub,
114 success: function(data) {
115 resolve({data:data, cb:cb});
117 error: function(error) {
118 console.log("There was an error deleting the config agent account: ", configAgentAccount, error);
121 }).fail(function(xhr){
122 //Authentication and the handling of fail states should be wrapped up into a connection class.
123 Utils.checkAuthentication(xhr.status);
127 success: createConfigAgentAccountActions.deleteSuccess,
128 loading: createConfigAgentAccountActions.updateLoading,
129 error: createConfigAgentAccountActions.deleteFail
133 * Get a config agent account
137 getConfigAgentAccount: function() {
139 remote: function(state, configAgentAccount) {
140 return new Promise(function(resolve, reject) {
142 url: '//' + window.location.hostname + ':3000/launchpad/config-agent-account/' + configAgentAccount + '?api_server=' + API_SERVER,
144 beforeSend: Utils.addAuthorizationStub,
145 success: function(data) {
147 configAgentAccount: data
150 error: function(error) {
151 console.log('There was an error getting configAgentAccount', error);
154 }).fail(function(xhr){
155 //Authentication and the handling of fail states should be wrapped up into a connection class.
156 Utils.checkAuthentication(xhr.status);
160 success: createConfigAgentAccountActions.getConfigAgentAccountSuccess,
161 error: createConfigAgentAccountActions.getConfigAgentAccountFail
164 getConfigAgentAccounts: function() {
167 return new Promise(function(resolve, reject) {
169 url: '//' + window.location.hostname + ':3000/launchpad/config-agent-account?api_server=' + API_SERVER,
171 beforeSend: Utils.addAuthorizationStub,
172 success: function(configAgentAccounts) {
173 resolve(configAgentAccounts);
175 }).fail(function(xhr){
176 //Authentication and the handling of fail states should be wrapped up into a connection class.
177 Utils.checkAuthentication(xhr.status);
181 success: createConfigAgentAccountActions.getConfigAgentAccountsSuccess,
182 error: createConfigAgentAccountActions.getConfigAgentAccountsFail
187 module.exports = createConfigAgentAccountSource;