Removed AJAX loading of User Enquiries view. This will make the initial load time of the View User page longer, but you can now update the status of the Enquiry again from that page. closes issue #52.
This commit is contained in:
parent
33369009bf
commit
5ddc942a93
|
|
@ -6,60 +6,60 @@ class UsersController extends AppController {
|
||||||
var $helpers = array('Html', 'Form', 'Javascript', 'Text');
|
var $helpers = array('Html', 'Form', 'Javascript', 'Text');
|
||||||
var $components = array('Acl', 'Auth', 'Cookie');
|
var $components = array('Acl', 'Auth', 'Cookie');
|
||||||
var $paginate = array(
|
var $paginate = array(
|
||||||
'limit' => 500,
|
'limit' => 500,
|
||||||
'order' => 'User.id asc',
|
'order' => 'User.id asc',
|
||||||
'Users' => array('order' => array('User.id' => 'asc'),
|
'Users' => array('order' => array('User.id' => 'asc'),
|
||||||
),
|
),
|
||||||
'Enquiry' => array('order' => array('Enquiry.id' => 'desc'), 'limit' => 250)
|
'Enquiry' => array('order' => array('Enquiry.id' => 'desc'), 'limit' => 250)
|
||||||
);
|
);
|
||||||
|
|
||||||
function beforeFilter() {
|
function beforeFilter() {
|
||||||
$this->Auth->allow('add');
|
$this->Auth->allow('add');
|
||||||
$this->set('currentuser', $this->Auth->user());
|
$this->set('currentuser', $this->Auth->user());
|
||||||
$this->Auth->autoRedirect = false;
|
$this->Auth->autoRedirect = false;
|
||||||
//$this->login();
|
//$this->login();
|
||||||
}
|
}
|
||||||
|
|
||||||
function login() { //Provided by the authComponent
|
function login() { //Provided by the authComponent
|
||||||
$this->pageTitle = ': Login';
|
$this->pageTitle = ': Login';
|
||||||
//$this->Session->setFlash(__('Please enter your Username and Password to continue', true));
|
//$this->Session->setFlash(__('Please enter your Username and Password to continue', true));
|
||||||
|
|
||||||
|
|
||||||
/* Auth Cookie code from http://www.webdevelopment2.com/cakephp-auth-component-tutorial-3/ */
|
/* Auth Cookie code from http://www.webdevelopment2.com/cakephp-auth-component-tutorial-3/ */
|
||||||
//– code inside this function will execute only when autoRedirect was set to false (i.e. in a beforeFilter).
|
//– code inside this function will execute only when autoRedirect was set to false (i.e. in a beforeFilter).
|
||||||
if ($this->Auth->user()) {
|
if ($this->Auth->user()) {
|
||||||
if (!empty($this->data) && $this->data['User']['remember_me']) {
|
if (!empty($this->data) && $this->data['User']['remember_me']) {
|
||||||
$cookie = array();
|
$cookie = array();
|
||||||
$cookie['username'] = $this->data['User']['username'];
|
$cookie['username'] = $this->data['User']['username'];
|
||||||
$cookie['password'] = $this->data['User']['password'];
|
$cookie['password'] = $this->data['User']['password'];
|
||||||
$this->Cookie->write('Auth.User', $cookie, true, '+2 weeks');
|
$this->Cookie->write('Auth.User', $cookie, true, '+2 weeks');
|
||||||
unset($this->data['User']['remember_me']);
|
unset($this->data['User']['remember_me']);
|
||||||
}
|
}
|
||||||
$this->redirect($this->Auth->redirect());
|
$this->redirect($this->Auth->redirect());
|
||||||
}
|
}
|
||||||
if (empty($this->data)) {
|
if (empty($this->data)) {
|
||||||
$cookie = $this->Cookie->read('Auth.User');
|
$cookie = $this->Cookie->read('Auth.User');
|
||||||
if (!is_null($cookie)) {
|
if (!is_null($cookie)) {
|
||||||
if ($this->Auth->login($cookie)) {
|
if ($this->Auth->login($cookie)) {
|
||||||
// Clear auth message, just in case we use it.
|
// Clear auth message, just in case we use it.
|
||||||
// $this->Session->setFlash(__('Welcome back '.$cookie['username']), true);
|
// $this->Session->setFlash(__('Welcome back '.$cookie['username']), true);
|
||||||
$this->Session->del('Message.auth');
|
$this->Session->del('Message.auth');
|
||||||
$this->redirect($this->Auth->redirect());
|
$this->redirect($this->Auth->redirect());
|
||||||
} else { // Delete invalid Cookie
|
} else { // Delete invalid Cookie
|
||||||
$this->Cookie->del('Auth.User');
|
$this->Cookie->del('Auth.User');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function logout() {
|
function logout() {
|
||||||
$this->Cookie->del('Auth.User');
|
$this->Cookie->del('Auth.User');
|
||||||
$this->redirect($this->Auth->logout());
|
$this->redirect($this->Auth->logout());
|
||||||
}
|
}
|
||||||
|
|
||||||
function index() {
|
function index() {
|
||||||
$this->User->recursive = 0;
|
$this->User->recursive = 0;
|
||||||
$this->set('users', $this->paginate());
|
$this->set('users', $this->paginate());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -70,24 +70,24 @@ class UsersController extends AppController {
|
||||||
* @param int $id
|
* @param int $id
|
||||||
*/
|
*/
|
||||||
function view($id = null) {
|
function view($id = null) {
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
$this->Session->setFlash(__('Invalid User.', true));
|
$this->Session->setFlash(__('Invalid User.', true));
|
||||||
$this->redirect(array('action' => 'index'));
|
$this->redirect(array('action' => 'index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
//$user = $this->User->read(null, $id);
|
//$user = $this->User->read(null, $id);
|
||||||
|
|
||||||
$userFields = array('User.id', 'User.principle_id', 'User.customer_id', 'User.type',
|
$userFields = array('User.id', 'User.principle_id', 'User.customer_id', 'User.type',
|
||||||
'User.access_level', 'User.username', 'User.first_name', 'User.last_name',
|
'User.access_level', 'User.username', 'User.first_name', 'User.last_name',
|
||||||
'User.email', 'User.job_title', 'User.phone', 'User.mobile', 'User.fax', 'User.phone_extension', 'User.direct_phone',
|
'User.email', 'User.job_title', 'User.phone', 'User.mobile', 'User.fax', 'User.phone_extension', 'User.direct_phone',
|
||||||
'User.notes', 'User.by_vault', 'User.blacklisted'
|
'User.notes', 'User.by_vault', 'User.blacklisted'
|
||||||
);
|
);
|
||||||
|
|
||||||
$user = $this->User->find('first', array('conditions' => array('User.id' => $id), 'fields' => $userFields, 'recursive' => 0));
|
$user = $this->User->find('first', array('conditions' => array('User.id' => $id), 'fields' => $userFields, 'recursive' => 0));
|
||||||
|
|
||||||
$this->set('user', $user);
|
$this->set('user', $user);
|
||||||
|
|
||||||
/* $emailIDs = array();
|
/* $emailIDs = array();
|
||||||
foreach($user['Email'] as $email) {
|
foreach($user['Email'] as $email) {
|
||||||
$emailIDs[] = $email['id'];
|
$emailIDs[] = $email['id'];
|
||||||
}
|
}
|
||||||
|
|
@ -96,82 +96,83 @@ class UsersController extends AppController {
|
||||||
/ */
|
/ */
|
||||||
|
|
||||||
|
|
||||||
switch ($user['User']['type']) {
|
switch ($user['User']['type']) {
|
||||||
case 'contact':
|
case 'contact':
|
||||||
|
|
||||||
if (isset($user['User']['customer_id'])) {
|
if (isset($user['User']['customer_id'])) {
|
||||||
$this->set('customer', $this->User->Customer->find('first', array('conditions' => array('Customer.id' => $user['User']['customer_id']), 'recursive' => 0)));
|
$this->set('customer', $this->User->Customer->find('first', array('conditions' => array('Customer.id' => $user['User']['customer_id']), 'recursive' => 0)));
|
||||||
}
|
}
|
||||||
$this->render('viewContact');
|
$this->render('viewContact');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'principle':
|
case 'principle':
|
||||||
|
|
||||||
$this->render('viewPrinciple');
|
$this->render('viewPrinciple');
|
||||||
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)));
|
||||||
|
$status_list = $this->User->Enquiry->Status->getJSON();
|
||||||
|
|
||||||
|
$this->set('status_list', $status_list);
|
||||||
|
$classNames = $this->User->Enquiry->Status->getClassNamesJSON();
|
||||||
|
$this->set('class_names', $classNames);
|
||||||
|
|
||||||
|
$this->render('viewUser');
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
$this->render('viewUser');
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_edit() {
|
function add_edit() {
|
||||||
Configure::write('debug', 0);
|
Configure::write('debug', 0);
|
||||||
|
|
||||||
if (isset($this->params['named']['type'])) {
|
if (isset($this->params['named']['type'])) {
|
||||||
$this->set('type', $this->params['named']['type']);
|
$this->set('type', $this->params['named']['type']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->params['named']['principle_id'])) {
|
if (isset($this->params['named']['principle_id'])) {
|
||||||
$this->set('principle_id', $this->params['named']['principle_id']);
|
$this->set('principle_id', $this->params['named']['principle_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->params['named']['customer_id'])) {
|
if (isset($this->params['named']['customer_id'])) {
|
||||||
$this->set('customer_id', $this->params['named']['customer_id']);
|
$this->set('customer_id', $this->params['named']['customer_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->params['named']['user_id'])) {
|
if (isset($this->params['named']['user_id'])) {
|
||||||
$userID = $this->params['named']['user_id'];
|
$userID = $this->params['named']['user_id'];
|
||||||
$this->set('user_id', $userID);
|
$this->set('user_id', $userID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->params['named']['action'])) {
|
if (isset($this->params['named']['action'])) {
|
||||||
$action = $this->params['named']['action'];
|
$action = $this->params['named']['action'];
|
||||||
$this->set('action', $action);
|
$this->set('action', $action);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($action) && isset($userID)) {
|
if (isset($action) && isset($userID)) {
|
||||||
$this->data = $this->User->read(null, $userID);
|
$this->data = $this->User->read(null, $userID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_user() {
|
function add_user() {
|
||||||
|
|
||||||
Configure::write('debug', 0);
|
Configure::write('debug', 0);
|
||||||
$this->layout = 'ajax';
|
$this->layout = 'ajax';
|
||||||
if (!empty($this->data)) {
|
if (!empty($this->data)) {
|
||||||
$this->User->create();
|
$this->User->create();
|
||||||
$this->User->set($this->data['User']);
|
$this->User->set($this->data['User']);
|
||||||
|
|
||||||
if ($this->User->save($this->data)) {
|
if ($this->User->save($this->data)) {
|
||||||
$message = __('The User has been saved.', true);
|
$message = __('The User has been saved.', true);
|
||||||
$data = $this->data;
|
$data = $this->data;
|
||||||
$this->set('status', array('status'=>'success'));
|
$this->set('status', array('status'=>'success'));
|
||||||
} else {
|
} else {
|
||||||
$message = __('The User could not be saved.', true);
|
$message = __('The User could not be saved.', true);
|
||||||
$this->set('status', array('status'=>'failure'));
|
$this->set('status', array('status'=>'failure'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if (!empty($this->data)) {
|
/* if (!empty($this->data)) {
|
||||||
|
|
@ -190,33 +191,33 @@ class UsersController extends AppController {
|
||||||
*/
|
*/
|
||||||
function add() {
|
function add() {
|
||||||
|
|
||||||
if (!empty($this->data)) {
|
if (!empty($this->data)) {
|
||||||
$this->User->create();
|
$this->User->create();
|
||||||
if ($this->User->save($this->data)) {
|
if ($this->User->save($this->data)) {
|
||||||
$this->Session->setFlash(__('The User has been saved', true));
|
$this->Session->setFlash(__('The User has been saved', true));
|
||||||
$this->redirect(array('action' => 'index'));
|
$this->redirect(array('action' => 'index'));
|
||||||
} else {
|
} else {
|
||||||
$this->Session->setFlash(__('The User could not be saved. Please, try again.', true));
|
$this->Session->setFlash(__('The User could not be saved. Please, try again.', true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function edit($id = null) {
|
function edit($id = null) {
|
||||||
if (!$id && empty($this->data)) {
|
if (!$id && empty($this->data)) {
|
||||||
$this->Session->setFlash(__('Invalid User', true));
|
$this->Session->setFlash(__('Invalid User', true));
|
||||||
$this->redirect(array('action' => 'index'));
|
$this->redirect(array('action' => 'index'));
|
||||||
}
|
}
|
||||||
if (!empty($this->data)) {
|
if (!empty($this->data)) {
|
||||||
if ($this->User->save($this->data)) {
|
if ($this->User->save($this->data)) {
|
||||||
$this->Session->setFlash(__('The User has been saved', true));
|
$this->Session->setFlash(__('The User has been saved', true));
|
||||||
$this->redirect(array('action' => 'index'));
|
$this->redirect(array('action' => 'index'));
|
||||||
} else {
|
} else {
|
||||||
$this->Session->setFlash(__('The User could not be saved. Please, try again.', true));
|
$this->Session->setFlash(__('The User could not be saved. Please, try again.', true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (empty($this->data)) {
|
if (empty($this->data)) {
|
||||||
$this->data = $this->User->read(null, $id);
|
$this->data = $this->User->read(null, $id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@
|
||||||
echo $javascript->link('global');
|
echo $javascript->link('global');
|
||||||
echo $javascript->link('search');
|
echo $javascript->link('search');
|
||||||
echo $javascript->link('jquery.jeditable.mini');
|
echo $javascript->link('jquery.jeditable.mini');
|
||||||
//echo $javascript->link('ckeditor/adapters/jquery');
|
|
||||||
echo $javascript->link('jquery.validate');
|
echo $javascript->link('jquery.validate');
|
||||||
|
|
||||||
echo $scripts_for_layout;
|
echo $scripts_for_layout;
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@
|
||||||
<h3><?php __('Enquiries Assigned to this User');?></h3>
|
<h3><?php __('Enquiries Assigned to this User');?></h3>
|
||||||
<? /* 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', $enquiries, $status_list);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
echo "No Enquiries for this User";
|
echo "No Enquiries for this User";
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
<?=$javascript->link('view_user'); ?>
|
|
||||||
<?=$javascript->link('view_user_email'); ?>
|
<?=$javascript->link('view_user_email'); ?>
|
||||||
<span id="userID" style="display: none;"><?=$user['User']['id']?></span>
|
<span id="userID" style="display: none;"><?=$user['User']['id']?></span>
|
||||||
|
|
||||||
|
|
@ -33,15 +32,15 @@
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
<div class="related">
|
<div class="related">
|
||||||
<h3><?php __('Enquiries Assigned to this User');?></h3>
|
<h3><?php __('Enquiries Assigned to '.$user['User']['first_name'].' '.$user['User']['last_name']);?></h3>
|
||||||
<button id="show" class="showHide">Show</button>
|
<?php if (!empty($enquiries)) {
|
||||||
<button id="hide" class="showHide">Hide</button>
|
echo $this->element('enquiry_table', $enquiries);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo "No Enquiries have been assigned";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
<div id="ajaxLoadEnquiry" style="display:none;"><?php echo $html->image('ajax-loader.gif'); ?></div>
|
|
||||||
|
|
||||||
<div id="enquiryTable">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,6 @@
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
$('#show').hide();
|
$('#show').hide();
|
||||||
|
|
||||||
$("#ajaxLoadEnquiry").hide();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var userID = $('#userID').text();
|
|
||||||
|
|
||||||
|
|
||||||
var enquiriesURL = '/enquiries/view_user_enquiries/'+userID;
|
|
||||||
|
|
||||||
getPage(enquiriesURL);
|
|
||||||
|
|
||||||
|
|
||||||
$("div.paging > a, div.paging > span > a, th.paginatorSort > a").live('click',function() {
|
|
||||||
destination = $(this).attr('href');
|
|
||||||
getPage(destination);
|
|
||||||
return false;
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#hide').click(function() {
|
$('#hide').click(function() {
|
||||||
$(this).hide();
|
$(this).hide();
|
||||||
|
|
@ -35,14 +15,4 @@ $(function() {
|
||||||
$('#enquiryTable').slideDown('fast');
|
$('#enquiryTable').slideDown('fast');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function getPage(url) {
|
|
||||||
|
|
||||||
$.get(url, function(data) {
|
|
||||||
$('#enquiryTable').html(data);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
Loading…
Reference in a new issue