/// <summary> /// Init event handler. /// </summary> protected override void OnInit(EventArgs e) { ucUIToolbar.ModuleName = MODULE_NAME; ucUIToolbar.ElementName = ELEMENT_NAME; // Set the viewmode according the the URL param if (ViewMode.IsLiveSite() && QueryHelper.Contains("viewmode")) { ViewModeEnum queryStringViewMode = ViewModeCode.GetPageEnumFromString(QueryHelper.GetString("viewmode", "livesite")); if (queryStringViewMode.IsEditLive()) { SetViewMode(queryStringViewMode); } } if (ViewMode.IsEditLive()) { // Check if there is required a redirect to the specific document if (QueryHelper.Contains("onsitenodeid")) { int nodeId = QueryHelper.GetInteger("onsitenodeid", 0); TreeProvider treeProvider = new TreeProvider(); TreeNode node = treeProvider.SelectSingleNode(nodeId); string url = URLHelper.ResolveUrl(DocumentURLProvider.GetUrl(node.NodeAliasPath, string.Empty /* ensure getting the link (not the linked document) */, node.NodeSiteName, RequestContext.CurrentURLLangPrefix)); URLHelper.Redirect(url); } } base.OnInit(e); }
/// <summary> /// Init event handler. /// </summary> protected override void OnInit(EventArgs e) { ucUIToolbar.ModuleName = MODULE_NAME; ucUIToolbar.ElementName = ELEMENT_NAME; // Set the viewmode according the the URL param if (ViewMode.IsLiveSite() && QueryHelper.Contains("viewmode")) { ViewModeEnum queryStringViewMode = ViewModeCode.GetPageEnumFromString(QueryHelper.GetString("viewmode", "livesite")); if (queryStringViewMode.IsEditLive()) { SetViewMode(queryStringViewMode); } } if (ViewMode.IsEditLive()) { // Check if there is required a redirect to the specific document if (QueryHelper.Contains("onsitenodeid")) { var nodeId = QueryHelper.GetInteger("onsitenodeid", 0); var treeProvider = new TreeProvider(); var node = treeProvider.SelectSingleNode(nodeId); var url = UrlResolver.ResolveUrl(DocumentURLProvider.GetUrl(node)); URLHelper.Redirect(url); } } base.OnInit(e); }
/// <summary> /// OnPreRender event /// </summary> protected override void OnPreRender(EventArgs e) { if (!ViewMode.IsEditLive()) { // Use the control visibility this.Visible = ucEditableImage.Visible; } base.OnPreRender(e); }
/// <summary> /// PreRender event handler. /// </summary> protected override void OnPreRender(EventArgs e) { if (ViewMode.IsEditLive()) { // Display workflow info message if (DocumentManager.Workflow != null) { string message = DocumentManager.GetDocumentInfo(true); if (!string.IsNullOrEmpty(message)) { ShowInformation(message); } } } base.OnPreRender(e); }
/// <summary> /// Handles reset button click. Resets zones of specified type to default settings. /// </summary> protected void btnReset_Click(object sender, EventArgs e) { // Security check if (!DisplayResetButton || !resetAllowed) { return; } PageInfo pi = DocumentContext.CurrentPageInfo; if (pi == null) { return; } // Delete user personalization info PersonalizationInfo up = PersonalizationInfoProvider.GetDashBoardPersonalization(MembershipContext.AuthenticatedUser.UserID, PortalContext.DashboardName, PortalContext.DashboardSiteName); PersonalizationInfoProvider.DeletePersonalizationInfo(up); // Clear cached page template if (pi.UsedPageTemplateInfo != null) { CacheHelper.TouchKey("cms.pagetemplate|byid|" + pi.UsedPageTemplateInfo.PageTemplateId); } // Make redirect to see changes after load string url = RequestContext.CurrentURL; if (ViewMode.IsEdit(true) || ViewMode.IsEditLive()) { // Ensure that the widgets will be loaded from the session layer (not from database) url = URLHelper.UpdateParameterInUrl(url, "cmscontentchanged", "true"); } URLHelper.Redirect(url); }
/// <summary> /// Registers script files for on-site editing /// </summary> /// <param name="pi">Current page info</param> private void RegisterEditScripts(PageInfo pi) { ScriptHelper.RegisterJQueryCookie(Page); StringBuilder script = new StringBuilder(); // Edit toolbar scripts if (ViewMode.IsEditLive()) { // Dialog scripts ScriptHelper.RegisterDialogScript(Page); // General url settings UIPageURLSettings settings = new UIPageURLSettings(); settings.AllowSplitview = false; settings.NodeID = pi.NodeID; settings.Culture = pi.DocumentCulture; settings.AdditionalQuery = "dialog=1"; // Edit document settings.Mode = "editform"; settings.Action = null; string editUrl = DocumentUIHelper.GetDocumentPageUrl(settings); settings.Mode = string.Empty; // Toolbar - Edit button script editUrl = URLHelper.RemoveParameterFromUrl(editUrl, "mode"); string scriptEdit = GetModalDialogScript(editUrl, "editpage"); // Delete document settings.Action = "delete"; string deleteUrl = DocumentUIHelper.GetDocumentPageUrl(settings); // Toolbar - Delete button script string scriptDelete = GetModalDialogScript(deleteUrl, "deletepage"); // User contributions - Delete item script string scriptDeleteItem = GetModalDialogScript(AddItemUrlParameters(deleteUrl), "deletepage"); // New document settings.Action = "new"; settings.AdditionalQuery += "&reloadnewpage=1"; string newUrl = DocumentUIHelper.GetDocumentPageUrl(settings); newUrl = AddNewItemUrlParameters(newUrl); // Include culture code newUrl = URLHelper.AddParameterToUrl(newUrl, "parentculture", preferredCultureCode); // Toolbar - New button script string scriptNew = GetModalDialogScript(newUrl, "newpage"); // Toolbar - Properties button script string scriptProperties = GetModalDialogScript(ResolveUrl("~/CMSModules/Content/CMSDesk/Properties/Properties_Frameset.aspx?mode=editlive&documentid=" + pi.DocumentID), "propertiespage"); // Display items from current level by default int nodeId = pi.NodeParentID; // If current level is root display first level if (nodeId == 0) { isRootDocument = true; nodeId = pi.NodeID; } // In page not found mode display first level if (nodeId == 0) { TreeProvider tp = new TreeProvider(cui); TreeNode tn = tp.SelectSingleNode(SiteContext.CurrentSiteName, "/", TreeProvider.ALL_CULTURES); if (tn != null) { nodeId = tn.NodeID; } } // Listing string listItemUrl = ResolveUrl("~/CMSModules/Content/CMSDesk/View/listing.aspx?dialog=1&wopenernodeid=" + pi.NodeID + "&nodeid=##id##"); string scriptListItem = GetModalDialogScript(listItemUrl.Replace("##id##", nodeId.ToString()), "listingpage"); // New culture string newCultureUrl = ResolveUrl("~/CMSModules/Content/CMSDesk/New/NewCultureVersion.aspx?nodeid=##id##&culture=##cult##&dialog=1"); script.Append(@" var OEIsRTL = ", (isRTL ? "true" : "false"), @"; var OECurrentNodeId = ", (DocumentContext.CurrentPageInfo != null) ? DocumentContext.CurrentPageInfo.NodeID : 0, @"; var OEIsMobile = ", (DeviceContext.CurrentDevice.IsMobile ? "true" : "false"), @"; var OEHdnPostbackValue = null; function NewDocument(parentId, classId, targetWindow) { OEClearZIndex(OEActiveWebPart); if (targetWindow == null) { ", scriptNew, @"; } else { targetWindow.location.href = '", newUrl, @"'; } } function EditDocument(nodeId, targetWindow) { OEClearZIndex(OEActiveWebPart); // Edit item button in repeaters and datalists var arg = 'editurl;' + nodeId; ", Page.ClientScript.GetCallbackEventReference(this, "arg", "OECallbackHandler", null), @"; } function SaveDocumentWidgets() { if (!CMSContentManager.contentModified()) { return false; } if (window.CMSContentManager) { CMSContentManager.allowSubmit = true; } ", ControlsHelper.GetPostBackEventReference(this, "savedocument"), @"; } function OECallbackHandler(arg, context) { ", GetModalDialogScript("arg", "editpage", false), @" } function DeleteDocument(nodeId) { OEClearZIndex(OEActiveWebPart); ", scriptDeleteItem, @" } function OnSiteToolbarAction(name) { ", checkChanges, @" switch(name) { case 'edit': ", scriptEdit, @" break; case 'properties': ", scriptProperties, @" break; case 'new': var parentId = OECurrentNodeId; var classId = 0; ", scriptNew, @" break; case 'delete': ", scriptDelete, @" break; case 'list': ", scriptListItem, @" break; default: alert('Required action is not implemented.'); } } function SelectNode(nodeId, parentNodeId) { var liu = '", listItemUrl, @"'; return liu.replace(/##id##/g, nodeId); } function NewDocumentCulture(nodeId, culture) { ", checkChanges, @" var liu = '", newCultureUrl, @"'; liu = liu.replace(/##id##/g, nodeId); liu = liu.replace(/##cult##/g, culture); ", GetModalDialogScript("liu", "newculture", false), @" } function OEEnsureHdnPostbackValue() { if (OEHdnPostbackValue == null) { OEHdnPostbackValue = document.getElementById('", hdnPostbackValue.ClientID, @"'); } } // Changes the device profile function ChangeDevice(device) { ", checkChanges, @" OEEnsureHdnPostbackValue(); OEHdnPostbackValue.value = device; ", ControlsHelper.GetPostBackEventReference(this, "changedeviceprofile"), @" } "); // Register jQuery ScriptHelper.RegisterJQueryDialog(Page); // Register OnSiteEdit script file ScriptHelper.RegisterScriptFile(Page, "DesignMode/OnSiteEdit.js"); ScriptHelper.RegisterScriptFile(Page, "~/CMSScripts/jquery/jquery-url.js"); } // Slider buttons scripts else if (ViewMode.IsLiveSite()) { script.Append(@" function OESlideSideToolbar() { // Hide the slider button in CMSDesk if (parent != this) { return; } var toolbarEl = document.getElementById('", pnlSlider.ClientID, @"'); toolbarEl.style.display = ""block""; // Show slider button toolbarEl.style.top = ""0px""; } // Display slider button jQuery(document).ready(function() { OESlideSideToolbar(); }); "); } script.Append(" function OnSiteEdit_ChangeEditMode(){", ControlsHelper.GetPostBackEventReference(this, "changeviewmode"), "} "); ControlsHelper.RegisterClientScriptBlock(this, Page, typeof(string), "OnSiteEditActions", ScriptHelper.GetScript(script.ToString())); }
/// <summary> /// Handles the Load event of the Page control. /// </summary> protected void Page_Load(object sender, EventArgs e) { // Do not process control by default StopProcessing = true; // Keep frequent objects cui = MembershipContext.AuthenticatedUser; PageInfo pi = DocumentContext.CurrentPageInfo; if (pi == null) { IsPageNotFound = true; pi = DocumentContext.CurrentCultureInvariantPageInfo ?? new PageInfo(); checkChanges = string.Empty; } ucUIToolbar.StopProcessing = true; // Get main UI element var element = UIElementInfoProvider.GetUIElementInfo(MODULE_NAME, ELEMENT_NAME); if (element == null) { return; } // Check whether user is authorized to edit page if ((pi != null) && AuthenticationHelper.IsAuthenticated() && cui.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Editor, SiteContext.CurrentSiteName) && ((IsPageNotFound && pi.NodeID == 0) || cui.IsAuthorizedPerTreeNode(pi.NodeID, NodePermissionsEnum.Read) == AuthorizationResultEnum.Allowed) && CMSPage.CheckUIElementAccessHierarchical(element, redirectToAccessDenied: false)) { // Enable processing StopProcessing = false; // Check whether the preferred culture is RTL isRTL = CultureHelper.IsUICultureRTL(); // Add link to CSS file CSSHelper.RegisterCSSLink(Page, "Design", "OnSiteEdit.css"); CSSHelper.RegisterBootstrap(Page); // Filter UI element buttons ucUIToolbar.OnButtonFiltered += ucUIToolbar_OnButtonFiltered; ucUIToolbar.OnButtonCreated += ucUIToolbar_OnButtonCreated; ucUIToolbar.OnGroupsCreated += ucUIToolbar_OnGroupsCreated; ucUIToolbar.IsRTL = isRTL; // Register edit script file RegisterEditScripts(pi); if (ViewMode.IsEditLive()) { popupHandler.Visible = true; IsLiveSite = false; MessagesPlaceHolder.IsLiveSite = false; MessagesPlaceHolder.Opacity = 100; // Keep content of editable web parts when saving the document changes if (!IsPageNotFound) { PortalManager.PreserveContent = true; } // Display warning in the Safe mode if (PortalHelper.SafeMode) { string safeModeText = GetString("onsiteedit.safemode") + "<br/><a href=\"" + RequestContext.RawURL.Replace("safemode=1", "safemode=0") + "\">" + GetString("general.close") + "</a> " + GetString("contentedit.safemode2"); string safeModeDescription = GetString("onsiteedit.safemode") + "<br/>" + GetString("general.seeeventlog"); // Display the warning message ShowWarning(safeModeText, safeModeDescription, ""); } ucUIToolbar.StopProcessing = false; // Ensure document redirection var redirectUrl = TreePathUtils.GetRedirectionUrl(pi); if (!String.IsNullOrEmpty(redirectUrl)) { redirectUrl = URLHelper.ResolveUrl(redirectUrl); ShowInformation(GetString("onsiteedit.redirectinfo") + " <a href=\"" + redirectUrl + "\">" + redirectUrl + "</a>"); } pnlUpdateProgress.Visible = true; } // Mode menu on live site else if (ViewMode.IsLiveSite()) { // Hide the edit panel, show only slider button pnlToolbarSpace.Visible = false; pnlToolbar.Visible = false; pnlSlider.Visible = true; icon.CssClass = "cms-icon-80 icon-edit"; icon.ToolTip = GetString("onsitedit.editmode"); pnlButton.Attributes.Add("onclick", "OnSiteEdit_ChangeEditMode();"); // Hide the OnSite edit button when displayed in CMSDesk pnlSlider.Style.Add("display", "none"); } } // Hide control actions for unauthorized users else { plcEdit.Visible = false; } }
/// <summary> /// Handles reset button click. Resets zones of specified type to default settings. /// </summary> protected void btnReset_Click(object sender, EventArgs e) { // Disable the reset action when document editing is not allowed (i.e. non-editable workflow step) if (!WidgetActionsEnabled) { resetAllowed = false; } // Security check if (!DisplayResetButton || !resetAllowed) { return; } PageInfo pi = CurrentPageInfo; if (pi == null) { return; } if ((zoneType == WidgetZoneTypeEnum.Editor) || (zoneType == WidgetZoneTypeEnum.Group)) { // Clear document webparts/group webparts TreeNode node = DocumentHelper.GetDocument(pi.DocumentID, TreeProvider); if (node != null) { bool updateDocument = true; if (zoneType == WidgetZoneTypeEnum.Editor) { if (ViewMode.IsEdit(true) || ViewMode.IsEditLive()) { // Do not save the document to the database, keep it in only in the memory updateDocument = false; // Get the default template widgets PortalContext.SaveEditorWidgets(pi.DocumentID, pi.UsedPageTemplateInfo.TemplateInstance.GetZonesXML(WidgetZoneTypeEnum.Editor)); } else { node.SetValue("DocumentWebParts", String.Empty); } ClearEditorWidgetsContent(node, pi.UsedPageTemplateInfo.TemplateInstance, updateDocument); // Delete all variants if (pi.UsedPageTemplateInfo != null) { foreach (WebPartZoneInstance zoneInstance in zoneInstances) { if (zoneInstance.WebPartsContainVariants) { VariantHelper.DeleteWidgetVariants(zoneInstance.ZoneID, pi.UsedPageTemplateInfo.PageTemplateId, node.DocumentID); } } } } else if (zoneType == WidgetZoneTypeEnum.Group) { node.SetValue("DocumentGroupWebParts", String.Empty); } if (updateDocument) { // Save the document DocumentHelper.UpdateDocument(node, TreeProvider); } } } else if (zoneType == WidgetZoneTypeEnum.User) { // Delete user personalization info PersonalizationInfo up = PersonalizationInfoProvider.GetUserPersonalization(MembershipContext.AuthenticatedUser.UserID, pi.DocumentID); PersonalizationInfoProvider.DeletePersonalizationInfo(up); // Clear cached values TreeNode node = DocumentHelper.GetDocument(pi.DocumentID, TreeProvider); if (node != null) { node.ClearCache(); } } else if (zoneType == WidgetZoneTypeEnum.Dashboard) { // Delete user personalization info PersonalizationInfo up = PersonalizationInfoProvider.GetDashBoardPersonalization(MembershipContext.AuthenticatedUser.UserID, PortalContext.DashboardName, PortalContext.DashboardSiteName); PersonalizationInfoProvider.DeletePersonalizationInfo(up); // Clear cached page template if (pi.UsedPageTemplateInfo != null) { CacheHelper.TouchKey("cms.pagetemplate|byid|" + pi.UsedPageTemplateInfo.PageTemplateId); } } // Make redirect to see changes after load string url = RequestContext.CurrentURL; if (ViewMode.IsEdit(true) || ViewMode.IsEditLive()) { // Ensure that the widgets will be loaded from the session layer (not from database) url = URLHelper.UpdateParameterInUrl(url, "cmscontentchanged", "true"); } URLHelper.Redirect(url); }