64 lines
1.5 KiB
JavaScript
64 lines
1.5 KiB
JavaScript
|
|
/**
|
||
|
|
* 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');
|
||
|
|
|
||
|
|
|
||
|
|
});
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
});
|
||
|
|
|