Added Ajax Add and edit for Contact users. Will extend to regular users and principle contacts shortly
This commit is contained in:
parent
f5b2ed3c67
commit
d5cb432a6d
|
|
@ -115,6 +115,41 @@ class UsersController extends AppController {
|
|||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function add_edit() {
|
||||
Configure::write('debug', 0);
|
||||
|
||||
if(isset($this->params['named']['type'])) {
|
||||
$this->set('type', $this->params['named']['type']);
|
||||
}
|
||||
|
||||
if(isset($this->params['named']['principle_id'])) {
|
||||
$this->set('principle_id', $this->params['named']['principle_id']);
|
||||
}
|
||||
|
||||
if(isset($this->params['named']['customer_id'])) {
|
||||
$this->set('customer_id', $this->params['named']['customer_id']);
|
||||
}
|
||||
|
||||
if(isset($this->params['named']['user_id'])) {
|
||||
$userID = $this->params['named']['user_id'];
|
||||
$this->set('user_id', $userID);
|
||||
}
|
||||
|
||||
if(isset($this->params['named']['action'])) {
|
||||
$action = $this->params['named']['action'];
|
||||
$this->set('action', $action);
|
||||
}
|
||||
|
||||
if(isset($action) && isset($userID)) {
|
||||
$this->data = $this->User->read(null, $userID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
8
vendors/shells/vault_two.php
vendored
8
vendors/shells/vault_two.php
vendored
|
|
@ -214,7 +214,7 @@ class VaultTwoShell extends Shell {
|
|||
}
|
||||
else {
|
||||
echo "Fatal Error: Unable to create user for email '{$recEmailLC}'\n";
|
||||
die();
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -253,8 +253,12 @@ class VaultTwoShell extends Shell {
|
|||
$newEmail['Email']['user_id'] = $recipientsIDs['from'][0]; //We should never have more than one 'from' user ID.
|
||||
}
|
||||
else {
|
||||
die("Email has no from Recipient!! Critical Failure"); //Change this to logging for deployment.
|
||||
print_r($recipientsIDs);
|
||||
echo "Email has no From Recipient ID. Ignoring this.\n";
|
||||
continue;
|
||||
|
||||
}
|
||||
//die("Email has no from Recipient!! Critical Failure"); //Change this to logging for deployment.
|
||||
|
||||
|
||||
// $newEmail['Email']['date'] = $this_header->date;
|
||||
|
|
|
|||
|
|
@ -91,7 +91,8 @@
|
|||
|
||||
<div class="related">
|
||||
<h3><?php __('Contacts');?><?php echo $html->image('system-users.png'); ?></h3>
|
||||
<button id="addUser">Add Contact</button>
|
||||
<button id="addContactUser" class="contact">Add Contact</button>
|
||||
<div class="customer_id" id="<?=$customer['Customer']['id']?>" style="display: none;"></div>
|
||||
<?php if (!empty($customer['Contact'])):?>
|
||||
<table cellpadding = "0" cellspacing = "0">
|
||||
<tr>
|
||||
|
|
@ -121,9 +122,11 @@
|
|||
<td><?php echo $contact['Contact']['fax'];?></td>
|
||||
<td><?php echo $contact['Contact']['notes'];?></td>
|
||||
<td class="actions">
|
||||
<?php echo $html->link(__('View', true), array('controller'=> 'users', 'action'=>'view', $contact['Contact']['id'])); ?>
|
||||
<?php echo $html->link(__('Edit', true), array('controller'=> 'users', 'action'=>'edit', $contact['Contact']['id'])); ?>
|
||||
<?php echo $html->link(__('Delete', true), array('controller'=> 'users', 'action'=>'delete', $contact['Contact']['id'])); ?>
|
||||
<button id="<?=$contact['Contact']['id']?>" class="ViewEditButton">View/Edit</button>
|
||||
|
||||
<?php //echo $html->link(__('View', true), array('controller'=> 'users', 'action'=>'view', $contact['Contact']['id'])); ?>
|
||||
<?php //echo $html->link(__('Edit', true), array('controller'=> 'users', 'action'=>'edit', $contact['Contact']['id'])); ?>
|
||||
<?php //echo $html->link(__('Delete', true), array('controller'=> 'users', 'action'=>'delete', $contact['Contact']['id'])); ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
|
@ -134,27 +137,9 @@
|
|||
|
||||
|
||||
</div>
|
||||
<? echo $javascript->link('add_user'); ?>
|
||||
<? echo $javascript->link('add_edit_user'); ?>
|
||||
<div id="addUserDiv">
|
||||
|
||||
<?php echo $form->create('User');?>
|
||||
|
||||
<?php
|
||||
echo $form->input('first_name');
|
||||
echo $form->input('last_name');
|
||||
echo $form->input('email');
|
||||
echo $form->input('job_title');
|
||||
echo $form->input('phone');
|
||||
echo $form->input('mobile');
|
||||
echo $form->input('fax');
|
||||
echo $form->input('phone_extension');
|
||||
echo $form->input('direct_phone');
|
||||
echo $form->input('notes');
|
||||
echo $form->input('type', array('type'=>'hidden', 'value'=>'contact'));
|
||||
echo $form->input('customer_id', array('type'=>'hidden', 'value'=>$customer['Customer']['id']));
|
||||
echo $form->submit('Add Contact', array('id'=>'submitUserButton'));
|
||||
?>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
|
|
|||
61
views/users/add_edit.ctp
Executable file
61
views/users/add_edit.ctp
Executable file
|
|
@ -0,0 +1,61 @@
|
|||
<?=$javascript->link('add_edit_user_ajax');?>
|
||||
|
||||
<div class="users form">
|
||||
<?php echo $form->create('User',array('action'=>'add_user'));?>
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
echo "TYPE IS :".$type."<br>";
|
||||
echo "customer_id".$customer_id."<br>";
|
||||
echo $form->input('first_name');
|
||||
echo $form->input('last_name');
|
||||
echo $form->input('email');
|
||||
echo $form->input('job_title');
|
||||
echo $form->input('phone');
|
||||
echo $form->input('mobile');
|
||||
echo $form->input('fax');
|
||||
echo $form->input('phone_extension');
|
||||
echo $form->input('direct_phone');
|
||||
echo $form->input('notes');
|
||||
|
||||
|
||||
switch($type) {
|
||||
case 'contact':
|
||||
echo $form->input('customer_id', array('type'=>'hidden', 'value'=>$customer_id));
|
||||
echo $form->input('type', array('type'=>'hidden', 'value'=>'contact'));
|
||||
$buttonStr = 'Contact';
|
||||
break;
|
||||
|
||||
case 'principle':
|
||||
echo $form->input('principle_id', array('type'=>'hidden', 'value'=>$principle_id));
|
||||
$buttonStr = 'Principle Contact';
|
||||
|
||||
case 'user':
|
||||
$buttonStr = 'User';
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch($action) {
|
||||
case 'add':
|
||||
$actionStr = 'Add';
|
||||
break;
|
||||
|
||||
case 'edit':
|
||||
$actionStr ='Edit';
|
||||
echo $form->input('id', array('type'=>'hidden', 'value'=>$user_id));
|
||||
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
echo $form->submit($actionStr.' '.$buttonStr, array('id'=>'submitUserButton'));
|
||||
|
||||
|
||||
?>
|
||||
</div>
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<div class="users form">
|
||||
<?php echo $form->create('User');?>
|
||||
<fieldset>
|
||||
<legend><?php __('Edit User');?></legend>
|
||||
<?php
|
||||
echo $form->input('id');
|
||||
echo $form->input('username');
|
||||
echo $form->input('password');
|
||||
echo $form->input('first_name');
|
||||
echo $form->input('last_name');
|
||||
echo $form->input('email');
|
||||
echo $form->input('job_title');
|
||||
echo $form->input('group_id');
|
||||
?>
|
||||
</fieldset>
|
||||
<?php echo $form->end('Submit');?>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<ul>
|
||||
<li><?php echo $html->link(__('Delete', true), array('action'=>'delete', $form->value('User.id')), null, sprintf(__('Are you sure you want to delete # %s?', true), $form->value('User.id'))); ?></li>
|
||||
<li><?php echo $html->link(__('List Users', true), array('action'=>'index'));?></li>
|
||||
<li><?php echo $html->link(__('List Enquiries', true), array('controller'=> 'enquiries', 'action'=>'index')); ?> </li>
|
||||
<li><?php echo $html->link(__('New Enquiry', true), array('controller'=> 'enquiries', 'action'=>'add')); ?> </li>
|
||||
</ul>
|
||||
</div>
|
||||
63
webroot/js/add_edit_user.js
Normal file
63
webroot/js/add_edit_user.js
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
* JS for adding a Contact to a company.
|
||||
*
|
||||
* 1. open a new model window on the add form.
|
||||
*
|
||||
* 2. When the submit button is clicked, check it for errors
|
||||
*
|
||||
* 3. If it passes the first validation, submit it to PHP controller via AJAX.
|
||||
*
|
||||
* 4a. If PHP reports sucessful save
|
||||
* i. close the Modal Window
|
||||
* ii. add the new contacts user details to the contact table.
|
||||
*
|
||||
* 4b. If PHP reports validation error. Display error. Set error class to the fields that failed.
|
||||
*
|
||||
*/
|
||||
|
||||
$(function() {
|
||||
|
||||
|
||||
//Style the Button
|
||||
$( "#addUser" ).button({
|
||||
text: true,
|
||||
icons: {
|
||||
primary: "ui-icon-plus"
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
//The diaglog box for Adding a contact.
|
||||
$("#addUserDiv").dialog({
|
||||
autoOpen: false,
|
||||
width: 450,
|
||||
modal: true,
|
||||
title: 'Add a Contact'
|
||||
});
|
||||
|
||||
$("#addContactUser").click(function() { //Meh, we'll just repeat this for the 3 user types. Easiest way to handle this.'
|
||||
var userType = 'contact';
|
||||
var customer_id = $('.customer_id').attr('id');
|
||||
var thisAction = 'add'
|
||||
$("#addUserDiv").load('/users/add_edit/action:'+thisAction+'/type:'+userType+'/customer_id:'+customer_id);
|
||||
$("#addUserDiv").dialog('open');
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
//Editing a Customer Contact
|
||||
$('.ViewEditButton').click(function() {
|
||||
var userType ='contact';
|
||||
var thisAction = 'edit';
|
||||
var user_id = $(this).attr('id');
|
||||
|
||||
$("#addUserDiv").load('/users/add_edit/action:'+thisAction+'/type:'+userType+'/user_id:'+user_id);
|
||||
$("#addUserDiv").dialog('open');
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
|
@ -1,49 +1,15 @@
|
|||
/**
|
||||
* JS for adding a Contact to a company.
|
||||
*
|
||||
* 1. open a new model window on the add form.
|
||||
*
|
||||
* 2. When the submit button is clicked, check it for errors
|
||||
*
|
||||
* 3. If it passes the first validation, submit it to PHP controller via AJAX.
|
||||
*
|
||||
* 4a. If PHP reports sucessful save
|
||||
* i. close the Modal Window
|
||||
* ii. add the new contacts user details to the contact table.
|
||||
*
|
||||
* 4b. If PHP reports validation error. Display error. Set error class to the fields that failed.
|
||||
*
|
||||
*/
|
||||
|
||||
$(function() {
|
||||
|
||||
|
||||
//Style the Button
|
||||
$( "#addUser" ).button({
|
||||
text: true,
|
||||
icons: {
|
||||
primary: "ui-icon-plus"
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
//The diaglog box for Adding a contact.
|
||||
$("#addUserDiv").dialog({
|
||||
autoOpen: false,
|
||||
width: 450,
|
||||
modal: true,
|
||||
title: 'Add a Contact'
|
||||
});
|
||||
|
||||
$("#addUser").click(function() {
|
||||
$("#addUserDiv").dialog('open');
|
||||
return false;
|
||||
});
|
||||
/**
|
||||
* Javascript to do the actual validation for Adding/Editing users in the modal window.
|
||||
*/
|
||||
|
||||
|
||||
var _loadingDiv = $("#ajaxLoading");
|
||||
|
||||
$('#UserAddForm, #UserEditForm').submit(function(){
|
||||
$('#submitUserButton').button();
|
||||
|
||||
$('#UserAddUserForm').submit(function(){
|
||||
_loadingDiv.show();
|
||||
$.post('/users/add_user',
|
||||
$(this).serializeArray(),
|
||||
|
|
@ -70,6 +36,8 @@ $(function() {
|
|||
function onSuccess(data) {
|
||||
flashMessage(data.message);
|
||||
_loadingDiv.hide();
|
||||
$('#submitUserButton').button('disable');
|
||||
|
||||
window.setTimeout(function() {
|
||||
// window.location.href = '/posts';
|
||||
window.location.reload(true);
|
||||
|
|
@ -91,7 +59,7 @@ $(function() {
|
|||
function flashMessage(message) {
|
||||
var _insert = $(document.createElement('div')).css('display', 'none');
|
||||
_insert.attr('id', 'flashMessage').addClass('message').text(message);
|
||||
_insert.insertAfter($("#UserAddForm")).fadeIn();
|
||||
_insert.insertAfter($("#UserAddUserForm")).fadeIn();
|
||||
}
|
||||
|
||||
function camelize(string) {
|
||||
|
|
@ -106,4 +74,3 @@ $(function() {
|
|||
|
||||
|
||||
});
|
||||
|
||||
Loading…
Reference in a new issue