private static HtmlBuilder Content(
     this HtmlBuilder hb,
     Context context,
     SiteSettings ss,
     long siteId,
     bool childMenu,
     NavigationMenu menu)
 {
     return(childMenu
         ? hb.ContentBody(
                context: context,
                ss: ss,
                siteId: siteId,
                childMenu: childMenu,
                menu: menu)
         : hb.Div(
                attributes: Attributes(
                    context: context,
                    ss: ss,
                    siteId: siteId,
                    menu: menu)
                .DataId(menu.MenuId)
                .Id(menu.Id),
                action: () => hb.ContentBody(
                    context: context,
                    ss: ss,
                    siteId: siteId,
                    childMenu: childMenu,
                    menu: menu)));
 }
Exemple #2
0
        private static string Text(
            Context context,
            SiteSettings ss,
            NavigationMenu menu)
        {
            switch (menu.Name)
            {
            case null:
            case "":
                return(null);

            case "{UserName}":
                return(SiteInfo.UserName(
                           context: context,
                           userId: context.UserId));

            case "{SiteSettingsDisplayName}":
                return(SiteSettingsDisplayName(
                           context: context,
                           ss: ss));

            default:
                return(Displays.Get(
                           context: context,
                           id: menu.Name));
            }
        }
        private static bool Check(
            Context context,
            SiteSettings ss,
            NavigationMenu menus)
        {
            var menuId = menus.MenuId;

            switch (menuId)
            {
            case "LockTableMenu_LockTable":
            case "LockTableMenu_UnlockTable":
            case "LockTableMenu_ForceUnlockTable":
                if (ss.IsTable())
                {
                    if (!ss.Locked())
                    {
                        return(menuId == "LockTableMenu_LockTable");
                    }
                    else if (ss.LockedTableUser.Id == context.UserId)
                    {
                        return(menuId == "LockTableMenu_UnlockTable");
                    }
                    else if (context.HasPrivilege)
                    {
                        return(menuId == "LockTableMenu_ForceUnlockTable");
                    }
                }
                return(false);

            case "ViewModelMenu_Index":
            case "ViewModelMenu_Calendar":
            case "ViewModelMenu_Crosstab":
            case "ViewModelMenu_Gantt":
            case "ViewModelMenu_BurnDown":
            case "ViewModelMenu_TimeSeries":
            case "ViewModelMenu_Kamban":
            case "ViewModelMenu_ImageLib":
                return((Def.ViewModeDefinitionCollection
                        .Where(mode => mode.ReferenceType == ss.ReferenceType)
                        .Where(mode => ss.EnableViewMode(
                                   context: context,
                                   name: mode.Name))
                        .Select(mode => mode.Name).ToList()).Contains(menuId.Substring(menuId.IndexOf("_") + 1)));

            default:
                return(true);
            }
        }
 private static HtmlBuilder ContentBody(
     this HtmlBuilder hb,
     Context context,
     SiteSettings ss,
     long siteId,
     bool childMenu,
     NavigationMenu menu)
 {
     if (menu.LinkParams == null &&
         menu.Url == null &&
         !childMenu)
     {
         return(hb
                .Span(css: menu.Icon)
                .Text(text: Text(
                          context: context,
                          ss: ss,
                          menu: menu)));
     }
     else
     {
         return(hb.A(
                    href: menu.Url
                    ?? Href(
                        context: context,
                        ss: ss,
                        siteId: siteId,
                        menu: menu)
                    ?? "javascript:void(0);",
                    target: menu.Target,
                    attributes: Attributes(
                        context: context,
                        ss: ss,
                        siteId: siteId,
                        childMenu: childMenu,
                        menu: menu),
                    action: () => hb
                    .Span(css: menu.Icon)
                    .Text(text: Text(
                              context: context,
                              ss: ss,
                              menu: menu))));
     }
 }
        private static string Href(
            Context context,
            SiteSettings ss,
            long siteId,
            NavigationMenu menu)
        {
            var linkParams = menu.LinkParams?.ConvertLinkParams(
                context: context,
                ss: ss,
                siteId: siteId);

            if (linkParams?.Any(o => o != null) != true)
            {
                return(null);
            }
            return(Locations.Get(
                       context: context,
                       parts: linkParams.ToArray()));
        }
 private static bool Check(
     Context context,
     SiteSettings ss,
     NavigationMenu menus,
     bool _using)
 {
     return(CheckRequest(
                type: context.Controller,
                paramList: menus.Controllers) &&
            CheckRequest(
                type: ss.ReferenceType,
                paramList: menus.ReferenceTypes) &&
            CheckRequest(
                type: context.Action,
                paramList: menus.Actions) &&
            Check(
                context: context,
                ss: ss,
                menus: menus) &&
            _using);
 }
        private static string Text(
            Context context,
            SiteSettings ss,
            NavigationMenu menu)
        {
            switch (menu.Name)
            {
            case null:
            case "":
                return(null);

            case "{UserName}":
                return(SiteInfo.UserName(
                           context: context,
                           userId: context.UserId));

            case "{SiteSettingsDisplayName}":
                return(SiteSettingsDisplayName(
                           context: context,
                           ss: ss));

            case "{ResponsiveDisplayName}":
                return(Parameters.Mobile.Responsive &&
                       context.Mobile &&
                       context.Responsive
                            ? Displays.DesktopDisplay(
                           context: context)
                            : Displays.MobileDisplay(
                           context: context));

            default:
                return(Displays.Get(
                           context: context,
                           id: menu.Name));
            }
        }
        private static bool Using(
            Context context,
            SiteSettings ss,
            string referenceType,
            long siteId,
            NavigationMenu menu)
        {
            var canManageGroups = context.UserSettings?.AllowGroupAdministration(context: context) == true;
            var canCreateGroups = context.UserSettings?.AllowGroupCreation(context: context) == true;
            var canManageSite   = siteId != 0 && context.CanManageSite(
                ss: ss,
                site: true);
            var canManageDepts         = Permissions.CanManageTenant(context: context);
            var canManageUsers         = Permissions.CanManageUser(context: context);
            var canManageRegistrations = Permissions.CanManageRegistrations(context: context);
            var canManageTenants       = Permissions.CanManageTenant(context: context) ||
                                         context.UserSettings?.EnableManageTenant == true;
            var canManageTrashBox = CanManageTrashBox(
                context: context,
                ss: ss);
            var canUseApi     = context.UserSettings?.AllowApi(context: context) == true;
            var canUnlockSite = ss.LockedTable() &&
                                ss.LockedTableUser.Id == context.UserId;

            switch (menu.MenuId)
            {
            case "NewMenu":
                return(ss.ReferenceType == "Sites" && context.Action == "index"
                        ? context.CanManageSite(ss: ss)
                        : ss.ReferenceType == "Groups"
                            ? canCreateGroups
                            : context.CanCreate(ss: ss) &&
                       ss.ReferenceType != "Wikis" &&
                       context.Action != "trashbox");

            case "ViewModeMenu":
                return(Def.ViewModeDefinitionCollection
                       .Any(o => o.ReferenceType == referenceType));

            case "SettingsMenu":
                return(canManageSite ||
                       canManageDepts ||
                       canManageGroups ||
                       canManageUsers ||
                       canUnlockSite);

            case "SettingsMenu_SiteSettings":
                return(canManageSite);

            case "SettingsMenu_DeptAdmin":
                return(canManageDepts);

            case "SettingsMenu_GroupAdmin":
                return(canManageGroups);

            case "SettingsMenu_UserAdmin":
                return(canManageUsers);

            case "SettingsMenu_Registrations":
                return(canManageRegistrations);

            case "SettingsMenu_TrashBox":
                return(canManageTrashBox);

            case "SettingsMenu_TenantAdmin":
                return(canManageTenants);

            case "SettingsMenu_ImportSitePackage":
                return(Parameters.SitePackage.Import &&
                       canManageSite &&
                       ss.IsSite(context: context) &&
                       ss.ReferenceType == "Sites" ||
                       (context.Controller == "items" &&
                        ss.SiteId == 0 &&
                        context.UserSettings?.AllowCreationAtTopSite(context: context) == true));

            case "SettingsMenu_ExportSitePackage":
                return(Parameters.SitePackage.Export &&
                       canManageSite &&
                       ss.IsSite(context: context));

            case "AccountMenu_ShowStartGuide":
                return(context.UserSettings?.ShowStartGuideAvailable(context: context) == true);

            case "AccountMenu_EditProfile":
                return(Parameters.Service.ShowProfiles);

            case "AccountMenu_ChangePassword":
                return(Parameters.Service.ShowChangePassword);

            case "AccountMenu_ApiSettings":
                return(Parameters.Api.Enabled &&
                       context.ContractSettings.Api != false &&
                       canUseApi);

            case "LockTableMenu_LockTable":
            case "LockTableMenu_ForceUnlockTable":
                return(canManageSite &&
                       ss.AllowLockTable == true);

            case "LockTableMenu_UnlockTable":
                return(ss.AllowLockTable == true);

            case "AccountMenu_Responsive":
                return(context.Mobile);

            default:
                return(true);
            }
        }
        private static HtmlAttributes Attributes(
            Context context,
            SiteSettings ss,
            long siteId,
            NavigationMenu menu,
            bool childMenu = true)
        {
            if (menu.Function == null)
            {
                return(new HtmlAttributes());
            }
            switch (menu.Function)
            {
            case "OpenImportDialog":
                return(new HtmlAttributes()
                       .OnClick("$p.openImportSitePackageDialog($(this));")
                       .DataAction("OpenImportSitePackageDialog")
                       .DataMethod("post"));

            case "OpenExportDialog":
                return(new HtmlAttributes()
                       .OnClick("$p.openExportSitePackageDialog($(this));")
                       .DataAction("OpenExportSitePackageDialog")
                       .DataMethod("post"));

            case "OpenChangePasswordDialog":
                return(new HtmlAttributes()
                       .OnClick("$p.openChangePasswordDialog($(this), 'ChangePasswordForm');")
                       .DataAction("OpenChangePasswordDialog")
                       .DataMethod("post"));

            case "DisplayStartGuide":
                return(new HtmlAttributes()
                       .OnClick("$p.setStartGuide(0,1);"));

            case "SendMainForm":
                return(new HtmlAttributes()
                       .OnClick("$p.send($(this),'MainForm');")
                       .DataAction(menu.Name)
                       .DataMethod("post"));

            case "CreateTemplates":
                return(childMenu
                        ? new HtmlAttributes()
                        : SiteIndex(
                           context: context,
                           ss: ss)
                                ? new HtmlAttributes()
                       .OnClick("$p.templates($(this));")
                       .DataAction("Templates")
                       .DataMethod("post")
                                : new HtmlAttributes());

            case "PostBack":
                var settingName = menu.MenuId.Substring(menu.MenuId.IndexOf("_") + 1);
                return(PostBack(
                           context: context,
                           ss: ss)
                            ? new HtmlAttributes().OnClick(
                           "$p.transition('" + Locations.ItemView(
                               context: context,
                               id: siteId,
                               action: settingName) + "')")
                            : new HtmlAttributes()
                       .OnClick("$p.viewMode($(this));")
                       .DataAction(settingName));

            case "Responsive":
                return(new HtmlAttributes()
                       .OnClick("$p.switchResponsive($(this));")
                       .DataAction(context.Responsive.ToString())
                       .DataMethod("post"));

            default:
                return(new HtmlAttributes());
            }
        }