public static IBindingsBuilder <T> Value <T, F>( this IBindingsBuilder <T> bindingsBuilder, Expression <Func <T, F> > expression) { if (expression == null) { throw (new ArgumentNullException("expression")); } string clientFormat; string prefix; string postfix; string nullString; int clientType = CoreHTMLHelpers. GetClientInfo(expression, out clientFormat, out prefix, out postfix, out nullString); bindingsBuilder.Add( bindingsBuilder.standardString <T, F>("value", expression, null, null) ); bindingsBuilder.Add("valueType: " + clientType); if (clientFormat.Length > 0) { bindingsBuilder.Add("formatString: "" + clientFormat + """); } return(bindingsBuilder); }
public static IBindingsBuilder <T> Text <T, F>( this IBindingsBuilder <T> bindingsBuilder, Expression <Func <T, F> > expression, string format = null, params LambdaExpression[] otherExpressions) where T : class { if (expression == null) { throw (new ArgumentNullException("expression")); } if (format == null) { string clientFormat; string prefix; string postfix; string nullString; int clientType = CoreHTMLHelpers. GetClientInfo(expression, out clientFormat, out prefix, out postfix, out nullString); bindingsBuilder.Add( string.Format(textScript, bindingsBuilder.GetFullBindingName(expression), clientFormat, clientType, prefix, postfix, nullString) ); return(bindingsBuilder); } bindingsBuilder.Add( bindingsBuilder.standardString <T, F>("text", expression, format, otherExpressions) ); return(bindingsBuilder); }
public static IBindingsBuilder <T> SelectedOptions <T, F>( this IBindingsBuilder <T> bindingsBuilder, Expression <Func <T, F> > expression, string format = null, params LambdaExpression[] otherExpressions) { if (expression == null) { throw (new ArgumentNullException("expression")); } bindingsBuilder.Add( bindingsBuilder.standardString <T, F>("selectedOptions", expression, format, otherExpressions) ); bindingsBuilder.Add("valueType: " + CoreHTMLHelpers.GetClientType(typeof(F))); return(bindingsBuilder); }
public static IBindingsBuilder <T> UniqueName <T>(this IBindingsBuilder <T> bindingsBuilder) where T : class { bindingsBuilder.Add( "uniqueName: true" ); return(bindingsBuilder); }
public static IBindingsBuilder <T> Options <T, F>( this IBindingsBuilder <T> bindingsBuilder, Expression <Func <T, F> > expression, string caption = null) { if (expression == null) { throw (new ArgumentNullException("expression")); } bindingsBuilder.Add( bindingsBuilder.standardString <T, F>("options", expression, null, null) ); int clientType = CoreHTMLHelpers.GetClientType(typeof(F)); bindingsBuilder.Add("valueType: " + clientType); if (!string.IsNullOrWhiteSpace(caption)) { bindingsBuilder.Add("optionsCaption: "" + caption + """); } return(bindingsBuilder); }
public static IBindingsBuilder <T> Submit <T, F>( this IBindingsBuilder <T> bindingsBuilder, Expression <Func <T, F> > expression, string format = null, params LambdaExpression[] otherExpressions) where T : class { if (expression == null) { throw (new ArgumentNullException("expression")); } bindingsBuilder.Add( bindingsBuilder.standardString <T, F>("submit", expression, format, otherExpressions) ); return(bindingsBuilder); }
public static IBindingsBuilder <T> Template <T, F>( this IBindingsBuilder <T> bindingsBuilder, string templateName, Expression <Func <T, F> > expression, string afterAdd = null, string beforeRemove = null, string afterRender = null, object templateOptions = null, string prefix = null, bool applyClientValidation = true, bool fastNoJavaScript = false, string afterAllRender = null, string templateEngine = null) where T : class { if (expression == null) { throw (new ArgumentNullException("expression")); } if (string.IsNullOrWhiteSpace(templateName)) { throw (new ArgumentNullException("templateName")); } string format = null; string actualPrefix = BasicHtmlHelper.AddField( bindingsBuilder.ModelPrefix, ExpressionHelper.GetExpressionText(expression)); if (prefix == null) { prefix = actualPrefix; } StringBuilder sb = new StringBuilder(); if (templateName[0] != '@') { sb.Append("template: { name: ""); sb.Append(templateName); if (typeof(IEnumerable).IsAssignableFrom(typeof(F))) { sb.Append("", foreach: "); } else { sb.Append("", data: "); } } else { templateName = templateName.Substring(1); sb.Append("template: { name: "); sb.Append(templateName); if (typeof(IEnumerable).IsAssignableFrom(typeof(F))) { sb.Append(", foreach: "); } else { sb.Append(", data: "); } } sb.Append(bindingsBuilder.GetFullBindingName(expression)); if (afterRender != null) { sb.Append(", afterRender: "); sb.Append(afterRender); } if (afterAdd != null) { sb.Append(", afterAdd: "); sb.Append(afterAdd); } if (beforeRemove != null) { sb.Append(", beforeRemove: "); sb.Append(beforeRemove); } if (afterAllRender != null) { sb.Append(", afterAllRender: "); sb.Append(afterAllRender); } if (templateEngine != null) { sb.Append(", templateEngine: ko."); sb.Append(templateEngine); sb.Append(".instance"); } var additionalOptions = new { ModelPrefix = """ + prefix + """, ModelId = """ + BasicHtmlHelper.IdFromName(prefix) + """, ItemPrefix = """", templateSymbol = """ + ClientTemplateHelper.templateSymbol + "0"" }; sb.Append(", templateOptions: {"); if (templateOptions != null) { sb.Append(BasicHtmlHelper.TranslateAnonymous(templateOptions)); sb.Append(", "); } sb.Append(BasicHtmlHelper.TranslateAnonymous(additionalOptions)); sb.Append(" }"); sb.Append(", processingOptions: {"); if (bindingsBuilder.ValidationType == "UnobtrusiveClient") { sb.Append("unobtrusiveClient: true"); if (bindingsBuilder.GetHelper().ViewData["_TemplateLevel_"] == null) { bindingsBuilder.AddServerErrors(actualPrefix); } } else { sb.Append("unobtrusiveClient: false"); } sb.Append(fastNoJavaScript ? ", fastNoJavaScript: true" : ", fastNoJavaScript: false"); sb.Append(applyClientValidation ? ", applyClientValidation: true" : ", applyClientValidation: false"); sb.Append(" }"); sb.Append(" }"); format = sb.ToString(); bindingsBuilder.Add( format ); return(bindingsBuilder); }
public static IBindingsBuilder <T> Options <T, F, IF, IFT>( this IBindingsBuilder <T> bindingsBuilder, Expression <Func <T, IEnumerable <F> > > expression, Expression <Func <F, IF> > valueField, Expression <Func <F, IFT> > textField, string caption = null, string valueFieldFormat = null, string textFieldFormat = null) { if (expression == null) { throw (new ArgumentNullException("expression")); } bindingsBuilder.Add( bindingsBuilder.standardString <T, IEnumerable <F> >("options", expression, null, null) ); if (valueFieldFormat == null) { bindingsBuilder.Add("optionsValue: "" + ExpressionHelper.GetExpressionText(valueField) + """); } else { bindingsBuilder.Add( baseStandardString <F, IF>("optionsValue", valueField, valueFieldFormat, null) ); } string clientFormat; string prefix; string postfix; string nullString; int clientType = CoreHTMLHelpers. GetClientInfo(valueField, out clientFormat, out prefix, out postfix, out nullString); bindingsBuilder.Add("valueType: " + clientType); if (clientFormat.Length > 0) { bindingsBuilder.Add("formatString: "" + clientFormat + """); } if (textFieldFormat == null) { bindingsBuilder.Add("optionsText: "" + ExpressionHelper.GetExpressionText(textField) + """); } else { bindingsBuilder.Add( baseStandardString <F, IFT>("optionsText", textField, textFieldFormat, null) ); } clientType = CoreHTMLHelpers. GetClientInfo(textField, out clientFormat, out prefix, out postfix, out nullString); bindingsBuilder.Add("textType: " + clientType); if (clientFormat.Length > 0) { bindingsBuilder.Add("textFormatString: "" + clientFormat + """); } bindingsBuilder.Add("textPrefix: "" + prefix + """); bindingsBuilder.Add("textPostfix: "" + postfix + """); bindingsBuilder.Add("textNullString: "" + nullString + """); if (!string.IsNullOrWhiteSpace(caption)) { bindingsBuilder.Add("optionsCaption: "" + caption + """); } return(bindingsBuilder); }