mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 10:54:50 +08:00
Merge
--HG-- branch : dev
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Common.Settings.BodyPartSettings>" %>
|
||||
<fieldset>
|
||||
<label for="<%:Html.FieldIdFor(m => m.FlavorDefault) %>"><%:T("Default flavor") %></label>
|
||||
<%:Html.EditorFor(m => m.FlavorDefault)%>
|
||||
<%:Html.ValidationMessageFor(m => m.FlavorDefault)%>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label for="<%:Html.FieldIdFor(m => m.FlavorDefault) %>"><%:T("Default flavor") %></label>
|
||||
<%:Html.EditorFor(m => m.FlavorDefault)%>
|
||||
<%:Html.ValidationMessageFor(m => m.FlavorDefault)%>
|
||||
</fieldset>
|
@@ -1,6 +1,6 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Common.Settings.BodyTypePartSettings>" %>
|
||||
<fieldset>
|
||||
<label for="<%:Html.FieldIdFor(m => m.Flavor) %>"><%:T("Flavor") %></label>
|
||||
<%:Html.EditorFor(m => m.Flavor) %>
|
||||
<%:Html.ValidationMessageFor(m => m.Flavor) %>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label for="<%:Html.FieldIdFor(m => m.Flavor) %>"><%:T("Flavor") %></label>
|
||||
<%:Html.EditorFor(m => m.Flavor) %>
|
||||
<%:Html.ValidationMessageFor(m => m.Flavor) %>
|
||||
</fieldset>
|
@@ -1,6 +1,5 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Common.Fields.TextField>" %>
|
||||
<fieldset>
|
||||
<label for="<%:Html.FieldIdFor(m=>m.Value) %>"><%:Model.Name %></label>
|
||||
<%: Html.EditorFor(m=>m.Value) %>
|
||||
<%: Html.ValidationMessageFor(m=>m.Value) %>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label for="<%:Html.FieldIdFor(m=>m.Value) %>"><%:Model.Name %></label>
|
||||
<%:Html.EditorFor(m=>m.Value) %><%:Html.ValidationMessageFor(m=>m.Value) %>
|
||||
</fieldset>
|
@@ -238,6 +238,46 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
return RedirectToAction("Edit", new {id});
|
||||
}
|
||||
|
||||
public ActionResult RemovePartFrom(string id) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content type.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var contentTypeDefinition = _contentDefinitionService.GetTypeDefinition(id);
|
||||
|
||||
var viewModel = new RemovePartViewModel();
|
||||
if (contentTypeDefinition == null
|
||||
|| !TryUpdateModel(viewModel)
|
||||
|| !contentTypeDefinition.Parts.Any(p => p.PartDefinition.Name == viewModel.Name))
|
||||
return new NotFoundResult();
|
||||
|
||||
viewModel.Type = new EditTypeViewModel { Name = contentTypeDefinition.Name, DisplayName = contentTypeDefinition.DisplayName };
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("RemovePartFrom")]
|
||||
public ActionResult RemovePartFromPOST(string id) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to edit a content type.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var contentTypeDefinition = _contentDefinitionService.GetTypeDefinition(id);
|
||||
|
||||
var viewModel = new RemovePartViewModel();
|
||||
if (contentTypeDefinition == null
|
||||
|| !TryUpdateModel(viewModel)
|
||||
|| !contentTypeDefinition.Parts.Any(p => p.PartDefinition.Name == viewModel.Name))
|
||||
return new NotFoundResult();
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
viewModel.Type = new EditTypeViewModel { Name = contentTypeDefinition.Name, DisplayName = contentTypeDefinition.DisplayName };
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
_contentDefinitionManager.AlterTypeDefinition(id, typeBuilder => typeBuilder.RemovePart(viewModel.Name));
|
||||
Services.Notifier.Information(T("The \"{0}\" part has been removed.", viewModel.Name));
|
||||
|
||||
return RedirectToAction("Edit", new {id});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Parts
|
||||
|
@@ -77,6 +77,7 @@
|
||||
<Compile Include="Services\ContentDefinitionService.cs" />
|
||||
<Compile Include="Services\IContentDefinitionService.cs" />
|
||||
<Compile Include="ViewModels\AddFieldViewModel.cs" />
|
||||
<Compile Include="ViewModels\RemovePartViewModel.cs" />
|
||||
<Compile Include="ViewModels\CreateTypeViewModel.cs" />
|
||||
<Compile Include="ViewModels\EditTypeViewModel.cs" />
|
||||
<Compile Include="ViewModels\ListContentsViewModel.cs" />
|
||||
@@ -87,6 +88,7 @@
|
||||
<Content Include="Styles\admin.css" />
|
||||
<Content Include="Views\Admin\AddFieldTo.ascx" />
|
||||
<Content Include="Views\Admin\AddPartsTo.ascx" />
|
||||
<Content Include="Views\Admin\RemovePartFrom.ascx" />
|
||||
<Content Include="Views\Admin\Create.ascx" />
|
||||
<Content Include="Views\Admin\EditPart.ascx" />
|
||||
<Content Include="Views\Admin\Edit.ascx" />
|
||||
|
@@ -32,11 +32,11 @@ namespace Orchard.ContentTypes.ViewModels {
|
||||
|
||||
return implicitTypePart == null
|
||||
? Enumerable.Empty<EditPartFieldViewModel>()
|
||||
: implicitTypePart.PartDefinition.Fields.Select(f => new EditPartFieldViewModel(f));
|
||||
: implicitTypePart.PartDefinition.Fields.Select(f => new EditPartFieldViewModel(f) { Part = new EditPartViewModel(implicitTypePart.PartDefinition) });
|
||||
}
|
||||
|
||||
private IEnumerable<EditTypePartViewModel> GetTypeParts(ContentTypeDefinition contentTypeDefinition) {
|
||||
return contentTypeDefinition.Parts.Where(p => p.PartDefinition.Name != Name).Select(p => new EditTypePartViewModel(p));
|
||||
return contentTypeDefinition.Parts.Where(p => p.PartDefinition.Name != Name).Select(p => new EditTypePartViewModel(p) { Type = this });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace Orchard.ContentTypes.ViewModels {
|
||||
Settings = part.Settings;
|
||||
}
|
||||
|
||||
public EditTypeViewModel Type { get; set; }
|
||||
public EditPartViewModel PartDefinition { get; set; }
|
||||
public SettingsDictionary Settings { get; set; }
|
||||
public IEnumerable<TemplateViewModel> Templates { get; set; }
|
||||
@@ -61,7 +62,7 @@ namespace Orchard.ContentTypes.ViewModels {
|
||||
}
|
||||
public EditPartViewModel(ContentPartDefinition contentPartDefinition) {
|
||||
Name = contentPartDefinition.Name;
|
||||
Fields = contentPartDefinition.Fields.Select(f => new EditPartFieldViewModel(f));
|
||||
Fields = contentPartDefinition.Fields.Select(f => new EditPartFieldViewModel(f) { Part = this });
|
||||
Settings = contentPartDefinition.Settings;
|
||||
}
|
||||
|
||||
@@ -81,6 +82,7 @@ namespace Orchard.ContentTypes.ViewModels {
|
||||
Settings = field.Settings;
|
||||
}
|
||||
|
||||
public EditPartViewModel Part { get; set; }
|
||||
public string Name { get; set; }
|
||||
public IEnumerable<TemplateViewModel> Templates { get; set; }
|
||||
public EditFieldViewModel FieldDefinition { get; set; }
|
||||
|
@@ -0,0 +1,8 @@
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.ContentTypes.ViewModels {
|
||||
public class RemovePartViewModel : BaseViewModel {
|
||||
public string Name { get; set; }
|
||||
public EditTypeViewModel Type { get; set; }
|
||||
}
|
||||
}
|
@@ -1,25 +1,30 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.EditTypeViewModel>" %>
|
||||
<% Html.RegisterStyle("admin.css"); %>
|
||||
<h1><%:Html.TitleForPage(T("Edit Content Type").ToString())%></h1>
|
||||
<% Html.RegisterStyle("admin.css");
|
||||
%><h1><%:Html.TitleForPage(T("Edit Content Type").ToString())%></h1>
|
||||
<p class="breadcrumb"><%:Html.ActionLink(T("Content Types").Text, "index") %><%:T(" > ") %><%:T("Edit Content Type") %></p><%
|
||||
using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<%:Html.ValidationSummary() %>
|
||||
<%--//todo: come up with real itemtype definitions and locations for said definitions--%>
|
||||
<div itemscope itemid="<%:Model.Name %>" itemtype="http://orchardproject.net/data/ContentType"><%:Html.ValidationSummary() %>
|
||||
<fieldset>
|
||||
<label for="DisplayName"><%:T("Display Name") %></label>
|
||||
<%:Html.TextBoxFor(m => m.DisplayName, new {@class = "textMedium"}) %>
|
||||
<%--// has unintended consequences (renamging the type) - changing the name creates a new type of that name--%>
|
||||
<label for="Name"><%:T("Name") %></label>
|
||||
<%:Html.TextBoxFor(m => m.Name, new {@class = "textMedium", disabled = "disabled"}) %>
|
||||
<%:Html.TextBoxFor(m => m.DisplayName, new { @class = "textMedium" })%>
|
||||
<%--// todo: if we continue to go down the midrodata route, some helpers would be nice--%>
|
||||
<meta itemprop="DisplayName" content="<%:Model.DisplayName %>" /><%--
|
||||
// has unintended consequences (renamging the type) - changing the name creates a new type of that name--%>
|
||||
<label for="Name" itemprop="name"><%:T("Name") %></label>
|
||||
<%:Html.TextBoxFor(m => m.Name, new { @class = "textMedium", disabled = "disabled" })%>
|
||||
<meta itemprop="Name" content="<%:Model.Name %>" />
|
||||
<%:Html.HiddenFor(m => m.Name) %>
|
||||
</fieldset>
|
||||
<% Html.RenderTemplates(Model.Templates); %>
|
||||
</fieldset><%
|
||||
Html.RenderTemplates(Model.Templates); %>
|
||||
<h2><%:T("Parts") %></h2>
|
||||
<div class="manage add-to-type"><%: Html.ActionLink(T("Add").Text, "AddPartsTo", new { area = "Orchard.ContentTypes", id = Model.Name }, new { @class = "button" })%></div>
|
||||
<%:Html.EditorFor(m => m.Parts, "Parts", "") %>
|
||||
<div class="manage add-to-type"><%: Html.ActionLink(T("Add").Text, "AddPartsTo", new { area = "Orchard.ContentTypes", id = Model.Name }, new { @class = "button" })%></div><%:
|
||||
Html.EditorFor(m => m.Parts, "Parts", "") %>
|
||||
<h2><%:T("Fields") %></h2>
|
||||
<div class="manage add-to-type"><%: Html.ActionLink(T("Add").Text, "AddFieldTo", new { area = "Orchard.ContentTypes", id = Model.Name }, new { @class = "button" }) %></div>
|
||||
<%:Html.EditorFor(m => m.Fields, "Fields", "") %>
|
||||
<div class="manage add-to-type"><%: Html.ActionLink(T("Add").Text, "AddFieldTo", new { area = "Orchard.ContentTypes", id = Model.Name }, new { @class = "button" }) %></div><%:
|
||||
Html.EditorFor(m => m.Fields, "Fields", "") %>
|
||||
<fieldset>
|
||||
<button class="primaryAction" type="submit"><%:T("Save") %></button>
|
||||
</fieldset><%
|
||||
</fieldset>
|
||||
</div><%
|
||||
} %>
|
@@ -0,0 +1,11 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.RemovePartViewModel>" %>
|
||||
<%
|
||||
Html.RegisterStyle("admin.css"); %>
|
||||
<h1><%:Html.TitleForPage(T("Remove the \"{0}\" part from \"{1}\"", Model.Name, Model.Type.DisplayName).ToString())%></h1><%
|
||||
using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<p><%:T("Looks like you couldn't use the fancy way to remove the part. Try hitting the button below to force the issue.") %></p>
|
||||
<fieldset>
|
||||
<%=Html.HiddenFor(m => m.Name) %>
|
||||
<button class="primaryAction" type="submit"><%:T("Remove") %></button>
|
||||
</fieldset><%
|
||||
} %>
|
@@ -1,8 +1,11 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<SettingsDictionary>" %>
|
||||
<%@ import Namespace="Orchard.ContentManagement.MetaData.Models" %>
|
||||
<dl><%
|
||||
foreach (var setting in Model) { %>
|
||||
<dt><%:setting.Key %></dt>
|
||||
<dd><%:setting.Value %></dd><%
|
||||
} %>
|
||||
</dl>
|
||||
<%
|
||||
if (Model.Any()) { %>
|
||||
<dl><%
|
||||
foreach (var setting in Model) { %>
|
||||
<dt><%:setting.Key %></dt>
|
||||
<dd><%:setting.Value %></dd><%
|
||||
} %>
|
||||
</dl><%
|
||||
} %>
|
@@ -2,15 +2,8 @@
|
||||
<fieldset class="manage-field">
|
||||
<h3><%:Model.Name %> <span>(<%:Model.FieldDefinition.Name %>)</span></h3>
|
||||
<div class="manage">
|
||||
<%--// these inline forms can't be here. should probably have some JavaScript in here to build up the forms and add the "remove" link.
|
||||
// get the antiforgery token from the edit type form and mark up the part in a semantic way so I can get some info from the DOM --%>
|
||||
<%:Html.Link("[remove]", "#forshowonlyandnotintendedtowork!") %>
|
||||
<%-- <% using (Html.BeginFormAntiForgeryPost(Url.Action("RemovePart", new { area = "Orchard.ContentTypes" }), FormMethod.Post, new {@class = "inline link"})) { %>
|
||||
<%:Html.Hidden("name", Model.PartDefinition.Name, new { id = "" }) %>
|
||||
<button type="submit" title="<%:T("Remove") %>"><%:T("Remove") %></button>
|
||||
<% } %> --%>
|
||||
</div>
|
||||
<% Html.RenderTemplates(Model.Templates); %>
|
||||
<%:Html.HiddenFor(m => m.Name) %>
|
||||
<%:Html.HiddenFor(m => m.FieldDefinition.Name) %>
|
||||
</div><%
|
||||
Html.RenderTemplates(Model.Templates); %>
|
||||
<%:Html.HiddenFor(m => m.Name) %><%:Html.HiddenFor(m => m.FieldDefinition.Name) %>
|
||||
</fieldset>
|
@@ -1,20 +1,13 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.EditTypePartViewModel>" %>
|
||||
<fieldset class="manage-part">
|
||||
<h3><%:Model.PartDefinition.Name %></h3>
|
||||
<fieldset class="manage-part" itemscope itemid="<%:Model.PartDefinition.Name %>" itemtype="http://orchardproject.net/data/ContentTypePart">
|
||||
<h3 itemprop="Name"><%:Model.PartDefinition.Name %></h3>
|
||||
<div class="manage">
|
||||
<%--// these inline forms can't be here. should probably have some JavaScript in here to build up the forms and add the "remove" link.
|
||||
// get the antiforgery token from the edit type form and mark up the part in a semantic way so I can get some info from the DOM --%>
|
||||
<%:Html.Link("[remove]", "#forshowonlyandnotintendedtowork") %>
|
||||
<%-- <% using (Html.BeginFormAntiForgeryPost(Url.Action("RemovePart", new { area = "Contents" }), FormMethod.Post, new {@class = "inline link"})) { %>
|
||||
<%:Html.Hidden("name", Model.PartDefinition.Name, new { id = "" }) %>
|
||||
<button type="submit" title="<%:T("Remove") %>"><%:T("Remove") %></button>
|
||||
<% } %> --%>
|
||||
</div>
|
||||
<% Html.RenderTemplates(Model.Templates); %>
|
||||
|
||||
<%:Html.ActionLink(T("Remove").Text, "RemovePartFrom", new { area = "Orchard.ContentTypes", id = Model.Type.Name, Model.PartDefinition.Name }, new { itemprop = "RemoveUrl UnsafeUrl" })%><%--// <- some experimentation--%>
|
||||
</div><%
|
||||
Html.RenderTemplates(Model.Templates); %>
|
||||
<h4><%:T("Global configuration") %></h4>
|
||||
<div class="manage minor"><%:Html.ActionLink(T("Edit").Text, "EditPart", new { area = "Orchard.ContentTypes", id = Model.PartDefinition.Name }) %></div>
|
||||
<%:Html.DisplayFor(m => m.PartDefinition.Settings, "Settings", "PartDefinition") %>
|
||||
<%:Html.EditorFor(m => m.PartDefinition.Fields, "Fields", "PartDefinition") %>
|
||||
<%:Html.Hidden("PartDefinition.Name", Model.PartDefinition.Name) %>
|
||||
<%:Html.DisplayFor(m => m.PartDefinition.Settings, "Settings", "PartDefinition")
|
||||
%><%:Html.EditorFor(m => m.PartDefinition.Fields, "Fields", "PartDefinition")
|
||||
%><%:Html.Hidden("PartDefinition.Name", Model.PartDefinition.Name) %>
|
||||
</fieldset>
|
@@ -1,5 +1,6 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<SettingsDictionary>" %>
|
||||
<%@ import Namespace="Orchard.ContentManagement.MetaData.Models" %><%
|
||||
<%@ import Namespace="Orchard.ContentManagement.MetaData.Models" %>
|
||||
<%
|
||||
if (Model.Any()) { %>
|
||||
<fieldset><%
|
||||
var si = 0;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Indexing.Settings.FieldIndexing>" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html" %>
|
||||
<fieldset>
|
||||
<%:Html.EditorFor(m=>m.Included) %>
|
||||
<label for="<%:Html.FieldIdFor(m => m.Included) %>" class="forcheckbox"><%:T("Include in the index") %></label>
|
||||
<%:Html.ValidationMessageFor(m => m.Included)%>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<%:Html.EditorFor(m=>m.Included) %>
|
||||
<label for="<%:Html.FieldIdFor(m => m.Included) %>" class="forcheckbox"><%:T("Include in the index") %></label><%:
|
||||
Html.ValidationMessageFor(m => m.Included)%>
|
||||
</fieldset>
|
@@ -1,7 +1,7 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Indexing.Settings.TypeIndexing>" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html" %>
|
||||
<fieldset>
|
||||
<%:Html.EditorFor(m=>m.Included) %>
|
||||
<label for="<%:Html.FieldIdFor(m => m.Included) %>" class="forcheckbox"><%:T("Index this content type for search") %></label>
|
||||
<%:Html.ValidationMessageFor(m=>m.Included) %>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<%:Html.EditorFor(m=>m.Included) %>
|
||||
<label for="<%:Html.FieldIdFor(m => m.Included) %>" class="forcheckbox"><%:T("Index this content type for search") %></label><%:
|
||||
Html.ValidationMessageFor(m=>m.Included) %>
|
||||
</fieldset>
|
@@ -15,7 +15,7 @@
|
||||
<p><%: module.Description %></p><%
|
||||
} %>
|
||||
<ul class="pageStatus" style="color:#666; margin:.6em 0 0 0;">
|
||||
<li><%: T("Features: {0}", string.Join(", ", module.Features.Select(f => Html.Link(f.Name, string.Format("{0}#{1}", Url.Action("features", new { area = "Orchard.Modules" }), f.Name.AsFeatureId(n => T(n)))).ToString()).OrderBy(s => s).ToArray())) %></li>
|
||||
<li><%:T("Features: {0}", MvcHtmlString.Create(string.Join(", ", module.Features.Select(f => Html.Link(f.Name, string.Format("{0}#{1}", Url.Action("features", new { area = "Orchard.Modules" }), f.Name.AsFeatureId(n => T(n)))).ToString()).OrderBy(s => s).ToArray()))) %></li>
|
||||
<li> | <%: T("Author: {0}", !string.IsNullOrEmpty(module.Author) ? module.Author : (new []{"Bradley", "Bertrand", "Renaud", "Suha", "Sebastien", "Jon", "Nathan", "Erik"})[(module.DisplayName.Length + (new Random()).Next()) % 7]) %></li><%-- very efficient, I know --%>
|
||||
<li> | <%: T("Website: {0}", !string.IsNullOrEmpty(module.HomePage) ? module.HomePage : T("<a href=\"http://orchardproject.net\">http://orchardproject.net</a>").ToString())%></li>
|
||||
</ul>
|
||||
|
@@ -1,69 +1,92 @@
|
||||
(function($){
|
||||
//todo: (heskew) make use of the autofocus attribute instead
|
||||
$.fn.extend({
|
||||
helpfullyFocus: function() {
|
||||
var _this = $(this);
|
||||
var firstError = _this.find(".input-validation-error").first();
|
||||
// try to focus the first error on the page
|
||||
if (firstError.size() === 1) {
|
||||
return firstError.focus();
|
||||
}
|
||||
// or, give it up to the browser to autofocus
|
||||
if ('autofocus' in document.createElement('input')) {
|
||||
return;
|
||||
}
|
||||
// otherwise, make the autofocus attribute work
|
||||
var autofocus = _this.find(":input[autofocus=autofocus]").first();
|
||||
return autofocus.focus();
|
||||
},
|
||||
toggleWhatYouControl: function() {
|
||||
var _this = $(this);
|
||||
var _controllees = $("[data-controllerid=" + _this.attr("id") + "]");
|
||||
var _controlleesAreHidden = _controllees.is(":hidden");
|
||||
if (_this.is(":checked") && _controlleesAreHidden) {
|
||||
_controllees.hide(); // <- unhook this when the following comment applies
|
||||
$(_controllees.show()[0]).find("input").focus(); // <- aaaand a slideDown there...eventually
|
||||
} else if (!(_this.is(":checked") && _controlleesAreHidden)) {
|
||||
//_controllees.slideUp(200); <- hook this back up when chrome behaves, or when I care less
|
||||
_controllees.hide()
|
||||
}
|
||||
}
|
||||
});
|
||||
// collapsable areas - anything with a data-controllerid attribute has its visibility controlled by the id-ed radio/checkbox
|
||||
(function() {
|
||||
$("[data-controllerid]").each(function() {
|
||||
var controller = $("#" + $(this).attr("data-controllerid"));
|
||||
if (controller.data("isControlling")) {
|
||||
return;
|
||||
}
|
||||
controller.data("isControlling", 1);
|
||||
if (!controller.is(":checked")) {
|
||||
$("[data-controllerid=" + controller.attr("id") + "]").hide();
|
||||
}
|
||||
if (controller.is(":checkbox")) {
|
||||
controller.click($(this).toggleWhatYouControl);
|
||||
} else if (controller.is(":radio")) {
|
||||
$("[name=" + controller.attr("name") + "]").click(function() { $("[name=" + $(this).attr("name") + "]").each($(this).toggleWhatYouControl); });
|
||||
(function ($) {
|
||||
//todo: (heskew) make use of the autofocus attribute instead
|
||||
$.fn.extend({
|
||||
helpfullyFocus: function () {
|
||||
var _this = $(this);
|
||||
var firstError = _this.find(".input-validation-error").first();
|
||||
// try to focus the first error on the page
|
||||
if (firstError.size() === 1) {
|
||||
return firstError.focus();
|
||||
}
|
||||
// or, give it up to the browser to autofocus
|
||||
if ('autofocus' in document.createElement('input')) {
|
||||
return;
|
||||
}
|
||||
// otherwise, make the autofocus attribute work
|
||||
var autofocus = _this.find(":input[autofocus=autofocus]").first();
|
||||
return autofocus.focus();
|
||||
},
|
||||
toggleWhatYouControl: function () {
|
||||
var _this = $(this);
|
||||
var _controllees = $("[data-controllerid=" + _this.attr("id") + "]");
|
||||
var _controlleesAreHidden = _controllees.is(":hidden");
|
||||
if (_this.is(":checked") && _controlleesAreHidden) {
|
||||
_controllees.hide(); // <- unhook this when the following comment applies
|
||||
$(_controllees.show()[0]).find("input").focus(); // <- aaaand a slideDown there...eventually
|
||||
} else if (!(_this.is(":checked") && _controlleesAreHidden)) {
|
||||
//_controllees.slideUp(200); <- hook this back up when chrome behaves, or when I care less
|
||||
_controllees.hide()
|
||||
}
|
||||
}
|
||||
});
|
||||
})();
|
||||
// inline form link buttons (form.inline.link button) swapped out for a link that submits said form
|
||||
(function() {
|
||||
$("form.inline.link").each(function() {
|
||||
var _this = $(this);
|
||||
var link = $("<a class='wasFormInlineLink' href='.'/>");
|
||||
var button = _this.children("button").first();
|
||||
link.text(button.text())
|
||||
// collapsable areas - anything with a data-controllerid attribute has its visibility controlled by the id-ed radio/checkbox
|
||||
(function () {
|
||||
$("[data-controllerid]").each(function () {
|
||||
var controller = $("#" + $(this).attr("data-controllerid"));
|
||||
if (controller.data("isControlling")) {
|
||||
return;
|
||||
}
|
||||
controller.data("isControlling", 1);
|
||||
if (!controller.is(":checked")) {
|
||||
$("[data-controllerid=" + controller.attr("id") + "]").hide();
|
||||
}
|
||||
if (controller.is(":checkbox")) {
|
||||
controller.click($(this).toggleWhatYouControl);
|
||||
} else if (controller.is(":radio")) {
|
||||
$("[name=" + controller.attr("name") + "]").click(function () { $("[name=" + $(this).attr("name") + "]").each($(this).toggleWhatYouControl); });
|
||||
}
|
||||
});
|
||||
})();
|
||||
// inline form link buttons (form.inline.link button) swapped out for a link that submits said form
|
||||
(function () {
|
||||
$("form.inline.link").each(function () {
|
||||
var _this = $(this);
|
||||
var link = $("<a class='wasFormInlineLink' href='.'/>");
|
||||
var button = _this.children("button").first();
|
||||
link.text(button.text())
|
||||
.addClass(button.attr("class"))
|
||||
.click(function() { _this.submit(); return false; })
|
||||
.unload(function() { _this = 0; });
|
||||
_this.replaceWith(link);
|
||||
_this.css({ "position": "absolute", "left": "-9999em" });
|
||||
$("body").append(_this);
|
||||
.click(function () { _this.submit(); return false; })
|
||||
.unload(function () { _this = 0; });
|
||||
_this.replaceWith(link);
|
||||
_this.css({ "position": "absolute", "left": "-9999em" });
|
||||
$("body").append(_this);
|
||||
});
|
||||
})();
|
||||
// a little better autofocus
|
||||
$(function () {
|
||||
$("body").helpfullyFocus();
|
||||
});
|
||||
// UnsafeUrl links -> form POST
|
||||
//todo: need some real microdata support eventually (incl. revisiting usage of data-* attributes)
|
||||
$(function () {
|
||||
var magicToken = $("input[name=__RequestVerificationToken]");
|
||||
if (!magicToken) { return; } // no sense in continuing if form POSTS will fail
|
||||
$("a[itemprop~=UnsafeUrl]").each(function () {
|
||||
var _this = $(this);
|
||||
var hrefParts = _this.attr("href").split("?");
|
||||
var form = $("<form action=\"" + hrefParts[0] + "\" method=\"POST\" />");
|
||||
form.append(magicToken.clone());
|
||||
if (hrefParts.length > 1) {
|
||||
var queryParts = hrefParts[1].split("&");
|
||||
for (var i = 0; i < queryParts.length; i++) {
|
||||
var queryPartKVP = queryParts[i].split("=");
|
||||
//trusting hrefs in the page here
|
||||
form.append($("<input type=\"hidden\" name=\"" + queryPartKVP[0] + "\" value=\"" + queryPartKVP[1] + "\" />"));
|
||||
}
|
||||
}
|
||||
form.css({ "position": "absolute", "left": "-9999em" });
|
||||
$("body").append(form);
|
||||
_this.click(function () { form.submit(); return false; });
|
||||
});
|
||||
});
|
||||
})();
|
||||
// a little better autofocus
|
||||
$(function() {
|
||||
$("body").helpfullyFocus();
|
||||
});
|
||||
})(jQuery);
|
Reference in New Issue
Block a user