kendo.js 4.54 KB
angular.module("KendoDemos", ["kendo.directives"])
    .controller("MyCtrl", function ($scope, $http) {
        $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)
                    schedulerStart()
                }

            }, function errorCallback(response) {
                console.error(response)
            });
        }
        getAuthURL()

        function schedulerStart() {
            $scope.schedulerOptions = {
                date: new Date("2016/10/12"),
                startTime: new Date("2016/10/12 07:00 AM"),
                height: 600,
                views: [
                    "day",
                    { type: "workWeek", selected: true },
                    "week",
                    "month",
                ],
                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" },
                                ownerId: { from: "OwnerID", defaultValue: 1 },
                                isAllDay: { type: "boolean", from: "IsAllDay" }
                            }
                        }
                    },
                    filter: {
                        logic: "or",
                        filters: [
                            { field: "ownerId", operator: "eq", value: 1 },
                            { field: "ownerId", operator: "eq", value: 2 }
                        ]
                    }
                },
                editable: true,
                resources: [
                    {
                        field: "ownerId",
                        title: "Owner",
                        dataSource: [
                            { text: "Alex", value: 1, color: "#f8a398" },
                            { text: "Bob", value: 2, color: "#51a0ed" },
                            { text: "Charlie", value: 3, color: "#56ca85" }
                        ]
                    }
                ]
            };
        }

    })