aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/static/itemeditor.js
diff options
context:
space:
mode:
Diffstat (limited to 'internal/admin/static/itemeditor.js')
-rw-r--r--internal/admin/static/itemeditor.js23
1 files changed, 20 insertions, 3 deletions
diff --git a/internal/admin/static/itemeditor.js b/internal/admin/static/itemeditor.js
index 53242ab..d48d70e 100644
--- a/internal/admin/static/itemeditor.js
+++ b/internal/admin/static/itemeditor.js
@@ -53,8 +53,8 @@ var SECTIONS = [
['xp', 'XP', 'number', '', 'narrow'],
['ticks_per_cycle', 'Ticks/Cycle', 'number', '', 'narrow'],
['output_qty', 'Output Qty', 'number', '', 'narrow'],
- ['station', 'Station', 'select', '|anvil|cooking_range|fire|furnace|pottery_oven|pottery_wheel|spinning_wheel|workbench'],
- ['tool', 'Tool', 'select', '|pickaxe|axe|fire|chisel|hammer|knife|needle|rake|saw|shears|spade|watering_can|fishing_rod|fly_rod|harpoon|small_net|big_net|lobster_pot'],
+ ['station', 'Station', 'select', 'dyn:stations'],
+ ['tool', 'Tool', 'select', 'dyn:tools'],
['fail', 'Fail Item', 'search', 'e.g. burnt_fish', '', null, 'items'],
['success_base', 'Base', 'number', '0.5', 'narrow'],
['success_per_level', 'Per Lvl', 'number', '0.01', 'narrow'],
@@ -125,6 +125,7 @@ function initItemEditor() {
window._ieRenderCurrent = renderCurrent;
window._ieRenderOnly = function() { if (itemID && itemData) renderItemEditor(itemID, itemData); };
window._ieSyncAll = function(ed) { if (ed) ie_syncAllInteractions(ed, SECTIONS); };
+ fetchDynamicOptions();
editorType = 'items';
editorFields = [];
loadList();
@@ -647,7 +648,11 @@ function renderSubFieldHTML(sec, stKey, idx, f, val) {
return '<label class="obj-field obj-check' + extraCls + '"' + extraStyle + '><input type="checkbox" id="' + fid + '"' + (val ? ' checked' : '') + dpAttr + '> <span>' + esc(f[1]) + '</span></label>';
}
if (f[2] === 'select') {
- var opts = f[3] ? f[3].split('|') : [];
+ var hint = f[3] || '';
+ if (hint.indexOf('dyn:') === 0) {
+ return '<label class="obj-field' + extraCls + '"' + extraStyle + '><span>' + esc(f[1]) + '</span>' + ced_buildDynamicSelect(fid, dpAttr, val, hint.substring(4)) + '</label>';
+ }
+ var opts = hint.split('|');
var sel = '<label class="obj-field' + extraCls + '"' + extraStyle + '><span>' + esc(f[1]) + '</span><select id="' + fid + '"' + dpAttr + '>';
opts.forEach(function(o) {
sel += '<option value="' + escAttr(o) + '"' + (String(val) === o ? ' selected' : '') + '>' + esc(o || '(none)') + '</option>';
@@ -1244,6 +1249,18 @@ function selectSearchResult(el) { ced_selectSearchResult(el); }
function updateSearchHighlight(results) { ced_updateSearchHighlight(results); }
+function fetchDynamicOptions() {
+ Promise.all([
+ API.get('/api/tools').catch(function() { return []; }),
+ API.get('/api/stations').catch(function() { return []; })
+ ]).then(function(results) {
+ window._dynOpts = window._dynOpts || {};
+ window._dynOpts.tools = results[0] || [];
+ window._dynOpts.stations = results[1] || [];
+ if (itemID && itemData) renderCurrent();
+ });
+}
+
// =========================================================================
// Validation
// =========================================================================