mirror of
https://github.com/remittor/zapret-openwrt.git
synced 2025-12-12 14:36:59 +03:00
luci: Add support multiline long string editing
This commit is contained in:
@@ -141,26 +141,36 @@ return view.extend({
|
|||||||
o.default = '<hr style="width: 620px; height: 1px; margin: 1px 0 1px; border-top: 1px solid;">';
|
o.default = '<hr style="width: 620px; height: 1px; margin: 1px 0 1px; border-top: 1px solid;">';
|
||||||
};
|
};
|
||||||
|
|
||||||
let add_param = function(sec, param, locname = null, rows = 10) {
|
let add_param = function(sec, param, locname = null, rows = 10, multiline = false) {
|
||||||
if (!locname)
|
if (!locname)
|
||||||
locname = param;
|
locname = param;
|
||||||
let btn = sec.taboption(tabname, form.Button, '_' + param + '_btn', locname);
|
let btn = sec.taboption(tabname, form.Button, '_' + param + '_btn', locname);
|
||||||
btn.inputtitle = _('Edit');
|
btn.inputtitle = _('Edit');
|
||||||
btn.inputstyle = 'edit btn';
|
btn.inputstyle = 'edit btn';
|
||||||
let val = sec.taboption(tabname, form.DummyValue, '_' + param);
|
let val = sec.taboption(tabname, form.DummyValue, '_' + param);
|
||||||
val.rawhtml = false;
|
val.rawhtml = multiline ? true : false;
|
||||||
val.cfgvalue = function(section_id) {
|
val.cfgvalue = function(section_id) {
|
||||||
let name = uci.get(tools.appName, section_id, param);
|
let value = uci.get(tools.appName, section_id, param);
|
||||||
if (name == null || name == "")
|
if (value == null) {
|
||||||
name = "";
|
return "";
|
||||||
return name;
|
}
|
||||||
|
value = value.trim();
|
||||||
|
if (multiline == 2) {
|
||||||
|
value = value.replace(/\n --/g, "\n--");
|
||||||
|
value = value.replace(/\n --/g, "\n--");
|
||||||
|
value = value.replace(/ --/g, "\n--");
|
||||||
|
}
|
||||||
|
if (val.rawhtml) {
|
||||||
|
value = value.replace(/</g, '˂');
|
||||||
|
value = value.replace(/>/g, '˃');
|
||||||
|
value = value.replace(/\n/g, '<br/>');
|
||||||
|
}
|
||||||
|
return value;
|
||||||
};
|
};
|
||||||
val.validate = function(section_id, value) {
|
val.validate = function(section_id, value) {
|
||||||
if (!value)
|
return (value) ? value.trim() : "";
|
||||||
return "";
|
|
||||||
return value.trim();
|
|
||||||
};
|
};
|
||||||
btn.onclick = () => new tools.longstrEditDialog('config', param, param, locname, rows).show();
|
btn.onclick = () => new tools.longstrEditDialog('config', param, param, locname, rows, multiline).show();
|
||||||
};
|
};
|
||||||
|
|
||||||
add_delim(s);
|
add_delim(s);
|
||||||
|
|||||||
@@ -350,18 +350,24 @@ return baseclass.extend({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
longstrEditDialog: baseclass.extend({
|
longstrEditDialog: baseclass.extend({
|
||||||
__init__: function(cfgsec, cfgparam, title, desc, rows = 10) {
|
__init__: function(cfgsec, cfgparam, title, desc, rows = 10, multiline = false) {
|
||||||
this.cfgsec = cfgsec;
|
this.cfgsec = cfgsec;
|
||||||
this.cfgparam = cfgparam;
|
this.cfgparam = cfgparam;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.desc = desc;
|
this.desc = desc;
|
||||||
this.rows = rows;
|
this.rows = rows;
|
||||||
|
this.multiline = multiline;
|
||||||
},
|
},
|
||||||
|
|
||||||
load: function() {
|
load: function() {
|
||||||
let value = uci.get('zapret', this.cfgsec, this.cfgparam);
|
let value = uci.get('zapret', this.cfgsec, this.cfgparam);
|
||||||
if (typeof(value) === 'string') {
|
if (typeof(value) === 'string') {
|
||||||
return value.trim();
|
value = value.trim();
|
||||||
|
if (this.multiline == 2) {
|
||||||
|
value = value.replace(/\n --/g, "\n--");
|
||||||
|
value = value.replace(/\n --/g, "\n--");
|
||||||
|
value = value.replace(/ --/g, "\n--");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
},
|
},
|
||||||
@@ -401,15 +407,36 @@ return baseclass.extend({
|
|||||||
|
|
||||||
handleSave: function(ev) {
|
handleSave: function(ev) {
|
||||||
let txt = document.getElementById('widget.modal_content');
|
let txt = document.getElementById('widget.modal_content');
|
||||||
let value = txt.value.trim().replace(/\r\n/g, ' ').replace(/\r/g, ' ').replace(/\n/g, ' ').trim();
|
let value = txt.value.trim();
|
||||||
|
if (this.multiline) {
|
||||||
|
value = value.replace(/\r/g, '');
|
||||||
|
if (value != "" && value != "\t") {
|
||||||
|
value = '\n' + value + '\n';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
value = value.replace(/\r\n/g, ' ');
|
||||||
|
value = value.replace(/\r/g, ' ');
|
||||||
|
value = value.replace(/\n/g, ' ');
|
||||||
|
value = value.trim();
|
||||||
|
}
|
||||||
if (value == "") {
|
if (value == "") {
|
||||||
value = "\t";
|
value = "\t";
|
||||||
}
|
}
|
||||||
|
value = value.replace(/˂/g, '<');
|
||||||
|
value = value.replace(/˃/g, '>');
|
||||||
uci.set('zapret', this.cfgsec, this.cfgparam, value);
|
uci.set('zapret', this.cfgsec, this.cfgparam, value);
|
||||||
uci.save();
|
uci.save();
|
||||||
let elem = document.getElementById("cbi-zapret-" + this.cfgsec + "-_" + this.cfgparam);
|
let elem = document.getElementById("cbi-zapret-" + this.cfgsec + "-_" + this.cfgparam);
|
||||||
if (elem) {
|
if (elem) {
|
||||||
elem.querySelector('div').textContent = value;
|
let val = value.trim();
|
||||||
|
if (this.multiline) {
|
||||||
|
val = val.replace(/</g, '˂');
|
||||||
|
val = val.replace(/>/g, '˃');
|
||||||
|
val = val.replace(/\n/g, '<br/>');
|
||||||
|
elem.querySelector('div').innerHTML = val;
|
||||||
|
} else {
|
||||||
|
elem.querySelector('div').textContent = val;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ui.hideModal();
|
ui.hideModal();
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user