cmc-sales/webroot/js/add_edit_user.js

76 lines
1.9 KiB
JavaScript
Raw Normal View History

/**
* 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'
});
$("#addContactUser").click(function() { //Adding a Contact to a Customer.
var userType = 'contact';
var customer_id = $('.customer_id').attr('id');
var thisAction = 'add'
$("#addUserDiv").dialog( "option", "title", 'Add Contact to Customer' );
$("#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');
});
//Editing a Customer Contact
$('.ViewEditButton').click(function() {
2011-06-15 20:27:33 -07:00
var userType = $('#userType').html();
var thisAction = 'edit';
var user_id = $(this).attr('id');
2011-06-15 20:27:33 -07:00
$("#addUserDiv").dialog( "option", "title", 'Edit Contact' );
$("#addUserDiv").load('/users/add_edit/action:'+thisAction+'/type:'+userType+'/user_id:'+user_id);
$("#addUserDiv").dialog('open');
});
});