From 02c9ab4cf361bdb20af1c83188f4e640c90cb28c Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Mon, 8 Nov 2010 15:54:29 -0800 Subject: [PATCH] Moving the tag create from from its own page right up to the top-right of the tag management UI --HG-- branch : dev --- src/Orchard.Web/Core/Shapes/Scripts/base.js | 44 ++++++++++++++++--- .../Controllers/AdminController.cs | 30 +++++++++---- .../Modules/Orchard.Tags/Orchard.Tags.csproj | 9 +++- .../Modules/Orchard.Tags/ResourceManifest.cs | 9 ++++ .../Modules/Orchard.Tags/Styles/Web.config | 18 ++++++++ .../Modules/Orchard.Tags/Styles/admin.css | 11 +++++ .../Orchard.Tags/Views/Admin/Create.cshtml | 15 ------- .../Orchard.Tags/Views/Admin/Index.cshtml | 7 ++- .../EditorTemplates/Parts/CreateTag.cshtml | 13 ++++++ .../Themes/TheAdmin/Styles/site.css | 4 ++ 10 files changed, 129 insertions(+), 31 deletions(-) create mode 100644 src/Orchard.Web/Modules/Orchard.Tags/ResourceManifest.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Tags/Styles/Web.config create mode 100644 src/Orchard.Web/Modules/Orchard.Tags/Styles/admin.css delete mode 100644 src/Orchard.Web/Modules/Orchard.Tags/Views/Admin/Create.cshtml create mode 100644 src/Orchard.Web/Modules/Orchard.Tags/Views/EditorTemplates/Parts/CreateTag.cshtml diff --git a/src/Orchard.Web/Core/Shapes/Scripts/base.js b/src/Orchard.Web/Core/Shapes/Scripts/base.js index 1d2571d2d..d4ee65f70 100644 --- a/src/Orchard.Web/Core/Shapes/Scripts/base.js +++ b/src/Orchard.Web/Core/Shapes/Scripts/base.js @@ -93,7 +93,39 @@ } // otherwise, make the autofocus attribute work var autofocus = _this.find(":input[autofocus]").first(); - return autofocus.focus(); + autofocus.focus(); + + return _this; + }, + helpfullyPlacehold: function () { + var _this = $(this); + + // give it up to the browser to handle placeholder text + if ('placeholder' in document.createElement('input')) { + return; + } + // otherwise, make the placeholder attribute work + $(":input[placeholder]") + .each(function () { + var _this = $(this); + if (_this.val() === "") { + _this.val(_this.attr("placeholder")).addClass("placeholderd"); + } + }) + .live("focus", function () { + var _this = $(this); + if (_this.val() === _this.attr("placeholder")) { + _this.val("").removeClass("placeholderd"); + } + }) + .live("blur", function () { + var _this = $(this); + if (_this.val() === "") { + _this.val(_this.attr("placeholder")).addClass("placeholderd"); + } + }); + + return _this; }, toggleWhatYouControl: function () { var _this = $(this); @@ -106,7 +138,7 @@ //_controllees.slideUp(200); <- hook this back up when chrome behaves, or when I care less...or when chrome behaves _controllees.hide() } - return this; + return _this; } }); // collapsable areas - anything with a data-controllerid attribute has its visibility controlled by the id-ed radio/checkbox @@ -131,7 +163,7 @@ $(function () { $("form.inline.link").each(function () { var _this = $(this); - console.log(_this.html()) + console.log(_this.html()) var link = $(""); var button = _this.children("button").first(); link.text(button.text()) @@ -143,9 +175,11 @@ $("body").append(_this); }); }); - // (do) a little better autofocus + // some default value add behavior $(function () { - $("body").helpfullyFocus(); + $("body").helpfullyFocus() // (do) a little better autofocus + .helpfullyPlacehold(); // pick up on placeholders + }); // UnsafeUrl links -> form POST //todo: need some real microdata support eventually (incl. revisiting usage of data-* attributes) diff --git a/src/Orchard.Web/Modules/Orchard.Tags/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Tags/Controllers/AdminController.cs index 4c31d6ed7..e8d2edbb1 100644 --- a/src/Orchard.Web/Modules/Orchard.Tags/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Tags/Controllers/AdminController.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Web.Mvc; using Orchard.Localization; using Orchard.ContentManagement; @@ -31,7 +32,9 @@ namespace Orchard.Tags.Controllers { } [HttpPost] - public ActionResult Index(FormCollection input) { + [FormValueRequired("submit.BulkEdit")] + public ActionResult Index(FormCollection input) + { var viewModel = new TagsAdminIndexViewModel {Tags = new List(), BulkAction = new TagAdminIndexBulkAction()}; if ( !TryUpdateModel(viewModel) ) { @@ -58,16 +61,14 @@ namespace Orchard.Tags.Controllers { return RedirectToAction("Index"); } - public ActionResult Create() { - return View(new TagsAdminCreateViewModel()); - } - - [HttpPost] - public ActionResult Create(FormCollection input) { + [HttpPost, ActionName("Index")] + [FormValueRequired("submit.Create")] + public ActionResult IndexCreatePOST() { var viewModel = new TagsAdminCreateViewModel(); if (!TryUpdateModel(viewModel)) { - return View(viewModel); + ViewData["CreateTag"] = viewModel; + return Index(); } if (!Services.Authorizer.Authorize(Permissions.CreateTag, T("Couldn't create tag"))) @@ -147,5 +148,18 @@ namespace Orchard.Tags.Controllers { IsChecked = false, }; } + + public class FormValueRequiredAttribute : ActionMethodSelectorAttribute { + private readonly string _submitButtonName; + + public FormValueRequiredAttribute(string submitButtonName) { + _submitButtonName = submitButtonName; + } + + public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) { + var value = controllerContext.HttpContext.Request.Form[_submitButtonName]; + return !string.IsNullOrEmpty(value); + } + } } } diff --git a/src/Orchard.Web/Modules/Orchard.Tags/Orchard.Tags.csproj b/src/Orchard.Web/Modules/Orchard.Tags/Orchard.Tags.csproj index c25bb40d0..da7604b48 100644 --- a/src/Orchard.Web/Modules/Orchard.Tags/Orchard.Tags.csproj +++ b/src/Orchard.Web/Modules/Orchard.Tags/Orchard.Tags.csproj @@ -70,6 +70,7 @@ + @@ -91,7 +92,7 @@ - + @@ -116,6 +117,12 @@ Designer + + + Designer + + + + + + + + + + + + + diff --git a/src/Orchard.Web/Modules/Orchard.Tags/Styles/admin.css b/src/Orchard.Web/Modules/Orchard.Tags/Styles/admin.css new file mode 100644 index 000000000..edf2945a1 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Tags/Styles/admin.css @@ -0,0 +1,11 @@ +.orchard-tags #main .manage form { + margin:0; +} +.orchard-tags .manage fieldset { + display:inline; + margin:0; + padding:0; +} +.orchard-tags .manage label[for=TagName] { + display:none; +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Tags/Views/Admin/Create.cshtml b/src/Orchard.Web/Modules/Orchard.Tags/Views/Admin/Create.cshtml deleted file mode 100644 index a69e65021..000000000 --- a/src/Orchard.Web/Modules/Orchard.Tags/Views/Admin/Create.cshtml +++ /dev/null @@ -1,15 +0,0 @@ -@model Orchard.Tags.ViewModels.TagsAdminCreateViewModel - -

@Html.TitleForPage(T("Add a Tag").ToString())

-@using (Html.BeginFormAntiForgeryPost()) { - @Html.ValidationSummary() - -
- @Html.LabelFor(m => m.TagName, T("Tag Name")) - @Html.TextBoxFor(m=>m.TagName, new { @class = "text" }) -
- -
- -
- } diff --git a/src/Orchard.Web/Modules/Orchard.Tags/Views/Admin/Index.cshtml b/src/Orchard.Web/Modules/Orchard.Tags/Views/Admin/Index.cshtml index 46df12f8b..deb569a1c 100644 --- a/src/Orchard.Web/Modules/Orchard.Tags/Views/Admin/Index.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Tags/Views/Admin/Index.cshtml @@ -3,11 +3,15 @@ @using Orchard.Utility.Extensions; @{ Script.Require("ShapesBase"); + Style.Require("TagsAdmin"); }

@Html.TitleForPage(T("Manage Tags").ToString())

+@Html.ValidationSummary() +
+ @Display.EditorTemplate(TemplateName: "Parts/CreateTag", Model: View.CreateTag != null ? View.CreateTag : new TagsAdminCreateViewModel()) +
@using(Html.BeginFormAntiForgeryPost()) { - @Html.ValidationSummary()
-
@Html.ActionLink(T("Add a tag").ToString(), "Create", new { }, new { @class = "button primaryAction" })
diff --git a/src/Orchard.Web/Modules/Orchard.Tags/Views/EditorTemplates/Parts/CreateTag.cshtml b/src/Orchard.Web/Modules/Orchard.Tags/Views/EditorTemplates/Parts/CreateTag.cshtml new file mode 100644 index 000000000..0d7cbf8ff --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Tags/Views/EditorTemplates/Parts/CreateTag.cshtml @@ -0,0 +1,13 @@ +@model Orchard.Tags.ViewModels.TagsAdminCreateViewModel +@{ + Style.Require("TagsAdmin"); +} +@using (Html.BeginFormAntiForgeryPost()) { +
+ @Html.LabelFor(m => m.TagName, T("New Tag Name")) + @Html.TextBoxFor(m => m.TagName, new { @class = "text", placeholder = T("New Tag Name") }) +
+
+ +
+} \ No newline at end of file diff --git a/src/Orchard.Web/Themes/TheAdmin/Styles/site.css b/src/Orchard.Web/Themes/TheAdmin/Styles/site.css index 03b7e88dc..ab6ff89f5 100644 --- a/src/Orchard.Web/Themes/TheAdmin/Styles/site.css +++ b/src/Orchard.Web/Themes/TheAdmin/Styles/site.css @@ -914,4 +914,8 @@ fieldset.publish-later-datetime input { /* todo: needed? */ .clearBoth { clear:both; +} +.placeholderd { + color:#ccc; + font-style:italic; } \ No newline at end of file