Next step in the ajaxification of the event view

- users can now edit all fields in an attribute whilst on the event page

- issues left to fix:
	- tag changes after an attribute change run into CSRF protection
	- batch add not handled gracefully yet
	- going back to the event view and editing a field gives users an error message over the CSRF protection - instead, silently check if the page is loaded in a dirty way and refresh the ajax fields silently
	- quickadd of attributes still missing
pull/274/head
iglocska 2014-04-14 15:13:01 +02:00
parent ba91f4dc5f
commit 77a4cd71f6
8 changed files with 499 additions and 115 deletions

View File

@ -761,6 +761,90 @@ class AttributesController extends AppController {
$this->set('typeDefinitions', $this->Attribute->typeDefinitions);
$this->set('categoryDefinitions', $this->Attribute->categoryDefinitions);
}
// ajax edit - post a single edited field and this method will attempt to save it and return a json with the validation errors if they occur.
public function editField($id) {
if ((!$this->request->is('post') && !$this->request->is('put')) || !$this->request->is('ajax')) throw new MethodNotAllowedException();
$this->Attribute->id = $id;
if (!$this->Attribute->exists()) {
throw new NotFoundException(__('Invalid attribute'));
}
$this->Attribute->recursive = -1;
$this->Attribute->contain('Event');
$attribute = $this->Attribute->read();
if (!$this->_isSiteAdmin()) {
//
if ($this->Attribute->data['Event']['orgc'] == $this->Auth->user('org')
&& (($this->userRole['perm_modify'] && $this->Attribute->data['Event']['user_id'] != $this->Auth->user('id'))
|| $this->userRole['perm_modify_org'])) {
// Allow the edit
} else {
$this->Session->setFlash(__('Invalid attribute.'));
$this->redirect(array('controller' => 'events', 'action' => 'index'));
}
}
foreach ($this->request->data['Attribute'] as $changedKey => $changedField) {
if ($attribute['Attribute'][$changedKey] == $changedField) {
$this->autoRender = false;
return new CakeResponse(array('body'=> json_encode('nochange'),'status'=>200));
}
$attribute['Attribute'][$changedKey] = $changedField;
}
$date = new DateTime();
$attribute['Attribute']['timestamp'] = $date->getTimestamp();
if ($this->Attribute->save($attribute)) {
$event = $this->Attribute->Event->find('first', array(
'recursive' => -1,
'fields' => array('id', 'published', 'timestamp', 'info'),
'conditions' => array(
'id' => $attribute['Attribute']['event_id'],
)));
$event['Event']['timestamp'] = $date->getTimestamp();
$event['Event']['published'] = 0;
$res = $this->Attribute->Event->save($event, array('fieldList' => array('published', 'timestamp', 'info')));
file_put_contents('/tmp/event.txt', serialize($res));
$this->autoRender = false;
return new CakeResponse(array('body'=> json_encode('saved'),'status'=>200));
} else {
$this->autoRender = false;
return new CakeResponse(array('body'=> json_encode('fail'),'status'=>400));
}
}
public function view($id, $hasChildren = 0) {
$this->Attribute->id = $id;
if (!$this->Attribute->exists()) {
throw new NotFoundException('Invalid attribute');
}
$this->Attribute->recursive = -1;
$this->Attribute->contain('Event');
$attribute = $this->Attribute->read();
if (!$this->_isSiteAdmin()) {
//
if ($this->Attribute->data['Event']['org'] == $this->Auth->user('org') || (($this->Attribute->data['Event']['distribution'] > 0) && $this->Attribute->data['Attribute']['distribution'] > 0)) {
throw new MethodNotAllowed('Invalid attribute');
}
}
$eventRelations = $this->Attribute->Event->getRelatedAttributes($this->Auth->user(), $this->_isSiteAdmin(), $attribute['Attribute']['event_id']);
$attribute['Attribute']['relations'] = array();
if (isset($eventRelations[$id])) {
foreach ($eventRelations[$id] as $relations) {
$attribute['Attribute']['relations'][] = array($relations['id'], $relations['info'], $relations['org']);
}
}
$object = $attribute['Attribute'];
$object['objectType'] = 0;
$object['hasChildren'] = $hasChildren;
$this->set('object', $object);
$this->set('distributionLevels', $this->Attribute->Event->distributionLevels);
/*
$this->autoRender = false;
$responseObject = array();
return new CakeResponse(array('body'=> json_encode($attribute['Attribute']),'status'=>200));
*/
}
/**
* delete method

View File

@ -341,6 +341,13 @@ class EventsController extends AppController {
$types = $this->_arrayToValuesIndexArray($types);
$this->set('types', $types);
$this->set('categoryDefinitions', $this->Event->Attribute->categoryDefinitions);
$typeCategory = array();
foreach ($this->Attribute->categoryDefinitions as $k => $category) {
foreach ($category['types'] as $type) {
$typeCategory[$type][] = $k;
}
}
$this->set('typeCategory', $typeCategory);
$this->request->data['Attribute']['event_id'] = $id;
// Show the discussion

View File

@ -1,5 +1,8 @@
<? echo $this->Html->script('ajaxification');?>
<div class="attributes <? if (!$ajax) echo 'form';?>">
<?php echo $this->Form->create('Attribute', array('id'));?>
<?php
echo $this->Form->create('Attribute', array('id'));
?>
<legend><?php echo __('Add Attribute'); ?></legend>
<fieldset>
<div id="formWarning" class="message ajaxMessage"></div>

View File

@ -56,93 +56,7 @@
</tr>
<?php
foreach($eventArray as $k => $object):
$extra = '';
$extra2 = '';
if ($object['objectType'] == 0 ) {
if ($object['hasChildren'] == 1) $extra = 'highlight1';
} else $extra = 'highlight2';
if ($object['objectType'] == 1) $extra2 = '1';
?>
<tr>
<td style="width: <?php echo $extra2; ?>0px;padding:0px;border:0px;"></td>
<td class="short <?php echo $extra; ?>">
<?php
if (isset($object['timestamp'])) echo date('Y-m-d', $object['timestamp']);
else echo '&nbsp';
?>
</td>
<td class="short <?php echo $extra; ?>">
<?php
echo h($object['category']);
?>
</td>
<td class="short <?php echo $extra; ?>">
<?php
echo h($object['type']);
?>
</td>
<td class="showspaces <?php echo $extra; ?>">
<?php
echo h($object['value']);
?>
</td>
<td class="showspaces bitwider <?php echo $extra; ?>">
<?php
echo h($object['comment']);
?>
</td>
<td class="shortish <?php echo $extra; ?>">
<ul class="inline" style="margin:0px;">
<?php
if ($object['objectType'] == 0 && isset($relatedAttributes[$object['id']]) && (null != $relatedAttributes[$object['id']])) {
foreach ($relatedAttributes[$object['id']] as $relatedAttribute) {
echo '<li style="padding-right: 0px; padding-left:0px;" title ="' . h($relatedAttribute['info']) . '"><span>';
if ($relatedAttribute['org'] == $me['org']) {
echo $this->Html->link($relatedAttribute['id'], array('controller' => 'events', 'action' => 'view', $relatedAttribute['id'], true, $event['Event']['id']), array ('style' => 'color:red;'));
} else {
echo $this->Html->link($relatedAttribute['id'], array('controller' => 'events', 'action' => 'view', $relatedAttribute['id'], true, $event['Event']['id']));
}
echo "</span></li>";
echo ' ';
}
}
?>
</ul>
</td>
<td class="short <?php echo $extra; ?>">
<?php
if ($object['to_ids']) echo 'Yes';
else echo 'No';
?>
</td>
<td class="short <?php echo $extra; ?>">
<?php
if ($object['objectType'] != 1 && $object['objectType'] != 2) echo h($object['distribution']);
else echo '&nbsp';
?>
</td>
<td class="short action-links <?php echo $extra;?>">
<?php
if ($object['objectType'] == 0) {
if ($isSiteAdmin || $mayModify) {
echo $this->Html->link('', array('controller' => 'attributes', 'action' => 'edit', $object['id']), array('class' => 'icon-edit', 'title' => 'Edit'));
echo $this->Form->postLink('', array('controller' => 'attributes', 'action' => 'delete', $object['id']), array('class' => 'icon-trash', 'title' => 'Delete'), __('Are you sure you want to delete this attribute? Keep in mind that this will also delete this attribute on remote MISP instances.'));
} else {
echo $this->Html->link('', array('controller' => 'shadow_attributes', 'action' => 'edit', $object['id']), array('class' => 'icon-edit', 'title' => 'Propose Edit'));
}
} else {
if (($event['Event']['orgc'] == $me['org'] && $mayModify) || $isSiteAdmin) {
echo $this->Form->postLink('', array('controller' => 'shadow_attributes', 'action' => 'accept', $object['id']), array('class' => 'icon-ok', 'title' => 'Accept'), 'Are you sure you want to accept this proposal?');
}
if (($event['Event']['orgc'] == $me['org'] && $mayModify) || $isSiteAdmin || ($object['org'] == $me['org'])) {
echo $this->Form->postLink('', array('controller' => 'shadow_attributes', 'action' => 'discard', $object['id']), array('class' => 'icon-trash', 'title' => 'Discard'), 'Are you sure you want to discard this proposal?');
}
}
?>
</td>
</tr>
<?php
echo $this->element('eventattributerow', array('object' => $object));
endforeach;
?>
</table>
@ -237,33 +151,6 @@
)
);
}
?>
<script>
function deleteObject(type, id) {
$.ajax({
success:function (data, textStatus) {
updateAttributeIndexOnSuccess();
},
type:"post",
url:"/" + type + "/delete/" + id,
});
}
function updateAttributeIndexOnSuccess() {
$.ajax({
beforeSend: function (XMLHttpRequest) {
$(".loading").show();
},
dataType:"html",
success:function (data, textStatus) {
$(".loading").hide();
$("#attributes_div").html(data);
},
url:"/events/view/<?php echo $event['Event']['id']; ?>/attributesPage:1",
});
}
</script>
<?php
endif;
echo $this->Js->writeBuffer();
?>

View File

@ -0,0 +1,216 @@
<?php
$extra = '';
$extra2 = '';
$currentType = 'ShadowAttribute';
// 0 = attribute
// 1 = shadow_attribute
if ($object['objectType'] == 0 ) {
$currentType = 'Attribute';
if ($object['hasChildren'] == 1) $extra = 'highlight1';
} else $extra = 'highlight2';
if ($object['objectType'] == 1) $extra2 = '1';
?>
<tr id = "<?php echo $currentType . '_' . $object['id'] . '_tr'; ?>">
<td style="width: <?php echo $extra2; ?>0px;padding:0px;border:0px;"></td>
<td class="short <?php echo $extra; ?>">
<?php
if (isset($object['timestamp'])) echo date('Y-m-d', $object['timestamp']);
else echo '&nbsp';
?>
</td>
<td class="shortish <?php echo $extra; ?>">
<?php
echo $this->Form->create($currentType, array('class' => 'inline-form inline-field-form', 'id' => $currentType . '_' . $object['id'] . '_category_form', 'action' => 'editField', 'onSubmit=\'activateField("' . $currentType . '", "' . $object['id'] . '", "' . $event['Event']['id'] . '")\''));
?>
<div class='inline-input inline-input-container'>
<div class="inline-input-accept inline-input-button inline-input-passive"><span class = "icon-ok"></span></div>
<div class="inline-input-decline inline-input-button inline-input-passive"><span class = "icon-remove"></span></div>
<?php
echo $this->Form->input('category', array(
'options' => array(array_combine($typeCategory[$object['type']], $typeCategory[$object['type']])),
'label' => false,
'selected' => $object['category'],
'error' => array('escape' => false),
'class' => 'inline-input',
'id' => $currentType . '_' . $object['id'] . '_category_field',
'div' => false
));
echo $this->Form->end();
?>
</div>
<div id = "<?php echo $currentType . '_' . $object['id'] . '_category_solid'; ?>" class="inline-field-solid" onClick="activateField('<?php echo $currentType; ?>', '<?php echo $object['id']; ?>', 'category', <?php echo $event['Event']['id'];?>);">
<?php echo h($object['category']); ?>
</div>
</td>
<td class="shortish <?php echo $extra; ?>">
<?php
echo $this->Form->create($currentType, array('class' => 'inline-form inline-field-form', 'id' => $currentType . '_' . $object['id'] . '_type_form', 'action' => 'editField', 'onSubmit=\'activateField("' . $currentType . '", "' . $object['id'] . '", "' . $event['Event']['id'] . '")\''));
?>
<div class='inline-input inline-input-container'>
<div class="inline-input-accept inline-input-button inline-input-passive"><span class = "icon-ok"></span></div>
<div class="inline-input-decline inline-input-button inline-input-passive"><span class = "icon-remove"></span></div>
<?php
echo $this->Form->input('type', array(
'options' => array(array_combine($categoryDefinitions[$object['category']]['types'], $categoryDefinitions[$object['category']]['types'])),
'label' => false,
'selected' => $object['type'],
'error' => array('escape' => false),
'class' => 'inline-input',
'id' => $currentType . '_' . $object['id'] . '_type_field',
'div' => false
));
echo $this->Form->end();
?>
</div>
<div id = "<?php echo $currentType . '_' . $object['id'] . '_type_solid'; ?>" class="inline-field-solid" onClick="activateField('<?php echo $currentType; ?>', '<?php echo $object['id']; ?>', 'type', <?php echo $event['Event']['id'];?>);">
<?php echo h($object['type']); ?>
</div>
</td>
<td class="showspaces <?php echo $extra; ?>">
<?php
echo $this->Form->create($currentType, array('class' => 'inline-form inline-field-form', 'id' => $currentType . '_' . $object['id'] . '_value_form', 'action' => 'editField', 'default' => false));
?>
<div class='inline-input inline-input-container'>
<div class="inline-input-accept inline-input-button inline-input-passive"><span class = "icon-ok"></span></div>
<div class="inline-input-decline inline-input-button inline-input-passive"><span class = "icon-remove"></span></div>
<?php
echo $this->Form->input('value', array(
'type' => 'textarea',
'label' => false,
'value' => h($object['value']),
'error' => array('escape' => false),
'class' => 'inline-input',
'id' => $currentType . '_' . $object['id'] . '_value_field',
'div' => false
));
?>
</div>
<?php
echo $this->Form->end();
?>
<div id = "<?php echo $currentType . '_' . $object['id'] . '_value_solid'; ?>" class="inline-field-solid" onClick="activateField('<?php echo $currentType; ?>', '<?php echo $object['id']; ?>', 'value', <?php echo $event['Event']['id'];?>);">
<?php echo nl2br(h($object['value'])); ?>
</div>
</td>
<td class="showspaces bitwider <?php echo $extra; ?>">
<?php
echo $this->Form->create($currentType, array('class' => 'inline-form inline-field-form', 'id' => $currentType . '_' . $object['id'] . '_comment_form', 'action' => 'editField'));
?>
<div class='inline-input inline-input-container'>
<div class="inline-input-accept inline-input-button inline-input-passive"><span class = "icon-ok"></span></div>
<div class="inline-input-decline inline-input-button inline-input-passive"><span class = "icon-remove"></span></div>
<?php
echo $this->Form->input('comment', array(
'type' => 'textarea',
'label' => false,
'value' => h($object['comment']),
'error' => array('escape' => false),
'class' => 'inline-input',
'id' => $currentType . '_' . $object['id'] . '_comment_field',
'div' => false
));
echo $this->Form->end();
?>
</div>
<div id = "<?php echo $currentType . '_' . $object['id'] . '_comment_solid'; ?>" class="inline-field-solid" onClick="activateField('<?php echo $currentType; ?>', '<?php echo $object['id']; ?>', 'comment', <?php echo $event['Event']['id'];?>);">
<?php echo nl2br(h($object['comment'])); ?>&nbsp;
</div>
</td>
<td class="shortish <?php echo $extra; ?>">
<ul class="inline" style="margin:0px;">
<?php
if ($object['objectType'] == 0 && isset($relatedAttributes[$object['id']]) && (null != $relatedAttributes[$object['id']])) {
foreach ($relatedAttributes[$object['id']] as $relatedAttribute) {
echo '<li style="padding-right: 0px; padding-left:0px;" title ="' . h($relatedAttribute['info']) . '"><span>';
if ($relatedAttribute['org'] == $me['org']) {
echo $this->Html->link($relatedAttribute['id'], array('controller' => 'events', 'action' => 'view', $relatedAttribute['id'], true, $event['Event']['id']), array ('style' => 'color:red;'));
} else {
echo $this->Html->link($relatedAttribute['id'], array('controller' => 'events', 'action' => 'view', $relatedAttribute['id'], true, $event['Event']['id']));
}
echo "</span></li>";
echo ' ';
}
}
?>
</ul>
</td>
<td class="short <?php echo $extra; ?>">
<?php
echo $this->Form->create($currentType, array('class' => 'inline-form inline-field-form', 'id' => $currentType . '_' . $object['id'] . '_ids_form', 'action' => 'editField'));
?>
<div class='inline-input inline-input-container'>
<div class="inline-input-accept inline-input-button inline-input-passive"><span class = "icon-ok"></span></div>
<div class="inline-input-decline inline-input-button inline-input-passive"><span class = "icon-remove"></span></div>
<?php
$current = 0;
if ($object['to_ids']) $current = 1;
echo $this->Form->input('to_ids', array(
'options' => array(0 => 'No', 1 => 'Yes'),
'label' => false,
'selected' => $current,
'class' => 'inline-input',
'id' => $currentType . '_' . $object['id'] . '_ids_field',
'div' => false
));
echo $this->Form->end();
?>
</div>
<div id = "<?php echo $currentType . '_' . $object['id'] . '_ids_solid'; ?>" class="inline-field-solid" onClick="activateField('<?php echo $currentType; ?>', '<?php echo $object['id']; ?>', 'ids', <?php echo $event['Event']['id'];?>);">
<?php
if ($object['objectType'] != 1 && $object['objectType'] != 2) {
if ($object['to_ids']) echo 'Yes';
else echo 'No';
}
?>
</div>
</td>
<td class="<?php echo $extra; ?>" style="width:150px;">
<?php
echo $this->Form->create($currentType, array('class' => 'inline-form inline-field-form', 'id' => $currentType . '_' . $object['id'] . '_distribution_form', 'action' => 'editField'));
?>
<div class='inline-input inline-input-container'>
<div class="inline-input-accept inline-input-button inline-input-passive"><span class = "icon-ok"></span></div>
<div class="inline-input-decline inline-input-button inline-input-passive"><span class = "icon-remove"></span></div>
<?php
echo $this->Form->input('distribution', array(
'options' => array($distributionLevels),
'label' => false,
'selected' => $object['distribution'],
'error' => array('escape' => false),
'class' => 'inline-input',
'id' => $currentType . '_' . $object['id'] . '_distribution_field',
'div' => false
));
echo $this->Form->end();
?>
</div>
<div id = "<?php echo $currentType . '_' . $object['id'] . '_distribution_solid'; ?>" class="inline-field-solid" onClick="activateField('<?php echo $currentType; ?>', '<?php echo $object['id']; ?>', 'distribution', <?php echo $event['Event']['id'];?>);">
<?php if ($object['objectType'] != 1 && $object['objectType'] != 2) echo h($distributionLevels[$object['distribution']]); ?>&nbsp;
</div>
</td>
<td class="short action-links <?php echo $extra;?>">
<?php
if ($object['objectType'] == 0) {
if ($isSiteAdmin || $mayModify) {
echo $this->Form->create('Attribute', array('class' => 'inline-delete', 'id' => $currentType . '_' . $object['id'] . '_delete', 'action' => 'delete'));
echo $this->Form->end();
?>
<a href="/attributes/edit/<?php echo $object['id']; ?>" title="Edit" class="icon-edit"></a>
<span id = "<?php echo $currentType . '_' . $object['id'] . '_delete'; ?>" class="icon-trash" onClick="deleteObject('attributes', '<?php echo $object['id']; ?>', '<?php echo $event['Event']['id']; ?>');"></span>
<?php
echo $this->Form->end();
} else {
echo $this->Html->link('', array('controller' => 'shadow_attributes', 'action' => 'edit', $object['id']), array('class' => 'icon-edit', 'title' => 'Propose Edit'));
}
} else {
if (($event['Event']['orgc'] == $me['org'] && $mayModify) || $isSiteAdmin) {
echo $this->Form->postLink('', array('controller' => 'shadow_attributes', 'action' => 'accept', $object['id']), array('class' => 'icon-ok', 'title' => 'Accept'), 'Are you sure you want to accept this proposal?');
}
if (($event['Event']['orgc'] == $me['org'] && $mayModify) || $isSiteAdmin || ($object['org'] == $me['org'])) {
echo $this->Form->postLink('', array('controller' => 'shadow_attributes', 'action' => 'discard', $object['id']), array('class' => 'icon-trash', 'title' => 'Discard'), 'Are you sure you want to discard this proposal?');
}
}
?>
</td>
</tr>

View File

@ -3,6 +3,7 @@ $mayModify = (($isAclModify && $event['Event']['user_id'] == $me['id'] && $event
$mayPublish = ($isAclPublish && $event['Event']['orgc'] == $me['org']);
?>
<?php
echo $this->Html->script('ajaxification');
echo $this->element('side_menu', array('menuList' => 'event', 'menuItem' => 'viewEvent', 'mayModify' => $mayModify, 'mayPublish' => $mayPublish));
?>
<div class="events view">

View File

@ -747,6 +747,61 @@ a.proposal_link_red:hover {
width:665px;
}
.inline-input {
width:100% !important;
margin-bottom:0px !important;
padding: 0px 0px !important;
font-size: 12px !important;
position:relative;
}
.inline-input textarea{
padding-left: 3px !important;
}
.inline-input-button {
width:19px;
height:17px;
bottom:-17px;
background-color: #fff;
position:absolute;
z-index:100;
}
.inline-input-active {
border-bottom: 1px solid rgba(82, 168, 236, 0.8);
border-right: 1px solid rgba(82, 168, 236, 0.8);
border-left: 1px solid rgba(82, 168, 236, 0.8);
}
.inline-input-passive {
border-bottom: 1px solid #cccccc;
border-right: 1px solid #cccccc;
border-left: 1px solid #cccccc;
}
.inline-input-button span {
display:block;
margin: 0 auto;
}
.inline-input-accept {
right:32px;
}
.inline-input-decline {
right:10px;
}
.inline-form {
display:none;
margin-bottom:0px !important;
}
.inline-delete {
margin-bottom:0px !important;
}
@-webkit-keyframes rotation {
from {-webkit-transform: rotate(0deg);}
to {-webkit-transform: rotate(359deg);}

View File

@ -0,0 +1,131 @@
function deleteObject(type, id, event) {
if (confirm("Are you sure you want to delete Attribute #" + id + "?")) {
var name = '#Attribute' + '_' + id + '_delete';
var formData = $(name).serialize();
$.ajax({
data: formData,
success:function (data, textStatus) {
updateAttributeIndexOnSuccess(event);
},
type:"post",
url:"/" + type + "/delete/" + id,
});
}
}
function updateAttributeIndexOnSuccess(event) {
$.ajax({
beforeSend: function (XMLHttpRequest) {
$(".loading").show();
},
dataType:"html",
success:function (data, textStatus) {
$(".loading").hide();
$("#attributes_div").html(data);
},
url:"/events/view/" + event + "/attributesPage:1",
});
}
// if someone clicks an inactive field, replace it with the hidden form field. Also, focus it and bind a focusout event, so that it gets saved if the user clicks away.
// If a user presses enter, submit the form
function activateField(type, id, field, event) {
resetForms();
var name = '#' + type + '_' + id + '_' + field;
$(name + '_form').show();
$(name + '_field').focus();
inputFieldButtonActive(name + '_field');
if (field == 'value' || field == 'comment') {
$(name + '_field').on('keyup mouseover', function () {
autoresize(this);
});
}
$(name + '_form').submit(function(e){
e.preventDefault();
submitForm(type, id, field, event);
return false;
});
$(name + '_form').bind("focusout", function() {
inputFieldButtonPassive(name + '_field');
});
$(name + '_form').bind("focusin", function(){
inputFieldButtonActive(name + '_field');
});
$(name + '_form').bind("keydown", function(e) {
if (e.ctrlKey && (e.keyCode == 13 || e.keyCode == 10)) {
submitForm(type, id, field, event);
}
});
$(name + '_field').closest('.inline-input-container').children('.inline-input-accept').bind('click', function() {
submitForm(type, id, field, event);
});
$(name + '_field').closest('.inline-input-container').children('.inline-input-decline').bind('click', function() {
resetForms();
});
$(name + '_solid').hide();
}
function resetForms() {
$('.inline-field-solid').show();
$('.inline-field-form').hide();
}
function inputFieldButtonActive(selector) {
$(selector).closest('.inline-input-container').children('.inline-input-accept').removeClass('inline-input-passive').addClass('inline-input-active');
$(selector).closest('.inline-input-container').children('.inline-input-decline').removeClass('inline-input-passive').addClass('inline-input-active');
}
function inputFieldButtonPassive(selector) {
$(selector).closest('.inline-input-container').children('.inline-input-accept').addClass('inline-input-passive').removeClass('inline-input-active');
$(selector).closest('.inline-input-container').children('.inline-input-decline').addClass('inline-input-passive').removeClass('inline-input-active');
}
function autoresize(textarea) {
textarea.style.height = '20px';
textarea.style.height = (textarea.scrollHeight) + 'px';
}
// submit the form - this can be triggered by unfocusing the activated form field or by submitting the form (hitting enter)
// after the form is submitted, intercept the response and act on it
function submitForm(type, id, field, event) {
var name = '#' + type + '_' + id + '_' + field;
$.ajax({
data: $(name + '_field').closest("form").serialize(),
success:function (data, textStatus) {
handleAjaxEditResponse(data, event);
},
error:function() {
alert('Request failed. This may be caused by the CSRF protection blocking your request. The forms will now be refreshed to resolve the issue.');
updateAttributeIndexOnSuccess(event);
},
type:"post",
url:"/attributes/editField/" + id
});
$(name + '_field').unbind("keyup");
$(name + '_form').unbind("focusout");
return false;
};
function handleAjaxEditResponse(data, event) {
if (data == "\"saved\"") updateAttributeIndexOnSuccess(event);
else {
updateAttributeIndexOnSuccess(event);
}
}
$(function(){
$('a:contains("Delete")').removeAttr('onclick');
$('a:contains("Delete")').click(function(e){
e.preventDefault();
var form = $(this).prev();
url = $(form).attr("action");
$.post(url);
return false;
});
});