Skip to content

Commit

Permalink
[DI-1132] Prevent editing IsDeleteOperation after save (#49)
Browse files Browse the repository at this point in the history
* Prevent editing IsDeleteOperation after save

* Hidden input for IsDeleteOperation on edit

* Remove hidden input with duplicate Id

* Fix jquery
  • Loading branch information
simpat-adam authored Dec 12, 2023
1 parent 8ac5a9e commit 6aea1bf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
27 changes: 22 additions & 5 deletions DataImport.Web/Features/DataMaps/AddEdit.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ See the LICENSE and NOTICES files in the project root for more information.
@Html.HiddenFor(m => m.ApiVersionId)
@Html.Display(m => m.ApiVersion)
@Html.Display(m => m.ResourceName)
@Html.HiddenFor(m => m.ResourcePath)
@Html.HiddenFor(m => m.ResourcePath)
@Html.HiddenFor(m => m.IsDeleteOperation)
}

<div class="form-group">
Expand All @@ -127,7 +128,18 @@ See the LICENSE and NOTICES files in the project root for more information.
</div>
</div>

@Html.Input(m => m.IsDeleteOperation)
if (ControllerAction(Context.Request.RouteValues) == "Add" || Model.IsDeleteOperation)
{
@Html.Input(m => m.IsDeleteOperation, ControllerAction(Context.Request.RouteValues) == "Edit")
}
else
{
<div class = "form-group">
<div class="col-sm-offset-2 col-sm-10">
<label>This is an INSERT/UPDATE map</label>
</div>
</div>
}

<fieldset>
<div id="attributeContainer" style="display:none;">
Expand Down Expand Up @@ -293,7 +305,7 @@ See the LICENSE and NOTICES files in the project root for more information.
var $apiVersionIdElem = $('#@Html.IdFor(m => m.ApiVersionId)');
var $resourcePathElem = $('#@Html.IdFor(m => m.ResourcePath)');
var $isDeleteOperationElem = $('#@Html.IdFor(m => m.IsDeleteOperation)');
var $isDeleteOperationElem = $('input:checkbox, #@Html.IdFor(m => m.IsDeleteOperation)');
refreshResourcePathVisibility();
refreshAllControlVisibility();
Expand Down Expand Up @@ -373,7 +385,7 @@ See the LICENSE and NOTICES files in the project root for more information.
{
@: var resourcePath = emptyToNull($("#ResourcePath").val());
}
var dataObject = {
apiVersionId: $apiVersionIdElem.val(),
dataMapId: $('#@Html.IdFor(m => m.DataMapId)').val(),
Expand All @@ -382,7 +394,7 @@ See the LICENSE and NOTICES files in the project root for more information.
mappings: mappingJson,
preprocessorId: $('#@Html.IdFor(m => m.PreprocessorId)').val(),
attribute: $('#@Html.IdFor(m => m.Attribute)').val(),
isDeleteOperation: $('#@Html.IdFor(m => m.IsDeleteOperation)').is(":checked"),
isDeleteOperation: $('input:checkbox, #@Html.IdFor(m => m.IsDeleteOperation)').is(":checked"),
columnHeaders: JSON.parse($('#@Html.IdFor(m => m.ColumnHeaders)').val())
};
$.ajax({
Expand Down Expand Up @@ -410,6 +422,10 @@ See the LICENSE and NOTICES files in the project root for more information.
$isDeleteOperationElem.change(function() {
$('#delete-operation-warning').toggleClass('hidden', $isDeleteOperationElem.is(":checked")===false)
clearColumnsMetadata();
clearDataMapping();
invalidateAPIConnectionVisibility();
refreshAttributeVisibility();
});
$apiVersionIdElem.change(function() {
Expand Down Expand Up @@ -606,6 +622,7 @@ See the LICENSE and NOTICES files in the project root for more information.
function clearDataMapping() {
$('#divModelFields').html('');
$('#divCSVFields').html('');
refreshAllControlVisibility();
$('#btnSubmit').hide();
}
Expand Down
11 changes: 9 additions & 2 deletions DataImport.Web/Infrastructure/HtmlHelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,22 @@ public static HtmlString ReadOnlyInput<TModel, TValue>(this IHtmlHelper<TModel>
return div.ToHtmlString();
}

public static HtmlString Input<TModel>(this IHtmlHelper<TModel> html, Expression<Func<TModel, bool>> expression)
public static HtmlString Input<TModel>(this IHtmlHelper<TModel> html, Expression<Func<TModel, bool>> expression, bool isDisabled)
{
var input = new TagBuilder("div");
input.AddCssClass("form-group");

var inputDiv = new TagBuilder("div");
inputDiv.AddCssClass("col-sm-offset-2 col-sm-10");

inputDiv.InnerHtml.AppendHtml(html.CheckBoxFor(expression));
if (isDisabled)
{
inputDiv.InnerHtml.AppendHtml(html.CheckBoxFor(expression, new { disabled = "disabled"}));
}
else
{
inputDiv.InnerHtml.AppendHtml(html.CheckBoxFor(expression));
}
inputDiv.InnerHtml.AppendHtml(" ");
inputDiv.InnerHtml.AppendHtml(html.LabelFor(expression));

Expand Down

0 comments on commit 6aea1bf

Please sign in to comment.