Step 5.1. Initializing & configuring the scheduler

Step 5.1. Initializing & configuring the scheduler

Skip and go to the next step

In this chapter you will be shown how to implement the Employee role. The implementation takes place in the Employee() action that we created on the Step 2 (sub-step 3.2.2).

Step 5.1.2. Scheduler Initialization

At the very beginning of our implementation, we should initialize the scheduler.

Your actions: modify the Employee() action so it looks like the action below:

public ActionResult Employee()
            var scheduler = new DHXScheduler(this);
            return View(scheduler );

Step 5.1.2. Checking user rights

Then, we will check whether a user has employee rights (we performed the similar checking for the Manager role).

Your action: add the region below to the Employee() action.

#region check rights
     if (!RoleIs("Employee"))
         return RedirectToAction("Index", "System");

RoleIs() is the function that we defined on the step 3 (sub-step 3.2.3).

Step 5.1.3. Scheduler configuration

As the name suggests, on this step we will configure the recently initialized scheduler.

We will add 2 extensions: one for providing tooltips and the other for providing cookies.

Your action: add the region below to the Employee() action.

#region configuration  
       scheduler.Extensions.Add(SchedulerExtensions.Extension.Cookie);// activates the extension to provide cookie
       scheduler.Extensions.Add(SchedulerExtensions.Extension.Tooltip);// activates the extension to provide tooltips
       var template = "<b>Task:</b> {text}<br/><b>Start date:</b>";
       template += "<%= scheduler.templates.tooltip_date_format(start) %><br/><b>End date:</b>";
       template += "<%= scheduler.templates.tooltip_date_format(end) %>";
       scheduler.Templates.tooltip_text = template;// sets template for the tooltip text

Back to top

Step 5.1.4. Configuration of scheduler views

Here we will configure views of the scheduler: remove the default ones and add WeekAgenda and Month views.

Your action: add the region below to the Employee action.

#region views
       scheduler.Views.Clear();//removes all views from the scheduler 
       scheduler.Views.Add(new WeekAgendaView());// adds a tab with the weekAgenda view
       scheduler.Views.Add(new MonthView()); // adds a tab with the Month view
       scheduler.InitialView = scheduler.Views[0].Name;// makes the weekAgenda view selected initially

Back to top

Step 5.1.5. Common data managing. Enabling dataProcessor

And at the end of this step we will enable dataProcessor to have a possibility to change the status of tasks. Also we will make here common data management.

Your action: add the region below to the Employee action.

#region data
       scheduler.SetEditMode(EditModes.Forbid);// forbids editing of tasks    
       scheduler.LoadData = true;//'says' to send data request after scheduler initialization 
       scheduler.DataAction = "Tasks";//sets a controller action which will be called for data requests 
       scheduler.Data.Loader.PreventCache();// adds the current ticks value to url to prevent caching of the request 
       scheduler.InitialDate = new DateTime(2011, 10, 7);// sets the initial date of the scheduler

See the full code of the action here.

comments powered by Disqus