Ejemplo n.º 1
0
        private void BuildAfterSubmitForm_ContentView(SNC.Content formitem)
        {
            if (CurrentForm == null)
            {
                return;
            }

            //FormItem fi = new FormItem(CurrentForm);
            //_cFormItem = SNC.Content.Create(fi);
            if (formitem == null && _formItemID != 0)
            {
                formitem = Content.Load(_formItemID);
            }

            if (formitem != null)
            {
                _cFormItem = formitem;

                _cvFormItem = ContentView.Create(_cFormItem, this.Page, ViewMode.New, AfterSubmitViewPath);

                _cvFormItem.ID = "cvAfterSubmitFormItem";
                //_cvFormItem.Init += new EventHandler(_cvFormItem_Init);
                _cvFormItem.UserAction += new EventHandler <UserActionEventArgs>(_cvAfterSubmitFormItem_UserAction);

                this.Controls.Add(_cvFormItem);
            }
            else if (!string.IsNullOrEmpty(AfterSubmitViewPath))
            {
                this.Controls.Add(Page.LoadControl(AfterSubmitViewPath));
            }
        }
Ejemplo n.º 2
0
        protected override void CreateChildControls()
        {
            var content = Content.Create(ContextNode);
            var view    = ContentView.Create(content, Page, ViewMode.Browse);

            Controls.Add(view);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        protected override void CreateChildControls()
        {
            var content = Repo.Content.Create(ContextNode);

            if (ContextNode.NodeType.IsInstaceOfOrDerivedFrom("ApprovalWorkflowTask"))
            {
                ContentView view = null;
                if (!string.IsNullOrEmpty(Renderer))
                {
                    view = ContentView.Create(content, Page, ViewMode.Browse, Renderer);
                }

                if (view == null)
                {
                    view = ContentView.Create(content, Page, ViewMode.Browse);
                }

                Controls.Add(view);

                if (RejectButton != null)
                {
                    RejectButton.Click += RejectButton_Click;
                }

                if (ApproveButton != null)
                {
                    ApproveButton.Click += ApproveButton_Click;
                }
            }

            ChildControlsCreated = true;
        }
Ejemplo n.º 5
0
        protected override void CreateChildControls()
        {
            try
            {
                var modelData = GetModel() as SN.Content;
                if (modelData == null)
                {
                    return;
                }

                if (!this.HasPermission)
                {
                    Controls.Add(new LiteralControl(HttpContext.GetGlobalResourceObject("Notification", "NotEnoughPermissions") as string));
                    return;
                }

                _contentView = ContentView.Create(modelData, Page, ViewMode.Edit, ContentViewPath);
                this.Controls.Add(_contentView);

                //add event handler
                if (this.SaveButton != null)
                {
                    this.SaveButton.Click += BtnSave_Click;
                }
            }
            catch (Exception ex)
            {
                Logger.WriteException(ex);
                Controls.Clear();
                Controls.Add(new LiteralControl("ContentView error: " + ex.Message));
            }
        }
        protected virtual void ProcessRegistration()
        {
            if (User.Current.Id != User.Visitor.Id)
            {
                WriteErrorMessageOnly(Configuration.AlreadyRegisteredUserMessage);
                return;
            }

            // creates an empty user
            _content = CreateNewUserContent(Configuration.DefaultDomainPath);
            if (_content == null)
            {
                return;
            }
            _content.ContentHandler.Created += ContentHandler_Created;
            // loads the publicregistration contentviews
            // and exception raises when registration contentview has not been found.)
            ChangeToAdminAccount();
            try
            {
                _contentView = String.IsNullOrEmpty(Configuration.NewRegistrationContentView)
                    ? ContentView.Create(_content, Page, ViewMode.InlineNew)
                    : ContentView.Create(_content, Page, ViewMode.New, Configuration.NewRegistrationContentView);
            }
            catch (Exception exc) //logged
            {
                Logger.WriteException(exc);
                WriteErrorMessageOnly(String.Format(HttpContext.GetGlobalResourceObject("PublicRegistrationPortlet", "ErrorCreatingContentView") as string, Configuration.NewRegistrationContentView));
                RestoreOriginalUser();
                return;
            }
            _contentView.UserAction += ContentView_UserAction_New;
            Controls.Add(_contentView);
            RestoreOriginalUser();
        }
Ejemplo n.º 7
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;
        }
        private void ProcessUpdateProfile()
        {
            _content = SNC.Content.Load(User.Current.Id);
            if (_content == null)
            {
                return; // todo: could not load current user content.
            }
            var currentUserNodeTypeName = ((Node)User.Current).NodeType.Name;

            if (currentUserNodeTypeName != Configuration.UserTypeName)
            {
                this.Controls.Clear();
                this.Controls.Add(new LiteralControl(HttpContext.GetGlobalResourceObject("PublicRegistrationPortlet", "UserTypeDoesNotMatch") as string));
                return; // todo: update only the correct UserType. It prevents that user updates his/her profile with another user type inlinenew contentview.
            }
            this.ChangeToAdminAccount();
            try
            {
                _contentView = String.IsNullOrEmpty(Configuration.EditProfileContentView)
                    ? ContentView.Create(this._content, this.Page, ViewMode.InlineEdit)
                    : ContentView.Create(this._content, this.Page, ViewMode.InlineEdit, Configuration.EditProfileContentView);
            }
            catch (Exception exc) //logged
            {
                Logger.WriteException(exc);
                WriteErrorMessageOnly(String.Format(HttpContext.GetGlobalResourceObject("PublicRegistrationPortlet", "ErrorCreatingContentView") as string, Configuration.EditProfileContentView));
                this.RestoreOriginalUser();
                return;
            }
            this._contentView.UserAction += new EventHandler <UserActionEventArgs>(ContentView_UserAction_Update);
            this.Controls.Add(this._contentView);
            this.RestoreOriginalUser();
        }
Ejemplo n.º 9
0
 private void CreateControls()
 {
     if (CurrentForm != null)
     {
         if (!CurrentForm.Security.HasPermission(PermissionType.AddNew))
         {
             try
             {
                 if (!string.IsNullOrEmpty(PermissionErrorViewPath))
                 {
                     _cvFormItem = ContentView.Create(SNC.Content.Create(CurrentForm), this.Page, ViewMode.Browse, PermissionErrorViewPath);
                     this.Controls.Add(_cvFormItem);
                 }
             }
             catch (Exception ex)
             {
                 Logger.WriteException(ex);
                 this.Controls.Clear();
                 this.Controls.Add(new LiteralControl("ContentView error: " + ex.Message));
             }
         }
         else
         {
             CreateNewFormItem();
         }
     }
 }
Ejemplo n.º 10
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.º 11
0
        protected override ContentView GetContentView(Content newContent)
        {
            if (!string.IsNullOrEmpty(ContentViewPath))
            {
                return(base.GetContentView(newContent));
            }

            var contentList = ContentList.GetContentListByParentWalk(GetContextNode());

            if (contentList != null)
            {
                //try to find a content view at /Root/.../MyList/WorkflowTemplates/MyWorkflow.ascx
                var wfTemplatesPath = RepositoryPath.Combine(contentList.Path, "WorkflowTemplates");
                var viewPath        = RepositoryPath.Combine(wfTemplatesPath, newContent.Name + ".ascx");

                if (Node.Exists(viewPath))
                {
                    return(ContentView.Create(newContent, Page, ViewMode.InlineNew, viewPath));
                }

                //try to find it by type name, still locally
                viewPath = RepositoryPath.Combine(wfTemplatesPath, newContent.ContentType.Name + ".ascx");

                if (Node.Exists(viewPath))
                {
                    return(ContentView.Create(newContent, Page, ViewMode.InlineNew, viewPath));
                }

                //last attempt: global view for the workflow type
                return(ContentView.Create(newContent, Page, ViewMode.InlineNew, "StartWorkflow.ascx"));
            }
            else
            {
                var viewPath     = string.Format("{0}/{1}/{2}", Repository.ContentViewFolderName, newContent.ContentType.Name, "StartWorkflow.ascx");
                var resolvedPath = string.Empty;
                if (!SkinManager.TryResolve(viewPath, out resolvedPath))
                {
                    resolvedPath = RepositoryPath.Combine(Repository.SkinGlobalFolderPath,
                                                          SkinManager.TrimSkinPrefix(viewPath));

                    if (!Node.Exists(resolvedPath))
                    {
                        resolvedPath = string.Empty;
                    }
                }

                if (!string.IsNullOrEmpty(resolvedPath))
                {
                    return(ContentView.Create(newContent, Page, ViewMode.InlineNew, resolvedPath));
                }
            }

            return(base.GetContentView(newContent));
        }
Ejemplo n.º 12
0
        protected override void CreateChildControls()
        {
            if (Cacheable && CanCache && IsInCache)
            {
                return;
            }

            Controls.Clear();

            var node = GetContextNode() as ContentList;

            if (node == null)
            {
                return;
            }

            var fieldName = FieldName;

            if (string.IsNullOrEmpty(fieldName))
            {
                return;
            }

            Content content = null;

            foreach (FieldSettingContent fieldSetting in node.FieldSettingContents)
            {
                if (fieldSetting.FieldSetting.Name.CompareTo(fieldName) != 0)
                {
                    continue;
                }

                content = Content.Create(fieldSetting);
                content.Fields[FieldSetting.AddToDefaultViewName].FieldSetting.VisibleEdit = FieldVisibility.Hide;
                break;
            }

            if (content == null)
            {
                return;
            }

            var contentView = String.IsNullOrEmpty(this.Renderer) ?
                              ContentView.Create(content, Page, ViewMode.InlineEdit) :
                              ContentView.Create(content, Page, ViewMode.InlineEdit, this.Renderer);

            Controls.Add(contentView);

            ChildControlsCreated = true;
        }
Ejemplo n.º 13
0
        protected override void CreateChildControls()
        {
            if (this.ContextNode == null)
            {
                return;
            }
            var content = Content.Create(this.ContextNode);
            var cv      = ContentView.Create(content, this.Page, ViewMode.InlineEdit, "$skin/contentviews/ContentList/IncomingEmailSettings.ascx");

            cv.UserAction += cv_UserAction;

            this.Controls.Add(cv);

            this.ChildControlsCreated = true;
        }
Ejemplo n.º 14
0
        private ContentView CreateContentView(Node node)
        {
            SNC.Content content = SNC.Content.Create(node);
            ContentView cv      = null;

            if (string.IsNullOrEmpty(this.CvFolderPath))
            {
                cv = ContentView.Create(content, this.Page, ViewMode.Query);
            }
            else
            {
                cv = ContentView.Create(content, this.Page, ViewMode.Query, this.CvFolderPath);
            }

            return(cv);
        }
        protected override void CreateChildControls()
        {
            var currentContent = ContentRepository.Content.Create(ContextNode);

            ReferenceField refField;

            try
            {
                refField = currentContent.Fields["FieldSettingContents"] as ReferenceField;
            }
            catch (Exception)
            {
                base.CreateChildControls();
                return;
            }


            if (refField != null)
            {
                var originalValue = refField.OriginalValue as List <Node>;

                _currentUserControl = LoadUserInterface(Page, GuiPath);

                var addedFields = from fs in originalValue where fs.Name.StartsWith("#") select fs;

                if (addedFields.Count() == 0)
                {
                    base.CreateChildControls();
                    return;
                }
            }

            if (!String.IsNullOrEmpty(SecondQuestionContentViewPath))
            {
                var contentView = ContentView.Create(currentContent, Page, ViewMode.InlineNew, SecondQuestionContentViewPath);
                Controls.Add(contentView);
            }
            else
            {
                Controls.Add(new Literal {
                    Text = "Voting already has a question."
                });
            }
        }
Ejemplo n.º 16
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.º 17
0
        private void SetControls()
        {
            var contextNode = PortalContext.Current.ContextNode;

            foreach (var templateName in templateNames)
            {
                var templateNode = contextNode.GetReference <Node>(string.Concat(templateName, "Page"));
                if (templateNode == null)
                {
                    continue;
                }

                var templateContent = ContentRepository.Content.Create(templateNode);

                var placeHolder     = this.FindControlRecursive(string.Concat("ph", templateName));
                var pageContentView = contextNode.GetReference <Node>("PageContentView").Path;
                var contentView     = ContentView.Create(templateContent, this.Page, ViewMode.Browse, pageContentView);

                if (placeHolder == null || contentView == null)
                {
                    continue;
                }

                placeHolder.Controls.Clear();
                placeHolder.Controls.Add(contentView);

                var btnEdit = this.FindControlRecursive(string.Concat("btnEdit", templateName)) as Button;

                if (btnEdit == null)
                {
                    continue;
                }

                if (SecurityHandler.HasPermission(contextNode, new[] { PermissionType.AddNew, PermissionType.Save }) &&
                    SecurityHandler.HasPermission(templateNode, PermissionType.Save))
                {
                    btnEdit.Visible = true;
                }
            }
        }
Ejemplo n.º 18
0
        //================================================================ Overrides

        protected override void CreateChildControls()
        {
            Controls.Clear();

            try
            {
                var viewControl = Page.LoadControl(ViewPath) as UserControl;
                if (viewControl == null)
                {
                    return;
                }

                Controls.Add(viewControl);

                // load rename contentview
                if (this.ContentViewPlaceHolder != null)
                {
                    var node    = GetContextNode();
                    var content = SenseNet.ContentRepository.Content.Create(node);
                    this.RenameContentView = ContentView.Create(content, this.Page, ViewMode.InlineEdit, this.ContentViewPath);

                    // manipulate contentview controls according to CTD visibility settings
                    if (content.Fields["DisplayName"].FieldSetting.VisibleEdit == SenseNet.ContentRepository.Schema.FieldVisibility.Hide)
                    {
                        DisplayNamePlaceHolder.Parent.Controls.Remove(DisplayNamePlaceHolder);
                        NameControl.AlwaysEditable = true;
                    }
                    this.ContentViewPlaceHolder.Controls.Add(this.RenameContentView);
                }

                BindEvents();
            }
            catch (Exception exc)
            {
                Logger.WriteException(exc);
            }

            ChildControlsCreated = true;
        }
        protected override void CreateChildControls()
        {
            if (this.ContextNode == null)
            {
                return;
            }
            var content = Content.Create(this.ContextNode);
            var cv      = ContentView.Create(content, this.Page, ViewMode.InlineEdit, "$skin/contentviews/ContentList/IncomingEmailSettings.ascx");

            // set default mailprocessworkflow
            var emailworkflow = content["IncomingEmailWorkflow"] as IEnumerable <SenseNet.ContentRepository.Storage.Node>;

            if (emailworkflow == null || emailworkflow.Count() == 0)
            {
                content["IncomingEmailWorkflow"] = Node.LoadNode("/Root/System/Schema/ContentTypes/GenericContent/Workflow/MailProcessorWorkflow");
            }

            cv.UserAction += new EventHandler <UserActionEventArgs>(cv_UserAction);

            this.Controls.Add(cv);

            this.ChildControlsCreated = true;
        }
Ejemplo n.º 20
0
        //-- Methods -----------------------------------------------------

        private void CreateNewFormItem()
        {
            if (CurrentForm == null)
            {
                return;
            }

            var act         = CurrentForm.GetAllowedChildTypes();
            var allowedType = act.FirstOrDefault(ct => ct.IsInstaceOfOrDerivedFrom("FormItem"));
            var typeName    = allowedType == null ? "FormItem" : allowedType.Name;

            _cFormItem = SNC.Content.CreateNew(typeName, CurrentForm, null);

            try
            {
                if (string.IsNullOrEmpty(ContentViewPath))
                {
                    _cvFormItem = ContentView.Create(_cFormItem, this.Page, ViewMode.New);
                }
                else
                {
                    _cvFormItem = ContentView.Create(_cFormItem, this.Page, ViewMode.New, ContentViewPath);
                }

                _cvFormItem.ID          = "cvNewFormItem";
                _cvFormItem.Init       += new EventHandler(_cvFormItem_Init);
                _cvFormItem.UserAction += new EventHandler <UserActionEventArgs>(_cvFormItem_UserAction);

                this.Controls.Add(_cvFormItem);
            }
            catch (Exception ex)         //logged
            {
                Logger.WriteException(ex);
                this.Controls.Clear();
                this.Controls.Add(new LiteralControl("ContentView error: " + ex.Message));
            }
        }
Ejemplo n.º 21
0
        protected override void CreateChildControls()
        {
            Controls.Clear();

            var genericContent = this.ContextNode as GenericContent;

            if (genericContent != null && genericContent.CheckInCommentsMode > CheckInCommentsMode.None && SavingAction.HasCheckIn(genericContent))
            {
                var content = Content.Create(genericContent);

                //we need to reset the comments field before displaying it
                content["CheckInComments"] = string.Empty;

                var contentView = ContentView.Create(content, Page, ViewMode.InlineEdit, RepositoryPath.Combine(Repository.ContentViewFolderName, "CheckIn.ascx"));

                if (contentView != null)
                {
                    contentView.CommandButtonsAction += ContentView_CommandButtonsAction;
                    Controls.Add(contentView);
                }
            }

            ChildControlsCreated = true;
        }
Ejemplo n.º 22
0
        // 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")
                });
            }
        }
Ejemplo n.º 23
0
        protected override void CreateChildControls()
        {
            if (Cacheable && CanCache && IsInCache)
            {
                return;
            }

            Controls.Clear();

            var node = GetContextNode();

            if (node == null)
            {
                if (this.RenderException != null)
                {
                    Controls.Clear();
                    Controls.Add(new System.Web.UI.WebControls.Label()
                    {
                        Text = string.Format("Error loading content view: {0}", this.RenderException.Message)
                    });
                }
                else
                {
                    Controls.Clear();
                    Controls.Add(new System.Web.UI.WebControls.Label()
                    {
                        Text = "Content could not be loaded"
                    });
                }
                ChildControlsCreated = true;
                return;
            }

            var content = Content.Create(node);

            var contentView = String.IsNullOrEmpty(ContentViewPath) ?
                              ContentView.Create(content, Page, ViewMode.InlineEdit) :
                              ContentView.Create(content, Page, ViewMode.InlineEdit, ContentViewPath);

            //workaround for the hack below: if cannot change the RenderMode of a
            //field control here, than set the default value for the whole content view
            //(we want to use the InlineView for the view, but Edit behavior for the controls...)
            //contentView.DefaultControlRenderMode = FieldControlRenderMode.Edit;

            contentView.CommandButtonsAction += new EventHandler <CommandButtonsEventArgs>(contentView_CommandButtonsAction);

            // backward compatibility: use eventhandler for contentviews using defaultbuttons and not commandbuttons
            contentView.UserAction += new EventHandler <UserActionEventArgs>(contentView_UserAction);

            try
            {
                Controls.Add(contentView);
            }
            catch (Exception ex)
            {
                Logger.WriteException(ex);

                this.Controls.Clear();

                var message = ex.Message.Contains("does not contain Field")
                                  ? string.Format("Content and view mismatch: {0}", ex.Message)
                                  : string.Format("Error: {0}", ex.Message);

                Controls.Add(new LiteralControl(message));
            }

            ChildControlsCreated = true;
        }
Ejemplo n.º 24
0
 protected virtual ContentView GetContentView(Content newContent)
 {
     return(String.IsNullOrEmpty(ContentViewPath) ?
            ContentView.Create(newContent, Page, ViewMode.InlineNew) :
            ContentView.Create(newContent, Page, ViewMode.InlineNew, ContentViewPath));
 }
Ejemplo n.º 25
0
        // Voting View
        private void AddVotingView()
        {
            var votingNode = ContextNode as Voting;

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

            if (votingNode.IsVotingAvailable)
            {
                if (votingNode.VotingPageContentView != null)
                {
                    var contentView = ContentView.Create(_currentContent, Page, ViewMode.Browse, votingNode.VotingPageContentView.Path);
                    if (contentView == null)
                    {
                        Controls.Add(new Literal {
                            Text = SenseNetResourceManager.Current.GetString("Voting", "ContentViewCreateError")
                        });
                        return;
                    }

                    //add ContentView to the Controls collection
                    Controls.Add(contentView);

                    var qph = contentView.FindControlRecursive("QuestionPlaceHolder") as PlaceHolder;
                    if (qph == null)
                    {
                        Controls.Clear();
                        Controls.Add(new Literal {
                            Text = SenseNetResourceManager.Current.GetString("Voting", "PlaceHolderError")
                        });
                        return;
                    }

                    var args = new object[0];

                    // Checks if Foldering is enabled and sets the parent depending on it
                    var parent     = FolderingEnabled ? GetFolder(ContextNode) : ContextNode;
                    var votingItem = Content.CreateNew("VotingItem", parent, null, args);

                    // If there is no question in the Voting (question is avalaible on the Voting Items under the Voting)
                    var isQuestionExist = votingItem.Fields.Any(a => a.Value.Name.StartsWith("#"));
                    if (!isQuestionExist)
                    {
                        Controls.Add(new Literal {
                            Text = SenseNetResourceManager.Current.GetString("Voting", "NoQuestion")
                        });
                        return;
                    }

                    var votingItemNewContentView = ContentView.Create(votingItem, Page, ViewMode.InlineNew);
                    if (votingItemNewContentView == null)
                    {
                        Controls.Add(new Literal {
                            Text = SenseNetResourceManager.Current.GetString("Voting", "ContentViewCreateError")
                        });
                        return;
                    }
                    votingItemNewContentView.ID          = "VotingItenContentView";
                    votingItemNewContentView.UserAction += VotingItemNewContentViewUserAction;

                    qph.Controls.Add(votingItemNewContentView);

                    if (!SecurityHandler.HasPermission(votingItemNewContentView.ContentHandler, PermissionType.AddNew))
                    {
                        var btn = votingItemNewContentView.FindControlRecursive("ActButton1") as Button;
                        if (btn != null)
                        {
                            btn.Visible = false;
                        }
                    }

                    if (MoreFilingIsEnabled && IsResultAvalaibleBefore && 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", "GoToResultLink");
                        lb.Click  += LbClick;
                        lb.Visible = true;
                    }
                    return;
                }
                // No content view is set
                Controls.Add(new Literal {
                    Text = SenseNetResourceManager.Current.GetString("Voting", "NoContentView")
                });
            }
            else
            {
                // When the user can only Vote once
                Controls.Add(new Literal {
                    Text = SenseNetResourceManager.Current.GetString("Voting", "OnlyOneVoteError")
                });
            }
        }
Ejemplo n.º 26
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.º 27
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.º 28
0
        protected override void CreateChildControls()
        {
            if (Cacheable && CanCache && IsInCache)
            {
                return;
            }

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

            if (this.RenderingMode == RenderMode.Ascx || this.RenderingMode == RenderMode.Native)
            {
                using (var traceOperation = Logger.TraceOperation("ContentPortlet.CreateChildControls", this.Name))
                {
                    Controls.Clear();

                    try
                    {
                        var node = GetContextNode();

                        if (node != null)
                        {
                            var         content     = Content.Create(node);
                            ContentView contentView = null;
                            if (!string.IsNullOrEmpty(Renderer))
                            {
                                contentView = ContentView.Create(content, Page, ViewMode.Browse, Renderer);
                            }
                            if (contentView == null)
                            {
                                contentView = ContentView.Create(content, Page, ViewMode.Browse);
                            }

                            if (contentView != null)
                            {
                                Controls.Add(contentView);
                            }
                            else
                            {
                                Controls.Clear();
                                Controls.Add(new System.Web.UI.WebControls.Label()
                                {
                                    Text = SR.GetString(SR.Exceptions.ContentView.NotFound)
                                });
                            }
                        }
                        else if (this.RenderException != null)
                        {
                            Controls.Clear();
                            Controls.Add(new System.Web.UI.WebControls.Label()
                            {
                                Text = string.Format("Error loading content view: {0}", this.RenderException.Message)
                            });
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.WriteException(e);
                        Controls.Clear();
                        Controls.Add(new System.Web.UI.WebControls.Label()
                        {
                            Text = string.Format("Error loading content view: {0}", e.Message)
                        });
                    }

                    ChildControlsCreated        = true;
                    traceOperation.IsSuccessful = true;
                }
            }

            if (ShowExecutionTime)
            {
                Timer.Stop();
            }
        }
Ejemplo n.º 29
0
        protected override void CreateChildControls()
        {
            if (Cacheable && CanCache && IsInCache)
            {
                return;
            }

            Controls.Clear();

            var node = GetContextNode();

            if (node == null)
            {
                if (this.RenderException != null)
                {
                    Controls.Clear();
                    Controls.Add(new System.Web.UI.WebControls.Label()
                    {
                        Text = string.Format("Error loading content view: {0}", this.RenderException.Message)
                    });
                }
                else
                {
                    Controls.Clear();
                    Controls.Add(new System.Web.UI.WebControls.Label()
                    {
                        Text = "Content could not be loaded"
                    });
                }
                ChildControlsCreated = true;
                return;
            }

            var content = Content.Create(node);

            var contentView = String.IsNullOrEmpty(ContentViewPath) ?
                              ContentView.Create(content, Page, ViewMode.InlineEdit) :
                              ContentView.Create(content, Page, ViewMode.InlineEdit, ContentViewPath);

            if (contentView == null)
            {
                this.Controls.Clear();
                this.Controls.Add(new System.Web.UI.WebControls.Label {
                    Text = SR.GetString(SR.Exceptions.ContentView.NotFound)
                });

                return;
            }

            contentView.CommandButtonsAction += new EventHandler <CommandButtonsEventArgs>(contentView_CommandButtonsAction);

            // backward compatibility: use eventhandler for contentviews using defaultbuttons and not commandbuttons
            contentView.UserAction += new EventHandler <UserActionEventArgs>(contentView_UserAction);

            try
            {
                Controls.Add(contentView);
            }
            catch (Exception ex)
            {
                SnLog.WriteException(ex);

                this.Controls.Clear();

                var message = ex.Message.Contains("does not contain Field")
                                  ? string.Format("Content and view mismatch: {0}", ex.Message)
                                  : string.Format("Error: {0}", ex.Message);

                Controls.Add(new LiteralControl(message));
            }

            ChildControlsCreated = true;
        }
Ejemplo n.º 30
0
        protected virtual void BuildSearchForm()
        {
            if (string.IsNullOrEmpty(SearchFormCtd))
            {
                return;
            }
            var nt = (from t in ActiveSchema.NodeTypes
                      where t.NodeTypePath.Equals(SearchFormCtd.Remove(0, 33))
                      select t).FirstOrDefault();

            if (nt == null)
            {
                return;
            }

            var c = Content.CreateNew(nt.Name, Repository.Root, null);

            var s = State;

            if (_state != null && !string.IsNullOrWhiteSpace(_state.ExportQueryFields))
            {
                var xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(_state.ExportQueryFields);
                XmlNodeList allFields           = xmlDoc.SelectNodes("/ContentMetaData/Fields/*");
                var         transferringContext = new ImportContext(allFields, "", c.Id == 0, true, false);
                //import flat properties
                c.ImportFieldData(transferringContext, false);
                //update references
                transferringContext.UpdateReferences = true;
                c.ImportFieldData(transferringContext, false);
            }

            //override content filed from url parameters
            foreach (KeyValuePair <string, Field> keyValuePair in c.Fields)
            {
                var portletSpecKey = GetPortletSpecificParamName(keyValuePair.Key);
                var requestValue   = GetValueFromRequest(portletSpecKey);

                if (!string.IsNullOrEmpty(requestValue) && c.Fields.ContainsKey(keyValuePair.Key))
                {
                    c.Fields[keyValuePair.Key].Parse(requestValue);
                }
            }

            var cv = string.IsNullOrEmpty(SearchFormRenderer)
                         ? ContentView.Create(c, this.Page, ViewMode.InlineNew)
                         : ContentView.Create(c, this.Page, ViewMode.InlineNew, SearchFormRenderer);

            //Attach search event
            var iCsView = cv as IContentSearchView;

            if (iCsView != null)
            {
                iCsView.Search += new EventHandler(ContentSearchView_Search_OnClick);
            }
            else
            {
                var btn = cv.FindControl(SearchBtnId) as Button;
                if (btn == null)
                {
                    btn = new Button {
                        ID = SearchBtnId, Text = SenseNetResourceManager.Current.GetString(ResourceCalssName, "SearchBtnText"), CssClass = "sn-submit"
                    };
                    cv.Controls.Add(btn);
                }
                btn.Click += new EventHandler(ContentSearchView_Search_OnClick);
            }
            SearchForm = cv;
        }