195486811a0ce281076963d399c99b2899fa748e
[osm/riftware.git] /
1 /*
2  *    Copyright 2016 RIFT.IO Inc
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17
18 /*
19  * 
20  *
21  */
22 import LaunchNetworkServiceSource from '../network_service_launcher/launchNetworkServiceSource.js';
23 import LaunchNetworkServiceActions from '../network_service_launcher/launchNetworkServiceActions.js';
24
25 var alt = require('../../core/alt');
26 var ConfigAgentAccountSource = require('./configAgentAccountSource');
27 var ConfigAgentAccountActions = require('./configAgentAccountActions');
28
29 function createconfigAgentAccountStore () {
30   this.exportAsync(ConfigAgentAccountSource);
31   this.exportAsync(LaunchNetworkServiceSource);
32   this.bindAction(ConfigAgentAccountActions.CREATE_SUCCESS, this.createSuccess);
33   this.bindAction(ConfigAgentAccountActions.CREATE_LOADING, this.createLoading);
34   this.bindAction(ConfigAgentAccountActions.CREATE_FAIL, this.createFail);
35   this.bindAction(ConfigAgentAccountActions.UPDATE_SUCCESS, this.updateSuccess);
36   this.bindAction(ConfigAgentAccountActions.UPDATE_LOADING, this.updateLoading);
37   this.bindAction(ConfigAgentAccountActions.UPDATE_FAIL, this.updateFail);
38   this.bindAction(ConfigAgentAccountActions.DELETE_SUCCESS, this.deleteSuccess);
39   this.bindAction(ConfigAgentAccountActions.DELETE_FAIL, this.deleteFail);
40   this.bindAction(ConfigAgentAccountActions.GET_CONFIG_AGENT_ACCOUNT_SUCCESS, this.getConfigAgentAccountSuccess);
41   this.bindAction(ConfigAgentAccountActions.GET_CONFIG_AGENT_ACCOUNT_FAIL, this.getConfigAgentAccountFail);
42   this.bindAction(ConfigAgentAccountActions.GET_CONFIG_AGENT_ACCOUNTS_SUCCESS, this.getConfigAgentAccountsSuccess);
43   // this.bindAction(ConfigAgentAccountActions.GET_CONFIG_AGENT_ACCOUNTS_FAIL, this.getConfigAgentAccountsFail);
44   this.bindAction(ConfigAgentAccountActions.VALIDATE_ERROR, this.validateError);
45   this.bindAction(ConfigAgentAccountActions.VALIDATE_RESET, this.validateReset);
46       this.bindListeners({
47         getCatalogSuccess: LaunchNetworkServiceActions.getCatalogSuccess
48     });
49   this.exportPublicMethods({
50     resetAccount: this.resetAccount.bind(this)
51   })
52   this.configAgentAccount = {};
53   this.configAgentAccounts = [];
54   var self = this;
55   self.validateErrorMsg = "";
56   self.validateErrorEvent = 0;
57   this.isLoading = true;
58   this.params = {
59     "juju": [{
60         label: "IP Address",
61         ref: 'ip-address'
62     }, {
63         label: "Port",
64         ref: 'port',
65         optional: true
66     }, {
67         label: "Username",
68         ref: 'user'
69     }, {
70         label: "Secret",
71         ref: 'secret'
72     }]
73   };
74
75   this.accountType = [{
76       "name": "JUJU",
77       "account-type": "juju",
78   }];
79
80   this.configAgentAccount = {
81       name: '',
82       'account-type': 'juju'
83   };
84
85 }
86
87 createconfigAgentAccountStore.prototype.resetAccount = function() {
88   this.setState({
89     configAgentAccount: {
90       name: '',
91       'account-type': 'juju'
92   }
93   });
94 };
95
96 createconfigAgentAccountStore.prototype.createLoading = function() {
97   this.setState({
98     isLoading: true
99   });
100 };
101 createconfigAgentAccountStore.prototype.createSuccess = function() {
102   this.setState({
103     isLoading: false
104   });
105 };
106 createconfigAgentAccountStore.prototype.createFail = function() {
107   var xhr = arguments[0];
108   this.setState({
109     isLoading: false,
110     validateErrorEvent: true,
111     validateErrorMsg: "There was an error creating your Config Agent Account. Please contact your system administrator"
112   });
113 };
114 createconfigAgentAccountStore.prototype.updateLoading = function() {
115   this.setState({
116     isLoading: true
117   });
118 };
119 createconfigAgentAccountStore.prototype.updateSuccess = function() {
120   this.setState({
121     isLoading: false
122   });
123 };
124 createconfigAgentAccountStore.prototype.updateFail = function() {
125   var xhr = arguments[0];
126   this.setState({
127     isLoading: false,
128     validateErrorEvent: true,
129     validateErrorMsg: "There was an error updating your Config Agent Account. Please contact your system administrator"
130   });
131 };
132
133 createconfigAgentAccountStore.prototype.deleteSuccess = function(data) {
134   this.setState({
135     isLoading: false
136   });
137   if(data.cb) {
138     data.cb();
139   }
140 };
141
142 createconfigAgentAccountStore.prototype.deleteFail = function(data) {
143   this.setState({
144     isLoading: false,
145     validateErrorEvent: true,
146     validateErrorMsg: "There was an error deleting your Config Agent Account. Please contact your system administrator"
147   });
148   if(data.cb) {
149     data.cb();
150   }
151 };
152
153 createconfigAgentAccountStore.prototype.getConfigAgentAccountSuccess = function(data) {
154
155   this.setState({
156     configAgentAccount: data.configAgentAccount,
157     isLoading:false
158   });
159 };
160
161 createconfigAgentAccountStore.prototype.getConfigAgentAccountFail = function(data) {
162   this.setState({
163     isLoading:false,
164     validateErrorEvent: true,
165     validateErrorMsg: "There was an error obtaining the data for the Config Agent Account. Please contact your system administrator"
166   });
167 };
168
169 createconfigAgentAccountStore.prototype.validateError = function(msg) {
170   this.setState({
171     validateErrorEvent: true,
172     validateErrorMsg: msg
173   });
174 };
175 createconfigAgentAccountStore.prototype.validateReset = function() {
176   this.setState({
177     validateErrorEvent: false
178   });
179 };
180 createconfigAgentAccountStore.prototype.getConfigAgentAccountsSuccess = function(configAgentAccounts) {
181   this.setState({
182     configAgentAccounts: configAgentAccounts || [],
183     isLoading:false
184   });
185 };
186 createconfigAgentAccountStore.prototype.getCatalogSuccess = function(data) {
187   var self = this;
188   var descriptorCount = 0;
189   data.forEach(function(catalog) {
190     descriptorCount += catalog.descriptors.length;
191   });
192
193   self.setState({
194     descriptorCount: descriptorCount
195   });
196 };
197
198
199 module.exports = alt.createStore(createconfigAgentAccountStore);;
200