mirror of https://github.com/MISP/MISP
chg: [element:serverRuleElements] Rules are parsed and build on rules_widget container
They can later be recovered by external commands without having to rely on fixed HTML ID propertiespull/7354/head
parent
4b4f9c6bda
commit
4c84a00aaa
|
@ -130,6 +130,7 @@ function initRuleWidgetPicker<?= $seed ?>() {
|
|||
deleteSelectedRules($select, $pickerSelect)
|
||||
}
|
||||
});
|
||||
rebuildRules($('.container-seed-<?= $seed ?>'))
|
||||
}
|
||||
|
||||
function deleteSelectedRules($select, $pickerSelect) {
|
||||
|
@ -144,6 +145,7 @@ function deleteSelectedRules($select, $pickerSelect) {
|
|||
$item.remove()
|
||||
})
|
||||
$pickerSelect.trigger('chosen:updated')
|
||||
rebuildRules($select.closest('.rules-widget-container'))
|
||||
}
|
||||
|
||||
function handleDeleteButtonClick(targetClass, clicked) {
|
||||
|
@ -179,6 +181,7 @@ function moveItemToSelect($target, $source) {
|
|||
}));
|
||||
}
|
||||
$source.remove()
|
||||
rebuildRules($target.closest('.rules-widget-container'))
|
||||
}
|
||||
|
||||
function addItemToSelect($target, data) {
|
||||
|
@ -188,6 +191,7 @@ function addItemToSelect($target, data) {
|
|||
text : data
|
||||
}));
|
||||
}
|
||||
rebuildRules($target.closest('.rules-widget-container'))
|
||||
}
|
||||
|
||||
function getValuesFromSelect($select) {
|
||||
|
@ -197,6 +201,15 @@ function getValuesFromSelect($select) {
|
|||
})
|
||||
return values
|
||||
}
|
||||
|
||||
function rebuildRules($ruleContainer) {
|
||||
var tmpRules = {}
|
||||
var $selectAllow = $ruleContainer.find('select.rules-allow')
|
||||
var $selectBlock = $ruleContainer.find('select.rules-block')
|
||||
tmpRules['OR'] = getValuesFromSelect($selectAllow)
|
||||
tmpRules['NOT'] = getValuesFromSelect($selectBlock)
|
||||
$ruleContainer.data('rules', tmpRules)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
|
|
@ -239,7 +239,7 @@
|
|||
'class' => 'pull-rule-modal',
|
||||
'confirm' => [
|
||||
'title' => __('Update'),
|
||||
'onclick' => "submitServerRulePopulateTagPicklistValues('pull');"
|
||||
'onclick' => "serverRulesUpdateState('pull');"
|
||||
]
|
||||
];
|
||||
echo $this->element('genericElements/infoModal', $modalData);
|
||||
|
|
|
@ -243,7 +243,7 @@
|
|||
'class' => 'pull-rule-modal',
|
||||
'confirm' => [
|
||||
'title' => __('Update'),
|
||||
'onclick' => "submitServerRulePopulateTagPicklistValues('pull');"
|
||||
'onclick' => "serverRulesUpdateState('pull');"
|
||||
]
|
||||
];
|
||||
echo $this->element('genericElements/infoModal', $modalData);
|
||||
|
|
|
@ -200,7 +200,7 @@
|
|||
'class' => 'push-rule-modal',
|
||||
'confirm' => [
|
||||
'title' => __('Update'),
|
||||
'onclick' => "submitServerRulePopulateTagPicklistValues('push');"
|
||||
'onclick' => "serverRulesUpdateState('push');"
|
||||
]
|
||||
];
|
||||
echo $this->element('genericElements/infoModal', $modalData);
|
||||
|
@ -210,7 +210,7 @@
|
|||
'ruleObject' => $pullRules
|
||||
]);
|
||||
$modalData['class'] = 'pull-rule-modal';
|
||||
$modalData['confirm']['onclick'] = "submitServerRulePopulateTagPicklistValues('pull');";
|
||||
$modalData['confirm']['onclick'] = "serverRulesUpdateState('pull');";
|
||||
echo $this->element('genericElements/infoModal', $modalData);
|
||||
?>
|
||||
</div>
|
||||
|
|
|
@ -51,7 +51,9 @@ foreach ($servers as $server):
|
|||
$ruleDescription[$syncOption] .= '<span class=\'bold\'>' . ucfirst($fieldOption) . ' ' . $typeData['text'] . '</span>: <span class=\'' . $typeData['colour'] . '\'>';
|
||||
foreach ($rules[$syncOption][$fieldOption][$typeOption] as $k => $temp) {
|
||||
if ($k != 0) $ruleDescription[$syncOption] .= ', ';
|
||||
if ($syncOption === 'push') $temp = $collection[$fieldOption][$temp];
|
||||
if ($syncOption === 'push') {
|
||||
$temp = !empty($collection[$fieldOption][$temp]) ? $collection[$fieldOption][$temp] : $temp;
|
||||
}
|
||||
$ruleDescription[$syncOption] .= h($temp);
|
||||
}
|
||||
$ruleDescription[$syncOption] .= '</span><br>';
|
||||
|
|
|
@ -3548,19 +3548,14 @@ function serverRuleGenerateJSON() {
|
|||
});
|
||||
}
|
||||
|
||||
function submitServerRulePopulateTagPicklistValues(context) {
|
||||
function serverRulesUpdateState(context) {
|
||||
var $rootContainer = $('.server-rule-container-' + context)
|
||||
validFields.forEach(function(field) {
|
||||
rules[context][field]["OR"] = [];
|
||||
$("#" + field + context + "LeftValues option").each(function() {
|
||||
rules[context][field]["OR"].push($(this).val());
|
||||
});
|
||||
rules[context][field]["NOT"] = [];
|
||||
$("#" + field + context + "RightValues option").each(function() {
|
||||
rules[context][field]["NOT"].push($(this).val());
|
||||
});
|
||||
});
|
||||
var $fieldContainer = $rootContainer.find('.scope-' + field)
|
||||
rules[context][field] = $fieldContainer.data('rules')
|
||||
})
|
||||
if (context === 'pull') {
|
||||
rules[context]["url_params"] = $('#urlParams').val();
|
||||
rules[context]["url_params"] = $rootContainer.find('textarea#urlParams').val();
|
||||
}
|
||||
serverRuleUpdate();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue