public void Initialize(BXCustomField currentField,BXCustomProperty currentValue) { field = currentField; value = currentValue; if (field == null) return; string fieldName = currentField.EditFormLabel; BXParamsBag<object> settings = new BXParamsBag<object>(currentField.Settings); ValueRequired.Enabled = currentField.Mandatory; if (ValueRequired.Enabled) ValueRequired.ErrorMessage = GetMessageFormat("Error.Required", fieldName); ValueTextBox.Columns = settings.ContainsKey("TextBoxSize") ? settings.GetInt("TextBoxSize") : 20; ValueMin.Enabled = ValueMax.Enabled = false; ValueType.ErrorMessage = ValueMax.ErrorMessage = ValueMin.ErrorMessage = GetMessageFormat("Error.DefaultRangeInvalid", fieldName); if (settings.ContainsKey("MinValue")) { double min = Convert.ToDouble(settings["MinValue"]);// is int ? (double)((int)settings["MinValue"]) : (double)settings["MinValue"]; ValueMin.ValueToCompare = min.ToString(); ValueMin.Enabled = true; } if (settings.ContainsKey("MaxValue")) { double max = Convert.ToDouble(settings["MaxValue"]); //is int ? (double)((int)settings["MaxValue"]) : (double)settings["MaxValue"]; ValueMax.ValueToCompare = max.ToString(); ValueMax.Enabled = true; } int precision = settings.ContainsKey("Precision") ? settings.GetInt("Precision") : 4; if (value != null) ValueTextBox.Text = string.Format("{0:F" + precision + "}", value.Value); else ValueTextBox.Text = settings.ContainsKey("DefaultValue") ? settings["DefaultValue"].ToString() : String.Empty; }
public override void Init(BXCustomField currentField) { field = currentField; if (field == null) return; BXParamsBag<object> settings = new BXParamsBag<object>(currentField.Settings); defaultValue = settings.GetInt("default", 1) != 1; view = settings.ContainsKey("view") ? (BooleanViewType)settings["view"] : BooleanViewType.Default; }
public void Initialize(BXCustomField currentField, BXCustomProperty currentValue) { field = currentField; value = currentValue; if (field == null) return; settings = new BXParamsBag<object>(field.Settings); viewMode = settings.ContainsKey("ViewMode") && (string)settings["ViewMode"] == "list" ? ViewMode.List : ViewMode.Flag; valDDList.Enabled = false; valList.Enabled = false; valFlag.Enabled = false; valCheckbox.Enabled = false; ListControl list; int listCount = Math.Max(settings.GetInt("ListSize", 5), 1); if (viewMode == ViewMode.List) { if (field.Multiple) { View.ActiveViewIndex = 0; list = List; validator = valList; List.Rows = Math.Min(listCount, Enums.Count + (!field.Multiple && !field.Mandatory ? 1 : 0)); } else { View.ActiveViewIndex = 3; list = DDList; validator = valDDList; } } else { if (field.Multiple) { View.ActiveViewIndex = 2; list = ChBox; validator = valCheckbox; } else { View.ActiveViewIndex = 1; list = Flag; validator = valFlag; } } ListItem none = null; if (!field.Multiple && !field.Mandatory) { none = new ListItem(GetMessage("Option.NotSelected"), ""); none.Selected = true; list.Items.Add(none); } validator.Enabled = field.Mandatory; validator.ValidationGroup = ValidationGroup; foreach (BXCustomFieldEnum e in Enums) list.Items.Add(new ListItem(e.Value, e.Id.ToString())); if (value != null) { bool stop = false; foreach (ListItem item in list.Items) { foreach (int val in value.Values) if (item.Value == val.ToString()) { if (!field.Multiple) { if (none != null) none.Selected = false; stop = true; } item.Selected = true; break; } if (stop) break; } } else //BIND DEFAULT { bool stop = false; foreach (ListItem item in list.Items) { foreach (BXCustomFieldEnum val in Enums) if (item.Value == val.Id.ToString() && val.Default) { if (!field.Multiple) { if (none != null) none.Selected = false; stop = true; } item.Selected = true; break; } if (stop) break; } } }
public void Initialize(BXCustomField currentField, BXCustomProperty currentValue) { field = currentField; value = currentValue; if (currentField == null) return; string fieldName = currentField.EditFormLabel; string errorMessage = currentField.ErrorMessage; if (string.IsNullOrEmpty(errorMessage)) errorMessage = GetMessageFormat("Error.RegexInvalid", fieldName); BXParamsBag<object> settings = new BXParamsBag<object>(currentField.Settings); ValueRequired.Enabled = currentField.Mandatory; if (ValueRequired.Enabled) ValueRequired.ErrorMessage = GetMessageFormat("Error.Required", fieldName); int i = settings.ContainsKey("RowsCount") ? settings.GetInt("RowsCount") : 1; ValueTextBox.TextMode = (i > 1) ? TextBoxMode.MultiLine : TextBoxMode.SingleLine; if (ValueTextBox.TextMode == TextBoxMode.MultiLine) ValueTextBox.Rows = i; ValueTextBox.Columns = settings.ContainsKey("TextBoxSize") ? settings.GetInt("TextBoxSize") : 20; minLength = null; if (settings.ContainsKey("MinLength")) minLength = settings.GetInt("MinLength"); maxLength = null; if (settings.ContainsKey("MaxLength")) maxLength = settings.GetInt("MaxLength"); ValueMinLength.Enabled = minLength.HasValue && minLength > 0; ValueMaxLength.Enabled = maxLength.HasValue && maxLength > 0; minValidationScript = null; maxValidationScript = null; if (ValueMinLength.Enabled) { minValidationScript = string.Format("if(!args.Value||args.Value.length<{0})return;", minLength.Value); ValueMinLength.ErrorMessage = GetMessageFormat("Error.MinLength", fieldName, minLength.Value); } if (ValueMaxLength.Enabled) { maxValidationScript = string.Format("if(args.Value&&args.Value.length>{0})return;", maxLength.Value); ValueMaxLength.ErrorMessage = GetMessageFormat("Error.MaxLength", fieldName, maxLength.Value); } ValueRegex.Enabled = settings.ContainsKey("ValidationRegex") && !String.IsNullOrEmpty((string)settings["ValidationRegex"]); if (ValueRegex.Enabled) { ValueRegex.ValidationExpression = (string)settings["ValidationRegex"]; ValueRegex.ErrorMessage = errorMessage; } if (value != null && value.Value is string) ValueTextBox.Text = value.Value.ToString(); else ValueTextBox.Text = settings.ContainsKey("DefaultValue") ? (string)settings["DefaultValue"] : String.Empty; }
public EnumerationItem(BXParamsBag<object> data) { Id = data.GetInt("Id"); Title = data.GetString("Title"); XmlId = data.GetString("XmlId"); IsDefault = data.GetBool("Default"); IsNew = data.GetBool("New"); Sort = data.GetInt("Sort"); Delete = data.GetBool("Delete"); }
public override bool ProcessCommand(string commandName, BXParamsBag<object> commandParameters, List<string> commandErrors) { string url; if ( commandName.Equals("delete",StringComparison.OrdinalIgnoreCase)){ int delAlbumId = commandParameters.GetInt("AlbumId", AlbumId); int parentAlbumId = 0; try { parentAlbumId = BXIBlockSection.GetById(delAlbumId).SectionId; BXIBlockSection.Delete(delAlbumId); } catch (Exception ex) { errorMessage = GetMessage("Error.FailedToDeleteAlbum"); } if (EnableSef) { if (parentAlbumId > 0) { Results["AlbumId"] = parentAlbumId; url = MakeLink(Parameters.Get<string>("SefFolder"), Parameters.Get<string>("Sef_Album"), Results); } else { url = MakeLink(Parameters.Get<string>("SefFolder"), string.Empty, Results); } } else { if (parentAlbumId > 0) { url = string.Format("{0}?{1}={2}", Request.Path, Parameters.Get<string>("ParamAlbum", "Album"), parentAlbumId); } else { url = Request.Path; } } if (errorMessage == String.Empty) { if (Parameters.Get("EnableAjax", false) && !IsComponentDesignMode) { string script = string.Format("setTimeout(\"PageTransfer('{0}');\",1);", url); ScriptManager.RegisterStartupScript(Page, typeof(Page), "AJAX_BUTTON_CLICK", script, true); } else Response.Redirect(url); return true; } } else if (commandName.Equals("deletephotos", StringComparison.OrdinalIgnoreCase)) { var photos = commandParameters.Get<List<int>>("photoIds", new List<int>()); foreach (var id in photos) { BXIBlockElement photo = null; try { photo = BXIBlockElement.GetById(id); if (photo != null) photo.Delete(); } catch (Exception ex2) { commandErrors.Add(GetMessage("UnableToDeletePhoto") + (photo != null ? " " + photo.Name : "")); } } if (BXModuleManager.IsModuleInstalled("forum") && EnableComments)// have to delete comments for all photos { var c = new IncludeComponent("bitrix:forum.comment.block", "blog_comments"); c.Attributes["ForumId"] = Component.Parameters.GetString("CommentForumId", "0"); c.Attributes["IdentityPropertyName"] = Component.Parameters.GetString("CommentStoragePropertyName"); c.Attributes["IdentityPropertyValue"] = photos[0].ToString();//required by design c.Attributes["PostOperation"] = "DeleteCommentsForEntityList"; c.Attributes["EntityList"] = BXStringUtility.ListToCsv(photos.ConvertAll(x => x.ToString())); CommentsDeletePlaceHolder.Controls.Add(c); } if (EnableSef) { if (AlbumId > 0) { Results["AlbumId"] = AlbumId; url = MakeLink(Parameters.Get<string>("SefFolder"), Parameters.Get<string>("Sef_Album"), Results); } else { url = MakeLink(Parameters.Get<string>("SefFolder"), string.Empty, Results); } } else { NameValueCollection pars = HttpUtility.ParseQueryString(Request.Url.Query); pars.Remove("target"); pars.Remove("ValidationToken"); pars.Remove("del"); url = string.Format("{0}?{1}", Request.Path, pars.ToString()); } Response.Redirect(url); } return false; }
public override void Init(BXCustomField currentField) { field = currentField; if (field == null) return; BXParamsBag<object> settings = new BXParamsBag<object>(field.Settings); listValues = BXCustomFieldEnum.GetList(field.Id, field.FieldType, BXTextEncoder.EmptyTextEncoder); required = field.Mandatory; viewMode = settings.ContainsKey("ViewMode") ? ViewMode.List : ViewMode.Flags; listSize = settings.GetInt("ListSize", 5); }