private void RefreshContextInfo() { var ci = FindContextInfo(this.ContextInfoID); if (ci == null) { this.ContextInfoID = null; } else { this.ContentPath = ci.Path; } if (this.Content != null) { return; } var ctx = ContextBoundPortlet.GetContextNodeForControl(this); if (ctx != null) { this.ContentPath = ctx.Path; } }
protected override void OnClick(EventArgs e) { base.OnClick(e); if (!string.IsNullOrEmpty(PortalContext.Current.BackUrl)) { var pbase = Page as PageBase; if (pbase != null) { pbase.Done(); } return; } if (string.IsNullOrEmpty(this.Target)) { return; } string redirectUrl = null; switch (this.Target.Trim().ToLower()) { case "parent": var contextNode = ContextBoundPortlet.GetContextNodeForControl(this) ?? PortalContext.Current.ContextNode; if (contextNode != null) { redirectUrl = contextNode.ParentPath; } break; case "currentsite": redirectUrl = "/"; break; case "currentworkspace": var cws = PortalContext.Current.ContextWorkspace; if (cws != null) { redirectUrl = cws.Path; } break; case "currentlist": var cl = PortalContext.Current.ContextWorkspace; if (cl != null) { redirectUrl = cl.Path; } break; } if (!string.IsNullOrEmpty(redirectUrl)) { HttpContext.Current.Response.Redirect(redirectUrl, true); } }
//======================================================================= Event handlers protected override void OnButtonClick(object sender, EventArgs e) { var button = sender as IButtonControl; if (button == null) { return; } switch (button.CommandName) { case "Reject": var reason = this.CommentsTextBox == null ? string.Empty : this.CommentsTextBox.Text; if (OnReject == null) { //retrieve the current content var gc = ContextBoundPortlet.GetContextNodeForControl(this) as GenericContent; if (gc == null) { return; } if (SavingAction.HasReject(gc)) { gc["RejectReason"] = reason; gc.Reject(); var p = Page as PageBase; if (p != null) { p.Done(false); } } } else { OnReject(sender, new VersioningActionEventArgs(VersioningAction.Reject, reason)); } break; } }
private Node GetContextNode() { if (PortalContext.Current == null) { return(null); } var contextNode = PortalContext.Current.ContextNode; if (UsePortletContext) { var portletcontext = ContextBoundPortlet.GetContextNodeForControl(this); if (portletcontext != null) { contextNode = portletcontext; } else { // workaround: we can't reach the obsolete singlecontent // portlet here, unless we use reflection... try { var scp = TypeResolver.GetType("SenseNet.Portal.Portlets.SingleContentPortlet"); if (scp != null) { var mm = scp.GetMethod("GetContextNodeForControl"); if (mm != null) { var singleNode = mm.Invoke(null, new[] { this }) as Node; if (singleNode != null) { contextNode = singleNode; } } } } catch (Exception ex) { // error loading single content portlet SnLog.WriteException(ex); } } } var selector = this.Selector == null ? string.Empty : this.Selector.ToLower(); switch (selector) { case "currentuser": contextNode = User.Current as Node; break; case "currentpage": contextNode = PortalContext.Current.Page; break; case "currentsite": contextNode = Portal.Site.GetSiteByNode(contextNode); break; case "currentlist": contextNode = ContentList.GetContentListForNode(contextNode); break; case "currentworkspace": contextNode = PortalContext.Current.ContextWorkspace; break; case "parentworkspace": { var portalContext = PortalContext.Current; Workspace ws = null; using (new SystemAccount()) ws = portalContext.ContextWorkspace != null?Workspace.GetWorkspaceForNode(portalContext.ContextWorkspace.Parent) : null; if (ws != null && !ws.Security.HasPermission(PermissionType.See)) { ws = null; } contextNode = ws; break; } case "currentapplicationcontext": var app = PortalContext.Current.GetApplicationContext(); if (app != null) { contextNode = app; } else if (!ReplaceNullWithContext) { contextNode = null; } break; case "currenturlcontent": var urlNodePath = HttpContext.Current.Request.Params[PortalContext.ContextNodeParamName]; contextNode = !string.IsNullOrEmpty(urlNodePath) ? Node.LoadNode(urlNodePath) : null; break; } if (!string.IsNullOrEmpty(ReferenceFieldName) && contextNode != null) { // need to create the content here for its fields var content = Content.Create(contextNode); if (content.Fields.ContainsKey(ReferenceFieldName)) { var refValue = content[ReferenceFieldName]; var list = refValue as IEnumerable <Node>; var single = refValue as Node; if (list != null) { contextNode = list.FirstOrDefault(); } else if (single != null) { contextNode = single; } else { contextNode = null; } } else { throw new InvalidOperationException(string.Format("Content of type {0} does not have a field named {1}", contextNode.NodeType.Name, ReferenceFieldName)); } } return(contextNode); }