diff --git a/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/ContactTypeController.java b/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/ContactTypeController.java index 4162ab0..f215eea 100644 --- a/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/ContactTypeController.java +++ b/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/ContactTypeController.java @@ -1,6 +1,7 @@ package ua.pp.fairwind.favorid.internalDB.controllers; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.security.access.annotation.Secured; @@ -10,12 +11,14 @@ import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; import ua.pp.fairwind.favorid.internalDB.jgrid.JGridRowsResponse; +import ua.pp.fairwind.favorid.internalDB.jgrid.JSComboExpenseResp; import ua.pp.fairwind.favorid.internalDB.model.directories.ContactType; import ua.pp.fairwind.favorid.internalDB.repository.ContactTypeRepository; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.List; /** @@ -125,4 +128,43 @@ public void editor(@RequestParam String oper,ContactType contactType,BindingResu } } + @Transactional(readOnly = true) + @RequestMapping(value = "/showList", method = RequestMethod.GET) + @ResponseBody + public Object simpleClientList(@RequestParam(required = false) Integer page_num, @RequestParam(required = false) Integer per_page,@RequestParam(value = "pkey_val[]",required = false) String pkey,@RequestParam(value = "q_word[]",required = false) String[] qword,@RequestParam long firmID) { + // Retrieve all persons by delegating the call to PersonService + //Sort sort= FormSort.formSortFromSortDescription(orderby); + Sort sort=new Sort(Sort.Direction.ASC,"surname"); + PageRequest pager=null; + if(page_num!=null && per_page!=null) { + pager = new PageRequest(page_num - 1, per_page, sort); + } + if(pager!=null) { + Page page; + if (qword != null && qword.length > 0) { + page = repositoryContactType.findByNameContains(qword[0], pager); + } else { + page = repositoryContactType.findAll(pager); + } + return new JSComboExpenseResp<>(page); + } else { + if(pkey!=null && !pkey.isEmpty()){ + Long key=Long.valueOf(pkey); + ContactType ft=null; + if(key!=null) { + ft = repositoryContactType.findOne(key); + } + return ft; + } else { + List page; + if (qword != null && qword.length > 0) { + page = repositoryContactType.findByNameContains(qword[0],sort); + } else { + page = repositoryContactType.findAll(sort); + } + return new JSComboExpenseResp<>(page); + } + } + } + } diff --git a/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/DocumentController.java b/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/DocumentController.java new file mode 100644 index 0000000..7f7e8b6 --- /dev/null +++ b/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/DocumentController.java @@ -0,0 +1,7 @@ +package ua.pp.fairwind.favorid.internalDB.controllers; + +/** + * Created by ������ on 14.10.2015. + */ +public class DocumentController { +} diff --git a/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/DocumentTypeController.java b/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/DocumentTypeController.java index 96ad8fe..4df939c 100644 --- a/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/DocumentTypeController.java +++ b/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/DocumentTypeController.java @@ -1,6 +1,7 @@ package ua.pp.fairwind.favorid.internalDB.controllers; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.security.access.annotation.Secured; @@ -13,12 +14,14 @@ import org.springframework.web.bind.annotation.RequestParam; 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.model.directories.DocumentType; import ua.pp.fairwind.favorid.internalDB.repository.DocumentTypeRepository; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.List; /** @@ -118,4 +121,43 @@ public void editor(@RequestParam String oper,DocumentType documentType,BindingRe } } + @Transactional(readOnly = true) + @RequestMapping(value = "/showList", method = RequestMethod.GET) + @ResponseBody + public Object simpleClientList(@RequestParam(required = false) Integer page_num, @RequestParam(required = false) Integer per_page,@RequestParam(value = "pkey_val[]",required = false) String pkey,@RequestParam(value = "q_word[]",required = false) String[] qword,@RequestParam long firmID) { + // Retrieve all persons by delegating the call to PersonService + //Sort sort= FormSort.formSortFromSortDescription(orderby); + Sort sort=new Sort(Sort.Direction.ASC,"surname"); + PageRequest pager=null; + if(page_num!=null && per_page!=null) { + pager = new PageRequest(page_num - 1, per_page, sort); + } + if(pager!=null) { + Page page; + if (qword != null && qword.length > 0) { + page = repositoryDocumentType.findByNameContains(qword[0], pager); + } else { + page = repositoryDocumentType.findAll(pager); + } + return new JSComboExpenseResp<>(page); + } else { + if(pkey!=null && !pkey.isEmpty()){ + Long key=Long.valueOf(pkey); + DocumentType ft=null; + if(key!=null) { + ft = repositoryDocumentType.findOne(key); + } + return ft; + } else { + List page; + if (qword != null && qword.length > 0) { + page = repositoryDocumentType.findByNameContains(qword[0],sort); + } else { + page = repositoryDocumentType.findAll(sort); + } + return new JSComboExpenseResp<>(page); + } + } + } + } diff --git a/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/PositionController.java b/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/PositionController.java index 42f9e32..da99e82 100644 --- a/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/PositionController.java +++ b/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/PositionController.java @@ -1,6 +1,7 @@ package ua.pp.fairwind.favorid.internalDB.controllers; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.security.access.annotation.Secured; @@ -13,12 +14,14 @@ import org.springframework.web.bind.annotation.RequestParam; 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.model.directories.Position; import ua.pp.fairwind.favorid.internalDB.repository.PositionRepository; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.List; /** @@ -117,4 +120,44 @@ public void editor(@RequestParam String oper,Position position,BindingResult res } } + @Transactional(readOnly = true) + @RequestMapping(value = "/showList", method = RequestMethod.GET) + @ResponseBody + public Object simpleClientList(@RequestParam(required = false) Integer page_num, @RequestParam(required = false) Integer per_page,@RequestParam(value = "pkey_val[]",required = false) String pkey,@RequestParam(value = "q_word[]",required = false) String[] qword,@RequestParam long firmID) { + // Retrieve all persons by delegating the call to PersonService + //Sort sort= FormSort.formSortFromSortDescription(orderby); + Sort sort=new Sort(Sort.Direction.ASC,"surname"); + PageRequest pager=null; + if(page_num!=null && per_page!=null) { + pager = new PageRequest(page_num - 1, per_page, sort); + } + if(pager!=null) { + Page page; + if (qword != null && qword.length > 0) { + page = repositoryPosition.findByNameContains(qword[0], pager); + } else { + page = repositoryPosition.findAll(pager); + } + return new JSComboExpenseResp<>(page); + } else { + if(pkey!=null && !pkey.isEmpty()){ + Long key=Long.valueOf(pkey); + Position ft=null; + if(key!=null) { + ft = repositoryPosition.findOne(key); + } + return ft; + } else { + List page; + if (qword != null && qword.length > 0) { + page = repositoryPosition.findByNameContains(qword[0],sort); + } else { + page = repositoryPosition.findAll(sort); + } + return new JSComboExpenseResp<>(page); + } + } + } + + } diff --git a/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/TaskController.java b/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/TaskController.java new file mode 100644 index 0000000..19f7093 --- /dev/null +++ b/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/TaskController.java @@ -0,0 +1,7 @@ +package ua.pp.fairwind.favorid.internalDB.controllers; + +/** + * Created by ������ on 14.10.2015. + */ +public class TaskController { +} diff --git a/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/TaskTypeController.java b/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/TaskTypeController.java index 91f6ba4..72ae8d5 100644 --- a/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/TaskTypeController.java +++ b/src/main/java/ua/pp/fairwind/favorid/internalDB/controllers/TaskTypeController.java @@ -1,6 +1,7 @@ package ua.pp.fairwind.favorid.internalDB.controllers; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.security.access.annotation.Secured; @@ -13,12 +14,15 @@ import org.springframework.web.bind.annotation.RequestParam; 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.model.directories.Position; import ua.pp.fairwind.favorid.internalDB.model.directories.TaskType; import ua.pp.fairwind.favorid.internalDB.repository.TaskTypeRepository; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.List; /** @@ -118,4 +122,43 @@ public void editor(@RequestParam String oper,TaskType taskType,BindingResult res } } + @Transactional(readOnly = true) + @RequestMapping(value = "/showList", method = RequestMethod.GET) + @ResponseBody + public Object simpleClientList(@RequestParam(required = false) Integer page_num, @RequestParam(required = false) Integer per_page,@RequestParam(value = "pkey_val[]",required = false) String pkey,@RequestParam(value = "q_word[]",required = false) String[] qword,@RequestParam long firmID) { + // Retrieve all persons by delegating the call to PersonService + //Sort sort= FormSort.formSortFromSortDescription(orderby); + Sort sort=new Sort(Sort.Direction.ASC,"surname"); + PageRequest pager=null; + if(page_num!=null && per_page!=null) { + pager = new PageRequest(page_num - 1, per_page, sort); + } + if(pager!=null) { + Page page; + if (qword != null && qword.length > 0) { + page = repositoryTaskType.findByNameContains(qword[0], pager); + } else { + page = repositoryTaskType.findAll(pager); + } + return new JSComboExpenseResp<>(page); + } else { + if(pkey!=null && !pkey.isEmpty()){ + Long key=Long.valueOf(pkey); + TaskType ft=null; + if(key!=null) { + ft = repositoryTaskType.findOne(key); + } + return ft; + } else { + List page; + if (qword != null && qword.length > 0) { + page = repositoryTaskType.findByNameContains(qword[0],sort); + } else { + page = repositoryTaskType.findAll(sort); + } + return new JSComboExpenseResp<>(page); + } + } + } + } diff --git a/src/main/java/ua/pp/fairwind/favorid/internalDB/model/proxy/DonutData.java b/src/main/java/ua/pp/fairwind/favorid/internalDB/model/proxy/DonutData.java new file mode 100644 index 0000000..6b77e40 --- /dev/null +++ b/src/main/java/ua/pp/fairwind/favorid/internalDB/model/proxy/DonutData.java @@ -0,0 +1,22 @@ +package ua.pp.fairwind.internalDBSystem.datamodel.proxy; + +/** + * Created by Сергей on 16.09.2015. + */ +public class DonutData { + final private long value; + final private String label; + + public DonutData(long value, String label) { + this.value = value; + this.label = label; + } + + public long getValue() { + return value; + } + + public String getLabel() { + return label; + } +} diff --git a/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/ContactTypeRepository.java b/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/ContactTypeRepository.java index 179be1f..7f5c438 100644 --- a/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/ContactTypeRepository.java +++ b/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/ContactTypeRepository.java @@ -2,6 +2,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.data.jpa.repository.JpaRepository; import ua.pp.fairwind.favorid.internalDB.model.directories.ContactType; @@ -14,4 +15,5 @@ public interface ContactTypeRepository extends JpaRepository{ Page findByNameContains(String name,Pageable pager); List findByNameContains(String name); + List findByNameContains(String name,Sort sort); } diff --git a/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/CounterpartyRepository.java b/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/CounterpartyRepository.java index 8cbc469..09db2be 100644 --- a/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/CounterpartyRepository.java +++ b/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/CounterpartyRepository.java @@ -2,6 +2,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -19,6 +20,7 @@ public interface CounterpartyRepository extends JpaRepository{ Page findByShortNameContains(String shortName, Pageable pager); List findByShortNameContains(String ShortName); + List findByShortNameContains(String ShortName,Sort sort); //@Query("select r from User u join u.userRoles r where u.userID=:userID") @Query("select a from Agreement a join a.counterparty c where c.id=:ID") Page getAgreements(@Param("ID") long id, Pageable pager); diff --git a/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/DocumentTypeRepository.java b/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/DocumentTypeRepository.java index e2a2a51..387f6dc 100644 --- a/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/DocumentTypeRepository.java +++ b/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/DocumentTypeRepository.java @@ -2,6 +2,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.data.jpa.repository.JpaRepository; import ua.pp.fairwind.favorid.internalDB.model.directories.DocumentType; @@ -14,4 +15,5 @@ public interface DocumentTypeRepository extends JpaRepository{ Page findByNameContains(String name, Pageable pager); List findByNameContains(String name); + List findByNameContains(String name,Sort sort); } diff --git a/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/PositionRepository.java b/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/PositionRepository.java index 75d5cc4..2060d1e 100644 --- a/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/PositionRepository.java +++ b/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/PositionRepository.java @@ -2,6 +2,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.data.jpa.repository.JpaRepository; import ua.pp.fairwind.favorid.internalDB.model.directories.Position; @@ -14,4 +15,5 @@ public interface PositionRepository extends JpaRepository{ Page findByNameContains(String name, Pageable pager); List findByNameContains(String name); + List findByNameContains(String name,Sort sort); } diff --git a/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/TaskTypeRepository.java b/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/TaskTypeRepository.java index 15b9e83..098b2e4 100644 --- a/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/TaskTypeRepository.java +++ b/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/TaskTypeRepository.java @@ -2,6 +2,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.data.jpa.repository.JpaRepository; import ua.pp.fairwind.favorid.internalDB.model.directories.TaskType; @@ -14,4 +15,5 @@ public interface TaskTypeRepository extends JpaRepository{ Page findByNameContains(String name, Pageable pager); List findByNameContains(String name); + List findByNameContains(String name,Sort sort); } diff --git a/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/UserRepository.java b/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/UserRepository.java index 8c0ae1c..59b2954 100644 --- a/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/UserRepository.java +++ b/src/main/java/ua/pp/fairwind/favorid/internalDB/repository/UserRepository.java @@ -17,6 +17,7 @@ public interface UserRepository extends JpaRepository{ Page findByUserNameContains(String name, Pageable pager); List findByUserNameContains(String name); + User findByUserName(String userName); //@Query("select r from User u join u.userRoles r where u.userID=:userID") @Query("select r from Role r,User u where u.userID=:userID and (r MEMBER u.userRoles)") Page getUserRoles(@Param("userID")long userId, Pageable pager); diff --git a/src/main/java/ua/pp/fairwind/favorid/internalDB/security/MyUserDetailService.java b/src/main/java/ua/pp/fairwind/favorid/internalDB/security/MyUserDetailService.java new file mode 100644 index 0000000..18c3a3b --- /dev/null +++ b/src/main/java/ua/pp/fairwind/favorid/internalDB/security/MyUserDetailService.java @@ -0,0 +1,40 @@ +package ua.pp.fairwind.favorid.internalDB.security; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; +import ua.pp.fairwind.favorid.internalDB.model.administrative.User; +import ua.pp.fairwind.favorid.internalDB.repository.UserRepository; + +import java.util.logging.Logger; + +/** + * Created by ������ on 04.08.2015. + */ +@Service("myUserDetailsService") +public class MyUserDetailService implements UserDetailsService { + protected static Logger logger = Logger.getLogger("userDetailService"); + @Autowired + UserRepository users; + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + logger.info("Try find user: "+username); + User account= users.findByUserName(username); + + if(account==null){ + logger.info("NO user: "+username); + throw new UsernameNotFoundException("No such user: " + username); + } else { + if(account.getUserRoles().isEmpty()){ + logger.info("NO roles for: "+username); + throw new UsernameNotFoundException("User " + username + " has no authorities"); + } else { + logger.info("user find: "+username + " passowd:"+account.getPasswordHash() ); + return new UserDetailsAdapter(account); + } + } + } +} diff --git a/src/main/java/ua/pp/fairwind/favorid/internalDB/security/UserDetailsAdapter.java b/src/main/java/ua/pp/fairwind/favorid/internalDB/security/UserDetailsAdapter.java new file mode 100644 index 0000000..3066aaa --- /dev/null +++ b/src/main/java/ua/pp/fairwind/favorid/internalDB/security/UserDetailsAdapter.java @@ -0,0 +1,81 @@ +package ua.pp.fairwind.favorid.internalDB.security; + +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import ua.pp.fairwind.favorid.internalDB.model.administrative.User; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Created by ������ on 04.08.2015. + */ +public class UserDetailsAdapter implements UserDetails{ + private User user; + + public UserDetailsAdapter(User user) { + this.user = user; + } + + @Override + public Collection getAuthorities() { + Set authorities = user.getUserRoles().stream().map(r -> new SimpleGrantedAuthority(r.getName())).collect(Collectors.toSet()); + authorities.add(new SimpleGrantedAuthority("ROLE_USER")); + return authorities; + } + + public boolean hasRole(String role) { + Collection authorities = getAuthorities(); + boolean hasRole = false; + for (GrantedAuthority authority : authorities) { + hasRole = authority.getAuthority().equals(role); + if (hasRole) { + break; + } + } + return hasRole; + } + + + @Override + public String getPassword() { + return user.getPasswordHash(); + } + + @Override + public String getUsername() { + return user.getUserName(); + } + + @Override + public boolean isAccountNonExpired() { + return true; + } + + @Override + public boolean isAccountNonLocked() { + return true; + } + + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + @Override + public boolean isEnabled() { + return user.isEnabled(); + } + + + public long getUserId() { + return user.getUserID(); + } + + public User getUserP() { + return user; + } +} diff --git a/src/main/webapp/resources/script/jqgrid/jqgrid-ext.css b/src/main/webapp/resources/script/jqgrid/jqgrid-ext.css new file mode 100644 index 0000000..5973204 --- /dev/null +++ b/src/main/webapp/resources/script/jqgrid/jqgrid-ext.css @@ -0,0 +1,43 @@ +/** +* Nice grid look +*/ +.ui-jqgrid-nice {font-family: tahoma, arial;} +.ui-jqgrid-nice TR.jqgrow TD {font-size: 11px;} +.ui-jqgrid-nice TR.jqgrow TD {padding-left: 5px; padding-right: 5px;} +.ui-jqgrid-nice TR.jqgrow A {color: blue;} + +.ui-jqgrid-nice INPUT, +.ui-jqgrid-nice SELECT, +.ui-jqgrid-nice TEXTAREA, +.ui-jqgrid-nice BUTTON {font-family: tahoma, arial;} + +/** +* Row colors +*/ +.ui-jqgrid .altrow { background: #F4F4F4; } + +.ui-jqgrid .red { background: #FFCCCC; } +.ui-jqgrid .green { background: #CCFFCC; } +.ui-jqgrid .blue { background: #CCCCFF; } +.ui-jqgrid .purple { background: #CCCCFF; } +.ui-jqgrid .yellow { background: #FBEC88; } +.ui-jqgrid .orange { background: #F2CB35; } +.ui-jqgrid .grey { background: #DDDDDD; } + +/** +* Additional highlight styles +*/ +.ui-jqgrid TR.bold TD {font-weight: bold;} +.ui-jqgrid TR.jqgrow TD.bold {font-weight: bold;} + +.ui-jqgrid TR.italic TD {font-style: italic;} +.ui-jqgrid TR.jqgrow TD.italic {font-style: italic;} + +.ui-jqgrid .font-green {color: green;} +.ui-jqgrid .font-red {color: red;} + +/** +* Brighter highlight color +* It must be defined at the bottom to override previous background highlighting +*/ +.ui-jqgrid .ui-state-highlight {background: #FFFFCC;} \ No newline at end of file diff --git a/src/main/webapp/resources/script/jqgrid/jqgrid-ext.js b/src/main/webapp/resources/script/jqgrid/jqgrid-ext.js new file mode 100644 index 0000000..780cadb --- /dev/null +++ b/src/main/webapp/resources/script/jqgrid/jqgrid-ext.js @@ -0,0 +1,523 @@ +//--------------- +// Override some defaults +//--------------- + +$.extend($.jgrid.defaults, +{ + loadComplete : function(data) + { + $.jgrid.ext.errorHandler(data); + } +}); + +//---------------- +// Ext Functions +//--------------- + +$.jgrid.ext = +{ + errorHandler : function(obj) + { + if(obj && obj.error) + { + $.jgrid.info_dialog($.jgrid.errors.errcap,obj.error_msg,$.jgrid.edit.bClose); + } + }, + ajaxFormProxy: function(opts, act) + { + opts.url = $(this).getGridParam('url'); + opts.iframe = true; + + var $form = $('#FrmGrid_' + $(this).getGridParam('id')); + + //use normal ajax-call when no files to upload + if($form.find(':file[value!=""]').size() == 0) + { + $.ajax(opts); + return; + } + + //Prevent non-file inputs double serialization + var ele = $form.find(':input').not(':file'); + + ele.each(function() + { + $(this).data('name', $(this).attr('name')); + $(this).removeAttr('name'); + }); + + //Send only previously generated data + files + $form.ajaxSubmit(opts); + + //Set names back after form being submitted + setTimeout(function() + { + ele.each(function() + { + $(this).attr('name', $(this).data('name')); + }); + }, 200); + } +}; + +//--------------- +// Ext Formatters +//--------------- + +$.extend($.jgrid.formatter, +{ + ext_link : + { + 'href' : '#', + 'class' : '', + 'target': '' + } +}); + +$.extend($.fn.fmatter, +{ + ext_link: function(cellvalue, options, rowdata, act) + { + var def = options.ext_link; + var opt = options.colModel.formatoptions; + + opt = $.extend(null, def, opt); + + //Prevent creating new object every time! + var $grid = (typeof(window['$' + options.gid]) == 'object') ? window['$' + options.gid] : $('#' + options.gid); + + var href = opt.href.replace(/\{(.+?)\}/g, function(arg) + { + var arg = arg.substring(1, arg.length - 1); + + if(act == 'add') + { + return rowdata[$grid.jqGrid('getColIndex', arg)]; + } + else + { + //it is very tricky code here.. + if(typeof(rowdata[arg]) != 'undefined') + { + return rowdata[arg]; + } + else + { + return $grid.jqGrid('getCell', options.rowId, arg); + } + } + }); + + return $.jgrid.format('{3}', href, opt['class'], opt['target'], cellvalue); + } +}); + +//--------------- +// Form edit error handler +//--------------- + +$.extend($.jgrid.edit, +{ + afterSubmit: function(data) + { + var json = $.jgrid.parse(data.responseText); + var new_id = json.new_id || 0; + + if(typeof(json.error_msg) != 'undefined') + { + return [false, json.error_msg, new_id]; + } + + return [true, null, new_id]; + }, + + recreateForm : true +}); + +$.extend($.jgrid.del, +{ + afterSubmit: function(data) + { + var json = $.jgrid.parse(data.responseText); + + if(typeof(json.error_msg) != 'undefined') + { + return [false, json.error_msg, 0]; + } + + return [true, null, 0]; + }, + + recreateForm : true +}); + +//--------------- +// Ext Functions +//--------------- + +$.jgrid.extend( +{ + 'getColIndex' : function(col) + { + var $t = this[0]; + + if(typeof($t.p.colIndex) == 'undefined') + { + $t.p.colIndex = {}; + for(var idx in $t.p.colModel) + { + $t.p.colIndex[$t.p.colModel[idx].name] = idx; + } + } + + return (typeof $t.p.colIndex[col] != 'undefined') ? $t.p.colIndex[col] : -1; + }, + + 'resetColIndex' : function() + { + var $t = this[0]; + $t.p.colIndex = undefined; + }, + + 'extRequest' : function(data, options) + { + + return this.each(function() + { + var $t = this; + var $grid = $(this); + + //----------- + // Settings + //----------- + + var settings = { + 'url' : $grid.getGridParam('url'), + 'selrow' : false, + 'lock' : true, + 'reload' : true, + 'success' : null, + 'error' : null + }; + + $.extend(settings, options); + + //----------- + // Prepare + //----------- + + var postData = {}; + + if(settings.selrow) + { + if($grid.jqGrid('getGridParam', 'multiselect')) + { + postData['id[]'] = $grid.jqGrid('getGridParam', 'selarrrow'); + + if(postData['id[]'].length < 1) + { + $.jgrid.info_dialog($.jgrid.errors.errcap,$.jgrid.errors.norecords,$.jgrid.edit.bClose); + return; + } + } + else + { + postData['id'] = $grid.jqGrid('getGridParam', 'selrow'); + + if(!postData['id']) + { + $.jgrid.info_dialog($.jgrid.errors.errcap,$.jgrid.errors.norecords,$.jgrid.edit.bClose); + return; + } + } + } + + if(settings.lock) + { + $grid.jqGrid('extLoading'); + } + + //----------- + // Request + //----------- + + $.post(settings.url, $.extend(postData, data), function(ret) + { + if(ret.error) + { + if(settings.error) + { + settings.error.call($t, ret); + } + else + { + $.jgrid.ext.errorHandler(ret); + } + } + else if($.isFunction(settings.success)) + { + settings.success.call($t, ret); + } + + if(settings.lock) + { + $grid.jqGrid('extLoading', false); + } + + if(settings.reload) + { + $grid.trigger('reloadGrid'); + } + }, 'json'); + }); + }, + + 'extLoading' : function(state) + { + return this.each(function() + { + var id = $(this).attr('id'); + $("#lui_"+id).toggle(state !== false); + $("#load_"+id).toggle(state !== false); + }); + }, + + 'extHighlight' : function() + { + return this.each(function() + { + var _class = this.p.userData._class; + if(typeof _class != 'object') return; + + var $grid = $(this); + + for(var row_idx in _class) + { + var type = typeof(_class[row_idx]); + + if(type == 'string') + { + $grid.jqGrid('setRowData', row_idx, '', _class[row_idx]); + } + else if(type == 'object') + { + for(var cell_idx in _class[row_idx]) + { + if(cell_idx == '_row') + { + $grid.jqGrid('setRowData', row_idx, '', _class[row_idx][cell_idx]); + } + else + { + $grid.jqGrid('setCell', row_idx, cell_idx, '', _class[row_idx][cell_idx]); + } + } + } + } + }); + }, + + 'extFooterAgg' : function() + { + return this.each(function() + { + var $grid = $(this); + if(typeof $grid.jqGrid('getGridParam', 'userData')['agg'] != 'object') return; + $grid.jqGrid('footerData', 'set', $grid.jqGrid('getGridParam', 'userData')['agg']); + }); + }, + + 'extExport' : function(data, success) + { + return this.each(function(type) + { + $grid = $(this); + + var url = $grid.jqGrid('getGridParam', 'url'); + var postData = $grid.jqGrid('getGridParam', 'postData'); + + var $frame = $(''); + + $frame.load(function() + { + if($.isFunction(success)) + { + success.call($grid); + } + + $grid.jqGrid('extLoading', false); + }); + + if(!$.browser.msie && !$.browser.opera) + { + $grid.jqGrid('extLoading', true); + } + + $('html').append($frame); + }); + }, + + 'extBindEvents' : function() + { + $(this).bind('jqGridGridComplete', function() + { + $(this).jqGrid('extHighlight'); + $(this).jqGrid('extFooterAgg'); + }); + }, + + 'extGroupHeader': function(opts) + { + var $t = this[0]; + + var $labels = $(this).closest('.ui-jqgrid-view').find('.ui-jqgrid-htable .ui-jqgrid-labels'); + var $first_row = $labels.clone().removeClass('ui-jqgrid-labels').removeAttr('role'); + var $group_row = $(''); + + var $th = $('').addClass('ui-state-default ui-th-ltr'); + + var skip = 0; + var free = 0; + + for(var i in $t.p.colModel) + { + if($t.p.colModel[i].hidden) + { + $th.clone().hide().appendTo($group_row); + continue; + } + + if(skip) + { + skip--; + continue; + } + + var idx = $t.p.colModel[i].name; + + if(opts[idx]) + { + if(free) + { + $th.clone().attr('colspan', free).appendTo($group_row); + free = 0; + } + + $th.clone().attr('colspan', opts[idx][0]).text(opts[idx][1]).appendTo($group_row); + skip = opts[idx][0] - 1; + } + else + { + free++; + } + } + + //last free th + if(free) + { + $th.clone().attr('colspan', free).appendTo($group_row); + } + + $first_row.find('TH').height(0).text('').removeAttr('role').removeAttr('id'); + $labels.before($first_row).before($group_row); + + //preserve orig event + if($.isFunction($t.p.resizeStop)) + { + var resizeStop = $t.p.resizeStop; + } + + $t.p.resizeStop = function(nw,idx) + { + $first_row.find('TH').eq(idx).width(nw); + if($.isFunction(resizeStop)) resizeStop.call(this, nw, idx); + }; + }, + + 'updateGroupHeaderWR' : function() + { + return this.each(function() + { + var $t = this; + if(!$t.grid || !$t.p.groupHeaderWR) return; + + var $hDiv = $($t.grid.hDiv); + var $labels = $hDiv.find('.ui-jqgrid-labels'); + + var $first_row = $labels + .clone() + .removeClass('ui-jqgrid-labels') + .removeAttr('role') + .addClass('ui-jqgrid-labels-firstrow'); + + $first_row.find('TH').height(0).text('').removeAttr('role').removeAttr('id'); + + var $group_row = $('').addClass('ui-jqgrid-labels-grouprow'); + + var th = ''; + + //Iterate columns + var colspan = 0; + var prev_hgroup = null; + + for(var i in $t.p.colModel) + { + var col = $t.p.colModel[i]; + var hgroup = col.hgroup ? col.hgroup : ''; + + if(col.hidden) continue; + if(prev_hgroup === null) prev_hgroup = hgroup; //first non-hidden column becomes initial group + + if(prev_hgroup == hgroup) + { + colspan++; + } + else + { + var $th = $(th).attr('colspan', colspan); + if($t.p.groupHeaderWR[prev_hgroup]) $th.text($t.p.groupHeaderWR[prev_hgroup].label); + $th.appendTo($group_row); + + prev_hgroup = hgroup; + colspan = 1; + } + } + + //Last th + if(colspan) + { + var $th = $(th).attr('colspan', colspan); + if($t.p.groupHeaderWR[prev_hgroup]) $th.text($t.p.groupHeaderWR[prev_hgroup].label); + $th.appendTo($group_row); + } + + //Update DOM + $hDiv.find('.ui-jqgrid-labels-firstrow, .ui-jqgrid-labels-grouprow').remove(); + $labels.before($first_row).before($group_row); + + //Preserve orig event + //we have to move it to the core of resizing + if($.isFunction($t.p.resizeStop)) + { + var resizeStop = $t.p.resizeStop; + } + + $t.p.resizeStop = function(nw,idx) + { + $first_row.find('TH').eq(idx).width(nw); + if($.isFunction(resizeStop)) resizeStop.call(this, nw, idx); + }; + }); + }, + + 'destroyGroupHeaderWR' : function() + { + return this.each(function() + { + var $t = this; + if(!$t.grid) return; + + $($t.grid.hDiv).find('.ui-jqgrid-labels-firstrow, .ui-jqgrid-labels-grouprow').remove(); + }); + } +}); \ No newline at end of file