Fullcalendar scrolls to top when start dragging - php

When I start to dragging an event, always scrolls to top of the day (timeGridDay). If I drag and drop when I see, p.e. from 00:00 to 08:00 is ok, but I if I try to drag an event that's at 17:00 then automitically moves to 00:00 -- 08:00 area on the top..
I have another calendar that's working fine... I've compared and it's all the same I think..
Thanks for your help.
var doubleClick = false;
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source',
height: '700',
plugins: [ 'timeGrid','dayGrid' ,'resourceTimeGrid','interaction'],
titleFormat: {
year: 'numeric',
month: 'numeric',
day: 'numeric'
},
defaultView: 'timeGridDay',
locale: lan,
minTime: '00:00:00',
maxTime: '23:59:00',
allDaySlot: false,
editable: true,
selectable: true,
select: function(info)
{
$('#newEventForm').trigger('reset');
cadenaStr = info.startStr;
cadenaEnd = info.endStr;
datavisita = cadenaStr.substr(0,10);
horainici = cadenaStr.substr(11,8);
horafi = cadenaEnd.substr(11,8);
$('#horastart').val(horainici);
$('#horaend').val(horafi);
$('#data').val(datavisita);
$('#newEventModal').modal('show');
},
droppable: true,
dragScroll: true,
eventResourceEditable: true,
header: {
left: 'prev,next, addEventButton, addReserveButton',
center: 'title',
// right: 'resourceTimeGrid,dayGridMonth,timeGridWeek,timeGridDay'
right: ''
},
views: {
resourceTimeGrid: { buttonText: resbtnname },
//dayGridMonth: { buttonText: 'month' },
//dayGridWeek: { buttonText: 'week' },
//dayGridDay: { buttonText: 'day' }
},
timeZone: 'local',
customButtons: {
addEventButton: {
text: '+',
click: function() {
$('#newEventForm').trigger("reset");
//alert ("passo abans client");
//$('#client').val('').trigger('change');
//$('#pacient').val("");
$('#newEventModal').modal('show');
}
},
addReserveButton: {
text: '||',
click: function() {
$('#newReserveModal').modal('show');
$('#newReserveForm').trigger('reset');
}
}
},
// title: info.event.extendedProps.pacientnom+': '+info.event.extendedProps.description,
// tootlip show up on event mouse hover
dayClick: function(date, jsEvent, view) {
if(!doubleClick) {
doubleClick = true;
setTimeout(function() { doubleClick = false; }, 500); //this waits for a second click for the next 500ms
}
else {
alert ("doble cliiiiikkkk");
//do your double click action here (date and time available in date variable)
}
},
eventRender: function(info) {
var tooltip = new Tooltip(info.el, {
title: info.event.extendedProps.description,
placement: 'top',
trigger: 'hover',
container: 'body'
});
$(info.el).on("mousedown", function(){
tooltip.hide();
});
$(info.el).on("mouseup", function(){
tooltip.hide();
});
$(info.el).on("click", function(){
tooltip.hide();
});
},
// edit form modal show up on event click
eventClick: function(info) {
$('#editsala').empty();
$('#editpacient').empty();
var idvisita = info.event.id;
$('#idvisitaorg').val(idvisita);
$('#visitaForm').submit();
},
// drag and drop event with database records change
eventDrop: function( info ) {
$('.tooltip').hide();
//if (!confirm("Are you sure about this change?")) {
//
// info.revert();
//} else {
var id = info.event.id;
var title = info.event.title;
var timeSettings = { "hour": "2-digit", "minute": "2-digit", "hour12": false };
var starttime = calendar.formatDate(info.event.start, timeSettings);
var endtime = calendar.formatDate(info.event.end, timeSettings);
var startdate =moment(info.event.start).format('YYYY-MM-DD');
if(info.newResource) {
var resourceId = info.newResource.id;
} else {
if(info.oldEvent.extendedProps.Resource_Id){
var resourceId = info.oldEvent.extendedProps.Resource_Id;
} else {
var resourceId =0;
}
}
$.ajax({
url: "calvis_event_dropped_update.php",
type: "POST",
data: ({
id: id,
title: title,
starttime: starttime,
endtime: endtime,
startdate: startdate,
resourceId: resourceId
}),
success: function(data){
calendar.refetchEvents()
},
error: function() {
info.revert();
}
});
//}
},
// resize event with database records change
eventResize: function( info ) {
$('.tooltip').hide();
//if (!confirm("Are you sure about this change?")) {
// info.revert();
//} else {
var id = info.event.id;
var title = info.event.title;
var timeSettings = { "hour": "2-digit", "minute": "2-digit", "hour12": false };
var starttime = calendar.formatDate(info.event.start, timeSettings);
var startdate = moment(info.event.start).format('YYYY-MM-DD');
var endtime = calendar.formatDate(info.event.end, timeSettings);
var resourceId=info.event.extendedProps.Resource_Id;
//console.log(starttime);
//console.log(endtime);
// console.log(info.event.extendedProps.Resource_Id);
$.ajax({
url: "calvis_event_dropped_update.php",
type: "POST",
data: ({
id: id,
title: title,
starttime: starttime,
endtime: endtime,
startdate: startdate,
resourceId: resourceId
}),
success: function(data){
calendar.refetchEvents()
},
error: function() {
info.revert();
}
});
//}
},
//hide select resource for other views
viewSkeletonRender: function(info){
if(info.view.type=="resourceTimeGrid"){
$("#resource_select_div").show();
$("#filter_events_div").hide();
$('#usuario_filter').val('none');
calendar.refetchEvents();
} else{
$("#resource_select_div").hide();
$("#filter_events_div").show();
}
},
// generate events
eventSources: [
{
url: 'calvis_get_events_caltask.php',
method: 'POST',
extraParams: function() {
return {
idusuario: $('#usuario_filter').val()
};
},
failure: function() {
alert('there was an error while fetching events!');
}
}
// any other sources...
],
// generate resources
resources: 'calvis_get_resources.php',
});
//render calendar
calendar.render();

Related

How to use jQuery Ajax to fetch the data from MS-SQl database?

I'm developing an Event Calendar in PHP, saving the data in MS-SQL.
I was successful in sending the data to the database, however, I'm not able to fetch the data from it.
Here's what I've done so far:
$(document).ready(function() {
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
navLinks: true, // can click day/week names to navigate views
editable: true,
eventLimit: true,
events: "all_events.php",
displayEventTime: false,
eventRender: function(event, element, view) {
if (event.allDay === 'true') {
event.allDay = true;
} else {
event.allDay = false;
}
},
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
var title = prompt('Event Detail:');
if (title) {
var start = $.fullCalendar.formatDate(start, "Y-MM-DD HH:mm:ss");
var end = $.fullCalendar.formatDate(end, "Y-MM-DD HH:mm:ss");
$.ajax({
url: 'add_event.php',
data: 'title=' + title + '&start=' + start + '&end=' + end,
type: "POST",
success: function(data) {
displayMessage("Added Successfully");
}
});
calendar.fullCalendar('renderEvent', {
title: title,
start: start,
end: end,
allDay: allDay
}, true);
}
calendar.fullCalendar('unselect');
}
});
});
all_events.php
<?php
require_once("connection.php");
$conn = DB::databaseConnection();
$json = array();
$sql = "SELECT * FROM Events ORDER BY id";
$result = $conn->prepare($sql);
$result->bindParam(':id', $id);
$alldata = array();
while($row = $result->fetch(PDO::FETCH_ASSOC))
{
array_push($alldata, $row);
}
echo json_encode($alldata);
?>
I'm just getting a '[]' in the console. No other error and the calendar is blank, it is not displaying any data from the database.

How to show multiple highcharts on selection of few parameters and dynamically load JSON data using PHP page?

I have two parameters to load dynamic json data from mysql and visualise multiple line charts on page submit.
$.ajax({
url: 'get_pubmedid.php',
type: 'get',
data: {org: org, ptype: ptype, path: path,mirna: mirna},
dataType: 'json',
success:function(response) {
var len = response.length;
for( var i = 0; i<len; i++) {
pubmed = response[i]['name'];
cell=response[i]['cell'];
alert(cell+" "+pubmed+" "+len);
var cells=encodeURIComponent(cell);
var cname="charts"+(i+1);id=i+1;var pid=i+1;
var container = cname;
var func_name = cname;
func_name = function () {
Highcharts.chart(container, {
showhighcharts(org,ptype,path,mirna,cell,cells,pid,pubmed,cname,id);
}
}
func_name()
}
}
});
function showhighcharts(org,ptype,path,mirna,cell,cells,pid,pubmed,cname,id) {
$("#"+cname).html("Wait, Loading graph...");
var options = {
chart: {
type: 'line',
renderTo: cname
},
colors: ['#058DC7', '#50B432', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4'],
credits: {
enabled: false
},
title: {
text: 'Temporal Viewer',
x: -20
},
xAxis: {categories:<?php //echo $_SESSION["cat"]; ?>,
offset:2,
title: {enabled: true,text: 'Time Point' }
},
tooltip: {
shared: true,
useHTML: true,
headerFormat: '<b>Time Point:{point.key}</b> <table style="width:200px;font-size:12px;font-weight:bold;">',
pointFormat: '<tr><td>Dosage:</td><td style="color: {series.color}">{series.name} </td></tr>' + '<tr><td>Fold Change:</td><td style="color: {series.color}">{point.y} </td></tr>',
footerFormat: '</table>',
enabled: true,
crosshairs: {
color: 'light gray',
dashStyle: 'longdash'
}
},
plotOptions: {
series: {
dashStyle: 'longdash'
},
line: {
dataLabels: {
enabled: true
},
enableMouseTracking: true
}
},
series: [{}]
};
$.ajax({
url: "jdatas.php?org="+org+"&ptype="+ptype+"&path="+path+"&mirna="+mirna+"&pid="+id+"&cell="+cell+"&pub="+pubmed,
data: 'show=impressions',
type:'get',
dataType: "json",
success: function(data){
var getSeries = data;
options.series = getSeries;
var chart1 = new Highcharts.Chart(options);
}
});
I want multiple graphs to be loaded on submit.
But its not showing any graph.

refresh High chart after submitting a date range in PHP

am working in PHP. i am using High Chart , dynamically taking data from DB. Now i want to show data between certain date range. Data between certain date range is successfully fetched from DB but now how to refresh the Chart ??
JS Code :
`
function piechart() {
var date_from = $("#date_from").val();
var date_to = $("#date_to").val();
var dataString = 'date_from=' + date_from + '&date_to=' + date_to;
$.ajax({
type: "GET",
url: "pages/dashboard/chart_data.php",
data: dataString,
cache: false,
success: function(html) {
}
});
return false;
}
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Current Year Sales Report'
},
tooltip: {
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
}
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
}
}
}
},
series: [{
type: 'pie',
name: 'Sales (Rupees)',
data: []
}]
}
$.getJSON("chart_data.php", function(json) {
options.series[0].data = json;
chart = new Highcharts.Chart(options);
});
});
`
and chart_data.php
`
if($date_from !='' AND $date_to !='')
{
$where = "tran_date >='$date_from' AND tran_date <= '$date_to'";
echo $db->piechart($where);
}
else
echo $db->piechart();
?>
`
Any help will be highly appreciated.
It looks like it is JavaScript question.
You should move your code inside
`$(document).ready(function() {`
block into the function and execute it each time your date range fields are changed or then document is loaded first time.

fullCalendar displaying everything as allDay

I have created a calendar that saves to MySQL.
I have the allDay value set as false for time frame events but the calendar displays it as all day.
This gets the events..
$sql = mysql_query('SELECT * FROM `companies`.`calendar`');
${'Events'} = array();
while(${'Event'} = mysql_fetch_assoc($sql)){
${'Events'}[] = ${'Event'};
}
Snapshot of my table:
Here is my jQuery
$(document).ready(function() {
$('#eventToAdd').dialog({
autoOpen: false,
height: '300',
width: '550',
modal: true,
resizable: false,
position: 'center',
});
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
theme: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
loading: function(bool) {
if (bool) $('#loading').show();
else $('#loading').hide();
},
eventClick: function(calEvent, jsEvent, view) {
$('#eventTitle').val(calEvent.title);
$('#textColor').val(calEvent.textColor);
$('#backgroundColor').val(calEvent.color);
$("#eventToAdd").dialog({
autoOpen: true,
title: "Update Event",
modal: true,
buttons: [
{
text:"Update Event",
click: function () {
if($('#eventTitle').val()){
calEvent.title = $('#eventTitle').val();
calEvent.color = $('#backgroundColor').val();
calEvent.textColor = $('#textColor').val();
calendar.fullCalendar('updateEvent',calEvent);
$.post('post.api.php', { 'api': 'updateEvent', 'id': calEvent.id, 'title': calEvent.title, 'start': $.fullCalendar.formatDate(calEvent.start, 'yyyy-MM-dd h:mm:ss tt'), 'end': $.fullCalendar.formatDate(calEvent.end, 'yyyy-MM-dd h:mm:ss tt'), 'allDay': calEvent.allDay, 'bgColor': calEvent.color, 'textColor': calEvent.textColor }, function(resp) {
if(resp == 'SUCCESS') {
jAlert('The event has been updated','Updated');
} else {
jAlert('There was an error updating the event<br />Please try again later.<br />ERROR CODE: 728375', 'Process Error');
}
$('#eventToAdd').dialog('close');
});
}
}
},
{
text: "Cancel",
click: function() { $(this).dialog('close'); }
}]
});
},
selectable: true,
selectHelper: true,
select: function (start, end, allDay, jsEvent, view) {
$("#eventToAdd").dialog(
{
autoOpen: true,
title: "Create Event",
modal: true,
buttons: [
{
text:"Create Event",
click: function () {
if($('#eventTitle').val()){
calendar.fullCalendar('renderEvent',
{
title: $('#eventTitle').val(),
start: $.fullCalendar.formatDate(start, 'yyyy-MM-dd h:mm:ss tt'),
end: $.fullCalendar.formatDate(end, 'yyyy-MM-dd h:mm:ss tt'),
allDay: allDay,
textColor: $('#textColor').val(),
color: $('#backgroundColor').val()
},
true
);
var startDate = $.fullCalendar.formatDate(start, 'yyyy-MM-dd h:mm:ss tt');
var endDate = $.fullCalendar.formatDate(end, 'yyyy-MM-dd h:mm:ss tt');
$.post('post.api.php', { 'api': 'createEvent', 'title': $('#eventTitle').val(), 'start': startDate, 'end': endDate, 'allDay': allDay, 'textColor': $('#textColor').val(), 'bgColor': $('#backgroundColor').val() }, function(response) {
if(response == 'SUCCESS'){
jAlert('The event has been saved!','Event Created');
} else {
jAlert('There was an error saving your event<br />Please try again later or let JD know<br />ERROR CODE: 882293','Process Error');
}
});
}
$(this).dialog('close');
}
},
{
text: "Cancel",
click: function() { $(this).dialog('close'); }
}
],
close: function(){
$('#eventTitle').val('');
$('#textColor').val('');
$('#backgroundColor').val('');
}
});
},
editable: true,
events: <?= ${'Events'}; ?>
});
});
The record value should be returned as false (without quotes); not "false". I had the same problem and applied this simple solution:
// -----------------------
while ($row = mysql_fetch_assoc($sql)) {
// -----------------------
if ($row['event_allday'] = 'false') {
$allDayStatus = false;
}
// -----------------------
$eventsArray['id'] = $row['event_id'];
$eventsArray['title'] = $row['event_title'];
$eventsArray['start'] = $row['event_start'];
$eventsArray['end'] = $row['event_end'];
$eventsArray['url'] = $row['event_url'];
$eventsArray['allDay'] = $allDayStatus;
$eventsArray['className'] = $row['event_class'];
$eventsArray['admNotes'] = $row['event_adm_notes'];
// -----------------------

jQuery FullCalendar isn't clearing the event

I am currently working away with FullCalendar, which is pretty cool and has done a lot of neat stuff for me. The only problem I'm having is that if I edit an event, and then try and create another event the javascript seems to hold onto the initial events data.
I am using calendar.fullCalendar('unselect') when I need the link to end, but it doesn't seem to make a difference no matter what I do. I'm hoping you guys might be able to see something I'm overlooking.
<script type='text/javascript'>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultView: 'agendaWeek',
selectable: true,
unselectAuto: true,
selectHelper: true,
editable: true,
select: function(start, end, allDay) {
//var title = prompt('Event Title:');
//var desc = prompt('Event Description:');
//calendar.fullCalendar('unselect');
$('#eventStart').val(start);
$('#eventEnd').val(end);
$('#eventAllDay').val(allDay);
$('#formName').fadeIn();
$('.closeSchedule a').click(function(){
$('#formName').fadeOut('slow');
$('#calendar').fullCalendar('unselect');
//alert(jsEvent);
});
},
events: [
<?php
$first = true;
foreach ($events as $event)
{
if ($first == true)
{
$comma = '';
$first = false;
}
else
{
$comma = ',';
}
echo $comma."
{
id: '".$event->id."',
title: '".addSlashes($event->title)."',
start: '".$event->start."',
end: '".$event->end."',
allDay: ".$event->allDay."
}";
$first = false;
}
?>
],
eventClick: function(event) {
//alert(event.id);
$.ajax({
url: './schedule/getEdit/'+event.id,
success: function(data) {
var formEmpty = $('formName').html();
$('#formName').html(data);
$('#formName').fadeIn('fast');
$('.closeSchedule a').click(function(){
$('#formName').fadeOut('slow');
$('#calendar').fullCalendar('unselect');
});
$('#deleteEvent').live('click', function(){
var answer = confirm("Are you sure you wish to delete this event?")
if (answer){
$.ajax({
type: "POST",
url: "./schedule/deleteEvent/"+event.id,
success: function(msg){
$('#formName').fadeOut('fast');
calendar.fullCalendar( 'removeEvents', [event.id ] )
$('#calendar').fullCalendar('unselect');
}
});
}
});
$('#updateEvent').live('click', function(){
var title = $('#eventName').val();
var trainerID = $('#eventTrainer').val();
var trainer = $('#eventTrainer option:selected').text();
var classID = $('#eventType').val();
var eventType = $('#eventType option:selected').text();
var eventStart = $('#eventStart').val();
var eventEnd = $('#eventEnd').val();
var eventAllDay = $('#eventAllDay').val();
if (eventAllDay == 'false')
{
allDay = false;
}
else
{
allDay = true;
}
// This runs the ajax to add the event to the database.
newData = 'title='+title+'&trainerID='+trainerID+'&classID='+classID+'&start='+eventStart+'&end='+eventEnd+'&allDay='+allDay
$.ajax({
type: "POST",
url: "./schedule/updateEvent/"+event.id,
data: newData,
success: function(msg){
event.title = title;
calendar.fullCalendar('rerenderEvents');
//calendar.fullCalendar('unselect');
$('#calendar').fullCalendar('unselect');
}
});
$('#formName').fadeOut('fast');
$('#eventName').val('');
$('#eventTrainer').val();
$('#eventType').val();
});
}
});
},
eventDrop: function(event,dayDelta,minuteDelta,allDay,revertFunc) {
newData = 'start='+event.start+'&end='+event.end+'&allDay='+allDay
$.ajax({
type: "POST",
url: "./schedule/updateEventTime/"+event.id,
data: newData,
success: function(msg){
}
});
},
eventResize: function(event,dayDelta,minuteDelta,revertFunc) {
newData = 'start='+event.start+'&end='+event.end+'&allDay='+event.allDay
$.ajax({
type: "POST",
url: "./schedule/updateEventTime/"+event.id,
data: newData,
success: function(msg){
}
});
}
});
$('#submitEvent').click(function(){
$('#calendar').fullCalendar('unselect');
var title = $('#eventName').val();
var trainerID = $('#eventTrainer').val();
var trainer = $('#eventTrainer option:selected').text();
var classID = $('#eventType').val();
var eventType = $('#eventType option:selected').text();
var eventStart = $('#eventStart').val();
var eventEnd = $('#eventEnd').val();
var eventAllDay = $('#eventAllDay').val();
if (eventAllDay == 'false')
{
allDay = false;
}
else
{
allDay = true;
}
// This runs the ajax to add the event to the database.
newData = 'title='+title+'&trainerID='+trainerID+'&classID='+classID+'&start='+eventStart+'&end='+eventEnd+'&allDay='+allDay
$.ajax({
type: "POST",
url: "./schedule/addEvent",
data: newData,
success: function(msg){
var description = '<ol><li>'+title+'</li><li>'+trainer+'</li><li>'+eventType+'</li><li class="eventID hide">'+msg+'</li>';
calendar.fullCalendar('renderEvent',
{
id: msg,
title: title,
description: description,
start: eventStart,
end: eventEnd,
allDay: allDay
},
true // make the event "stick"
);
calendar.fullCalendar('unselect');
//calendar.fullCalendar( 'rerenderEvents' )
}
});
$('#formName').fadeOut('fast');
$('#eventName').val('');
$('#eventTrainer option:selected').removeAttr('selected');
$('#eventType option:selected').removeAttr('selected');
});
});
</script>
At this point, I feel like I've tried it all, and I'm just hoping a fresh set of eyes will see what I missed.
Ok took a quick look it looks like you aren't initializing the form with a blank form for the add action in the "select:" function of your full calendar:
In your event click you are doing this:
$('#formName').html(data);
I don't see where you are clearing that with a blank form for a new event. (might have just missed it there is a lot of code there)
Let me know.

Categories