2 * Copyright 2016 RIFT.IO Inc
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 * STANDARD_RIFT_IO_COPYRIGHT
21 var API_SERVER = require('utils/rw.js').getSearchParams(window.location).api_server;
23 var createConfigAgentAccountActions = require('./configAgentAccountActions.js');
24 var Utils = require('utils/utils.js');
25 import $ from 'jquery';
26 var createConfigAgentAccountSource = {
28 * Creates a new Config Agent Account
29 * @param {object} state Reference to parent store state.
30 * @param {object} configAgentAccount Config Agent Account payload. Should resemble the following:
32 * "name": "Config-Agent-Account-One",
33 * "config-agent-type":"type",
35 * "Type specific options"
38 * @return {[type]} [description]
43 remote: function(state, configAgentAccount) {
44 return new Promise(function(resolve, reject) {
46 url: '//' + window.location.hostname + ':3000/launchpad/config-agent-account?api_server=' + API_SERVER,
48 beforeSend: Utils.addAuthorizationStub,
49 data: JSON.stringify(configAgentAccount),
50 contentType: "application/json",
51 success: function(data) {
54 ,error: function(error) {
55 console.log("There was an error creating the config agent account: ", arguments);
58 }).fail(function(xhr){
59 console.log('checking authentication');
60 //Authentication and the handling of fail states should be wrapped up into a connection class.
61 Utils.checkAuthentication(xhr.status);
66 success: createConfigAgentAccountActions.createConfigAccountSuccess,
67 loading: createConfigAgentAccountActions.createConfigAccountLoading,
68 error: createConfigAgentAccountActions.createConfigAccountFailed
73 * Updates a Config Agent Account
74 * @param {object} state Reference to parent store state.
75 * @param {object} configAgentAccount Config Agent Account payload. Should resemble the following:
77 * "name": "Config-Agent-Account-One",
78 * "config-agent-type":"type",
80 * "Type specific options"
83 * @return {[type]} [description]
88 remote: function(state, configAgentAccount) {
89 return new Promise(function(resolve, reject) {
91 url: '//' + window.location.hostname + ':3000/launchpad/config-agent-account/' + configAgentAccount.name + '?api_server=' + API_SERVER,
93 beforeSend: Utils.addAuthorizationStub,
94 data: JSON.stringify(configAgentAccount),
95 contentType: "application/json",
96 success: function(data) {
99 error: function(error) {
100 console.log("There was an error updating the config agent account: ", configAgentAccount.name, error);
103 }).fail(function(xhr){
104 //Authentication and the handling of fail states should be wrapped up into a connection class.
105 Utils.checkAuthentication(xhr.status);
109 success: createConfigAgentAccountActions.updateSuccess,
110 loading: createConfigAgentAccountActions.updateLoading,
111 error: createConfigAgentAccountActions.updateFail
116 * Deletes a Config Agent Account
117 * @param {object} state Reference to parent store state.
118 * @param {object} configAgentAccount configAgentAccount to delete
119 * @return {[type]} [description]
124 remote: function(state, configAgentAccount, cb) {
125 return new Promise(function(resolve, reject) {
127 url: '//' + window.location.hostname + ':3000/launchpad/config-agent-account/' + configAgentAccount + '?api_server=' + API_SERVER,
129 beforeSend: Utils.addAuthorizationStub,
130 success: function(data) {
131 resolve({data:data, cb:cb});
133 error: function(error) {
134 console.log("There was an error deleting the config agent account: ", configAgentAccount, error);
137 }).fail(function(xhr){
138 //Authentication and the handling of fail states should be wrapped up into a connection class.
139 Utils.checkAuthentication(xhr.status);
143 success: createConfigAgentAccountActions.deleteSuccess,
144 loading: createConfigAgentAccountActions.updateLoading,
145 error: createConfigAgentAccountActions.deleteFail
149 * Get a config agent account
153 getConfigAgentAccount: function() {
155 remote: function(state, configAgentAccount) {
156 return new Promise(function(resolve, reject) {
158 url: '//' + window.location.hostname + ':3000/launchpad/config-agent-account/' + configAgentAccount + '?api_server=' + API_SERVER,
160 beforeSend: Utils.addAuthorizationStub,
161 success: function(data) {
163 configAgentAccount: data
166 error: function(error) {
167 console.log('There was an error getting configAgentAccount', error);
170 }).fail(function(xhr){
171 //Authentication and the handling of fail states should be wrapped up into a connection class.
172 Utils.checkAuthentication(xhr.status);
176 success: createConfigAgentAccountActions.getConfigAgentAccountSuccess,
177 error: createConfigAgentAccountActions.getConfigAgentAccountFail
180 getConfigAgentAccounts: function() {
183 return new Promise(function(resolve, reject) {
185 url: '//' + window.location.hostname + ':3000/launchpad/config-agent-account?api_server=' + API_SERVER,
187 beforeSend: Utils.addAuthorizationStub,
188 success: function(configAgentAccounts) {
189 resolve(configAgentAccounts);
191 }).fail(function(xhr){
192 //Authentication and the handling of fail states should be wrapped up into a connection class.
193 Utils.checkAuthentication(xhr.status);
197 success: createConfigAgentAccountActions.getConfigAgentAccountsSuccess,
198 error: createConfigAgentAccountActions.getConfigAgentAccountsFail
203 module.exports = createConfigAgentAccountSource;