/// <summary> /// Creates web part. Called when the "Create part" button is pressed. /// </summary> private bool CreateWebPart() { // Get parent category for web part WebPartCategoryInfo category = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName("MyNewCategory"); if (category != null) { // Create new web part object WebPartInfo newWebpart = new WebPartInfo(); // Set the properties newWebpart.WebPartDisplayName = "My new web part"; newWebpart.WebPartName = "MyNewWebpart"; newWebpart.WebPartDescription = "This is my new web part."; newWebpart.WebPartFileName = "whatever"; newWebpart.WebPartProperties = "<form></form>"; newWebpart.WebPartCategoryID = category.CategoryID; // Save the web part WebPartInfoProvider.SetWebPartInfo(newWebpart); return(true); } return(false); }
/// <summary> /// Handle btnOK's OnClick event. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { string errorMessage = ""; // Get WebPartInfo. WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(QueryHelper.GetInteger("webpartid", 0)); if (wpi != null) { // Update web part CSS try { wpi.WebPartCSS = etaCSS.Text; WebPartInfoProvider.SetWebPartInfo(wpi); lblInfo.Text = GetString("General.ChangesSaved"); lblInfo.Visible = true; } catch (Exception ex) { errorMessage = ex.Message; } // Show error message if (errorMessage != "") { lblError.Text = errorMessage; lblError.Visible = true; } } }
/// <summary> /// Gets and bulk updates web parts. Called when the "Get and bulk update parts" button is pressed. /// Expects the CreateWebPart method to be run first. /// </summary> private bool GetAndBulkUpdateWebParts() { // Prepare the parameters string where = "WebPartName LIKE N'MyNewWebpart%'"; // Get the data DataSet webparts = WebPartInfoProvider.GetWebParts(where, null); if (!DataHelper.DataSourceIsEmpty(webparts)) { // Loop through the individual items foreach (DataRow webpartDr in webparts.Tables[0].Rows) { // Create object from DataRow WebPartInfo modifyWebpart = new WebPartInfo(webpartDr); // Update the properties modifyWebpart.WebPartDisplayName = modifyWebpart.WebPartDisplayName.ToUpper(); // Save the changes WebPartInfoProvider.SetWebPartInfo(modifyWebpart); } return(true); } return(false); }
/// <summary> /// Event loaded after ok button clicked. /// </summary> /// <param name="sender">Sender</param> /// <param name="e">Event args</param> void ucDefaultValueEditor_XMLCreated(object sender, EventArgs e) { int webPartId = QueryHelper.GetInteger("webpartid", 0); WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPartId); if (wpi != null) { if (wpi.WebPartParentID > 0) { //Remove overloaded default values and replace them with new ones string filteredDef = String.Empty; //Load parent WebPartInfo parentInfo = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID); if (parentInfo != null) { // Remove properties from collection with same name as in default system xml filteredDef = ucDefaultValueEditor.FitlerDefaultValuesDefinition(wpi.WebPartDefaultValues, parentInfo.WebPartProperties, false); } // FilteredDef now contains only properties inherited from parent web part // Combine with changed default system values wpi.WebPartDefaultValues = FormHelper.CombineFormDefinitions(filteredDef, ucDefaultValueEditor.DefaultValueXMLDefinition); } else { wpi.WebPartDefaultValues = ucDefaultValueEditor.DefaultValueXMLDefinition; } WebPartInfoProvider.SetWebPartInfo(wpi); } string url = URLHelper.RemoveParameterFromUrl(URLRewriter.CurrentURL, "saved"); url = URLHelper.AddParameterToUrl(url, "saved", "1"); URLHelper.Redirect(url); }
/// <summary> /// Handle btnOK's OnClick event. /// </summary> protected void Save() { string errorMessage = ""; if (wpi != null) { // Update web part CSS try { wpi.WebPartCSS = etaCSS.Text; WebPartInfoProvider.SetWebPartInfo(wpi); ShowChangesSaved(); } catch (Exception ex) { errorMessage = ex.Message; } // Show error message if (errorMessage != "") { ShowError(errorMessage); } RegisterRefreshScript(); } }
/// <summary> /// OK click handler, save changes. /// </summary> protected void btnOk_Click(object sender, EventArgs e) { WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webpartId); if (wpi != null) { wpi.WebPartDocumentation = htmlText.ResolvedValue; WebPartInfoProvider.SetWebPartInfo(wpi); ShowChangesSaved(); } }
private void SaveFormUpdates(IWebPart webPart) { var webPartInfo = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartID); if (webPartInfo == null) { return; } webPartInfo.WebPartProperties = webPart.WebPartProperties; WebPartInfoProvider.SetWebPartInfo(webPartInfo); }
/// <summary> /// OK click handler, save changes. /// </summary> protected void btnOk_Click(object sender, EventArgs e) { WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webpartId); if (wpi != null) { wpi.WebPartDocumentation = htmlText.ResolvedValue; WebPartInfoProvider.SetWebPartInfo(wpi); lblInfo.Visible = true; lblInfo.Text = GetString("General.ChangesSaved"); } }
/// <inheritdoc /> public IWebPart Create(IWebPart webPart) { var webPartInfo = new WebPartInfo { WebPartCategoryID = webPart.WebPartCategoryID, WebPartFileName = webPart.WebPartFileName, WebPartDisplayName = webPart.WebPartDisplayName, WebPartName = webPart.WebPartName, WebPartProperties = FormInfo.GetEmptyFormDocument().OuterXml, }; WebPartInfoProvider.SetWebPartInfo(webPartInfo); return(webPartInfo.ActLike <IWebPart>()); }
/// <summary> /// XML created, save it. /// </summary> protected void defaultValueEditor_XMLCreated(object sender, EventArgs e) { if (!String.IsNullOrEmpty(defaultValueEditor.ErrorMessage)) { ShowError(defaultValueEditor.ErrorMessage); return; } if (wi != null) { // Load xml definition if (wi.WebPartParentID > 0) { // Load the form definition string before = PortalFormHelper.GetWebPartProperties(WebPartTypeEnum.Standard, PropertiesPosition.Before); string after = PortalFormHelper.GetWebPartProperties(WebPartTypeEnum.Standard, PropertiesPosition.Before); string formDef = FormHelper.CombineFormDefinitions(before, after); // Web part default values contains either properties or changed "system" values // First Remove records with same name as "system properties" => only actual webpart's properties remains string filteredDef = defaultValueEditor.FitlerDefaultValuesDefinition(wi.WebPartDefaultValues, formDef, false); WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WebPartParentID); // Remove records with same name as parent's property - its already stored in webpart's properties if (wpi != null) { filteredDef = defaultValueEditor.FitlerDefaultValuesDefinition(filteredDef, wpi.WebPartProperties, true); } // If inherited web part merge webpart's properties hier with default system values wi.WebPartDefaultValues = FormHelper.CombineFormDefinitions(filteredDef, defaultValueEditor.DefaultValueXMLDefinition); } else { wi.WebPartProperties = defaultValueEditor.DefaultValueXMLDefinition; } // Sav web part info WebPartInfoProvider.SetWebPartInfo(wi); // Redirect with saved assign string url = URLHelper.RemoveParameterFromUrl(URLRewriter.CurrentURL, "saved"); url = URLHelper.AddParameterToUrl(url, "saved", "1"); URLHelper.Redirect(url); } }
/// <inheritdoc /> public void Update(IWebPart webPart) { var webPartInfo = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartID); if (webPartInfo == null) { return; } webPartInfo.WebPartCategoryID = webPart.WebPartCategoryID; webPartInfo.WebPartDisplayName = webPart.WebPartDisplayName; webPartInfo.WebPartFileName = webPart.WebPartFileName; webPartInfo.WebPartName = webPart.WebPartName; webPartInfo.WebPartProperties = webPart.WebPartProperties; WebPartInfoProvider.SetWebPartInfo(webPartInfo); }
/// <summary> /// Gets and updates web part. Called when the "Get and update part" button is pressed. /// Expects the CreateWebPart method to be run first. /// </summary> private bool GetAndUpdateWebPart() { // Get the web part WebPartInfo updateWebpart = WebPartInfoProvider.GetWebPartInfo("MyNewWebpart"); if (updateWebpart != null) { // Update the properties updateWebpart.WebPartDisplayName = updateWebpart.WebPartDisplayName.ToLower(); // Save the changes WebPartInfoProvider.SetWebPartInfo(updateWebpart); return(true); } return(false); }
/// <summary> /// XML created, save it. /// </summary> protected void DefaultValueEditor1_XMLCreated(object sender, EventArgs e) { if (wi != null) { // Load xml definition if (wi.WebPartParentID > 0) { XmlDocument xmlBefore = new XmlDocument(); XmlDocument xmlAfter = new XmlDocument(); xmlBefore.Load(Server.MapPath("~/CMSModules/PortalEngine/UI/WebParts/Properties/WebPart_PropertiesBefore.xml")); xmlAfter.Load(Server.MapPath("~/CMSModules/PortalEngine/UI/WebParts/Properties/WebPart_PropertiesAfter.xml")); string formDef = FormHelper.CombineFormDefinitions(xmlBefore.DocumentElement.OuterXml, xmlAfter.DocumentElement.OuterXml); // Web part default values contains either properties or changed "system" values // First Remove records with same name as "system properties" => only actual webpart's properties remains string filteredDef = this.DefaultValueEditor1.FitlerDefaultValuesDefinition(wi.WebPartDefaultValues, formDef, false); WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WebPartParentID); // Remove records with same name as parent's property - its already stored in webpart's properties if (wpi != null) { filteredDef = this.DefaultValueEditor1.FitlerDefaultValuesDefinition(filteredDef, wpi.WebPartProperties, true); } // If inherited web part merge webpart's properties hier with default system values wi.WebPartDefaultValues = FormHelper.CombineFormDefinitions(filteredDef, this.DefaultValueEditor1.DefaultValueXMLDefinition); } else { wi.WebPartProperties = this.DefaultValueEditor1.DefaultValueXMLDefinition; } // Sav web part info WebPartInfoProvider.SetWebPartInfo(wi); // Redirect with saved assign string url = URLHelper.RemoveParameterFromUrl(URLRewriter.CurrentURL, "saved"); url = URLHelper.AddParameterToUrl(url, "saved", "1"); URLHelper.Redirect(url); } }
/// <summary> /// Handles OnAfterDefinitionUpdate action and updates form definition of inherited web part. /// </summary> protected void fieldEditor_OnAfterDefinitionUpdate(object sender, EventArgs e) { if ((webPartInfo != null) && (parentWebPartInfo != null)) { // Compare original and alternative form definitions - store differences only webPartInfo.WebPartProperties = FormHelper.GetFormDefinitionDifference(parentWebPartInfo.WebPartProperties, fieldEditor.FormDefinition, true); // If there is no difference save empty form if (string.IsNullOrEmpty(webPartInfo.WebPartProperties)) { webPartInfo.WebPartProperties = "<form></form>"; } // Update web part info in database WebPartInfoProvider.SetWebPartInfo(webPartInfo); } else { ShowError(GetString("general.invalidid")); } }
/// <summary> /// Adds web part. /// </summary> private void AddWebPart() { int webpartID = ValidationHelper.GetInteger(WebpartId, 0); // Add web part to the currently selected zone under currently selected page if ((webpartID > 0) && !string.IsNullOrEmpty(ZoneId)) { // Get the web part by code name WebPartInfo wi = WebPartInfoProvider.GetWebPartInfo(webpartID); if (wi != null) { // Ensure layout zone flag if (QueryHelper.GetBoolean("layoutzone", false)) { WebPartZoneInstance zone = pti.EnsureZone(ZoneId); zone.LayoutZone = true; } // Add the web part WebPartInstance newPart = null; if (ZoneVariantID == 0) { newPart = pti.AddWebPart(ZoneId, webpartID); } else { WebPartZoneInstance wpzi = templateInstance.EnsureZone(ZoneId); // Load the zone variants if not loaded yet if (wpzi.ZoneInstanceVariants == null) { wpzi.LoadVariants(); } // Find the correct zone variant wpzi = wpzi.ZoneInstanceVariants.Find(z => z.VariantID.Equals(ZoneVariantID)); if (wpzi != null) { newPart = wpzi.AddWebPart(webpartID); } } if (newPart != null) { // Prepare the form info to get the default properties FormInfo fi = null; if (wi.WebPartParentID > 0) { // Get from parent WebPartInfo parentWi = WebPartInfoProvider.GetWebPartInfo(wi.WebPartParentID); if (parentWi != null) { fi = new FormInfo(parentWi.WebPartProperties); } } if (fi == null) { fi = new FormInfo(wi.WebPartProperties); } // Load the default values to the properties if (fi != null) { DataRow dr = fi.GetDataRow(); fi.LoadDefaultValues(dr); newPart.LoadProperties(dr); } // Add webpart to user's last recently used CMSContext.CurrentUser.UserSettings.UpdateRecentlyUsedWebPart(wi.WebPartName); // Add last selection date to webpart wi.WebPartLastSelection = DateTime.Now; WebPartInfoProvider.SetWebPartInfo(wi); webPartInstance = newPart; } } } }
/// <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); }
/// <summary> /// Creates new web part. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // Validate the text box fields string errorMessage = new Validator().IsCodeName(txtWebPartName.Text, GetString("general.invalidcodename")).Result; // Validate and trim file name textbox only if it's visible if (radNewWebPart.Checked && radNewFile.Checked) { if (String.IsNullOrEmpty(errorMessage)) { errorMessage = new Validator().IsFileName(Path.GetFileName(txtCodeFileName.Text), GetString("WebPart_Clone.InvalidFileName")).Result; } } // Check file name if (radExistingFile.Checked && radNewWebPart.Checked) { if (String.IsNullOrEmpty(errorMessage)) { string webpartPath = WebPartInfoProvider.GetWebPartPhysicalPath(FileSystemSelector.Value.ToString()); errorMessage = new Validator().IsFileName(Path.GetFileName(webpartPath), GetString("WebPart_Clone.InvalidFileName")).Result; } } if (!String.IsNullOrEmpty(errorMessage)) { ShowError(HTMLHelper.HTMLEncode(errorMessage)); return; } // Run in transaction using (var tr = new CMSTransactionScope()) { WebPartInfo wi = new WebPartInfo(); // Check if new name is unique WebPartInfo webpart = WebPartInfoProvider.GetWebPartInfo(txtWebPartName.Text); if (webpart != null) { ShowError(GetString("Development.WebParts.WebPartNameAlreadyExist").Replace("%%name%%", txtWebPartName.Text)); return; } string filename = String.Empty; if (radNewWebPart.Checked) { if (radExistingFile.Checked) { filename = FileSystemSelector.Value.ToString().Trim(); if (filename.ToLowerCSafe().StartsWithCSafe("~/cmswebparts/")) { filename = filename.Substring("~/cmswebparts/".Length); } } else { filename = txtCodeFileName.Text.Trim(); if (!filename.EndsWithCSafe(".ascx")) { filename += ".ascx"; } } } wi.WebPartDisplayName = txtWebPartDisplayName.Text.Trim(); wi.WebPartFileName = filename; wi.WebPartName = txtWebPartName.Text.Trim(); wi.WebPartCategoryID = QueryHelper.GetInteger("parentobjectid", 0); wi.WebPartDescription = ""; wi.WebPartDefaultValues = "<form></form>"; // Initialize WebPartType - fill it with the default value wi.WebPartType = wi.WebPartType; // Inherited web part if (radInherited.Checked) { // Check if is selected webpart and isn't category item if (ValidationHelper.GetInteger(webpartSelector.Value, 0) <= 0) { ShowError(GetString("WebPartNew.InheritedCategory")); return; } int parentId = ValidationHelper.GetInteger(webpartSelector.Value, 0); var parent = WebPartInfoProvider.GetWebPartInfo(parentId); if (parent != null) { wi.WebPartType = parent.WebPartType; wi.WebPartResourceID = parent.WebPartResourceID; wi.WebPartSkipInsertProperties = parent.WebPartSkipInsertProperties; } wi.WebPartParentID = parentId; // Create empty default values definition wi.WebPartProperties = "<defaultvalues></defaultvalues>"; } else { // Check if filename was added if (FileSystemSelector.Visible && !FileSystemSelector.IsValid()) { ShowError(FileSystemSelector.ValidationError); return; } wi.WebPartProperties = "<form></form>"; wi.WebPartParentID = 0; } // Save the web part WebPartInfoProvider.SetWebPartInfo(wi); if (radNewFile.Checked && radNewWebPart.Checked) { string physicalFile = WebPartInfoProvider.GetFullPhysicalPath(wi); if (!File.Exists(physicalFile)) { string ascx; string code; string designer; // Write the files try { WebPartInfoProvider.GenerateWebPartCode(wi, null, out ascx, out code, out designer); string folder = Path.GetDirectoryName(physicalFile); // Ensure the folder if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } File.WriteAllText(physicalFile, ascx); File.WriteAllText(physicalFile + ".cs", code); // Designer file if (!String.IsNullOrEmpty(designer)) { File.WriteAllText(physicalFile + ".designer.cs", designer); } } catch (Exception ex) { LogAndShowError("WebParts", "GENERATEFILES", ex, true); return; } } else { ShowError(String.Format(GetString("General.FileExistsPath"), physicalFile)); return; } } // Refresh web part tree ScriptHelper.RegisterStartupScript(this, typeof(string), "reloadframee", ScriptHelper.GetScript( "parent.location = '" + UIContextHelper.GetElementUrl("cms.design", "Development.Webparts", false, wi.WebPartID) + "';")); PageBreadcrumbs.Items[1].Text = HTMLHelper.HTMLEncode(wi.WebPartDisplayName); ShowChangesSaved(); plcTable.Visible = false; tr.Commit(); } }
/// <summary> /// Updates existing or creates new web part. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // Validate the text box fields string errorMessage = new Validator().IsCodeName(txtWebPartName.Text, GetString("general.invalidcodename")).Result; if (errorMessage != String.Empty) { ShowError(errorMessage); return; } WebPartInfo wi = WebPartInfoProvider.GetWebPartInfo(webPartId); if (wi != null) { string webpartPath = GetWebPartPhysicalPath(FileSystemSelector.Value.ToString()); txtWebPartName.Text = TextHelper.LimitLength(txtWebPartName.Text.Trim(), 100, ""); txtWebPartDisplayName.Text = TextHelper.LimitLength(txtWebPartDisplayName.Text.Trim(), 100, ""); // Perform validation errorMessage = new Validator().NotEmpty(txtWebPartName.Text, rfvWebPartName.ErrorMessage).IsCodeName(txtWebPartName.Text, GetString("general.invalidcodename")) .NotEmpty(txtWebPartDisplayName.Text, rfvWebPartDisplayName.ErrorMessage).Result; // Check file name if (wi.WebPartParentID <= 0) { if (!FileSystemSelector.IsValid()) { errorMessage += FileSystemSelector.ValidationError; } } if (errorMessage != String.Empty) { ShowError(errorMessage); return; } string oldDisplayName = wi.WebPartDisplayName; string oldCodeName = wi.WebPartName; int oldCategory = wi.WebPartCategoryID; // Remove starting CMSwebparts folder string filename = FileSystemSelector.Value.ToString().Trim(); if (filename.ToLowerCSafe().StartsWithCSafe("~/cmswebparts/")) { filename = filename.Substring("~/cmswebparts/".Length); } // If name changed, check if new name is unique if (CMSString.Compare(wi.WebPartName, txtWebPartName.Text, true) != 0) { WebPartInfo webpart = WebPartInfoProvider.GetWebPartInfo(txtWebPartName.Text); if (webpart != null) { ShowError(GetString("Development.WebParts.WebPartNameAlreadyExist").Replace("%%name%%", txtWebPartName.Text)); return; } } wi.WebPartName = txtWebPartName.Text; wi.WebPartDisplayName = txtWebPartDisplayName.Text; wi.WebPartDescription = txtWebPartDescription.Text.Trim(); wi.WebPartFileName = filename; wi.WebPartType = ValidationHelper.GetInteger(drpWebPartType.SelectedValue, 0); wi.WebPartSkipInsertProperties = chkSkipInsertProperties.Checked; wi.WebPartLoadGeneration = drpGeneration.Value; wi.WebPartResourceID = ValidationHelper.GetInteger(drpModule.Value, 0); FileSystemSelector.Value = wi.WebPartFileName; wi.WebPartCategoryID = ValidationHelper.GetInteger(categorySelector.Value, 0); WebPartInfoProvider.SetWebPartInfo(wi); // if DisplayName or Category was changed, then refresh web part tree and header if ((oldCodeName != wi.WebPartName) || (oldDisplayName != wi.WebPartDisplayName) || (oldCategory != wi.WebPartCategoryID)) { ltlScript.Text += ScriptHelper.GetScript( "parent.parent.frames['webparttree'].location.replace('WebPart_Tree.aspx?webpartid=" + wi.WebPartID + "'); \n" + "parent.frames['webparteditheader'].location.replace(parent.frames['webparteditheader'].location.href); \n" ); } ShowChangesSaved(); } }
/// <summary> /// Creates new web part. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // Validate the text box fields string errorMessage = new Validator().IsCodeName(txtWebPartName.Text, GetString("general.invalidcodename")).Result; // Check file name if (errorMessage == String.Empty) { string webpartPath = GetWebPartPhysicalPath(FileSystemSelector.Value.ToString()); if (!radInherited.Checked) { errorMessage = new Validator().IsFileName(Path.GetFileName(webpartPath), GetString("WebPart_Clone.InvalidFileName")).Result; } } if (errorMessage != String.Empty) { lblError.Text = HTMLHelper.HTMLEncode(errorMessage); lblError.Visible = true; return; } WebPartInfo wi = new WebPartInfo(); // Check if new name is unique WebPartInfo webpart = WebPartInfoProvider.GetWebPartInfo(txtWebPartName.Text); if (webpart != null) { lblError.Visible = true; lblError.Text = GetString("Development.WebParts.WebPartNameAlreadyExist").Replace("%%name%%", txtWebPartName.Text); return; } string filename = FileSystemSelector.Value.ToString().Trim(); if (filename.ToLower().StartsWith("~/cmswebparts/")) { filename = filename.Substring("~/cmswebparts/".Length); } wi.WebPartDisplayName = txtWebPartDisplayName.Text.Trim(); wi.WebPartFileName = filename; wi.WebPartName = txtWebPartName.Text.Trim(); wi.WebPartCategoryID = QueryHelper.GetInteger("parentid", 0); wi.WebPartDescription = ""; wi.WebPartDefaultValues = "<form></form>"; // Inherited webpart if (radInherited.Checked) { // Check if is selected webpart and isn't category item if (ValidationHelper.GetInteger(webpartSelector.Value, 0) <= 0) { lblError.Visible = true; lblError.Text = GetString("WebPartNew.InheritedCategory"); return; } wi.WebPartParentID = ValidationHelper.GetInteger(webpartSelector.Value, 0); // Create empty default values definition wi.WebPartProperties = "<defaultvalues></defaultvalues>"; } else { // Check if filename was added if (!FileSystemSelector.IsValid()) { lblError.Visible = true; lblError.Text = FileSystemSelector.ValidationError; return; } else { wi.WebPartProperties = "<form></form>"; wi.WebPartParentID = 0; } } WebPartInfoProvider.SetWebPartInfo(wi); // Refresh web part tree ScriptHelper.RegisterStartupScript(this, typeof(string), "reloadframe", ScriptHelper.GetScript( "parent.frames['webparttree'].location.replace('" + URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_Tree.aspx") + "?webpartid=" + wi.WebPartID + "');" + "location.replace('" + URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_Edit_Frameset.aspx") + "?webpartid=" + wi.WebPartID + "')" )); pageTitleTabs[1, 0] = HTMLHelper.HTMLEncode(wi.WebPartDisplayName); this.CurrentMaster.Title.Breadcrumbs = pageTitleTabs; lblInfo.Visible = true; lblInfo.Text = GetString("General.ChangesSaved"); plcTable.Visible = false; }