This repository has been archived by the owner on Dec 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsettings-rules.js
57 lines (53 loc) · 1.93 KB
/
settings-rules.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
$("#rules-menuitem").on('click', function() {
var template = settingsRulesDoc.querySelector("#syntactical-rules")
var htmlContent = document.importNode(template, true)
var checkOptionTemplate = settingsRulesDoc.querySelector('#rule-checkbox')
$.get(ADDR+"api/syntactical-rules", function(data) {
jQuery.each(data, function(tabname, values){
var tableSelector = "#"+tabname+"-body";
var div = create_rules_div()
for(var i=0; i<values.length; i++){
var jsonObj = values[i];
var htmlOpt = get_rule_option(jsonObj, checkOptionTemplate)
div.appendChild(htmlOpt);
}
htmlContent.querySelector(tableSelector).appendChild(div);
});
open_rules_dialog("<b>Active rules</b>", htmlContent);
}, "json");
});
function create_rules_div(){
var div = document.createElement("div")
div.style.overflow = "auto";
div.style.height = "300px";
return div
}
function get_rule_option(jsonObj, checkTemplate){
var htmlOpt = document.importNode(checkTemplate, true)
var isChecked = false; var name = ""; var description = "";
for (var key in jsonObj){
var attrValue = jsonObj[key];
if(key==="name") name = attrValue;
if(key==="description") description = attrValue;
if(key==="ruleActived") isChecked = attrValue;
}
htmlOpt.querySelector('label').innerHTML = "<input id=\""+name.toLowerCase().replace(" ","-")+"\"type=\"checkbox\">"+description;
if(isChecked) htmlOpt.querySelector('input').checked = "checked";
return htmlOpt;
}
function open_rules_dialog(dialogName, htmlContent){
var dialog = new BootstrapDialog({
type: BootstrapDialog.TYPE_DEFAULT,
size: BootstrapDialog.SIZE_NORMAL,
title: dialogName,
animate:false,
autospin: true,
message: htmlContent,
hotkey:13, //enter
buttons: [{label: 'Close', autospin: true, cssClass: 'btn-primary',
action: function(dialog){ dialog.close(); }
}]
});
dialog.open();
dialog.getModal().css('background-color','rgba(255,255,255,0.3)');
}