using the scheduler with angular.js and dataprocessor

Hello,

I found in the docs dat we can send data from the scheduler to the database using this:

var dp = new dataProcessor(url)
dp.init(myobj)

But when I do the following, it gets into an infinite loop (above code are last lines of below code):

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.init($element[0], new Date(), "month");
          scheduler.load("agendaController.php", "json");
          var dp = new dataProcessor("agendaController.php");
          dp.init(scheduler);
        }
      }
    });

This is my controller code:

include('connections.php');
include('/db-connector/scheduler_connector.php');    
 
$scheduler = new JSONSchedulerConnector($conn);
$scheduler->render_table("events","id","start_date,end_date,text");

can anyone help me with getting started saving events to db? Thanks!

I was able to resolve the loop, moving the code to this part:

$scope.$watch($attrs.data, function(collection){
     if(collection) {
        scheduler.clearAll();
        scheduler.parse(collection, "json");
       
       //this does not cause infinite loop but does not work either
        var dp = new dataProcessor("agendaController.php");
        dp.init(scheduler);
      }
  }, true);

But it does not save changes or new events to the DB, can anyone help? Thx!

Does it send the data to server side, when events addede|changed ?

The both ways of initialization looks fine, and must not cause any problems.
dataprocessor must be initialized at any moment after scheduler initialization, exact place doesn’t matter.

I found the solution! I had a .js file added that was not necessary and that was already used bij de scheduler.js file. Once I removed this file it started working fine :slight_smile: