private void AddThankYouPage() { var parent = Content.Load((int)this.Content["ParentId"]); Node landingPage = null; Node landingView = null; // elevation: we do not want to grant Open permission to the user for this technical content using (new SystemAccount()) { if (parent.Fields.ContainsKey("LandingPage") && parent.Fields.ContainsKey("PageContentView")) { landingPage = parent["LandingPage"] as Node; landingView = parent["PageContentView"] as Node; } } if (landingPage == null || landingView == null) { return; } var landingContent = Content.Create(landingPage); var landingCV = ContentView.Create(landingContent, this.Page, ViewMode.Browse, landingView.Path); _wizard.WizardSteps[_wizard.WizardSteps.Count - 1].Controls.Add(landingCV); _wizard.WizardSteps[_wizard.WizardSteps.Count - 2].AllowReturn = false; }
/// <summary> /// Gets the number of participants. /// </summary> /// <param name="item">The CalendarEvent item.</param> /// <returns>Number of approved participants.</returns> private static int GetNumberOfParticipants(Node item) { var regForm = item.GetReference <Node>("RegistrationForm"); if (regForm != null) { var qResult = ContentQuery.Query("+Type:eventregistrationformitem +ParentId:@0", new QuerySettings { EnableAutofilters = FilterStatus.Disabled, EnableLifespanFilter = FilterStatus.Disabled }, regForm.Id); var i = 0; foreach (var node in qResult.Nodes) { var subs = Content.Create(node); var guests = 0; int.TryParse(subs["GuestNumber"].ToString(), out guests); i += (guests + 1); } return(i); } return(0); }
// Invalid View private void AddInvalidView() { var votingNode = ContextNode as Voting; if (votingNode == null) { Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "ContextNodeError") }); return; } if (votingNode.InvalidSurveyPage == null) { Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "InvalidSurveyPageError") }); return; } var landingContent = Content.Create(votingNode.InvalidSurveyPage); var landingCv = ContentView.Create(landingContent, Page, ViewMode.Browse, "/Root/Global/contentviews/WebContentDemo/Browse.ascx"); if (landingCv == null) { Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "ContentViewCreateError") }); return; } Controls.Add(landingCv); }
protected override void CreateChildControls() { var content = Content.Create(ContextNode); var view = ContentView.Create(content, Page, ViewMode.Browse); Controls.Add(view); }
private static ListItem[] GetListItems(IEnumerable <ContentType> contentTypes, Node contextNode) { var dict = new SortedDictionary <string, string>(); if (contentTypes == null) { return(new ListItem[0]); } foreach (var contentType in contentTypes) { if (!SavingAction.CheckManageListPermission(contentType.NodeType, contextNode)) { continue; } var ct = Content.Create(contentType); var title = string.IsNullOrEmpty(ct.DisplayName) ? ct.Name : ct.DisplayName; if (!dict.ContainsKey(title)) { dict.Add(title, ct.Name); } } return(dict.Keys.Count == 0 ? new ListItem[0] : dict.Keys.Select(key => new ListItem(key, dict[key])).ToArray()); }
// Thank You View private void AddThankYouView() { var votingNode = ContextNode as Voting; if (votingNode == null) { Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "ContextNodeError") }); return; } if (votingNode.LandingPage == null) { Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "LandingPageError") }); return; } var landingContent = Content.Create(votingNode.LandingPage); if (landingContent == null) { Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "ContentCreateError") }); return; } var landingCv = ContentView.Create(landingContent, Page, ViewMode.Browse, votingNode.GetReference <Node>("LandingPageContentView") != null ? votingNode.GetReference <Node>("LandingPageContentView").Path : "/Root/Global/contentviews/WebContentDemo/Browse.ascx"); if (landingCv == null) { Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "ContentViewCreateError") }); return; } Controls.Add(landingCv); //if (MoreFilingIsEnabled && UserVoted && VotingPortletMode == PortletMode.VoteAndGotoResult) //{ // var lb = landingCv.FindControl("VotingAndResult") as LinkButton; // if (lb == null) // { // Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "CannotFindLink") }); // return; // } // lb.Text = ResourceManager.Current.GetString("Voting", "GoToResultLink"); // lb.Click += LbClick; // lb.Visible = true; //} }
private bool Update(Node original, Dictionary <string, string> import) { var content = Content.Create(original); bool success = false; foreach (var field in content.Fields) { if (import.ContainsKey(field.Key) && !string.IsNullOrEmpty(import[field.Key])) { success = field.Value.Parse(import[field.Key]); } } content.Save(); return(success); }
protected override object GetModel() { var sf = SmartFolder.GetRuntimeQueryFolder(); var model = Content.Create(sf); if (!this.AllowEmptySearch && SearchTextIsTooGeneric(this.QueryString)) { if (HttpContext.Current.Request.Params.AllKeys.Contains(QueryParameterName)) { this.ErrorMessage = SNSR.GetString(ContextSearchClass, "Error_GenericSearchExpression"); } return(model); } sf.Query = ReplaceTemplates(this.QueryString); var baseModel = base.GetModel() as Content; if (baseModel != null) { model.ChildrenDefinition = baseModel.ChildrenDefinition; model.ChildrenDefinition.PathUsage = PathUsageMode.NotUsed; if (FilterByContext) { var ctx = GetContextNode(); if (ctx != null) { //add filter: we search only under the current context var escapedPath = ctx.Path.Replace("(", "\\(").Replace(")", "\\)"); model.ChildrenDefinition.ContentQuery = ContentQuery.AddClause(model.ChildrenDefinition.ContentQuery, ContentQuery.AddClause(sf.Query, string.Format("InTree:\"{0}\"", escapedPath), ChainOperator.And), ChainOperator.And); } } else { if (!string.IsNullOrEmpty(sf.Query)) { model.ChildrenDefinition.ContentQuery = ContentQuery.AddClause(model.ChildrenDefinition.ContentQuery, sf.Query, ChainOperator.And); } } } ResultModel = model; return(model); }
// ================================================================================================ Methods protected override void OnInit(EventArgs e) { base.OnInit(e); if (this.ContextNode == null) { return; } if (ShowExecutionTime) { Timer.Start(); } UITools.AddScript(UITools.ClientScriptConfigurations.SNWallPath); UITools.AddPickerCss(); UITools.AddScript(UITools.ClientScriptConfigurations.SNPickerPath); // get items for content types drowpdown in dropbox var gc = new GenericContent(this.ContextNode, "Folder"); var newItems = GenericScenario.GetNewItemNodes(gc, ContentType.GetContentTypes()); string jsonData; using (var s = new MemoryStream()) { var workData = newItems.Select(n => new ContentTypeItem { value = n.Name, label = Content.Create(n).DisplayName }).OrderBy(n => n.label); var serializer = new DataContractJsonSerializer(typeof(ContentTypeItem[])); serializer.WriteObject(s, workData.ToArray()); s.Flush(); s.Position = 0; using (var sr = new StreamReader(s)) { jsonData = sr.ReadToEnd(); } } UITools.RegisterStartupScript("initdropboxautocomplete", string.Format("SN.Wall.initDropBox({0})", jsonData), this.Page); if (ShowExecutionTime) { Timer.Stop(); } }
private static ListItem[] GetOtherListItems(IEnumerable <Node> nodes, Node contextNode) { if (nodes == null) { return(new ListItem[0]); } var dict = new SortedDictionary <string, string>(); foreach (var node in nodes) { var displayName = string.Empty; var name = string.Empty; var c = node as GenericContent; var ctd = node as ContentType; if (ctd != null) // content type { if (!SavingAction.CheckManageListPermission(ctd.NodeType, contextNode)) { continue; } var content = Content.Create(ctd); displayName = content.DisplayName; name = content.Name; } else if (c != null) // content template { if (!SavingAction.CheckManageListPermission(c.NodeType, contextNode)) { continue; } var content = Content.Create(c); displayName = content.DisplayName; name = content.Path; } var validTitle = string.IsNullOrEmpty(displayName) ? name : displayName; if (!dict.ContainsKey(validTitle)) { dict.Add(validTitle, name); } } return(dict.Keys.Count == 0 ? new ListItem[0] : dict.Keys.Select(key => new ListItem(key, dict[key])).ToArray()); }
protected override object GetModel() { if (ContextNode == null) { return(null); } var content = Content.Create(ContextNode); var cdef = content.ChildrenDefinition; if (EnableAutofilters != FilterStatus.Default) { cdef.EnableAutofilters = EnableAutofilters; } if (EnableLifespanFilter != FilterStatus.Default) { cdef.EnableLifespanFilter = EnableLifespanFilter; } if (Top > 0) { cdef.Top = Top; } if (State.Skip > 0) { cdef.Skip = State.Skip; } if (!string.IsNullOrEmpty(State.SortColumn)) { cdef.Sort = new[] { new SortInfo { FieldName = State.SortColumn, Reverse = State.SortDescending } } } ; var filter = GetQueryFilter(); if (!string.IsNullOrEmpty(content.ChildrenDefinition.ContentQuery)) { // combine the two queries (e.g. in case of a Smart Folder or a container with a custom children query) if (!string.IsNullOrEmpty(filter)) { content.ChildrenDefinition.ContentQuery = ContentQuery.AddClause(content.ChildrenDefinition.ContentQuery, filter, ChainOperator.And); } } else { content.ChildrenDefinition.ContentQuery = filter; } content.XmlWriterExtender = writer => { }; switch (CollectionAxis) { case CollectionAxisMode.Children: return(content); case CollectionAxisMode.VersionHistory: var versionRoot = SearchFolder.Create(content.Versions); return(versionRoot); case CollectionAxisMode.ReferenceProperty: return(content); case CollectionAxisMode.External: return(SearchFolder.Create(RequestNodeList)); } return(null); }
private void BuildContentView(string contentTypeName, Node parent, ViewMode viewMode) { var viewPath = string.Empty; #region creates container) if (_container == null) { CreateContainer(); } else { _container.Controls.Clear(); //this.Controls.Remove(_container); } if (this._container.Parent == null) { this.Controls.Add(this._container); } #endregion #region creates new content or loads an existing one // when we are in InlineNew creates an empty content if (viewMode == ViewMode.InlineNew) { if (!string.IsNullOrEmpty(contentTypeName) && !((GenericContent)PortalContext.Current.ContextNode).IsAllowedChildType(contentTypeName)) { var ct = ContentType.GetByName(contentTypeName); this._errorMessage = string.Format(SNSR.GetString("SingleContentPortlet", "TypeIsNotAllowed"), ct != null ? Content.Create(ct).DisplayName : contentTypeName); ShowSimpleErrorMessage(); return; } _content = SNC.Content.CreateNew(contentTypeName, parent, string.Empty); } // when the portlet is in browse, edit, inlineedit states, loads the content if (viewMode == ViewMode.Browse || viewMode == ViewMode.Edit || viewMode == ViewMode.InlineEdit) { Node node = Node.LoadNode(this.AbsoulteContentPath); // check if can select a single node (ie smartfolderex) ICustomSingleNode singleNode = node as ICustomSingleNode; // select single node if (singleNode != null) { node = singleNode.SelectedItem(); } if (node == null) { _content = null; } else { _content = SNC.Content.Create(node); } } #endregion if (viewMode == ViewMode.InlineEdit || viewMode == ViewMode.Edit) { this._displayMode = GetViewModeName(ViewMode.Edit); } // if content does not exist stop creating controls. if (_content == null) { this._errorMessage = String.Format(HttpContext.GetGlobalResourceObject("SingleContentPortlet", "PathNotFound") as string, AbsoulteContentPath); return; } #region checks validity // if content is not valid, exit the method, and an empty contol will be shown to the user. if (this.ValidationSetting != ValidationOption.DontCheckValidity) { //Use cache setting for deciding if we need to check content expiration. //This code will not run if the user is in one of the administrator groups. //Equivalent to: !PortalContext.IsInAdminGroup(User.Current, AdminGroupPaths) if (PortalContext.Current.LoggedInUserCacheEnabled) { _validitySetting = GetValiditySetting(_content); if (_validitySetting != null) { // User has been set the ValidationSetting, // and checks the content will be displayed or not. // if the content is not visible, just return (and don't do anything else) // otherwise the content processing will be going on. switch (this.ValidationSetting) { case ValidationOption.ShowAllValid: if (!_validitySetting.ShowAllValidContent) { return; } break; case ValidationOption.ShowValidButArchived: if (!_validitySetting.ShowValidAndArchived) { return; } break; case ValidationOption.ShowValidButNotArchived: if (!_validitySetting.ShowValidAndNotArchived) { return; } break; case ValidationOption.DontCheckValidity: // not used default: break; } } } } #endregion viewPath = GetViewPath(); // try to create ContentView which contains all webcontrols of the content try { if (this.UseUrlPath) { _contentView = ContentView.Create(_content, this.Page, viewMode, String.IsNullOrEmpty(this.ContentViewPath) ? viewPath : this.ContentViewPath); } else { _contentView = ContentView.Create(_content, this.Page, viewMode, viewPath); } _container.Controls.Remove(_contentView); } catch (Exception e) //logged { Logger.WriteException(e); this._errorMessage = String.Format("Message: {0} {1} Source: {2} {3} StackTrace: {4} {5}", e.Message, Environment.NewLine, e.Source, Environment.NewLine, e.StackTrace, Environment.NewLine); return; } _contentView.UserAction += _contentView_UserAction; _contentView.CommandButtonsAction += _contentView_CommandButtonsAction; _container.Controls.Add(_contentView); }
// Result View private void AddResultView() { var votingNode = ContextNode as Voting; if (votingNode == null) { Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "ContextNodeError") }); return; } if (!IsResultAvalaibleBefore && VotingPortletMode == PortletMode.ResultOnly) { Content c; // elevation: we do not want to grant Open permission to the // user for the view, so we need to load it in elevated mode using (new SystemAccount()) { c = Content.Create(votingNode.CannotSeeResultContentView); } if (c == null) { Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "ContentCreateError") }); return; } var contentView = ContentView.Create(c, this.Page, ViewMode.Browse); if (contentView == null) { Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "ContentViewCreateError") }); return; } Controls.Add(contentView); } else { Node resultView = null; // elevation: we do not want to grant Open permission to the // user for the view, so we need to load it in elevated mode using (new SystemAccount()) { resultView = votingNode.ResultPageContentView; } if (resultView != null) { var contentView = ContentView.Create(_currentContent, Page, ViewMode.InlineNew, resultView.Path) as VotingResultContentView; if (contentView == null) { Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "ContentViewCreateError") }); return; } contentView.DecimalsInResult = this.DecimalsInResult; Controls.Add(contentView); if (MoreFilingIsEnabled && UserVoted && VotingPortletMode == PortletMode.VoteAndGotoResult) { var lb = contentView.FindControl("VotingAndResult") as LinkButton; if (lb == null) { Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "CannotFindLink") }); return; } lb.Text = ResourceManager.Current.GetString("Voting", "GoToVotingLink"); lb.Click += MyLinkBClick; lb.Visible = true; } return; } // When there is no result to show Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "NoResult") }); } }
protected override void CreateChildControls() { base.CreateChildControls(); try { var ctn = ContextNode; } catch (SecurityException) { Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "ContextNodePermissionError") }); return; } // Check ContextNode is not null if ((ContextNode as Voting) == null) { Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "ContextNodeError") }); return; } try { _currentContent = Content.Create(ContextNode); } catch (Exception) { Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "BindingError") }); return; } // Check portlets' field to wheter to check validTill and validFrom fields if (this.EnableLifeSpan) { DateTime validFrom = ContextNode.GetProperty <DateTime>("ValidFrom"); DateTime validTill = ContextNode.GetProperty <DateTime>("ValidTill"); if (validTill == DateTime.MinValue) { validTill = DateTime.MaxValue; } // Check if the voting is valid to fill it if (DateTime.UtcNow < validFrom || DateTime.UtcNow >= validTill) { AddInvalidView(); return; } } // ResultOnly PorletMode if (VotingPortletMode == PortletMode.ResultOnly) { AddResultView(); } // VotingOnly PorletMode else if (VotingPortletMode == PortletMode.VotingOnly) { switch (_myState) { case "VotingView": AddVotingView(); break; case "ThankYouView": AddThankYouView(); break; default: Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "VotingOnlyError") }); break; } } // VoteAndGotoResult PorletMode else if (VotingPortletMode == PortletMode.VoteAndGotoResult) { switch (_myState) { case "VotingView": if (MoreFilingIsEnabled || !UserVoted) { AddVotingView(); } else { AddResultView(); } break; case "ResultView": AddResultView(); break; case "ThankYouView": AddThankYouView(); AddResultView(); break; default: Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "VoteAndGotoResultError") }); break; } } // ResultAndVoting PorletMode else if (VotingPortletMode == PortletMode.ResultAndVoting) { switch (_myState) { case "VotingView": if (ViewsOrder == ViewOrders.VotingViewFirst) { AddVotingView(); AddResultView(); } else { AddResultView(); AddVotingView(); } break; case "ThankYouView": AddThankYouView(); break; case "ResultView": AddResultView(); break; default: Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "ResultAndVotingError") }); break; } } ChildControlsCreated = true; }
protected override void CreateChildControls() { if (this.ContextNode == null) { return; } if (ShowExecutionTime) { Timer.Start(); } System.Web.UI.Control control = null; try { var viewHead = NodeHead.Get(ControlPath); if (viewHead != null && SecurityHandler.HasPermission(viewHead, PermissionType.RunApplication)) { control = Page.LoadControl(ControlPath); this.Controls.Add(control); } } catch (Exception ex) { Logger.WriteException(ex); this.Controls.Add(new System.Web.UI.LiteralControl(ex.Message)); return; } if (control == null) { return; } _workspaceIsWallContainer = control.FindControlRecursive("WorkspaceIsWallContainer") as PlaceHolder; var portletContextNodeLink = control.FindControlRecursive("PortletContextNodeLink") as System.Web.UI.WebControls.HyperLink; var configureWorkspaceWall = control.FindControlRecursive("ConfigureWorkspaceWall") as Button; if (_workspaceIsWallContainer != null && configureWorkspaceWall != null) { _workspaceIsWallContainer.Visible = false; var ws = this.ContextNode as Workspace; if (ws != null && !ws.IsWallContainer && ws.Security.HasPermission(PermissionType.Save)) { _workspaceIsWallContainer.Visible = true; if (portletContextNodeLink != null) { portletContextNodeLink.Text = System.Web.HttpUtility.HtmlEncode(Content.Create(ws).DisplayName); portletContextNodeLink.NavigateUrl = ws.Path; } configureWorkspaceWall.Click += ConfigureWorkspaceWall_Click; } } var postsPlaceholder = control.FindControlRecursive("Posts"); List <PostInfo> posts; using (new OperationTrace("Wall - Gather posts")) { var postInfos = GatherPosts(); posts = postInfos == null ? new List <PostInfo>() : postInfos.Take(PageSize).ToList(); } using (new OperationTrace("Wall - Posts markup")) { postsPlaceholder.Controls.Add(new Literal { Text = WallHelper.GetWallPostsMarkup(this.ContextNode.Path, posts) }); } if (ShowExecutionTime) { Timer.Stop(); } base.CreateChildControls(); this.ChildControlsCreated = true; }