mirror of https://github.com/MISP/MISP
Fixed adding / removing tags to a template, fixes #898
parent
b8591674ef
commit
07a03abdc7
|
@ -49,7 +49,6 @@ class TemplatesController extends AppController {
|
||||||
|
|
||||||
if ($this->request->is('post') || $this->request->is('put')) {
|
if ($this->request->is('post') || $this->request->is('put')) {
|
||||||
$this->request->data['Template']['id'] = $id;
|
$this->request->data['Template']['id'] = $id;
|
||||||
|
|
||||||
unset($this->request->data['Template']['tagsPusher']);
|
unset($this->request->data['Template']['tagsPusher']);
|
||||||
$tags = $this->request->data['Template']['tags'];
|
$tags = $this->request->data['Template']['tags'];
|
||||||
unset($this->request->data['Template']['tags']);
|
unset($this->request->data['Template']['tags']);
|
||||||
|
@ -67,7 +66,7 @@ class TemplatesController extends AppController {
|
||||||
|
|
||||||
$newTags = $this->TemplateTag->Tag->find('all', array(
|
$newTags = $this->TemplateTag->Tag->find('all', array(
|
||||||
'recursive' => -1,
|
'recursive' => -1,
|
||||||
'conditions' => array('name' => $tagArray)
|
'conditions' => array('id' => $tagArray)
|
||||||
));
|
));
|
||||||
|
|
||||||
foreach($oldTags as $k => $oT) {
|
foreach($oldTags as $k => $oT) {
|
||||||
|
@ -147,7 +146,7 @@ class TemplatesController extends AppController {
|
||||||
$this->loadModel('Tag');
|
$this->loadModel('Tag');
|
||||||
foreach ($tagArray as $t) {
|
foreach ($tagArray as $t) {
|
||||||
$tag = $this->Tag->find('first', array(
|
$tag = $this->Tag->find('first', array(
|
||||||
'conditions' => array('name' => $t),
|
'conditions' => array('id' => $t),
|
||||||
'fields' => array('id', 'name'),
|
'fields' => array('id', 'name'),
|
||||||
'recursive' => -1,
|
'recursive' => -1,
|
||||||
));
|
));
|
||||||
|
|
|
@ -56,7 +56,7 @@ var selectedTags = [
|
||||||
<?php
|
<?php
|
||||||
foreach ($currentTags as $k => $t) {
|
foreach ($currentTags as $k => $t) {
|
||||||
if ($k != 0) echo ', ';
|
if ($k != 0) echo ', ';
|
||||||
echo '"' . $t['Tag']['name'] . '"';
|
echo '"' . $t['Tag']['id'] . '"';
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
];
|
];
|
||||||
|
|
|
@ -720,26 +720,38 @@ function cancelPopoverForm() {
|
||||||
$('#popover_form').fadeOut();
|
$('#popover_form').fadeOut();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function activateTagField() {
|
||||||
|
$("#addTagButton").hide();
|
||||||
|
$("#addTagField").show();
|
||||||
|
}
|
||||||
|
|
||||||
function appendTemplateTag(selected) {
|
function tagFieldChange() {
|
||||||
var selectedTag;
|
if ($("#addTagField :selected").val() > 0) {
|
||||||
allTags.forEach(function(tag) {
|
var selected_id = $("#addTagField :selected").val();
|
||||||
if (tag.name == selected) {
|
var selected_text = $("#addTagField :selected").text();
|
||||||
$.ajax({
|
if ($.inArray(selected_id, selectedTags)==-1) {
|
||||||
beforeSend: function (XMLHttpRequest) {
|
selectedTags.push(selected_id);
|
||||||
$(".loading").show();
|
appendTemplateTag(selected_id);
|
||||||
},
|
|
||||||
dataType:"html",
|
|
||||||
cache: false,
|
|
||||||
success:function (data, textStatus) {
|
|
||||||
$(".loading").hide();
|
|
||||||
$("#tags").append(data);
|
|
||||||
},
|
|
||||||
url:"/tags/viewTag/" + tag.id,
|
|
||||||
});
|
|
||||||
updateSelectedTags();
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
$("#addTagButton").show();
|
||||||
|
$("#addTagField").hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
function appendTemplateTag(selected_id) {
|
||||||
|
$.ajax({
|
||||||
|
beforeSend: function (XMLHttpRequest) {
|
||||||
|
$(".loading").show();
|
||||||
|
},
|
||||||
|
dataType:"html",
|
||||||
|
cache: false,
|
||||||
|
success:function (data, textStatus) {
|
||||||
|
$(".loading").hide();
|
||||||
|
$("#tags").append(data);
|
||||||
|
},
|
||||||
|
url:"/tags/viewTag/" + selected_id,
|
||||||
});
|
});
|
||||||
|
updateSelectedTags();
|
||||||
}
|
}
|
||||||
|
|
||||||
function addAllTags(tagArray) {
|
function addAllTags(tagArray) {
|
||||||
|
@ -751,8 +763,8 @@ function addAllTags(tagArray) {
|
||||||
|
|
||||||
function removeTemplateTag(id, name) {
|
function removeTemplateTag(id, name) {
|
||||||
selectedTags.forEach(function(tag) {
|
selectedTags.forEach(function(tag) {
|
||||||
if (tag == name) {
|
if (tag == id) {
|
||||||
var index = selectedTags.indexOf(name);
|
var index = selectedTags.indexOf(id);
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
selectedTags.splice(index, 1);
|
selectedTags.splice(index, 1);
|
||||||
updateSelectedTags();
|
updateSelectedTags();
|
||||||
|
@ -2187,3 +2199,4 @@ function mergeOrganisationTypeToggle() {
|
||||||
$('#orgsExternal').show();
|
$('#orgsExternal').show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue