mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 15:39:33 +00:00
Rework Preference Panes
This commit is contained in:
parent
7d82c7b897
commit
5d2f1f4c03
3 changed files with 555 additions and 260 deletions
|
|
@ -20,39 +20,59 @@ end
|
|||
-- ############################################
|
||||
-- Runtime preference
|
||||
|
||||
function prefsInputField(label, comment, key, value, _input_type)
|
||||
function prefsInputFieldPrefs(label, comment, prekey, key, default_value, _input_type, showEnabled)
|
||||
|
||||
k = prekey..key
|
||||
|
||||
if(_GET[key] ~= nil) then
|
||||
k = "ntopng.prefs."..key
|
||||
v_s = _GET[key]
|
||||
v = tonumber(v_s)
|
||||
if(v ~= nil and (v > 0) and (v <= 86400)) then
|
||||
ntop.setCache(k, tostring(v))
|
||||
value = v
|
||||
elseif (v_s ~= nil) then
|
||||
ntop.setCache(k, v_s)
|
||||
value = v_s
|
||||
|
||||
v_cache = ntop.getCache(k)
|
||||
value = v_cache
|
||||
if ((v_cache==nil) or (v ~= v_cache)) then
|
||||
|
||||
if(v ~= nil and (v > 0) and (v <= 86400)) then
|
||||
ntop.setCache(k, tostring(v))
|
||||
value = v
|
||||
elseif (v_s ~= nil) then
|
||||
v_s = string.gsub(v_s, "ldaps:__", "ldaps://")
|
||||
v_s = string.gsub(v_s, "ldap:__", "ldap://")
|
||||
ntop.setCache(k, v_s)
|
||||
value = v_s
|
||||
end
|
||||
-- least but not last we ascynchronously notify the runtime ntopng instance for changes
|
||||
notifyNtopng(key)
|
||||
end
|
||||
else
|
||||
v_s = ntop.getCache(k)
|
||||
value = v_s
|
||||
if((v_s==nil) or (v_s=="")) then
|
||||
ntop.setCache(k, tostring(default_value))
|
||||
value = default_value
|
||||
notifyNtopng(key)
|
||||
end
|
||||
-- least but not last we ascynchronously notify the runtime ntopng instance for changes
|
||||
notifyNtopng(key)
|
||||
end
|
||||
|
||||
if ((showEnabled == nil) or (showEnabled == true)) then
|
||||
showEnabled = "table-row"
|
||||
else
|
||||
showEnabled = "none"
|
||||
end
|
||||
|
||||
local input_type = "text"
|
||||
if _input_type ~= nil then input_type = _input_type end
|
||||
print('<tr><td width=50%><strong>'..label..'</strong><p><small>'..comment..'</small></td>')
|
||||
print('<tr id="'..key..'" style="display: '..showEnabled..';"><td width=50%><strong>'..label..'</strong><p><small>'..comment..'</small></td>')
|
||||
|
||||
print [[
|
||||
<td class="input-group col-lg-3" align=right><form class="navbar-form navbar-right">]]
|
||||
print('<input id="csrf" name="csrf" type="hidden" value="'..ntop.getRandomCSRFValue()..'" />\n')
|
||||
<td class="input-group col-lg-3" align=right>]]
|
||||
print [[
|
||||
<div class="input-group" >
|
||||
<div class="input-group" >
|
||||
<div >
|
||||
<span class="input-group-btn">
|
||||
<input type="]] print(input_type) print [[" class="form-control" name="]] print(key) print [[" value="]] print(value.."") print [[">
|
||||
|
||||
<button class="btn btn-default" type="submit">Save</button>
|
||||
</span>
|
||||
<input id="id_input_]] print(key) print[["type="]] print(input_type) print [[" class="form-control" name="]] print(key) print [[" style="text-align:right;" value="]] print(value.."") print [[">
|
||||
</div>
|
||||
</div><!-- /input-group -->
|
||||
</form></td></tr>
|
||||
</td></tr>
|
||||
]]
|
||||
|
||||
end
|
||||
|
|
@ -87,14 +107,112 @@ function toggleTableButton(label, comment, on_label, on_value, on_color , off_la
|
|||
print('<button type="submit" '..disabled..' class="btn btn-sm '..on_active..'">'..on_label..'</button>')
|
||||
print('<button '..disabled..' class="btn btn-sm '..off_active..'">'..off_label..'</button></div>\n')
|
||||
print('<input id="csrf" name="csrf" type="hidden" value="'..ntop.getRandomCSRFValue()..'" />\n')
|
||||
print('<input type=hidden name='..submit_field..' value='..rev_value..'>\n')
|
||||
print('<input type=hidden name='..submit_field..' value='..rev_value..' />\n')
|
||||
print('</form>\n')
|
||||
if(label ~= "") then print('</td></tr>') end
|
||||
|
||||
return(value)
|
||||
end
|
||||
|
||||
function multipleTableButton(label, comment, array_labels, array_values, default_value, selected_color, submit_field, redis_key, disabled)
|
||||
function toggleTableButtonPrefs(label, comment, on_label, on_value, on_color , off_label, off_value, off_color, submit_field,
|
||||
redis_key, default_value, disabled, elementToSwitch, hideOn, showElement)
|
||||
|
||||
value = ntop.getCache(redis_key)
|
||||
if(_GET[submit_field] ~= nil) then
|
||||
if ( (value == nil) or (value ~= _GET[submit_field])) then
|
||||
ntop.setCache(redis_key, _GET[submit_field])
|
||||
value = _GET[submit_field]
|
||||
notifyNtopng(submit_field)
|
||||
end
|
||||
else
|
||||
if ((value == nil) or (value == "")) then
|
||||
if (default_value ~= nil) then
|
||||
value = default_value
|
||||
else
|
||||
value = off_value
|
||||
end
|
||||
ntop.setCache(redis_key, value)
|
||||
notifyNtopng(submit_field)
|
||||
end
|
||||
end
|
||||
|
||||
if (disabled == true) then
|
||||
disabled = 'disabled = ""'
|
||||
else
|
||||
disabled = ""
|
||||
end
|
||||
|
||||
-- Read it anyway to
|
||||
if(value == off_value) then
|
||||
on_active = "btn-default"
|
||||
off_active = "btn-"..off_color.." active"
|
||||
else
|
||||
value = on_value
|
||||
on_active = "btn-"..on_color.." active"
|
||||
off_active = "btn-default"
|
||||
end
|
||||
|
||||
local objRow = ""
|
||||
if ((showElement ~= nil) and (showElement == false)) then
|
||||
objRow = " style=\"display:none\""
|
||||
else
|
||||
objRow = " style=\"display:table-row\""
|
||||
end
|
||||
if(label ~= "") then print('<tr id="row_'..submit_field..'"'..objRow..'><td width=50%><strong>'..label..'</strong><p><small>'..comment..'</small></td><td align=right>\n') end
|
||||
print('<div class="btn-group btn-toggle">')
|
||||
print('<button type="button" onclick="'..submit_field..'_functionOn()" id="'..submit_field..'_on_id" '..disabled..' class="btn btn-sm '..on_active..'">'..on_label..'</button>')
|
||||
print('<button type="button" onclick="'..submit_field..'_functionOff()" id="'..submit_field..'_off_id" '..disabled..' class="btn btn-sm '..off_active..'">'..off_label..'</button></div>\n')
|
||||
print('<input type=hidden id="'..submit_field..'_input" name='..submit_field..' value="'..value..'"/>\n')
|
||||
if(label ~= "") then print('</td></tr>') end
|
||||
print('\n')
|
||||
print('<script>\n')
|
||||
print[[function ]] print(submit_field) print [[_functionOn(){
|
||||
var classOn = document.getElementById("]] print(submit_field) print [[_on_id");
|
||||
var classOff = document.getElementById("]] print(submit_field) print [[_off_id");
|
||||
classOn.removeAttribute("class");
|
||||
classOff.removeAttribute("class");
|
||||
classOn.setAttribute("class", "btn btn-sm btn-]]print(on_color) print[[ active");
|
||||
classOff.setAttribute("class", "btn btn-sm btn-default");
|
||||
$("#]] print(submit_field) print [[_input").val("]] print(on_value) print[[");]]
|
||||
if elementToSwitch ~= nil then
|
||||
for element = 1, #elementToSwitch do
|
||||
if ((hideOn == nil) or (hideOn == false)) then
|
||||
print('$("#'..elementToSwitch[element]..'").css("display","table-row");')
|
||||
else
|
||||
print('$("#'..elementToSwitch[element]..'").css("display","none");')
|
||||
end
|
||||
end
|
||||
end
|
||||
print[[
|
||||
}
|
||||
]]
|
||||
print[[
|
||||
function ]] print(submit_field) print [[_functionOff(){
|
||||
var classOn = document.getElementById("]] print(submit_field) print [[_on_id");
|
||||
var classOff = document.getElementById("]] print(submit_field) print [[_off_id");
|
||||
classOn.removeAttribute("class");
|
||||
classOff.removeAttribute("class");
|
||||
classOn.setAttribute("class", "btn btn-sm btn-default");
|
||||
classOff.setAttribute("class", "btn btn-sm btn-]]print(off_color) print[[ active");
|
||||
$("#]] print(submit_field) print [[_input").val("]]print(off_value) print[[");]]
|
||||
if elementToSwitch ~= nil then
|
||||
for element = 1, #elementToSwitch do
|
||||
if ((hideOn == nil) or (hideOn == false)) then
|
||||
print('$("#'..elementToSwitch[element]..'").css("display","none");')
|
||||
else
|
||||
print('$("#'..elementToSwitch[element]..'").css("display","table-row");')
|
||||
end
|
||||
end
|
||||
end
|
||||
print [[
|
||||
}]]
|
||||
print('</script>\n')
|
||||
return(value)
|
||||
end
|
||||
|
||||
function multipleTableButtonPrefs(label, comment, array_labels, array_values, default_value, selected_color,
|
||||
submit_field, redis_key, disabled, elementToSwitch, showElementArray,
|
||||
javascriptAfterSwitch, showElement)
|
||||
if(_GET[submit_field] ~= nil) then
|
||||
ntop.setCache(redis_key, _GET[submit_field])
|
||||
value = _GET[submit_field]
|
||||
|
|
@ -115,9 +233,15 @@ function multipleTableButton(label, comment, array_labels, array_values, default
|
|||
disabled = ""
|
||||
end
|
||||
|
||||
local objRow = ""
|
||||
if ((showElement ~= nil) and (showElement == false)) then
|
||||
objRow = " style=\"display:none\""
|
||||
else
|
||||
objRow = " style=\"display:table-row\""
|
||||
end
|
||||
if(value ~= nil) then
|
||||
if(label ~= "") then print('<tr><td width=50%><strong>'..label..'</strong><p><small>'..comment..'</small></td><td align=right>\n') end
|
||||
print('<form id="form-'..submit_field..'">\n<div class="btn-group" data-toggle="buttons-radio" data-toggle-name="'..submit_field..'">')
|
||||
if(label ~= "") then print('<tr id="row_'..submit_field..'"'..objRow..'><td width=50%><strong>'..label..'</strong><p><small>'..comment..'</small></td><td align=right>\n') end
|
||||
print('<div class="btn-group" data-toggle="buttons-radio" data-toggle-name="'..submit_field..'">')
|
||||
|
||||
for nameCount = 1, #array_labels do
|
||||
local type_button = "btn-default"
|
||||
|
|
@ -127,17 +251,43 @@ function multipleTableButton(label, comment, array_labels, array_values, default
|
|||
print('<button id="id_'..array_values[nameCount]..'" value="'..array_values[nameCount]..'" type="button" class="btn btn-sm '..type_button..'" data-toggle="button">'..array_labels[nameCount]..'</button>\n')
|
||||
end
|
||||
print('</div>\n')
|
||||
print('<input id="csrf" name="csrf" type="hidden" value="'..ntop.getRandomCSRFValue()..'" />\n')
|
||||
print('<input type="hidden" id="id-toggle-'..submit_field..'" name="'..submit_field..'" value="'..value..'" />\n')
|
||||
print('</form>\n')
|
||||
print('<script>\n')
|
||||
for nameCount = 1, #array_labels do
|
||||
print('$("#id_'..array_values[nameCount]..'").click(function() {\n')
|
||||
print(' $(\'#id-toggle-'..submit_field..'\').val("'..array_values[nameCount]..'");\n')
|
||||
|
||||
print('$("#id_'..array_values[nameCount]..'").click(function() {\n')
|
||||
print(' $(\'#id-toggle-'..submit_field..'\').val("'..array_values[nameCount]..'");\n')
|
||||
print(' $(\'#form-'..submit_field..'\').submit();\n')
|
||||
print('});\n')
|
||||
for indexLabel = 1, #array_labels do
|
||||
print[[ var class_]] print(array_values[indexLabel]) print[[ = document.getElementById("id_]] print(array_values[indexLabel]) print [[");
|
||||
class_]] print(array_values[indexLabel]) print[[.removeAttribute("class");]]
|
||||
if(array_values[indexLabel] == array_values[nameCount]) then
|
||||
print[[class_]] print(array_values[indexLabel]) print[[.setAttribute("class", "btn btn-sm btn-]]print(selected_color) print[[ active");]]
|
||||
else
|
||||
print[[class_]] print(array_values[indexLabel]) print[[.setAttribute("class", "btn btn-sm btn-default");]]
|
||||
end
|
||||
end
|
||||
|
||||
if (showElementArray ~= nil) then
|
||||
for indexSwitch = 1, #showElementArray do
|
||||
if (indexSwitch == nameCount) then
|
||||
if elementToSwitch ~= nil then
|
||||
for element = 1, #elementToSwitch do
|
||||
if (showElementArray[indexSwitch] == true) then
|
||||
print('$("#'..elementToSwitch[element]..'").css("display","table-row");\n')
|
||||
else
|
||||
print('$("#'..elementToSwitch[element]..'").css("display","none");\n')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if javascriptAfterSwitch ~= nil then
|
||||
print(javascriptAfterSwitch)
|
||||
end
|
||||
|
||||
print('});\n')
|
||||
end
|
||||
print('</script>\n')
|
||||
if(label ~= "") then print('</td></tr>') end
|
||||
|
|
@ -145,65 +295,3 @@ function multipleTableButton(label, comment, array_labels, array_values, default
|
|||
|
||||
return(value)
|
||||
end
|
||||
|
||||
function prefsInputFieldWithParamCheck(label, comment, pre_key, key, value, _input_type, js_body_funtion_check)
|
||||
if(_GET[key] ~= nil) then
|
||||
k = pre_key.."."..key
|
||||
v_s = _GET[key]
|
||||
v = tonumber(v_s)
|
||||
if(v ~= nil and (v > 0) and (v <= 86400)) then
|
||||
ntop.setCache(k, tostring(v))
|
||||
value = v
|
||||
elseif (v_s ~= nil) then
|
||||
-- fix for ldap preference
|
||||
v_s = string.gsub(v_s, "ldaps:__", "ldaps://")
|
||||
v_s = string.gsub(v_s, "ldap:__", "ldap://")
|
||||
ntop.setCache(k, v_s)
|
||||
value = v_s
|
||||
end
|
||||
-- least but not last we ascynchronously notify the runtime ntopng instance for changes
|
||||
notifyNtopng(key)
|
||||
end
|
||||
local input_type = "text"
|
||||
if _input_type ~= nil then input_type = _input_type end
|
||||
print('<tr><td width=50%><strong>'..label..'</strong><p><small>'..comment..'</small></td>')
|
||||
|
||||
print [[
|
||||
<td class="input-group col-lg-3" align=right><form id="form-]] print(key) print [[" class="navbar-form navbar-right">]]
|
||||
print('<input id="csrf" name="csrf" type="hidden" value="'..ntop.getRandomCSRFValue()..'" />\n')
|
||||
print [[
|
||||
<div class="input-group" >
|
||||
<div >
|
||||
<span class="input-group-btn">
|
||||
<input id="input_]] print(key) print [[" type="]] print(input_type) print [[" class="form-control" name="]] print(key) print [[" value="]] print(value.."") print [[">
|
||||
|
||||
<button id="button_]] print(key) print [[" class="btn btn-default" type="button">Save</button>
|
||||
</span>
|
||||
</div>
|
||||
</div><!-- /input-group -->
|
||||
<script>
|
||||
]]
|
||||
|
||||
print('function check_field_'..key..'(field){\n')
|
||||
if (js_body_funtion_check ~= nil and js_body_funtion_check ~= "") then
|
||||
print(js_body_funtion_check)
|
||||
else
|
||||
print("return \"\";\n")
|
||||
end
|
||||
print('}\n')
|
||||
|
||||
print('$("#button_'..key..'").click(function() {\n')
|
||||
print(' var result = check_field_'..key..'($("#input_'..key..'").val());\n')
|
||||
print(' if(result!=""){\n')
|
||||
print(' alert(result);\n')
|
||||
print(' return;\n')
|
||||
print(' }\n')
|
||||
print(' $(\'#form-'..key..'\').submit();\n')
|
||||
print('});\n')
|
||||
|
||||
print [[ </script>
|
||||
</form>
|
||||
</td></tr>
|
||||
]]
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue