fix: entry model sub-select linkage via DOM options and event delegation
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,4 +1,11 @@
|
|||||||
(function (global) {
|
(function (global) {
|
||||||
|
|
||||||
|
var delegated = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function queryInScope(scope, id) {
|
||||||
|
|
||||||
if (scope && scope.querySelector) return scope.querySelector("#" + id);
|
if (scope && scope.querySelector) return scope.querySelector("#" + id);
|
||||||
|
|
||||||
return document.getElementById(id);
|
return document.getElementById(id);
|
||||||
@@ -7,7 +14,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function tradeStyleForCode(code) {
|
function categoriesData() {
|
||||||
|
|
||||||
|
return global.ORDER_ENTRY_MODEL_CATEGORIES || [];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function codeToCategoryMap() {
|
function codeToCategoryMap() {
|
||||||
|
|
||||||
return global.ORDER_ENTRY_MODEL_CODE_TO_CATEGORY || {};
|
return global.ORDER_ENTRY_MODEL_CODE_TO_CATEGORY || {};
|
||||||
@@ -24,12 +38,44 @@
|
|||||||
|
|
||||||
if (opt) {
|
if (opt) {
|
||||||
|
|
||||||
function rebuildEntryModelSubSelect(preserveCode) {
|
var ds = opt.getAttribute("data-trade-style");
|
||||||
var catSel = document.getElementById("order-entry-category");
|
|
||||||
var modelSel = document.getElementById("order-entry-model");
|
if (ds === "swing" || ds === "trend") return ds;
|
||||||
if (!catSel || !modelSel) return;
|
|
||||||
|
|
||||||
var catKey = catSel.value;
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var map = global.ORDER_ENTRY_MODEL_TRADE_STYLE || {};
|
||||||
|
|
||||||
|
return map[code] || "trend";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function findOption(catKey, code) {
|
||||||
|
|
||||||
|
var cats = categoriesData();
|
||||||
|
|
||||||
|
for (var i = 0; i < cats.length; i++) {
|
||||||
|
|
||||||
|
if (cats[i].key !== catKey) continue;
|
||||||
|
|
||||||
|
var opts = cats[i].options || [];
|
||||||
|
|
||||||
|
for (var j = 0; j < opts.length; j++) {
|
||||||
|
|
||||||
|
if (opts[j].code === code) return opts[j];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function filterDomSubOptions(modelSel, catKey, preserveCode) {
|
function filterDomSubOptions(modelSel, catKey, preserveCode) {
|
||||||
@@ -48,7 +94,6 @@
|
|||||||
|
|
||||||
var show = !!catKey && opt.getAttribute("data-entry-category") === catKey;
|
var show = !!catKey && opt.getAttribute("data-entry-category") === catKey;
|
||||||
|
|
||||||
syncOrderEntryModelTradeStyle();
|
|
||||||
opt.hidden = !show;
|
opt.hidden = !show;
|
||||||
|
|
||||||
opt.disabled = !show;
|
opt.disabled = !show;
|
||||||
@@ -71,43 +116,61 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
syncOrderEntryModelTradeStyle();
|
|
||||||
var pick = preserveCode || "";
|
var pick = preserveCode || "";
|
||||||
|
|
||||||
function syncOrderEntryModelTradeStyle() {
|
if (pick) {
|
||||||
var modelSel = document.getElementById("order-entry-model");
|
|
||||||
|
var picked = modelSel.querySelector('option[value="' + pick.replace(/"/g, '\\"') + '"]:not([disabled])');
|
||||||
|
|
||||||
|
if (picked) {
|
||||||
|
|
||||||
|
modelSel.value = pick;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var visible = [];
|
||||||
|
|
||||||
for (var k = 0; k < tagged.length; k++) {
|
for (var k = 0; k < tagged.length; k++) {
|
||||||
|
|
||||||
if (!tagged[k].disabled) visible.push(tagged[k]);
|
if (!tagged[k].disabled) visible.push(tagged[k]);
|
||||||
|
|
||||||
var ts = tradeStyleForCode(code);
|
}
|
||||||
|
|
||||||
if (visible.length === 1) modelSel.value = visible[0].value;
|
if (visible.length === 1) modelSel.value = visible[0].value;
|
||||||
|
|
||||||
else modelSel.value = "";
|
else modelSel.value = "";
|
||||||
function initOrderEntryModelSelect(root) {
|
|
||||||
var scope = root && root.querySelector ? root : document;
|
return true;
|
||||||
var catSel =
|
|
||||||
scope === document
|
}
|
||||||
? document.getElementById("order-entry-category")
|
|
||||||
: scope.querySelector("#order-entry-category");
|
|
||||||
var modelSel =
|
|
||||||
scope === document
|
function rebuildFromCategories(modelSel, catKey, preserveCode) {
|
||||||
? document.getElementById("order-entry-model")
|
|
||||||
: scope.querySelector("#order-entry-model");
|
var cats = categoriesData();
|
||||||
if (!catSel || !modelSel) return;
|
|
||||||
|
var cat = null;
|
||||||
|
|
||||||
|
for (var i = 0; i < cats.length; i++) {
|
||||||
|
|
||||||
|
if (cats[i].key === catKey) {
|
||||||
|
|
||||||
|
cat = cats[i];
|
||||||
|
|
||||||
break;
|
break;
|
||||||
if (catSel.dataset.entryModelWired !== "1") {
|
|
||||||
catSel.dataset.entryModelWired = "1";
|
}
|
||||||
catSel.addEventListener("change", function () {
|
|
||||||
rebuildEntryModelSubSelect("");
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
if (modelSel.dataset.entryModelWired !== "1") {
|
|
||||||
modelSel.dataset.entryModelWired = "1";
|
|
||||||
modelSel.addEventListener("change", syncOrderEntryModelTradeStyle);
|
|
||||||
}
|
|
||||||
|
|
||||||
modelSel.innerHTML = "";
|
modelSel.innerHTML = "";
|
||||||
|
|
||||||
@@ -115,11 +178,11 @@
|
|||||||
|
|
||||||
placeholder.value = "";
|
placeholder.value = "";
|
||||||
|
|
||||||
rebuildEntryModelSubSelect(presetCode);
|
placeholder.textContent = "类型";
|
||||||
|
|
||||||
modelSel.appendChild(placeholder);
|
modelSel.appendChild(placeholder);
|
||||||
|
|
||||||
rebuildEntryModelSubSelect("");
|
|
||||||
|
|
||||||
if (!cat || !cat.options || !cat.options.length) {
|
if (!cat || !cat.options || !cat.options.length) {
|
||||||
|
|
||||||
@@ -140,7 +203,12 @@
|
|||||||
for (var k = 0; k < cat.options.length; k++) {
|
for (var k = 0; k < cat.options.length; k++) {
|
||||||
|
|
||||||
var o = cat.options[k];
|
var o = cat.options[k];
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
|
||||||
|
var opt = document.createElement("option");
|
||||||
|
|
||||||
|
opt.value = o.code;
|
||||||
|
|
||||||
|
opt.textContent = o.label;
|
||||||
|
|
||||||
});
|
if (o.trade_style) opt.setAttribute("data-trade-style", o.trade_style);
|
||||||
|
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ const ORDER_ENTRY_MODEL_TRADE_STYLE = {{ entry_model_trade_style_map | tojson }}
|
|||||||
const ORDER_ENTRY_MODEL_CATEGORIES = {{ entry_model_categories | tojson }};
|
const ORDER_ENTRY_MODEL_CATEGORIES = {{ entry_model_categories | tojson }};
|
||||||
const ORDER_ENTRY_MODEL_CODE_TO_CATEGORY = {{ entry_model_code_to_category | tojson }};
|
const ORDER_ENTRY_MODEL_CODE_TO_CATEGORY = {{ entry_model_code_to_category | tojson }};
|
||||||
</script>
|
</script>
|
||||||
<script src="/static/order_entry_model.js?v=4"></script>
|
<script src="/static/order_entry_model.js?v=5"></script>
|
||||||
<script src="/static/manual_order_rr_preview.js?v=5"></script>
|
<script src="/static/manual_order_rr_preview.js?v=5"></script>
|
||||||
<script src="/static/symbol_live_price.js?v=2"></script>
|
<script src="/static/symbol_live_price.js?v=2"></script>
|
||||||
<script src="/static/strategy_roll.js?v=6"></script>
|
<script src="/static/strategy_roll.js?v=6"></script>
|
||||||
|
|||||||
@@ -559,7 +559,7 @@ const ORDER_ENTRY_MODEL_TRADE_STYLE = {{ entry_model_trade_style_map | tojson }}
|
|||||||
const ORDER_ENTRY_MODEL_CATEGORIES = {{ entry_model_categories | tojson }};
|
const ORDER_ENTRY_MODEL_CATEGORIES = {{ entry_model_categories | tojson }};
|
||||||
const ORDER_ENTRY_MODEL_CODE_TO_CATEGORY = {{ entry_model_code_to_category | tojson }};
|
const ORDER_ENTRY_MODEL_CODE_TO_CATEGORY = {{ entry_model_code_to_category | tojson }};
|
||||||
</script>
|
</script>
|
||||||
<script src="/static/order_entry_model.js?v=4"></script>
|
<script src="/static/order_entry_model.js?v=5"></script>
|
||||||
<script src="/static/manual_order_rr_preview.js?v=5"></script>
|
<script src="/static/manual_order_rr_preview.js?v=5"></script>
|
||||||
<script src="/static/symbol_live_price.js?v=2"></script>
|
<script src="/static/symbol_live_price.js?v=2"></script>
|
||||||
<script src="/static/strategy_roll.js?v=6"></script>
|
<script src="/static/strategy_roll.js?v=6"></script>
|
||||||
|
|||||||
@@ -10,6 +10,11 @@
|
|||||||
|
|
||||||
<option value="">性质</option>
|
<option value="">性质</option>
|
||||||
|
|
||||||
|
{% for cat in entry_model_categories %}
|
||||||
|
|
||||||
|
<option value="{{ cat.key }}">{{ cat.label }}</option>
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user