Exemplo n.º 1
0
        public void RaisePostBackEvent(string eventArgument)
        {
            SPContext.Current.Web.AllowUnsafeUpdates = true;
            Guid uniqueId = Guid.Empty;

            try
            {
                string[] eventArg = eventArgument.Split(new string[1] {
                    "#;"
                }, StringSplitOptions.None);

                SPWeb      rootWeb = SPContext.Current.Site.RootWeb;
                SPListItem item    = SPContext.Current.ListItem;

                if (!string.IsNullOrEmpty(eventArg[1]))
                {
                    PageLayout layout = servicePageLayouts.GetPageLayout(new Guid(eventArg[1]));

                    if (item != null && layout != null)
                    {
                        SPFile currentFile = item.File;
                        bool   checkout    = false;
                        if (currentFile != null && currentFile.Exists)
                        {
                            if (currentFile.CheckOutType == SPFile.SPCheckOutType.None && currentFile.RequiresCheckout)
                            {
                                currentFile.CheckOut();
                                checkout = true;
                            }
                        }

                        SPUser            suser     = null;
                        SPListItemVersion spversion = null;

                        SPListItemVersionCollection versions = item.Versions;
                        if (versions.Count > 0)
                        {
                            foreach (SPListItemVersion version in versions)
                            {
                                if (version.IsCurrentVersion)
                                {
                                    suser     = version.CreatedBy.User;
                                    spversion = version;
                                    item      = version.ListItem;
                                    break;
                                }
                            }
                        }

                        /*
                         * else
                         * {
                         *  listItem = file.ListItemAllFields;
                         * }
                         */

                        using (SPSite site = new SPSite(SPContext.Current.Web.Url, suser.UserToken))
                        {
                            SPWeb      spweb  = site.OpenWeb();
                            SPFile     spfile = spweb.GetFile(currentFile.UniqueId);
                            SPListItem spitem = spfile.Item.Versions.GetVersionFromLabel(spversion.VersionLabel).ListItem;


                            PublishingPageDesignFieldValue value = spitem[BuildFieldId.PublishingPageDesign] as PublishingPageDesignFieldValue;
                            value.Id    = layout.UniqueId;
                            value.Title = layout.Title;
                            value.Url   = layout.Url;

                            spitem[BuildFieldId.PublishingPageDesign] = value;

                            try
                            {
                                spitem.Fields[BuildFieldId.PublishingPageDesign].Update(true);
                            }
                            catch (Exception)
                            {
                            }

                            try
                            {
                                spitem.Update();
                            }
                            catch (Exception)
                            {
                            }

                            try
                            {
                                spitem.SystemUpdate(false);
                            }
                            catch (Exception)
                            {
                            }

                            try
                            {
                                spfile.Update();
                            }
                            catch (Exception)
                            {
                            }
                        }

                        uniqueId = layout.UniqueId;

                        //currentFile.Update();

                        if (checkout)
                        {
                            currentFile.CheckIn("Layout Changed", SPCheckinType.OverwriteCheckIn);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
                //result = ex;
            }
            SPContext.Current.Web.AllowUnsafeUpdates = false;

            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());

            base.parentStateControl.EnsureItemSavedIfEditMode(true);
            this.RefreshPageState();
            this.OnPageStateChanged();

            //base.ClearChildControlState();


            HtmlMeta refresh = new HtmlMeta();

            refresh.HttpEquiv = "refresh";
            refresh.Content   = "0;URL=" + url + "";
            this.Page.Header.Controls.Add(refresh);
            this.Page.Header.Controls.Add(new LiteralControl(Environment.NewLine));

            /*
             * if (IsEditMode(this.Page))
             * {
             *  SPUtility.Redirect("~/" + url, SPRedirectFlags.Trusted,HttpContext.Current);
             * }
             * else
             * {
             *  SPUtility.Redirect("~/" + base.parentStateControl.ContextUri, SPRedirectFlags.Trusted, HttpContext.Current);
             * }
             */
        }
Exemplo n.º 2
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);
            }
        }