/// <summary> /// Gets and bulk updates web part layouts. Called when the "Get and bulk update layouts" button is pressed. /// Expects the CreateWebPartLayout method to be run first. /// </summary> private bool GetAndBulkUpdateWebPartLayouts() { // Prepare the parameters string where = "WebPartLayoutCodeName LIKE N'MyNewLayout%'"; // Get the data DataSet layouts = WebPartLayoutInfoProvider.GetWebPartLayouts(where, null); if (!DataHelper.DataSourceIsEmpty(layouts)) { // Loop through the individual items foreach (DataRow layoutDr in layouts.Tables[0].Rows) { // Create object from DataRow WebPartLayoutInfo modifyLayout = new WebPartLayoutInfo(layoutDr); // Update the properties modifyLayout.WebPartLayoutDisplayName = modifyLayout.WebPartLayoutDisplayName.ToUpper(); // Save the changes WebPartLayoutInfoProvider.SetWebPartLayoutInfo(modifyLayout); } return(true); } return(false); }
/// <summary> /// Saves the form data. /// </summary> private void Save() { // Remove "." due to virtual path provider replacement txtCodeName.Text = txtCodeName.Text.Replace(".", ""); txtDisplayName.Text = txtDisplayName.Text.Trim(); txtCodeName.Text = txtCodeName.Text.Trim(); string errorMessage = new Validator() .NotEmpty(txtCodeName.Text, rfvCodeName.ErrorMessage) .NotEmpty(txtDisplayName.Text, rfvDisplayName.ErrorMessage) .IsCodeName(txtCodeName.Text, GetString("general.invalidcodename")) .Result; if (errorMessage != String.Empty) { lblError.Text = errorMessage; lblError.Visible = true; return; } // Check web part id int webPartId = QueryHelper.GetInteger("webpartId", 0); WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPartId); if (wpi == null) { lblError.Text = GetString("WebPartEditLayoutNew.InvalidWebPartID"); lblError.Visible = true; return; } // Check web part layout code name WebPartLayoutInfo tempwpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, txtCodeName.Text); if (tempwpli != null) { lblError.Text = GetString("WebPartEditLayoutNew.CodeNameAlreadyExist"); lblError.Visible = true; return; } // Create and fill info structure WebPartLayoutInfo wpli = new WebPartLayoutInfo(); wpli.WebPartLayoutID = 0; wpli.WebPartLayoutCodeName = txtCodeName.Text; wpli.WebPartLayoutDisplayName = txtDisplayName.Text; wpli.WebPartLayoutCode = tbCode.Text; wpli.WebPartLayoutCSS = tbCSS.Text; wpli.WebPartLayoutDescription = txtDescription.Text; wpli.WebPartLayoutWebPartID = webPartId; WebPartLayoutInfoProvider.SetWebPartLayoutInfo(wpli); URLHelper.Redirect("WebPart_Edit_Layout_Frameset.aspx?layoutID=" + wpli.WebPartLayoutID + "&webpartID=" + webPartId); }
/// <summary> /// Gets and updates web part layout. Called when the "Get and update layout" button is pressed. /// Expects the CreateWebPartLayout method to be run first. /// </summary> private bool GetAndUpdateWebPartLayout() { // Get the web part layout WebPartLayoutInfo updateLayout = WebPartLayoutInfoProvider.GetWebPartLayoutInfo("MyNewWebpart", "MyNewLayout"); if (updateLayout != null) { // Update the properties updateLayout.WebPartLayoutDisplayName = updateLayout.WebPartLayoutDisplayName.ToLower(); // Save the changes WebPartLayoutInfoProvider.SetWebPartLayoutInfo(updateLayout); return(true); } return(false); }
/// <summary> /// Creates web part layout. Called when the "Create layout" button is pressed. /// </summary> private bool CreateWebPartLayout() { // Get the web part WebPartInfo webpart = WebPartInfoProvider.GetWebPartInfo("MyNewWebpart"); if (webpart != null) { // Create new web part layout object WebPartLayoutInfo newLayout = new WebPartLayoutInfo(); // Set the properties newLayout.WebPartLayoutDisplayName = "My new layout"; newLayout.WebPartLayoutCodeName = "MyNewLayout"; newLayout.WebPartLayoutWebPartID = webpart.WebPartID; newLayout.WebPartLayoutCode = "This is the new layout of MyNewWebpart webpart."; // Save the web part layout WebPartLayoutInfoProvider.SetWebPartLayoutInfo(newLayout); return(true); } return(false); }
/// <summary> /// Save layout code. /// </summary> protected bool SaveData() { // Remove "." due to virtual path provider replacement txtCodeName.Text = txtCodeName.Text.Replace(".", ""); txtDisplayName.Text = txtDisplayName.Text.Trim(); txtCodeName.Text = txtCodeName.Text.Trim(); string errorMessage = new Validator() .NotEmpty(txtCodeName.Text, rfvCodeName.ErrorMessage) .NotEmpty(txtDisplayName.Text, rfvDisplayName.ErrorMessage) .IsCodeName(txtCodeName.Text, GetString("general.invalidcodename")).Result; int webPartId = ValidationHelper.GetInteger(Request.QueryString["webpartId"], 0); WebPartInfo webPartInfo = WebPartInfoProvider.GetWebPartInfo(webPartId); if (webPartInfo == null) { errorMessage = GetString("WebPartEditLayoutEdit.InvalidWebPartID"); } if (errorMessage != String.Empty) { lblError.Text = errorMessage; lblError.Visible = true; return(false); } // Get layout info WebPartLayoutInfo webPartLayoutInfo = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(layoutId); if (webPartLayoutInfo != null) { // Get layout info using its code name - layout code name must be unique DataSet ds = WebPartLayoutInfoProvider.GetWebPartLayouts("WebPartLayoutCodeName = '" + WebPartLayoutInfoProvider.GetWebPartLayoutFullCodeName(webPartInfo.WebPartName, txtCodeName.Text) + "'", null); // Find anything? if (!DataHelper.DataSourceIsEmpty(ds)) { WebPartLayoutInfo temp = new WebPartLayoutInfo(ds.Tables[0].Rows[0]); // Is it the same layout? if ((ds.Tables[0].Rows.Count > 1) || (temp.WebPartLayoutID != webPartLayoutInfo.WebPartLayoutID)) { lblError.Text = String.Format(GetString("WebPartEditLayoutEdit.CodeNameAlreadyExist"), txtCodeName.Text); lblError.Visible = true; return(false); } } webPartLayoutInfo.WebPartLayoutCodeName = txtCodeName.Text; webPartLayoutInfo.WebPartLayoutDisplayName = txtDisplayName.Text; webPartLayoutInfo.WebPartLayoutDescription = txtDescription.Text; if (!webPartLayoutInfo.Generalized.IsCheckedOut) { webPartLayoutInfo.WebPartLayoutCode = etaCode.Text; webPartLayoutInfo.WebPartLayoutCSS = tbCSS.Text; } WebPartLayoutInfoProvider.SetWebPartLayoutInfo(webPartLayoutInfo); // Reload header if changes were saved if (TabMode) { ScriptHelper.RefreshTabHeader(Page, null); } } return(true); }
/// <summary> /// Sets current layout. /// </summary> protected void SetCurrentLayout(bool saveToWebPartInstance, bool updateLayout) { if ((webPart != null) && (LayoutCodeName != "|new|")) { if (saveToWebPartInstance) { if (LayoutCodeName == "|default|") { webPart.SetValue("WebPartLayout", ""); } else { webPart.SetValue("WebPartLayout", LayoutCodeName); } bool isWebPartVariant = (variantId > 0) || (zoneVariantId > 0) || isNewVariant; if (!isWebPartVariant) { // Update page template PageTemplateInfoProvider.SetPageTemplateInfo(pti); } else { // Save the variant properties if ((webPart != null) && (webPart.ParentZone != null) && (webPart.ParentZone.ParentTemplateInstance != null) && (webPart.ParentZone.ParentTemplateInstance.ParentPageTemplate != null)) { XmlDocument doc = new XmlDocument(); XmlNode xmlWebParts = null; if (zoneVariantId > 0) { // This webpart is in a zone variant therefore save the whole variant webparts xmlWebParts = webPart.ParentZone.GetXmlNode(doc); if (webPart.VariantMode == VariantModeEnum.MVT) { ModuleCommands.OnlineMarketingSaveMVTVariantWebParts(zoneVariantId, xmlWebParts); } else if (webPart.VariantMode == VariantModeEnum.ContentPersonalization) { ModuleCommands.OnlineMarketingSaveContentPersonalizationVariantWebParts(zoneVariantId, xmlWebParts); } } else if (variantId > 0) { // This webpart is a web part variant xmlWebParts = webPart.GetXmlNode(doc); if (webPart.VariantMode == VariantModeEnum.MVT) { ModuleCommands.OnlineMarketingSaveMVTVariantWebParts(variantId, xmlWebParts); } else if (webPart.VariantMode == VariantModeEnum.ContentPersonalization) { ModuleCommands.OnlineMarketingSaveContentPersonalizationVariantWebParts(variantId, xmlWebParts); } } } } } string parameters = this.aliasPath + "/" + this.zoneId + "/" + this.webpartId; string cacheName = "CMSVirtualWebParts|" + parameters.ToLower().TrimStart('/'); CacheHelper.Remove(cacheName); if (updateLayout) { WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType); if (wpi != null) { WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, LayoutCodeName); if (wpli != null) { if (CurrentUser.IsAuthorizedPerResource("CMS.Design", "EditCode")) { wpli.WebPartLayoutCode = etaCode.Text; } wpli.WebPartLayoutCSS = etaCSS.Text; WebPartLayoutInfoProvider.SetWebPartLayoutInfo(wpli); } } } } }
/// <summary> /// Save new layout. /// </summary> protected bool Save() { if (webPartInfo != null) { // Remove "." due to virtual path provider replacement txtLayoutName.Text = txtLayoutName.Text.Replace(".", ""); string result = new Validator().NotEmpty(txtLayoutName.Text, GetString("WebPartPropertise.errCodeName")).NotEmpty(txtLayoutDisplayName.Text, GetString("WebPartPropertise.errDisplayName")).IsCodeName(txtLayoutName.Text, GetString("WebPartPropertise.errCodeNameFormat")).Result; if (result == "") { WebPartLayoutInfo tmpLayInfo = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(webPartInfo.WebPartName, txtLayoutName.Text.Trim()); if (tmpLayInfo == null) { WebPartLayoutInfo wpli = new WebPartLayoutInfo(); wpli.WebPartLayoutCodeName = txtLayoutName.Text.Trim(); wpli.WebPartLayoutDescription = txtDescription.Text; wpli.WebPartLayoutDisplayName = txtLayoutDisplayName.Text; if (CurrentUser.IsAuthorizedPerResource("CMS.Design", "EditCode")) { wpli.WebPartLayoutCode = etaCode.Text; } else { wpli.WebPartLayoutCode = GetDefaultCode(); } wpli.WebPartLayoutCSS = etaCSS.Text; wpli.WebPartLayoutWebPartID = webPartInfo.WebPartID; WebPartLayoutInfoProvider.SetWebPartLayoutInfo(wpli); LayoutCodeName = wpli.WebPartLayoutCodeName; txtDescription.Text = ""; txtLayoutDisplayName.Text = ""; txtLayoutName.Text = ""; plcDescription.Visible = false; plcValues.Visible = false; etaCode.Rows = 17; lblInfo.Visible = true; lblInfo.Text = GetString("General.ChangesSaved"); pnlMenu.Visible = true; pnlCheckOutInfo.Visible = true; } else { lblError.Visible = true; lblError.Text = GetString("WebPartPropertise.CodeNameAllreadyExists"); etaCode.Rows = 17; return(false); } } else { lblError.Visible = true; lblError.Text = result; etaCode.Rows = 17; return(false); } } return(true); }
/// <summary> /// Button OK click handler. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // Trim text values txtWebPartName.Text = txtWebPartName.Text.Trim(); txtWebPartDisplayName.Text = txtWebPartDisplayName.Text.Trim(); txtWebPartFileName.Text = txtWebPartFileName.Text.Trim(); // Validate the text box fields string errorMessage = new Validator() .NotEmpty(txtWebPartName.Text, rfvWebPartName.ErrorMessage) .NotEmpty(txtWebPartDisplayName.Text, rfvWebPartDisplayName.ErrorMessage) .IsCodeName(txtWebPartName.Text, GetString("WebPart_Clone.InvalidCodeName")) .Result; // Validate file name if (string.IsNullOrEmpty(errorMessage) && chckCloneWebPartFiles.Checked) { errorMessage = new Validator() .NotEmpty(txtWebPartFileName.Text, rfvWebPartFileName.ErrorMessage) .IsFileName(Path.GetFileName(txtWebPartFileName.Text.Trim('~')), GetString("WebPart_Clone.InvalidFileName")).Result; } // Check if webpart with same name exists if (WebPartInfoProvider.GetWebPartInfo(txtWebPartName.Text) != null) { errorMessage = GetString(String.Format("Development-WebPart_Clone.WebPartExists", txtWebPartName.Text)); } // Check if webpart is not cloned to the root category WebPartCategoryInfo wci = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName("/"); if (wci.CategoryID == ValidationHelper.GetInteger(drpWebPartCategories.SelectedValue, -1)) { errorMessage = GetString("Development-WebPart_Clone.cannotclonetoroot"); } if (errorMessage != "") { lblError.Text = errorMessage; lblError.Visible = true; return; } // get web part info object WebPartInfo wi = WebPartInfoProvider.GetWebPartInfo(webPartId); if (wi == null) { lblError.Text = GetString("WebPart_Clone.InvalidWebPartID"); lblError.Visible = true; return; } // Create new webpart with all properties from source webpart WebPartInfo nwpi = new WebPartInfo(wi, false); nwpi.WebPartID = 0; nwpi.WebPartGUID = Guid.NewGuid(); // Modify clone info nwpi.WebPartName = txtWebPartName.Text; nwpi.WebPartDisplayName = txtWebPartDisplayName.Text; nwpi.WebPartCategoryID = ValidationHelper.GetInteger(drpWebPartCategories.SelectedValue, -1); if (nwpi.WebPartParentID <= 0) { nwpi.WebPartFileName = txtWebPartFileName.Text; } string path = String.Empty; string filename = String.Empty; string inher = String.Empty; try { // Copy file if needed and webpart is not ihnerited if (chckCloneWebPartFiles.Checked && (wi.WebPartParentID == 0)) { // Get source file path string srcFile = GetWebPartPhysicalPath(wi.WebPartFileName); // Get destination file path string dstFile = GetWebPartPhysicalPath(nwpi.WebPartFileName); // Ensure directory DirectoryHelper.EnsureDiskPath(Path.GetDirectoryName(DirectoryHelper.EnsurePathBackSlash(dstFile)), URLHelper.WebApplicationPhysicalPath); // Check if source and target file path are different if (File.Exists(dstFile)) { throw new Exception(GetString("general.fileexists")); } // Get file name filename = Path.GetFileName(dstFile); // Get path to the partial class name replace string wpPath = nwpi.WebPartFileName; if (!wpPath.StartsWith("~/")) { wpPath = WebPartInfoProvider.WebPartsDirectory + "/" + wpPath.TrimStart('/'); } path = Path.GetDirectoryName(wpPath); inher = path.Replace('\\', '_').Replace('/', '_') + "_" + Path.GetFileNameWithoutExtension(filename).Replace('.', '_'); inher = inher.Trim('~'); inher = inher.Trim('_'); // Read .aspx file, replace classname and save as new file string text = File.ReadAllText(srcFile); File.WriteAllText(dstFile, ReplaceASCX(text, DirectoryHelper.CombinePath(path, filename), inher)); // Read .aspx file, replace classname and save as new file if (File.Exists(srcFile + ".cs")) { text = File.ReadAllText(srcFile + ".cs"); File.WriteAllText(dstFile + ".cs", ReplaceASCXCS(text, inher)); } if (File.Exists(srcFile + ".vb")) { text = File.ReadAllText(srcFile + ".vb"); File.WriteAllText(dstFile + ".vb", ReplaceASCXVB(text, inher)); } // Copy web part subfolder string srcDirectory = srcFile.Remove(srcFile.Length - Path.GetFileName(srcFile).Length) + Path.GetFileNameWithoutExtension(srcFile) + "_files"; if (Directory.Exists(srcDirectory)) { string dstDirectory = dstFile.Remove(dstFile.Length - Path.GetFileName(dstFile).Length) + Path.GetFileNameWithoutExtension(dstFile) + "_files"; if (srcDirectory.ToLower() != dstDirectory.ToLower()) { DirectoryHelper.EnsureDiskPath(srcDirectory, URLHelper.WebApplicationPhysicalPath); DirectoryHelper.CopyDirectory(srcDirectory, dstDirectory); } } } } catch (Exception ex) { lblError.Text = ex.Message; lblError.Visible = true; return; } // Add new web part to database WebPartInfoProvider.SetWebPartInfo(nwpi); try { // Get and duplicate all webpart layouts associated to webpart DataSet ds = WebPartLayoutInfoProvider.GetWebPartLayouts(webPartId); if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow dr in ds.Tables[0].Rows) { WebPartLayoutInfo wpli = new WebPartLayoutInfo(dr); wpli.WebPartLayoutID = 0; // Create new record wpli.WebPartLayoutWebPartID = nwpi.WebPartID; // Associate layout to new webpart wpli.WebPartLayoutGUID = Guid.NewGuid(); wpli.WebPartLayoutCheckedOutByUserID = 0; wpli.WebPartLayoutCheckedOutFilename = ""; wpli.WebPartLayoutCheckedOutMachineName = ""; // Replace classname and inherits attribut wpli.WebPartLayoutCode = ReplaceASCX(wpli.WebPartLayoutCode, DirectoryHelper.CombinePath(path, filename), inher); WebPartLayoutInfoProvider.SetWebPartLayoutInfo(wpli); } } // Duplicate associated thumbnail MetaFileInfoProvider.CopyMetaFiles(webPartId, nwpi.WebPartID, PortalObjectType.WEBPART, MetaFileInfoProvider.OBJECT_CATEGORY_THUMBNAIL, null); } catch (Exception ex) { lblError.Text = ex.Message; lblError.Visible = true; return; } // Close clone window // Refresh web part tree and select/edit new widget string script = String.Empty; string refreshLink = URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_Tree.aspx?webpartid=" + nwpi.WebPartID + "&reload=true"); if (QueryHelper.Contains("reloadAll")) { script += "wopener.parent.parent.frames['webparttree'].location.href ='" + refreshLink + "';"; } else { script = "wopener.location = '" + refreshLink + "';"; } script += "window.close();"; ltlScript.Text = ScriptHelper.GetScript(script); }