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