/// <summary>
        /// Creates a new instance of this object with all of the members having the same value.
        /// Note: termed "Copy" and not "Clone" to avoid confusion of the scope of the copy made (http://stackoverflow.com/questions/78536/cloning-objects-in-c/78856#78856)
        /// </summary>
        /// <returns></returns>
        public CmsPageEditMenuAction Copy()
        {
            CmsPageEditMenuAction ret = new CmsPageEditMenuAction(this.ActionCategory, this.ActionItem, this.RequiredEditMode, this.SortOrdinal, this.doRenderToString);

            ret.CreateNewPageOptions = this.CreateNewPageOptions;
            return(ret);
        }
            public static string Logoff(CmsPageEditMenuAction action, CmsPage pageToRenderFor, CmsLanguage langToRenderFor)
            {
                string actionPagePath         = CmsConfig.getConfigValue("LoginPath", "/_login");
                NameValueCollection paramList = new NameValueCollection();

                paramList.Add("action", "logoff");
                string actionUrl = CmsContext.getUrlByPagePath(actionPagePath, paramList, langToRenderFor);

                return("<a href=\"" + actionUrl + "\"><strong>Logoff</strong></a>");
            }
            public static string ExitFromEditing(CmsPageEditMenuAction action, CmsPage pageToRenderFor, CmsLanguage langToRenderFor)
            {
                // return RenderLink("GotoEditModePath", "/_admin/action/gotoView", pageToRenderFor, langToRenderFor, "<strong>Exit from editing</strong>");

                NameValueCollection paramList = new NameValueCollection();

                paramList.Add("target", pageToRenderFor.ID.ToString());
                string url = CmsContext.getUrlByPagePath(CmsConfig.getConfigValue("GotoViewModePath", "/_admin/action/gotoView"), paramList, langToRenderFor);

                return("<input type=\"button\" onclick=\"window.location = '" + url + "';\" value=\"Exit from editing\">");
            }
 public void addCustomActionItem(CmsPageEditMenuAction newActionItem)
 {
     // -- if the custom item already exists, do not add it
     foreach (CmsPageEditMenuAction action in currentPageActions)
     {
         if (action.ActionItem == newActionItem.ActionItem && action.doRenderToString == newActionItem.doRenderToString)
         {
             return;
         }
     }
     currentPageActions.Add(newActionItem);
 }
            public static string SaveAndViewThisPage(CmsPageEditMenuAction action, CmsPage pageToRenderFor, CmsLanguage langToRenderFor)
            {
                StringBuilder js = new StringBuilder();

                js.Append("function FloatingEditMenuSubmit() {" + Environment.NewLine);
                js.Append(" submitting = true;" + Environment.NewLine);
                js.Append(" document.getElementById('" + HatCMS.Controls.StartEditForm.FormId + "').submit();" + Environment.NewLine);
                js.Append(" return false;" + Environment.NewLine);
                js.Append("}" + Environment.NewLine);
                pageToRenderFor.HeadSection.AddJSStatements(js.ToString());

                return("<input type=\"button\" onclick=\"return FloatingEditMenuSubmit();\" value=\"Save & view this page\">");
            }
            public static string CreateNewPage(CmsPageEditMenuAction action, CmsPage pageToRenderFor, CmsLanguage langToRenderFor)
            {
                action.CreateNewPageOptions = CmsCreateNewPageOptions.CreateInstanceWithDefaultsForCurrentUser(pageToRenderFor);
                NameValueCollection createPageParams = action.CreateNewPageOptions.GetCreatePagePopupParams();

                if (action.CreateNewPageOptions.RequiresUserInput())
                {
                    return(RenderPopupLink("CreateNewPagePath", "/_admin/createPage", createPageParams, pageToRenderFor, langToRenderFor, "<strong>Create</strong> a new sub-page", 500, 400));
                }
                else
                {
                    return(RenderLink("CreateNewPagePath", "/_admin/createPage", createPageParams, pageToRenderFor, langToRenderFor, "<strong>Create</strong> a new sub-page"));
                }
            }
            public static string RefreshEditLockStatus(CmsPageEditMenuAction action, CmsPage pageToRenderFor, CmsLanguage langToRenderFor)
            {
                CmsPageLockData lockData = pageToRenderFor.getCurrentPageLockData();
                StringBuilder   html     = new StringBuilder();

                if (lockData != null)
                {
                    html.Append("<strong>Editing is locked</strong><br />");
                    html.Append("Locked by: " + lockData.LockedByUsername + "<br />");
                    TimeSpan expiresIn  = TimeSpan.FromTicks(lockData.LockExpiresAt.Ticks - DateTime.Now.Ticks);
                    int      numMinutes = Convert.ToInt32(Math.Round(expiresIn.TotalMinutes));
                    html.Append("Lock expires in " + numMinutes + " minutes or when editing is complete<br />");
                    html.Append("<a href=\"" + pageToRenderFor.Url + "\">refresh status</a>");
                }
                return(html.ToString());
            }
            public static string SwitchEditLanguage(CmsPageEditMenuAction action, CmsPage pageToRenderFor, CmsLanguage langToRenderFor)
            {
                if (CmsConfig.Languages.Length > 1)
                {
                    pageToRenderFor.HeadSection.AddCSSStyleStatements(".FloatingLangCurrent { text-decoration: none; color: black; font-weight: bold; } ");
                    pageToRenderFor.HeadSection.AddCSSStyleStatements(".FloatingLangNotCurrent { text-decoration: underline; color: #444; font-weight: normal; } ");

                    List <string> shortCodes = new List <string>();
                    foreach (CmsLanguage lang in CmsConfig.Languages)
                    {
                        shortCodes.Add(lang.shortCode.ToLower().Trim());
                    }

                    StringBuilder js = new StringBuilder();
                    js.Length = 0;
                    js.Append("function FloatingEditMenuSelectLanguage(langCode){" + Environment.NewLine);
                    js.Append("     var codes = [" + StringUtils.Join(",", shortCodes.ToArray(), "'", "'") + "];" + Environment.NewLine);
                    js.Append("     for(var i=0; i< codes.length; i++){" + Environment.NewLine);
                    js.Append("         if (langCode == codes[i]){" + Environment.NewLine);
                    js.Append("             document.getElementById('lang_'+codes[i]).style.display = 'block';" + Environment.NewLine);
                    js.Append("             document.getElementById('langSel_'+codes[i]).className = 'FloatingLangCurrent';" + Environment.NewLine);
                    js.Append("         } else {" + Environment.NewLine);
                    js.Append("             document.getElementById('lang_'+codes[i]).style.display = 'none';" + Environment.NewLine);
                    js.Append("             document.getElementById('langSel_'+codes[i]).className = 'FloatingLangNotCurrent';" + Environment.NewLine);
                    js.Append("         }" + Environment.NewLine);
                    js.Append("     }" + Environment.NewLine);
                    js.Append("}" + Environment.NewLine);
                    pageToRenderFor.HeadSection.AddJSStatements(js.ToString());

                    List <string> links = new List <string>();
                    foreach (CmsLanguage lang in CmsConfig.Languages)
                    {
                        string linkClass = "FloatingLangNotCurrent";
                        if (lang == CmsContext.currentLanguage)
                        {
                            linkClass = "FloatingLangCurrent";
                        }
                        links.Add("<a href=\"#\" class=\"" + linkClass + "\" id=\"langSel_" + lang.shortCode.ToLower() + "\" onclick=\"FloatingEditMenuSelectLanguage('" + lang.shortCode.ToLower() + "'); return false;\">" + lang.shortCode + "</a>");
                    } // foreach

                    StringBuilder html = new StringBuilder();
                    html.Append("Edit Language: ");
                    html.Append(string.Join(" | ", links.ToArray()));
                    return(html.ToString());
                }
                return("");
            }
            public static string RemoveEditLock(CmsPageEditMenuAction action, CmsPage pageToRenderFor, CmsLanguage langToRenderFor)
            {
                CmsPageLockData     lockData  = pageToRenderFor.getCurrentPageLockData();
                NameValueCollection paramList = new NameValueCollection();
                StringBuilder       html      = new StringBuilder();

                // -- Kill lock link
                if (lockData.LockedByUsername == CmsContext.currentWebPortalUser.UserName || CmsContext.currentUserIsSuperAdmin)
                {
                    paramList.Clear();
                    paramList.Add("target", pageToRenderFor.ID.ToString());
                    paramList.Add("action", "logoff");
                    string killLockLink = CmsContext.getUrlByPagePath(CmsConfig.getConfigValue("KillLockPath", "/_admin/actions/killLock"), paramList);
                    html.Append("<a href=\"#\" onclick=\"EditMenuConfirmModal('Do you really want to remove the edit lock?','" + killLockLink + "',300, 300);\"><strong>Remove</strong> edit lock</a><br />");
                }
                return(html.ToString());
            }
            public static string DeleteThisPage(CmsPageEditMenuAction action, CmsPage pageToRenderFor, CmsLanguage langToRenderFor)
            {
                NameValueCollection paramList = new NameValueCollection();

                paramList.Add("target", pageToRenderFor.ID.ToString());

                string confirmText      = "Do you really want to delete this page?";
                int    numPagesToDelete = pageToRenderFor.getLinearizedPages().Keys.Count;

                if (numPagesToDelete > 1)
                {
                    confirmText = "Do you really want to delete this page and all " + (numPagesToDelete - 1) + " sub-pages?";
                }

                string deletePageUrl = CmsContext.getUrlByPagePath(CmsConfig.getConfigValue("DeletePagePath", "/_admin/actions/deletePage"), paramList, langToRenderFor);

                return("<a href=\"#\" onclick=\"EditMenuConfirmModal('" + confirmText + "','" + deletePageUrl + "',300, 300);\"><strong>Delete</strong> this page</a>");
            }
            public static string ViewCurrentPageRevisionInformation(CmsPageEditMenuAction action, CmsPage pageToRenderFor, CmsLanguage langToRenderFor)
            {
                StringBuilder       html    = new StringBuilder();
                CmsPageRevisionData revData = pageToRenderFor.getRevisionData(CmsContext.requestedPageVersionNumberToView);

                CmsPageRevisionData[] allRevs = pageToRenderFor.getAllRevisionData();
                bool isLiveVersion            = false;

                if (revData.RevisionNumber == allRevs[allRevs.Length - 1].RevisionNumber)
                {
                    isLiveVersion = true;
                }

                if (isLiveVersion)
                {
                    html.Append("Viewing live version");
                }
                else
                {
                    html.Append("Viewing page version #" + revData.RevisionNumber.ToString());
                }
                html.Append("<br />");
                html.Append("Saved by " + revData.RevisionSavedByUsername + "<br />");
                html.Append("on " + revData.RevisionSavedAt.ToString("d MMM yyyy") + " at " + revData.RevisionSavedAt.ToString("%h:mm tt") + "<br />");

                // revert to this revision
                if (isLiveVersion)
                {
                    html.Append("<a href=\"" + pageToRenderFor.Url + "\">view full edit menu</a>");
                }
                else
                {
                    html.Append("<a href=\"" + pageToRenderFor.Url + "\">go to live version</a>");
                }

                return(html.ToString());
            }
 public static string UserManagement(CmsPageEditMenuAction action, CmsPage pageToRenderFor, CmsLanguage langToRenderFor)
 {
     return(RenderPopupLink("EditUsersPagePath", "/_admin/EditUsers", pageToRenderFor, langToRenderFor, "<strong>User</strong> management", 500, 400));
 }
 public static string AdminReportsAndTools(CmsPageEditMenuAction action, CmsPage pageToRenderFor, CmsLanguage langToRenderFor)
 {
     return(RenderPopupLink("AuditPagePath", "/_admin/Audit", pageToRenderFor, langToRenderFor, "<strong>Admin</strong> reports &amp; tools", 700, 400));
 }
 public static string MoveThisPage(CmsPageEditMenuAction action, CmsPage pageToRenderFor, CmsLanguage langToRenderFor)
 {
     return(RenderPopupLink("MovePagePath", "/_admin/actions/movePage", pageToRenderFor, langToRenderFor, "<strong>Move</strong> this page", 500, 400));
 }
 public static string ChangeTemplate(CmsPageEditMenuAction action, CmsPage pageToRenderFor, CmsLanguage langToRenderFor)
 {
     return(RenderPopupLink("ChangePageTemplatePath", "/_admin/actions/changeTemplate", pageToRenderFor, langToRenderFor, "Change page template", 500, 400));
 }
 public static string ChangeMenuVisibility(CmsPageEditMenuAction action, CmsPage pageToRenderFor, CmsLanguage langToRenderFor)
 {
     return(RenderPopupLink("ChangeMenuVisibilityPath", "/_admin/actions/MenuVisibilityPopup", pageToRenderFor, langToRenderFor, "<strong>Change</strong> menu visibility", 650, 400));
 }
 public static string SortSubPages(CmsPageEditMenuAction action, CmsPage pageToRenderFor, CmsLanguage langToRenderFor)
 {
     return(RenderPopupLink("SortSubPagesPath", "/_admin/actions/sortSubPages", pageToRenderFor, langToRenderFor, "<strong>Sort</strong> sub-pages", 500, 400));
 }
 public static string ViewRevisions(CmsPageEditMenuAction action, CmsPage pageToRenderFor, CmsLanguage langToRenderFor)
 {
     return(RenderPopupLink("ViewRevisionsPagePath", "/_admin/ViewRevisions", pageToRenderFor, langToRenderFor, "Revisions", 500, 400));
 }
 public static int CompareBySortOrdinal(CmsPageEditMenuAction x, CmsPageEditMenuAction y)
 {
     return(x.SortOrdinal.CompareTo(y.SortOrdinal));
 }
 public static string EditThisPage(CmsPageEditMenuAction action, CmsPage pageToRenderFor, CmsLanguage langToRenderFor)
 {
     return(RenderLink("GotoEditModePath", "/_admin/action/gotoEdit", pageToRenderFor, langToRenderFor, "<strong>Edit</strong> this page"));
 }