AJAXified the user view

This commit is contained in:
Karl Cordes 2011-03-16 17:51:43 +11:00
parent 164ad97265
commit 862b4c451b
7 changed files with 90 additions and 33 deletions

View file

@ -100,6 +100,14 @@ class EmailsController extends AppController {
} }
/**
* View Emails to, from or CC a particular user ID.
*
*
*/
function view_user_emails($id) {
}
} }
?> ?>

View file

@ -542,8 +542,26 @@ class EnquiriesController extends AppController {
function view_user_enquiries($id = null) {
if($id == null) {
$this->Session->setFlash('Invalid Enquiry ID');
$this->redirect(array('action'=>'index'));
}
else {
$this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.user_id' => $id)));
$statuses = $this->Enquiry->Status->find('all', array('recursive'=>0));
$status_list = array();
foreach ($statuses as $status) {
$statusid = $status['Status']['id'];
$status_list[$statusid] = $status['Status']['name'];
}
$this->set('status_list', $status_list);
$this->layout = 'ajax';
}
}
} }
?> ?>

View file

@ -99,17 +99,9 @@ class UsersController extends AppController {
break; break;
case 'user': case 'user':
$this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.user_id' => $id))); //$this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.user_id' => $id)));
$statuses = $this->User->Enquiry->Status->find('all', array('recursive'=>0));
$status_list = array();
foreach ($statuses as $status) {
$statusid = $status['Status']['id'];
$status_list[$statusid] = $status['Status']['name'];
}
$this->set('status_list', $status_list);
$this->render('viewUser'); $this->render('viewUser');
break; break;
@ -118,12 +110,6 @@ class UsersController extends AppController {
break; break;
} }
} }
@ -256,9 +242,5 @@ class UsersController extends AppController {
} }
?> ?>

View file

@ -0,0 +1 @@
<?=$this->element('enquiry_table', $enquiries); ?>

View file

@ -37,6 +37,7 @@
</head> </head>
<body> <body>
<div id="container"> <div id="container">
<div id="header"> <div id="header">
<h3 id="logo">CMC Technologies</h3> <h3 id="logo">CMC Technologies</h3>

View file

@ -1,3 +1,7 @@
<?=$javascript->link('view_user'); ?>
<span id="userID" style="display: none;"><?=$user['User']['id']?></span>
<div class="users view"> <div class="users view">
<h2><?php __('User: '.$user['User']['username'] );?></h2> <h2><?php __('User: '.$user['User']['username'] );?></h2>
<dl><?php $i = 0; $class = ' class="altrow"';?> <dl><?php $i = 0; $class = ' class="altrow"';?>
@ -30,21 +34,20 @@
</div> </div>
<div class="related"> <div class="related">
<h3><?php __('Enquiries Assigned to this User');?></h3> <h3><?php __('Enquiries Assigned to this User');?></h3>
<button id="show" class="showHide">Show</button>
<button id="hide" class="showHide">Hide</button>
<div id="enquiryTable">
<div id="ajaxLoad" style="display:none;"><?php echo $html->image('ajax-loader.gif'); ?></div>
</div>
<? /* If there are enquiries for this user, render the enquiries table passing the $enquiries array */ ?> <? /* If there are enquiries for this user, render the enquiries table passing the $enquiries array */ ?>
<?php if (!empty($user['Enquiry'])) { <?php if (!empty($user['Enquiry'])) {
echo $this->element('enquiry_table', $enquiries); //echo $this->element('enquiry_table', $user['Enquiry']);
} }
else { else {
echo "No Enquiries for this User"; echo "No Enquiries for this User";
} }
?> ?>
<div class="actions">
<ul>
<li><?php echo $html->link(__('New Enquiry', true), array('controller'=> 'enquiries', 'action'=>'add'));?> </li>
</ul>
</div> </div>
</div>

44
webroot/js/view_user.js Normal file
View file

@ -0,0 +1,44 @@
$(function() {
$('#hide').hide();
$('#enquiryTable').hide();
$("#ajaxLoad").hide();
$("#ajaxLoad").bind("ajaxSend", function() {
$(this).show();
}).bind("ajaxComplete", function() {
$(this).hide();
});
var userID = $('#userID').text();
var alreadyFetched = false;
$('#show').click(function() {
$(this).hide();
$('#hide').show();
if(alreadyFetched == false) {
$.get('/enquiries/view_user_enquiries/'+userID, function(data) {
$('#enquiryTable').html(data);
});
alreadyFetched = true;
}
$('#enquiryTable').slideDown('fast');
});
$('#hide').click(function() {
$(this).hide();
$('#show').show();
$('#enquiryTable').slideUp('fast');
});
});