diff --git a/src/main/java/com/abdobean/wdcalendar/controller/HomeController.java b/src/main/java/com/abdobean/wdcalendar/controller/HomeController.java index f4ed62d..5954731 100644 --- a/src/main/java/com/abdobean/wdcalendar/controller/HomeController.java +++ b/src/main/java/com/abdobean/wdcalendar/controller/HomeController.java @@ -40,14 +40,13 @@ public ModelAndView home() { model.addObject("userList", listUsers); return model; } - + @RequestMapping(value = "/edit") public ModelAndView edit() { ModelAndView model = new ModelAndView("edit"); String id = context.getParameter("id"); - if(id != null) - { - Jqcalendar jqcalendar= jqCalendarDAO.getcalendar(Integer.parseInt(id)); + if (id != null) { + Jqcalendar jqcalendar = jqCalendarDAO.getcalendar(Integer.parseInt(id)); String startDateTime = utilities.convertDateTimeToJS(jqcalendar.getStartTime()); String endDateTime = utilities.convertDateTimeToJS(jqcalendar.getEndTime()); String[] stDT = startDateTime.split(" "); @@ -58,15 +57,16 @@ public ModelAndView edit() { model.addObject("etpartdate", edDT[0]); model.addObject("etparttime", edDT[1]); } - + return model; } - @RequestMapping(value = "/calendar/rest", method = RequestMethod.POST) public @ResponseBody String getShopInJSON(@RequestParam("method") String method, @RequestParam(value = "showdate", required = false) String showdate, @RequestParam(value = "viewtype", required = false) String viewtype) { String res = ""; + + System.out.println(method); if (method.equals("list")) { System.out.println(showdate); System.out.println(viewtype); @@ -74,6 +74,12 @@ String getShopInJSON(@RequestParam("method") String method, @RequestParam(value } else if (method.equals("add")) { res = addCalendar(); + } else if (method.equals("adddetails")) { + res = addDetails(); + } else if (method.equals("update")) { + res = update(); + } else if (method.equals("remove")) { + res = remove(); } return res; @@ -120,4 +126,87 @@ public String addCalendar() { return "{\"IsSuccess\":true,\"Msg\":\"add faild\""; } } + + public String addDetails() { + String stpartdate = context.getParameter("stpartdate"); + String stparttime = context.getParameter("stparttime"); + String etpartdate = context.getParameter("etpartdate"); + String etparttime = context.getParameter("etparttime"); + + String start = stpartdate + " " + stparttime; + String end = etpartdate + " " + etparttime; + + + String IsAllDayEvent = context.getParameter("IsAllDayEvent"); + String CalendarTitle = context.getParameter("Subject"); + String Description = context.getParameter("Description"); + String Location = context.getParameter("Location"); + String colorvalue = context.getParameter("colorvalue"); + String timezone = context.getParameter("timezone"); + + + Jqcalendar jqcalendar = new Jqcalendar(); + jqcalendar.setColor(colorvalue); + jqcalendar.setDescription(Description); + jqcalendar.setEndTime(utilities.getdateDateTime(end)); + jqcalendar.setStartTime(utilities.getdateDateTime(start)); + if (IsAllDayEvent != null) { + jqcalendar.setIsAllDayEvent(new Short("1")); + } else { + jqcalendar.setIsAllDayEvent(new Short("0")); + } + + jqcalendar.setLocation(Location); + jqcalendar.setSubject(CalendarTitle); + + + + + int ids = 0; + + String id = context.getParameter("id"); + if (id != null) { + jqcalendar.setId(Integer.parseInt(id)); + ids = jqCalendarDAO.update(jqcalendar); + } else { + ids = jqCalendarDAO.add(jqcalendar); + } + + + if (ids > 0) { + return "{\"IsSuccess\":true,\"Msg\":\"add success\",\"Data\":" + id + "}"; + } else { + return "{\"IsSuccess\":true,\"Msg\":\"add faild\""; + } + + } + + public String update() { + + String calendarId = context.getParameter("calendarId"); + String CalendarStartTime = context.getParameter("CalendarStartTime"); + String CalendarEndTime = context.getParameter("CalendarEndTime"); + + int idCal = Integer.parseInt(calendarId); + Jqcalendar jqcalendar = jqCalendarDAO.getcalendar(idCal); + jqcalendar.setId(idCal); + jqcalendar.setStartTime(utilities.getdateDateTime(CalendarStartTime)); + jqcalendar.setEndTime(utilities.getdateDateTime(CalendarEndTime)); + + int id = jqCalendarDAO.update(jqcalendar); + + if (id > 0) { + return "{\"IsSuccess\":true,\"Msg\":\"add success\",\"Data\":" + id + "}"; + } else { + return "{\"IsSuccess\":true,\"Msg\":\"add faild\""; + } + + + } + + public String remove() { + String calendarId = context.getParameter("calendarId"); + jqCalendarDAO.remove(Integer.parseInt(calendarId)); + return "{\"IsSuccess\":true,\"Msg\":\"add success\"}"; + } } diff --git a/src/main/java/com/abdobean/wdcalendar/dao/JqCalendarDAO.java b/src/main/java/com/abdobean/wdcalendar/dao/JqCalendarDAO.java index f5d4a8a..9a7e030 100644 --- a/src/main/java/com/abdobean/wdcalendar/dao/JqCalendarDAO.java +++ b/src/main/java/com/abdobean/wdcalendar/dao/JqCalendarDAO.java @@ -7,5 +7,7 @@ public interface JqCalendarDAO { public List list(DateTime start,DateTime end); public int add(Jqcalendar jqcalendar); + public int update(Jqcalendar jqcalendar); public Jqcalendar getcalendar(int id); + public void remove(int id); } diff --git a/src/main/java/com/abdobean/wdcalendar/dao/JqCalendarDAOImpl.java b/src/main/java/com/abdobean/wdcalendar/dao/JqCalendarDAOImpl.java index 86eafa8..7440f40 100644 --- a/src/main/java/com/abdobean/wdcalendar/dao/JqCalendarDAOImpl.java +++ b/src/main/java/com/abdobean/wdcalendar/dao/JqCalendarDAOImpl.java @@ -7,6 +7,7 @@ import org.hibernate.Criteria; +import org.hibernate.Query; import org.hibernate.SessionFactory; import org.hibernate.criterion.Restrictions; import org.joda.time.DateTime; @@ -47,4 +48,16 @@ public Jqcalendar getcalendar(int id) { return jqcalendar; } + @Transactional + public int update(Jqcalendar jqcalendar) { + sessionFactory.getCurrentSession().saveOrUpdate(jqcalendar); + return jqcalendar.getId(); + } + + @Transactional + public void remove(int id) { + Query query = sessionFactory.getCurrentSession().createQuery("delete from Jqcalendar where id="+id+""); + query.executeUpdate(); + } + } diff --git a/src/main/webapp/WEB-INF/jsp/edit.jsp b/src/main/webapp/WEB-INF/jsp/edit.jsp index 6761d79..65d926c 100644 --- a/src/main/webapp/WEB-INF/jsp/edit.jsp +++ b/src/main/webapp/WEB-INF/jsp/edit.jsp @@ -196,7 +196,7 @@
-
+