From 9e103196874ba6c3af6b178ecd5bdd288eb30318 Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Mon, 4 Jul 2011 15:22:39 +1000 Subject: [PATCH] Improved add_edit-ing of users --- views/customers/customer_contacts.ctp | 23 +++++--- views/users/add_edit.ctp | 6 +-- webroot/js/add_edit_user.js | 75 ++++++++++++++++----------- webroot/js/add_enquiry.js | 44 ++++++++++++++++ 4 files changed, 108 insertions(+), 40 deletions(-) create mode 100644 webroot/js/add_enquiry.js diff --git a/views/customers/customer_contacts.ctp b/views/customers/customer_contacts.ctp index 8c4be252..9a4b04ec 100644 --- a/views/customers/customer_contacts.ctp +++ b/views/customers/customer_contacts.ctp @@ -1,19 +1,26 @@ radio('Enquiry.contact_id', $contacts, array('legend'=>'Choose Contact')); - +echo $form->radio('Enquiry.contact_id', $contacts, array('legend' => 'Choose Contact')); ?> - + -link('add_edit_user'); ?>
+ input('first_name', array('class' => 'required')); + echo $form->input('last_name', array('class' => '')); + echo $form->input('email', array('class' => 'email')); + echo $form->input('job_title'); + echo $form->input('phone'); + echo $form->input('phone_extension'); + echo $form->input('mobile'); + echo $form->input('fax'); - - + echo $form->input('direct_phone'); + echo $form->input('notes'); + ?>
\ No newline at end of file diff --git a/views/users/add_edit.ctp b/views/users/add_edit.ctp index 1ca699c4..b7b865f0 100755 --- a/views/users/add_edit.ctp +++ b/views/users/add_edit.ctp @@ -14,10 +14,10 @@ function processJson(data) { if(data.status == 'success') { - + window.location.reload(); } else { - alert("Error while adding this Contact"); + alert("Error while adding/editing this Contact"); } } @@ -33,7 +33,7 @@ input('first_name', array('class' => 'required')); echo $form->input('last_name', array('class' => '')); -echo $form->input('email', array('class' => 'email')); +echo $form->input('email', array('class' => 'required email')); echo $form->input('job_title'); echo $form->input('phone'); echo $form->input('phone_extension'); diff --git a/webroot/js/add_edit_user.js b/webroot/js/add_edit_user.js index 56bd1501..4d24c6f8 100644 --- a/webroot/js/add_edit_user.js +++ b/webroot/js/add_edit_user.js @@ -20,58 +20,75 @@ $(function() { //Style the Button $( "#addUser" ).button({ - text: true, - icons: { - primary: "ui-icon-plus" - } + text: true, + icons: { + primary: "ui-icon-plus" + } }); //The diaglog box for Adding a contact. $("#addUserDiv").dialog({ - autoOpen: false, - width: 300, - modal: true, - position: 'top' + autoOpen: false, + width: 300, + modal: true, + position: 'top' }); $("#addContactUser").live('click', function() { //Adding a Contact to a Customer. - var userType = 'contact'; - var customer_id = $('.customer_id').attr('id'); - var thisAction = 'add' + 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; + $("#addUserDiv").dialog( "option", "title", 'Add Contact to Customer' ); + + + + + getForm('/users/add_edit/action:'+thisAction+'/type:'+userType+'/customer_id:'+customer_id); + + + $("#addUserDiv").dialog('open'); + return false; }); - - $("#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'); + $("#addPrincipleUser").click(function() { + var userType = 'principle'; + var customer_id = $('.principle_id').attr('id'); + var thisAction = 'add' + + $("#addUserDiv").dialog( "option", "title", 'Add Contact to Principle' ); + getForm('/users/add_edit/action:'+thisAction+'/type:'+userType+'/principle_id:'+customer_id); + $("#addUserDiv").dialog('open'); }); //Editing a Customer Contact $('.ViewEditButton').click(function() { - var userType = $('#userType').html(); - var thisAction = 'edit'; - var user_id = $(this).attr('id'); - $("#addUserDiv").dialog( "option", "title", 'Edit Contact' ); - $("#addUserDiv").load('/users/add_edit/action:'+thisAction+'/type:'+userType+'/user_id:'+user_id); - $("#addUserDiv").dialog('open'); + var userType = $('#userType').html(); + var thisAction = 'edit'; + var user_id = $(this).attr('id'); + $("#addUserDiv").dialog( "option", "title", 'Edit Contact' ); + getForm('/users/add_edit/action:'+thisAction+'/type:'+userType+'/user_id:'+user_id); + $("#addUserDiv").dialog('open'); }); + function getForm(url) { + $.ajax({ + url: url, + cache: false, + success: function(data) { + $("#addUserDiv").html(data); + $("#addUserDiv").dialog('open'); + } + + }); + } }); diff --git a/webroot/js/add_enquiry.js b/webroot/js/add_enquiry.js new file mode 100644 index 00000000..82b2b647 --- /dev/null +++ b/webroot/js/add_enquiry.js @@ -0,0 +1,44 @@ +/** + * file: add_enquiry.js + */ + +$(function() { + + + $("#customer_autocomplete").autocomplete({ + source: "/customers/completeCustomer", + minLength: 2, + select: function( event, ui ) { + $("#customer_id").val(ui.item.id); + + + $.ajax({ + url: '/customers/customerContacts/'+ui.item.id, + cache: false, + success: function(data) { + $(".customer_id").attr('id', ui.item.id); + $("#contacts").html(data); + } + + }); + + /*$.get('/addresses/customerAddresses/'+ui.item.id, function(data) { + $("#address").html(data); + $(".selectAddress", data).button(); + });*/ + + + + } + }); + + + $("#addContact").live('click', function(event) { + event.preventDefault(); + $("#contacts").html("

ADD CONTACT

"); + return false; + }); + + + +}); \ No newline at end of file