This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static IEnumerable<T> Sort<T>(this IEnumerable<T> sortables) where T : IClientSortable | |
| { | |
| return sortables.EmptyIfNull() | |
| .OrderBy(i => i.ClientOrder); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IClientDeletable | |
| { | |
| bool ClientDeleted { get; set; } | |
| } | |
| public class DeletableThing : IClientDeletable | |
| { | |
| public string Text { get; set; } | |
| public int Number { get; set; } | |
| public bool IsEven { get; private set; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @model DgonDotNet.Blog.Samples.DynamicCollections.Models.DeletableThing | |
| <tr> | |
| <td> | |
| @Html.HiddenFor(m => m.ClientDeleted, new { @class = "data-delete" }) | |
| @Html.HiddenFor(m => m.Number) | |
| @Html.DisplayFor(m => m.Number) | |
| </td> | |
| <td> | |
| @Html.HiddenFor(m => m.Text) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DGON_DOTNET.ClientInteraction = | |
| { | |
| makeDeletable: function (tableSelector, options) { | |
| options = optionsWithDefaults(options, { | |
| deleteSelector: '.trash', | |
| deletedSelector: '.data-delete', | |
| }); | |
| $(tableSelector).delegate( | |
| options.deleteSelector, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [HttpPost] | |
| public override ActionResult Index(string save, string discard, DeleteViewModel posted) | |
| { | |
| if (isSave(save, discard)) | |
| { | |
| _repository.Save(DeletableThing.ToThings(posted.Things)); | |
| } | |
| IEnumerable<Thing> updatedThings = _repository.Find(); | |
| var model = new DeleteViewModel | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static IEnumerable<Thing> ToThings(DeletableThing[] from) | |
| { | |
| return from | |
| .NotDeleted() | |
| .Select(st => st.ToThing()); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static IEnumerable<T> NotDeleted<T>(this IEnumerable<T> deletables) where T : IClientDeletable | |
| { | |
| return deletables.EmptyIfNull() | |
| // ignore the ones deleted client-side | |
| .Where(i => !i.ClientDeleted); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function deleteRow(column, options) { | |
| $(column).parents('tr') | |
| .hide({ | |
| complete: function () { | |
| var $row = $(this); | |
| $row.find(options.deletedSelector).val(true); | |
| } | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class AddableThing | |
| { | |
| public AddableThing() { } | |
| public AddableThing(Thing from) | |
| { | |
| Number = from.Number; | |
| Text = from.Text; | |
| IsEven = (from.Number % 2) == 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @model DgonDotNet.Blog.Samples.DynamicCollections.Models.AddViewModel | |
| <script id="addable-template" type="text/x-handlebars-template"> | |
| <tr> | |
| <td> | |
| <div class="col-xs-4"> | |
| @(Html.Templated("{{NewIndex}}") | |
| .TextBox(m => m.Things[0].Number, string.Empty, new { @class = "form-control input-sm" })) | |
| </div> | |
| </td> |