Ejemplo n.º 1
0
        // Invalid View
        private void AddInvalidView()
        {
            var votingNode = ContextNode as Voting;

            if (votingNode == null)
            {
                Controls.Add(new Literal {
                    Text = SenseNetResourceManager.Current.GetString("Voting", "ContextNodeError")
                });
                return;
            }

            if (votingNode.InvalidSurveyPage == null)
            {
                Controls.Add(new Literal {
                    Text = SenseNetResourceManager.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 = SenseNetResourceManager.Current.GetString("Voting", "ContentViewCreateError")
                });
                return;
            }

            Controls.Add(landingCv);
        }
        /// <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);
        }
Ejemplo n.º 3
0
        protected override void CreateChildControls()
        {
            var content = Content.Create(ContextNode);
            var view    = ContentView.Create(content, Page, ViewMode.Browse);

            Controls.Add(view);
        }
Ejemplo n.º 4
0
        protected override object GetModel()
        {
            if (ContextNode == null)
            {
                return(null);
            }

            var content = Content.Create(ContextNode);

            var qs = new QuerySettings();

            if (EnableAutofilters != FilterStatus.Default)
            {
                qs.EnableAutofilters = (EnableAutofilters == FilterStatus.Enabled);
            }
            if (EnableLifespanFilter != FilterStatus.Default)
            {
                qs.EnableLifespanFilter = (EnableLifespanFilter == FilterStatus.Enabled);
            }

            if (Top > 0)
            {
                qs.Top = Top;
            }
            if (State.Skip > 0)
            {
                qs.Skip = State.Skip;
            }

            if (!string.IsNullOrEmpty(State.SortColumn))
            {
                qs.Sort = new[] { new SortInfo {
                                      FieldName = State.SortColumn, Reverse = State.SortDescending
                                  } };
            }

            content.ChildrenQuerySettings = qs;
            content.ChildrenQueryFilter   = GetQueryFilter();

            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);
        }
Ejemplo n.º 5
0
        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());
        }
Ejemplo n.º 6
0
        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;
        }
Ejemplo n.º 7
0
        protected override object GetModel()
        {
            string subscriptionCtd;

            using (new SystemAccount())
            {
                var ctdFile = Node.LoadNode("/Root/System/Schema/ContentTypes/GenericContent/Subscription") as ContentType;
                if (ctdFile != null)
                {
                    using (var ctdStream = ctdFile.Binary.GetStream())
                    {
                        subscriptionCtd = RepositoryTools.GetStreamString(ctdStream);
                    }
                }
                else
                {
                    throw new InvalidOperationException("Subscription CTD not found.");
                }
            }
            var currentSite = PortalContext.Current.Site;
            var siteUrl     = PortalContext.Current.SiteUrl;

            if (this.User == null)
            {
                return(null);
            }

            // edit subscription or create new if not exists
            var subscription = Subscription.GetSubscriptionByUser(this.User.Path, this.ContentPath);

            if (subscription != null)
            {
                IsSubscriptionNew = false;
            }
            else
            {
                subscription = new Subscription()
                {
                    ContentPath = this.ContentPath,
                    Frequency   = NotificationFrequency.Immediately,
                    IsActive    = true,
                    UserEmail   = this.User.Email,
                    UserPath    = this.User.Path,
                    UserId      = this.User.Id,
                    UserName    = this.User.Name,
                    Language    = "en",
                    SitePath    = currentSite?.Path,
                    SiteUrl     = siteUrl
                };

                IsSubscriptionNew = true;
            }

            var sct = Content.Create(subscription, subscriptionCtd);
            var rch = sct.ContentHandler as Content.RuntimeContentHandler;

            rch?.SetIsNew(IsSubscriptionNew);

            return(sct);
        }
Ejemplo n.º 8
0
        // Thank You View
        private void AddThankYouView()
        {
            var votingNode = ContextNode as Voting;

            if (votingNode == null)
            {
                Controls.Add(new Literal {
                    Text = SenseNetResourceManager.Current.GetString("Voting", "ContextNodeError")
                });
                return;
            }

            if (votingNode.LandingPage == null)
            {
                Controls.Add(new Literal {
                    Text = SenseNetResourceManager.Current.GetString("Voting", "LandingPageError")
                });
                return;
            }
            var landingContent = Content.Create(votingNode.LandingPage);

            if (landingContent == null)
            {
                Controls.Add(new Literal {
                    Text = SenseNetResourceManager.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 = SenseNetResourceManager.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 = SenseNetResourceManager.Current.GetString("Voting", "CannotFindLink") });
            //        return;
            //    }

            //    lb.Text = SenseNetResourceManager.Current.GetString("Voting", "GoToResultLink");
            //    lb.Click += LbClick;
            //    lb.Visible = true;
            //}
        }
Ejemplo n.º 9
0
        protected override object GetModel()
        {
            var sf = Node.Load <SmartFolder>("/Root/System/RuntimeQuery");

            if (sf == null)
            {
                using (new SystemAccount())
                {
                    var systemFolder = Node.LoadNode("/root/system");
                    sf = new SmartFolder(systemFolder)
                    {
                        Name = "RuntimeQuery"
                    };
                    sf.Save();
                }
            }

            var model = Content.Create(sf);

            if (!this.AllowEmptySearch && SearchTextIsTooGeneric(this.QueryString))
            {
                this.ErrorMessage = "Please give a more specific search text";
                return(model);
            }

            sf.Query = ReplaceTemplates(this.QueryString);

            var baseModel = base.GetModel() as Content;

            if (baseModel != null)
            {
                model.ChildrenQueryFilter   = baseModel.ChildrenQueryFilter;
                model.ChildrenQuerySettings = baseModel.ChildrenQuerySettings;

                if (FilterByContext)
                {
                    var ctx = GetContextNode();
                    if (ctx != null)
                    {
                        //add filter: we search only under the current context
                        var excapedPath = ctx.Path.Replace("(", "\\(").Replace(")", "\\)");

                        sf.Query = ContentQuery.AddClause(sf.Query, string.Format("InTree:\"{0}\"", excapedPath), ChainOperator.And);
                    }
                }
            }

            ResultModel = model;

            return(model);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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 = SR.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), LogicalOperator.And), LogicalOperator.And);
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(sf.Query))
                    {
                        model.ChildrenDefinition.ContentQuery = ContentQuery.AddClause(model.ChildrenDefinition.ContentQuery, sf.Query, LogicalOperator.And);
                    }
                }
            }

            ResultModel = model;

            return(model);
        }
Ejemplo n.º 12
0
        // ================================================================================================ 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();
            }
        }
Ejemplo n.º 13
0
        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());
        }
Ejemplo n.º 14
0
        // Thank You View
        private void AddThankYouView()
        {
            var votingNode = ContextNode as Voting;

            if (votingNode == null)
            {
                Controls.Add(new Literal {
                    Text = SenseNetResourceManager.Current.GetString("Voting", "ContextNodeError")
                });
                return;
            }

            if (votingNode.LandingPage == null)
            {
                Controls.Add(new Literal {
                    Text = SenseNetResourceManager.Current.GetString("Voting", "LandingPageError")
                });
                return;
            }
            var landingContent = Content.Create(votingNode.LandingPage);

            if (landingContent == null)
            {
                Controls.Add(new Literal {
                    Text = SenseNetResourceManager.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 = SenseNetResourceManager.Current.GetString("Voting", "ContentViewCreateError")
                });
                return;
            }

            Controls.Add(landingCv);
        }
Ejemplo n.º 15
0
        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(State.SortColumn, 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, LogicalOperator.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);
        }
Ejemplo n.º 16
0
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            try
            {
                var ctn = ContextNode;
            }
            catch (SenseNetSecurityException)
            {
                Controls.Add(new Literal {
                    Text = SenseNetResourceManager.Current.GetString("Voting", "ContextNodePermissionError")
                });
                return;
            }

            // Check ContextNode is not null
            if ((ContextNode as Voting) == null)
            {
                Controls.Add(new Literal {
                    Text = SenseNetResourceManager.Current.GetString("Voting", "ContextNodeError")
                });
                return;
            }

            try
            {
                _currentContent = Content.Create(ContextNode);
            }
            catch (Exception)
            {
                Controls.Add(new Literal {
                    Text = SenseNetResourceManager.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.Now < validFrom || DateTime.Now >= 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 = SenseNetResourceManager.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 = SenseNetResourceManager.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 = SenseNetResourceManager.Current.GetString("Voting", "ResultAndVotingError")
                    });
                    break;
                }
            }

            ChildControlsCreated = true;
        }
Ejemplo n.º 17
0
        // Result View
        private void AddResultView()
        {
            var votingNode = ContextNode as Voting;

            if (votingNode == null)
            {
                Controls.Add(new Literal {
                    Text = SenseNetResourceManager.Current.GetString("Voting", "ContextNodeError")
                });
                return;
            }

            if (!IsResultAvalaibleBefore && VotingPortletMode == PortletMode.ResultOnly)
            {
                var c = Content.Create(votingNode.CannotSeeResultContentView);
                if (c == null)
                {
                    Controls.Add(new Literal {
                        Text = SenseNetResourceManager.Current.GetString("Voting", "ContentCreateError")
                    });
                    return;
                }

                var contentView = ContentView.Create(c, this.Page, ViewMode.Browse);
                if (contentView == null)
                {
                    Controls.Add(new Literal {
                        Text = SenseNetResourceManager.Current.GetString("Voting", "ContentViewCreateError")
                    });
                    return;
                }
                Controls.Add(contentView);
            }
            else
            {
                if (votingNode.ResultPageContentView != null)
                {
                    var contentView = ContentView.Create(_currentContent, Page, ViewMode.InlineNew, votingNode.ResultPageContentView.Path) as VotingResultContentView;

                    if (contentView == null)
                    {
                        Controls.Add(new Literal {
                            Text = SenseNetResourceManager.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 = SenseNetResourceManager.Current.GetString("Voting", "CannotFindLink")
                            });
                            return;
                        }
                        lb.Text    = SenseNetResourceManager.Current.GetString("Voting", "GoToVotingLink");
                        lb.Click  += MyLinkBClick;
                        lb.Visible = true;
                    }
                    return;
                }
                // When there is no result to show
                Controls.Add(new Literal {
                    Text = SenseNetResourceManager.Current.GetString("Voting", "NoResult")
                });
            }
        }
Ejemplo n.º 18
0
        private void BuildContentView(string contentTypeName, Node parent, ViewMode viewMode)
        {
            var viewPath = string.Empty;

            #region creates container)
            if (_container == null)
            {
                CreateContainer();
            }
            else
            {
                _container.Controls.Clear();
            }

            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(SR.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:
                        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
            {
                SnLog.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);
        }
Ejemplo n.º 19
0
        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)
            {
                SnLog.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;

            var postInfos = GatherPosts();

            posts = postInfos == null ? new List <PostInfo>() : postInfos.Take(PageSize).ToList();

            postsPlaceholder.Controls.Add(new Literal {
                Text = WallHelper.GetWallPostsMarkup(this.ContextNode.Path, posts)
            });

            if (ShowExecutionTime)
            {
                Timer.Stop();
            }

            base.CreateChildControls();
            this.ChildControlsCreated = true;
        }