5bc2d391aeb71330d78a57e4ddbf5e039849fe19
[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  * STANDARD_RIFT_IO_COPYRIGHT
20  */
21 import Alt from '../alt';
22 import LaunchNetworkServiceSource from '../network_service_launcher/launchNetworkServiceSource';
23 import LaunchNetworkServiceActions from '../network_service_launcher/launchNetworkServiceActions';
24 var ConfigAgentAccountSource = require('./configAgentAccountSource');
25 var ConfigAgentAccountActions = require('./configAgentAccountActions');
26
27 function createconfigAgentAccountStore () {
28   this.exportAsync(ConfigAgentAccountSource);
29   this.exportAsync(LaunchNetworkServiceSource);
30   this.bindAction(ConfigAgentAccountActions.createConfigAccountSuccess, this.createConfigAccountSuccess);
31   this.bindAction(ConfigAgentAccountActions.createConfigAccountLoading, this.createConfigAccountLoading);
32   this.bindAction(ConfigAgentAccountActions.createConfigAccountFailed, this.createConfigAccountFailed);
33   this.bindAction(ConfigAgentAccountActions.UPDATE_SUCCESS, this.updateSuccess);
34   this.bindAction(ConfigAgentAccountActions.UPDATE_LOADING, this.updateLoading);
35   this.bindAction(ConfigAgentAccountActions.UPDATE_FAIL, this.updateFail);
36   this.bindAction(ConfigAgentAccountActions.DELETE_SUCCESS, this.deleteSuccess);
37   this.bindAction(ConfigAgentAccountActions.DELETE_FAIL, this.deleteFail);
38   this.bindAction(ConfigAgentAccountActions.GET_CONFIG_AGENT_ACCOUNT_SUCCESS, this.getConfigAgentAccountSuccess);
39   this.bindAction(ConfigAgentAccountActions.GET_CONFIG_AGENT_ACCOUNT_FAIL, this.getConfigAgentAccountFail);
40   this.bindAction(ConfigAgentAccountActions.GET_CONFIG_AGENT_ACCOUNTS_SUCCESS, this.getConfigAgentAccountsSuccess);
41   // this.bindAction(ConfigAgentAccountActions.GET_CONFIG_AGENT_ACCOUNTS_FAIL, this.getConfigAgentAccountsFail);
42   this.bindAction(ConfigAgentAccountActions.VALIDATE_ERROR, this.validateError);
43   this.bindAction(ConfigAgentAccountActions.VALIDATE_RESET, this.validateReset);
44       this.bindListeners({
45         getCatalogSuccess: LaunchNetworkServiceActions.getCatalogSuccess
46     });
47   this.exportPublicMethods({
48     resetAccount: this.resetAccount.bind(this),
49     validateReset: this.validateReset.bind(this),
50     createConfigAccountFailed: this.createConfigAccountFailed.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   this.validateErrorEvent = 0;
85   this.validateErrorMsg = '';
86
87 }
88
89 createconfigAgentAccountStore.prototype.resetAccount = function() {
90   this.setState({
91     configAgentAccount: {
92       name: '',
93       'account-type': 'juju'
94   }
95   });
96 };
97 createconfigAgentAccountStore.prototype.validateReset = function() {
98   this.setState({
99     validateErrorEvent: false
100   });
101 };
102 createconfigAgentAccountStore.prototype.createConfigAccountLoading = function() {
103   this.setState({
104     isLoading: true
105   });
106 };
107 createconfigAgentAccountStore.prototype.createConfigAccountSuccess = function() {
108   this.setState({
109     isLoading: false
110   });
111 };
112 createconfigAgentAccountStore.prototype.createConfigAccountFailed = function(msg) {
113   console.log('failed')
114   var xhr = arguments[0];
115   this.setState({
116     isLoading: false,
117     validateErrorEvent: true,
118     validateErrorMsg: "There was an error creating your Config Agent Account. Please contact your system administrator"
119   });
120 };
121 createconfigAgentAccountStore.prototype.updateLoading = function() {
122   this.setState({
123     isLoading: true
124   });
125 };
126 createconfigAgentAccountStore.prototype.updateSuccess = function() {
127   this.setState({
128     isLoading: false
129   });
130 };
131 createconfigAgentAccountStore.prototype.updateFail = function() {
132   var xhr = arguments[0];
133   this.setState({
134     isLoading: false,
135     validateErrorEvent: true,
136     validateErrorMsg: "There was an error updating your Config Agent Account. Please contact your system administrator"
137   });
138 };
139
140 createconfigAgentAccountStore.prototype.deleteSuccess = function(data) {
141   this.setState({
142     isLoading: false
143   });
144   if(data.cb) {
145     data.cb();
146   }
147 };
148
149 createconfigAgentAccountStore.prototype.deleteFail = function(data) {
150   this.setState({
151     isLoading: false,
152     validateErrorEvent: true,
153     validateErrorMsg: "There was an error deleting your Config Agent Account. Please contact your system administrator"
154   });
155   if(data.cb) {
156     data.cb();
157   }
158 };
159
160 createconfigAgentAccountStore.prototype.getConfigAgentAccountSuccess = function(data) {
161
162   this.setState({
163     configAgentAccount: data.configAgentAccount,
164     isLoading:false
165   });
166 };
167
168 createconfigAgentAccountStore.prototype.getConfigAgentAccountFail = function(data) {
169   this.setState({
170     isLoading:false,
171     validateErrorEvent: true,
172     validateErrorMsg: "There was an error obtaining the data for the Config Agent Account. Please contact your system administrator"
173   });
174 };
175
176 createconfigAgentAccountStore.prototype.validateError = function(msg) {
177   this.setState({
178     validateErrorEvent: true,
179     validateErrorMsg: msg
180   });
181 };
182 createconfigAgentAccountStore.prototype.validateReset = function() {
183   this.setState({
184     validateErrorEvent: false
185   });
186 };
187 createconfigAgentAccountStore.prototype.getConfigAgentAccountsSuccess = function(configAgentAccounts) {
188   this.setState({
189     configAgentAccounts: configAgentAccounts || [],
190     isLoading:false
191   });
192 };
193 createconfigAgentAccountStore.prototype.getCatalogSuccess = function(data) {
194   var self = this;
195   var descriptorCount = 0;
196   data.forEach(function(catalog) {
197     descriptorCount += catalog.descriptors.length;
198   });
199
200   self.setState({
201     descriptorCount: descriptorCount
202   });
203 };
204
205
206 module.exports = Alt.createStore(createconfigAgentAccountStore);;
207