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
        /// <summary>
        /// Gets the model.
        /// </summary>
        /// <returns></returns>
        protected override object GetModel()
        {
            //var manager = Content.Load("/Root/IMS/BuiltIn/Portal/Administrator");

            var manager = Content.Load(FirstManager);

            if (manager == null)
            {
                throw new NotSupportedException(SenseNetResourceManager.Current.GetString("OrganizationChart", "NoSuchManagerError"));
            }


            var managerStream = manager.GetXml(true);
            var resultXml     = new XmlDocument();

            resultXml.Load(managerStream);

            _usedNodeId = new List <int>();
            _usedNodeId.Add(manager.Id);

            try
            {
                GetEmployees(manager, resultXml.SelectSingleNode("/Content"), 1);
            }
            catch (Exception ex)
            {
                Logger.WriteException(ex);
                throw new NotSupportedException(ex.Message);
            }

            return(resultXml);
        }
Ejemplo n.º 3
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.º 4
0
        /// <summary>
        /// Sets the callback URL of the ActionMenu. It represents the service url with correct parameters for the actions.
        /// </summary>
        private void SetServiceUrl()
        {
            var scParams = GetReplacedScenarioParameters();
            var context  = UITools.FindContextInfo(this, ContextInfoID);
            var path     = !String.IsNullOrEmpty(ContextInfoID) ? context.Path : NodePath;

            var encodedReturnUrl = Uri.EscapeDataString(PortalContext.Current.RequestedUri.PathAndQuery);
            var encodedParams    = Uri.EscapeDataString(scParams ?? string.Empty);

            if (String.IsNullOrEmpty(path))
            {
                path = GetPathFromContentView(this);
            }

            if (string.IsNullOrEmpty(path))
            {
                this.Visible = false;
                return;
            }

            this.Content = Content.Load(path);

            //Pre-check action count. If empty, hide the action menu.
            if (CheckActionCount)
            {
                var sc          = ScenarioManager.GetScenario(Scenario, scParams);
                var actionCount = 0;

                if (sc != null)
                {
                    actionCount = sc.GetActions(this.Content, PortalContext.Current.RequestedUri.PathAndQuery).Count();
                }

                if (actionCount < 2 && string.Equals(Scenario, "new", StringComparison.CurrentCultureIgnoreCase))
                {
                    ClickDisabled = true;
                }
                else if (actionCount == 0)
                {
                    this.Visible = false;
                    return;
                }
            }

            //Pre-check required permissions
            var permissions = ActionFramework.GetRequiredPermissions(RequiredPermissions);

            if (permissions.Count > 0 && !SecurityHandler.HasPermission(NodeHead.Get(path), permissions.ToArray()))
            {
                this.Visible = false;
                return;
            }

            var encodedPath = HttpUtility.UrlEncode(path);

            ServiceUrl = String.Format("/SmartAppHelper.mvc/GetActions?path={0}&scenario={1}&back={2}&parameters={3}",
                                       encodedPath, Scenario, encodedReturnUrl, encodedParams);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the model.
        /// </summary>
        /// <returns></returns>
        protected override object GetModel()
        {
            var managerHead = NodeHead.Get(FirstManager);

            if (managerHead == null)
            {
                throw new NotSupportedException(SenseNetResourceManager.Current.GetString("OrganizationChart", "NoSuchManagerError"));
            }

            var resultXml = new XmlDocument();

            if (!SecurityHandler.HasPermission(managerHead, PermissionType.Open))
            {
                return(resultXml);
            }

            var manager = Content.Load(FirstManager);

            if (manager == null)
            {
                throw new NotSupportedException(SenseNetResourceManager.Current.GetString("OrganizationChart", "NoSuchManagerError"));
            }

            var managerStream = manager.GetXml(true);

            resultXml.Load(managerStream);

            _usedNodeId = new List <int> {
                manager.Id
            };

            try
            {
                GetEmployees(manager, resultXml.SelectSingleNode("/Content"), 1);
            }
            catch (Exception ex)
            {
                Logger.WriteException(ex);
                throw new NotSupportedException(ex.Message);
            }

            return(resultXml);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the employees.
        /// </summary>
        /// <param name="manager">The manager.</param>
        /// <param name="container">The container.</param>
        /// <param name="depth">The depth.</param>
        private void GetEmployees(Content manager, XmlNode container, int depth)
        {
            if (depth > DepthLimit)
            {
                return;
            }

            var employeesNode = container.OwnerDocument.CreateElement("Employees");

            container.AppendChild(employeesNode);

            var query  = SenseNet.Search.LucQuery.Parse(string.Format("+Manager:{0} +Type:User", manager.Id));
            var result = query.Execute();

            foreach (var lucObject in result)
            {
                if (!_usedNodeId.Contains(lucObject.NodeId))
                {
                    _usedNodeId.Add(lucObject.NodeId);
                }
                else
                {
                    throw new NotSupportedException(SenseNetResourceManager.Current.GetString("OrganizationChart", "CircularReferenceError"));
                }

                var employee       = Content.Load(lucObject.NodeId);
                var employeeStream = employee.GetXml(false);
                var employeeXml    = new XmlDocument();
                employeeXml.Load(employeeStream);

                var node = employeesNode.OwnerDocument.ImportNode(employeeXml.DocumentElement, true);

                employeesNode.AppendChild(node);
                var employeeNode = employeesNode.SelectSingleNode(string.Format("Content[SelfLink='{0}']", employee.Path));

                GetEmployees(employee, employeeNode, depth + 1);
            }
        }
Ejemplo n.º 7
0
        // ========================================================================================= Event handlers

        protected void StartWorkflowButton_Click(object sender, EventArgs e)
        {
            if (this.ContentView == null)
            {
                return;
            }

            this.ContentView.NeedToValidate = true;
            this.ContentView.UpdateContent();

            var content = this.ContentView.Content;

            if (this.ContentView.IsUserInputValid && content.IsValid)
            {
                try
                {
                    if (this.StartOnCurrentContent)
                    {
                        var workflow = content.ContentHandler as WorkflowHandlerBase;
                        if (workflow != null)
                        {
                            content.Fields["RelatedContent"].SetData(this.ContextNode);
                        }
                    }

                    ValidateWorkflow();

                    WorkflowHandlerBase wfContent;

                    // need to create workflow in elevated mode
                    using (new SystemAccount())
                    {
                        content.Fields["OwnerSiteUrl"].SetData(PortalContext.Current.RequestedUri.GetLeftPart(UriPartial.Authority));
                        content.Save();

                        //TODO: review this ... this is a temporary solution
                        wfContent = Node.Load <WorkflowHandlerBase>(content.Id);
                    }

                    // start workflow
                    InstanceManager.Start(wfContent);
                }
                catch (Exception ex)
                {
                    // cleanup: delete the instance if it was saved before the error
                    if (content.Id != 0)
                    {
                        using (new SystemAccount())
                        {
                            content.ForceDelete();
                        }
                    }

                    SnLog.WriteException(ex);
                    this.ContentView.ContentException = ex;

                    return;
                }

                if (!string.IsNullOrEmpty(ConfirmContentPath))
                {
                    // if confirm page or content is given, redirect there
                    var confirmContent      = Content.Load(ConfirmContentPath);
                    var confirmBrowseAction = Helpers.Actions.BrowseUrl(confirmContent);

                    // If the user does not have enough permissions for the Browse action
                    // in this subtree, but the target content is a page, than use its path.
                    if (string.IsNullOrEmpty(confirmBrowseAction) && confirmContent != null && confirmContent.ContentType.IsInstaceOfOrDerivedFrom("Page"))
                    {
                        confirmBrowseAction = PortalContext.GetSiteRelativePath(confirmContent.Path);
                    }

                    if (!string.IsNullOrEmpty(confirmBrowseAction))
                    {
                        HttpContext.Current.Response.Redirect(confirmBrowseAction, false);
                        return;
                    }
                }

                CallDone(false);
            }
        }
Ejemplo n.º 8
0
        protected override void Render(HtmlTextWriter writer)
        {
            // render nothing if the action does not exist
            if (Action == null)
            {
                return;
            }

            var actionClickable = true;

            if (CheckActionCount)
            {
                var am = ActionMenu.FindContainerActionMenu(this);
                List <ActionBase> scActions = null;
                var scenario = string.Empty;

                if (am != null)
                {
                    scenario = am.Scenario;

                    if (!string.IsNullOrEmpty(scenario))
                    {
                        scActions = ActionFramework.GetActions(Content.Load(ContextPath), scenario, am.GetReplacedScenarioParameters()).ToList();
                    }
                }

                if (scActions != null)
                {
                    if (scActions.Count > 1)
                    {
                        actionClickable = false;
                    }
                    else if (scActions.Count == 1 &&
                             string.Equals(scenario, "new", StringComparison.CurrentCultureIgnoreCase) &&
                             string.Equals(this.ActionName, "add", StringComparison.CurrentCultureIgnoreCase))
                    {
                        // change action to the single "New" action found in the parent menu
                        _action        = scActions.First();
                        _actionChecked = true;

                        this.Text = this.Text + " " + _action.Text;
                    }
                }
            }

            if (actionClickable)
            {
                var claction = Action as ClientAction;
                if (claction != null && claction.Callback != null)
                {
                    NavigateUrl = "javascript:";
                    this.Attributes["onclick"] = claction.Callback;
                }
                else
                {
                    NavigateUrl = Action.Uri;
                }
            }

            // load html template (provided by the builder)
            string templateText = null;

            if (!string.IsNullOrEmpty(Template))
            {
                templateText = HtmlTemplate.GetActionLinkTemplate(Template);
            }

            // load html template (by default names)
            if (string.IsNullOrEmpty(templateText))
            {
                templateText = IconVisible
                    ? (string.IsNullOrEmpty(IconUrl)
                        ? HtmlTemplate.GetActionLinkTemplate(HtmlTemplate.Names.ActionButton)       // icon is rendered as a <span>
                        : HtmlTemplate.GetActionLinkTemplate(HtmlTemplate.Names.ActionImageButton)) // icon is rendered as an <image> tag
                    : HtmlTemplate.GetActionLinkTemplate(HtmlTemplate.Names.ActionLink);            // no icon
            }

            // add actionlinkbutton class only if there is no template
            if (string.IsNullOrEmpty(templateText))
            {
                this.CssClass += " sn-actionlinkbutton";
            }

            // fill control properties according to the current state of the action
            FillProperties();

            // if a template was found, fill its parameters and render it
            if (!string.IsNullOrEmpty(templateText))
            {
                writer.Write(TemplateManager.Replace(typeof(ActionTemplateReplacer), templateText, this));
                return;
            }

            // backward compatibility (classic ASP.NET behavior, when there is no html template)
            base.Render(writer);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Sets the callback URL of the ActionMenu. It represents the service url with correct parameters for the actions.
        /// </summary>
        private void SetServiceUrl()
        {
            var scParams = GetReplacedScenarioParameters();
            var context  = UITools.FindContextInfo(this, ContextInfoID);
            var path     = !string.IsNullOrEmpty(ContextInfoID) ? context.Path : NodePath;

            var encodedReturnUrl = Uri.EscapeDataString(PortalContext.Current.RequestedUri.PathAndQuery);
            var encodedParams    = Uri.EscapeDataString(scParams ?? string.Empty);

            if (string.IsNullOrEmpty(path))
            {
                path = ContentView.GetContentPath(this);
            }

            if (string.IsNullOrEmpty(path))
            {
                this.Visible = false;
                return;
            }

            var head = NodeHead.Get(path);

            if (head == null || !SecurityHandler.HasPermission(head, PermissionType.See))
            {
                this.Visible = false;
                return;
            }

            this.Content = Content.Load(path);

            // Pre-check action count. If empty, hide the action menu.
            if (CheckActionCount)
            {
                var actionCount = 0;

                if (!string.IsNullOrEmpty(Scenario))
                {
                    actionCount = ActionFramework.GetActions(this.Content, Scenario, scParams, null).Count();
                }

                if (actionCount < 2 && string.Equals(Scenario, "new", StringComparison.CurrentCultureIgnoreCase))
                {
                    ClickDisabled = true;
                }
                else if (actionCount == 0)
                {
                    this.Visible = false;
                    return;
                }
            }

            // Pre-check required permissions
            var permissions = SenseNet.ContentRepository.Fields.PermissionChoiceField.ConvertToPermissionTypes(RequiredPermissions).ToArray();

            if (permissions.Length > 0 && !SecurityHandler.HasPermission(head, permissions))
            {
                this.Visible = false;
                return;
            }

            ServiceUrl = string.Format(ODataTools.GetODataOperationUrl(path, "SmartAppGetActions") + "?scenario={0}&back={1}&parameters={2}", Scenario, encodedReturnUrl, encodedParams);
        }
Ejemplo n.º 10
0
        //========================================================================================= Event handlers

        protected void StartWorkflowButton_Click(object sender, EventArgs e)
        {
            if (this.ContentView == null)
            {
                return;
            }

            this.ContentView.NeedToValidate = true;
            this.ContentView.UpdateContent();

            var content = this.ContentView.Content;

            if (this.ContentView.IsUserInputValid && content.IsValid)
            {
                try
                {
                    if (this.StartOnCurrentContent)
                    {
                        var workflow = content.ContentHandler as WorkflowHandlerBase;
                        if (workflow != null)
                        {
                            content.Fields["RelatedContent"].SetData(this.ContextNode);
                            //workflow.RelatedContent = this.ContextNode;
                        }
                    }

                    ValidateWorkflow();

                    //need to create workflow in elevated mode
                    using (new SystemAccount())
                    {
                        content.Fields["OwnerSiteUrl"].SetData(PortalContext.Current.RequestedUri.GetLeftPart(UriPartial.Authority));
                        content.Save();
                    }

                    //TODO: review this ... this is a temporary solution
                    var wfContent = Node.LoadNode(content.Id);

                    //start workflow
                    InstanceManager.Start(wfContent as WorkflowHandlerBase);
                }
                catch (Exception ex)
                {
                    //cleanup: delete the instance if it was saved before the error
                    if (content.Id != 0)
                    {
                        using (new SystemAccount())
                        {
                            content.ForceDelete();
                        }
                    }

                    Logger.WriteException(ex);
                    this.ContentView.ContentException = ex;

                    return;
                }

                if (!string.IsNullOrEmpty(ConfirmContentPath))
                {
                    //if confirm page or content is given, redirect there
                    var confirmBrowseAction = Helpers.Actions.BrowseUrl(Content.Load(ConfirmContentPath));
                    if (!string.IsNullOrEmpty(confirmBrowseAction))
                    {
                        HttpContext.Current.Response.Redirect(confirmBrowseAction, false);
                    }
                }

                CallDone(false);
            }
        }
Ejemplo n.º 11
0
        protected override void Render(HtmlTextWriter writer)
        {
            //render nothing if the action does not exist
            if (Action == null)
            {
                return;
            }

            var actionClickable = true;

            if (CheckActionCount)
            {
                var am = ActionMenu.FindContainerActionMenu(this);
                List <ActionBase> scActions = null;
                var scenario = string.Empty;

                if (am != null)
                {
                    scenario = am.Scenario;

                    if (!string.IsNullOrEmpty(scenario))
                    {
                        scActions = ActionFramework.GetActions(Content.Load(ContextPath), scenario, am.GetReplacedScenarioParameters()).ToList();
                    }
                }

                if (scActions != null)
                {
                    if (scActions.Count > 1)
                    {
                        actionClickable = false;
                    }
                    else if (scActions.Count == 1 &&
                             string.Equals(scenario, "new", StringComparison.CurrentCultureIgnoreCase) &&
                             string.Equals(this.ActionName, "add", StringComparison.CurrentCultureIgnoreCase))
                    {
                        //change action to the single "New" action found in the parent menu
                        _action        = scActions.First();
                        _actionChecked = true;

                        this.Text = this.Text + " " + _action.Text;
                    }
                }
            }

            if (actionClickable)
            {
                var claction = Action as ClientAction;
                if (claction != null && claction.Callback != null)
                {
                    NavigateUrl = "javascript:";
                    this.Attributes["onclick"] = claction.Callback;
                }
                else
                {
                    NavigateUrl = Action.Uri;
                }
            }

            this.CssClass += (string.IsNullOrEmpty(this.CssClass) ? "" : " ") + "sn-actionlinkbutton";

            if (Action.Forbidden)
            {
                this.CssClass   += " sn-disabled";
                this.Enabled     = false;
                this.NavigateUrl = string.Empty;
            }

            base.Render(writer);
        }