Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by mano on Jul 24, 2009 07:11
open dhtmlx forum
Very Urgent----- regarding dhtmlx Scheduler--------

I want to save&delete a new event .just say me which event method is correct .
For Save onEventAdded or onEventChanged
& For Delete onBeforeEventDelete or anything

My problem is Im saving and updating a new event by onEventChanged method & deleting the event by onBeforeEventDelete method.But when i want to save a new event i click the save button it is not saving in my database but after clicking detaiails and then click on save it is saving my record.

In case of delete a saved record is not deleted immediately when i press delete button. If i refresh the page then i see the event is deleted.So i want to clear that saved event immediately when i click on the delete button instead of refresing the page.
I am sending you the source code below...Plese help me immediate..pls ...pls


My Jsp File
----------------
<script type="text/javascript" charset="utf-8">
function RTrim( value ) {
var re = /((\s*\S+)*)\s*/;
return value.replace(re, "$1");
}
function init() {
var aDate='<%=assignDate%>';
scheduler.config.xml_date="%Y-%m-%d %H:%i";        
scheduler.config.date_step = "5"    
if(aDate!=""){
scheduler.init('scheduler_here',aDate,'day');
}else{
scheduler.init('scheduler_here',null,'day');
}
scheduler.load("<bean:message key="ajaxPath"/>/addapointments?empid=<%=empid%>");    
scheduler.attachEvent("onEventChanged", function(event_id,event_object){

var SaveStatus="Save";
var enddate = scheduler.getEvent(event_id).end_date;

var edate=enddate+"";
var endDateYear=enddate.getFullYear()
var endDateMonth=edate.substring(4,7);
var endDateFinal=edate.substring(8,10);
endDateFinal=RTrim(endDateFinal);
var hr=enddate.getHours();
var mm=enddate.getMinutes();
var sec=enddate.getSeconds();

var endDateTime=hr+":"+mm+":"+sec;
var finalEndDate=endDateFinal+"-"+endDateMonth+"-"+endDateYear+" "+endDateTime;

var startdate = scheduler.getEvent(event_id).start_date;

var sdate=startdate+"";
var startDateYear=startdate.getFullYear()
var startDateMonth=sdate.substring(4,7);
var startDateFinal=sdate.substring(8,10);
startDateFinal=RTrim(startDateFinal);
var startDateTime=sdate.substring(10,19);
var hr1=startdate.getHours();
var mm1=startdate.getMinutes();
var sec1=startdate.getSeconds();

var startDateTime=hr1+":"+mm1+":"+sec1;

var finalStartDate=startDateFinal+"-"+startDateMonth+"-"+startDateYear+" "+startDateTime;

var text=scheduler.getEvent(event_id).text;
/*alert(endDateYear);
alert(endDateMonth);
alert(endDateFinal);
alert(endDateTime);
alert(finalEndDate);
alert(finalEndDate.length);

alert(startDateYear);
alert(startDateMonth);
alert(startDateFinal);
alert(startDateTime);
alert(finalStartDate);
alert(finalStartDate.length);
alert(edate);*/

var url="<bean:message key="ajaxPath"/>/saveappointmentdata";
var param = "startDate="+finalStartDate+"&endDate="+finalEndDate+"&text="+text+"&eventId="+event_id+"&status="+SaveStatus+"&empid=<%=empid%>";
loader=dhtmlxAjax.postSync(url,param);


});
scheduler.attachEvent("onBeforeEventDelete", function(event_id,event_object){
var enddate = scheduler.getEvent(event_id).end_date;

var edate=enddate+"";
var endDateYear=enddate.getFullYear()
var endDateMonth=edate.substring(4,7);
var endDateFinal=edate.substring(8,10);
endDateFinal=RTrim(endDateFinal);
var hr=enddate.getHours();
var mm=enddate.getMinutes();
var sec=enddate.getSeconds();
/* if(hr.length!=2){
hr="0"+hr;
}
if(sec.length!=2){
sec="0"+sec;
}*/
var endDateTime=hr+":"+mm+":"+sec;
var finalEndDate=endDateFinal+"-"+endDateMonth+"-"+endDateYear+" "+endDateTime;

var startdate = scheduler.getEvent(event_id).start_date;

var sdate=startdate+"";
var startDateYear=startdate.getFullYear()
var startDateMonth=sdate.substring(4,7);
var startDateFinal=sdate.substring(8,10);
startDateFinal=RTrim(startDateFinal);
var startDateTime=sdate.substring(10,19);
var hr1=startdate.getHours();
var mm1=startdate.getMinutes();
var sec1=startdate.getSeconds();
/*if(hr1.length!=2){
hr1="0"+hr1;
}
if(sec1.length!=2){
sec1="0"+sec1;
}*/
var startDateTime=hr1+":"+mm1+":"+sec1;

var finalStartDate=startDateFinal+"-"+startDateMonth+"-"+startDateYear+" "+startDateTime;

var text=scheduler.getEvent(event_id).text;
var deleteStatus="Delete";
var url="<bean:message key="ajaxPath"/>/saveappointmentdata";
var param = "startDate="+finalStartDate+"&endDate="+finalEndDate+"&text="+text+"&eventId="+event_id+"&status="+deleteStatus+"&empid=<%=empid%>";
loader=dhtmlxAjax.postSync(url,param);
});
}

</script>
</head>    
<body onload="init();">    

==============================================================================

This is my Java Class
--------------------------

public class SaveAppointmentData extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=windows-1252";

DataSource ds = null;
public void init(ServletConfig config) throws ServletException {
try {

InitialContext ctx=new InitialContext();
ds=(DataSource)ctx.lookup(config.getInitParameter("JNDIString"));
} catch (Exception exp) {
exp.printStackTrace();
}
}

public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{response.setContentType(CONTENT_TYPE);
Connection connnection = null;
Statement statement = null;
Statement st1 = null;
boolean cheeckUpdateCase=false;
String inSql="";
response.setContentType(CONTENT_TYPE);
response.setHeader("Cache-Control","no-cache");
PrintWriter out = response.getWriter();
String evId = request.getParameter("eventId");
String sDate = request.getParameter("startDate");
String eDate = request.getParameter("endDate");
String textNote = request.getParameter("text");
String functionStatus = request.getParameter("status");
String empId = request.getParameter("empid");
String detailsNote ="";
String statusNote ="A";

System.out.println("evId"+evId);
System.out.println("sDate"+sDate);
System.out.println("eDate"+eDate);
System.out.println("Inside Ajax"+textNote);


// DateFormat df = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
// Date startDate=null;
// try {
// startDate = (Date)df.parse(sDate);
// } catch (ParseException e) {
// e.printStackTrace();
// }
// Date endDate=null;
// try {
// endDate = (Date)df.parse(eDate);
// } catch (ParseException e) {
// e.printStackTrace();
// }
try {
connnection = ds.getConnection();
st1= connnection.createStatement();
if(functionStatus.equalsIgnoreCase("Save")){
cheeckUpdateCase=updateCase( st1, evId);
if(cheeckUpdateCase==true){
inSql = "UPDATE EMP_APPOINTMENTS SET START_DATE=to_date('"+sDate+"','DD-MON-YYYY HH24:mi:ss'),END_DATE=to_date('"+eDate+"','DD-MON-YYYY HH24:mi:ss'),TEXT='"+textNote+"',DETAILS='"+detailsNote+"',STATUS='"+statusNote+"',EMP_ID='"+empId+"' WHERE EVENT_ID='"+evId+"'";
}else{
inSql = "INSERT INTO EMP_APPOINTMENTS (EVENT_ID,START_DATE,END_DATE,TEXT,DETAILS,STATUS,EMP_ID) values ("+evId+",to_date('"+sDate+"','DD-MON-YYYY HH24:mi:ss'),to_date('"+eDate+"','DD-MON-YYYY HH24:mi:ss'),'"+textNote+"','"+detailsNote+"','"+statusNote+"','"+empId+"')";
}
}
if(functionStatus.equalsIgnoreCase("Delete")){
inSql ="DELETE FROM EMP_APPOINTMENTS WHERE EVENT_ID='"+evId+"'";
}
System.out.println(inSql);
statement= connnection.createStatement();
statement.execute(inSql);

} catch (SQLException sqe) {
sqe.printStackTrace();
} finally {
try {

if (statement != null) {
statement.close();
statement = null;
}
if (connnection != null) {
connnection.close();
connnection = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}

out = response.getWriter();
out.flush();
out.close();
}
public boolean updateCase(Statement st1,String eventId){
ResultSet rs=null;
boolean ret=false;
try {

rs=st1.executeQuery("Select EVENT_ID from EMP_APPOINTMENTS where EVENT_ID='"+eventId+"'");
while(rs.next()){
ret=true;
}
} catch (SQLException sqe) {
sqe.printStackTrace();
}
finally {
try {
if (rs != null) {
rs.close();
rs = null;
}

} catch (SQLException e) {
e.printStackTrace();
}
}
return ret;
}
}
Answer posted on Jul 24, 2009 08:24
>>In case of delete a saved record is not deleted immediately when i press delete button
add return true; to the end of onbeforeeventdelete event


scheduler.attachEvent("onBeforeEventDelete", function(event_id,event_object){
 ... any custom code ... 
  return true;
}); 
 
>>but after clicking detaiails and then click on save it is saving my record. 
OnEventChanged event occurs after event was edited ( by direct edit or by details form ) event doesn't occurs if some property of event was changed directly through API