Example #1
0
        public override Task <string> BuildOutputAsync()
        {
            var b = new HtmlCodeBuilder();

            b.Line("@using IntelliTect.Coalesce.Knockout.Helpers");
            b.Line();

            BuildOutput(b);
            return(Task.FromResult(b.ToString()));
        }
Example #2
0
        public static HtmlString ModalFor(MethodViewModel method, string elementId = null, bool includeWithBinding = true)
        {
            if (elementId == null)
            {
                elementId = $"method-{method.Name}";
            }

            var b = new HtmlCodeBuilder();

            b.Line($"<!-- Modal for method: {method.Name} -->");
            var withBinding = includeWithBinding ? $"with: {method.JsVariable}" : null;

            using (b
                   .TagBlock("div", new { @class = "modal fade", id = elementId, tabindex = -1, role = "dialog", data_bind = withBinding })
                   .TagBlock("div", "modal-dialog")
                   .TagBlock("div", "modal-content")
                   )
            {
                using (b.TagBlock("div", "modal-header"))
                {
                    b.Line("<button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>");
                    b.Line($"<h4 class='modal-title'>{method.Name.ToProperCase()}</h4>");
                }

                using (b.TagBlock("div", "modal-body form-horizontal", "with: args"))
                {
                    foreach (ParameterViewModel arg in method.ClientParameters)
                    {
                        using (b.TagBlock("div", "form-group"))
                        {
                            b.Line($"<label class='col-md-4 control-label'>{arg.Name.ToProperCase()}</label>");
                            using (b.TagBlock("div", "col-md-8"))
                            {
                                b.Line($"<input type='text' class='form-control' data-bind='value: {arg.JsVariable}'>");
                            }
                        }
                    }
                }

                using (b.TagBlock("div", "modal-footer"))
                {
                    b.Line("<button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button>");
                    b.Line(@"<button type='button' class='btn btn-primary btn-ok'");
                    b.Indented(@"data-bind=""click: invokeWithArgs.bind(this, args, function(){jQuery($element).closest('.modal').modal('hide')}, null)"">");
                    b.Indented("OK");
                    b.Line("</button>");
                }
            }

            return(new HtmlString(b.ToString()));
        }