Commit 84c4489d by NGUYEN HOANG SON

fix operation category multi level

parent d434b3ce
......@@ -299,12 +299,12 @@ OL.createCategoryList = function () {
//Create a side menu category structure
var categoryListElement = $('#categoryListMenu');
categoryListElement.empty();
//sort group master list by level low to hight
OL.operationGroupMaster.sort(function (a, b) {
if (a.operationGroupMasterLevel < b.operationGroupMasterLevel) return -1;
if (a.operationGroupMasterLevel > b.operationGroupMasterLevel) return 1;
return 1;
});
let allChecked = '';
if (typeof OL.operationGroupMasterId === 'undefined' || OL.operationGroupMasterId == 0) {
allChecked = ' checked';
......@@ -316,7 +316,6 @@ OL.createCategoryList = function () {
//create category(operationGroupMaster) structure
for (let i = 0; i < OL.operationGroupMaster.length; i++) {
const item = OL.operationGroupMaster[i];
console.log(item);
let inputLabel = $('<label>');
let inputRadio = $('<input type="radio" name="category">');
inputRadio.val(item.operationGroupMasterId);
......@@ -326,11 +325,20 @@ OL.createCategoryList = function () {
let groupSpan = $('<span>' + item.operationGroupMasterName + '</span>');
inputLabel.append(inputRadio);
inputLabel.append(groupSpan);
if (item.operationGroupMasterLevel == 0) {
const isParent = OL.operationGroupMaster.find(function(child) {
return item.operationGroupMasterId == child.parentOperationGroupMasterId;
});
let parentElement = categoryListElement;
if (item.parentOperationGroupMasterId != 0) {
parentElement = $('#collapse' + item.parentOperationGroupMasterId + ' > ul');
}
if (isParent) {
//accordion
const accordionId = 'accordion' + item.operationGroupMasterId;
const headingId = 'heading' + item.operationGroupMasterId;
const collapseId = 'collapse' + item.operationGroupMasterId;
let categoryParentElm = $('<li class="accordion" id="' + accordionId + '" />');
let accordionElm = $('<li class="accordion" id="' + accordionId + '" />');
//heading
let headingDiv = $('<div id="' + headingId + '" />');
let linkA = $('<a class="list-menu-link" />');
let collapseButton = $('<button type="button" class="collapsed" data-toggle="collapse" aria-expanded="true" />');
......@@ -340,26 +348,19 @@ OL.createCategoryList = function () {
linkA.append(collapseButton);
linkA.append(inputLabel);
headingDiv.append(linkA);
categoryParentElm.append(headingDiv);
categoryListElement.append(categoryParentElm);
//collapse
let collapseElm = $('<div id="' + collapseId + '" class="collapse">');
collapseElm.attr('data-parent', '#' + accordionId);
collapseElm.attr('aria-labelledby', headingId);
let ul = $('<ul>');
collapseElm.append(ul);
accordionElm.append(headingDiv);
accordionElm.append(collapseElm);
parentElement.append(accordionElm);
} else {
let li = $('<li>');
li.append(inputLabel);
let parentElm = $('#collapse' + item.parentOperationGroupMasterId + ' > ul');
if (typeof parentElm === 'undefined' || !parentElm || parentElm.length < 1) {
const accordionParentId = 'accordion' + item.parentOperationGroupMasterId;
const headingParentId = 'heading' + item.parentOperationGroupMasterId;
const collapseParentId = 'collapse' + item.parentOperationGroupMasterId;
parentElm = $('<div id="' + collapseParentId + '" class="collapse">');
parentElm.attr('data-parent', '#' + accordionParentId);
parentElm.attr('aria-labelledby', headingParentId);
let ul = $('<ul>');
ul.append(li);
parentElm.append(ul);
$('#' + accordionParentId).append(parentElm);
} else {
parentElm.append(li);
}
parentElement.append(li);
}
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment