public override void CreateActionJavaScript(string methodName, StringCollection code, StringCollection parameters, string returnReceiver) { if (string.CompareOrdinal(methodName, "IsFileTypeValid") == 0) { if (!string.IsNullOrEmpty(returnReceiver)) { code.Add(string.Format(CultureInfo.InvariantCulture, "{0}=({1}.value.split('.').pop().toLowerCase()>=0);\r\n", returnReceiver, WebPageCompilerUtility.JsCodeRef(CodeName))); } } else if (string.CompareOrdinal(methodName, "IsFileSizeValid") == 0) { if (!string.IsNullOrEmpty(returnReceiver)) { code.Add(string.Format(CultureInfo.InvariantCulture, "{0}={1}.jsData.IsFileSizeValid();\r\n", returnReceiver, WebPageCompilerUtility.JsCodeRef(CodeName))); } } else if (string.CompareOrdinal(methodName, "SetMaxFileSize") == 0) { code.Add(string.Format(CultureInfo.InvariantCulture, "{0}.jsData.SetMaxFileSize({1});\r\n", WebPageCompilerUtility.JsCodeRef(CodeName), parameters[0])); } else { WebPageCompilerUtility.CreateActionJavaScript(WebPageCompilerUtility.JsCodeRef(CodeName), methodName, code, parameters, returnReceiver); } }
public override string GetJavaScriptReferenceCode(StringCollection method, string attributeName, string[] parameters) { if (string.CompareOrdinal(attributeName, "IsFileTypeValid") == 0) { return(string.Format(CultureInfo.InvariantCulture, "{0}.toLowerCase().indexOf({1}.{2}.value.split('.').pop().toLowerCase()) >= 0", parameters[0], this.FormName, Site.Name)); } if (string.CompareOrdinal(attributeName, "IsFileSizeValid") == 0) { return(string.Format(CultureInfo.InvariantCulture, "{0}.jsData.IsFileSizeValid({1})", Site.Name, parameters[0])); } string s = WebPageCompilerUtility.GetJavaScriptWebMethodReferenceCode(WebPageCompilerUtility.JsCodeRef(CodeName), attributeName, method, parameters); if (!string.IsNullOrEmpty(s)) { return(s); } return(null); }
public static void CreateJavaScript(IProperty SetProperty, string v, StringCollection sb, StringCollection parameters) { if (SetProperty.RootPointer != null && typeof(WebPage).IsAssignableFrom(SetProperty.RootPointer.BaseClassType)) { ClassPointer pp = SetProperty.PropertyOwner as ClassPointer; if (pp != null) { if (pp.ClassId != SetProperty.RootPointer.ClassId) { sb.Add(string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setPropertyByPageId({0},'{1}',{2});\r\n", pp.ClassId, SetProperty.Name, v)); return; } } } if (typeof(ProjectResources).Equals(SetProperty.Owner.ObjectInstance)) { if (string.CompareOrdinal(SetProperty.Name, "ProjectCultureName") == 0) { sb.Add(string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.SwitchCulture({0});\r\n", v)); return; } } IWebClientComponent wcc = SetProperty.Owner.ObjectInstance as IWebClientComponent; if (wcc == null && SetProperty.Owner.ObjectInstance == null) { if (SetProperty.Owner.ObjectType != null) { if (SetProperty.Owner.ObjectType.GetInterface("IWebClientComponent") != null) { try { wcc = Activator.CreateInstance(SetProperty.Owner.ObjectType) as IWebClientComponent; if (wcc != null) { wcc.SetCodeName(SetProperty.Owner.CodeName); } } catch { } } } } if (wcc != null) { v = wcc.MapJavaScriptVallue(SetProperty.Name, v); } IWebClientPropertyCustomSetter wpcs = SetProperty.Owner.ObjectInstance as IWebClientPropertyCustomSetter; if (wpcs == null && SetProperty.Owner.ObjectInstance == null) { wpcs = wcc as IWebClientPropertyCustomSetter; } if (wpcs != null) { string ownerCode = SetProperty.Owner.GetJavaScriptReferenceCode(sb); if (wpcs.CreateSetPropertyJavaScript(ownerCode, SetProperty.Name, v, sb)) { return; } } if (string.CompareOrdinal("Font", SetProperty.Name) == 0) { IWebClientControl webc = SetProperty.Owner.ObjectInstance as IWebClientControl; if (webc != null) { sb.Add(string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setFont({0},{1});\r\n", WebPageCompilerUtility.JsCodeRef(webc.CodeName), WebPageCompilerUtility.GetFontJavascriptValues(v))); return; } } if (typeof(SessionVariableCollection).Equals(SetProperty.Owner.ObjectType)) { sb.Add(string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setSessionVariable('{0}',{1});\r\n", SetProperty.Name, v)); return; } if (typeof(LimnorWebApp).IsAssignableFrom(SetProperty.Owner.ObjectType)) { if (string.CompareOrdinal(SetProperty.Name, "GlobalVariableTimeout") == 0) { sb.Add(string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setSessionTimeout({0});\r\n", v)); return; } } string code = null; IWebClientPropertyHolder wcph = SetProperty.Owner.ObjectInstance as IWebClientPropertyHolder; if (wcph != null) { code = wcph.CreateSetPropertyJavaScript(SetProperty.Owner.CodeName, SetProperty.Name, v); if (!string.IsNullOrEmpty(code)) { sb.Add(code); } } IWebClientPropertySetter wcps = SetProperty.Owner.ObjectInstance as IWebClientPropertySetter; if (string.IsNullOrEmpty(code)) { if (wcps == null || !wcps.UseCustomSetter(SetProperty.Name)) { string left = SetProperty.GetJavaScriptReferenceCode(sb); if (left.EndsWith(".innerText", StringComparison.Ordinal)) { code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.SetInnerText({0},{1});\r\n", left.Substring(0, left.Length - 10), v); } else if (left.StartsWith("JsonDataBinding.GetInnerText(", StringComparison.Ordinal)) { string oc = SetProperty.Owner.GetJavaScriptReferenceCode(sb); code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.SetInnerText({0},{1});\r\n", oc, v); } else if (left.EndsWith(".Opacity", StringComparison.Ordinal)) { code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setOpacity({0},{1});\r\n", left.Substring(0, left.Length - ".Opacity".Length), v); } else if (left.StartsWith("JsonDataBinding.getOpacity(", StringComparison.Ordinal)) { string oc = SetProperty.Owner.GetJavaScriptReferenceCode(sb); code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setOpacity({0},{1});\r\n", oc, v); } else if (left.EndsWith(".style.display", StringComparison.Ordinal)) { code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setVisible({0},{1});\r\n", left.Substring(0, left.Length - ".style.display".Length), v); } else { if (wcc != null && v != null) { if (string.CompareOrdinal(SetProperty.Name, "Top") == 0 || string.CompareOrdinal(SetProperty.Name, "Left") == 0 || string.CompareOrdinal(SetProperty.Name, "Height") == 0 || string.CompareOrdinal(SetProperty.Name, "Width") == 0) { if (!v.EndsWith("px", StringComparison.Ordinal)) { code = string.Format(CultureInfo.InvariantCulture, "{0}=({1})+'px';\r\n", left, v); } } } if (code == null && SetProperty.Holder != null) { if (typeof(HtmlListBox).Equals(SetProperty.Holder.ObjectType) || typeof(HtmlDropDown).Equals(SetProperty.Holder.ObjectType)) { if (string.CompareOrdinal(SetProperty.Name, "SelectedValue") == 0 || string.CompareOrdinal(SetProperty.Name, "selectedValue") == 0) { code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.SetSelectedListValue({0},{1});\r\n", SetProperty.Holder.GetJavaScriptReferenceCode(sb), v); } else if (string.CompareOrdinal(SetProperty.Name, "SelectedItem") == 0 || string.CompareOrdinal(SetProperty.Name, "selectedItem") == 0) { code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.SetSelectedListText({0},{1});\r\n", SetProperty.Holder.GetJavaScriptReferenceCode(sb), v); } } } if (code == null) { code = string.Format(CultureInfo.InvariantCulture, "{0}={1};\r\n", left, v); } } if (!string.IsNullOrEmpty(code)) { sb.Add(code); } } } bool isCustomValue = false; if (string.CompareOrdinal("tag", SetProperty.Name) == 0) { isCustomValue = true; } else if (wcc != null) { WebClientValueCollection cvc = wcc.CustomValues; if (cvc != null) { if (cvc.ContainsKey(SetProperty.Name)) { isCustomValue = true; } } } if (isCustomValue) { string ownerCode = SetProperty.Owner.GetJavaScriptReferenceCode(sb); sb.Add(string.Format(CultureInfo.InvariantCulture, "{0}JsonDataBinding.onSetCustomValue({1},'{2}');\r\n", Indentation.GetIndent(), ownerCode, SetProperty.Name)); } if (wcps != null) { wcps.OnSetProperty(SetProperty.Name, v, sb); } }