Files
PetitTeton/public/admin/categoryEditor.html

106 lines
2.7 KiB
HTML

<div id="categoryEditor" class="page">
<h1>Categories</h1>
<table id="categoryTree" class="editorTable">
<colgroup>
<col style="width: 1*; min-width: 400px;"></col>
<col style="width: 30px;"></col>
</colgroup>
<thead>
<tr><th>Name</th><th>Visible</th></tr>
</thead>
<tbody>
<tr> <td></td> <td></td> </tr>
</tbody>
</table>
</div>
<runonce>
$.ajax({url: "/GetMeasures", dataType: 'json', cache: false, success: function(data, textStatus, jqXHR) {
var measures = data;
var colgroup = $('#categoryTree colgroup');
var theadtr = $('#categoryTree thead tr');
var bodytr = $('#categoryTree body tr');
//Add a column per measure.
for(var i = 0; i < measures.length; i++) {
var measure = measures[i];
if(measure.visible) {
colgroup.append('<col style="width: 30px;"></col>');
theadtr.append('<th><image class="headerIcon" src="/images/' + measure.image + '"/></th>');
bodytr.append('<td></td>');
}
}
//Setup the tree table.
$("#categoryTree").fancytree({
extensions: ["table"],
table: {
indentation: 20, // indent 20px per node level
nodeColumnIdx: 0
},
renderColumns: function(event, data) {
var node = data.node, $tdList = $(node.tr).find(">td");
//$tdList.eq(0).text(node.name);
$tdList.eq(1).html("<input type='checkbox' name='visible' value='" + node.visible + "'>");
//$tdList.eq(2).text(node.data.counts);
if(node.data.type == 'Item') {
for(var i = 0; i < measures.length; i++) {
var measure = measures[i];
if(measure.id in node.data.counts) {
$tdList.eq(2+i).text("X");
}
else {
$tdList.eq(2+i).text("_");
}
}
}
},
source: {
url: "/GetCategories",
cache: false
},
lazyLoad: function(event, data) {
var node = data.node.data;
if(node.type == 'Category') {
data.result = {
url: "/GetSubcategories",
data: {id: node.id}
}
}
else if(node.type == 'Subcategory') {
data.result = {
url: "/GetItems",
data: {id: node.id}
}
}
else {
data.result = [];
}
},
postProcess: function(event, data) {
var nodes = data.response;
for(var i = 0; i < nodes.length; i++) {
nodes[i].key = (data.node != null ? data.node.key + "/" : "") + nodes[i].id;
nodes[i].title = nodes[i].name;
nodes[i].cache = false;
nodes[i].type = data.node.data.type == null ? "Category" : data.node.data.type == 'Category' ? "Subcategory" : "Item";
nodes[i].lazy = nodes[i].folder = nodes[i].type != 'Item';
//check(data.node);
}
}
});
}, fail: function(jqXHR, textStatus, errorThrown) {
//TODO:
alert("Get measures failed.");
}});
</runonce>