コード例 #1
0
        //public override TabDefinition GetTabDefinition()
        public TabDefinition GetTabDefinition()
        {
            var groups = new List <GroupDefinition>();

            var listsettings = new List <ControlDefinition>();

            var listbutton = new ButtonDefinition()
            {
                Id                = "PageLayoutList",
                Title             = "PageLayouts",
                Image             = ImageLibrary.GetStandardImage(13, 1),
                CommandJavaScript = "ShowPagelayoutList();",
                TemplateAlias     = "c1"
            };

            listsettings.Add(listbutton);

            var settings = new GroupDefinition()
            {
                Id       = "PageLayouts",
                Title    = "Pagelayouts for this site",
                Sequence = "10",
                Template = GroupTemplateLibrary.SimpleTemplate,
                Controls = listsettings.ToArray()
            };

            groups.Add(settings);

            //int index = 0;
            //int sequence = 30;

            SPContentTypeId contentTypeId = (SPContentTypeId)SPContext.Current.ListItem[SPBuiltInFieldId.ContentTypeId];
            string          contentType   = SPContext.Current.ListItem[SPBuiltInFieldId.ContentType].ToString();
            //string id = SPContext.Current.ListItem[SPBuiltInFieldId.ContentTypeId].ToString();
            //SPContentTypeId contentTypeId = new SPContentTypeId(id);

            //foreach (string category in Categories)
            //{
            List <PageLayout> layouts = servicePageLayouts.GetPageLayouts().Where(n => n.ContenTypeId == contentTypeId).Select(n => n).ToList();

            layouts.AddRange(servicePageLayouts.GetPageLayouts().Where(n => n.ContenTypeId == contentTypeId.Parent).Select(n => n).ToList());
            layouts.AddRange(servicePageLayouts.GetPageLayouts().Where(n => n.ContenTypeId.Parent == contentTypeId).Select(n => n).ToList());

            if (layouts.Count > 0)
            {
                var controls = new List <ControlDefinition>();

                foreach (PageLayout item in layouts)
                {
                    ImageDefinition image = new ImageDefinition();
                    image.Url16 = item.Icon;
                    image.Url32 = item.Icon;

                    ToolTipDefinition tooltip = new ToolTipDefinition();
                    tooltip.Description = item.Description.ToString();
                    tooltip.Title       = item.Title;
                    tooltip.Image       = item.Preview;
                    tooltip.Class       = "tooltip_preview";

                    url = base.parentStateControl.ContextUri;


                    if (IsEditMode(this.Page))
                    {
                        url = WebPageStateControl.AddQueryStringParameter(WebPageStateControl.AddQueryStringParameter(url, "ControlMode", "Edit"), "DisplayMode", "Design");
                    }

                    url = WebPageStateControl.AddQueryStringParameter(url, "PageLayout", DateTime.Now.Ticks.ToString());

                    var button = new ButtonDefinition()
                    {
                        Id      = item.Title.Replace(" ", String.Empty).Trim(),
                        Title   = item.Title,
                        ToolTip = tooltip,
                        Image   = image,
                        CommandEnableJavaScript = "document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value == 0",
                        CommandJavaScript       = String.Format("ChangePageLayout('{0}','{1}','{2}')", this.ClientID, url, item.UniqueId),
                        TemplateAlias           = "c1"
                    };

                    controls.Add(button);
                }

                var group = new GroupDefinition()
                {
                    Id       = "PageLayouts",
                    Title    = "Pagelayouts for ContentType " + contentType,
                    Sequence = "10",
                    Template = GroupTemplateLibrary.SimpleTemplate,
                    Controls = controls.ToArray()
                };

                groups.Add(group);

                //sequence += 10;
                //index += 1;
            }
            //}
            if (groups.Count > 0)
            {
                return(new TabDefinition()
                {
                    Id = "Hemrika.SharePresence.Design",
                    Title = "Design",
                    Sequence = "120",
                    GroupTemplates = GroupTemplateLibrary.AllTemplates,
                    Groups = groups.ToArray()
                });
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
        public TabDefinition GetTabDefinition()
        {
            var groups = new List <GroupDefinition>();

            var maintenance = new List <ControlDefinition>();

            ToolTipDefinition tooltip = new ToolTipDefinition();

            tooltip.Description = String.Format("View all WebParts on page {0}.", SPContext.Current.ListItem.Title);
            tooltip.Title       = "WebParts on Page.";

            var button = new ButtonDefinition()
            {
                Id                = "WebpartMaintenance",
                Title             = "WebParts on Page",
                ToolTip           = tooltip,
                Image             = ImageLibrary.GetStandardImage(3, 4),
                CommandJavaScript = "ShowMaintenancePage(commandId, properties, sequence)"
            };

            maintenance.Add(button);

            button = new ButtonDefinition()
            {
                Id    = "WebPartInsert",
                Title = "WebPart Adder",
                Image = ImageLibrary.GetStandardImage(13, 9),
                CommandEnableJavaScript = "document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value == 1",
                CommandJavaScript       = "CoreInvoke('ShowWebPartAdder', 'insertWebPart');return false"
            };
            //CommandJavaScript = "window.LoadWPAdderOnDemand(); ShowWebPartAdder('insertWebPart')"

            maintenance.Add(button);

            var maintenancegroup = new GroupDefinition()
            {
                Id       = "Maintenance",
                Title    = "Maintenance",
                Sequence = "10",
                Template = GroupTemplateLibrary.SimpleTemplate,
                Controls = maintenance.ToArray()
            };

            groups.Add(maintenancegroup);

            if (WebPartManager.Zones.Count > 1)
            {
                var zones = new List <ControlDefinition>();

                var label = new LabelDefinition()
                {
                    Id            = "ZoneLabel",
                    Title         = "Select your Zone",
                    Image         = ImageLibrary.GetStandardImage(2, 4),
                    TemplateAlias = "c1",
                    ForId         = "ZoneDropDown"
                };

                zones.Add(label);

                var    choices = new List <ControlDefinition>();
                string choice  = string.Empty;
                foreach (WebPartZoneBase zone in WebPartManager.Zones)
                {
                    if (zone != null && zone.ID != "wpz")
                    {
                        tooltip             = new ToolTipDefinition();
                        tooltip.Description = String.Format("Add WebPart to {0} zone.", zone.DisplayTitle);
                        tooltip.Title       = zone.DisplayTitle;
                        if (string.IsNullOrEmpty(choice))
                        {
                            choice = zone.ID;
                        }

                        button = new ButtonDefinition()
                        {
                            Id                = zone.ID,
                            Title             = zone.DisplayTitle,
                            ToolTip           = tooltip,
                            Image             = ImageLibrary.GetStandardImage(13, 2),
                            TemplateAlias     = "c1",
                            CommandJavaScript = String.Format("SetWebpartZone('{0}')", zone.ID)
                        };
                        choices.Add(button);
                    }
                }

                var dropdown = new DropDownDefinition()
                {
                    Id                     = "ZoneDropDown",
                    ControlsSize           = ControlSize.Size32x32,
                    Title                  = "Zones",
                    InitialValueJavaScript = "'" + choice + "'",
                    Controls               = choices.ToArray()
                };

                zones.Add(dropdown);


                var Selectedlabel = new LabelDefinition()
                {
                    Id            = "SelectedZoneLabel",
                    Title         = "Selected Zone",
                    TemplateAlias = "c1"
                };

                zones.Add(Selectedlabel);

                var zonegroup = new GroupDefinition()
                {
                    Id       = "WebpartZone",
                    Title    = "WebpartZone",
                    Sequence = "20",
                    Template = GroupTemplateLibrary.ThreeRowTemplate,
                    Controls = zones.ToArray()
                };

                groups.Add(zonegroup);
            }

            int index    = 0;
            int sequence = 30;


            foreach (string category in Categories)
            {
                List <WebPartGalleryItem> buttons = Sources.Where(n => n.Category == category).Select(n => n).ToList();

                if (buttons.Count > 0)
                {
                    var controls = new List <ControlDefinition>();

                    foreach (WebPartGalleryItem item in buttons)
                    {
                        ImageDefinition image = new ImageDefinition();
                        image.Url16 = item.IconUrl;
                        image.Url32 = item.IconUrl;

                        button = new ButtonDefinition()
                        {
                            Id    = item.Title.Replace(" ", String.Empty).Trim(),
                            Title = item.Title,
                            Image = image,
                            CommandEnableJavaScript = "webpartzone != null",
                            CommandJavaScript       = String.Format("AddWebPartToPage('{0}','{1}')", this.ClientID, item.Id),
                            TemplateAlias           = "c1"
                        };

                        controls.Add(button);
                    }

                    var group = new GroupDefinition()
                    {
                        Id       = ((category != null) ? category.Replace(" ", string.Empty).Trim() : "None"),
                        Title    = (category != null) ? category : "None",
                        Sequence = sequence.ToString(),
                        Template = GroupTemplateLibrary.SimpleTemplate,
                        Controls = new ControlDefinition[]
                        {
                            new MRUSplitButtonDefinition()
                            {
                                Id           = "MRU" + ((category != null) ? category.Replace(" ", string.Empty).Trim() : "None"),
                                InitialItem  = controls[0].Id,
                                ControlsSize = ControlSize.Size32x32,
                                Controls     = controls.ToArray()
                            }
                        }
                    };

                    groups.Add(group);

                    sequence += 10;
                    index    += 1;
                }
            }
            if (groups.Count > 0)
            {
                return(new TabDefinition()
                {
                    Id = "Hemrika.SharePresence.Content",
                    Title = "Content",
                    Sequence = "110",
                    GroupTemplates = GroupTemplateLibrary.AllTemplates,
                    Groups = groups.ToArray()
                });
            }
            else
            {
                return(null);
            }
        }