Skip to content

Commit

Permalink
Start work on documents manipulation
Browse files Browse the repository at this point in the history
TODO:
DOCUMENT MANIPULATION
DOCUMENT FILE MANIPULATION
TASK MANIPULATION
SHOW CONTEOLLED TASK FOR USER
SHOW USERS TASK
STOREHAUSE MANIPULATION
GOOD PRODUCTION AND SERVICE
  • Loading branch information
FairWindCo committed Oct 16, 2015
1 parent a0459eb commit 46b95f0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@
import org.springframework.web.bind.annotation.ResponseBody;
import ua.pp.fairwind.favorid.internalDB.jgrid.JGridRowsResponse;
import ua.pp.fairwind.favorid.internalDB.jgrid.JSComboExpenseResp;
import ua.pp.fairwind.favorid.internalDB.jgrid.Utils;
import ua.pp.fairwind.favorid.internalDB.model.directories.DocumentType;
import ua.pp.fairwind.favorid.internalDB.model.document.Document;
import ua.pp.fairwind.favorid.internalDB.model.proxy.DocumentProxy;
import ua.pp.fairwind.favorid.internalDB.repository.CounterpartyRepository;
import ua.pp.fairwind.favorid.internalDB.repository.DocumentRepository;
import ua.pp.fairwind.favorid.internalDB.repository.DocumentTypeRepository;
import ua.pp.fairwind.favorid.internalDB.repository.PersonRepository;
import ua.pp.fairwind.favorid.internalDB.security.UserDetailsAdapter;

import javax.servlet.http.HttpServletRequest;
Expand All @@ -34,7 +39,12 @@
public class DocumentController {
@Autowired
DocumentRepository documentRepository;

@Autowired
DocumentTypeRepository documentTypeRepository;
@Autowired
PersonRepository personRepository;
@Autowired
CounterpartyRepository counterpartyRepository;


@Secured("ROLE_USER")
Expand Down Expand Up @@ -81,12 +91,12 @@ public JGridRowsResponse<Document> getTable(HttpServletRequest request){

@Transactional(readOnly = false)
@RequestMapping(value = "/edit", method = {RequestMethod.POST,RequestMethod.GET})
public void editor(@RequestParam String oper,Document document,BindingResult result,HttpServletResponse response)throws IOException {
public void editor(@RequestParam String oper,Document document,BindingResult result,HttpServletRequest request,HttpServletResponse response)throws IOException {
if(result.hasErrors()){
response.sendError(400,result.toString());
return;
}
UserDetailsAdapter userDetail=(UserDetailsAdapter)SecurityContextHolder.getContext().getAuthentication().getDetails();
UserDetailsAdapter userDetail=(UserDetailsAdapter)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if(userDetail==null){
response.sendError(403, "FORBIDDEN!");
return;
Expand All @@ -95,6 +105,11 @@ public void editor(@RequestParam String oper,Document document,BindingResult res
case "add":
if(userDetail.hasRole("ROLE_ADD_DOCUMENTS")) {
//document.setCreationUser(userDetail.getUserP());
Long typeId= Utils.getLongParameter("documentType_key",request);
if(typeId!=null){
DocumentType dt=documentTypeRepository.findOne(typeId);
if(dt!=null)document.setDocumentType(dt);
}
documentRepository.save(document);
response.setStatus(200);
} else {
Expand All @@ -109,6 +124,11 @@ public void editor(@RequestParam String oper,Document document,BindingResult res
cpt.setNumber(document.getNumber());
cpt.setName(document.getName());
cpt.setDescription(document.getDescription());
Long typeId= Utils.getLongParameter("documentType_key",request);
if(typeId!=null){
DocumentType dt=documentTypeRepository.findOne(typeId);
if(dt!=null)cpt.setDocumentType(dt);
}
documentRepository.save(cpt);
response.setStatus(200);
} else {
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/ua/pp/fairwind/favorid/internalDB/jgrid/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ua.pp.fairwind.favorid.internalDB.jgrid;

import javax.servlet.http.HttpServletRequest;

/**
* Created by Ñåðãåé on 17.10.2015.
*/
public class Utils {
public static Long getLongParameter(String name,HttpServletRequest request){
Long val=null;
String value=request.getParameter(name);
if(value!=null && !value.isEmpty()){
try {
val = Long.parseLong(value);
}catch (NumberFormatException e){
//do nothing
}
}
return val;
}
}
7 changes: 2 additions & 5 deletions src/main/webapp/jsp/documents_list.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,8 @@
{name:'name',index:'name', width:100, editable:true, editrules:{required:false}, editoptions:{size:10},search:false},
{name:'description',index:'description', width:100, editable:true, editrules:{required:false}, editoptions:{size:10},search:false},
{name:'documentType_key', width:100, editable:true,hidden:true, search:false},
{name:'documentType', width:100, editable:true, editrules:{required:false},search:false,editoptions:{
{name:'documentType_name', width:100, editable:true, editrules:{edithidden:true,required:false},jsonmap:'documentType.name',search:false,editoptions:{
/**/
formater:function(elem){
return elem.name;
},
dataInit : function (elem) {
var value_elem=$(elem).val();
$(elem).wrap("<div></div>");
Expand All @@ -90,7 +87,7 @@
init_record: [value_elem.id],
bind_to:'personIDkey_setup',
}).bind('personIDkey_setup', function() {
$('#documentType_key').val($('#documenttypeid_primary_key').val());
$('#documentType_key').val($('#documentType_name_primary_key').val());
});
}/**/
}},
Expand Down

0 comments on commit 46b95f0

Please sign in to comment.