Skip to content

Commit 6765d93

Browse files
committed
Widget improvements - validation and cancel save
1 parent f764445 commit 6765d93

5 files changed

Lines changed: 30 additions & 17 deletions

File tree

BlogEngine/BlogEngine.NET/Custom/Widgets/Post List/edit.cshtml

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,24 @@
1111

1212
var widgetId = Request.QueryString["id"];
1313
var settings = WidgetHelper.GetSettings(widgetId);
14-
14+
Validation.Add("txtNumberOfPosts",
15+
Validator.Required("Field is required"),
16+
Validator.Integer("Field is numeric")
17+
);
1518
if (IsPost)
1619
{
17-
settings["numberofposts"] = Request.Form["txtNumberOfPosts"];
18-
settings["cutegory"] = Request.Form["ddlCategories"];
19-
settings["author"] = Request.Form["ddlAuthors"];
20-
settings["sortorder"] = Request.Form["ddlSortBy"];
21-
settings["showimg"] = Request.Form["cbShowImg"] == "on" ? "true" : "false";
22-
settings["showdesc"] = Request.Form["cbShowDesc"] == "on" ? "true" : "false";
23-
settings["showdate"] = Request.Form["cbShowDate"] == "on" ? "true" : "false";
24-
WidgetHelper.SaveSettings(settings, widgetId);
20+
if (Validation.IsValid())
21+
{
22+
settings["numberofposts"] = Request.Form["txtNumberOfPosts"];
23+
settings["cutegory"] = Request.Form["ddlCategories"];
24+
settings["author"] = Request.Form["ddlAuthors"];
25+
settings["sortorder"] = Request.Form["ddlSortBy"];
26+
settings["showimg"] = Request.Form["cbShowImg"] == "on" ? "true" : "false";
27+
settings["showdesc"] = Request.Form["cbShowDesc"] == "on" ? "true" : "false";
28+
settings["showdate"] = Request.Form["cbShowDate"] == "on" ? "true" : "false";
29+
WidgetHelper.SaveSettings(settings, widgetId);
30+
@:<script type="text/javascript">window.parent.toastr.success("Completed");</script>
31+
}
2532
}
2633
if (settings != null && settings.Count > 0)
2734
{
@@ -59,11 +66,13 @@
5966
<link rel="stylesheet" href="~/admin/themes/standard/css/styles.css">
6067
<style>
6168
body { background-color: #fff; }
69+
.field-validation-error { background-color: #d9534f; border-color: #d9534f; color: #fff; padding: 5px 15px; display: block; }
6270
</style>
63-
<form method="post">
71+
<form method="post" onsubmit="window.parent.updateTitle()">
6472
<div class="form-group">
6573
<label for="txtNumberOfPosts">@Resources.labels.numberOfPosts</label>
6674
@Html.TextBox("txtNumberOfPosts", numberOfPosts, new { @class = "form-control" })
75+
@Html.ValidationMessage("txtNumberOfPosts")
6776
</div>
6877
<div class="form-group">
6978
<label for="ddlCategories">@Resources.labels.category</label>
@@ -93,7 +102,7 @@
93102
</label>
94103
</div>
95104
<div>
96-
<button type="submit" onclick="window.parent.updateTitle()" class="btn btn-success btn-sm pull-left">
105+
<button type="submit" class="btn btn-success btn-sm pull-left">
97106
@Resources.labels.save
98107
</button>
99108
</div>

BlogEngine/BlogEngine.NET/Custom/Widgets/RecentComments/edit.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
</style>
3333
</head>
3434
<body>
35-
<form method="post">
35+
<form method="post" onsubmit="window.parent.updateTitle()">
3636
<div class="form-group">
3737
<label>@Resources.labels.numberOfComments</label>
3838
<input type="text" class="form-control" id="txtNumberOfComments" name="txtNumberOfComments" value="@NumberOfComments" />
3939
@Html.ValidationMessage("txtNumberOfComments")
4040
</div>
4141
<div>
42-
<button type="submit" onclick="window.parent.updateTitle()" class="btn btn-success btn-sm pull-left">
42+
<button type="submit" class="btn btn-success btn-sm pull-left">
4343
@Resources.labels.save
4444
</button>
4545
</div>

BlogEngine/BlogEngine.NET/Custom/Widgets/Tag cloud/edit.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
</div>
6161
<div>
6262
<button type="submit" onclick="window.parent.updateTitle()" class="btn btn-success btn-sm pull-left">
63-
Save
63+
@Resources.labels.save
6464
</button>
6565
</div>
6666
</form>

BlogEngine/BlogEngine.NET/Custom/Widgets/shared.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
<style>body { background-color: #fff; }</style>
77
</head>
88
<body>
9-
<form method="post">
9+
<form method="post" onsubmit="window.parent.updateTitle()">
1010
<div>
11-
<button type="submit" onclick="window.parent.updateTitle()" class="btn btn-success btn-sm pull-left">
11+
<button type="submit" class="btn btn-success btn-sm pull-left">
1212
@Resources.labels.save
1313
</button>
1414
</div>

BlogEngine/BlogEngine.NET/admin/app/custom/widgets/widgetController.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
$scope.editTitle = title;
4040
$("#txtWidgetTitle").val(title);
4141
$("#titleValidation").hide();
42+
$("#settingsFrame").contents().find('.field-validation-error').hide();
4243
$.ajax({
4344
type: 'HEAD',
4445
url: customSrc,
@@ -101,11 +102,14 @@
101102
}
102103
}
103104
$scope.save();
105+
return true;
104106
}
107+
return false;
105108
}
106109
else {
107110
$("#titleValidation").show();
108111
$("#txtWidgetTitle").focus();
112+
return false;
109113
}
110114
}
111115

@@ -118,5 +122,5 @@
118122
}]);
119123

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

0 commit comments

Comments
 (0)