/// <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); }
protected void Page_Load(object sender, EventArgs e) { // Check if current device is desktop if ((CookieHelper.CurrentCookieLevel < CookieLevel.Essential) || (String.IsNullOrEmpty(DeviceContext.CurrentDeviceProfileName) && String.IsNullOrEmpty(DeviceProfileInfoProvider.GetOriginalCurrentDevicProfileName(CurrentSite.SiteName)))) { pnlContent.Visible = false; return; } bool useDesktop = ViewMode.IsLiveSite() ? ShowDesktopVersion : String.IsNullOrEmpty(DeviceContext.CurrentDeviceProfileName); lnkLink.Text = ContextResolver.ResolveMacros(useDesktop ? LinkContentDesktop : LinkContentMobile); }
/// <summary> /// Displays the provided error message if viewmode is non-LiveSite or hides the webpart if on LiveSite /// </summary> /// <param name="message">The error message.</param> private void ShowDesignErrorOrHide(string message) { if (!ViewMode.IsLiveSite()) { // Append a linebreak because of WP menu. lblError.Text = "<br />" + message; lblError.Visible = true; } else { Visible = false; } }
/// <summary> /// Initializes the control properties. /// </summary> protected void SetupControl() { if (!StopProcessing && AnalyticsHelper.IsLoggingEnabled(SiteContext.CurrentSiteName, DocumentContext.CurrentAliasPath) && Service.Resolve <IAnalyticsConsentProvider>().HasConsentForLogging()) { // If already in session or livesite .. do not register info calling if ((SessionHelper.GetValue("BrowserCapatibilities") == null) && ViewMode.IsLiveSite()) { Guid checkGuid = Guid.NewGuid(); String parameters = $"{LogResolution.ToString().ToLowerInvariant()},{LogColorDepth.ToString().ToLowerInvariant()},{LogOperatingSystem.ToString().ToLowerInvariant()},{LogSilverlight.ToString().ToLowerInvariant()},{LogJava.ToString().ToLowerInvariant()},{LogFlash.ToString().ToLowerInvariant()},'{ResolveUrl("~/CMSModules/WebAnalytics/Pages/Content/AnalyticsLog.aspx")}','{checkGuid.ToString()}'"; ScriptHelper.RegisterStartupScript(this, typeof(string), "BrowserCapatibilitiesInit", ScriptHelper.GetScript("collectBrowserData(" + parameters + ")")); ScriptHelper.RegisterScriptFile(Page, "~/CMSScripts/BrowserCapabilities.js"); SessionHelper.SetValue("BrowserCapatibilities", checkGuid.ToString()); } } }
/// <summary> /// Sets filter for document control (mydocuments,pending documents,approval,recent). /// </summary> private void SetDocumentFilter() { // Set Documents control ucDocuments.Visible = true; ucDocuments.Path = Path; ucDocuments.DocumentAge = DocumentAge; ucDocuments.DocumentName = DocumentName; ucDocuments.DocumentType = DocumentType; ucDocuments.ItemsPerPage = ItemsPerPage; ucDocuments.DisplayOnlyRunningSites = true; // Set OrderBy with sorting if ((ListingType == ListingTypeEnum.All) || ((ListingType != ListingTypeEnum.All) && (OrderBy != "type"))) { ucDocuments.OrderBy = OrderBy + " " + Sorting; } ucDocuments.SiteName = SiteName; ucDocuments.StopProcessing = false; ucDocuments.IsLiveSite = ViewMode.IsLiveSite(); }
/// <summary> /// Initializes the control properties. /// </summary> protected void SetupControl() { if (StopProcessing) { recBin.StopProcessing = true; } else { recBin.ObjectDisplayName = ObjectDisplayName; recBin.ObjectType = ObjectType; recBin.IsLiveSite = ViewMode.IsLiveSite(); recBin.ItemsPerPage = ItemsPerPage; recBin.IsSingleSite = true; recBin.SiteName = SiteContext.CurrentSiteName; recBin.RestrictUsers = false; if (!String.IsNullOrEmpty(OrderBy)) { recBin.OrderBy = OrderBy + " " + Sorting; } } }
private void addressForm_OnAfterDataLoad(object sender, EventArgs e) { if (!ViewMode.IsLiveSite()) { // Suppress form validation on Check-in/Check-out actions addressForm.StopProcessing = true; return; } CustomerInfo customer = ShoppingCart.Customer; AddressInfo address = addressForm.EditedObject as AddressInfo; // Preset personal name filed for new address and logged in user if ((customer != null) && (address != null) && (address.AddressID == 0) && string.IsNullOrEmpty(address.AddressPersonalName)) { address.AddressPersonalName = $"{customer.CustomerFirstName} {customer.CustomerLastName}".Trim(); } if (PropagateChangesOnPostback) { // Propagate changes on postback if there is address info in UIForm if (((CurrentCartAddress != null) || (address != null)) && RequestHelper.IsPostBack()) { // Set first time user current address for postback tax recalculation if (CurrentCartAddress == null) { CurrentCartAddress = address; } var formControl = addressForm.FieldControls["AddressCountryID"]; if (formControl != null) { formControl.Changed += CountrySelector_Changed; } } } }
/// <summary> /// Overridden CreateChildControls method. /// </summary> protected override void CreateChildControls() { Controls.Clear(); base.CreateChildControls(); if (!StopProcessing) { if (!CMSAbstractEditableControl.RequestEditViewMode(ViewMode, ContentID)) { ViewMode = ViewModeEnum.Preview; } // Create controls by actual page mode switch (ViewMode) { case ViewModeEnum.Edit: case ViewModeEnum.EditDisabled: { // Main editor panel pnlEditor = new Panel(); pnlEditor.ID = "pnlEditor"; pnlEditor.CssClass = "EditableImageEdit EditableImage_" + ContentID; pnlEditor.Attributes.Add("data-tracksavechanges", "true"); if (ImageWidth > 0) { pnlEditor.Style.Add(HtmlTextWriterStyle.Width, ImageWidth.ToString() + "px;"); } Controls.Add(pnlEditor); // Title label lblTitle = new Label(); lblTitle.EnableViewState = false; lblTitle.CssClass = "EditableTextTitle"; pnlEditor.Controls.Add(lblTitle); // Error label lblError = new Label(); lblError.EnableViewState = false; lblError.CssClass = "EditableTextError"; pnlEditor.Controls.Add(lblError); // Add image selector selPath = new ImageSelector(null, false); selPath.Culture = MembershipContext.AuthenticatedUser.PreferredUICultureCode; selPath.EnableOpenInFull = false; selPath.ID = "selPath"; selPath.UseImagePath = true; selPath.ImageCssClass = ImageCssClass; selPath.ImageStyle = ImageStyle; selPath.ShowTextBox = DisplaySelectorTextBox; selPath.DefaultValue = DefaultImage; selPath.AddCssClass("cms-bootstrap"); // Dialog configuration selPath.DialogConfig.ResizeToHeight = ResizeToHeight; selPath.DialogConfig.ResizeToWidth = ResizeToWidth; selPath.DialogConfig.ResizeToMaxSideSize = ResizeToMaxSideSize; pnlEditor.Controls.Add(selPath); selPath.Enabled = ViewMode.IsEdit(); selPath.IsLiveSite = ViewMode.IsLiveSite(); } break; default: { // Display content in non editing modes imgImage = new Image(); imgImage.ID = "imgImage"; imgImage.GenerateEmptyAlternateText = true; if (ImageCssClass != "") { imgImage.CssClass = ImageCssClass; } if (ImageStyle != "") { imgImage.Attributes.Add("style", ImageStyle); } imgImage.AlternateText = AlternateText; imgImage.ToolTip = AlternateText; imgImage.EnableViewState = false; Controls.Add(imgImage); } break; } } }
private void CustomerForm_OnAfterDataLoad(object sender, EventArgs e) { // Suppress form validation on Check-in/Check-out actions customerForm.StopProcessing = !ViewMode.IsLiveSite(); }
/// <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; } }