Skip to content

Commit

Permalink
beta release
Browse files Browse the repository at this point in the history
  • Loading branch information
abdo.talaat authored and abdo.talaat committed Jun 24, 2015
1 parent f94aa03 commit 0af7cba
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 7 deletions.
101 changes: 95 additions & 6 deletions src/main/java/com/abdobean/wdcalendar/controller/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(" ");
Expand All @@ -58,22 +57,29 @@ 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);
res = list(showdate, viewtype);

} 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;
Expand Down Expand Up @@ -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\"}";
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/abdobean/wdcalendar/dao/JqCalendarDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
public interface JqCalendarDAO {
public List<Jqcalendar> 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);
}
13 changes: 13 additions & 0 deletions src/main/java/com/abdobean/wdcalendar/dao/JqCalendarDAOImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

}
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/jsp/edit.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
</div>
<div class="infocontainer">
<!-- <form action="php/datafeed.php?method=adddetails><?php echo isset($event)?"&id=".$event->Id:""; ?>" class="fform" id="fmEdit" method="post"> -->
<form action='calendar/rest?method=adddetails<c:if test="${not empty event}"><c:out value="&id=${event.id}"/></c:if>>' class="fform" id="fmEdit" method="post">
<form action='calendar/rest?method=adddetails<c:if test="${not empty event}"><c:out value="&id=${event.id}"/></c:if>' class="fform" id="fmEdit" method="post">
<label>
<span> *Subject:
</span>
Expand Down

0 comments on commit 0af7cba

Please sign in to comment.