mirror of https://github.com/MISP/MISP
Merge branch '2.4' of github.com:MISP/MISP into 2.4
commit
4f7a034a91
2
PyMISP
2
PyMISP
|
@ -1 +1 @@
|
|||
Subproject commit 166ef3866dfefbc2456a394b55fb5f9819f257b8
|
||||
Subproject commit cc35d81fa3e07884607dae196ff98e2311b21371
|
|
@ -46,7 +46,7 @@ class AppController extends Controller
|
|||
|
||||
public $helpers = array('Utility', 'OrgImg');
|
||||
|
||||
private $__queryVersion = '61';
|
||||
private $__queryVersion = '62';
|
||||
public $pyMispVersion = '2.4.103';
|
||||
public $phpmin = '7.0';
|
||||
public $phprec = '7.2';
|
||||
|
|
|
@ -2995,10 +2995,6 @@ class AttributesController extends AppController
|
|||
|
||||
public function addTag($id = false, $tag_id = false)
|
||||
{
|
||||
if (!$this->request->is('post')) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'You don\'t have permission to do that. Only POST requests are accepted.')), 'status' => 200, 'type' => 'json'));
|
||||
}
|
||||
|
||||
$rearrangeRules = array(
|
||||
'request' => false,
|
||||
'Attribute' => false,
|
||||
|
@ -3014,140 +3010,148 @@ class AttributesController extends AppController
|
|||
if ($id === 'selected') {
|
||||
$idList = json_decode($this->request->data['attribute_ids'], true);
|
||||
}
|
||||
if ($tag_id === false) {
|
||||
$tag_id = $this->request->data['tag'];
|
||||
}
|
||||
if (!is_numeric($tag_id)) {
|
||||
if (preg_match('/^collection_[0-9]+$/i', $tag_id)) {
|
||||
$tagChoice = explode('_', $tag_id)[1];
|
||||
$this->loadModel('TagCollection');
|
||||
$tagCollection = $this->TagCollection->fetchTagCollection($this->Auth->user(), array('conditions' => array('TagCollection.id' => $tagChoice)));
|
||||
if (empty($tagCollection)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Invalid Tag Collection.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
$tag_id_list = array();
|
||||
foreach ($tagCollection[0]['TagCollectionTag'] as $tagCollectionTag) {
|
||||
$tag_id_list[] = $tagCollectionTag['tag_id'];
|
||||
}
|
||||
} else {
|
||||
// try to parse json array
|
||||
$tag_ids = json_decode($tag_id);
|
||||
if ($tag_ids !== null) { // can decode json
|
||||
$tag_id_list = array();
|
||||
foreach ($tag_ids as $tag_id) {
|
||||
if (preg_match('/^collection_[0-9]+$/i', $tag_id)) {
|
||||
$tagChoice = explode('_', $tag_id)[1];
|
||||
$this->loadModel('TagCollection');
|
||||
$tagCollection = $this->TagCollection->fetchTagCollection($this->Auth->user(), array('conditions' => array('TagCollection.id' => $tagChoice)));
|
||||
if (empty($tagCollection)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Invalid Tag Collection.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
foreach ($tagCollection[0]['TagCollectionTag'] as $tagCollectionTag) {
|
||||
$tag_id_list[] = $tagCollectionTag['tag_id'];
|
||||
}
|
||||
} else {
|
||||
$tag_id_list[] = $tag_id;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$tag = $this->Event->EventTag->Tag->find('first', array('recursive' => -1, 'conditions' => $conditions));
|
||||
if (empty($tag)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Invalid Tag.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
$tag_id = $tag['Tag']['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isset($idList)) {
|
||||
$idList = array($id);
|
||||
}
|
||||
if (empty($tag_id_list)) {
|
||||
$tag_id_list = array($tag_id);
|
||||
}
|
||||
$success = 0;
|
||||
$fails = 0;
|
||||
foreach ($idList as $id) {
|
||||
$this->Attribute->id = $id;
|
||||
if (!$this->Attribute->exists()) {
|
||||
throw new NotFoundException(__('Invalid attribute'));
|
||||
}
|
||||
$this->Attribute->read();
|
||||
if (!$this->_isSiteAdmin() && $this->Attribute->data['Event']['orgc_id'] !== $this->Auth->user('org_id')) {
|
||||
$fails++;
|
||||
continue;
|
||||
}
|
||||
if ($this->Attribute->data['Attribute']['deleted']) {
|
||||
throw new NotFoundException(__('Invalid attribute'));
|
||||
}
|
||||
$eventId = $this->Attribute->data['Attribute']['event_id'];
|
||||
$this->Attribute->Event->recursive = -1;
|
||||
$event = $this->Attribute->Event->read(array(), $eventId);
|
||||
if (!$this->_isSiteAdmin() && !$this->userRole['perm_sync']) {
|
||||
if (!$this->userRole['perm_tagger'] || ($this->Auth->user('org_id') !== $event['Event']['org_id'] && $this->Auth->user('org_id') !== $event['Event']['orgc_id'])) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'You don\'t have permission to do that.')), 'status' => 200, 'type' => 'json'));
|
||||
}
|
||||
}
|
||||
if (!$this->_isRest()) {
|
||||
$this->Attribute->Event->insertLock($this->Auth->user(), $eventId);
|
||||
}
|
||||
$this->Attribute->recursive = -1;
|
||||
|
||||
foreach ($tag_id_list as $tag_id) {
|
||||
$this->Attribute->AttributeTag->Tag->id = $tag_id;
|
||||
if (!$this->Attribute->AttributeTag->Tag->exists()) {
|
||||
$fails++;
|
||||
continue;
|
||||
}
|
||||
$tag = $this->Attribute->AttributeTag->Tag->find('first', array(
|
||||
'conditions' => array('Tag.id' => $tag_id),
|
||||
'recursive' => -1,
|
||||
'fields' => array('Tag.name')
|
||||
));
|
||||
$found = $this->Attribute->AttributeTag->find('first', array(
|
||||
'conditions' => array(
|
||||
'attribute_id' => $id,
|
||||
'tag_id' => $tag_id
|
||||
),
|
||||
'recursive' => -1,
|
||||
));
|
||||
$this->autoRender = false;
|
||||
if (!empty($found)) {
|
||||
$fails++;
|
||||
continue;
|
||||
}
|
||||
$this->Attribute->AttributeTag->create();
|
||||
if ($this->Attribute->AttributeTag->save(array('attribute_id' => $id, 'tag_id' => $tag_id, 'event_id' => $eventId))) {
|
||||
$event['Event']['published'] = 0;
|
||||
$date = new DateTime();
|
||||
$event['Event']['timestamp'] = $date->getTimestamp();
|
||||
$this->Attribute->Event->save($event);
|
||||
$this->Attribute->data['Attribute']['timestamp'] = $date->getTimestamp();
|
||||
$this->Attribute->save($this->Attribute->data);
|
||||
$log = ClassRegistry::init('Log');
|
||||
$log->createLogEntry($this->Auth->user(), 'tag', 'Attribute', $id, 'Attached tag (' . $tag_id . ') "' . $tag['Tag']['name'] . '" to attribute (' . $id . ')', 'Attribute (' . $id . ') tagged as Tag (' . $tag_id . ')');
|
||||
$success++;
|
||||
} else {
|
||||
$fails++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($fails == 0) {
|
||||
if ($success == 1) {
|
||||
$message = 'Tag added.';
|
||||
} else {
|
||||
$message = $success . ' tags added.';
|
||||
}
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => $message, 'check_publish' => true)), 'status' => 200, 'type' => 'json'));
|
||||
if (!$this->request->is('post')) {
|
||||
$this->set('object_id', $id);
|
||||
$this->set('scope', 'Attribute');
|
||||
$this->layout = false;
|
||||
$this->autoRender = false;
|
||||
$this->render('/Events/add_tag');
|
||||
} else {
|
||||
if ($fails == 1) {
|
||||
$message = 'Tag could not be added.';
|
||||
if ($tag_id === false) {
|
||||
$tag_id = $this->request->data['tag'];
|
||||
}
|
||||
if (!is_numeric($tag_id)) {
|
||||
if (preg_match('/^collection_[0-9]+$/i', $tag_id)) {
|
||||
$tagChoice = explode('_', $tag_id)[1];
|
||||
$this->loadModel('TagCollection');
|
||||
$tagCollection = $this->TagCollection->fetchTagCollection($this->Auth->user(), array('conditions' => array('TagCollection.id' => $tagChoice)));
|
||||
if (empty($tagCollection)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Invalid Tag Collection.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
$tag_id_list = array();
|
||||
foreach ($tagCollection[0]['TagCollectionTag'] as $tagCollectionTag) {
|
||||
$tag_id_list[] = $tagCollectionTag['tag_id'];
|
||||
}
|
||||
} else {
|
||||
// try to parse json array
|
||||
$tag_ids = json_decode($tag_id);
|
||||
if ($tag_ids !== null) { // can decode json
|
||||
$tag_id_list = array();
|
||||
foreach ($tag_ids as $tag_id) {
|
||||
if (preg_match('/^collection_[0-9]+$/i', $tag_id)) {
|
||||
$tagChoice = explode('_', $tag_id)[1];
|
||||
$this->loadModel('TagCollection');
|
||||
$tagCollection = $this->TagCollection->fetchTagCollection($this->Auth->user(), array('conditions' => array('TagCollection.id' => $tagChoice)));
|
||||
if (empty($tagCollection)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Invalid Tag Collection.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
foreach ($tagCollection[0]['TagCollectionTag'] as $tagCollectionTag) {
|
||||
$tag_id_list[] = $tagCollectionTag['tag_id'];
|
||||
}
|
||||
} else {
|
||||
$tag_id_list[] = $tag_id;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$tag = $this->Event->EventTag->Tag->find('first', array('recursive' => -1, 'conditions' => $conditions));
|
||||
if (empty($tag)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Invalid Tag.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
$tag_id = $tag['Tag']['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isset($idList)) {
|
||||
$idList = array($id);
|
||||
}
|
||||
if (empty($tag_id_list)) {
|
||||
$tag_id_list = array($tag_id);
|
||||
}
|
||||
$success = 0;
|
||||
$fails = 0;
|
||||
foreach ($idList as $id) {
|
||||
$this->Attribute->id = $id;
|
||||
if (!$this->Attribute->exists()) {
|
||||
throw new NotFoundException(__('Invalid attribute'));
|
||||
}
|
||||
$this->Attribute->read();
|
||||
if (!$this->_isSiteAdmin() && $this->Attribute->data['Event']['orgc_id'] !== $this->Auth->user('org_id')) {
|
||||
$fails++;
|
||||
continue;
|
||||
}
|
||||
if ($this->Attribute->data['Attribute']['deleted']) {
|
||||
throw new NotFoundException(__('Invalid attribute'));
|
||||
}
|
||||
$eventId = $this->Attribute->data['Attribute']['event_id'];
|
||||
$this->Attribute->Event->recursive = -1;
|
||||
$event = $this->Attribute->Event->read(array(), $eventId);
|
||||
if (!$this->_isSiteAdmin() && !$this->userRole['perm_sync']) {
|
||||
if (!$this->userRole['perm_tagger'] || ($this->Auth->user('org_id') !== $event['Event']['org_id'] && $this->Auth->user('org_id') !== $event['Event']['orgc_id'])) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'You don\'t have permission to do that.')), 'status' => 200, 'type' => 'json'));
|
||||
}
|
||||
}
|
||||
if (!$this->_isRest()) {
|
||||
$this->Attribute->Event->insertLock($this->Auth->user(), $eventId);
|
||||
}
|
||||
$this->Attribute->recursive = -1;
|
||||
|
||||
foreach ($tag_id_list as $tag_id) {
|
||||
$this->Attribute->AttributeTag->Tag->id = $tag_id;
|
||||
if (!$this->Attribute->AttributeTag->Tag->exists()) {
|
||||
$fails++;
|
||||
continue;
|
||||
}
|
||||
$tag = $this->Attribute->AttributeTag->Tag->find('first', array(
|
||||
'conditions' => array('Tag.id' => $tag_id),
|
||||
'recursive' => -1,
|
||||
'fields' => array('Tag.name')
|
||||
));
|
||||
$found = $this->Attribute->AttributeTag->find('first', array(
|
||||
'conditions' => array(
|
||||
'attribute_id' => $id,
|
||||
'tag_id' => $tag_id
|
||||
),
|
||||
'recursive' => -1,
|
||||
));
|
||||
$this->autoRender = false;
|
||||
if (!empty($found)) {
|
||||
$fails++;
|
||||
continue;
|
||||
}
|
||||
$this->Attribute->AttributeTag->create();
|
||||
if ($this->Attribute->AttributeTag->save(array('attribute_id' => $id, 'tag_id' => $tag_id, 'event_id' => $eventId))) {
|
||||
$event['Event']['published'] = 0;
|
||||
$date = new DateTime();
|
||||
$event['Event']['timestamp'] = $date->getTimestamp();
|
||||
$this->Attribute->Event->save($event);
|
||||
$this->Attribute->data['Attribute']['timestamp'] = $date->getTimestamp();
|
||||
$this->Attribute->save($this->Attribute->data);
|
||||
$log = ClassRegistry::init('Log');
|
||||
$log->createLogEntry($this->Auth->user(), 'tag', 'Attribute', $id, 'Attached tag (' . $tag_id . ') "' . $tag['Tag']['name'] . '" to attribute (' . $id . ')', 'Attribute (' . $id . ') tagged as Tag (' . $tag_id . ')');
|
||||
$success++;
|
||||
} else {
|
||||
$fails++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($fails == 0) {
|
||||
if ($success == 1) {
|
||||
$message = 'Tag added.';
|
||||
} else {
|
||||
$message = $success . ' tags added.';
|
||||
}
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => $message, 'check_publish' => true)), 'status' => 200, 'type' => 'json'));
|
||||
} else {
|
||||
$message = $fails . ' tags could not be added.';
|
||||
if ($fails == 1) {
|
||||
$message = 'Tag could not be added.';
|
||||
} else {
|
||||
$message = $fails . ' tags could not be added.';
|
||||
}
|
||||
if ($success > 0) {
|
||||
$message .= ' However, ' . $success . ' tag(s) were added.';
|
||||
}
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => $message)), 'status' => 200, 'type' => 'json'));
|
||||
}
|
||||
if ($success > 0) {
|
||||
$message .= ' However, ' . $success . ' tag(s) were added.';
|
||||
}
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => $message)), 'status' => 200, 'type' => 'json'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3551,9 +3551,6 @@ class EventsController extends AppController
|
|||
|
||||
public function addTag($id = false, $tag_id = false)
|
||||
{
|
||||
if (!$this->request->is('post')) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'You don\'t have permission to do that.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
$rearrangeRules = array(
|
||||
'request' => false,
|
||||
'Event' => false,
|
||||
|
@ -3566,112 +3563,120 @@ class EventsController extends AppController
|
|||
if ($id === false) {
|
||||
$id = $this->request->data['event'];
|
||||
}
|
||||
if ($tag_id === false) {
|
||||
$tag_id = $this->request->data['tag'];
|
||||
}
|
||||
$conditions = array('LOWER(Tag.name) LIKE' => strtolower(trim($tag_id)));
|
||||
if (!$this->_isSiteAdmin()) {
|
||||
$conditions['Tag.org_id'] = array('0', $this->Auth->user('org_id'));
|
||||
$conditions['Tag.user_id'] = array('0', $this->Auth->user('id'));
|
||||
}
|
||||
if (!is_numeric($tag_id)) {
|
||||
if (preg_match('/^collection_[0-9]+$/i', $tag_id)) {
|
||||
$tagChoice = explode('_', $tag_id)[1];
|
||||
$this->loadModel('TagCollection');
|
||||
$tagCollection = $this->TagCollection->fetchTagCollection($this->Auth->user(), array('conditions' => array('TagCollection.id' => $tagChoice)));
|
||||
if (empty($tagCollection)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Invalid Tag Collection.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
$tag_id_list = array();
|
||||
foreach ($tagCollection[0]['TagCollectionTag'] as $tagCollectionTag) {
|
||||
$tag_id_list[] = $tagCollectionTag['tag_id'];
|
||||
}
|
||||
} else {
|
||||
$tag_ids = json_decode($tag_id);
|
||||
if ($tag_ids !== null) { // can decode json
|
||||
$tag_id_list = array();
|
||||
foreach ($tag_ids as $tag_id) {
|
||||
if (preg_match('/^collection_[0-9]+$/i', $tag_id)) {
|
||||
$tagChoice = explode('_', $tag_id)[1];
|
||||
$this->loadModel('TagCollection');
|
||||
$tagCollection = $this->TagCollection->fetchTagCollection($this->Auth->user(), array('conditions' => array('TagCollection.id' => $tagChoice)));
|
||||
if (empty($tagCollection)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Invalid Tag Collection.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
$tag_id_list = array();
|
||||
foreach ($tagCollection[0]['TagCollectionTag'] as $tagCollectionTag) {
|
||||
$tag_id_list[] = $tagCollectionTag['tag_id'];
|
||||
}
|
||||
} else {
|
||||
$tag_id_list[] = $tag_id;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$tag = $this->Event->EventTag->Tag->find('first', array('recursive' => -1, 'conditions' => $conditions));
|
||||
if (empty($tag)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Invalid Tag.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
$tag_id = $tag['Tag']['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->Event->recursive = -1;
|
||||
$event = $this->Event->read(array(), $id);
|
||||
if (empty($event)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Invalid event.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
if (!$this->_isSiteAdmin() && !$this->userRole['perm_sync']) {
|
||||
if (!$this->userRole['perm_tagger'] || ($this->Auth->user('org_id') !== $event['Event']['orgc_id'])) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'You don\'t have permission to do that.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
}
|
||||
$this->autoRender = false;
|
||||
$error = false;
|
||||
$success = false;
|
||||
if (empty($tag_id_list)) {
|
||||
$tag_id_list = array($tag_id);
|
||||
}
|
||||
foreach ($tag_id_list as $tag_id) {
|
||||
$this->Event->EventTag->Tag->id = $tag_id;
|
||||
if (!$this->Event->EventTag->Tag->exists()) {
|
||||
$error = __('Invalid Tag.');
|
||||
continue;
|
||||
}
|
||||
$tag = $this->Event->EventTag->Tag->find('first', array(
|
||||
'conditions' => array('Tag.id' => $tag_id),
|
||||
'recursive' => -1,
|
||||
'fields' => array('Tag.name')
|
||||
));
|
||||
$found = $this->Event->EventTag->find('first', array(
|
||||
'conditions' => array(
|
||||
'event_id' => $id,
|
||||
'tag_id' => $tag_id
|
||||
),
|
||||
'recursive' => -1,
|
||||
));
|
||||
if (!empty($found)) {
|
||||
$error = __('Tag is already attached to this event.');
|
||||
continue;
|
||||
}
|
||||
$this->Event->EventTag->create();
|
||||
if ($this->Event->EventTag->save(array('event_id' => $id, 'tag_id' => $tag_id))) {
|
||||
$event['Event']['published'] = 0;
|
||||
$date = new DateTime();
|
||||
$event['Event']['timestamp'] = $date->getTimestamp();
|
||||
$this->Event->save($event);
|
||||
$log = ClassRegistry::init('Log');
|
||||
$log->createLogEntry($this->Auth->user(), 'tag', 'Event', $id, 'Attached tag (' . $tag_id . ') "' . $tag['Tag']['name'] . '" to event (' . $id . ')', 'Event (' . $id . ') tagged as Tag (' . $tag_id . ')');
|
||||
$success = __('Tag(s) added.');
|
||||
} else {
|
||||
$fail = __('Tag could not be added.');
|
||||
}
|
||||
}
|
||||
if ($success) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => __('Tag(s) added.'), 'check_publish' => true)), 'status'=>200, 'type' => 'json'));
|
||||
} elseif (empty($fail)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => __('All tags are already present, nothing to add.'), 'check_publish' => true)), 'status'=>200, 'type' => 'json'));
|
||||
if (!$this->request->is('post')) {
|
||||
$this->set('object_id', $id);
|
||||
$this->set('scope', 'Event');
|
||||
$this->layout = false;
|
||||
$this->autoRender = false;
|
||||
$this->render('/Events/add_tag');
|
||||
} else {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => $fail)), 'status'=>200, 'type' => 'json'));
|
||||
if ($tag_id === false) {
|
||||
$tag_id = $this->request->data['tag'];
|
||||
}
|
||||
if (!$this->_isSiteAdmin() && !$this->userRole['perm_sync']) {
|
||||
if (!$this->userRole['perm_tagger'] || ($this->Auth->user('org_id') !== $event['Event']['orgc_id'])) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'You don\'t have permission to do that.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
}
|
||||
$conditions = array('LOWER(Tag.name) LIKE' => strtolower(trim($tag_id)));
|
||||
if (!$this->_isSiteAdmin()) {
|
||||
$conditions['Tag.org_id'] = array('0', $this->Auth->user('org_id'));
|
||||
$conditions['Tag.user_id'] = array('0', $this->Auth->user('id'));
|
||||
}
|
||||
if (!is_numeric($tag_id)) {
|
||||
if (preg_match('/^collection_[0-9]+$/i', $tag_id)) {
|
||||
$tagChoice = explode('_', $tag_id)[1];
|
||||
$this->loadModel('TagCollection');
|
||||
$tagCollection = $this->TagCollection->fetchTagCollection($this->Auth->user(), array('conditions' => array('TagCollection.id' => $tagChoice)));
|
||||
if (empty($tagCollection)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Invalid Tag Collection.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
$tag_id_list = array();
|
||||
foreach ($tagCollection[0]['TagCollectionTag'] as $tagCollectionTag) {
|
||||
$tag_id_list[] = $tagCollectionTag['tag_id'];
|
||||
}
|
||||
} else {
|
||||
$tag_ids = json_decode($tag_id);
|
||||
if ($tag_ids !== null) { // can decode json
|
||||
$tag_id_list = array();
|
||||
foreach ($tag_ids as $tag_id) {
|
||||
if (preg_match('/^collection_[0-9]+$/i', $tag_id)) {
|
||||
$tagChoice = explode('_', $tag_id)[1];
|
||||
$this->loadModel('TagCollection');
|
||||
$tagCollection = $this->TagCollection->fetchTagCollection($this->Auth->user(), array('conditions' => array('TagCollection.id' => $tagChoice)));
|
||||
if (empty($tagCollection)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Invalid Tag Collection.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
$tag_id_list = array();
|
||||
foreach ($tagCollection[0]['TagCollectionTag'] as $tagCollectionTag) {
|
||||
$tag_id_list[] = $tagCollectionTag['tag_id'];
|
||||
}
|
||||
} else {
|
||||
$tag_id_list[] = $tag_id;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$tag = $this->Event->EventTag->Tag->find('first', array('recursive' => -1, 'conditions' => $conditions));
|
||||
if (empty($tag)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Invalid Tag.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
$tag_id = $tag['Tag']['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->autoRender = false;
|
||||
$error = false;
|
||||
$success = false;
|
||||
if (empty($tag_id_list)) {
|
||||
$tag_id_list = array($tag_id);
|
||||
}
|
||||
foreach ($tag_id_list as $tag_id) {
|
||||
$this->Event->EventTag->Tag->id = $tag_id;
|
||||
if (!$this->Event->EventTag->Tag->exists()) {
|
||||
$error = __('Invalid Tag.');
|
||||
continue;
|
||||
}
|
||||
$tag = $this->Event->EventTag->Tag->find('first', array(
|
||||
'conditions' => array('Tag.id' => $tag_id),
|
||||
'recursive' => -1,
|
||||
'fields' => array('Tag.name')
|
||||
));
|
||||
$found = $this->Event->EventTag->find('first', array(
|
||||
'conditions' => array(
|
||||
'event_id' => $id,
|
||||
'tag_id' => $tag_id
|
||||
),
|
||||
'recursive' => -1,
|
||||
));
|
||||
if (!empty($found)) {
|
||||
$error = __('Tag is already attached to this event.');
|
||||
continue;
|
||||
}
|
||||
$this->Event->EventTag->create();
|
||||
if ($this->Event->EventTag->save(array('event_id' => $id, 'tag_id' => $tag_id))) {
|
||||
$event['Event']['published'] = 0;
|
||||
$date = new DateTime();
|
||||
$event['Event']['timestamp'] = $date->getTimestamp();
|
||||
$this->Event->save($event);
|
||||
$log = ClassRegistry::init('Log');
|
||||
$log->createLogEntry($this->Auth->user(), 'tag', 'Event', $id, 'Attached tag (' . $tag_id . ') "' . $tag['Tag']['name'] . '" to event (' . $id . ')', 'Event (' . $id . ') tagged as Tag (' . $tag_id . ')');
|
||||
$success = __('Tag(s) added.');
|
||||
} else {
|
||||
$fail = __('Tag could not be added.');
|
||||
}
|
||||
}
|
||||
if ($success) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => __('Tag(s) added.'), 'check_publish' => true)), 'status'=>200, 'type' => 'json'));
|
||||
} elseif (empty($fail)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => __('All tags are already present, nothing to add.'), 'check_publish' => true)), 'status'=>200, 'type' => 'json'));
|
||||
} else {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => $fail)), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -270,34 +270,42 @@ class GalaxiesController extends AppController
|
|||
|
||||
public function attachMultipleClusters($target_id, $target_type = 'event')
|
||||
{
|
||||
if ($target_id === 'selected') {
|
||||
$target_id_list = json_decode($this->request->data['Galaxy']['attribute_ids']);
|
||||
} else {
|
||||
$target_id_list = array($target_id);
|
||||
}
|
||||
$cluster_ids = $this->request->data['Galaxy']['target_ids'];
|
||||
if (!empty($cluster_ids)) {
|
||||
$cluster_ids = json_decode($cluster_ids, true);
|
||||
if ($cluster_ids === null) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'error' => __('Failed to parse request.'))), 'status'=>200, 'type' => 'json'));
|
||||
if ($this->request->is('post')) {
|
||||
if ($target_id === 'selected') {
|
||||
$target_id_list = json_decode($this->request->data['Galaxy']['attribute_ids']);
|
||||
} else {
|
||||
$target_id_list = array($target_id);
|
||||
}
|
||||
$cluster_ids = $this->request->data['Galaxy']['target_ids'];
|
||||
if (!empty($cluster_ids)) {
|
||||
$cluster_ids = json_decode($cluster_ids, true);
|
||||
if ($cluster_ids === null) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'error' => __('Failed to parse request.'))), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
} else {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'error' => __('No clusters picked.'))), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
$result = "";
|
||||
if (!is_array($cluster_ids)) { // in case we only want to attach 1
|
||||
$cluster_ids = array($cluster_ids);
|
||||
}
|
||||
foreach ($cluster_ids as $cluster_id) {
|
||||
foreach ($target_id_list as $target_id) {
|
||||
$result = $this->Galaxy->attachCluster($this->Auth->user(), $target_type, $target_id, $cluster_id);
|
||||
}
|
||||
}
|
||||
if ($this->request->is('ajax')) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => $result, 'check_publish' => true)), 'status'=>200, 'type' => 'json'));
|
||||
} else {
|
||||
$this->Flash->info($result);
|
||||
$this->redirect($this->referer());
|
||||
}
|
||||
} else {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'error' => __('No clusters picked.'))), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
$result = "";
|
||||
if (!is_array($cluster_ids)) { // in case we only want to attach 1
|
||||
$cluster_ids = array($cluster_ids);
|
||||
}
|
||||
foreach ($cluster_ids as $cluster_id) {
|
||||
foreach ($target_id_list as $target_id) {
|
||||
$result = $this->Galaxy->attachCluster($this->Auth->user(), $target_type, $target_id, $cluster_id);
|
||||
}
|
||||
}
|
||||
if ($this->request->is('ajax')) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => $result, 'check_publish' => true)), 'status'=>200, 'type' => 'json'));
|
||||
} else {
|
||||
$this->Flash->info($result);
|
||||
$this->redirect($this->referer());
|
||||
$this->set('target_id', $target_id);
|
||||
$this->set('target_type', $target_type);
|
||||
$this->layout = false;
|
||||
$this->autoRender = false;
|
||||
$this->render('/Galaxies/ajax/attach_multiple_clusters');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -227,9 +227,6 @@ class TagCollectionsController extends AppController
|
|||
|
||||
public function addTag($id = false, $tag_id = false)
|
||||
{
|
||||
if (!$this->request->is('post')) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'You don\'t have permission to do that.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
$rearrangeRules = array(
|
||||
'request' => false,
|
||||
'TagCollection' => false,
|
||||
|
@ -242,102 +239,110 @@ class TagCollectionsController extends AppController
|
|||
if ($id === false) {
|
||||
$id = $this->request->data['tag_collection'];
|
||||
}
|
||||
if ($tag_id === false) {
|
||||
$tag_id = $this->request->data['tag'];
|
||||
}
|
||||
$conditions = array();
|
||||
if (!$this->_isSiteAdmin()) {
|
||||
$conditions['Tag.org_id'] = array('0', $this->Auth->user('org_id'));
|
||||
$conditions['Tag.user_id'] = array('0', $this->Auth->user('id'));
|
||||
}
|
||||
if (!is_numeric($tag_id)) {
|
||||
$tag_ids = json_decode($tag_id);
|
||||
$tag_lookups = array();
|
||||
foreach ($tag_ids as $temp) {
|
||||
if (is_numeric($temp)) {
|
||||
$tag_lookups['OR']['Tag.id'][] = $temp;
|
||||
} else {
|
||||
$tag_lookups['OR']['LOWER(Tag.name) LIKE'][] = strtolower(trim($tag_id));
|
||||
}
|
||||
}
|
||||
if ($tag_ids !== null && is_array($tag_ids)) { // can decode json
|
||||
$tag_ids = $this->TagCollection->TagCollectionTag->Tag->find('list', array(
|
||||
'conditions' => array(
|
||||
'AND' => array(
|
||||
$conditions,
|
||||
$tag_lookups
|
||||
)
|
||||
),
|
||||
'fields' => array('Tag.id', 'Tag.id')
|
||||
));
|
||||
$tag_id_list = array_values($tag_ids);
|
||||
if (empty($tag_id_list)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Invalid Tag(s).')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
} else {
|
||||
$tag = $this->TagCollection->TagCollectionTag->Tag->find('first', array('recursive' => -1, 'conditions' => $conditions));
|
||||
if (empty($tag)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Invalid Tag.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
$tag_id = $tag['Tag']['id'];
|
||||
}
|
||||
}
|
||||
$tagCollection = $this->TagCollection->find('first', array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array('TagCollection.id' => $id)
|
||||
));
|
||||
if (empty($tagCollection)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Invalid tag collection.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
if (!$this->_isSiteAdmin()) {
|
||||
if (!$this->userRole['perm_tagger'] || ($this->Auth->user('org_id') !== $tagCollection['TagCollection']['org_id'])) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'You don\'t have permission to do that.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
}
|
||||
$this->autoRender = false;
|
||||
$error = false;
|
||||
$success = false;
|
||||
if (empty($tag_id_list)) {
|
||||
$tag_id_list = array($tag_id);
|
||||
}
|
||||
|
||||
foreach ($tag_id_list as $tag_id) {
|
||||
$this->TagCollection->TagCollectionTag->Tag->id = $tag_id;
|
||||
if (!$this->TagCollection->TagCollectionTag->Tag->exists()) {
|
||||
$error = __('Invalid Tag.');
|
||||
continue;
|
||||
}
|
||||
$tag = $this->TagCollection->TagCollectionTag->Tag->find('first', array(
|
||||
'conditions' => array('Tag.id' => $tag_id),
|
||||
'recursive' => -1,
|
||||
'fields' => array('Tag.name')
|
||||
));
|
||||
$found = $this->TagCollection->TagCollectionTag->find('first', array(
|
||||
'conditions' => array(
|
||||
'tag_collection_id' => $id,
|
||||
'tag_id' => $tag_id
|
||||
),
|
||||
'recursive' => -1,
|
||||
));
|
||||
if (!empty($found)) {
|
||||
$error = __('Tag is already attached to this event.');
|
||||
continue;
|
||||
}
|
||||
$this->TagCollection->TagCollectionTag->create();
|
||||
if ($this->TagCollection->TagCollectionTag->save(array('tag_collection_id' => $id, 'tag_id' => $tag_id))) {
|
||||
$log = ClassRegistry::init('Log');
|
||||
$log->createLogEntry($this->Auth->user(), 'tag', 'TagCollection', $id, 'Attached tag (' . $tag_id . ') "' . $tag['Tag']['name'] . '" to collection (' . $id . ')', 'Event (' . $id . ') tagged as Tag (' . $tag_id . ')');
|
||||
$success = __('Tag(s) added.');
|
||||
} else {
|
||||
$fail = __('Tag(s) could not be added.');
|
||||
}
|
||||
}
|
||||
if ($success) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => $success)), 'status'=>200, 'type' => 'json'));
|
||||
} elseif (empty($fail)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => __('All tags are already present, nothing to add.'), 'check_publish' => true)), 'status'=>200, 'type' => 'json'));
|
||||
if (!$this->request->is('post')) {
|
||||
$this->set('object_id', $id);
|
||||
$this->set('scope', 'TagCollection');
|
||||
$this->layout = false;
|
||||
$this->autoRender = false;
|
||||
$this->render('/Events/add_tag');
|
||||
} else {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => $fail)), 'status'=>200, 'type' => 'json'));
|
||||
if ($tag_id === false) {
|
||||
$tag_id = $this->request->data['tag'];
|
||||
}
|
||||
$conditions = array();
|
||||
if (!$this->_isSiteAdmin()) {
|
||||
$conditions['Tag.org_id'] = array('0', $this->Auth->user('org_id'));
|
||||
$conditions['Tag.user_id'] = array('0', $this->Auth->user('id'));
|
||||
}
|
||||
if (!is_numeric($tag_id)) {
|
||||
$tag_ids = json_decode($tag_id);
|
||||
$tag_lookups = array();
|
||||
foreach ($tag_ids as $temp) {
|
||||
if (is_numeric($temp)) {
|
||||
$tag_lookups['OR']['Tag.id'][] = $temp;
|
||||
} else {
|
||||
$tag_lookups['OR']['LOWER(Tag.name) LIKE'][] = strtolower(trim($tag_id));
|
||||
}
|
||||
}
|
||||
if ($tag_ids !== null && is_array($tag_ids)) { // can decode json
|
||||
$tag_ids = $this->TagCollection->TagCollectionTag->Tag->find('list', array(
|
||||
'conditions' => array(
|
||||
'AND' => array(
|
||||
$conditions,
|
||||
$tag_lookups
|
||||
)
|
||||
),
|
||||
'fields' => array('Tag.id', 'Tag.id')
|
||||
));
|
||||
$tag_id_list = array_values($tag_ids);
|
||||
if (empty($tag_id_list)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Invalid Tag(s).')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
} else {
|
||||
$tag = $this->TagCollection->TagCollectionTag->Tag->find('first', array('recursive' => -1, 'conditions' => $conditions));
|
||||
if (empty($tag)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Invalid Tag.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
$tag_id = $tag['Tag']['id'];
|
||||
}
|
||||
}
|
||||
$tagCollection = $this->TagCollection->find('first', array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array('TagCollection.id' => $id)
|
||||
));
|
||||
if (empty($tagCollection)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Invalid tag collection.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
if (!$this->_isSiteAdmin()) {
|
||||
if (!$this->userRole['perm_tagger'] || ($this->Auth->user('org_id') !== $tagCollection['TagCollection']['org_id'])) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'You don\'t have permission to do that.')), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
}
|
||||
$this->autoRender = false;
|
||||
$error = false;
|
||||
$success = false;
|
||||
if (empty($tag_id_list)) {
|
||||
$tag_id_list = array($tag_id);
|
||||
}
|
||||
|
||||
foreach ($tag_id_list as $tag_id) {
|
||||
$this->TagCollection->TagCollectionTag->Tag->id = $tag_id;
|
||||
if (!$this->TagCollection->TagCollectionTag->Tag->exists()) {
|
||||
$error = __('Invalid Tag.');
|
||||
continue;
|
||||
}
|
||||
$tag = $this->TagCollection->TagCollectionTag->Tag->find('first', array(
|
||||
'conditions' => array('Tag.id' => $tag_id),
|
||||
'recursive' => -1,
|
||||
'fields' => array('Tag.name')
|
||||
));
|
||||
$found = $this->TagCollection->TagCollectionTag->find('first', array(
|
||||
'conditions' => array(
|
||||
'tag_collection_id' => $id,
|
||||
'tag_id' => $tag_id
|
||||
),
|
||||
'recursive' => -1,
|
||||
));
|
||||
if (!empty($found)) {
|
||||
$error = __('Tag is already attached to this event.');
|
||||
continue;
|
||||
}
|
||||
$this->TagCollection->TagCollectionTag->create();
|
||||
if ($this->TagCollection->TagCollectionTag->save(array('tag_collection_id' => $id, 'tag_id' => $tag_id))) {
|
||||
$log = ClassRegistry::init('Log');
|
||||
$log->createLogEntry($this->Auth->user(), 'tag', 'TagCollection', $id, 'Attached tag (' . $tag_id . ') "' . $tag['Tag']['name'] . '" to collection (' . $id . ')', 'Event (' . $id . ') tagged as Tag (' . $tag_id . ')');
|
||||
$success = __('Tag(s) added.');
|
||||
} else {
|
||||
$fail = __('Tag(s) could not be added.');
|
||||
}
|
||||
}
|
||||
if ($success) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => $success)), 'status'=>200, 'type' => 'json'));
|
||||
} elseif (empty($fail)) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => __('All tags are already present, nothing to add.'), 'check_publish' => true)), 'status'=>200, 'type' => 'json'));
|
||||
} else {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => $fail)), 'status'=>200, 'type' => 'json'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -283,5 +283,4 @@ function submitFunction(clicked, callback) {
|
|||
options_templates['<?php echo $select_id; ?>'] = <?php echo json_encode($option_templates); ?>;
|
||||
options_additionalData['<?php echo $select_id; ?>'] = <?php echo json_encode($options_additionalData); ?>;
|
||||
</script>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
echo $this->Form->create($scope, array('url' => array('controller' => Inflector::tableize($scope), 'action' => 'addTag', $object_id)));
|
||||
if ($scope === 'Attribute') {
|
||||
echo $this->Form->input('attribute_ids', array());
|
||||
}
|
||||
echo $this->Form->input('tag', array('value' => 0));
|
||||
echo $this->Form->end();
|
||||
?>
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
echo $this->Form->create('Galaxy', array('url' => array('controller' => 'galaxies', 'action' => 'attachMultipleClusters', $target_id, $target_type), 'style' => 'margin:0px;'));
|
||||
echo $this->Form->input('target_ids', array('type' => 'text'));
|
||||
echo $this->Form->input('attribute_ids', array('style' => 'display:none;', 'label' => false));
|
||||
echo $this->Form->end();
|
||||
?>
|
|
@ -1,14 +1,5 @@
|
|||
<div class="hidden">
|
||||
<?php
|
||||
echo $this->Form->create('Galaxy', array('url' => '/galaxies/attachMultipleClusters/' . h($target_id) . '/' . h($target_type), 'style' => 'margin:0px;'));
|
||||
echo $this->Form->input('target_ids', array('type' => 'text'));
|
||||
echo $this->Form->input('attribute_ids', array('style' => 'display:none;', 'label' => false));
|
||||
echo $this->Form->end();
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div id="temp"></div>
|
||||
<?php echo $this->element('generic_picker'); ?>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#GalaxyAttributeIds').attr('value', getSelected());
|
||||
|
|
|
@ -1,16 +1,2 @@
|
|||
<div style="display:none;">
|
||||
<?php
|
||||
if ($scope === 'attribute') {
|
||||
echo $this->Form->create('Attribute', array('url' => '/attributes/addTag/' . $object_id, 'style' => 'margin:0px;'));
|
||||
echo $this->Form->input('attribute_ids', array('style' => 'display:none;', 'label' => false));
|
||||
} elseif ($scope === 'event') {
|
||||
echo $this->Form->create('Event', array('url' => '/events/addTag/' . $object_id, 'style' => 'margin:0px;'));
|
||||
} elseif ($scope === 'tag_collection') {
|
||||
echo $this->Form->create('TagCollection', array('url' => '/tag_collections/addTag/' . $object_id, 'style' => 'margin:0px;'));
|
||||
}
|
||||
echo $this->Form->input('tag', array('value' => 0));
|
||||
echo $this->Form->end();
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div id="temp"></div>
|
||||
<?php echo $this->element('generic_picker'); ?>
|
||||
|
|
|
@ -579,9 +579,11 @@ function submitForm(type, id, field, context) {
|
|||
|
||||
function quickSubmitTagForm(selected_tag_ids, addData) {
|
||||
var event_id = addData.id;
|
||||
var formData = fetchFormDataAjax("/events/addTag/" + event_id);
|
||||
$('#temp').html(formData);
|
||||
$('#EventTag').val(JSON.stringify(selected_tag_ids));
|
||||
$.ajax({
|
||||
data: $('#EventSelectTagForm').closest("form").serialize(),
|
||||
data: $('#EventAddTagForm').serialize(),
|
||||
beforeSend: function (XMLHttpRequest) {
|
||||
$(".loading").show();
|
||||
},
|
||||
|
@ -596,6 +598,7 @@ function quickSubmitTagForm(selected_tag_ids, addData) {
|
|||
loadGalaxies(event_id, 'event');
|
||||
},
|
||||
complete:function() {
|
||||
$('#temp').empty();
|
||||
$("#popover_form").fadeOut();
|
||||
$("#gray_out").fadeOut();
|
||||
$(".loading").hide();
|
||||
|
@ -603,17 +606,20 @@ function quickSubmitTagForm(selected_tag_ids, addData) {
|
|||
type:"post",
|
||||
url:"/events/addTag/" + event_id
|
||||
});
|
||||
$('#temp').remove();
|
||||
return false;
|
||||
}
|
||||
|
||||
function quickSubmitAttributeTagForm(selected_tag_ids, addData) {
|
||||
var attribute_id = addData.id;
|
||||
var formData = fetchFormDataAjax("/attributes/addTag/" + attribute_id);
|
||||
$('#temp').html(formData);
|
||||
$('#AttributeTag').val(JSON.stringify(selected_tag_ids));
|
||||
if (attribute_id == 'selected') {
|
||||
$('#AttributeAttributeIds').val(getSelected());
|
||||
}
|
||||
$.ajax({
|
||||
data: $('#AttributeSelectTagForm').closest("form").serialize(),
|
||||
data: $('#AttributeAddTagForm').serialize(),
|
||||
beforeSend: function (XMLHttpRequest) {
|
||||
$(".loading").show();
|
||||
},
|
||||
|
@ -639,14 +645,17 @@ function quickSubmitAttributeTagForm(selected_tag_ids, addData) {
|
|||
type:"post",
|
||||
url:"/attributes/addTag/" + attribute_id
|
||||
});
|
||||
$('#temp').remove();
|
||||
return false;
|
||||
}
|
||||
|
||||
function quickSubmitTagCollectionTagForm(selected_tag_ids, addData) {
|
||||
var tag_collection_id = addData.id;
|
||||
var formData = fetchFormDataAjax("/tag_collections/addTag/" + tag_collection_id);
|
||||
$('#temp').html(formData);
|
||||
$('#TagCollectionTag').val(JSON.stringify(selected_tag_ids));
|
||||
$.ajax({
|
||||
data: $('#TagCollectionSelectTagForm').closest("form").serialize(),
|
||||
data: $('#TagCollectionAddTagForm').serialize(),
|
||||
beforeSend: function (XMLHttpRequest) {
|
||||
$(".loading").show();
|
||||
},
|
||||
|
@ -666,6 +675,7 @@ function quickSubmitTagCollectionTagForm(selected_tag_ids, addData) {
|
|||
type:"post",
|
||||
url:"/tag_collections/addTag/" + tag_collection_id
|
||||
});
|
||||
$('#temp').remove();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -3563,12 +3573,15 @@ function addGalaxyListener(id) {
|
|||
function quickSubmitGalaxyForm(cluster_ids, additionalData) {
|
||||
var target_id = additionalData['target_id'];
|
||||
var scope = additionalData['target_type'];
|
||||
var formData = fetchFormDataAjax("/galaxies/attachMultipleClusters/" + target_id + "/" + scope);
|
||||
console.log(formData);
|
||||
$('#temp').html(formData);
|
||||
$('#GalaxyTargetIds').val(JSON.stringify(cluster_ids));
|
||||
if (target_id == 'selected') {
|
||||
$('#AttributeAttributeIds').val(getSelected());
|
||||
}
|
||||
$.ajax({
|
||||
data: $('#GalaxySelectClusterForm').closest("form").serialize(),
|
||||
data: $('#GalaxyAttachMultipleClustersForm').serialize(),
|
||||
beforeSend: function (XMLHttpRequest) {
|
||||
$(".loading").show();
|
||||
},
|
||||
|
@ -3596,6 +3609,7 @@ function quickSubmitGalaxyForm(cluster_ids, additionalData) {
|
|||
type:"post",
|
||||
url: "/galaxies/attachMultipleClusters/" + target_id + "/" + scope
|
||||
});
|
||||
$('#temp').remove();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -4129,22 +4143,9 @@ function removeRestClientHistoryItem(id) {
|
|||
function changeTaxonomyRequiredState(checkbox) {
|
||||
var checkbox_state = $(checkbox).is(":checked");
|
||||
var taxonomy_id = $(checkbox).data('taxonomy-id');
|
||||
var formData = false;
|
||||
var formData = fetchFormDataAjax('/taxonomies/toggleRequired/' + taxonomy_id);
|
||||
$.ajax({
|
||||
data: '[]',
|
||||
success:function (data, textStatus) {
|
||||
formData = $(data).serialize();
|
||||
},
|
||||
error:function() {
|
||||
handleGenericAjaxResponse({'saved':false, 'errors':['Request failed due to an unexpected error.']});
|
||||
},
|
||||
async: false,
|
||||
type:"get",
|
||||
cache: false,
|
||||
url: '/taxonomies/toggleRequired/' + taxonomy_id,
|
||||
});
|
||||
$.ajax({
|
||||
data: formData,
|
||||
data: $(formData).serialize(),
|
||||
success:function (data, textStatus) {
|
||||
handleGenericAjaxResponse({'saved':true, 'success':['Taxonomy\'s required state toggled.']});
|
||||
},
|
||||
|
@ -4160,6 +4161,24 @@ function changeTaxonomyRequiredState(checkbox) {
|
|||
formData = false;
|
||||
}
|
||||
|
||||
function fetchFormDataAjax(url) {
|
||||
var formData = false;
|
||||
$.ajax({
|
||||
data: '[]',
|
||||
success:function (data, textStatus) {
|
||||
formData = data;
|
||||
},
|
||||
error:function() {
|
||||
handleGenericAjaxResponse({'saved':false, 'errors':['Request failed due to an unexpected error.']});
|
||||
},
|
||||
async: false,
|
||||
type:"get",
|
||||
cache: false,
|
||||
url: url
|
||||
});
|
||||
return formData;
|
||||
}
|
||||
|
||||
(function(){
|
||||
"use strict";
|
||||
$(".datepicker").datepicker({
|
||||
|
|
Loading…
Reference in New Issue