internal void CreateNewWorkspace() { try { var state = WizardState; var newName = state.WorkspaceNewName; var sourceNodePath = state.SelectedWorkspacePath; var targetNode = PortalContext.Current.ContextNodeHead ?? NodeHead.Get(TargetPath); var sourceNode = Node.LoadNode(sourceNodePath); var contentTypeName = sourceNode.Name; Content workspace = null; workspace = ContentTemplate.HasTemplate(contentTypeName) ? ContentTemplate.CreateTemplated(Node.LoadNode(targetNode.Id), ContentTemplate.GetTemplate(contentTypeName), newName) : Content.CreateNew(contentTypeName, Node.LoadNode(targetNode.Id), newName); workspace.Fields["Description"].SetData(state.WorkspaceNewDescription); workspace.Save(); var newPath = new StringBuilder(PortalContext.Current.OriginalUri.GetLeftPart(UriPartial.Authority)).Append(targetNode.Path).Append("/").Append(newName); NewWorkspaceLink.HRef = newPath.ToString(); } catch (Exception exc) //logged { Logger.WriteException(exc); HasError = true; ErrorMessageControl.Visible = true; ErrorMessageControl.Text = exc.Message; // log exception } }
// Returns the folder (parent) as container of the VotingItems private Node GetFolder(Node contextNode) { var folderName = DateTime.UtcNow.ToString("yyyy_MM_dd"); var folderPath = RepositoryPath.Combine(ContextNode.Path, folderName); using (new SystemAccount()) { // If Folder doesn't exists if (!Node.Exists(folderPath)) { var newFolder = Content.CreateNew("Folder", contextNode, folderName); newFolder.Fields["DisplayName"].SetData(folderName); newFolder.Fields["Name"].SetData(folderName); newFolder.Save(); return(newFolder.ContentHandler); } // Return existing Folder return(Node.LoadNode(folderPath)); } }
// Voting View private void AddVotingView() { var votingNode = ContextNode as Voting; if (votingNode == null) { Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "ContextNodeError") }); return; } if (votingNode.IsVotingAvailable) { Node votingView = 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()) { votingView = votingNode.VotingPageContentView; } if (votingView != null) { var contentView = ContentView.Create(_currentContent, Page, ViewMode.Browse, votingView.Path); if (contentView == null) { Controls.Add(new Literal { Text = ResourceManager.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 = ResourceManager.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 = ResourceManager.Current.GetString("Voting", "NoQuestion") }); return; } var votingItemNewContentView = ContentView.Create(votingItem, Page, ViewMode.InlineNew); if (votingItemNewContentView == null) { Controls.Add(new Literal { Text = ResourceManager.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 = ResourceManager.Current.GetString("Voting", "CannotFindLink") }); return; } lb.Text = ResourceManager.Current.GetString("Voting", "GoToResultLink"); lb.Click += LbClick; lb.Visible = true; } return; } // No content view is set Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "NoContentView") }); } else { // When the user can only Vote once Controls.Add(new Literal { Text = ResourceManager.Current.GetString("Voting", "OnlyOneVoteError") }); } }
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/*"); // do this in elevated mode to avoid errors related to non-writable fields, like CreationDate using (new SystemAccount()) { 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 = ResourceManager.Current.GetString(ResourceClassName, "SearchBtnText"), CssClass = "sn-submit" }; cv.Controls.Add(btn); } btn.Click += new EventHandler(ContentSearchView_Search_OnClick); } SearchForm = cv; }