search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

reloading events on scheduler from server after initialization

Asked by c boland
3 years ago.

I'm using a demo version of the scheduler pro for angularjs and am pulling in angulerjs v 1.3.8.

I'm having difficulty re-loading the scheduler with events after the control has been initialized. Events loaded at initialization display fine. But when a new day is selected in the navigator, I want to pull the events from the server and update the scheduler with those. The displayed day on the scheduler changes, but I cannot get the new events to load.

The code being called on the update is this:

$scope.dp.startDate = workingDate;
$scope.dp.events.list = eventsService.getEvents(workingDate);
$scope.dp.update();

where eventsService.getEvents returns some hard coded json data. I've tried:
1. updating just $scope.events with the new data like I do at init
2. passing the new events json data in the update call like this: $scope.dp.update({events: eventsService.getEvents(workingDate)});
3. updating the events after the update call

but nothing works.

Below is a larger snapshot of what I have.

What am I doing wrong?

The html:

<div class="row-fluid">
<div class="span2">
<daypilot

  • navigator id="navigator" daypilot-config="navigatorConfig"></daypilot-navigator>
  • </div>

<div class="span7">
<daypilot

  • scheduler id="dp" daypilot-config="config" daypilot-events="events" style="width:100%"></daypilot-scheduler>

</div>
</div>

The controller file:

angular.module('SchedulerCtrl', ['daypilot']).controller('SchedulerController', ['$scope', 'eventsService', '$routeParams', '$cookieStore', '$timeout',
function ($scope, eventsService, $routeParams, $cookieStore, $timeout) {
'use strict';

$scope.workingDate = new Date();

$scope.config = {
startDate: $scope.workingDate,
days: 1,
showNonBusiness : false,
businessBeginsHour: 7,
businessEndsHour: 21 ,
dayBeginsHour: 7,
dayEndsHour: 21,
cellWidthSpec: "Auto",
treeEnabled: true,
treePreventParentUsage: true,
theme: 'white_w_colored_event'
};

$scope.events = [];

$scope.navigatorConfig = {
selectMode: "month",
showMonths: 3,
skipMonths: 3,
onTimeRangeSelected: function(args) {
$scope.loadEvents(new Date(Date.parse(args.day)));
}
};

//initialize
var init = function() {

if ($scope.userId) {
if(!$scope.user) {
eventsService.userInfo($scope.userId).success(function(response){
eventsService.setUserInfo(response[0]);
$scope.user = response[0];
$scope.userModule = $scope.user.module;
$scope.module = $cookieStore.get('userModule') || $scope.module;
}).error(function() {
throw ('Error on line 19 of ModuleController.js');
});
}
}

$scope.loadResources();
$scope.events = eventsService.getEvents($scope.workingDate);

};

$scope.loadResources = function() {
$scope.config.resources = eventsService.getRoomResources();
/* eventsService.getRoomResources().success(function(response){
$scope.config.resources = response;
}).error(function() {
throw ('Error on line 19 of ModuleController.js');
});
*/

};

$scope.loadEvents= function(workingDate) {
$scope.workingDate = workingDate;
$scope.dp.startDate = workingDate;
$scope.events = eventsService.getEvents(workingDate);
$scope.dp.update();

};

init();
}
]);

some hard coded resources and events in the service file:

var resources = [
{ name: "Courtroom A", id: "A", children:[
{ name : "Room A.1", id : "A.1" },
{ name : "Room A.2", id : "A.2" }
]
},
{ name: "Courtroom B", id: "B" },
{ name: "Courtroom C", id: "C"}
];

var events14 = [
{
start: new DayPilot.Date("2016-12-14T08:00:00"),
end: new DayPilot.Date("2016-12-14T12:30:00"),
id: DayPilot.guid(),
resource: "A.1",
text: "Orientation 14",
interpreter_id: '773636363'
},
{
start: new DayPilot.Date("2016-12-14T14:00:00"),
end: new DayPilot.Date("2016-12-14T16:45:00"),
id: DayPilot.guid(),
resource: "B",
text: "English Written Test 14",
interpreter_id: '773636363'
},

];

var events13 = [
{
start: new DayPilot.Date("2016-12-13T08:00:00"),
end: new DayPilot.Date("2016-12-13T12:30:00"),
id: DayPilot.guid(),
resource: "A.1",
text: "Orientation 13",
interpreter_id: '773636363'
},
{
start: new DayPilot.Date("2016-12-13T14:00:00"),
end: new DayPilot.Date("2016-12-13T16:45:00"),
id: DayPilot.guid(),
resource: "B",
text: "English Written Test 13",
interpreter_id: '773636363'
},

];
var events12 = [

{
start: new DayPilot.Date("2016-12-12T13:00:00"),
end: new DayPilot.Date("2016-12-12T15:45:00"),
id: DayPilot.guid(),
resource: "B",
text: "English Written Test Dec 12",
interpreter_id: '773636363'
},
];

getRoomResources: function() {

return resources;
//return $http.get('/api/events/certificates/module/?key=' + eventCertificateKey);
},

getEvents: function(currentDate) {
var day = currentDate.getUTCDate();

if ( day == 14)
return events14;
else if ( day == 13)
return events13;
else
return events12;
return $http.get('/api/events/certificates/module/?key=' + currentDate);
},

This question is more than 3 months old and has been closed. Please create a new question if you have anything to add.