mirror of
https://github.com/aclindsa/moneygo.git
synced 2025-06-13 13:39:23 -04:00
Add initial UI for user-editable securities
This commit is contained in:
@ -19,6 +19,52 @@ function securitiesFetched(securities) {
|
||||
}
|
||||
}
|
||||
|
||||
function createSecurity() {
|
||||
return {
|
||||
type: SecurityConstants.CREATE_SECURITY
|
||||
}
|
||||
}
|
||||
|
||||
function securityCreated(security) {
|
||||
return {
|
||||
type: SecurityConstants.SECURITY_CREATED,
|
||||
security: security
|
||||
}
|
||||
}
|
||||
|
||||
function updateSecurity() {
|
||||
return {
|
||||
type: SecurityConstants.UPDATE_SECURITY
|
||||
}
|
||||
}
|
||||
|
||||
function securityUpdated(security) {
|
||||
return {
|
||||
type: SecurityConstants.SECURITY_UPDATED,
|
||||
security: security
|
||||
}
|
||||
}
|
||||
|
||||
function removeSecurity() {
|
||||
return {
|
||||
type: SecurityConstants.REMOVE_SECURITY
|
||||
}
|
||||
}
|
||||
|
||||
function securityRemoved(securityId) {
|
||||
return {
|
||||
type: SecurityConstants.SECURITY_REMOVED,
|
||||
securityId: securityId
|
||||
}
|
||||
}
|
||||
|
||||
function securitySelected(securityId) {
|
||||
return {
|
||||
type: SecurityConstants.SECURITY_SELECTED,
|
||||
securityId: securityId
|
||||
}
|
||||
}
|
||||
|
||||
function fetchAll() {
|
||||
return function (dispatch) {
|
||||
dispatch(fetchSecurities());
|
||||
@ -47,6 +93,88 @@ function fetchAll() {
|
||||
};
|
||||
}
|
||||
|
||||
function create(security) {
|
||||
return function (dispatch) {
|
||||
dispatch(createSecurity());
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
url: "security/",
|
||||
data: {security: security.toJSON()},
|
||||
success: function(data, status, jqXHR) {
|
||||
var e = new Error();
|
||||
e.fromJSON(data);
|
||||
if (e.isError()) {
|
||||
ErrorActions.serverError(e);
|
||||
} else {
|
||||
var s = new Security();
|
||||
s.fromJSON(data);
|
||||
dispatch(securityCreated(s));
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, status, error) {
|
||||
ErrorActions.ajaxError(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function update(security) {
|
||||
return function (dispatch) {
|
||||
dispatch(updateSecurity());
|
||||
|
||||
$.ajax({
|
||||
type: "PUT",
|
||||
dataType: "json",
|
||||
url: "security/"+security.SecurityId+"/",
|
||||
data: {security: security.toJSON()},
|
||||
success: function(data, status, jqXHR) {
|
||||
var e = new Error();
|
||||
e.fromJSON(data);
|
||||
if (e.isError()) {
|
||||
ErrorActions.serverError(e);
|
||||
} else {
|
||||
var s = new Security();
|
||||
s.fromJSON(data);
|
||||
dispatch(securityUpdated(s));
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, status, error) {
|
||||
ErrorActions.ajaxError(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function remove(security) {
|
||||
return function(dispatch) {
|
||||
dispatch(removeSecurity());
|
||||
|
||||
$.ajax({
|
||||
type: "DELETE",
|
||||
dataType: "json",
|
||||
url: "security/"+security.SecurityId+"/",
|
||||
success: function(data, status, jqXHR) {
|
||||
var e = new Error();
|
||||
e.fromJSON(data);
|
||||
if (e.isError()) {
|
||||
ErrorActions.serverError(e);
|
||||
} else {
|
||||
dispatch(securityRemoved(security.SecurityId));
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, status, error) {
|
||||
ErrorActions.ajaxError(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fetchAll: fetchAll
|
||||
fetchAll: fetchAll,
|
||||
create: create,
|
||||
update: update,
|
||||
remove: remove,
|
||||
select: securitySelected
|
||||
};
|
||||
|
62
js/actions/SecurityTemplateActions.js
Normal file
62
js/actions/SecurityTemplateActions.js
Normal file
@ -0,0 +1,62 @@
|
||||
var SecurityTemplateConstants = require('../constants/SecurityTemplateConstants');
|
||||
|
||||
var ErrorActions = require('./ErrorActions');
|
||||
|
||||
var models = require('../models.js');
|
||||
var Security = models.Security;
|
||||
var Error = models.Error;
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
function search(searchString, searchType, limit) {
|
||||
return function (dispatch) {
|
||||
dispatch(searchSecurityTemplates(searchString, searchType));
|
||||
|
||||
if (searchString == "")
|
||||
return;
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "securitytemplate/?search="+searchString+"&type="+searchType+"&limit="+limit,
|
||||
success: function(data, status, jqXHR) {
|
||||
var e = new Error();
|
||||
e.fromJSON(data);
|
||||
if (e.isError()) {
|
||||
ErrorActions.serverError(e);
|
||||
} 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) {
|
||||
ErrorActions.ajaxError(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
search: search
|
||||
};
|
Reference in New Issue
Block a user