I want to do Event/Scheduler calendar in asp.net MVC. So far I've written this code for the database table in , but something doesn't work.
The controller code :
public ActionResult Index()
{
return View();
}
public JsonResult GetEvents()
{
var events = db.MedicationTrackers.ToList();
return new JsonResult { Data = events, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
and the View-Index code
#model IEnumerable<LICENTA.Database.MedicationTracker>
#{
ViewBag.Title = "Index";
}
<h2>Index</h2>
#section Scripts {
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<scripts src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.9.0/fullcalendar.min.js"></scripts>
<script>
$(document).ready(function () {
var events = [];
$.ajax({
type: "GET",
url: "/MedicationTrackers/GetEvents",
success: function (data) {
$.each(data, function(i,v){ //i=index v=value
events.push({
title: v.IdMember,
description: v.IdMedication,
start: moment(v.Start),
end: v.Stop != null? moment(v.End):null,
status: v.Status
})
})
GenerateCalendar(events);
},
error: function (error) {
alert("Error occured!!")
}
})
})
function GenerateCalendar(events) {
$('calender').fullCalendar('destroy'); //clear first
$('calender').fullCalendar({
contentheight: 400,
defaultdate: new date(),
timeformat: 'h(:mn)a',
header: {
left: 'prev,next today',
center: 'title',
right: 'month, basicweek, basicday, agenda'
},
eventlimit: true,
eventcolor: '#378006',
events: events
}}
</script>
When I run the project the ajax error appear. I tried to test just the calendar to see if it works but it does not appear on the page.
A calender is not an html element. You need to add a div to your view with an id:
<div id="calendar"><div>
And update your javascript:
function GenerateCalendar(events) {
$('#calendar').fullCalendar('destroy'); //clear first
$('#calendar').fullCalendar({
contentheight: 400,
defaultdate: new date(),
timeformat: 'h(:mn)a',
header: {
left: 'prev,next today',
center: 'title',
right: 'month, basicweek, basicday, agenda'
},
eventlimit: true,
eventcolor: '#378006',
events: events
});
}
Related
I am working on my project to calculate the vistors time, and i want to highlight the visitors who visit after 6:OO pm with red color and rest of them with green color in short i am trying a conditional formatting on timestamp. The variable start: moment(data.Logdate) is responsible to get the date time from database.
The code snippet is as under:
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
buttonText: {
today: 'today',
month: 'month',
week: 'week',
day: 'day'
},
events: function(start, end, timezone, callback, Status) {
$.ajax({
// url: '/Home/Index',
type: "GET",
dataType: "JSON",
success: function(result) {
var events = [];
$.each(result, function(i, data) {
events.push({
title: data.Status,
start: moment(data.Logdate),
//backgroundColor: "#dcdcdc",
// color:"#000000",
//if(moment(data.Logdate).format('HH:MM')>'18:00')backgroundColor:"#dcdcdc", else backgroundColor:"#dcdcdc"
});
});
callback(events);
}
});
},
eventRender: function(event, element) {
element.qtip({
content: event.description
});
},
editable: false
});
});
Good evening everyone!
I need to show the FullCalendar events of my agenda.
I have a list of events in my database and my method returns database data via json (DAO jsp). I'm using dataSet and End date because Java does not support the use of the attributes of reserved words.
my json returns this:
[{"id": 3,"title": "Alexandre Garcia","dataStart": "05/09/2016 20:00","dataEnd": "05/09/2016 21:00"}]
my javascript:
<script type="text/javascript">
$(document).ready(function () {
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultView: 'agendaWeek',
timezone: "local",
ignoreTimezone: false,
editable: false,
selectable: true,
minTime: "07:00:00",
maxTime: "17:00:00",
slotDuration: "00:60:00",
allDay: false,
events: function (start, end, timezone, callback) {
$.ajax({
url: 'app.json',
type: "GET",
datatype: 'json',
success: function (doc) {
var events = [];
if (doc != undefined && doc.length > 0) {
doc.forEach(function (entry) {
events.push({
title: entry.title,
start: entry.dataStart,
end: entry.dataEnd
});
});
}
callback(events);
}, error: function (err) {
alert('Error in fetching data');
}
});
},
eventClick: function (calEvent, jsEvent, view) {
alert(calEvent.title);
}
});
});
</script>
but my calendar is always empty, could help me?
I'm using the fullcalendar jquery plugin and I want to get the value of allDay that is true or false and I want to append the value to a form.But value that is getting appended is [object Object]
<input type="hidden" id="apptAllDay" value="[object Object]">
<script type="text/javascript">
$(document).ready(function(){
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: '2015-02-12',
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
$('#apptStartTime').val(start);
$('#apptEndTime').val(end);
$('#apptAllDay').val(allDay);
$.magnificPopup.open({
items: {
src: '#popup',
type: 'inline'
}
});
},
editable: true,
eventLimit: true, // allow "more" link when too many events
eventStartEditable : false,
events: "http://localhost/app1/events",
});
$(document).on("click","#addEvent",function(e) {
e.preventDefault();
doSubmit();
});
function doSubmit(){
var title = $("#titleContainer").val();
var description = $.trim($("#descContainer").val());
var url = $("#urlContainer").val();
if (!title) {
alert("Title is required");
return false;
}
$("#calendar").fullCalendar('renderEvent',
{
title: title,
start: new Date($('#apptStartTime').val()),
end: new Date($('#apptEndTime').val()),
allDay: ($('#apptAllDay').val() == "true")
},
true);
}
});
How can I get the real value that is TRUE or FAlSE?
This might probably help you, change according to your requirement.
function parseClientEvents(){
var clientArr = $('#calendar').fullCalendar('clientEvents');
for(i in clientArr){
console.log(clientArr[i]);//gives events full description.
console.log(clientArr[i].allDay);
//check for value here and append to your hidden field.
//all your logic goes here.
}
return true;
}
I want to load all events in full calendar using Ajax when the page loads.I am getting response from Ajax.But the event is not added in Full calendar.
here is my jquery code
$('#calendar').fullCalendar({
theme: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: '2014-06-12',
editable: true,
events: function(start,end,callback){
var mydata = {
action: "fw_ajax_callback",
subaction: "get_myappointments",
};
$.ajax({
url :ajax_url,
type: 'POST',
data: mydata,
dataType: 'json',
success:function(appointments){
var events = [];
if(!!appointments){
$.map( appointments, function( r ) {
events.push({
title: r.title,
start: r.start,
end: r.start
});
});
}
callback(events);
}
})
}
});
From my console I found an error stating callback is not a function.Please help me i am a newbie.
I think you are making what is supposed to be easy look very complex: I have added a JSFiddle Link to show you how it work.
$('#calendar').fullCalendar({
//theme: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: moment().format("YYYY-MM-DD"),
editable: true,
events: {
url: 'http://www.json-generator.com/api/json/get/ccUKVDYErS?indent=2',
error: function() {
$('#script-warning').show();
},
success: function(){
alert("successful: You can now do your stuff here. You dont need ajax. Full Calendar will do the ajax call OK? ");
}
},
loading: function(bool) {
$('#loading').toggle(bool);
}
});
});
I am using fullCalendar with bootstrap popovers. The goal is to append a form for adding new event inside the popovers. The code does make the popover appears above the cells, however, on clicking the popovers, the cells underneath it are selected rather than the popovers themselves.
Here is my code:
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
height: height,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
dayClick: function( date, allDay, jsEvent, view ){
if (view.name=='month'){
$(this).children().popover({
placement: 'right',
content: function() {return $("#popover-content").html();},
html : true, container: 'body'
});
$('.popover.in').remove();
$(this).children().popover('show');
..........
and html
<div id="popover-content" class="hide">
<form>
<input id="easyeventtitle" />
</form>
</div>
This is how it looks like
I have tried z-index to popovers, instead, they do not appear at all!
Please help! Thank you for your time!
Edit: here is the link to test it
Try this code
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay',
},
events: '/events.json',
editable: true,
selectable: true,
dayClick: function(start, end, allDay, jsEvent, view) {
$(this).popover({
html: true,
placement: 'right',
title: function() {
return $("#popover-head").html();
},
content: function() {
return $("#popover-content").html();
},
html: true,
container: 'body'
});
$(this).popover('toggle');
}
});
});