Beispiel #1
0
        public override void RaisePostBackEvent(string eventArgument)
        {
            try
            {
                if (eventArgument == this.ClientSideCommandId)
                {
                    SPFile webPageFile = SPContext.Current.ListItem.File;
                    //PublishingPage publishingPage = PublishingPage.GetPublishingPage(SPContext.Current.ListItem);
                    WebPageStateControl parentStateControl = base.parentStateControl as WebPageStateControl;
                    if ((base.parentStateControl.EnsureItemSavedIfEditMode(false)))// && parentStateControl.EnsureSchedulingStateIsValid())
                    {
                        string directoryName   = Path.GetDirectoryName(webPageFile.Url);
                        string str2            = directoryName;
                        string checkInComments = this.Page.Request.Form[SPPageStateControl.InputCommentsClientId];

                        /*
                         * if (publishingPage.RequiresRouting)
                         * {
                         *  publishingPage = PublishingPage.Route(publishingPage, checkInComments);
                         *  str2 = Path.GetDirectoryName(publishingPage.Url);
                         * }
                         */
                        //SPFile file = publishingPage.ListItem.File;
                        if (webPageFile.CheckOutType != SPFile.SPCheckOutType.None)
                        {
                            webPageFile.CheckIn(checkInComments);
                            parentStateControl.OnPageStateChanged();
                            //ULS.SendTraceTag(0x38347468, ULSCat.msoulscat_CMS_Publishing, ULSTraceLevel.Medium, "Checked in current page: {0}", new object[] { file.ServerRelativeUrl });
                        }
                        Guid defaultContentApprovalWorkflowId = SPContext.Current.ListItem.ParentList.DefaultContentApprovalWorkflowId;
                        if (defaultContentApprovalWorkflowId != Guid.Empty)
                        {
                            //PublishAction.LaunchDefaultApprovalWorkflow(webPageFile.Item, defaultContentApprovalWorkflowId, webPageFile.Url.ToString());
                        }
                        else
                        {
                            if (webPageFile.Item.ParentList.EnableModeration)
                            {
                                webPageFile.Publish(checkInComments);
                                //ULS.SendTraceTag(0x38347469, ULSCat.msoulscat_CMS_Publishing, ULSTraceLevel.Medium, "Publishing current page: {0}", new object[] { file.ServerRelativeUrl });
                            }
                            string serverRelativeUrl = webPageFile.ServerRelativeUrl;

                            /*
                             * if (directoryName != str2)
                             * {
                             *  serverRelativeUrl = ConsoleUtilities.AddQueryStringParameterToUrl(serverRelativeUrl, "route", "1");
                             * }
                             * ConsoleUtilities.CleanRedirect(serverRelativeUrl, true, true);
                             */
                            SPUtility.Redirect(serverRelativeUrl, SPRedirectFlags.Trusted, HttpContext.Current);
                        }
                    }
                }
            }
            catch (SPException exception)
            {
                base.SetGenericErrorMessage(exception);
            }
        }
        public override void RaisePostBackEvent(string eventArgument)
        {
            try
            {
                if (eventArgument == this.ClientSideCommandId)
                {
                    //PublishingPage publishingPage = PublishingPage.GetPublishingPage(SPContext.Current.ListItem);
                    SPFile webPageFile = SPContext.Current.ListItem.File;
                    WebPageStateControl parentStateControl = base.parentStateControl as WebPageStateControl;
                    if ((base.parentStateControl.EnsureItemSavedIfEditMode(false)))// && parentStateControl.EnsureSchedulingStateIsValid())
                    {
                        string checkInComments = this.Page.Request.Form[SPPageStateControl.InputCommentsClientId];
                        string directoryName   = Path.GetDirectoryName(webPageFile.Url);
                        string str3            = directoryName;

                        /*
                         * if (publishingPage.RequiresRouting)
                         * {
                         *  publishingPage = PublishingPage.Route(publishingPage, checkInComments);
                         *  str3 = Path.GetDirectoryName(publishingPage.Url);
                         * }
                         */
                        //SPFile file = publishingPage.ListItem.File;
                        if (webPageFile.CheckOutType != SPFile.SPCheckOutType.None)
                        {
                            webPageFile.CheckIn(checkInComments, SPCheckinType.MajorCheckIn);
                            parentStateControl.OnPageStateChanged();
                            //ULS.SendTraceTag(0x38347465, ULSCat.msoulscat_CMS_Publishing, ULSTraceLevel.Medium, "Checked in current page: {0}", new object[] { file.ServerRelativeUrl });
                        }
                        Guid defaultContentApprovalWorkflowId = SPContext.Current.ListItem.ParentList.DefaultContentApprovalWorkflowId;
                        if (defaultContentApprovalWorkflowId != Guid.Empty)
                        {
                            //PublishAction.LaunchDefaultApprovalWorkflow(publishingPage.ListItem, defaultContentApprovalWorkflowId, publishingPage.Uri.ToString());
                        }
                        else
                        {
                            if (SPContext.Current.ListItem.ParentList.EnableMinorVersions)
                            {
                                webPageFile.Publish(checkInComments);
                            }
                            if (SPContext.Current.ListItem.ParentList.EnableModeration)
                            {
                                webPageFile.Approve(checkInComments);
                                //ULS.SendTraceTag(0x38347467, ULSCat.msoulscat_CMS_Publishing, ULSTraceLevel.Medium, "Approved current page: {0}", new object[] { file.ServerRelativeUrl });
                            }

                            RaisePostBackEventDelegate raisePostBackEventDelegate = new RaisePostBackEventDelegate(this.BaseRaisePostBackEvent);
                            (base.parentStateControl as WebPageStateControl).RaisePostBackEventForPageRouting(eventArgument, this, raisePostBackEventDelegate);

                            //string serverRelativeUrl = webPageFile.ServerRelativeUrl;
                            //SPUtility.Redirect(serverRelativeUrl, SPRedirectFlags.Trusted, HttpContext.Current);
                        }
                    }
                }
            }
            catch (SPException exception)
            {
                base.SetGenericErrorMessage(exception);
            }
        }
 public override void RaisePostBackEvent(string eventArgument)
 {
     if (eventArgument == this.ClientSideCommandId)
     {
         WebPageStateControl parentStateControl = base.parentStateControl as WebPageStateControl;
         //if (parentStateControl.EnsureSchedulingStateIsValid())
         //{
         if (base.WorkflowPostbackCommand != null)
         {
             base.RaisePostBackEvent(eventArgument);
         }
         else
         {
             base.ApproveFileWithComments();
             SPUtility.Redirect(base.parentStateControl.ContextUri, SPRedirectFlags.Trusted, HttpContext.Current);
         }
         //}
     }
 }
Beispiel #4
0
        /*
         * protected void Page_Load(object sender, EventArgs e)
         * {
         *  try
         *  {
         *      HtmlGenericControl body = this.Master.FindControl("body") as HtmlGenericControl;
         *      if (body != null)
         *      {
         *          body.Attributes.Add("onload", "if (typeof(_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper();");
         *      }
         *  }
         *  catch { };
         * }
         */

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            //EnsureChildControls();
            SPRibbon current = SPRibbon.GetCurrent(this.Page);

            if ((current != null) && HttpContext.Current.User.Identity.IsAuthenticated)
            {
                if (wpsc == null)
                {
                    wpsc = new WebPageStateControl();
                    this.Page.Controls.Add(wpsc);
                }

                WebPageSetHomePageHandler homepage = new WebPageSetHomePageHandler(wpsc);
                this.Controls.Add(homepage);

                ContentRibbon content = new ContentRibbon(wpsc);
                this.Controls.Add(content);

                DesignRibbon design = new DesignRibbon(wpsc);
                this.Controls.Add(design);

                CssRegistration.Register("/_layouts/Hemrika/WebSitePage/Hemrika.SharePresence.WebSite.css");

                TransformDialog();
                var manager    = new SPRibbonScriptManager();
                var methodInfo = typeof(SPRibbonScriptManager).GetMethod("RegisterInitializeFunction", BindingFlags.Instance | BindingFlags.NonPublic);
                methodInfo.Invoke(manager, new object[] { Page, "InitPageComponent", "/_layouts/Hemrika/WebSitePage/Hemrika.SharePresence.WebSite.Page.js", false, "Hemrika.SharePresence.WebSite.Page.PageComponent.initialize()" });

                current.CommandUIVisible = true;
                current.CheckForInitializationReadiness = true;
                current.MakeTabAvailable("Ribbon.Read", "WSSPageStateVisibilityContext");
                current.MakeTabAvailable("Ribbon.EditingTools", "WSSPageStateVisibilityContext");
                current.MakeTabAvailable("Ribbon.Hemrika.SharePresence.Page", "WSSPageStateVisibilityContext");
                current.MakeTabAvailable("Ribbon.Hemrika.SharePresence.Content", "WSSPageStateVisibilityContext");
                current.MakeTabAvailable("Ribbon.Hemrika.SharePresence.Design", "WSSPageStateVisibilityContext");
                current.MakeTabAvailable("Ribbon.Hemrika.SharePresence.SEO", "WSSPageStateVisibilityContext");
                current.MakeTabAvailable("Ribbon.Hemrika.SharePresence.Analytics", "WSSPageStateVisibilityContext");
                current.MakeTabAvailable("Ribbon.Hemrika.SharePresence.Settings", "WSSPageStateVisibilityContext");
                current.EnableVisibilityContext("WSSPageStateVisibilityContext");
                //current.DisableVisibilityContext("WSSWebPartPage");
                //Allow Browse button for visibility
                //current.TrimById(SPRibbon.ReadTabId);
                current.TrimById("Ribbon.WebPartPage", "WSSWebPartPage");
                current.TrimById("Ribbon.WikiPageTab", "WSSPageStateVisibilityContext");
                current.TrimById("Ribbon.EditingTools.CPEditTab.Layout.PageLayout", "WSSPageStateVisibilityContext");
                current.TrimById("Ribbon.WebPartInsert", "WSSPageStateVisibilityContext");
                current.TrimById("Ribbon.WebPartInsert.Tab", "WSSPageStateVisibilityContext");

                current.CommandUIVisible = true;
                //RegisterWebSitePage(this);

                //AlohaEditor(this);
            }
            else
            {
                EnsureChildControls();

                ScriptManager manager = ScriptManager.GetCurrent(Page);
                manager.LoadScriptsBeforeUI       = false;
                manager.AllowCustomErrorsRedirect = true;
                manager.ScriptMode = ScriptMode.Release;
                //Remove WPSC script block
                this.Page.ClientScript.RegisterStartupScript(typeof(SPWebPartManager), "WPSCScriptBlock", string.Empty);
            }

            //BlogConnector();
        }
Beispiel #5
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);
             * }
             */
        }
Beispiel #6
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);
            }
        }