0

我已按照教程使调度程序与角度一起工作。不过我确实有一个问题。人们只能通过我自己的表单添加事件,而不是通过调度程序本身,因为他们必须选择要添加到事件的图像。

但这使得 scheduler.collision 不起作用。我仍然可以在同一时间范围内添加事件。另外,如果我想覆盖 checkCollision 方法,我会在控制台中收到一个错误,表明该方法未知。

我真的不知道如何让两者一起工作,因为我是 Angular 的新手。

我的调度程序指令:

myAppProfile.directive('dhxScheduler', function() {
        return {
        restrict: 'A',
        scope: false,
        transclude: true,
        template:'<div class="dhx_cal_navline" ng-transclude></div><div class="dhx_cal_header"> 
                      </div><div class="dhx_cal_data"></div>',

        link:function ($scope, $element, $attrs, $controller){
          //default state of the scheduler
          if (!$scope.scheduler)
          $scope.scheduler = {};
          $scope.scheduler.mode = $scope.scheduler.mode || "month";
          $scope.scheduler.date = $scope.scheduler.date || new Date();

          //watch data collection, reload on changes
          $scope.$watch($attrs.data, function(collection){
                 if(collection) {

            scheduler.clearAll();
            scheduler.parse(collection, "json");


           }

          }, true);

          //watch mode and date
          $scope.$watch(function(){
            return $scope.scheduler.mode + $scope.scheduler.date.toString();
          }, function(nv, ov) {
            var mode = scheduler.getState();

            if (nv.date != mode.date || nv.mode != mode.mode)
              scheduler.setCurrentView($scope.scheduler.date, $scope.scheduler.mode);
          }, true);

          //size of scheduler
          $scope.$watch(function() {
            return $element[0].offsetWidth + "." + $element[0].offsetHeight;
          }, function() {
            scheduler.setCurrentView();
          });

          //styling for dhtmlx scheduler
          $element.addClass("dhx_cal_container");

          //init scheduler
          scheduler.config.xml_date="%Y-%m-%d %H:%i";
          scheduler.config.dblclick_create = false;
          scheduler.config.drag_create = false;
          scheduler.config.drag_move = true;
          scheduler.config.readonly = false;
          scheduler.config.touch= true; 
          scheduler.config.collision_limit = 1; //this does not give an error but does not work
          scheduler.attachEvent("onEventLoading", function(ev){ //this gives error
                return scheduler.checkCollision(ev);             
           });
          scheduler.init($element[0], new Date(), "month");
          scheduler.load("agendaController.php", "json");
          var dp = new dataProcessor("agendaController.php");
          dp.init(scheduler); 


        }
      }
});

调度程序 save_event 方法(通过 php):

myAppProfile.controller('addEventController', function($scope,$location, $http) {
        $scope.saveEvent = function() {
             $http({

                    method: 'POST', 
                    url: 'eventController.php',
                    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                    data: { 
                            'begin': $scope.begin + " " + $scope.btijd,
                            'einde': $scope.einde + " " + $scope.etijd,
                            'beschrijving': $scope.beschrijving,
                            'img': $scope.img
                         }
                }).

                success(function(data, status) {

                    $location.path("/agenda");

                }).

                error(function(data, status) {
                    alert(data);
                });
        }
});
4

1 回答 1

1

确保您正在加载 ext/dhtmlxscheduler_limit.js,如果没有此文件,将不会定义 checkCollision 方法。

此外,使用 onEventLoading 中的 checkCollision 非常昂贵(您将进行 n*n*n/4 次检查)。取而代之的是,您可以在将数据发送到服务器端之前使用类似 next 的代码

var id = scheduler.addEvent({ event object details here })
if (scheduler.getEvent(id)){
  //there is no collision, server side saving data call can be initiated
} else {
  //collision detected, event *not added*, show some message for the user
}
于 2014-03-03T12:38:47.093 回答