2011-03-10 17:22:57 -08:00
|
|
|
/**
|
|
|
|
|
* 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,
|
2011-03-10 19:09:38 -08:00
|
|
|
position: 'top'
|
2011-03-10 17:22:57 -08:00
|
|
|
});
|
|
|
|
|
|
2011-03-10 18:58:26 -08:00
|
|
|
$("#addContactUser").click(function() { //Adding a Contact to a Customer.
|
2011-03-10 17:22:57 -08:00
|
|
|
var userType = 'contact';
|
|
|
|
|
var customer_id = $('.customer_id').attr('id');
|
|
|
|
|
var thisAction = 'add'
|
2011-03-10 18:58:26 -08:00
|
|
|
|
|
|
|
|
$("#addUserDiv").dialog( "option", "title", 'Add Contact to Customer' );
|
2011-03-10 17:22:57 -08:00
|
|
|
$("#addUserDiv").load('/users/add_edit/action:'+thisAction+'/type:'+userType+'/customer_id:'+customer_id);
|
|
|
|
|
$("#addUserDiv").dialog('open');
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2011-05-24 02:43:26 -07:00
|
|
|
$("#addPrincipleUser").click(function() {
|
|
|
|
|
var userType = 'principle';
|
|
|
|
|
var customer_id = $('.principle_id').attr('id');
|
|
|
|
|
var thisAction = 'add'
|
|
|
|
|
|
|
|
|
|
$("#addUserDiv").dialog( "option", "title", 'Add Contact to Principle' );
|
|
|
|
|
$("#addUserDiv").load('/users/add_edit/action:'+thisAction+'/type:'+userType+'/principle_id:'+customer_id);
|
|
|
|
|
$("#addUserDiv").dialog('open');
|
|
|
|
|
|
|
|
|
|
});
|
2011-03-10 17:22:57 -08:00
|
|
|
|
|
|
|
|
//Editing a Customer Contact
|
|
|
|
|
$('.ViewEditButton').click(function() {
|
|
|
|
|
var userType ='contact';
|
|
|
|
|
var thisAction = 'edit';
|
|
|
|
|
var user_id = $(this).attr('id');
|
2011-03-10 18:58:26 -08:00
|
|
|
$("#addUserDiv").dialog( "option", "title", 'Edit Customer Contact' );
|
2011-03-10 17:22:57 -08:00
|
|
|
$("#addUserDiv").load('/users/add_edit/action:'+thisAction+'/type:'+userType+'/user_id:'+user_id);
|
|
|
|
|
$("#addUserDiv").dialog('open');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|