Esempio n. 1
0
        public MvcHtmlString EditorCommandControls(EditStateManagerHelper esmHelper, EditorViewConfig config)
        {
            var commandStringBuilder = new StringBuilder();

            commandStringBuilder.Append(esmHelper.CreateCommand(EditStateManagerHelper.Command.BeginEdit));
            if (!config.HideEndEditButton)
            {
                commandStringBuilder.Append(esmHelper.CreateCommand(EditStateManagerHelper.Command.EndEdit));
            }
            commandStringBuilder.Append(esmHelper.CreateCommand(EditStateManagerHelper.Command.Reset));
            if (!config.HideSaveButton)
            {
                commandStringBuilder.Append(esmHelper.CreateCommand(EditStateManagerHelper.Command.Save));
            }
            commandStringBuilder.Append(esmHelper.CreateCommand(EditStateManagerHelper.Command.Cancel));

            return(new MvcHtmlString(commandStringBuilder.ToString()));
        }
Esempio n. 2
0
 public MvcHtmlString EditorCommandControls(string stateManagerName, EditorViewConfig config)
 {
     return(EditorCommandControls(new EditStateManagerHelper(stateManagerName), config));
 }
Esempio n. 3
0
        public MvcHtmlString EditorViewFor <TValue>(Expression <Func <TModel, TValue> > expression, string stateManagerName, EditorViewConfig config, bool scopeBindingToProperty)
        {
            var esmHelper       = new EditStateManagerHelper(stateManagerName);
            var model           = ContextSwitcher.SwitchContext(expression, HtmlHelper.ViewData.Model);
            var newHelper       = HtmlHelperFactory.BuildHtmlHelper(HtmlHelper.ViewContext, model);
            var knockoutBuilder = new KnockoutUIBuilder <TValue>(newHelper, ContainerBuilder);

            var editor = new TagBuilder("div");

            editor.MergeAttribute("data-bind", esmHelper.VisibleWhenEditingBinding);
            editor.InnerHtml = knockoutBuilder.EditorForModel().ToHtmlString();

            var display = new TagBuilder("div");

            display.MergeAttribute("data-bind", esmHelper.VisibleWhenReadonlyBinding);
            display.InnerHtml = knockoutBuilder.DisplayForModel().ToHtmlString();

            var footer = new TagBuilder("footer");

            footer.InnerHtml = EditorCommandControls(esmHelper, config).ToString();

            var containerHtmlStringBuilder = new StringBuilder();

            containerHtmlStringBuilder.Append(display);
            containerHtmlStringBuilder.Append(editor);
            containerHtmlStringBuilder.Append(footer);

            var containerBuilder = scopeBindingToProperty
                                       ? new BindingScopeUIContainerBuilder()
                                       : new UIContainerBuilder();

            var container = containerBuilder.BuildUIContainer(expression, "div");

            container.AddCssClass("editor-control");
            container.InnerHtml = containerHtmlStringBuilder.ToString();
            return(new MvcHtmlString(container.ToString()));
        }