-1

I'm looking for a way to connect my open source Kendo UI Scheduler to a local database using javascript.

I've already started but got stuck because I can't find any helpful documentation on how to do this using javascript.

$(function () {
        $('#scheduler').kendoScheduler({
            views: [{type:"day", selected:true}],
            dataSource:
                {
                    transport:
                    {
                        read: { url: "@Url.Action("GetTasks","Schedules")", dataType: "json" },
                        update: { url: "@Url.Action("UpdateTask","Schedules")", dataType: "json" },
                        create: { url: "@Url.Action("CreateTask","Schedules")", dataType: "json" },
                        destroy: { url: "@Url.Action("DeleteTask","Schedules")", dataType: "json" },
                        parameterMap: function (options, operation) {
                            if (operation !== "read" && options.models) {
                                return { models: kendo.stringify(options.models) };
                            }  
                        }
                    },
                    schema:
                    {
                        /* Define your actual models for your events here */
                        model:
                        {


                            /* See the available documentation for more information */
                        }
                    }

I've been looking on the Telerik documentation without any success besides that I looked for some clues here on stackoverflow but besides this thread https://stackoverflow.com/questions/23322409/how-to-bind-datasource-to-the-scheduler-in-kendo-ui-using-javascript I couldn't find anything helpful.

Can anybody point me in the right direction concerning useful documentation or an illustrative example binding the Kendo UI Scheduler to a local database using javascript?

Thanks in advance


MODEL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;

namespace Eindwerk.Models
{
    public class Events
    {
        public int Id { get; set; }
        public string eventTitle { get; set; }

        public DateTime eventStart { get; set; }
        public DateTime eventStop { get; set; }

        public Boolean eventAllday { get; set; }

        public string eventDescription { get; set; }

        public string eventRoom { get; set; }

        public string eventAttend { get; set; }

        public string eventExtra { get; set; }

        public string eventRequest { get; set; }

        public class CalendarDBContext : DbContext
        {
            public DbSet<Events> RoomEvents { get; set; }
        }
    }


}

TASKVIEWMODEL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Eindwerk.Models
{
    public class TaskViewModel
    {
        public int TaskID { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }

        private DateTime start;
        public DateTime Start
        {
            get
            {
                return start;
            }
            set
            {
                start = value.ToUniversalTime();
            }
        }

        private DateTime end;
        public DateTime End
        {
            get
            {
                return end;
            }
            set
            {
                end = value.ToUniversalTime();
            }
        }
        public bool IsAllDay { get; set; }
        public int? OwnerID { get; set; }
        public string eventRoom { get; set; }
        public string eventAttend { get; set; }
        public string eventExtra { get; set; }
        public string eventRequest { get; set; }


    }
}

CONTROLLER

      private Events.CalendarDBContext db = new Events.CalendarDBContext();

        public ActionResult Tasks_Read()
        {

            using (var sampleDB = db)
            {
                IQueryable<TaskViewModel> tasks = sampleDB.RoomEvents.ToList().Select(task => new TaskViewModel()
                {
                    TaskID = task.Id,
                    Title = task.eventTitle,
                    Start = DateTime.SpecifyKind(task.eventStart, DateTimeKind.Utc),
                    End = DateTime.SpecifyKind(task.eventStop, DateTimeKind.Utc),
                    Description = task.eventDescription,
                    IsAllDay = task.eventAllday,
                    OwnerID = 1
                }).AsQueryable();
                //return Json(tasks.ToDataSourceResult(Request));
                return Json(tasks.ToList(), JsonRequestBehavior.AllowGet);


            }
        }

        public ActionResult Tasks_Create([DataSourceRequest]DataSourceRequest request, TaskViewModel task)
        {


            if (ModelState.IsValid)
            {
                using (var sampleDB = db)
                {
                    //Create a new Task entity and set its properties from the posted TaskViewModel
                    var entity = new Events
                    {
                        Id = task.TaskID,
                        eventTitle = task.Title,
                        eventStart = DateTime.SpecifyKind(task.Start, DateTimeKind.Utc),
                        eventStop = DateTime.SpecifyKind(task.End, DateTimeKind.Utc),
                        eventDescription = task.Description,
                        eventAllday = task.IsAllDay


                    };


                    // Add the entity
                    sampleDB.RoomEvents.Add(entity);
                    //sampleDB.Tasks.AddObject(entity);
                    // Insert the entity in the database
                    sampleDB.SaveChanges();

                    // Get the TaskID generated by the database
                    task.TaskID = entity.Id;
                }
            }
            // Return the inserted task. The scheduler needs the generated TaskID. Also return any validation errors.
            return Json(new[] { task }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);


        }
    }
}

VIEW

$(function () {
    $('#scheduler').kendoScheduler({
        date: new Date(Date.now()),
        startTime: new Date("2014/03/07 09:00 AM"),
        endTime: new Date("2014/03/07 07:00 PM"),
        height:800,
        views: [{type:"day", selected:true}],
        timezone: "Etc/UTC",
        dataSource:
            {
                transport:
                {
                    read: { url: "@Url.Action("Tasks_Read","Home")", dataType: "json" },
                    update: { url: "@Url.Action("Tasks_Update","Home")", dataType: "json" },
                    create: { url: "@Url.Action("Tasks_Create","Home")", dataType: "json" },
                    destroy: { url: "@Url.Action("Tasks_Destroy","Home")", dataType: "json" },
                    parameterMap: function (options, operation) {
                        if (operation !== "read" && options.models) {
                            return { models: kendo.stringify(options.models) };
                        }  
                    }
                },

            },
        schema: {

            model: { 
                id: "meetingID", 
                fields: { 
                    meetingID: { type: "number" }, 
                    title: { defaultValue: "No title", validation: { required: true } }, 
                    start: { type: "DateTime" }, 
                    end: { type: "DateTime" }, 
                    roomId: { nullable: true }, 
                    attendee: { defaultValue: 1 }, 
                    isAllDay: { type: "boolean" } 
                } 
            } 
        }
Community
  • 1
  • 1
Sesamzaad
  • 462
  • 8
  • 25

2 Answers2

0
schema: {
            model: {
                id: "meetingID",
                fields: {
                    meetingID: { type: "number" },
                    title: { defaultValue: "No title", validation: { required: true } },
                    start: { type: "date" },
                    end: { type: "date" },
                    roomId: { nullable: true },
                    attendee: { defaultValue: 1 },
                    isAllDay: { type: "boolean" }
                }
            }
        }

and look in the exemples of : http://demos.telerik.com/kendo-ui/web/scheduler/restriction.html

Ilya Luzyanin
  • 7,910
  • 4
  • 29
  • 49
ChrG
  • 141
  • 4
  • Ok, thanks for replying! Now I got the model but how am I going to execute the functions like: url: "@Url.Action("CreateTask","Schedules")"? Using a controller I guess but how? – Sesamzaad May 14 '14 at 07:52
  • Ignore my previous answer, I managed to implement everything using documentation (http://docs.telerik.com/kendo-ui/getting-started/using-kendo-with/aspnet-mvc/helpers/scheduler/ajax-editing) but when saving an event I get an error on sampleDB.SaveChanges() telling me: System.Data.SqlServerCe.SqlCeException: An overflow occurred while converting to datetime. I Googled this error but found no solid solutions... – Sesamzaad May 14 '14 at 13:15
  • i will do this wenn i creat events Start = DateTime.SpecifyKind(Booking.BookDateTimeFrom, DateTimeKind.Utc) – ChrG May 14 '14 at 14:49
  • and set Timezone on utc .Timezone("Etc/UTC") i rember reading about same error it has somthing to do with the utc format i think – ChrG May 14 '14 at 14:52
  • where do I set the timezone on utc .Timezone("Etc/UTC")? Cause I already used the DateTime.SpecifyKind... – Sesamzaad May 14 '14 at 15:32
  • $("#scheduler").kendoScheduler({ date: new Date("2013/6/13"), startTime: new Date("2013/6/13 07:00 AM"), height: 600, views: [ "day", { type: "workWeek", selected: true }, "week", "month", "agenda" ], **timezone: "Etc/UTC"**, dataSource: { batch: true, transport: – ChrG May 15 '14 at 05:58
  • found this _This error message actually had to do with converting a 'decimal' datatype in my Visual Studio Dataset Designer to a 'numeric' data type in my SQLCE database which I apparently cannot do._ – ChrG May 15 '14 at 08:15
  • or this _the overflow error was a result of trying to insert an uninitialized "System.DateTime" even though the value was null (Note: uninitialized DateTime is 1/1/0001 12:00:00 and not necessarily null) the value needs to be set explicitly to null for the insert so the Microsoft-dataset-generated-code will use "System.DBNull.Value" otherwise the DB driver throws a overflow error._ – ChrG May 15 '14 at 08:16
  • can you look in youre object befor u send it to youre service. Mabey some values are not set or the db entity is not same as db table – ChrG May 15 '14 at 08:19
  • I edited above and included all my code used in model, controller and view. I can't seem to find the problem.. – Sesamzaad May 15 '14 at 09:15
  • youre model needs to implemt interface ISchedulerEvent – ChrG May 15 '14 at 09:34
  • I don't quite understand? – Sesamzaad May 15 '14 at 09:38
  • and wy you need two ? Also the Schema in view needs to be set on Model fild with from :`taskId: { from: "TaskID", type: "number" }` i am sry that i cant help that much my scheduler is in razor with mvc it look realy diferent – ChrG May 15 '14 at 09:41
  • `public class Events : ISchedulerEvent` – ChrG May 15 '14 at 09:45
  • I'm using the open source version of Kendo Scheduler, I think I can't use the ISchedulerEvent? Could you give me an example of your schema and saving to db? – Sesamzaad May 15 '14 at 09:48
  • `public class SchedulerModel : ISchedulerEvent { public int BookingId { get; set; } [Required] public string Title { get; set; } public string Description { get; set; } private DateTime start; [Required] public DateTime Start { get{ return start; } set{ start = value.ToUniversalTime(); } }` – ChrG May 15 '14 at 10:05
  • ` public string StartTimezone { get; set; } private DateTime end; [Required] public DateTime End { get { return end; } set { end = value.ToUniversalTime(); } } public string EndTimezone { get; set; } public string RecurrenceRule { get; set; } public int? RecurrenceID { get; set; } public string RecurrenceException { get; set; } public bool IsAllDay { get; set; public string Timezone { get; set; }` I am using also the open source and you need ISchedulerEvent` – ChrG May 15 '14 at 10:07
  • Do you also use the open source version? – Sesamzaad May 15 '14 at 10:37
  • I am using also the open source and you need ISchedulerEvent – ChrG May 15 '14 at 10:43
  • okay which references do you use? using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.Entity...? – Sesamzaad May 15 '14 at 10:55
  • ChrG: I looked into it and now I also use the ISchedulerEvent but still same error... Could you include your working code sample of model, controller and view? It would really help me out! – Sesamzaad May 19 '14 at 09:15
  • Sry i cant some of the code its not in my estate. But i think the problem belongs to tu referenz of the data base some variable are not the same or somthing like that. Maby this will help [Link](http://mail.mcmscontrols.com/forums/editortemplate-for-schelduler) it helps me realy out. – ChrG May 19 '14 at 09:42
0

I did this using JavaScript and HTML

Demo available click hereJSfiddle demo

AmanVirdi
  • 1,667
  • 2
  • 22
  • 32
overflow
  • 145
  • 8
  • Could you please add your solution here briefly? Jsfiddle link may stop working in future, no need to overcome SO requirement on posting code when adding jsfiddle links - it's there for a reason. – Ilya Luzyanin Sep 11 '14 at 07:30