zoukankan      html  css  js  c++  java
  • 总结隐藏Ribbon菜单的方法

    1. 重载
    using (SPSite site = new SPSite("http://SP2010-01"))
    {
     using (SPWeb web = site.OpenWeb())
     {
      SPList list = web.Lists.TryGetList("Shared Documents");
      web.AllowUnsafeUpdates = true;
      SPUserCustomAction actionView = list.UserCustomActions.Add();
    
       StringBuilder newurl = new StringBuilder();
      newurl.AppendLine("<CommandUIExtension>");
      newurl.AppendLine("     <CommandUIDefinitions>");
      //Provide Location ID to hide the button
      newurl.AppendLine("        <CommandUIDefinition Location="Ribbon.Documents.New.NewFolder">");
      newurl.AppendLine("        </CommandUIDefinition>");
      newurl.AppendLine("    </CommandUIDefinitions>");
      newurl.AppendLine("</CommandUIExtension>");
    
       actionView.Location = "CommandUI.Ribbon";
      actionView.Title = "RemoveNewFolderButton";
      actionView.CommandUIExtension = newurl.ToString();
      actionView.Update();
    
       web.AllowUnsafeUpdates = true;
     }
    }
    2. 后台代码控制
    SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);
    if (ribbon != null)
    {
    ribbon.TrimById(“RibbonGroupId”);
    }

    3. 使用javascript控制

    需要引用到

    • Core.js
    • CUI.js
    • Init.js
    • SP.Ribbon.js
    //使用RIBBON API
    <asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
     
       <!-- ScriptLink tags for sp.js and CUI.js could go here if you wish -->
     
       <script language="javascript" type="text/javascript">
     
          function DoSomethingWithRibbon() {
             // Gets a reference to a CUI.Ribbon object (CUI.js)
             var ribbon = SP.Ribbon.PageManager.get_instance().get_ribbon();
     
             // Show me which tab is selected - will show
             // 'Ribbon.Read' if the Browse tab is selected.
             alert(ribbon.get_selectedTabId());
          }
     
          // Note: 'SOD' is an abbreviation for "Script on Demand"
          SP.SOD.executeOrDelayUntilScriptLoaded(function() {
     
             var pm = SP.Ribbon.PageManager.get_instance();
     
             pm.add_ribbonInited(function() {
                DoSomethingWithRibbon();
             });
     
             var ribbon = null;
             try
             {
                ribbon = pm.get_ribbon();
             }
             catch (e) { }
     
             if (!ribbon) {
                if (typeof(_ribbonStartInit) == "function")
                   _ribbonStartInit(_ribbon.initialTabId, false, null);
             }
             else {
                DoSomethingWithRibbon();
             }
          },
          "sp.ribbon.js");
       </script>
    </asp:Content>

    实用隐藏方法

    function hideEditRibbon() {
               var ribbon = SP.Ribbon.PageManager.get_instance().get_ribbon();
               // Set the tab to the “Browse” tab
               SelectRibbonTab("Ribbon.Read", true);
               // Remove the “Edit” tab from a list from from the ribbon.
               ribbon.removeChild('Ribbon.ListForm.Edit');
         }
    
         SP.SOD.executeOrDelayUntilScriptLoaded(function() {
    
               var pm = SP.Ribbon.PageManager.get_instance();
         
               pm.add_ribbonInited(function() {
                    hideEditRibbon();
               });
    
               var ribbon = null;
               try {
                    ribbon = pm.get_ribbon();
               }
               catch (e) { }
    
               if (!ribbon) {
                    if (typeof(_ribbonStartInit) == "function")
                          _ribbonStartInit(_ribbon.initialTabId, false, null);
               }
               else {
                    hideEditRibbon();
               }
         },
         "sp.ribbon.js");
  • 相关阅读:
    深入解析DC/OS 1.8 – 高可靠的微服务及大数据管理平台
    Mesos源码分析
    Openvswitch原理与代码分析(8): 修改Openvswitch代码添加自定义action
    Openvswitch原理与代码分析(7): 添加一条流表flow
    Openvswitch原理与代码分析(6):用户态流表flow table的操作
    Openvswitch原理与代码分析(5): 内核中的流表flow table操作
    Openvswitch原理与代码分析(4):网络包的处理过程
    Openvswitch原理与代码分析(3): openvswitch内核模块的加载
    Openvswitch原理与代码分析(2): ovs-vswitchd的启动
    Openvswitch原理与代码分析(1):总体架构
  • 原文地址:https://www.cnblogs.com/frankzye/p/3167779.html
Copyright © 2011-2022 走看看