Skip to content

Commit

Permalink
Widget improvements - validation and cancel save
Browse files Browse the repository at this point in the history
  • Loading branch information
rxtur committed Feb 12, 2016
1 parent f764445 commit 6765d93
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
31 changes: 20 additions & 11 deletions BlogEngine/BlogEngine.NET/Custom/Widgets/Post List/edit.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,24 @@

var widgetId = Request.QueryString["id"];
var settings = WidgetHelper.GetSettings(widgetId);

Validation.Add("txtNumberOfPosts",
Validator.Required("Field is required"),
Validator.Integer("Field is numeric")
);
if (IsPost)
{
settings["numberofposts"] = Request.Form["txtNumberOfPosts"];
settings["cutegory"] = Request.Form["ddlCategories"];
settings["author"] = Request.Form["ddlAuthors"];
settings["sortorder"] = Request.Form["ddlSortBy"];
settings["showimg"] = Request.Form["cbShowImg"] == "on" ? "true" : "false";
settings["showdesc"] = Request.Form["cbShowDesc"] == "on" ? "true" : "false";
settings["showdate"] = Request.Form["cbShowDate"] == "on" ? "true" : "false";
WidgetHelper.SaveSettings(settings, widgetId);
if (Validation.IsValid())
{
settings["numberofposts"] = Request.Form["txtNumberOfPosts"];
settings["cutegory"] = Request.Form["ddlCategories"];
settings["author"] = Request.Form["ddlAuthors"];
settings["sortorder"] = Request.Form["ddlSortBy"];
settings["showimg"] = Request.Form["cbShowImg"] == "on" ? "true" : "false";
settings["showdesc"] = Request.Form["cbShowDesc"] == "on" ? "true" : "false";
settings["showdate"] = Request.Form["cbShowDate"] == "on" ? "true" : "false";
WidgetHelper.SaveSettings(settings, widgetId);
@:<script type="text/javascript">window.parent.toastr.success("Completed");</script>
}
}
if (settings != null && settings.Count > 0)
{
Expand Down Expand Up @@ -59,11 +66,13 @@
<link rel="stylesheet" href="~/admin/themes/standard/css/styles.css">
<style>
body { background-color: #fff; }
.field-validation-error { background-color: #d9534f; border-color: #d9534f; color: #fff; padding: 5px 15px; display: block; }
</style>
<form method="post">
<form method="post" onsubmit="window.parent.updateTitle()">
<div class="form-group">
<label for="txtNumberOfPosts">@Resources.labels.numberOfPosts</label>
@Html.TextBox("txtNumberOfPosts", numberOfPosts, new { @class = "form-control" })
@Html.ValidationMessage("txtNumberOfPosts")
</div>
<div class="form-group">
<label for="ddlCategories">@Resources.labels.category</label>
Expand Down Expand Up @@ -93,7 +102,7 @@
</label>
</div>
<div>
<button type="submit" onclick="window.parent.updateTitle()" class="btn btn-success btn-sm pull-left">
<button type="submit" class="btn btn-success btn-sm pull-left">
@Resources.labels.save
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
</style>
</head>
<body>
<form method="post">
<form method="post" onsubmit="window.parent.updateTitle()">
<div class="form-group">
<label>@Resources.labels.numberOfComments</label>
<input type="text" class="form-control" id="txtNumberOfComments" name="txtNumberOfComments" value="@NumberOfComments" />
@Html.ValidationMessage("txtNumberOfComments")
</div>
<div>
<button type="submit" onclick="window.parent.updateTitle()" class="btn btn-success btn-sm pull-left">
<button type="submit" class="btn btn-success btn-sm pull-left">
@Resources.labels.save
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</div>
<div>
<button type="submit" onclick="window.parent.updateTitle()" class="btn btn-success btn-sm pull-left">
Save
@Resources.labels.save
</button>
</div>
</form>
4 changes: 2 additions & 2 deletions BlogEngine/BlogEngine.NET/Custom/Widgets/shared.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<style>body { background-color: #fff; }</style>
</head>
<body>
<form method="post">
<form method="post" onsubmit="window.parent.updateTitle()">
<div>
<button type="submit" onclick="window.parent.updateTitle()" class="btn btn-success btn-sm pull-left">
<button type="submit" class="btn btn-success btn-sm pull-left">
@Resources.labels.save
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
$scope.editTitle = title;
$("#txtWidgetTitle").val(title);
$("#titleValidation").hide();
$("#settingsFrame").contents().find('.field-validation-error').hide();
$.ajax({
type: 'HEAD',
url: customSrc,
Expand Down Expand Up @@ -101,11 +102,14 @@
}
}
$scope.save();
return true;
}
return false;
}
else {
$("#titleValidation").show();
$("#txtWidgetTitle").focus();
return false;
}
}

Expand All @@ -118,5 +122,5 @@
}]);

var updateTitle = function () {
angular.element($('#edit-widget')).scope().updateTitle();
return angular.element($('#edit-widget')).scope().updateTitle();
}

0 comments on commit 6765d93

Please sign in to comment.