/// <summary> /// Gets the prevalue editor settings. /// </summary> /// <param name="dataTypeDefinitionId">The data type definition id.</param> /// <returns>The PreValue Editor Settings.</returns> public PreValueEditorSettings GetPrevalueEditorSettings(int dataTypeDefinitionId) { var prevalues = PreValues.GetPreValues(dataTypeDefinitionId); var settings = new PreValueEditorSettings(); if (prevalues.Count > 0) { var prevalue = (PreValue)prevalues[0]; if (!string.IsNullOrEmpty(prevalue.Value)) { var serializer = new JavaScriptSerializer(); try { settings = serializer.Deserialize <PreValueEditorSettings>(prevalue.Value); } catch (Exception ex) { // Cannot understand stored prevalues Helper.Log.Error <DataType>("Error when parsing stored prevalues", ex); } } } return(settings); }
/// <summary> /// Initializes a new instance of the <see cref="DataEditor"/> class. /// </summary> /// <param name="data">The data.</param> /// <param name="settings">The settings.</param> /// <param name="dataTypeDefinitionId">The data type definition id.</param> /// <param name="instanceId">The instance id.</param> public DataEditor(IData data, PreValueEditorSettings settings, int dataTypeDefinitionId, string instanceId) { this.settings = settings; this.data = data; this.dataTypeDefinitionId = dataTypeDefinitionId; this.instanceId = instanceId; }
/// <summary> /// Saves this instance. /// </summary> public override void Save() { lock (m_Locker) { var prevalues = new List <object>(); // Set settings if (this._settings == null) { this._settings = DtgHelpers.GetSettings(this.m_DataType.DataTypeDefinitionId); } this._settings.ShowLabel = this._showLabel != null && this._showLabel.Checked; this._settings.ShowGridHeader = this._showHeader != null && this._showHeader.Checked; this._settings.ShowGridFooter = this._showFooter != null && this._showFooter.Checked; this._settings.ReadOnly = this._readOnly != null && this._readOnly.Checked; this._settings.TableHeight = this._tableHeight != null?int.Parse(this._tableHeight.Text) : 300; prevalues.Add(this._settings); // Add existing prevalues; foreach (var t in this._preValues) { var parsedprevalue = ParsePrevalue(t); if (parsedprevalue != null) { prevalues.Add(parsedprevalue); } } // Add last (new) prevalue var newprevalue = ParsePrevalue(this._newPreValue); if (newprevalue != null) { prevalues.Add(newprevalue); } if (prevalues.Count > 0) { // Delete former values PreValues.DeleteByDataTypeDefinition(this.m_DataType.DataTypeDefinitionId); // Add new values AddPrevalues(prevalues); // Must not refresh on initial load. [LK] if (prevalues.Count > 1) { // Reload IFrame to show changes this.Page.Response.Redirect(this.Page.Request.Url.ToString()); } } } }
/// <summary> /// Initializes a new instance of the <see cref="DataEditor"/> class. /// </summary> /// <param name="data">The data.</param> /// <param name="settings">The settings.</param> /// <param name="dataTypeDefinitionId">The data type definition id.</param> /// <param name="instanceId">The instance id.</param> public DataEditor(IData data, PreValueEditorSettings settings, int dataTypeDefinitionId, string instanceId) { // Set up dependencies this.prevalueEditorSettingsHandler = new PrevalueEditorSettingsHandler(); this.settings = settings; this.data = data; this.dataTypeDefinitionId = dataTypeDefinitionId; this.instanceId = instanceId; }
/// <summary> /// Creates child controls for this control /// </summary> protected override void CreateChildControls() { base.CreateChildControls(); // Get configuration this._newPreValue = new PreValueRow(); this._preValues = new List <PreValueRow>(); this._settings = DtgHelpers.GetSettings(this.m_DataType.DataTypeDefinitionId); this.GetConfig(); // Instantiate default controls this._accordionContainer = new Panel { ID = "dtg_accordion_" + this.m_DataType.DataTypeDefinitionId, CssClass = "dtg_accordion" }; this._showLabel = new CheckBox() { ID = "showLabel", Checked = this._settings.ShowLabel }; this._showHeader = new CheckBox() { ID = "showHeader", Checked = this._settings.ShowGridHeader }; this._showFooter = new CheckBox() { ID = "showFooter", Checked = this._settings.ShowGridFooter }; this._readOnly = new CheckBox() { ID = "readOnly", Checked = this._settings.ReadOnly }; this._tableHeight = new TextBox() { ID = "TableHeight", Text = this._settings.TableHeight.ToString() }; this._tableHeightValidator = new RegularExpressionValidator() { ID = "NumberOfRowsValidator", CssClass = "validator", ValidationExpression = @"^[1-9]*[0-9]*$", ControlToValidate = this._tableHeight.ClientID, Display = ValidatorDisplay.Dynamic, ErrorMessage = Helper.Dictionary.GetDictionaryItem("MustBeANumber", "Must be a number") }; // Write controls for adding new entry var addNewProperty = new Panel() { ID = "newProperty", CssClass = "addNewProperty" }; var addNewPropertyHeader = new Panel() { CssClass = "propertyHeader" }; var addNewPropertyTitle = new HtmlGenericControl("h3") { InnerText = Helper.Dictionary.GetDictionaryItem("AddNewDataType", "Add new datatype") }; addNewPropertyTitle.Attributes["class"] = "propertyTitle"; var icnNewError = new HtmlGenericControl("span") { InnerText = Helper.Dictionary.GetDictionaryItem("Error", "Error") }; icnNewError.Attributes["class"] = "ErrorProperty"; addNewPropertyHeader.Controls.Add(addNewPropertyTitle); addNewPropertyHeader.Controls.Add(icnNewError); var addNewPropertyControls = new Panel() { ID = "addNewPropertyControls", CssClass = "propertyControls" }; addNewPropertyControls.Controls.Add(new LiteralControl() { Text = "<ul>" }); // NAME addNewPropertyControls.Controls.Add(new LiteralControl() { Text = "<li>" }); // Instantiate controls var txtNewName = new TextBox() { ID = "newName", CssClass = "newName" }; var lblNewName = new Label() { AssociatedControlID = txtNewName.ClientID, Text = Helper.Dictionary.GetDictionaryItem("Name", "Name") + "<br/><small class='description'>" + Helper.Dictionary.GetDictionaryItem( "NameDescription", "The column display name") + "</small>", CssClass = "label" }; var valNewName = new RequiredFieldValidator() { ID = "newNameValidator", CssClass = "validator", Enabled = false, ControlToValidate = txtNewName.ClientID, Display = ValidatorDisplay.Dynamic, ErrorMessage = Helper.Dictionary.GetDictionaryItem("YouMustSpecifyAName", "You must specify a name") }; // Add controls to control addNewPropertyControls.Controls.Add(lblNewName); addNewPropertyControls.Controls.Add(txtNewName); addNewPropertyControls.Controls.Add(valNewName); ((PreValueRow)this._newPreValue).Controls.Add(txtNewName); addNewPropertyControls.Controls.Add(new LiteralControl() { Text = "</li>" }); // ALIAS addNewPropertyControls.Controls.Add(new LiteralControl() { Text = "<li>" }); // Instantiate controls var txtNewAlias = new TextBox() { ID = "newAlias", CssClass = "newAlias" }; var lblNewAlias = new Label() { AssociatedControlID = txtNewAlias.ClientID, Text = Helper.Dictionary.GetDictionaryItem("Alias", "Alias") + "<br/><small class='description'>" + Helper.Dictionary.GetDictionaryItem( "AliasDescription", "The column alias") + "</small>", CssClass = "label" }; var valNewAlias = new RequiredFieldValidator() { ID = "newAliasValidator", CssClass = "validator", Enabled = false, ControlToValidate = txtNewAlias.ClientID, Display = ValidatorDisplay.Dynamic, ErrorMessage = Helper.Dictionary.GetDictionaryItem("YouMustSpecifyAnAlias", "You must specify an alias") }; var valNewAliasExists = new CustomValidator() { ID = "newAliasExistsValidator", CssClass = "validator exists", Enabled = false, ControlToValidate = txtNewAlias.ClientID, Display = ValidatorDisplay.Dynamic, ClientValidationFunction = "ValidateNewAliasExists", ErrorMessage = Helper.Dictionary.GetDictionaryItem("AliasAlreadyExists", "Alias already exists!") }; valNewAliasExists.ServerValidate += valNewAliasExists_ServerValidate; // Add controls to control addNewPropertyControls.Controls.Add(lblNewAlias); addNewPropertyControls.Controls.Add(txtNewAlias); addNewPropertyControls.Controls.Add(valNewAlias); addNewPropertyControls.Controls.Add(valNewAliasExists); ((PreValueRow)this._newPreValue).Controls.Add(txtNewAlias); addNewPropertyControls.Controls.Add(new LiteralControl() { Text = "</li>" }); // DATATYPE addNewPropertyControls.Controls.Add(new LiteralControl() { Text = "<li>" }); // Instantiate controls var ddlNewType = DtgHelpers.GetDataTypeDropDown(); ddlNewType.ID = "newType"; var lblNewType = new Label() { AssociatedControlID = ddlNewType.ClientID, Text = Helper.Dictionary.GetDictionaryItem("DataType", "Datatype") + "<br/><small class='description'>" + Helper.Dictionary.GetDictionaryItem( "DatatypeDescription", "The column data editor") + "</small>", CssClass = "label" }; // Add controls to control addNewPropertyControls.Controls.Add(lblNewType); addNewPropertyControls.Controls.Add(ddlNewType); ((PreValueRow)this._newPreValue).Controls.Add(ddlNewType); addNewPropertyControls.Controls.Add(new LiteralControl() { Text = "</li>" }); // MANDATORY addNewPropertyControls.Controls.Add(new LiteralControl() { Text = "<li>" }); // Instantiate controls var chkNewMandatory = new CheckBox() { ID = "newMandatory", CssClass = "newMandatory" }; var lblNewMandatory = new Label() { AssociatedControlID = chkNewMandatory.ClientID, Text = Helper.Dictionary.GetDictionaryItem("Mandatory", "Mandatory") + "<br/><small class='description'>" + Helper.Dictionary.GetDictionaryItem( "MandatoryDescription", "Whether this column is mandatory") + "</small>", CssClass = "label" }; // Add controls to control addNewPropertyControls.Controls.Add(lblNewMandatory); addNewPropertyControls.Controls.Add(chkNewMandatory); ((PreValueRow)this._newPreValue).Controls.Add(chkNewMandatory); addNewPropertyControls.Controls.Add(new LiteralControl() { Text = "</li>" }); // VISIBLE addNewPropertyControls.Controls.Add(new LiteralControl() { Text = "<li>" }); // Instantiate controls var chkNewVisible = new CheckBox() { ID = "newVisible", CssClass = "newVisible", Checked = true }; var lblNewVisible = new Label() { AssociatedControlID = chkNewVisible.ClientID, Text = Helper.Dictionary.GetDictionaryItem("Visible", "Visible") + "<br/><small class='description'>" + Helper.Dictionary.GetDictionaryItem( "VisibleDescription", "Whether this column is visible in the grid. <br/>(it can still be edited)") + "</small>", CssClass = "label" }; // Add controls to control addNewPropertyControls.Controls.Add(lblNewVisible); addNewPropertyControls.Controls.Add(chkNewVisible); ((PreValueRow)this._newPreValue).Controls.Add(chkNewVisible); addNewPropertyControls.Controls.Add(new LiteralControl() { Text = "</li>" }); // VALIDATION addNewPropertyControls.Controls.Add(new LiteralControl() { Text = "<li>" }); // Instantiate controls var txtNewValidation = new TextBox() { ID = "newValidation", TextMode = TextBoxMode.MultiLine, Rows = 2, Columns = 20, CssClass = "newValidation" }; var lblNewValidation = new Label() { AssociatedControlID = txtNewValidation.ClientID, Text = Helper.Dictionary.GetDictionaryItem("Validation", "Validation") + "<br/><small class='description'>" + Helper.Dictionary.GetDictionaryItem( "ValidationDescription", "The regular expression used for validation. Leave empty to disable") + "</small>", CssClass = "label" }; var lnkNewValidation = new HyperLink { ID = "newValidationLink", CssClass = "validationLink", NavigateUrl = "#", Text = Helper.Dictionary.GetDictionaryItem( "SearchForARegularExpression", "Search for a regular expression") }; var valNewValidation = new CustomValidator() { ID = "newValidationValidator", CssClass = "validator", ControlToValidate = txtNewValidation.ClientID, Display = ValidatorDisplay.Dynamic, ClientValidationFunction = "ValidateRegex", ErrorMessage = Helper.Dictionary.GetDictionaryItem( "ValidationStringIsNotValid", "Validation string is not valid") }; valNewValidation.ServerValidate += this.valNewValidation_ServerValidate; // Add controls to control addNewPropertyControls.Controls.Add(lblNewValidation); addNewPropertyControls.Controls.Add(txtNewValidation); addNewPropertyControls.Controls.Add(valNewValidation); addNewPropertyControls.Controls.Add(new LiteralControl() { Text = "<br/>" }); addNewPropertyControls.Controls.Add(lnkNewValidation); ((PreValueRow)this._newPreValue).Controls.Add(txtNewValidation); addNewPropertyControls.Controls.Add(new LiteralControl() { Text = "</li>" }); // PREVALUE SORT ORDER // Instantiate controls var hdnNewSortOrder = new HiddenField() { Value = (this._preValues.Count + 1).ToString() }; addNewPropertyControls.Controls.Add(hdnNewSortOrder); ((PreValueRow)this._newPreValue).Controls.Add(hdnNewSortOrder); addNewPropertyControls.Controls.Add(new LiteralControl() { Text = "</ul>" }); addNewProperty.Controls.Add(addNewPropertyHeader); addNewProperty.Controls.Add(addNewPropertyControls); this._accordionContainer.Controls.Add(addNewProperty); // Write stored entries foreach (var s in this._preValues) { var editProperty = new Panel() { ID = "editProperty_" + s.Id.ToString(), CssClass = "editProperty" }; var editDataType = ddlNewType.Items.FindByValue(s.DataTypeId.ToString()); var editPropertyHeader = new Panel() { CssClass = "propertyHeader" }; var editPropertyTitle = new HtmlGenericControl("h3") { InnerText = string.Format( "{0} ({1}), {2}: {3}", s.Name.StartsWith("#") ? uQuery.GetDictionaryItem( s.Name.Substring( 1, s.Name.Length - 1), s.Name.Substring( 1, s.Name.Length - 1)) : s.Name, s.Alias, uQuery.GetDictionaryItem("Type", "Type"), editDataType != null ? editDataType.Text : "ERROR: This datatype is not supported") }; editPropertyTitle.Attributes["class"] = "propertyTitle"; var lnkDelete = new LinkButton { CssClass = "DeleteProperty ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only", Text = "<span class='ui-button-icon-primary ui-icon ui-icon-close'> </span><span class='ui-button-text'>Delete</span>", OnClientClick = "return confirm('" + uQuery.GetDictionaryItem( "AreYouSureYouWantToDeleteThisColumn", "Are you sure you want to delete this column") + "?');", CommandArgument = s.Id.ToString(), CommandName = "Delete" }; lnkDelete.Command += new CommandEventHandler(this.lnkDelete_Command); var icnEditError = new HtmlGenericControl("span") { InnerText = Helper.Dictionary.GetDictionaryItem("Error", "Error") }; icnEditError.Attributes["class"] = "ErrorProperty"; editPropertyHeader.Controls.Add(editPropertyTitle); editPropertyHeader.Controls.Add(lnkDelete); editPropertyHeader.Controls.Add(icnEditError); var editPropertyControls = new Panel() { CssClass = "propertyControls" }; editPropertyControls.Controls.Add(new LiteralControl() { Text = "<ul>" }); // NAME editPropertyControls.Controls.Add(new LiteralControl() { Text = "<li>" }); // Instantiate controls var txtEditName = new TextBox() { ID = "editName_" + this._preValues.IndexOf(s), CssClass = "editName", Text = s.Name }; var lblEditName = new Label() { AssociatedControlID = txtEditName.ClientID, Text = Helper.Dictionary.GetDictionaryItem("Name", "Name") + "<br/><small class='description'>" + Helper.Dictionary.GetDictionaryItem( "NameDescription", "The column display name") + "</small>", CssClass = "label" }; var valEditName = new RequiredFieldValidator() { ID = "editNameValidator_" + this._preValues.IndexOf(s), CssClass = "validator", ControlToValidate = txtEditName.ClientID, Display = ValidatorDisplay.Dynamic, ErrorMessage = "You must specify a name" }; // Add controls to control editPropertyControls.Controls.Add(lblEditName); editPropertyControls.Controls.Add(txtEditName); editPropertyControls.Controls.Add(valEditName); s.Controls.Add(txtEditName); editPropertyControls.Controls.Add(new LiteralControl() { Text = "</li>" }); // ALIAS editPropertyControls.Controls.Add(new LiteralControl() { Text = "<li>" }); // Instantiate controls var txtEditAlias = new TextBox() { ID = "editAlias_" + this._preValues.IndexOf(s), CssClass = "editAlias", Text = s.Alias }; var lblEditAlias = new Label() { AssociatedControlID = txtEditAlias.ClientID, Text = Helper.Dictionary.GetDictionaryItem("Alias", "Alias") + "<br/><small class='description'>" + Helper.Dictionary.GetDictionaryItem( "AliasDescription", "The column alias") + "</small>", CssClass = "label" }; var valEditAlias = new RequiredFieldValidator() { ID = "editAliasValidator_" + this._preValues.IndexOf(s), CssClass = "validator", ControlToValidate = txtEditAlias.ClientID, Display = ValidatorDisplay.Dynamic, ErrorMessage = "You must specify an alias" }; var valEditAliasExists = new CustomValidator() { ID = "editAliasExistsValidator_" + this._preValues.IndexOf(s), CssClass = "validator exists", ControlToValidate = txtEditAlias.ClientID, Display = ValidatorDisplay.Dynamic, ClientValidationFunction = "ValidateAliasExists", ErrorMessage = "Alias already exists!" }; valEditAliasExists.ServerValidate += valEditAliasExists_ServerValidate; // Add controls to control editPropertyControls.Controls.Add(lblEditAlias); editPropertyControls.Controls.Add(txtEditAlias); editPropertyControls.Controls.Add(valEditAlias); editPropertyControls.Controls.Add(valEditAliasExists); s.Controls.Add(txtEditAlias); editPropertyControls.Controls.Add(new LiteralControl() { Text = "</li>" }); // DATATYPE editPropertyControls.Controls.Add(new LiteralControl() { Text = "<li>" }); // Instantiate controls var ddlEditType = DtgHelpers.GetDataTypeDropDown(); ddlEditType.ID = "editDataType_" + this._preValues.IndexOf(s); var lblEditType = new Label() { AssociatedControlID = ddlEditType.ClientID, Text = Helper.Dictionary.GetDictionaryItem("DataType", "Datatype") + "<br/><small class='description'>" + Helper.Dictionary.GetDictionaryItem( "DatatypeDescription", "The column data editor") + "</small>", CssClass = "label" }; // Add controls to control editPropertyControls.Controls.Add(lblEditType); ddlEditType.SelectedValue = s.DataTypeId.ToString(); editPropertyControls.Controls.Add(ddlEditType); s.Controls.Add(ddlEditType); editPropertyControls.Controls.Add(new LiteralControl() { Text = "</li>" }); // MANDATORY editPropertyControls.Controls.Add(new LiteralControl() { Text = "<li>" }); // Instantiate controls var chkEditMandatory = new CheckBox() { ID = "editMandatory_" + this._preValues.IndexOf(s), CssClass = "editMandatory", Checked = s.Mandatory }; var lblEditMandatory = new Label() { AssociatedControlID = chkEditMandatory.ClientID, Text = Helper.Dictionary.GetDictionaryItem("Mandatory", "Mandatory") + "<br/><small class='description'>" + Helper.Dictionary.GetDictionaryItem( "MandatoryDescription", "Whether this column is mandatory") + "</small>", CssClass = "label" }; // Add controls to control editPropertyControls.Controls.Add(lblEditMandatory); editPropertyControls.Controls.Add(chkEditMandatory); s.Controls.Add(chkEditMandatory); editPropertyControls.Controls.Add(new LiteralControl() { Text = "</li>" }); // VISIBLE editPropertyControls.Controls.Add(new LiteralControl() { Text = "<li>" }); // Instantiate controls var chkEditVisible = new CheckBox() { ID = "editVisible_" + this._preValues.IndexOf(s), CssClass = "editVisible", Checked = s.Visible }; var lblEditVisible = new Label() { AssociatedControlID = chkEditVisible.ClientID, Text = Helper.Dictionary.GetDictionaryItem("Visible", "Visible") + "<br/><small class='description'>" + Helper.Dictionary.GetDictionaryItem( "VisibleDescription", "Whether this column is visible in the grid. <br/>(it can still be edited)") + "</small>", CssClass = "label" }; // Add controls to control editPropertyControls.Controls.Add(lblEditVisible); editPropertyControls.Controls.Add(chkEditVisible); s.Controls.Add(chkEditVisible); editPropertyControls.Controls.Add(new LiteralControl() { Text = "</li>" }); // VALIDATION editPropertyControls.Controls.Add(new LiteralControl() { Text = "<li>" }); // Instantiate control var txtEditValidation = new TextBox() { ID = "editValidation_" + this._preValues.IndexOf(s), TextMode = TextBoxMode.MultiLine, Rows = 2, Columns = 20, CssClass = "editValidation", Text = s.ValidationExpression }; var lblEditValidation = new Label() { AssociatedControlID = txtEditValidation.ClientID, Text = Helper.Dictionary.GetDictionaryItem("Validation", "Validation") + "<br/><small class='description'>" + Helper.Dictionary.GetDictionaryItem( "ValidationDescription", "The regular expression used for validation. Leave empty to disable") + "</small>", CssClass = "label" }; var lnkEditValidation = new HyperLink { CssClass = "validationLink", NavigateUrl = "#", Text = Helper.Dictionary.GetDictionaryItem( "SearchForARegularExpression", "Search for a regular expression") }; var valEditValidation = new CustomValidator() { ID = "editValidationValidator_" + this._preValues.IndexOf(s), CssClass = "validator", ControlToValidate = txtEditValidation.ClientID, Display = ValidatorDisplay.Dynamic, ClientValidationFunction = "ValidateRegex", ErrorMessage = Helper.Dictionary.GetDictionaryItem( "ValidationStringIsNotValid", "Validation string is not valid") }; valEditValidation.ServerValidate += valEditValidation_ServerValidate; // Add controls to control editPropertyControls.Controls.Add(lblEditValidation); editPropertyControls.Controls.Add(txtEditValidation); editPropertyControls.Controls.Add(valEditValidation); editPropertyControls.Controls.Add(new LiteralControl() { Text = "<br/>" }); editPropertyControls.Controls.Add(lnkEditValidation); s.Controls.Add(txtEditValidation); editPropertyControls.Controls.Add(new LiteralControl() { Text = "</li>" }); // SORT ORDER // Instantiate controls var hdnEditSortOrderWrapper = new Panel() { CssClass = "sortOrder" }; var hdnEditSortOrder = new HiddenField() { Value = s.SortOrder.ToString() }; hdnEditSortOrderWrapper.Controls.Add(hdnEditSortOrder); editPropertyControls.Controls.Add(hdnEditSortOrderWrapper); s.Controls.Add(hdnEditSortOrder); editPropertyControls.Controls.Add(new LiteralControl() { Text = "</ul>" }); editProperty.Controls.Add(editPropertyHeader); editProperty.Controls.Add(editPropertyControls); this._accordionContainer.Controls.Add(editProperty); } this.Controls.Add(this._showLabel); this.Controls.Add(this._showHeader); this.Controls.Add(this._showFooter); this.Controls.Add(this._readOnly); this.Controls.Add(this._tableHeight); this.Controls.Add(this._tableHeightValidator); this.Controls.Add(this._accordionContainer); }