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

Choosing which ContextMenu to use

Asked by brandon
12 years ago.

Hi Dan,
I'll try to make my questions/problems as clear as possible. I'm using DayPilot Calendar for MVC3 Razor and I'm trying to use a context menu that is specific to the user. Only an admin or the user who created the event should have the option to delete/edit it. So I've defined two different context menus in my view. Here's the code:

@Html.DayPilotMenu("menu_priveledged_user", new DayPilotMenuConfig
{
CssClassPrefix = "menu_",
UseShadow = true,
Items = new DayPilot.Web.Mvc.MenuItemCollection
{
new DayPilot.Web.Mvc.MenuItem { Text = "Open", Action = DayPilot.Web.Mvc.Enums.MenuItemAction.JavaScript, JavaScript = "alert(e.value());"},
new DayPilot.Web.Mvc.MenuItem { Text = "Delete", Action = DayPilot.Web.Mvc.Enums.MenuItemAction.CallBack, Command = "Delete"},
new DayPilot.Web.Mvc.MenuItem { Text = "Edit", Action = DayPilot.Web.Mvc.Enums.MenuItemAction.JavaScript, JavaScript = "editEvent(e)"},
}
})

@Html.DayPilotMenu("menu_disallow", new DayPilotMenuConfig
{
CssClassPrefix = "menu_",
UseShadow = true,
Items = new DayPilot.Web.Mvc.MenuItemCollection
{
new DayPilot.Web.Mvc.MenuItem { Text = "Open", Action = DayPilot.Web.Mvc.Enums.MenuItemAction.JavaScript, JavaScript = "alert(e.value());"},
new DayPilot.Web.Mvc.MenuItem { Text = "<span style='color:gray'>Delete</span>", Action = DayPilot.Web.Mvc.Enums.MenuItemAction.JavaScript, JavaScript = "void(0);"},
new DayPilot.Web.Mvc.MenuItem { Text = "<span style='color:gray'>Edit</span>", Action = DayPilot.Web.Mvc.Enums.MenuItemAction.JavaScript, JavaScript = "void(0);"}
}
})

When I define my calendar what should I set ContextMenu equal to so that I may use OnBeforeEventRender to specify which events the user is actually allowed to change?

Also, according to the code below, am I correctly setting ContextMenuClientName in OnBeforeEventRender?

protected override void OnBeforeEventRender(BeforeEventRenderArgs e)
{
if (user = admin || user = create_user)
{
// open context menu that allows for editing and deleting of this event
e.ContextMenuClientName = "menu_priveledged_user";
}

else
e.ContextMenuClientName = "menu_disallow";
}

Comment posted by brandon
12 years ago.

I've looked through your website and I found this page [http://blue-telescope.com/projects/10/files/Context-menu-_-DayPilot-for-ASP.pdf] and they both help but it seems like I'm doing everything as DayPilot likes.. Thanks in advance for any help.

Brandon

Answer posted by Dan Letecky [DayPilot]
12 years ago.

Yes, this is the correct way. You should set a default menu using ContextMenu. In this case it's either "menu_priveledged_user" or "menu_disallow". Then you should override this default value using OnBeforeEventRender, e.ContextMenuClientName.

If the default menu is set, it's enough to set values that are different from that in OnBeforeEventRender.

e.g. for ContextMenu = "menu_disallow" you can use:

protected override void OnBeforeEventRender(BeforeEventRenderArgs e) 
{ 
  if (user = admin || user = create_user) 
  { 
    // open context menu that allows for editing and deleting of this event 
    e.ContextMenuClientName = "menu_priveledged_user"; 
  }
} 

The menu helpers (@Html.DayPilotMenu(...)) should be placed above the calendar helper to make sure that the menu objects are available to the calendar.

Comment posted by brandon
12 years ago.

Thanks for the timely response; unfortunately, however, my problem persists. I have the default menu set to menu_disallow and--for the sake of testing--I try to change every other event's ContextMenuClientName (determined by even or odd ID number) to menu_privileged_user. I also change some things like color (from gray EventBackColor to red) and move-ability properties just to make sure it's actually catching every other event. It is. But still saying e.ContextMenuClientName = "menu_priveleged_user" doesn't seem to affect anything at all. I also tried changing my if statement. So i changed it to:

if (e.ContextMenuClientName == "menu_disallow" && Convert.ToInt32(e.Id) % 2 == 0)

Since menu_disallow is my default menu, would you happen to know why this if statement would suddenly be false in all cases? (shown by all my events being gray again).
My menu helpers are both above my calendar helper. I don't quite understand why this isn't working. No matter what I try I still get the same context menu across all the events and it's always the default menu I set in calendar.
As always, I appreciate the help and hope I've made my problem as clear as possible.

Brandon

Comment posted by Dan Letecky [DayPilot]
12 years ago.

Brandon,
Please let me check it. It looks like it might be an internal issue. What's the version of DayPilot you are using?

Comment posted by brandon
12 years ago.

I'm using DayPilot Pro for ASP .NET MVC version 1.4.5384.0

Answer posted by Dan Letecky [DayPilot]
12 years ago.

This turned out to be a bug. It's now fixed in the latest sandbox build (1.5.5402). There is a special demo page where you can test it:

http://mvc.daypilot.org/sandbox/Calendar/ContextMenu

e.ContextMenuClientName is always null because the default menu is not synchronized with the server.

Comment posted by brandon
12 years ago.

Great! This fixed the problem; now it works just as it's supposed to. Thanks a lot, Dan. Quick response much appreciated.

Comment posted by brandon
12 years ago.

Hey Dan I tried to also use a DayPilot Month on a different page and I get the same context menu issue. It just always uses the default context menu that I set when I created the dpm. Is it possible the same bug exists for Month? It's also possible I need to set the context menu a different way but again I've tried to do my research and I believe Month and Calendar are not too different.

Brandon

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