public override void Execute() { #line 6 "..\..\Views\Shared\DisplayTemplates\SelectBox.cshtml" string id = ViewData.TemplateInfo.GetFullHtmlFieldId(""); string name = ViewData.TemplateInfo.HtmlFieldPrefix; ModelMetadata metaData = ViewData.ModelMetadata; if (!metaData.AdditionalValues.ContainsKey(KescoSelectAttribute.AdditionalValuesKey_SelectBox)) { throw new Exception(String.Format( "Неверное использование шаблона. Атрибут KescoSelect не найден для свойства {0}", metaData.PropertyName )); } KescoSelectAttribute descriptor = metaData.AdditionalValues[KescoSelectAttribute.AdditionalValuesKey_SelectBox] as KescoSelectAttribute; if (descriptor == null) { throw new Exception(String.Format( "Неверное использование шаблона. Атрибут-дескриптор для свойства '{0}' имеет неверный тип {1}.", metaData.PropertyName, metaData.AdditionalValues[KescoSelectAttribute.AdditionalValuesKey_SelectBox].GetType() )); } if (descriptor.SelectControllerType == null) { throw new Exception(String.Format( "Неверное использование шаблона. Не указан тип контроллера для свойства '{0}'", metaData.PropertyName, metaData.AdditionalValues[KescoSelectAttribute.AdditionalValuesKey_SelectBox].GetType() )); } var controller = descriptor.SelectControllerType.IsAssignableFrom(typeof(ControllerEx)); if (controller == null) { throw new Exception(String.Format( "Неверное использование шаблона. Для свойства '{0}' в качестве контроллера указан тип {1}, который не является контроллером", metaData.PropertyName, descriptor.SelectControllerType )); } // Получим начальные значения string value = ""; string label = Model.HasValue ? String.Empty : metaData.NullDisplayText; bool actual = false; if (Model.HasValue && descriptor.EntityAccessorType != null) { value = Model.ToString(); label = String.Format("#{0}", value); Kesco.DataAccess.IAccessor accessor = BLToolkit.Reflection.TypeAccessor.CreateInstanceEx( descriptor.EntityAccessorType ) as Kesco.DataAccess.IAccessor; if (accessor != null) { object entry = accessor.GetInstance(value); if (entry != null) { metaData.AdditionalValues.Add( KescoSelectAttribute.AdditionalValuesKey_SelectBox + "_EntityInstance", entry ); if (accessor is Kesco.Web.Mvc.UI.Controls.DataAccess.IKescoSelectAccessor) { label = ((IKescoSelectAccessor)accessor).GetInstanceDisplayName(entry); actual = true; } else if (entry is Kesco.ObjectModel.IFriendlyNamed) { label = ((Kesco.ObjectModel.IFriendlyNamed)entry).GetInstanceFriendlyName(); actual = true; } } } } var linkBuilder = new TagBuilder("A"); // Объединяем HTML атрибуты для элемента управления var htmlAttributes = Html.MergeHtmlAttributes((object)ViewBag.HtmlAttributes); htmlAttributes["id"] = "{0}__Link".FormatWith(id); htmlAttributes["href"] = "javascript: void(0)"; htmlAttributes["data-actual"] = actual?"true":"false"; htmlAttributes["alt"] = label; htmlAttributes["title"] = label; // Укажим data-bind для библиотеки knockout htmlAttributes.PrependInValue( "data-bind", ",", @"dynamicLink: {{ value: {0}, source: Env.URI_{1}_GetItem }} " .FormatWith(name, descriptor.SelectControllerType.Name) ); linkBuilder.MergeAttributes(htmlAttributes, true); linkBuilder.AddCssClass("selectControl"); linkBuilder.SetInnerText(label); #line default #line hidden #line 110 "..\..\Views\Shared\DisplayTemplates\SelectBox.cshtml" Write(Html.Raw(linkBuilder)); #line default #line hidden WriteLiteral("\r\n"); #line 111 "..\..\Views\Shared\DisplayTemplates\SelectBox.cshtml" Write(Html.CommonScriptCode("selectControlCommon_{0}".FormatWith(descriptor.SelectControllerType.Name), item => new System.Web.WebPages.HelperResult(__razor_template_writer => { #line default #line hidden WriteLiteralTo(@__razor_template_writer, "<script>\r\n\t\t!(function() { var env = window.Env || {}; window.Env = env; env.URI_" + ""); #line 113 "..\..\Views\Shared\DisplayTemplates\SelectBox.cshtml" WriteTo(@__razor_template_writer, descriptor.SelectControllerType.Name); #line default #line hidden WriteLiteralTo(@__razor_template_writer, "_GetItem = \'"); #line 113 "..\..\Views\Shared\DisplayTemplates\SelectBox.cshtml" WriteTo(@__razor_template_writer, Url.AbsoluteAction("GetItem", descriptor.SelectControllerType.Name.Replace("Controller", ""))); #line default #line hidden WriteLiteralTo(@__razor_template_writer, "\'; })();\r\n</script>"); #line 114 "..\..\Views\Shared\DisplayTemplates\SelectBox.cshtml" }))); #line default #line hidden WriteLiteral("\r\n"); }
public override void Execute() { #line 5 "..\..\Views\Shared\DisplayTemplates\IncorporationFormSelect.cshtml" string id = ViewData.TemplateInfo.GetFullHtmlFieldId(""); string name = ViewData.TemplateInfo.HtmlFieldPrefix; ModelMetadata metaData = ViewData.ModelMetadata; if (!metaData.AdditionalValues.ContainsKey(IncorporationFormSelectAttribute.AdditionalValuesKey)) { throw new Exception(String.Format( "Неверное использование шаблона IncorporationFormSelectAttribute. Атрибут-дескриптор {1} не найден для свойства {0}", metaData.PropertyName, typeof(IncorporationFormSelectAttribute) )); } var descriptor = metaData.AdditionalValues[IncorporationFormSelectAttribute.AdditionalValuesKey] as IncorporationFormSelectAttribute; if (descriptor == null) { throw new Exception(String.Format( "Неверное использование шаблона EmployeeSelect. Атрибут-дескриптор для свойства '{0}' имеет неверный тип {1}.", metaData.PropertyName, metaData.AdditionalValues[IncorporationFormSelectAttribute.AdditionalValuesKey].GetType() )); } // Получим начальные значения string value = ""; string label = Model.HasValue ? "" : metaData.NullDisplayText; if (Model.HasValue && descriptor.EntityAccessorType != null) { value = Model.ToString(); label = String.Format("#{0}", value); Kesco.DataAccess.IAccessor accessor = BLToolkit.Reflection.TypeAccessor.CreateInstanceEx( descriptor.EntityAccessorType ) as Kesco.DataAccess.IAccessor; if (accessor != null) { object entry = accessor.GetInstance(value); if (entry != null) { if (accessor is Kesco.Web.Mvc.UI.Controls.DataAccess.IKescoSelectAccessor) { label = ((IKescoSelectAccessor)accessor).GetInstanceDisplayName(entry); } else if (entry is Kesco.ObjectModel.IFriendlyNamed) { label = ((Kesco.ObjectModel.IFriendlyNamed)entry).GetInstanceFriendlyName(); } } } } #line default #line hidden WriteLiteral("\r\n<span"); WriteAttribute("id", Tuple.Create(" id=\"", 2011), Tuple.Create("\"", 2027) #line 51 "..\..\Views\Shared\DisplayTemplates\IncorporationFormSelect.cshtml" , Tuple.Create(Tuple.Create("", 2016), Tuple.Create <System.Object, System.Int32>(id #line default #line hidden , 2016), false) , Tuple.Create(Tuple.Create("", 2021), Tuple.Create("__Link", 2021), true) ); WriteLiteral(" class=\"IncorporationFormControl\""); WriteLiteral(" href=\"javascript: void(0)\""); WriteAttribute("title", Tuple.Create(" title=\"", 2088), Tuple.Create("\"", 2104) #line 51 "..\..\Views\Shared\DisplayTemplates\IncorporationFormSelect.cshtml" , Tuple.Create(Tuple.Create("", 2096), Tuple.Create <System.Object, System.Int32>(label #line default #line hidden , 2096), false) ); WriteAttribute("alt", Tuple.Create(" alt=\"", 2105), Tuple.Create("\"", 2119) #line 51 "..\..\Views\Shared\DisplayTemplates\IncorporationFormSelect.cshtml" , Tuple.Create(Tuple.Create("", 2111), Tuple.Create <System.Object, System.Int32>(label #line default #line hidden , 2111), false) ); WriteLiteral(" \r\n\tdata-actual=\"true\""); WriteLiteral("\r\n\tdata-bind=\"\r\n\t\tdynamicLink: { \r\n\t\t\tvalue: "); #line 55 "..\..\Views\Shared\DisplayTemplates\IncorporationFormSelect.cshtml" Write(name); #line default #line hidden WriteLiteral(", \r\n\t\t\tsource: \'"); #line 56 "..\..\Views\Shared\DisplayTemplates\IncorporationFormSelect.cshtml" Write(Url.Action("GetItem", "IncorporationFormSelect")); #line default #line hidden WriteLiteral("\'\r\n\t\t}\r\n\t\""); WriteLiteral(">"); #line 58 "..\..\Views\Shared\DisplayTemplates\IncorporationFormSelect.cshtml" Write(label); #line default #line hidden WriteLiteral("</span>\r\n"); }