Skip to content

Commit 99719ca

Browse files
committed
Minor category tree improvements
1 parent b3ad686 commit 99719ca

2 files changed

Lines changed: 29 additions & 29 deletions

File tree

src/Presentation/SmartStore.Web/Administration/Controllers/CategoryController.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,16 +363,22 @@ public ActionResult Tree()
363363
public ActionResult TreeLoadChildren(TreeViewItem node)
364364
{
365365
var parentId = !string.IsNullOrEmpty(node.Value) ? Convert.ToInt32(node.Value) : 0;
366+
var urlHelper = new UrlHelper(this.ControllerContext.RequestContext);
367+
368+
var children = _categoryService.GetAllCategoriesByParentCategoryId(parentId, true).Select(x =>
369+
{
370+
var childCount = _categoryService.GetAllCategoriesByParentCategoryId(x.Id, true).Count;
371+
string text = (childCount > 0 ? "{0} ({1})".FormatWith(x.Name, childCount) : x.Name);
366372

367-
var children = _categoryService.GetAllCategoriesByParentCategoryId(parentId, true).Select(x => {
368373
var item = new TreeViewItem
369374
{
370-
Text = x.Alias.HasValue() ? "{0} <span class='label'>{1}</span>".FormatCurrent(x.Name, x.Alias) : x.Name,
375+
Text = x.Alias.HasValue() ? "{0} <span class='label'>{1}</span>".FormatCurrent(text, x.Alias) : text,
371376
Encoded = x.Alias.IsEmpty(),
372377
Value = x.Id.ToString(),
373-
LoadOnDemand = _categoryService.GetAllCategoriesByParentCategoryId(x.Id, true).Count > 0,
378+
LoadOnDemand = (childCount > 0),
374379
Enabled = true,
375-
ImageUrl = Url.Content(x.Published ? "~/Administration/Content/images/ico-content.png" : "~/Administration/Content/images/ico-content-o60.png")
380+
ImageUrl = Url.Content(x.Published ? "~/Administration/Content/images/ico-content.png" : "~/Administration/Content/images/ico-content-o60.png"),
381+
Url = urlHelper.Action("Edit", "Category", new { id = x.Id })
376382
};
377383
return item;
378384
});

src/Presentation/SmartStore.Web/Administration/Views/Category/Tree.cshtml

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,33 @@
1919
<td>
2020
@(Html.Telerik().TreeView()
2121
.Name("category-treeview")
22-
.ClientEvents(events => events.OnSelect("onSelect").OnNodeDropped("onNodeDropped"))
22+
.ClientEvents(events => events.OnNodeDropped("onNodeDropped"))
2323
.DataBinding(dataBinding => dataBinding.Ajax().Enabled(true).Select("TreeLoadChildren", "Category"))
2424
.ShowLines(true)
2525
.DragAndDrop(true))
2626

2727
<script type="text/javascript">
28-
function onNodeDropped(e) {
29-
var treeview = $('#category-treeview').data("tTreeView");
28+
function onNodeDropped(e) {
29+
var treeview = $('#category-treeview').data("tTreeView");
3030
31-
var item = treeview.getItemValue(e.item);
32-
var destination = treeview.getItemValue(e.destinationItem);
31+
var item = treeview.getItemValue(e.item);
32+
var destination = treeview.getItemValue(e.destinationItem);
3333
34-
var data = {};
35-
data.item = item;
36-
data.destinationitem = destination;
37-
data.position = e.dropPosition;
34+
var data = {};
35+
data.item = item;
36+
data.destinationitem = destination;
37+
data.position = e.dropPosition;
3838
39-
$.ajax({
40-
cache:false,
41-
url: "@Url.Action("TreeDrop")",
42-
data: data,
43-
type: "POST",
44-
success: function () {
45-
$(this).addClass("done");
46-
}
47-
});
48-
}
49-
50-
function onSelect(e) {
51-
var itemId = $('#category-treeview').data('tTreeView').getItemValue(e.item);
52-
var url = "@(Url.Action("Edit"))" + "/" + itemId;
53-
window.location = url;
54-
}
39+
$.ajax({
40+
cache:false,
41+
url: "@Url.Action("TreeDrop")",
42+
data: data,
43+
type: "POST",
44+
success: function () {
45+
$(this).addClass("done");
46+
}
47+
});
48+
}
5549
</script>
5650
</td>
5751
</tr>

0 commit comments

Comments
 (0)