angular.module("KendoDemos", ["kendo.directives"])
.controller("MyCtrl", function ($scope, $http) {
$scope.monthPickerConfig = {
start: "year",
depth: "year",
format: "MMMM yyyy"
};
$scope.update = function () {
console.log("update")
}
$scope.create = function () {
console.log("create")
}
function getAuthURL() {
$http({
method: 'get',
url: '/events'
}).then(function successCallback(response) {
var res = response.data
if (res.result) {
if (res.result.status == "redirect") {
window.open(res.result.data, '_self')
}
} else {
console.info(response)
schedulerOptions2()
}
}, function errorCallback(response) {
console.error(response)
});
}
getAuthURL()
$scope.filter = {}
$scope.data = {}
$scope.test = function () {
console.log($scope.operation)
}
function schedulerStart() {
$scope.schedulerOptions = {
date: new Date("2016/10/12"),
startTime: new Date("2016/10/12 07:00"),
majorTimeHeaderTemplate: kendo.template("#=kendo.toString(date, 'HH:mm')# น."),
minorTickCount: 1,
toolbar: ["pdf"],
messages: {
cancel: "Cancel",
save: "Save",
deleteWindowTitle: "Remove event",
pdf: "PDF Export",
editable: {
confirmation: "Are you sure you want to delete this event?"
},
editor: {
description: "Description"
}
},
height: 600,
views: [
"day",
{ type: "workWeek", selected: true },
"week",
"month",
"agenda",
"timeline"
],
timezone: "Asia/Bangkok",
dataSource: {
batch: true,
transport: {
read: {
url: "//localhost:3001/events",
dataType: "jsonp",
type: "GET"
},
update: {
url: "//localhost:3001/events",
dataType: "jsonp",
type: "PUT"
},
create: {
url: "//localhost:3001/events",
dataType: "jsonp",
type: "POST"
},
destroy: {
url: "//localhost:3001/events",
dataType: "jsonp",
type: "DELETE"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
schema: {
model: {
id: "taskId",
fields: {
taskId: { from: "TaskID" },
title: { from: "Title", defaultValue: "No title", validation: { required: true } },
start: { type: "datetime", from: "Start" },
end: { type: "datetime", from: "End" },
startTimezone: { from: "StartTimezone", defaultValue: "Asia/Bangkok" },
endTimezone: { from: "EndTimezone", defaultValue: "Asia/Bangkok" },
description: { from: "Description" },
recurrenceId: { from: "RecurrenceID" },
recurrenceRule: { from: "RecurrenceRule" },
recurrenceException: { from: "RecurrenceException" },
eventTypeID: { from: "EventTypeID" },
isAllDay: { type: "boolean", from: "IsAllDay" }
}
}
},
filter: {
field: "eventTypeID", operator: "eq", value: parseInt($scope.data.value)
}
},
editable: true,
resources: [
{
field: "eventTypeID",
title: "EventType",
dataSource: [
{ text: "Type1", value: 1, color: "#f8a398" },
{ text: "Type2", value: 2, color: "#51a0ed" },
{ text: "Type3", value: 3, color: "#56ca85" }
]
}
]
};
}
function schedulerOptions2() {
$(function () {
$("#scheduler").kendoScheduler({
date: new Date("2016/10/12"),
startTime: new Date("2016/10/12 07:00"),
majorTimeHeaderTemplate: kendo.template("#=kendo.toString(date, 'HH:mm')# น."),
minorTickCount: 1,
toolbar: ["pdf"],
messages: {
cancel: "Cancel",
save: "Save",
deleteWindowTitle: "Remove event",
pdf: "PDF Export",
editable: {
confirmation: "Are you sure you want to delete this event?"
},
editor: {
description: "Description"
}
},
height: 600,
views: [
"day",
{ type: "workWeek", selected: true },
"week",
"month",
"agenda",
"timeline"
],
timezone: "Asia/Bangkok",
dataSource: {
batch: true,
transport: {
read: {
url: "//localhost:3001/events",
dataType: "jsonp",
type: "GET"
},
update: {
url: "//localhost:3001/events",
dataType: "jsonp",
type: "PUT"
},
create: {
url: "//localhost:3001/events",
dataType: "jsonp",
type: "POST"
},
destroy: {
url: "//localhost:3001/events",
dataType: "jsonp",
type: "DELETE"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
schema: {
model: {
id: "taskId",
fields: {
taskId: { from: "TaskID" },
title: { from: "Title", defaultValue: "No title", validation: { required: true } },
start: { type: "datetime", from: "Start" },
end: { type: "datetime", from: "End" },
startTimezone: { from: "StartTimezone", defaultValue: "Asia/Bangkok" },
endTimezone: { from: "EndTimezone", defaultValue: "Asia/Bangkok" },
description: { from: "Description" },
recurrenceId: { from: "RecurrenceID" },
recurrenceRule: { from: "RecurrenceRule" },
recurrenceException: { from: "RecurrenceException" },
eventTypeID: { from: "EventTypeID" },
isAllDay: { type: "boolean", from: "IsAllDay" }
}
}
},
filter: {
logic: "or",
filters: [
{ field: "eventTypeID", operator: "eq", value: 1 },
{ field: "eventTypeID", operator: "eq", value: 2 }
]
}
},
editable: true,
resources: [
{
field: "eventTypeID",
title: "EventType",
dataSource: [
{ text: "Type1", value: 1, color: "#f8a398" },
{ text: "Type2", value: 2, color: "#51a0ed" },
{ text: "Type3", value: 3, color: "#56ca85" }
]
}
]
});
$("#people :checkbox").change(function (e) {
var checked = $.map($("#people :checked"), function (checkbox) {
return parseInt($(checkbox).val());
});
var scheduler = $("#scheduler").data("kendoScheduler");
scheduler.dataSource.filter({
operator: function (task) {
return $.inArray(task.eventTypeID, checked) >= 0;
}
});
});
});
}
})