/* Author : Vipul Limbachiya FileName : jQuery.presentation Reqires : jQuery.js,jQuery.init.js,jQuery-ui-personalized-1.5.2.js */ function Elem(elemId){return document.getElementById(elemId);} jQuery.preloadImages = function() { for(var i = 0; i").attr("src", arguments[i]); } } // Properties for handler classes and ID so later on we can change if required var Properties = { currentDayBoxClass: ".calDayCur", calendarBoxId: "#clndrEvent", eventContainerBoxId: "#events", eventBoxClass: ".calEvent", eventBoxClassOnDrag: ".calEventDrag" }; // This class manages all AJAX requests and response, its integrated with Presentation class var EventCallBack= { // This method is being called on drop of event box on day, // Calls async page and retrives details of selected template and date. // And generates form of event using presentation class retriveEventTemplateDetais : function(eventBoxId,templateId,selDate) { Presentation.appendMessage(eventBoxId, "Wait..."); $.ajax({type:"POST", url: "asyncHandler/handlerEvents.ashx", data: "act=getEventTemplateDetails&tempId=" + templateId + "&selDate=" + selDate, success:function(serverResponseData) { EventCallBack.retriveEventTemplateDetaisSuccess(serverResponseData,selDate,eventBoxId); }, error: function(reqObject,typeofError,exceptionObj) { EventCallBack.retriveEventTemplateDetaisFailure(eventBoxId); }, complete: function() { Presentation.removeMessage(eventBoxId); } }); }, // Being called on success of method : retriveEventTemplateDetais retriveEventTemplateDetaisSuccess:function(responseText,selDate,eventBoxId) { Presentation.refreshEventPanel(); data = eval("(" + responseText + ")"); if(parseInt(data.response.error)===0) { Presentation.generateMyReminderPanel(data.response.table, selDate, eventBoxId); } else { Presentation.alertMessage(data.response.message); Presentation.resetEventBoxIdPosition(eventBoxId,""); } }, // Being called on failure of method : retriveEventTemplateDetais retriveEventTemplateDetaisFailure:function(eventBoxId) { Presentation.alertMessage("Error occored while processing request on server!"); Presentation.resetEventBoxIdPosition(eventBoxId,""); }, // Submits selected option and data of event form submitEventData : function(eventBoxId) { if($("#myReminderPanel_isActive").val()=="yes") { Presentation.appendMessage("myReminderFormPanel", "Please Wait..."); var frequencyOption = ""; $("#myReminderPanel_EventFreq_Panel > select option:selected").each(function () { if(frequencyOption.length>0) { frequencyOption += $(this).text() + ","; } else { frequencyOption = $(this).text(); } }); var reminderOption = ""; $("#myReminderPanel_EventReminder_Panel > select option:selected").each(function () { if(reminderOption.length>0) { reminderOption += $(this).text() + ","; } else { reminderOption = $(this).text(); } }); var SelectedDate = $("#myReminderPanel_EventDate").val(); var disableEmailReminder = false; if(Elem("myReminderPanel_EventDisableEmailReminder")) { disableEmailReminder = Elem("myReminderPanel_EventDisableEmailReminder").checked; } var disableSMSReminder = false; if(Elem("myReminderPanel_EventDisableSMSReminder")) { disableSMSReminder = Elem("myReminderPanel_EventDisableSMSReminder").checked; } $.ajax({type:"POST", url: "asyncHandler/handlerEvents.ashx", data: "act=add" + "&tempId=" + $("#myReminderPanel_EventTemplateId").val() + "&eventTitle=" + $("#myReminderPanel_EventTitle").val() + "&eventDate=" + SelectedDate + "&eventFreq=" + frequencyOption + "&eventReminder=" + reminderOption + "&disableEmailReminder=" + disableEmailReminder + "&disableSMSReminder=" + disableSMSReminder + "&eventAltEmail=" + $("#myReminderPanel_EventAltEmail").val() + "&eventAltMobile=" + $("#myReminderPanel_EventAltMobile").val(), success:function(serverResponseData) { EventCallBack.submitEventDataSuccess(serverResponseData,SelectedDate); }, error: function(reqObject,typeofError,exceptionObj) { EventCallBack.submitEventDataFailure(SelectedDate); }, complete: function() { Presentation.removeMessage("myReminderFormPanel"); } }); } }, // Being called on success of method : submitEventData submitEventDataSuccess:function(responseText,selDate) { data = eval("(" + responseText + ")"); if(data.response.error==0) { var newEventId = data.response.newEvent[0].event_id; var strEventBoxId = Presentation.currentEventBoxId(); Presentation.resetEventBoxIdPosition(strEventBoxId,selDate); var eventElem = $("#"+strEventBoxId); eventElem.effect("highlight", {}, 2000); eventElem.removeAttr("id"); eventElem.attr("id","UserEvent_"+newEventId); Presentation.alertMessage(data.response.message); } else { Presentation.alertMessage(data.response.message); Presentation.resetEventBoxIdPosition(Presentation.currentEventBoxId(),""); } Presentation.showHideMyReminderPanel(false); }, // Being called on failure of method : submitEventData submitEventDataFailure:function() { Presentation.alertMessage("Error Occured!"); Presentation.resetEventBoxIdPosition(Presentation.currentEventBoxId(),""); }, // Retrive event data async call retriveEventDetails: function(eventBoxId,eventId,selDate) { Presentation.appendMessage(eventBoxId, "Wait..."); $.ajax({type:"POST", url: "asyncHandler/handlerEvents.ashx", data: "act=getEventDetails&eventId=" + eventId, success:function(serverResponseData) { EventCallBack.retriveEventDetailsSuccess(serverResponseData,selDate,eventBoxId); }, error: function(reqObject,typeofError,exceptionObj) { EventCallBack.retriveEventDetailsFailure(eventBoxId); }, complete: function() { Presentation.removeMessage(eventBoxId); } }); }, // Being called on success of method : retriveEventDetails retriveEventDetailsSuccess:function(responseText,selDate,eventBoxId) { data = eval("(" + responseText + ")"); if(data.response.error==0) { Presentation.generateMyReminderPanelForEdit(data.response.table, selDate, eventBoxId); } else { Presentation.showHideMyReminderPanel(false); Presentation.alertMessage(data.response.message); var selDate = $("#"+eventBoxId).attr("currentdate") || ""; Presentation.resetEventBoxIdPosition(eventBoxId,selDate); } }, // Being called on failure of method : retriveEventDetails retriveEventDetailsFailure:function(eventBoxId) { Presentation.alertMessage("Error occored while processing request on server!"); }, // Update event async call updateEvent: function(eventBoxId,templateId,selDate) { if($("#myReminderPanel_isActive").val()=="yes") { Presentation.appendMessage("myReminderFormPanel", "Please Wait..."); var frequencyOption = ""; $("#myReminderPanel_EventFreq_Panel > select option:selected").each(function () { if(frequencyOption.length>0) { frequencyOption += $(this).text() + ","; } else { frequencyOption = $(this).text(); } }); var reminderOption = ""; $("#myReminderPanel_EventReminder_Panel > select option:selected").each(function () { if(reminderOption.length>0) { reminderOption += $(this).text() + ","; } else { reminderOption = $(this).text(); } }); var SelectedDate = $("#myReminderPanel_EventDate").val(); var disableEmailReminder = false; if(Elem("myReminderPanel_EventDisableEmailReminder")) { disableEmailReminder = Elem("myReminderPanel_EventDisableEmailReminder").checked; } var disableSMSReminder = false; if(Elem("myReminderPanel_EventDisableSMSReminder")) { disableSMSReminder = Elem("myReminderPanel_EventDisableSMSReminder").checked; } $.ajax({type:"POST", url: "asyncHandler/handlerEvents.ashx", data: "act=updateEvent" + "&eventId=" + $("#myReminderPanel_EditEventId").val() + "&tempId=" + $("#myReminderPanel_EventTemplateId").val() + "&eventTitle=" + $("#myReminderPanel_EventTitle").val() + "&eventDate=" + SelectedDate + "&eventFreq=" + frequencyOption + "&eventReminder=" + reminderOption + "&disableEmailReminder=" + disableEmailReminder + "&disableSMSReminder=" + disableSMSReminder + "&eventAltEmail=" + $("#myReminderPanel_EventAltEmail").val() + "&eventAltMobile=" + $("#myReminderPanel_EventAltMobile").val(), success:function(serverResponseData) { EventCallBack.updateEventSuccess(serverResponseData,SelectedDate,eventBoxId); }, error: function(reqObject,typeofError,exceptionObj) { EventCallBack.updateEventFailure(eventBoxId); }, complete: function() { Presentation.removeMessage("myReminderFormPanel"); } }); } }, // Being called on success of method : updateEvent updateEventSuccess:function(responseText,selDate,eventBoxId) { data = eval("(" + responseText + ")"); var strEventBoxId = Presentation.currentEventBoxId(); if(data.response.error==0) { $("#"+strEventBoxId).attr("currentdate",selDate); Presentation.resetEventBoxIdPosition(strEventBoxId,selDate); $("#"+strEventBoxId).effect("highlight", {}, 2000); Presentation.alertMessage(data.response.message); } else { Presentation.alertMessage(data.response.message); var boxselDate = $("#"+strEventBoxId).attr("currentdate") || ""; Presentation.resetEventBoxIdPosition(strEventBoxId,boxselDate); } Presentation.showHideMyReminderPanel(false); }, // Being called on failure of method : updateEvent updateEventFailure:function(eventBoxId) { Presentation.alertMessage("Error Occured!"); var selDate = $("#"+eventBoxId).attr("currentdate") || ""; Presentation.resetEventBoxIdPosition(eventBoxId,selDate); } } // This class manages presentation of calendar. // Drag drop and initilization of dragdrop is handled by init function var Presentation = { // Initializes events and drag drop init:function() { $.preloadImages("Images/throbber.gif"); Presentation.initDragDrop(); $("#myReminderPanel_Close").bind("click", Presentation.cancleAction); $("#eventCalendar").after(""); $(".calEvent").bind("click", function(){ if($(this).attr("currentdate")) { if($("#myReminderPanel_isActive").val()!="yes") { Presentation.onDropFunction(this.id, "dv"+$(this).attr("currentdate"), true); } } }); }, alertMessage:function(msg) { var alertMessageDiv=$("#alertMessage"); if(alertMessageDiv) { alertMessageDiv.text(msg); } alertMessageDiv.fadeIn(1000).fadeOut(3000) }, refreshEventBox:function(idOfDroppedElement) { var eventBoxId = Presentation.currentEventBoxId(); if(eventBoxId!="" && eventBoxId!=idOfDroppedElement) { if(Presentation.isEditEvent()) { var selDate = $("#"+eventBoxId).attr("currentdate"); Presentation.resetEventBoxIdPosition(eventBoxId, selDate); } else { Presentation.resetEventBoxIdPosition(eventBoxId, ""); } } }, cancleAction: function() { Presentation.refreshEventBox(); Presentation.refreshEventPanel(); Presentation.showHideMyReminderPanel(false); }, // Fuction being called on drop of event box onDropFunction:function(droppedElement,idOfDateElement,flag) { var idOfDroppedElement = ""; if(flag) { idOfDroppedElement = droppedElement; } else { idOfDroppedElement = droppedElement[0].id; } //Not required, because drag is disabled when add/edit form is open //Presentation.refreshEventBox(idOfDroppedElement); if ("#"+idOfDateElement != Properties.eventContainerBoxId) { if(idOfDroppedElement.indexOf('EventTemplateId_')>=0) // Add event { EventCallBack.retriveEventTemplateDetais(idOfDroppedElement, idOfDroppedElement.replace('EventTemplateId_',''), idOfDateElement.replace('dv','')); Presentation.refreshEventPanel(); } else // Edit Event { EventCallBack.retriveEventDetails(idOfDroppedElement, idOfDroppedElement.replace('UserEvent_',''), idOfDateElement.replace('dv','')); } } else { Presentation.showHideMyReminderPanel(false); } }, // Init funciton for dragdrop initDragDrop: function() { $(Properties.currentDayBoxClass).droppable({ accept: Properties.eventBoxClass, drop: function(ev, ui) { $(this).append($(ui.draggable)); Presentation.onDropFunction($(ui.draggable),this.id); } }); $(Properties.eventContainerBoxId).droppable({ accept: Properties.eventBoxClass, drop: function(ev, ui) { $(this).append($(ui.draggable)); Presentation.onDropFunction($(ui.draggable),this.id); } }); $(Properties.eventBoxClass).draggable({ helper:'clone', opacity:0.5 }); }, // Removes previously created message box removeMessage: function(targetElementId,postfix) { postfix = postfix || "msg"; $("#"+targetElementId+"_" + postfix).remove(); }, // Appends message box to given element by id and with options appendMessage: function(targetElementId,text,msgDivPostfix,containerClass,messageElementClass) { msgDivPostfix = msgDivPostfix || "msg"; containerClass = containerClass || "loaderContainer"; messageElementClass = messageElementClass || "waitMessage"; if($("#"+targetElementId+"_"+msgDivPostfix).length>0) { Presentation.removeMessage(targetElementId, msgDivPostfix); } $("#"+targetElementId).prepend("
"+text+"
"); }, // Refreshes event panle, to check whether more events available or not refreshEventPanel:function() { if($("#events div").length==0) { if($("#dvNoEventAvailableMessage").length==0) { $("#events").append("
No more events available
") } } else { $("#dvNoEventAvailableMessage").remove(); } }, // Sets visibility of event form showHideMyReminderPanel :function(show) { if(show) { $("#myReminderPanel").show(); $("#myReminderPanel_isActive").val("yes"); $(Properties.eventBoxClass).draggable("disable"); $(Properties.eventBoxClass).css({cursor:"text"}); } else { $("#myReminderPanel").hide(); $("#myReminderPanel_isActive").val("no"); $(Properties.eventBoxClass).draggable("enable"); $(Properties.eventBoxClass).css({cursor:"move"}); } }, // Generates Event's form using json data retrived from server generateMyReminderPanel :function(templateData,dateOfEvent,eventBoxId) { if(templateData) { if(templateData.length>0) { var currentTemplate = templateData[0]; Presentation.showHideMyReminderPanel(true); Presentation.switchSubmitButtonActionForEdit(false); $("#myReminderPanel_Header").html("Event details"); $("#myReminderPanel_Submit").val("Save"); Presentation.currentEventBoxId(eventBoxId); $("#myReminderPanel_EventDate").val(dateOfEvent); $("#myReminderPanel_EventFreq").val(currentTemplate.event_template_frequency); $("#myReminderPanel_EventReminder").val(currentTemplate.event_template_reminder); $("#myReminderPanel_EventFreq_Panel > select option:first-child").attr("selected","true"); $("#myReminderPanel_EventReminder_Panel > select option:first-child").attr("selected","true"); if(Elem("myReminderPanel_EventDisableEmailReminder")) { Elem("myReminderPanel_EventDisableEmailReminder").checked=(currentTemplate.event_template_email=="y"); } if(Elem("myReminderPanel_EventDisableSMSReminder")) { Elem("myReminderPanel_EventDisableSMSReminder").checked=(currentTemplate.event_template_sms=="y"); } $("#myReminderPanel_EventTitle").val(currentTemplate.event_template_name); $("#myReminderPanel_EventTemplateId").val(currentTemplate.event_template_id); if(currentTemplate.event_template_account_def_time!="y") { $("#myReminderPanel_EventReminder_Panel").hide(); } else { $("#myReminderPanel_EventReminder_Panel").show(); } if(currentTemplate.event_template_email!="y") { $("#myReminderPanel_EventDisableEmailReminder_Panel").hide(); } else { $("#myReminderPanel_EventDisableEmailReminder_Panel").show(); } if(currentTemplate.event_template_sms!="y") { $("#myReminderPanel_EventDisableSMSReminder_Panel").hide(); } else { $("#myReminderPanel_EventDisableSMSReminder_Panel").show(); } if(currentTemplate.event_template_alt_email!="y") { $("#myReminderPanel_EventAltEmail_Panel").hide(); } else { $("myReminderPanel_EventAltEmail_Panel").show(); } if(currentTemplate.event_template_alt_mobile!="y") { $("#myReminderPanel_EventAltMobile_Panel").hide(); } else { $("#myReminderPanel_EventAltMobile_Panel").show(); } $("#myReminderPanel_EventTitle").focus(); } } }, isEditEvent:function() { return $("#myReminderPanel_EditEventId").val()!=""; }, currentEventBoxId:function(value) { if(value) { $("#myReminderPanel_currentEventBoxId").val(value); } return $("#myReminderPanel_currentEventBoxId").val(); }, switchSubmitButtonActionForEdit:function(flag,eventId) { eventId = eventId || ""; $("#myReminderPanel_Submit").unbind("click", EventCallBack.updateEvent); $("#myReminderPanel_Submit").unbind("click", EventCallBack.submitEventData); $("#myReminderPanel_EditEventId").val(eventId); if(flag) { $("#myReminderPanel_EventDate_Panel_Edit").show(); $("#myReminderPanel_Submit").bind("click", EventCallBack.updateEvent); } else { $("#myReminderPanel_EventDate_Panel_Edit").hide(); $("#myReminderPanel_Submit").bind("click", EventCallBack.submitEventData); } }, // Generates Event's form for edit using json data retrived from server generateMyReminderPanelForEdit : function(eventData,dateOfEvent,eventBoxId) { if(eventData) { if(eventData.length>0) { var currentEvent = eventData[0]; Presentation.showHideMyReminderPanel(true); Presentation.switchSubmitButtonActionForEdit(true, eventBoxId.replace('UserEvent_','')); $("#myReminderPanel_Header").html("Edit Event details"); $("#myReminderPanel_Submit").val("Update"); Presentation.currentEventBoxId(eventBoxId); $("#myReminderPanel_EventDate").val(dateOfEvent); $("#myReminderPanel_EventDateEdit").html(currentEvent.converteddate); $("#myReminderPanel_EventFreq").val(currentEvent.event_frequency); $("#myReminderPanel_EventReminder").val(currentEvent.event_reminder); $("#myReminderPanel_EventFreq_Panel > select option").each(function(){ if($(this).attr("value")==currentEvent.event_frequency) { $(this).attr("selected","true"); } }); $("#myReminderPanel_EventReminder_Panel > select option").each(function(){ if($(this).attr("value")==currentEvent.event_reminder) { $(this).attr("selected","true"); } }); if(Elem("myReminderPanel_EventDisableEmailReminder")) { Elem("myReminderPanel_EventDisableEmailReminder").checked=(currentEvent.event_email=="y"); } if(Elem("myReminderPanel_EventDisableSMSReminder")) { Elem("myReminderPanel_EventDisableSMSReminder").checked=(currentEvent.event_sms=="y"); } $("#myReminderPanel_EventTitle").val(currentEvent.event_title); $("#myReminderPanel_EventTemplateId").val(currentEvent.event_template_id); $("#myReminderPanel_EventTitle").focus(); $("#myReminderPanel_EventReminder_Panel").show(); $("#myReminderPanel_EventDisableEmailReminder_Panel").show(); $("#myReminderPanel_EventDisableSMSReminder_Panel").show(); $("#myReminderPanel_EventAltEmail_Panel").show(); $("#myReminderPanel_EventAltMobile_Panel").show(); } } }, resetEventBoxIdPosition:function(eventBoxId,selDate) { if(selDate=="") { if(Elem(eventBoxId)) { var selDate = $("#"+eventBoxId).attr("currentdate") || ""; if(selDate.length==0) { Elem("events").appendChild(Elem(eventBoxId)); Presentation.currentEventBoxId(""); $("#myReminderPanel_EditEventId").val(""); } } } else { var currentDateId = $("#"+eventBoxId).parent().get(0).id; if(currentDateId != "dv" + selDate) { if(Elem("dv" + selDate)) { if(Elem(eventBoxId)) { Elem("dv" + selDate).appendChild(Elem(eventBoxId)); Presentation.currentEventBoxId(""); $("#myReminderPanel_EditEventId").val(""); } } else { if(selDate==undefined) { Presentation.alertMessage("error occured, Selected date not valid") } else { Presentation.alertMessage("Event is saved. Date selected is not in current month so it will not be visible") Elem(eventBoxId).parentNode.removeChild(Elem(eventBoxId)); } } } } } }