string AttachConstructor(JsModule module, string type) { var varModule = JsFunction.VarName(AttachFunction.Module); var varLines = JsFunction.VarName(module); var line = type.FirstLower(); var args = AttachFunction.Arguments.ToString(a => a == JsFunction.This ? "that" : a == this ? line : JsonConvert.SerializeObject(a, AttachFunction.JsonSerializerSettings), ", "); var result = "require(['" + module + "', '" + AttachFunction.Module.Name + "'], function(" + varLines + ", " + varModule + ") {\r\n" + "var " + line + " = " + NewLine(varLines, type) + ";\r\n" + varModule + "." + AttachFunction.FunctionName + "(" + args + ");\r\n" + line + ".ready();\r\n" + "});"; if (!AttachFunction.Arguments.Contains(JsFunction.This)) { return(result); } return("(function(that) { " + result + "})(this)"); }
string BasicConstructor(JsModule module, string type) { var varNameLines = JsFunction.VarName(module); var result = "require(['" + module + "'], function(" + varNameLines + ") { " + NewLine(varNameLines, type) + ".ready(); });"; return(result); }
public string GetPreConstructorScript(ClientConstructorContext ctx) { if (!ctx.Type.IsEntity()) { return(Default()); } List <JsFunction> list = new List <JsFunction>(); if (GlobalPreConstructors != null) { list.AddRange(GlobalPreConstructors.GetInvocationListTyped().Select(f => f(ctx))); } var pre = PreConstructors.TryGetC(ctx.Type); if (pre != null) { list.Add(pre(ctx)); } else { list.Add(OperationClient.Manager.ClientConstruct(ctx)); } list.RemoveAll(a => a == null); if (list.IsEmpty()) { return(Default()); } var modules = list.Select(p => p.Module).Distinct(); var code = list.AsEnumerable().Reverse().Aggregate("resolve(extraArgs);", (acum, js) => @"if(extraArgs == null) return Promise.resolve(null); " + InvokeFunction(js) + @" .then(function(extraArgs){ " + acum.Indent(4) + @" });"); var result = @"function(extraArgs){ return new Promise(function(resolve){ require([{moduleNames}], function({moduleVars}){ extraArgs = extraArgs || {}; {code} }); }); }".Replace("{moduleNames}", modules.ToString(m => "'" + m.Name + "'", ", ")) .Replace("{moduleVars}", modules.ToString(m => JsFunction.VarName(m), ", ")) .Replace("{code}", code.Indent(12)); return(result); }
private static MvcHtmlString CountSearchControlInternal(FindOptions findOptions, Web.CountSearchControl options, Context context) { findOptions.SearchOnLoad = true; HtmlStringBuilder sb = new HtmlStringBuilder(); if (options.Navigate) { sb.Add(new HtmlTag("a").Id(context.Prefix) .Class("count-search") .Attr("href", options.Href.HasText() ? options.Href : findOptions.ToString()) .SetInnerText("...")); } else { sb.Add(new HtmlTag("span").Id(context.Prefix) .Class("count-search") .SetInnerText("...")); } if (options.View) { sb.Add(new HtmlTag("a", context.Compose("csbtnView")) .Class("sf-line-button sf-view") .Attr("title", EntityControlMessage.View.NiceToString()) .Attr("onclick", JsModule.Finder["explore"](findOptions.ToJS(context.Compose("New"))).ToString()) .InnerHtml(new HtmlTag("span").Class("glyphicon glyphicon-arrow-right"))); } var function = new JsFunction(JsModule.Finder, "count", findOptions.ToJS(context.Prefix), new JRaw("'" + context.Prefix + "'.get()")); sb.Add(MvcHtmlString.Create("<script>" + function.ToHtmlString() + "</script>")); return(sb.ToHtml()); }
private string InvokeFunction(JsFunction func) { return(JsFunction.VarName(func.Module) + "." + func.FunctionName + "(" + func.Arguments.ToString(a => a == ExtraJsonParams ? "extraArgs" : JsonConvert.SerializeObject(a, func.JsonSerializerSettings), ", ") + ")"); }
private static MvcHtmlString CountSearchControlInternal(FindOptions findOptions, Web.CountSearchControl options, Context context) { findOptions.SearchOnLoad = true; HtmlStringBuilder sb = new HtmlStringBuilder(); if (options.Navigate) { sb.Add(new HtmlTag("a").Id(context.Prefix) .Class("count-search") .Attr("href", options.Href.HasText() ? options.Href : findOptions.ToString()) .SetInnerText("...")); } else { sb.Add(new HtmlTag("span").Id(context.Prefix) .Class("count-search") .SetInnerText("...")); } if (options.View) { sb.Add(new HtmlTag("a", context.Compose("csbtnView")) .Class("sf-line-button sf-view") .Attr("title", EntityControlMessage.View.NiceToString()) .Attr("onclick", JsModule.Finder["explore"](findOptions.ToJS(context.Compose("New"))).ToString()) .InnerHtml(new HtmlTag("span").Class("glyphicon glyphicon-arrow-right"))); } var function = new JsFunction(JsModule.Finder, "count", findOptions.ToJS(context.Prefix), new JRaw("'" + context.Prefix + "'.get()")); sb.Add(MvcHtmlString.Create("<script>" + function.ToHtmlString() + "</script>")); return sb.ToHtml(); }
public virtual string SFControlThen(string functionCall) { return(JsFunction.SFControlThen(Prefix, functionCall)); }