private static TagBuilder CreatLookupButton(Lookup.Tree lookInfo) { TagBuilder button = new TagBuilder("span"); button.MergeAttribute("id", string.Format("btnCr_{0}", Id)); button.AddCssClass(string.Format("{0} {1}", StyleKind.RighSpace, StyleKind.Button)); TagBuilder icon = new TagBuilder("span"); icon.AddCssClass(StyleKind.Icons.LookUP); button.InnerHtml = icon.ToString() + ShowLookupScript(lookInfo); return(button); }
private static string ShowLookupScript(Lookup.Tree info) { var script = @"<script> $(document).ready(function () { " + "$('#" + string.Format("btnCr_{0}", Id) + "').click(function () { var temp =$(this); if( temp.attr('disabled')!== 'disabled') " + string.Format("Lookup.loadTree('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}',{8},{9}", info.Title, info.ViewModel, info.ViewInfoKey, info.LookupName, info.TreeID, info.PropertyNameForDisplay, info.PropertyNameForBinding, info.UseMultiSelect, info.Width, info.Height ) + @" );" + "else return false; });} );</script>"; return(script); }
public static MvcHtmlString LookUpCr <TModel>(this HtmlHelper helper, string id, string name, string title, TreeInfo treeInfo, string propertyNameForBinding, bool isMultiSelect, object htmlAttributes, bool readOnly, Dictionary <string, object> lookupHtmlAttributes, params ValidationBase[] validationCr) where TModel : IViewModel, new() { Id = id; TagBuilder container = new TagBuilder("span"); container.AddCssClass("rp-lookup"); if (htmlAttributes != null) { var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); container.MergeAttributes(attributes); } TagBuilder containerState = new TagBuilder("span"); //-----MultiSelect Kendo.Mvc.UI.Fluent.MultiSelectBuilder multiSelect = helper.MultiSelectCr(propertyNameForBinding, treeInfo.DataTextField, treeInfo.DataSource.ModelCr.ModelIdName, Kendo.Mvc.UI.FilterType.Contains); lookupHtmlAttributes = lookupHtmlAttributes ?? new Dictionary <string, object>(); Dictionary <string, string> _htmlAttributes = null; if (validationCr != null && validationCr.Count() > 0) { _htmlAttributes = CreateValidationForlookup(lookupHtmlAttributes, validationCr); } else { _htmlAttributes = lookupHtmlAttributes.ToDictionary(t => t.Key, t => (string)t.Value); } if (readOnly) { _htmlAttributes.Add("readOnly", "true"); } if (!string.IsNullOrEmpty(Id)) { _htmlAttributes.Add("id", Id); } if (!string.IsNullOrEmpty(name)) { _htmlAttributes.Add("name", name); } multiSelect.HtmlAttributes(_htmlAttributes.ToDictionary(t => t.Key, t => (object)t.Value)); var multiSelectHtml = multiSelect.ToHtmlString(); containerState.AddCssClass(multiSelectHtml.Contains("data-val-required") ? StyleKind.RequiredInput : StyleKind.OptionalInput); //string treeID = string.Format("lookupTree_{0}", Id); //treeInfo.Name = treeID; //var treeInfoHashKey = treeInfo.GetHashCode(); //AllTreeLookups.TryAdd(treeInfoHashKey, treeInfo); string treeID = string.Format("lookupTree_{0}", Id); ///we must new from static instance to set info itself var info = treeInfo.DeepCopy <TreeInfo>(); info.Name = treeID; var treeInfoKey = string.Format("{0}_{1}", treeInfo.GetHashCode(), treeID); AllTreeLookups.TryAdd(treeInfoKey, info); var lookupInfo = new Lookup.Tree { Title = title, LookupName = Id, TreeID = treeID, // ViewModel = typeof(TModel).FullName, ViewModel = typeof(TModel).AssemblyQualifiedName, ViewInfoKey = treeInfoKey, UseMultiSelect = true, PropertyNameForDisplay = treeInfo.DataTextField, PropertyNameForValue = treeInfo.DataSource.ModelCr.ModelIdName, PropertyNameForBinding = propertyNameForBinding }; //-----Create lookup---- containerState.InnerHtml = multiSelectHtml + CreatLookupButton(lookupInfo); container.InnerHtml = containerState.ToString(); container.InnerHtml = containerState.ToString(); return(MvcHtmlString.Create(container.ToString())); }
public static MvcHtmlString LookUpCr <TModel>(this HtmlHelper helper, string id, string name, string title, TreeInfo treeInfo, string propertyNameForBinding , object htmlAttributes, bool readOnly, Dictionary <string, object> lookupHtmlAttributes, params ValidationBase[] validationCr) where TModel : IViewModel, new() { Id = id; TagBuilder container = new TagBuilder("span"); if (htmlAttributes != null) { var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); container.MergeAttributes(attributes); } TagBuilder containerState = new TagBuilder("span"); //-----textbox MvcHtmlString textbox; lookupHtmlAttributes = lookupHtmlAttributes ?? new Dictionary <string, object>(); //---value TagBuilder hiddenValue = new TagBuilder("input"); hiddenValue.MergeAttribute("type", "hidden"); hiddenValue.MergeAttribute("id", propertyNameForBinding); if (!string.IsNullOrEmpty(name)) { hiddenValue.MergeAttribute("name", name); } hiddenValue.MergeAttribute("data-bind", string.Format("value:{0}", propertyNameForBinding)); if (validationCr != null && validationCr.Count() > 0) { hiddenValue.MergeAttributes(CreateValidationForlookup(lookupHtmlAttributes, validationCr)); } textbox = helper.TextBoxCr(Id, readOnly, lookupHtmlAttributes); //string treeID = string.Format("lookupTree_{0}", Id); //treeInfo.Name = treeID; //var treeInfoHashKey = treeInfo.GetHashCode(); //AllTreeLookups.TryAdd(treeInfoHashKey, treeInfo); string treeID = string.Format("lookupTree_{0}", Id); ///we must new from static instance to set info itself var info = treeInfo.DeepCopy <TreeInfo>(); info.Name = treeID; var treeInfoKey = string.Format("{0}_{1}", treeInfo.GetHashCode(), treeID); AllTreeLookups.TryAdd(treeInfoKey, info); var lookupInfo = new Lookup.Tree { Title = title, LookupName = Id, TreeID = treeID, ViewModel = typeof(TModel).AssemblyQualifiedName, ViewInfoKey = treeInfoKey, UseMultiSelect = false, PropertyNameForDisplay = treeInfo.DataTextField, PropertyNameForBinding = propertyNameForBinding }; //-----create lookup---- containerState.InnerHtml = textbox.ToHtmlString() + hiddenValue + CreatLookupButton(lookupInfo); container.InnerHtml = containerState.ToString(); return(MvcHtmlString.Create(container.ToString())); }