Customization of WidgetTypeMenu

by berkay 2. December 2011 13:25

 

You can easily customize WidgetTypeMenu by  using WidgetTypeMenuPrepare event of DashboardSurface.

Below code sample shows how to load WidgetTypes to WidgetTypeMenu according to authorization.

 

protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //WidgetTypeMenuPrepare event helps to customize widget type menu
                surface.WidgetTypeMenuPrepare += new Kalitte.Dashboard.Framework.WidgetTypeMenuPrepareEventHandler(surface_WidgetTypeMenuPrepare);
          surface.DataBind();
            }
        }

        void surface_WidgetTypeMenuPrepare(object sender, Kalitte.Dashboard.Framework.WidgetTypeMenuPrepareEventArgs e)
        {
            //Gets all of widget types from provider.
            var widgets = DashboardFramework.GetAllWidgetTypes();
            foreach (var item in widgets)
            {
                bool hasAuthorization = false;
                //AuthorizationInfo provides authorization information of widget types
                foreach (var authorizationInfo in item.AuthorizationInfo)
                {
                    //Authorization checking
                    hasAuthorization = Thread.CurrentPrincipal.IsInRole(authorizationInfo.Role) && authorizationInfo.CanView;
                    if (hasAuthorization) break;
                }
                //WidgetTypeMenu items load from e.List which is List<WidgetTypeMenuItemData>
                //Adding widget type to WidgetTypeMenu  according to authorization
                if (hasAuthorization) e.List.Add(new WidgetTypeMenuItemData(item));
           }
        }

You can download more examples from here

Tags: