/// <summary> /// Renders the view. /// </summary> /// <param name="module">The module on behalf of which the view is rendered.</param> /// <param name="model">The model being rendered by the view.</param> /// <returns>The HTML representing the view.</returns> public async Task <string> RenderViewAsync(ModuleDefinition module, object model) { HtmlBuilder hb = new HtmlBuilder(); string actionName = (string)HtmlHelper.RouteData.Values["action"]; string submit = null, submitTT = null; bool submitShown; ButtonTypeEnum submitType = ButtonTypeEnum.Submit; string submitName = null; if (ObjectSupport.TryGetPropertyValue <bool>(model, "__submitShown", out submitShown, true) && submitShown) { ObjectSupport.TryGetPropertyValue <string>(model, "__submitTT", out submitTT); ObjectSupport.TryGetPropertyValue <string>(model, "__submit", out submit); ObjectSupport.TryGetPropertyValue <ButtonTypeEnum>(model, "__submitType", out submitType, ButtonTypeEnum.Submit); ObjectSupport.TryGetPropertyValue <string>(model, "__submitName", out submitName); } string cancel = null, cancelTT = null; bool cancelShown; ButtonTypeEnum cancelType = ButtonTypeEnum.Cancel; if (ObjectSupport.TryGetPropertyValue <bool>(model, "__cancelShown", out cancelShown, true) && cancelShown) { ObjectSupport.TryGetPropertyValue <string>(model, "__cancelTT", out cancelTT); ObjectSupport.TryGetPropertyValue <string>(model, "__cancel", out cancel); ObjectSupport.TryGetPropertyValue <ButtonTypeEnum>(model, "__cancelType", out cancelType, ButtonTypeEnum.Cancel); } List <FormButton> buttons = new List <FormButton>(); if (submitShown) { buttons.Add(new FormButton() { ButtonType = submitType, Text = submit, Title = submitTT, Name = submitName }); } if (cancelShown) { buttons.Add(new FormButton() { ButtonType = cancelType, Text = cancel, Title = cancelTT }); } hb.Append($@" {await RenderBeginFormAsync(ActionName: actionName)} {await PartialForm(async () => await RenderPartialViewAsync(module, model))} {await FormButtonsAsync(buttons)} {await RenderEndFormAsync()}"); return(hb.ToString()); }
internal async Task<string> RenderPropertyListTabbedAsync(object model, bool readOnly) { List<string> categories = GetCategories(model); if (categories.Count <= 1) // if there is only one category, show as regular property list return await RenderPropertyListAsync(model, readOnly); PropertyList.PropertyListSetup setup = await PropertyListComponentBase.GetPropertyListSetupAsync(model, categories); categories = setup.CategoryOrder; HtmlBuilder hb = new HtmlBuilder(); Type modelType = model.GetType(); ClassData classData = ObjectSupport.GetClassData(modelType); RenderHeader(hb, classData); string divId = Manager.UniqueId(); bool showVariables = YetaWF.Core.Localize.UserSettings.GetProperty<bool>("ShowVariables"); switch (setup.Style) { default: case PropertyList.PropertyListStyleEnum.Tabbed: UI ui = new UI { TabsDef = new TabsDefinition() }; int activeTab = 0; if (ObjectSupport.TryGetPropertyValue<int>(model, "_ActiveTab", out activeTab)) ui.TabsDef.ActiveTabIndex = activeTab; foreach (string category in categories) { string cat = category; if (classData.Categories.ContainsKey(cat)) cat = classData.Categories[cat]; ui.TabsDef.Tabs.Add(new TabEntry { Caption = cat, RenderPaneAsync = async (int tabIndex) => { return (await RenderListAsync(model, category, showVariables, readOnly)).ToString(); }, }); } hb.Append($@" <div id='{divId}' class='yt_propertylist t_tabbed {(readOnly ? "t_display" : "t_edit")}'> {await RenderHiddenAsync(model)} {await HtmlHelper.ForDisplayAsync(ui, nameof(ui.TabsDef), HtmlAttributes: new { __NoTemplate = true })} </div>"); break; case PropertyList.PropertyListStyleEnum.BoxedWithCategories: await Manager.AddOnManager.AddAddOnNamedAsync(AreaRegistration.CurrentPackage.AreaName, "masonry.desandro.com"); hb.Append($@" <div id='{divId}' class='yt_propertylist t_boxedcat {(readOnly ? "t_display" : "t_edit")}'> {await RenderHiddenAsync(model)}"); foreach (string category in categories) { string contents = await RenderListAsync(model, category, showVariables, readOnly); if (!string.IsNullOrWhiteSpace(contents)) { string stat = ""; if (setup.ExpandableList.Contains(category)) stat = (setup.InitialExpanded == category) ? " t_propexpandable t_propexpanded" : " t_propexpandable t_propcollapsed"; hb.Append($@" <div class='t_proptable{stat} t_cat t_boxpanel-{GetCategoryNormalized(category)}'> <div class='t_boxlabel'>{category}</div>"); if (setup.ExpandableList.Contains(category)) hb.Append(@$"<div class='t_boxexpcoll t_show'></div>"); hb.Append($@" {contents} </div>"); } } hb.Append($@" </div>"); break; case PropertyList.PropertyListStyleEnum.Boxed: await Manager.AddOnManager.AddAddOnNamedAsync(AreaRegistration.CurrentPackage.AreaName, "masonry.desandro.com"); hb.Append($@" <div id='{divId}' class='yt_propertylist t_boxed {(readOnly ? "t_display" : "t_edit")}'> {await RenderHiddenAsync(model)}"); foreach (string category in categories) { string contents = await RenderListAsync(model, category, showVariables, readOnly); if (!string.IsNullOrWhiteSpace(contents)) { string stat = ""; if (setup.ExpandableList.Contains(category)) stat = (setup.InitialExpanded == category) ? " t_propexpandable t_propexpanded" : " t_propexpandable t_propcollapsed"; hb.Append($@" <div class='t_proptable {stat} t_cat t_boxpanel-{GetCategoryNormalized(category)}'>"); if (setup.ExpandableList.Contains(category)) hb.Append($"<div class='t_boxexpcoll t_show'></div>"); hb.Append($@" {contents} </div>"); } } hb.Append($@" </div>"); break; } RenderFooter(hb, classData); ControlData cd = null; if (!readOnly) cd = GetControlSets(model, divId); if (setup.ExpandableList != null) { // normalize category names for javascript setup.ExpandableList = (from l in setup.ExpandableList select GetCategoryNormalized(l)).ToList(); } if (setup.InitialExpanded != null) setup.InitialExpanded = GetCategoryNormalized(setup.InitialExpanded); Manager.ScriptManager.AddLast($@"new YetaWF_ComponentsHTML.PropertyListComponent('{divId}', {Utility.JsonSerialize(setup)}, {Utility.JsonSerialize(cd)});"); return hb.ToString(); }