mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-26 12:03:16 +08:00
Implementing that Dynamic Forms elements' Names are auto-generated from the given Labels, fixes #5287
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Web.Mvc;
|
||||
using Orchard.DynamicForms.Services;
|
||||
using Orchard.DynamicForms.ViewModels;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.DynamicForms.Controllers {
|
||||
public class AdminController : Controller {
|
||||
@@ -17,5 +18,12 @@ namespace Orchard.DynamicForms.Controllers {
|
||||
};
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
public ActionResult GetTechnicalName(string displayName, int version) {
|
||||
return Json(new {
|
||||
result = displayName.ToHtmlName(),
|
||||
version = version
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,8 +16,8 @@ namespace Orchard.DynamicForms.Drivers {
|
||||
}
|
||||
|
||||
protected override EditorResult OnBuildEditor(CheckBox element, ElementEditorContext context) {
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel");
|
||||
var checkBoxEditor = BuildForm(context, "CheckBox");
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel", "Properties:1");
|
||||
var checkBoxEditor = BuildForm(context, "CheckBox", "Properties:15");
|
||||
var checkBoxValidation = BuildForm(context, "CheckBoxValidation", "Validation:10");
|
||||
|
||||
return Editor(context, autoLabelEditor, checkBoxEditor, checkBoxValidation);
|
||||
|
||||
@@ -47,5 +47,8 @@ namespace Orchard.DynamicForms.Drivers {
|
||||
context.ElementShape.Child.Add(New.PlaceChildContent(Source: context.ElementShape));
|
||||
}
|
||||
|
||||
protected override EditorResult OnBuildEditor(FormElement element, ElementEditorContext context) {
|
||||
return Editor(context, BuildForm(context, "CommonFormElement", "Properties:10"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,8 @@ namespace Orchard.DynamicForms.Drivers {
|
||||
}
|
||||
|
||||
protected override EditorResult OnBuildEditor(EmailField element, ElementEditorContext context) {
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel");
|
||||
var emailFieldEditor = BuildForm(context, "EmailField");
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel", "Properties:1");
|
||||
var emailFieldEditor = BuildForm(context, "EmailField", "Properties:15");
|
||||
var emailFieldValidation = BuildForm(context, "EmailFieldValidation", "Validation:10");
|
||||
|
||||
return Editor(context, autoLabelEditor, emailFieldEditor, emailFieldValidation);
|
||||
|
||||
@@ -19,8 +19,8 @@ namespace Orchard.DynamicForms.Drivers {
|
||||
}
|
||||
|
||||
protected override EditorResult OnBuildEditor(Enumeration element, ElementEditorContext context) {
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel");
|
||||
var enumerationEditor = BuildForm(context, "Enumeration");
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel", "Properties:1");
|
||||
var enumerationEditor = BuildForm(context, "Enumeration", "Properties:15");
|
||||
var checkBoxValidation = BuildForm(context, "EnumerationValidation", "Validation:10");
|
||||
|
||||
return Editor(context, autoLabelEditor, enumerationEditor, checkBoxValidation);
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Orchard.DynamicForms.Drivers {
|
||||
}
|
||||
|
||||
protected override EditorResult OnBuildEditor(PasswordField element, ElementEditorContext context) {
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel");
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel", "Properties:1");
|
||||
var passwordFieldValidation = BuildForm(context, "PasswordFieldValidation", "Validation:10");
|
||||
|
||||
return Editor(context, autoLabelEditor, passwordFieldValidation);
|
||||
|
||||
@@ -31,8 +31,8 @@ namespace Orchard.DynamicForms.Drivers {
|
||||
}
|
||||
|
||||
protected override EditorResult OnBuildEditor(Query element, ElementEditorContext context) {
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel");
|
||||
var enumerationEditor = BuildForm(context, "QueryForm");
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel", "Properties:1");
|
||||
var enumerationEditor = BuildForm(context, "QueryForm", "Properties:15");
|
||||
var checkBoxValidation = BuildForm(context, "QueryValidation", "Validation:10");
|
||||
|
||||
return Editor(context, autoLabelEditor, enumerationEditor, checkBoxValidation);
|
||||
|
||||
@@ -26,8 +26,8 @@ namespace Orchard.DynamicForms.Drivers {
|
||||
}
|
||||
|
||||
protected override EditorResult OnBuildEditor(Taxonomy element, ElementEditorContext context) {
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel");
|
||||
var enumerationEditor = BuildForm(context, "TaxonomyForm");
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel", "Properties:1");
|
||||
var enumerationEditor = BuildForm(context, "TaxonomyForm", "Properties:15");
|
||||
var checkBoxValidation = BuildForm(context, "TaxonomyValidation", "Validation:10");
|
||||
|
||||
return Editor(context, autoLabelEditor, enumerationEditor, checkBoxValidation);
|
||||
|
||||
@@ -14,8 +14,8 @@ namespace Orchard.DynamicForms.Drivers {
|
||||
}
|
||||
|
||||
protected override EditorResult OnBuildEditor(TextArea element, ElementEditorContext context) {
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel");
|
||||
var textAreaEditor = BuildForm(context, "TextArea");
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel", "Properties:1");
|
||||
var textAreaEditor = BuildForm(context, "TextArea", "Properties:15");
|
||||
var textAreaValidation = BuildForm(context, "TextAreaValidation", "Validation:10");
|
||||
|
||||
return Editor(context, autoLabelEditor, textAreaEditor, textAreaValidation);
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Orchard.DynamicForms.Drivers {
|
||||
}
|
||||
|
||||
protected override EditorResult OnBuildEditor(TextField element, ElementEditorContext context) {
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel");
|
||||
var textFieldEditor = BuildForm(context, "TextField");
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel", "Properties:1");
|
||||
var textFieldEditor = BuildForm(context, "TextField", "Properties:15");
|
||||
var textFieldValidation = BuildForm(context, "TextFieldValidation", "Validation:10");
|
||||
|
||||
return Editor(context, autoLabelEditor, textFieldEditor, textFieldValidation);
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Orchard.DynamicForms.Drivers {
|
||||
}
|
||||
|
||||
protected override EditorResult OnBuildEditor(UrlField element, ElementEditorContext context) {
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel");
|
||||
var webAddressFieldEditor = BuildForm(context, "UrlField");
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel", "Properties:1");
|
||||
var webAddressFieldEditor = BuildForm(context, "UrlField", "Properties:15");
|
||||
var webAddressFieldValidation = BuildForm(context, "UrlFieldValidation", "Validation:10");
|
||||
|
||||
return Editor(context, autoLabelEditor, webAddressFieldEditor, webAddressFieldValidation);
|
||||
|
||||
@@ -20,8 +20,8 @@ namespace Orchard.DynamicForms.Forms {
|
||||
Name: "Label",
|
||||
Title: "Label",
|
||||
Classes: new[] { "text", "large", "tokenized" },
|
||||
Description: T("The label text to render."),
|
||||
EnabledBy: "ShowLabel"));
|
||||
Description: T("The label text to render.")),
|
||||
_AutoLabelScript: shape.AutoLabelScript());
|
||||
|
||||
return form;
|
||||
});
|
||||
|
||||
@@ -554,6 +554,9 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Views\EditorTemplates\BuilderSteps\FormSubmissions.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\AutoLabelScript.cshtml" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
@using (Script.Foot()) {
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
$(function () {
|
||||
var $name = $("#CommonFormElement #InputName");
|
||||
var $displayName = $("#AutoLabel #Label");
|
||||
var jsonUrl = "@Url.Action("GetTechnicalName", "Admin", new { Area = "Orchard.DynamicForms" } )";
|
||||
var version = 0;
|
||||
|
||||
var nameAltered;
|
||||
$name.keypress(function () {
|
||||
nameAltered = true;
|
||||
});
|
||||
|
||||
var compute = function () {
|
||||
// Stop processing automatically if altered by the user.
|
||||
if (nameAltered) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$.post(jsonUrl, {
|
||||
displayName: $displayName.val(),
|
||||
version: ++version,
|
||||
__RequestVerificationToken: $("input[name=__RequestVerificationToken]").val()
|
||||
},
|
||||
function (data) {
|
||||
if (version == data.version) {
|
||||
$name.val(data.result);
|
||||
}
|
||||
},
|
||||
"json"
|
||||
);
|
||||
};
|
||||
|
||||
// Pull technical name input from tab order.
|
||||
$name.attr("tabindex", -1);
|
||||
|
||||
$displayName.keyup(compute);
|
||||
$displayName.blur(compute);
|
||||
})
|
||||
//]]>
|
||||
</script>
|
||||
}
|
||||
@@ -16,15 +16,15 @@
|
||||
@* Only render the editor shapes if the dialog is not closing. *@
|
||||
@if (Model.Submitted != true) {
|
||||
@Html.ValidationSummary()
|
||||
using (Html.BeginFormAntiForgeryPost(Url.Action("Update", "Element", new {session = Model.SessionKey, area = "Orchard.Layouts"}))) {
|
||||
foreach (var tab in Model.Tabs) {
|
||||
var id = String.Format("element-{0}", tab.ToLowerInvariant());
|
||||
using (Html.BeginFormAntiForgeryPost(Url.Action("Update", "Element", new {session = Model.SessionKey, area = "Orchard.Layouts"}))) {
|
||||
foreach (var tab in Model.Tabs) {
|
||||
var orderedEditorsInTab = Model.EditorResult.Editors
|
||||
.Where(editor => ShapePosition.Parse((String)editor.Metadata.Position).Name == tab)
|
||||
.OrderBy(editor => ShapePosition.Parse((String)editor.Metadata.Position).Position);
|
||||
var id = String.Format("element-{0}", tab.ToLowerInvariant());
|
||||
<div id="@id" class="tab-view">
|
||||
@foreach (var editor in Model.EditorResult.Editors) {
|
||||
var position = ShapePosition.Parse((String) editor.Metadata.Position);
|
||||
if (position.Name == tab) {
|
||||
@Display(editor)
|
||||
}
|
||||
@foreach (var editor in orderedEditorsInTab) {
|
||||
@Display(editor)
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user