2016-11-28 10:42:58 +00:00
|
|
|
/**
|
|
|
|
* Object to handle the creation of operation categories.
|
|
|
|
*
|
|
|
|
* @author n1474335 [n1474335@gmail.com]
|
|
|
|
* @copyright Crown Copyright 2016
|
|
|
|
* @license Apache-2.0
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {string} name - The name of the category.
|
|
|
|
* @param {boolean} selected - Whether this category is pre-selected or not.
|
|
|
|
*/
|
2017-04-13 18:08:50 +01:00
|
|
|
const HTMLCategory = function(name, selected) {
|
2016-11-28 10:42:58 +00:00
|
|
|
this.name = name;
|
|
|
|
this.selected = selected;
|
2017-01-31 18:24:56 +00:00
|
|
|
this.opList = [];
|
2016-11-28 10:42:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds an operation to this category.
|
|
|
|
*
|
|
|
|
* @param {HTMLOperation} operation - The operation to add.
|
|
|
|
*/
|
2017-01-31 18:24:56 +00:00
|
|
|
HTMLCategory.prototype.addOperation = function(operation) {
|
|
|
|
this.opList.push(operation);
|
2016-11-28 10:42:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the category and all operations within it in HTML.
|
|
|
|
*
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2017-01-31 18:24:56 +00:00
|
|
|
HTMLCategory.prototype.toHtml = function() {
|
2017-04-13 18:08:50 +01:00
|
|
|
const catName = "cat" + this.name.replace(/[\s/-:_]/g, "");
|
|
|
|
let html = "<div class='panel category'>\
|
2016-11-28 10:42:58 +00:00
|
|
|
<a class='category-title' data-toggle='collapse'\
|
2017-01-31 18:24:56 +00:00
|
|
|
data-parent='#categories' href='#" + catName + "'>\
|
2016-11-28 10:42:58 +00:00
|
|
|
" + this.name + "\
|
|
|
|
</a>\
|
2017-01-31 18:24:56 +00:00
|
|
|
<div id='" + catName + "' class='panel-collapse collapse\
|
|
|
|
" + (this.selected ? " in" : "") + "'><ul class='op-list'>";
|
2017-02-09 15:09:33 +00:00
|
|
|
|
2017-04-13 18:08:50 +01:00
|
|
|
for (let i = 0; i < this.opList.length; i++) {
|
2017-01-31 18:24:56 +00:00
|
|
|
html += this.opList[i].toStubHtml();
|
2016-11-28 10:42:58 +00:00
|
|
|
}
|
2017-02-09 15:09:33 +00:00
|
|
|
|
2016-11-28 10:42:58 +00:00
|
|
|
html += "</ul></div></div>";
|
|
|
|
return html;
|
|
|
|
};
|
2017-03-23 17:52:20 +00:00
|
|
|
|
|
|
|
export default HTMLCategory;
|