aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/static/objecteditor.js
diff options
context:
space:
mode:
Diffstat (limited to 'internal/admin/static/objecteditor.js')
-rw-r--r--internal/admin/static/objecteditor.js44
1 files changed, 43 insertions, 1 deletions
diff --git a/internal/admin/static/objecteditor.js b/internal/admin/static/objecteditor.js
index 3f2a875..5153458 100644
--- a/internal/admin/static/objecteditor.js
+++ b/internal/admin/static/objecteditor.js
@@ -2,6 +2,7 @@ var objectData = null;
var objectID = null;
var expandedCards = {};
var cardWidths = {};
+var toolTypes = null;
var SECTIONS = [
{
@@ -48,7 +49,7 @@ var SECTIONS = [
['deplete_timer', 'Deplete', 'number', '45', 'narrow', function(d) { return d.skill === 'woodcutting'; }],
['nest_chance', 'Nest 1/n', 'number', '256', 'narrow', function(d) { return d.skill === 'woodcutting'; }],
]},
- {label:'Tools', key:'tools', type:'tags'},
+ {label:'Tools', key:'tools', type:'tools_checkbox'},
],
subtables: [
{label:'Drops', key:'drops', fields:[
@@ -133,6 +134,7 @@ function initObjectEditor() {
editorType = 'objects';
editorFields = [];
loadList();
+ fetchToolTypes();
if (window.location.hash) loadObject(window.location.hash.substring(1));
}
@@ -266,6 +268,10 @@ function renderCard(sec, data) {
h += '<div class="obj-inline-group" style="flex:1">';
h += renderTags(sec, il, data);
h += '</div>';
+ } else if (il.type === 'tools_checkbox') {
+ h += '<div class="obj-inline-group" style="flex:1">';
+ h += renderToolsCheckbox(sec, il, data);
+ h += '</div>';
} else if (il.type === 'kv') {
h += '<div class="obj-inline-group" style="flex:1">';
h += renderKV(sec, il, data);
@@ -286,6 +292,8 @@ function renderCard(sec, data) {
noRow.forEach(function(il) {
if (il.type === 'tags') {
h += renderTags(sec, il, data);
+ } else if (il.type === 'tools_checkbox') {
+ h += renderToolsCheckbox(sec, il, data);
} else if (il.type === 'kv') {
h += renderKV(sec, il, data);
} else {
@@ -518,6 +526,35 @@ function renderKV(sec, il, data) {
return h;
}
+function renderToolsCheckbox(sec, il, data) {
+ var sectionRoot = data[cardPath(sec)] || {};
+ var arr = sectionRoot[il.key] || [];
+ var choices = toolTypes || [];
+ var h = '<div class="obj-inline-group">';
+ h += '<span class="obj-inline-label">' + esc(il.label) + '</span>';
+ h += '<div class="obj-tools-checkboxes" style="display:flex;flex-wrap:wrap;gap:4px 12px;margin-top:4px">';
+ choices.forEach(function(t) {
+ var checked = arr.indexOf(t) >= 0 ? ' checked' : '';
+ h += '<label class="obj-field obj-check" style="margin:0;padding:2px 0"><input type="checkbox" class="obj-tool-chk" data-tool="' + escAttr(t) + '"' + checked + '> <span style="font-size:12px">' + esc(t) + '</span></label>';
+ });
+ h += '</div>';
+ if (choices.length === 0) {
+ h += '<span style="color:#888;font-size:11px">Loading tool types...</span>';
+ }
+ h += '</div>';
+ return h;
+}
+
+function fetchToolTypes() {
+ API.get('/api/tools').then(function(tools) {
+ toolTypes = tools || [];
+ renderCurrent();
+ }).catch(function() {
+ toolTypes = [];
+ renderCurrent();
+ });
+}
+
function toggleCard(id) {
expandedCards[id] = expandedCards[id] === false ? true : false;
renderCurrent();
@@ -742,6 +779,11 @@ function saveObject() {
sectionObj[il.key] = el.value.split(',').map(function(s) { return s.trim(); }).filter(function(s) { return s; });
hasValues = true;
}
+ } else if (il.type === 'tools_checkbox') {
+ var chks = document.querySelectorAll('.obj-tool-chk:checked');
+ var tools = [];
+ chks.forEach(function(c) { tools.push(c.getAttribute('data-tool')); });
+ if (tools.length > 0) { sectionObj[il.key] = tools; hasValues = true; }
} else if (il.type === 'kv') {
var kvEl = document.querySelector('.obj-kv-list[data-sec="' + sec.id + '"][data-key="' + il.key + '"]');
if (kvEl) {