2016-10-26 06:58:14 -04:00
|
|
|
var SecurityTemplateConstants = require('../constants/SecurityTemplateConstants');
|
|
|
|
|
|
|
|
var ErrorActions = require('./ErrorActions');
|
|
|
|
|
|
|
|
var models = require('../models.js');
|
|
|
|
var Security = models.Security;
|
|
|
|
var Error = models.Error;
|
2017-06-21 21:25:38 -04:00
|
|
|
var SecurityType = models.SecurityType;
|
2016-10-26 06:58:14 -04:00
|
|
|
|
|
|
|
function searchSecurityTemplates(searchString, searchType) {
|
|
|
|
return {
|
|
|
|
type: SecurityTemplateConstants.SEARCH_SECURITY_TEMPLATES,
|
|
|
|
searchString: searchString,
|
|
|
|
searchType: searchType
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function securityTemplatesSearched(searchString, searchType, securities) {
|
|
|
|
return {
|
|
|
|
type: SecurityTemplateConstants.SECURITY_TEMPLATES_SEARCHED,
|
|
|
|
searchString: searchString,
|
|
|
|
searchType: searchType,
|
|
|
|
securities: securities
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:25:38 -04:00
|
|
|
function fetchCurrencyTemplates() {
|
|
|
|
return {
|
|
|
|
type: SecurityTemplateConstants.FETCH_CURRENCIES
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function currencyTemplatesFetched(currencies) {
|
|
|
|
return {
|
|
|
|
type: SecurityTemplateConstants.CURRENCIES_FETCHED,
|
|
|
|
currencies: currencies
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-26 06:58:14 -04:00
|
|
|
function search(searchString, searchType, limit) {
|
|
|
|
return function (dispatch) {
|
|
|
|
dispatch(searchSecurityTemplates(searchString, searchType));
|
|
|
|
|
|
|
|
if (searchString == "")
|
|
|
|
return;
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: "GET",
|
|
|
|
dataType: "json",
|
2017-11-11 08:05:09 -05:00
|
|
|
url: "v1/securitytemplates/?search="+searchString+"&type="+searchType+"&limit="+limit,
|
2016-10-26 06:58:14 -04:00
|
|
|
success: function(data, status, jqXHR) {
|
|
|
|
var e = new Error();
|
|
|
|
e.fromJSON(data);
|
|
|
|
if (e.isError()) {
|
2017-01-03 05:32:19 -05:00
|
|
|
dispatch(ErrorActions.serverError(e));
|
2016-10-26 06:58:14 -04:00
|
|
|
} else if (data.securities == null) {
|
|
|
|
dispatch(securityTemplatesSearched(searchString, searchType, new Array()));
|
|
|
|
} else {
|
|
|
|
dispatch(securityTemplatesSearched(searchString, searchType,
|
|
|
|
data.securities.map(function(json) {
|
|
|
|
var s = new Security();
|
|
|
|
s.fromJSON(json);
|
|
|
|
return s;
|
|
|
|
})));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(jqXHR, status, error) {
|
2017-01-09 21:22:13 -05:00
|
|
|
dispatch(ErrorActions.ajaxError(error));
|
2016-10-26 06:58:14 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:25:38 -04:00
|
|
|
function fetchCurrencies() {
|
|
|
|
return function (dispatch) {
|
|
|
|
dispatch(fetchCurrencyTemplates());
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: "GET",
|
|
|
|
dataType: "json",
|
2017-11-11 08:05:09 -05:00
|
|
|
url: "v1/securitytemplates/?search=&type=currency",
|
2017-06-21 21:25:38 -04:00
|
|
|
success: function(data, status, jqXHR) {
|
|
|
|
var e = new Error();
|
|
|
|
e.fromJSON(data);
|
|
|
|
if (e.isError()) {
|
|
|
|
dispatch(ErrorActions.serverError(e));
|
|
|
|
} else if (data.securities == null) {
|
|
|
|
dispatch(currencyTemplatesFetched(new Array()));
|
|
|
|
} else {
|
|
|
|
dispatch(currencyTemplatesFetched(
|
|
|
|
data.securities.map(function(json) {
|
|
|
|
var s = new Security();
|
|
|
|
s.fromJSON(json);
|
|
|
|
return s;
|
|
|
|
})));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(jqXHR, status, error) {
|
|
|
|
dispatch(ErrorActions.ajaxError(error));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-10-26 06:58:14 -04:00
|
|
|
module.exports = {
|
2017-06-21 21:25:38 -04:00
|
|
|
search: search,
|
|
|
|
fetchCurrencies: fetchCurrencies
|
2016-10-26 06:58:14 -04:00
|
|
|
};
|