next step in the ajaxification

- multiselect / multidelete
- some additional UI changes for the event view
pull/274/head
iglocska 2014-04-16 15:52:25 +02:00
parent 77a4cd71f6
commit 979bb370e7
9 changed files with 323 additions and 178 deletions

View File

@ -153,6 +153,11 @@ class AttributesController extends AppController {
// debug(tru);
}
}
if ($this->request->is('ajax')) {
$this->autoRender = false;
// handle it if some of them failed!!!!
return new CakeResponse(array('body'=> json_encode('saved'),'status'=>200));
} else {
// we added all the attributes,
if ($fails) {
// list the ones that failed
@ -169,7 +174,7 @@ class AttributesController extends AppController {
}
$this->redirect(array('controller' => 'events', 'action' => 'view', $this->request->data['Attribute']['event_id']));
}
} else {
if (isset($this->request->data['Attribute']['uuid'])) { // TODO here we should start RESTful dialog
// check if the uuid already exists and also save the existing attribute for further checks
@ -860,7 +865,27 @@ class AttributesController extends AppController {
if (!$this->request->is('post') && !$this->_isRest()) {
throw new MethodNotAllowedException();
}
if ($this->__delete($id)) {
$this->Session->setFlash(__('Attribute deleted'));
} else {
$this->Session->setFlash(__('Attribute was not deleted'));
}
if (!$this->_isRest()) $this->redirect($this->referer()); // TODO check
else $this->redirect(array('action' => 'index'));
}
/**
* unification of the actual delete for the multi-select
*
* @param unknown $id
* @throws NotFoundException
* @throws MethodNotAllowedException
* @return boolean
*
* returns true/false based on success
*/
private function __delete($id) {
$this->Attribute->id = $id;
if (!$this->Attribute->exists()) {
throw new NotFoundException(__('Invalid attribute'));
@ -897,13 +922,26 @@ class AttributesController extends AppController {
// We have just deleted the attribute, let's also check if there are any shadow attributes that were attached to it and delete them
$this->loadModel('ShadowAttribute');
$this->ShadowAttribute->deleteAll(array('ShadowAttribute.old_id' => $id), false);
$this->Session->setFlash(__('Attribute deleted'));
return true;
} else {
$this->Session->setFlash(__('Attribute was not deleted'));
return false;
}
if (!$this->_isRest()) $this->redirect($this->referer()); // TODO check
else $this->redirect(array('action' => 'index'));
}
public function deleteSelected() {
//if (!$this->request->is('post') && !$this->request->is('ajax')) {
if (!$this->request->is('post')) {
throw new MethodNotAllowedException();
}
// get a json object with a list of attribute IDs to be deleted
// check each of them and return a json object with the successful deletes and the failed ones.
$ids = json_decode($this->request->data['Attribute']['ids']);
foreach ($ids as $id) {
$this->__delete($id);
}
$this->autoRender = false;
return new CakeResponse(array('body'=> json_encode('saved'),'status'=>200));
}
/**

View File

@ -433,9 +433,6 @@ class EventsController extends AppController {
$this->set('currentEvent', $id);
}
private function __view() {
}
private function __startPivoting($id, $info, $date){
$this->Session->write('pivot_thread', null);

View File

@ -0,0 +1,2 @@
<?php
echo $this->element('eventattributerow', array('object' => $object));

View File

@ -1,4 +1,5 @@
<?php
echo $this->Html->script('ajaxification');
$mayModify = (($isAclModify && $event['Event']['user_id'] == $me['id'] && $event['Event']['orgc'] == $me['org']) || ($isAclModifyOrg && $event['Event']['orgc'] == $me['org']));
$mayPublish = ($isAclPublish && $event['Event']['orgc'] == $me['org']);
if (!empty($eventArray)):
@ -41,9 +42,18 @@
<?php
endif;
?>
<table class="table table-striped table-condensed">
<div id="attributeList" class="attributeListContainer">
<div class="tabMenu">
<span id="create-button" class="icon-plus" onClick="clickCreateButton();"></span>
<span id="multi-edit-button" class="icon-edit mass-select" onClick="editSelectedAttributes(<?php echo $event['Event']['id']; ?>);"></span>
<span id="multi-delete-button" class = "icon-trash mass-select" onClick="deleteSelectedAttributes(<?php echo $event['Event']['id']; ?>);"></span>
</div>
<table class="table table-striped table-condensed">
<tr>
<th style="width:0px;padding:0px;border:0px;"></th>
<?php if ($mayModify): ?>
<th><input class="select_all" type="checkbox" onClick="toggleAllAttributeCheckboxes();" /></th>
<?php endif;?>
<th>Date</th>
<th>Category</th>
<th>Type</th>
@ -56,10 +66,11 @@
</tr>
<?php
foreach($eventArray as $k => $object):
echo $this->element('eventattributerow', array('object' => $object));
echo $this->element('eventattributerow', array('object' => $object, 'mayModify' => $mayModify, 'mayPublish' => $mayPublish));
endforeach;
?>
</table>
</table>
</div>
<?php if ($pageCount > 1): ?>
<span id = "current_page" style="visibility:hidden;"><?php echo $page;?></span>
<p>Page <?php echo $page; ?> of <?php echo $pageCount;?>, showing <?php echo count($eventArray); ?> records out of <?php echo $objectCount; ?> total, starting on <?php echo (($page-1) * 50) + 1;?>, ending on <?php echo (($page-1) * 50) + count($eventArray); ?></p>
@ -97,6 +108,20 @@
</div>
<?php
endif;
?>
<div id="edit_object_div">
<?php
echo $this->Form->create('Attribute', array('id' => 'delete_selected', 'action' => 'deleteSelected'));
echo $this->Form->input('ids', array(
'type' => 'text',
'value' => 'test',
'style' => 'display:none;',
'label' => false,
));
echo $this->Form->end();
?>
</div>
<?php
for ($j = 0; $j < 2; $j++) {
$side = 'a';
if ($j == 1) $side = 'b';
@ -152,5 +177,15 @@
);
}
endif;
?>
<script>
$(document).ready(function(){
$('.mass-select').hide();
$('input[type="checkbox"]').click(function(){
attributeListAnyCheckBoxesChecked();
});
});
</script>
<?php
echo $this->Js->writeBuffer();
?>

View File

@ -11,7 +11,13 @@ if ($object['objectType'] == 0 ) {
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>
<?php if ($mayModify): ?>
<td class="<?php echo $extra; ?>" style="width:10px;">
<?php if ($object['objectType'] == 0): ?>
<input id = "select_<?php echo $object['id']; ?>" class="select_attribute" type="checkbox" data-id="<?php echo $object['id'];?>" />
<?php endif; ?>
</td>
<?php endif; ?>
<td class="short <?php echo $extra; ?>">
<?php
if (isset($object['timestamp'])) echo date('Y-m-d', $object['timestamp']);
@ -20,7 +26,7 @@ if ($object['objectType'] == 1) $extra2 = '1';
</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'] . '")\''));
echo $this->Form->create($currentType, array('class' => 'inline-form inline-field-form', 'id' => $currentType . '_' . $object['id'] . '_category_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>
@ -44,7 +50,7 @@ if ($object['objectType'] == 1) $extra2 = '1';
</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'] . '")\''));
echo $this->Form->create($currentType, array('class' => 'inline-form inline-field-form', 'id' => $currentType . '_' . $object['id'] . '_type_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>
@ -158,10 +164,8 @@ if ($object['objectType'] == 1) $extra2 = '1';
</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>

View File

@ -2,6 +2,7 @@
<div class="pagination">
<ul>
<?php
if (!empty($posts)):
$this->Paginator->options(array(
'update' => '#top',
'evalScripts' => true,
@ -123,6 +124,7 @@
?>
</ul>
</div>
<?php endif; ?>
<div class="comment">
<?php echo $this->Form->create('Post');?>
<fieldset>

View File

@ -201,10 +201,6 @@ $mayPublish = ($isAclPublish && $event['Event']['orgc'] == $me['org']);
<div id="pivots_div">
<?php if (sizeOf($allPivots) > 1) echo $this->element('pivot'); ?>
</div>
<div id="create_object_div">
<span id="create-button" class="btn btn-inverse" onClick="clickCreateButton();">Add Attribute</span>
</div>
<br />
<div id="attribute_add_form" class="attribute_add_form"></div>
<div id="attribute_creation_div" style="display:none;">
<?php

View File

@ -802,6 +802,32 @@ a.proposal_link_red:hover {
margin-bottom:0px !important;
}
.tabMenu {
position:absolute;
top:-21px;
height:20px;
margin-left:5px;
padding-left:10px;
padding-right:10px;
-webkit-border-radius: 4px 4px 0 0;
-moz-border-radius: 4px 4px 0 0;
border-radius: 4px 4px 0 0;
border: 1px solid #ddd;
border-bottom-color: transparent;
background-color: #f9f9f9;
border-collapse: separate !important;
}
.tabMenu [class^="icon-"] {
vertical-align:baseline;
margin-top:3px;
}
.attributeListContainer{
position:relative;
margin-top:10px;
}
@-webkit-keyframes rotation {
from {-webkit-transform: rotate(0deg);}
to {-webkit-transform: rotate(359deg);}

View File

@ -119,6 +119,13 @@ function handleAjaxEditResponse(data, event) {
}
}
function handleAjaxMassDeleteResponse(data, event) {
if (data == "\"saved\"") updateAttributeIndexOnSuccess(event);
else {
updateAttributeIndexOnSuccess(event);
}
}
$(function(){
$('a:contains("Delete")').removeAttr('onclick');
$('a:contains("Delete")').click(function(e){
@ -129,3 +136,41 @@ $(function(){
return false;
});
});
function toggleAllAttributeCheckboxes() {
if ($(".select_all").is(":checked")) {
$(".select_attribute").prop("checked", true);
} else {
$(".select_attribute").prop("checked", false);
}
}
function attributeListAnyCheckBoxesChecked() {
if ($('input[type="checkbox"]:checked').length > 0) $('.mass-select').show();
else $('.mass-select').hide();
}
function deleteSelectedAttributes(event) {
var answer = confirm("Are you sure you want to delete all selected attributes?");
if (answer) {
var selected = [];
$(".select_attribute").each(function() {
if ($(this).is(":checked")) {
var test = $(this).data("id");
selected.push(test);
}
});
$('#AttributeIds').attr('value', JSON.stringify(selected));
var formData = $('#delete_selected').serialize();
$.ajax({
data: formData,
type:"POST",
url:"/attributes/deleteSelected/",
success:function (data, textStatus) {
handleAjaxMassDeleteResponse(data, event);
},
});
}
return false;
}