Skip to content

Commit 6aea1bf

Browse files
authored
[DI-1132] Prevent editing IsDeleteOperation after save (#49)
* Prevent editing IsDeleteOperation after save * Hidden input for IsDeleteOperation on edit * Remove hidden input with duplicate Id * Fix jquery
1 parent 8ac5a9e commit 6aea1bf

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

DataImport.Web/Features/DataMaps/AddEdit.cshtml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ See the LICENSE and NOTICES files in the project root for more information.
104104
@Html.HiddenFor(m => m.ApiVersionId)
105105
@Html.Display(m => m.ApiVersion)
106106
@Html.Display(m => m.ResourceName)
107-
@Html.HiddenFor(m => m.ResourcePath)
107+
@Html.HiddenFor(m => m.ResourcePath)
108+
@Html.HiddenFor(m => m.IsDeleteOperation)
108109
}
109110

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

130-
@Html.Input(m => m.IsDeleteOperation)
131+
if (ControllerAction(Context.Request.RouteValues) == "Add" || Model.IsDeleteOperation)
132+
{
133+
@Html.Input(m => m.IsDeleteOperation, ControllerAction(Context.Request.RouteValues) == "Edit")
134+
}
135+
else
136+
{
137+
<div class = "form-group">
138+
<div class="col-sm-offset-2 col-sm-10">
139+
<label>This is an INSERT/UPDATE map</label>
140+
</div>
141+
</div>
142+
}
131143

132144
<fieldset>
133145
<div id="attributeContainer" style="display:none;">
@@ -293,7 +305,7 @@ See the LICENSE and NOTICES files in the project root for more information.
293305
294306
var $apiVersionIdElem = $('#@Html.IdFor(m => m.ApiVersionId)');
295307
var $resourcePathElem = $('#@Html.IdFor(m => m.ResourcePath)');
296-
var $isDeleteOperationElem = $('#@Html.IdFor(m => m.IsDeleteOperation)');
308+
var $isDeleteOperationElem = $('input:checkbox, #@Html.IdFor(m => m.IsDeleteOperation)');
297309
298310
refreshResourcePathVisibility();
299311
refreshAllControlVisibility();
@@ -373,7 +385,7 @@ See the LICENSE and NOTICES files in the project root for more information.
373385
{
374386
@: var resourcePath = emptyToNull($("#ResourcePath").val());
375387
}
376-
388+
377389
var dataObject = {
378390
apiVersionId: $apiVersionIdElem.val(),
379391
dataMapId: $('#@Html.IdFor(m => m.DataMapId)').val(),
@@ -382,7 +394,7 @@ See the LICENSE and NOTICES files in the project root for more information.
382394
mappings: mappingJson,
383395
preprocessorId: $('#@Html.IdFor(m => m.PreprocessorId)').val(),
384396
attribute: $('#@Html.IdFor(m => m.Attribute)').val(),
385-
isDeleteOperation: $('#@Html.IdFor(m => m.IsDeleteOperation)').is(":checked"),
397+
isDeleteOperation: $('input:checkbox, #@Html.IdFor(m => m.IsDeleteOperation)').is(":checked"),
386398
columnHeaders: JSON.parse($('#@Html.IdFor(m => m.ColumnHeaders)').val())
387399
};
388400
$.ajax({
@@ -410,6 +422,10 @@ See the LICENSE and NOTICES files in the project root for more information.
410422
411423
$isDeleteOperationElem.change(function() {
412424
$('#delete-operation-warning').toggleClass('hidden', $isDeleteOperationElem.is(":checked")===false)
425+
clearColumnsMetadata();
426+
clearDataMapping();
427+
invalidateAPIConnectionVisibility();
428+
refreshAttributeVisibility();
413429
});
414430
415431
$apiVersionIdElem.change(function() {
@@ -606,6 +622,7 @@ See the LICENSE and NOTICES files in the project root for more information.
606622
607623
function clearDataMapping() {
608624
$('#divModelFields').html('');
625+
$('#divCSVFields').html('');
609626
refreshAllControlVisibility();
610627
$('#btnSubmit').hide();
611628
}

DataImport.Web/Infrastructure/HtmlHelperExtensions.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,22 @@ public static HtmlString ReadOnlyInput<TModel, TValue>(this IHtmlHelper<TModel>
9393
return div.ToHtmlString();
9494
}
9595

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

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

104-
inputDiv.InnerHtml.AppendHtml(html.CheckBoxFor(expression));
104+
if (isDisabled)
105+
{
106+
inputDiv.InnerHtml.AppendHtml(html.CheckBoxFor(expression, new { disabled = "disabled"}));
107+
}
108+
else
109+
{
110+
inputDiv.InnerHtml.AppendHtml(html.CheckBoxFor(expression));
111+
}
105112
inputDiv.InnerHtml.AppendHtml(" ");
106113
inputDiv.InnerHtml.AppendHtml(html.LabelFor(expression));
107114

0 commit comments

Comments
 (0)