protected void btnCreateDocument_Click(object sender, EventArgs e) { if (radCopy.Checked) { string sourceCulture = copyCulturesElem.Value.ToString(); TreeNode sourceNode = DocumentHelper.GetDocument(NodeID, sourceCulture, Tree); if (sourceNode != null) { if (chkSaveBeforeEditing.Checked && (node != null)) { // Create the version first TreeNode newCulture = TreeNode.New(node.ClassName); DocumentHelper.CopyNodeData(sourceNode, newCulture, new CopyNodeDataSettings(true, null)); NewCultureDocumentSettings settings = new NewCultureDocumentSettings { Node = newCulture, CultureCode = RequiredCulture, CopyAttachments = true, CopyCategories = true }; DocumentHelper.InsertNewCultureVersion(settings); // Refresh page if (RequiresDialog) { string url = URLHelper.ResolveUrl(DocumentURLProvider.GetUrl(newCulture.NodeAliasPath) + "?" + URLHelper.LanguageParameterName + "=" + RequiredCulture); ScriptHelper.RegisterStartupScript(this, typeof(string), "NewCultureRefreshAction", ScriptHelper.GetScript(" wopener.location = " + ScriptHelper.GetString(url) + "; CloseDialog();")); } else { ScriptHelper.RegisterStartupScript(this, typeof(string), "NewCultureRefreshAction", ScriptHelper.GetScript("if (FramesRefresh) { FramesRefresh(" + node.NodeID + "); }")); } } else { var url = GetEditUrl(node); url = URLHelper.AddParameterToUrl(url, "sourcedocumentid", sourceNode.DocumentID.ToString()); Response.Redirect(url); } } else { ShowError(GetString("transman.notallowedcreate")); } } else { var url = GetEditUrl(node); Response.Redirect(url); } }
/// <summary> /// Process additional department tasks. /// </summary> public void ProcessDepartment(object sender, EventArgs e) { TreeNode editedNode = Form.EditedObject as TreeNode; // Get department template source document TreeNode sourceNode = DocumentHelper.GetDocument(SiteContext.CurrentSiteName, DepartmentTemplatePath, null, true, null, null, null, TreeProvider.ALL_LEVELS, false, null, TreeProvider); // Copy relevant template data to department document. Proceed only when creating a department, updating a department must not rewrite its data with template's data. if (Form.IsInsertMode && (sourceNode != null)) { var excludeColumns = new [] { "DocumentName", "NodeAlias", "DocumentTagGroupID", "DocumentStylesheetID", "DocumentPublishFrom", "DocumentPublishTo" }; DocumentHelper.CopyNodeData(sourceNode, editedNode, new CopyNodeDataSettings(true, true, false, true, true, false, false, false, excludeColumns)); DocumentHelper.UpdateDocument(editedNode, TreeProvider); } #region "Create department tag group" // Get tag group info TagGroupInfo tgi = TagGroupInfoProvider.GetTagGroupInfo(editedNode.DocumentTagGroupID); // If not exist, create new tag group and set it to document if (tgi == null) { // Populate tag group info fields tgi = new TagGroupInfo(); tgi.TagGroupDisplayName = editedNode.GetDocumentName(); tgi.TagGroupName = editedNode.NodeGUID.ToString(); tgi.TagGroupDescription = ""; tgi.TagGroupSiteID = SiteContext.CurrentSiteID; tgi.TagGroupIsAdHoc = false; // Store tag group info to DB TagGroupInfoProvider.SetTagGroupInfo(tgi); // Update document Tag group ID editedNode.DocumentTagGroupID = tgi.TagGroupID; DocumentHelper.UpdateDocument(editedNode, TreeProvider); } #endregion if (!DataHelper.DataSourceIsEmpty(TemplateDocuments)) { // List of selected documents string selectedDocs = ";" + Value + ";"; // Get already created documents under edited document DataSet dsExistingDocs = DocumentHelper.GetDocuments(SiteContext.CurrentSiteName, editedNode.NodeAliasPath + "/%", editedNode.DocumentCulture, true, null, null, null, 1, false, 0, "NodeAlias, " + DocumentColumnLists.SELECTNODES_REQUIRED_COLUMNS, null); StringBuilder sbExistDocs = new StringBuilder(); // Process existing documents to obtain list of aliases foreach (DataRow drExistDoc in dsExistingDocs.Tables[0].Rows) { sbExistDocs.Append(";"); sbExistDocs.Append(drExistDoc["NodeAlias"].ToString().ToLowerCSafe()); } sbExistDocs.Append(";"); string existingDocs = sbExistDocs.ToString(); // Set same ordering as for original template documents bool orgUseAutomaticOrdering = TreeProvider.UseAutomaticOrdering; TreeProvider.UseAutomaticOrdering = false; // Process template documents foreach (DataRow drDoc in TemplateDocuments.Tables[0].Rows) { if (DocumentHelper.IsDocumentTypeAllowed(editedNode, ValidationHelper.GetInteger(drDoc["NodeClassID"], 0))) { string nodeAlias = drDoc["NodeAlias"].ToString().ToLowerCSafe(); string contNodeAlias = ";" + nodeAlias + ";"; // Set marks bool existing = existingDocs.Contains(contNodeAlias); bool selected = selectedDocs.Contains(contNodeAlias); int nodeId = ValidationHelper.GetInteger(drDoc["NodeID"], 0); string docCulture = ValidationHelper.GetString(drDoc["DocumentCulture"], ""); TreeNode srcNode = DocumentHelper.GetDocument(nodeId, docCulture, editedNode.TreeProvider); // Check if section exists if (srcNode != null) { // Copy or remove marked document sections if (selected) { if (!existing) { CopyDocumentSection(srcNode, editedNode, TreeProvider); } } else { if (existing) { // Select node to delete var aliasPath = editedNode.NodeAliasPath + "/" + nodeAlias; var combineWithDefaultCulture = SettingsKeyInfoProvider.GetBoolValue(SiteContext.CurrentSiteName + ".CMSCombineWithDefaultCulture"); TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser); TreeNode delNode = tree.SelectSingleNode(SiteContext.CurrentSiteName, aliasPath, LocalizationContext.PreferredCultureCode, combineWithDefaultCulture); if (delNode != null) { DeleteDocumentSection(delNode, TreeProvider); } } } // Process additional operations if (selected && !existing) { switch (nodeAlias) { // Create department forum case FORUM_DOCUMENT_ALIAS: CreateDepartmentForumGroup(editedNode); CreateDepartmentForumSearchIndex(editedNode); break; // Create media library case MEDIA_DOCUMENT_ALIAS: CreateDepartmentMediaLibrary(editedNode); break; } } } } } // Set previous ordering TreeProvider.UseAutomaticOrdering = orgUseAutomaticOrdering; } mDocumentSaved = true; }
/// <summary> /// Creates new culture version of object. /// </summary> protected void btnCreateDocument_Click(object sender, EventArgs e) { if (radCopy.Checked) { string sourceCulture = copyCulturesElem.Value.ToString(); TreeNode actualSourceNode = DocumentHelper.GetDocument(NodeID, sourceCulture, Tree); TreeNode sourceNode = actualSourceNode.IsLink ? DocumentHelper.GetDocument(Tree.GetOriginalNode(actualSourceNode), Tree) : actualSourceNode; if (sourceNode != null) { if (chkSaveBeforeEditing.Checked && (Node != null)) { // Create the version first TreeNode newCulture = TreeNode.New(Node.ClassName); // The 'DocumentABTestConfiguration' is excluded from copying node to another culture as A/B test is linked to the culture specific node var excludedColumns = new[] { "DocumentABTestConfiguration" }; DocumentHelper.CopyNodeData(sourceNode, newCulture, new CopyNodeDataSettings(true, excludedColumns) { ResetChanges = true }); if (string.Equals(Node.ClassName, "cms.blogpost", StringComparison.InvariantCultureIgnoreCase)) { // Ensure blog post hierarchy if node is blog post newCulture.DocumentCulture = RequiredCulture; DocumentHelper.EnsureBlogPostHierarchy(newCulture, DocumentHelper.GetDocument(newCulture.NodeParentID, TreeProvider.ALL_CULTURES, Tree), Tree); } var settings = new NewCultureDocumentSettings(newCulture, RequiredCulture, Tree) { CopyAttachments = true, CopyCategories = true, ClearAttachmentFields = false }; try { DocumentHelper.InsertNewCultureVersion(settings); } catch (Exception ex) { // Catch possible exceptions LogAndShowError("Content", "NEWCULTUREVERSION", ex); return; } // Make sure document is published when versioning without workflow is applied var workflow = newCulture.GetWorkflow(); if ((workflow != null) && workflow.WorkflowAutoPublishChanges && !workflow.UseCheckInCheckOut(newCulture.NodeSiteName)) { newCulture.MoveToPublishedStep(); } // Refresh page if (RequiresDialog) { string url = UrlResolver.ResolveUrl(DocumentURLProvider.GetUrl(newCulture) + "?" + URLHelper.LanguageParameterName + "=" + RequiredCulture); ScriptHelper.RegisterStartupScript(this, typeof(string), "NewCultureRefreshAction", ScriptHelper.GetScript(" wopener.location = " + ScriptHelper.GetString(url) + "; CloseDialog();")); } else { ViewModeEnum mode = ViewModeEnum.Edit; if (!TreePathUtils.IsMenuItemType(Node.NodeClassName) && (PortalContext.ViewMode != ViewModeEnum.EditLive)) { mode = ViewModeEnum.EditForm; } ScriptHelper.RegisterStartupScript(this, typeof(string), "NewCultureRefreshAction", ScriptHelper.GetScript("if (FramesRefresh) { FramesRefresh(" + Node.NodeID + ", '" + mode + "'); }")); } } else { var url = GetEditUrl(Node); url = URLHelper.AddParameterToUrl(url, "sourcedocumentid", sourceNode.DocumentID.ToString()); if (RequiresDialog) { // Reload new page after save url = URLHelper.AddParameterToUrl(url, "reloadnewpage", "true"); } // Provide information about actual node if (actualSourceNode.IsLink) { url = URLHelper.AddParameterToUrl(url, "sourcenodeid", actualSourceNode.NodeID.ToString()); } URLHelper.ResponseRedirect(url); } } else { ShowError(GetString("transman.notallowedcreate")); } } else { var url = GetEditUrl(Node); if (RequiresDialog) { // Reload new page after save url = URLHelper.AddParameterToUrl(url, "reloadnewpage", "true"); } URLHelper.ResponseRedirect(url); } }
/// <summary> /// Process additional department tasks. /// </summary> public void ProcessDepartment(object sender, EventArgs e) { TreeNode editedNode = Form.EditedObject as TreeNode; // Get department template source document TreeNode sourceNode = DocumentHelper.GetDocument(CMSContext.CurrentSiteName, DepartmentTemplatePath, null, true, null, null, null, 0, false, null, TreeProvider); // Copy relevant template data to department document if (sourceNode != null) { DocumentHelper.CopyNodeData(sourceNode, editedNode, true, true, false, true, true, false, false, "DocumentName;NodeAlias;DocumentTagGroupID;DocumentStylesheetID;DocumentPublishFrom;DocumentPublishTo"); DocumentHelper.UpdateDocument(editedNode, TreeProvider); } #region "Create department tag group" // Get tag group info TagGroupInfo tgi = TagGroupInfoProvider.GetTagGroupInfo(editedNode.DocumentTagGroupID); // If not exist, create new tag group and set it to document if (tgi == null) { // Populate tag group info fields tgi = new TagGroupInfo(); tgi.TagGroupDisplayName = editedNode.DocumentName; tgi.TagGroupName = editedNode.NodeGUID.ToString(); tgi.TagGroupDescription = ""; tgi.TagGroupSiteID = CMSContext.CurrentSiteID; tgi.TagGroupIsAdHoc = false; // Store tag group info to DB TagGroupInfoProvider.SetTagGroupInfo(tgi); // Update document Tag group ID editedNode.DocumentTagGroupID = tgi.TagGroupID; DocumentHelper.UpdateDocument(editedNode, TreeProvider); } #endregion if (!DataHelper.DataSourceIsEmpty(TemplateDocuments)) { // List of selected documents string selectedDocs = ";" + Value + ";"; // Get already created documents under edited document DataSet dsExistingDocs = DocumentHelper.GetDocuments(CMSContext.CurrentSiteName, editedNode.NodeAliasPath + "/%", editedNode.DocumentCulture, true, null, null, null, 1, false, 0, "NodeAlias, " + TreeProvider.SELECTNODES_REQUIRED_COLUMNS, null); StringBuilder sbExistDocs = new StringBuilder(); // Process existing documents to obtain list of aliases foreach (DataRow drExistDoc in dsExistingDocs.Tables[0].Rows) { sbExistDocs.Append(";"); sbExistDocs.Append(drExistDoc["NodeAlias"].ToString().ToLower()); } sbExistDocs.Append(";"); string existingDocs = sbExistDocs.ToString(); // Set same ordering as for original template documents bool orgUseAutomaticOrdering = TreeProvider.UseAutomaticOrdering; TreeProvider.UseAutomaticOrdering = false; // Process template documents foreach (DataRow drDoc in TemplateDocuments.Tables[0].Rows) { string nodeAlias = drDoc["NodeAlias"].ToString().ToLower(); string contNodeAlias = ";" + nodeAlias + ";"; // Set marks bool existing = existingDocs.Contains(contNodeAlias); bool selected = selectedDocs.Contains(contNodeAlias); int nodeId = ValidationHelper.GetInteger(drDoc["NodeID"], 0); string docCulture = ValidationHelper.GetString(drDoc["DocumentCulture"], ""); TreeNode srcNode = DocumentHelper.GetDocument(nodeId, docCulture, editedNode.TreeProvider); // Check if section exists if (srcNode != null) { // Copy or remove marked document sections if (selected) { if (!existing) { CopyDocumentSection(srcNode, editedNode.NodeID, TreeProvider); } } else { if (existing) { // Select node to delete TreeNode delNode = TreeHelper.SelectSingleNode(editedNode.NodeAliasPath + "/" + nodeAlias); if (delNode != null) { DeleteDocumentSection(delNode, TreeProvider); } } } // Process additional operations if (selected && !existing) { switch (nodeAlias) { // Create department forum case FORUM_DOCUMENT_ALIAS: CreateDepartmentForumGroup(editedNode); CreateDepartmentForumSearchIndex(editedNode); break; // Create media library case MEDIA_DOCUMENT_ALIAS: CreateDepartmentMediaLibrary(editedNode); break; } } } } // Set previous ordering TreeProvider.UseAutomaticOrdering = orgUseAutomaticOrdering; } mDocumentSaved = true; }
protected void btnCreateDocument_Click(object sender, EventArgs e) { if (radCopy.Checked) { string sourceCulture = copyCulturesElem.Value.ToString(); TreeNode actualSourceNode = DocumentHelper.GetDocument(NodeID, sourceCulture, Tree); TreeNode sourceNode = actualSourceNode.IsLink ? DocumentHelper.GetDocument(Tree.GetOriginalNode(actualSourceNode), Tree) : actualSourceNode; if (sourceNode != null) { if (chkSaveBeforeEditing.Checked && (node != null)) { // Create the version first TreeNode newCulture = TreeNode.New(node.ClassName); DocumentHelper.CopyNodeData(sourceNode, newCulture, new CopyNodeDataSettings(true, null)); NewCultureDocumentSettings settings = new NewCultureDocumentSettings { Node = newCulture, CultureCode = RequiredCulture, CopyAttachments = true, CopyCategories = true }; DocumentHelper.InsertNewCultureVersion(settings); // Refresh page if (RequiresDialog) { string url = URLHelper.ResolveUrl(DocumentURLProvider.GetUrl(newCulture.NodeAliasPath) + "?" + URLHelper.LanguageParameterName + "=" + RequiredCulture); ScriptHelper.RegisterStartupScript(this, typeof(string), "NewCultureRefreshAction", ScriptHelper.GetScript(" wopener.location = " + ScriptHelper.GetString(url) + "; CloseDialog();")); } else { ViewModeEnum mode = ViewModeEnum.Edit; if (!TreePathUtils.IsMenuItemType(node.NodeClassName) && (CMSContext.ViewMode != ViewModeEnum.EditLive)) { mode = ViewModeEnum.EditForm; } ScriptHelper.RegisterStartupScript(this, typeof(string), "NewCultureRefreshAction", ScriptHelper.GetScript("if (FramesRefresh) { FramesRefresh(" + node.NodeID + ", '" + mode + "'); }")); } } else { var url = GetEditUrl(node); url = URLHelper.AddParameterToUrl(url, "sourcedocumentid", sourceNode.DocumentID.ToString()); // Provide information about actual node if ((actualSourceNode != null) && actualSourceNode.IsLink) { url = URLHelper.AddParameterToUrl(url, "sourcenodeid", actualSourceNode.NodeID.ToString()); } Response.Redirect(url); } } else { ShowError(GetString("transman.notallowedcreate")); } } else { var url = GetEditUrl(node); Response.Redirect(url); } }