Skip to content

Commit

Permalink
Content Definition: Redirect to Edit or Create on Enter in search
Browse files Browse the repository at this point in the history
Fixes #1071
  • Loading branch information
agriffard committed Oct 7, 2017
1 parent 1d084df commit 45502ae
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<nav class="admin-toolbar">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a asp-route-action="Create" class="btn btn-primary" role="button">@T["Create new type"]</a>
<a asp-route-action="Create" id="btnCreate" class="btn btn-primary" role="button">@T["Create new type"]</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
Expand All @@ -16,7 +16,7 @@
<ul class="list-group">
@foreach (var type in Model.Types)
{
<li class="list-group-item" data-filter-value="@type.DisplayName">
<li class="list-group-item" data-filter-value="@type.DisplayName" data-type-name="@type.Name">
@Html.DisplayFor(m => type)
</li>
}
Expand All @@ -26,12 +26,13 @@
$(function() {
var searchBox = $('#search-box');
// On each keypress filter the list of features
// On each keypress filter the list of types
searchBox.keyup(function(e) {
var search = $(this).val().toLowerCase();
var elementsToFilter = $("[data-filter-value]");
// On ESC, clear the search box and display all features
// On ESC, clear the search box and display all types
if (e.keyCode == 27 || search == '') {
searchBox.val('');
elementsToFilter.toggle(true);
Expand All @@ -42,6 +43,19 @@
$(this).toggle(found);
});
}
// On Enter, redirect to the edit page if the type exists or the create page with a suggestion
if (e.keyCode == 13) {
var visibleRows = $("[data-type-name]:visible");
if (visibleRows.length > 0) {
var editLink = $(".related a:last", visibleRows[0]);
location.href = editLink.attr("href");
} else {
var primaryButton = $("#btnCreate");
location.href = primaryButton.attr("href") + "?suggestion=" + search;
}
return;
}
});
});
//]]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
<h1>@RenderTitleSegments(T["Content Parts"])</h1>

<nav class="admin-toolbar">

<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a asp-route-action="CreatePart" class="btn btn-primary" role="button">@T["Create new part"]</a>
<a asp-route-action="CreatePart" id="btnCreate" class="btn btn-primary" role="button">@T["Create new part"]</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input id="search-box" class="form-control" type="text" placeholder="@T["Filter"]" autofocus="autofocus">
<input id="search-box" class="form-control mr-sm-2" type="text" placeholder="@T["Filter"]" autofocus="autofocus">
</form>
</nav>

<ul class="list-group">
@foreach (var type in Model.Parts)
{
<li class="list-group-item" data-filter-value="@type.DisplayName">
<li class="list-group-item" data-filter-value="@type.DisplayName" data-type-name="@type.Name">
@Html.DisplayFor(m => type)
</li>
}
Expand All @@ -27,12 +26,12 @@
$(function() {
var searchBox = $('#search-box');
// On each keypress filter the list of features
// On each keypress filter the list of parts
searchBox.keyup(function(e) {
var search = $(this).val().toLowerCase();
var elementsToFilter = $("[data-filter-value]");
// On ESC, clear the search box and display all features
// On ESC, clear the search box and display all parts
if (e.keyCode == 27 || search == '') {
searchBox.val('');
elementsToFilter.toggle(true);
Expand All @@ -43,6 +42,19 @@
$(this).toggle(found);
});
}
// On Enter, redirect to the edit page if the part exists or the create page with a suggestion
if (e.keyCode == 13) {
var visibleRows = $("[data-type-name]:visible");
if (visibleRows.length > 0) {
var editLink = $(".related a:last", visibleRows[0]);
location.href = editLink.attr("href");
} else {
var primaryButton = $("#btnCreate");
location.href = primaryButton.attr("href") + "?suggestion=" + search;
}
return;
}
});
});
//]]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
var settings = Model.Settings.ToObject<ContentTypeSettings>();
}
<div class="properties">
<a asp-route-action="Edit" asp-route-area="OrchardCore.ContentTypes" asp-route-id="@Model.Name">@Model.DisplayName</a>
<div class="related">
@if (settings.Creatable)
{
Expand All @@ -12,7 +13,6 @@
<a asp-route-action="List" asp-route-area="OrchardCore.Contents" asp-route-id="@Model.Name" class="btn btn-secondary btn-sm" role="button">@T["List Items"]</a>
<a asp-route-action="Edit" asp-route-area="OrchardCore.ContentTypes" asp-route-id="@Model.Name" class="btn btn-primary btn-sm" role="button">@T["Edit"]</a>
</div>
<a asp-route-action="Edit" asp-route-area="OrchardCore.ContentTypes" asp-route-id="@Model.Name">@Model.DisplayName</a>
@if (!string.IsNullOrWhiteSpace(settings.Stereotype))
{
<span class="badge badge-default badge-pill" title="Stereotype">@settings.Stereotype</span>
Expand Down

0 comments on commit 45502ae

Please sign in to comment.