From 689f45330fc65249fff146672de82038e44497cc Mon Sep 17 00:00:00 2001 From: kenzok8 Date: Tue, 21 Jan 2025 16:24:29 +0800 Subject: [PATCH] update 2025-01-21 16:24:29 --- .../htdocs/luci-static/resources/fchomo.js | 67 ++++++++++++++++++- .../resources/view/fchomo/client.js | 2 +- .../resources/view/fchomo/global.js | 3 +- 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/luci-app-fchomo/htdocs/luci-static/resources/fchomo.js b/luci-app-fchomo/htdocs/luci-static/resources/fchomo.js index 054d4702f..71ad85f87 100644 --- a/luci-app-fchomo/htdocs/luci-static/resources/fchomo.js +++ b/luci-app-fchomo/htdocs/luci-static/resources/fchomo.js @@ -15,6 +15,11 @@ const sharktaikogif = function() { 'c2hhcmstdGFpa28uZ2lm' }() +const less_24_10 = !form.RichListValue; + +const pr7558_merged = false; +const pr7574_merged = false; + const monospacefonts = [ '"Cascadia Code"', '"Cascadia Mono"', @@ -235,6 +240,29 @@ const tls_client_fingerprints = [ ]; /* Prototype */ +const CBIDynamicList = form.DynamicList.extend({ + __name__: 'CBI.DynamicList', + + renderWidget(section_id, option_index, cfgvalue) { + const value = (cfgvalue != null) ? cfgvalue : this.default; + const choices = this.transformChoices(); + const items = L.toArray(value); + + const widget = new UIDynamicList(items, choices, { + id: this.cbid(section_id), + sort: this.keylist, + allowduplicates: this.allowduplicates, + optional: this.optional || this.rmempty, + datatype: this.datatype, + placeholder: this.placeholder, + validate: L.bind(this.validate, this, section_id), + disabled: (this.readonly != null) ? this.readonly : this.map.readonly + }); + + return widget.render(); + } +}); + const CBIGenValue = form.Value.extend({ __name__: 'CBI.GenValue', @@ -268,7 +296,7 @@ const CBIStaticList = form.DynamicList.extend({ __name__: 'CBI.StaticList', renderWidget(/* ... */) { - let El = form.DynamicList.prototype.renderWidget.apply(this, arguments); + let El = ((less_24_10 || !pr7558_merged) ? CBIDynamicList : form.DynamicList).prototype.renderWidget.apply(this, arguments); El.querySelector('.add-item ul > li[data-value="-"]')?.remove(); @@ -278,14 +306,45 @@ const CBIStaticList = form.DynamicList.extend({ const CBITextValue = form.TextValue.extend({ renderWidget(/* ... */) { + if (pr7574_merged) + this.monospace = monospacefonts.join(','); + let frameEl = form.TextValue.prototype.renderWidget.apply(this, arguments); - frameEl.querySelector('textarea').style.fontFamily = monospacefonts.join(','); + if (!pr7574_merged) + frameEl.querySelector('textarea').style.fontFamily = monospacefonts.join(','); return frameEl; } }); +const UIDynamicList = ui.DynamicList.extend({ + addItem(dl, value, text, flash) { + if (this.options.allowduplicates) { + const new_item = E('div', { 'class': flash ? 'item flash' : 'item', 'tabindex': 0, 'draggable': !less_24_10 }, [ + E('span', {}, [ text ?? value ]), + E('input', { + 'type': 'hidden', + 'name': this.options.name, + 'value': value })]); + + const ai = dl.querySelector('.add-item'); + ai.parentNode.insertBefore(new_item, ai); + } + + ui.DynamicList.prototype.addItem.call(this, dl, value, text, flash); + }, + + handleDropdownChange(ev) { + ui.DynamicList.prototype.handleDropdownChange.call(this, ev); + + if (this.options.allowduplicates) { + const sbVal = ev.detail.value; + sbVal?.element.removeAttribute('unselectable'); + } + } +}); + /* Method */ // thanks to homeproxy function calcStringMD5(e) { @@ -1067,6 +1126,9 @@ return baseclass.extend({ /* Member */ rulesetdoc, sharktaikogif, + less_24_10, + pr7558_merged, + pr7574_merged, monospacefonts, dashrepos, dashrepos_urlparams, @@ -1088,6 +1150,7 @@ return baseclass.extend({ tls_client_fingerprints, /* Prototype */ + DynamicList: CBIDynamicList, GenValue: CBIGenValue, ListValue: CBIListValue, StaticList: CBIStaticList, diff --git a/luci-app-fchomo/htdocs/luci-static/resources/view/fchomo/client.js b/luci-app-fchomo/htdocs/luci-static/resources/view/fchomo/client.js index 5086644dc..53c55fdf5 100644 --- a/luci-app-fchomo/htdocs/luci-static/resources/view/fchomo/client.js +++ b/luci-app-fchomo/htdocs/luci-static/resources/view/fchomo/client.js @@ -392,7 +392,7 @@ function renderPayload(s, total, uciconfig) { return true; } - o = s.option(form.DynamicList, prefix + 'fused', _('Factor') + ' ++', + o = s.option((hm.less_24_10 || !hm.pr7558_merged) ? hm.DynamicList : form.DynamicList, prefix + 'fused', _('Factor') + ' ++', _('Content will not be verified, Please make sure you enter it correctly.')); extenbox[n].forEach((type) => { o.depends(Object.fromEntries([['type', type], [prefix + 'type', /.+/]])); diff --git a/luci-app-fchomo/htdocs/luci-static/resources/view/fchomo/global.js b/luci-app-fchomo/htdocs/luci-static/resources/view/fchomo/global.js index 2e76e4729..9485b2b19 100644 --- a/luci-app-fchomo/htdocs/luci-static/resources/view/fchomo/global.js +++ b/luci-app-fchomo/htdocs/luci-static/resources/view/fchomo/global.js @@ -168,7 +168,6 @@ return view.extend({ const res_ver_geoip = data[7]; const res_ver_geosite = data[8]; - const less_24_10 = !form.RichListValue; const dashboard_repo = uci.get(data[0], 'api', 'dashboard_repo'); let m, s, o, ss, so; @@ -473,7 +472,7 @@ return view.extend({ } so.default = 'system'; so.rmempty = false; - if (less_24_10) + if (hm.less_24_10) so.onchange = function(ev, section_id, value) { var desc = ev.target.nextSibling; if (value === 'mixed')