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
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
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
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
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
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