This is a migrated thread and some comments may be shown as answers.

Resource Grouping with permissions

5 Answers 43 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 13 Sep 2016, 03:05 PM

I already have a calendar setup with Resource Grouping and now would like to setup permissions so that some users can only admin certain resources but see all. I would handle the determination of right so that each resource would have a flag set as something like adminAllowed and when that is true the resource can be booked.  Is this possible, I'm fairly sure that it is possible via the client API but want to check before I waste any time on it.

Regards

Jon

5 Answers, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 16 Sep 2016, 09:35 AM
Hello Jon,

To achieve the desired you could use a combination of server-side and client-side events, exposed by the RadScheduler. Based on our Resource grouping demo, I could suggest you to use the OnAppointmentCreated server-side event to make some of the events not editable and not deletable, depending on which resource they belong to:
protected void RadScheduler1_AppointmentCreated(object sender, AppointmentCreatedEventArgs e)
{
    var appointment = e.Appointment;
    var resource = appointment.Resources[0];
    int key;
 
    if (int.TryParse(resource.Key.ToString(), out key) && key == 1)
    {
        appointment.AllowDelete = false;
        appointment.AllowEdit = false;
    }
}

To prevent event creation, depending on the current resource, you could use the OnClientAppointmentInserting client-side event:
function inserting(sender, args) {
    var targetSlot = args.get_targetSlot();
    var resourceKey = targetSlot.get_resource().get_key();
    if (resourceKey == 1) {
        args.set_cancel(true);
    }
}

Regards,
Veselin Tsvetanov
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Jon
Top achievements
Rank 1
answered on 16 Sep 2016, 10:18 AM

Hi Veselin

Many thanks - the appointment created bit works very well.

On the client side though I need to be able to get the true/false value for admin permission from the resource.  There doesn't appear to be an event that I can attach to in order to add extra values.  For example on the scheduler itself I use the CustomAttributeNames to add extra attributes to the appointments but there doesn't appear to be something for the resources - or did I miss something?

Regards

Jon

0
Veselin Tsvetanov
Telerik team
answered on 17 Sep 2016, 01:45 PM
Hello Jon,

You could use the TimeSlotCreated event of the RadScheduler to attach custom attributes to the resource that is associated with a specific TimeSlot:
protected void RadScheduler1_TimeSlotCreated(object sender, TimeSlotCreatedEventArgs e)
{
    var timeSlot = e.TimeSlot;
    var resource = timeSlot.Resource;
    int key;
 
    if (int.TryParse(resource.Key.ToString(), out key) && key == 1)
    {
        resource.Attributes.Add("alowedManipulation", "notAllowed");
    }
}

Then, again in the OnClientAppointmentInserting, you could retrieve that value and based on that you could cancel the event:
function inserting(sender, args) {
    var targetSlot = args.get_targetSlot();
    var resource = targetSlot.get_resource();
    var allowed = resource.get_attributes().getAttribute("alowedManipulation");
    if (allowed == "notAllowed") {
        args.set_cancel(true);
    }
}

Regards,
Veselin Tsvetanov
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Jon
Top achievements
Rank 1
answered on 17 Sep 2016, 04:50 PM

Hi Veselin

Thanks for that - it certainly looks like that will get me close to the solution.  The permission "AdminPermissionAllowed" I have coming from the database though in the resource data source so ideally it would get the data from there.  In the resource object that you get in the timeslotcreated event there is a dataitem.  It is always blank though.  Is there no way to add extra attributes from the database?

If not then I will just have to get the resource data a second time in the pageload event and make a list of the resources that have permission allowed with a reference to that in the timeslotcreated event.  

Regards

Jon

 

 

0
Peter Milchev
Telerik team
answered on 21 Sep 2016, 01:43 PM
Hello Jon, 

I am afraid that currently it is not possible to use the "AdminPermissionAllowed" value of the Database object directly and  you should use the approach Veselin suggested - by adding manually attributes to the resource.

Regards,
Peter Milchev
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Scheduler
Asked by
Jon
Top achievements
Rank 1
Answers by
Veselin Tsvetanov
Telerik team
Jon
Top achievements
Rank 1
Peter Milchev
Telerik team
Share this question
or