App-Office-Contacts
view release on metacpan or search on metacpan
htdocs/assets/templates/app/office/contacts/homepage.tx view on Meta::CPAN
},
No: function()
{
$(this).dialog("close");
}
},
dialogClass: "no-close",
modal: true
});
}
function delete_org()
{
var name = $("#update_org_name").val();
var sid = $("#update_org_sid").val();
$.ajax
({
data:
{
organization_id: $("#update_org_id").val(),
name: name,
sid: sid
},
dataType: "xml",
type: "POST",
url: "/Organization/delete",
success: function(response, status, jqXHR)
{
var $xml = $(response);
var error = $xml.find("error").text();
var html = $xml.find("html").text();
if (error != "")
{
status_error(error, html);
return;
}
$("#status_div").val("Status: Deleted " + name);
// Next, update the occupation list of the displayed person, if any,
// and if this organization did indeed employ that person.
// Actually we update the occ list without checking for the org explicitly.
var visible_person_id = $("#update_person_id").val();
if (visible_person_id != null)
{
update_occupations($("#update_person_name").val(), visible_person_id, sid);
}
// Lastly, update the search results to remove the deleted organization.
search();
// Set focus to Search tab's search_name field.
global_tab_div.tabs("option", "active", 0);
setTimeout(function(){$("#search_name").focus();}, 10);
},
error: function(jqXHR, status, error)
{
status_error("Cannot delete organization", "HTTP error: " + error);
}
});
}
function delete_org_note(note_id)
{
$("#confirm_delete")
.empty()
.append("Really delete note for " + $("#update_org_name").val() + "?")
.dialog
({
buttons:
{
Yes: function()
{
delete_orgs_note(note_id);
$(this).dialog("close");
},
No: function()
{
$(this).dialog("close");
}
},
dialogClass: "no-close",
modal: true
});
}
function delete_orgs_note(note_id)
{
$.ajax
({
data:
{
entity_id: $("#update_org_id").val(),
entity_type: "organizations", // Must use name of table.
note_id: note_id,
sid: $("#update_org_sid").val()
},
dataType: "xml",
type: "POST",
url: "/Note/delete",
success: function(response, status, jqXHR)
{
var $xml = $(response);
var error = $xml.find("error").text();
var html = $xml.find("html").text();
if (error != "")
{
status_error(error, html);
return;
}
htdocs/assets/templates/app/office/contacts/homepage.tx view on Meta::CPAN
$("#status_div").val("Status: Deleted note");
},
error: function(jqXHR, status, error)
{
status_error("Cannot delete person", "HTTP error: " + error);
}
});
}
function delete_person()
{
var sid = $("#update_person_sid").val();
var name = generate_update_persons_name();
$.ajax
({
data:
{
given_names: $("#update_person_given_names").val(),
name: name,
person_id: $("#update_person_id").val(),
sid: sid,
surname: $("#update_person_surname").val(),
},
dataType: "xml",
type: "POST",
url: "/Person/delete",
success: function(response, status, jqXHR)
{
var $xml = $(response);
var error = $xml.find("error").text();
var html = $xml.find("html").text();
if (error != "")
{
status_error(error, html);
return;
}
$("#status_div").val("Status: Deleted " + name);
// Next, update the staff list of the displayed org, if any,
// and if this person was indeed a member of their staff.
// Actually we update the staff list without checking for the person explicitly.
var visible_org_id = $("#update_org_id").val();
if (visible_org_id != null)
{
update_staff($("#update_org_name").val(), visible_org_id, sid);
}
// Lastly, update the search results to remove the deleted person.
search();
// Set focus to Search tab's search_name field.
global_tab_div.tabs("option", "active", 0);
setTimeout(function(){$("#search_name").focus();}, 10);
},
error: function(jqXHR, status, error)
{
status_error("Cannot delete person", "HTTP error: " + error);
}
});
}
function delete_person_from_staff(person_name, person_id, organization_id, occupation_id)
{
$.ajax
({
data:
{
occupation_id: occupation_id,
organization_id: organization_id,
person_id: person_id,
sid: $("#staff_sid").val()
},
dataType: "xml",
type: "POST",
url: "/Occupation/delete_staff",
success: function(response, status, jqXHR)
{
// Step 1: Check for errors.
var $xml = $(response);
var error = $xml.find("error").text();
var html = $xml.find("html").text();
if (error != "")
{
status_error(error, html);
return;
}
// Step 2: Display updated staff list.
$("#staff_list_div")
.empty()
.append(html);
$("#status_div").val("Status: Deleted staff member");
// Step 3: Check to see if the person who was deleted
// from the staff is currently displayed.
// If they are visible, their list of occupations must be updated.
var visible_person_id = $("#update_person_id").val();
if (visible_person_id == null)
{
return;
}
var ajax_person_id = $xml.find("person_id").text();
if (visible_person_id == ajax_person_id)
{
htdocs/assets/templates/app/office/contacts/homepage.tx view on Meta::CPAN
{
$("#confirm_delete")
.empty()
.append("Really delete staff member " + person_name + "?")
.dialog
({
buttons:
{
Yes: function()
{
delete_person_from_staff(person_name, person_id, organization_id, occupation_id);
$(this).dialog("close");
},
No: function()
{
$(this).dialog("close");
}
},
dialogClass: "no-close",
modal: true
});
}
function display_organization(org_id, sid)
{
$.ajax
({
data:
{
organization_id: org_id,
sid: sid
},
dataType: "xml",
type: "POST",
url: "/Organization/display",
success: function(response, status, jqXHR)
{
var $xml = $(response);
var error = $xml.find("error").text();
var html = $xml.find("html").text();
if (error != "")
{
status_error(error, html);
return;
}
status_ok();
$("#update_org_tab").empty().append(html);
$("#add_staff_button, #add_org_note_button, #delete_org_button, #update_org_button").button();
$("#update_org_div").tabs
({
beforeActivate: function(event, tab)
{
switch (tab.index)
{
case 0: // Update org tab.
setTimeout(function(){$("#update_org_name").focus();}, 10);
break;
case 1: // Add staff tab.
setTimeout(function(){$("#add_staff_person_name").focus();}, 10);
break;
case 2: // Add note tab.
setTimeout(function(){$("#org_note").focus();}, 10);
break;
}
}
});
global_tab_div.tabs("option", "active", 1); // Update tab within global tabs.
update_tab_div.tabs("option", "active", 1); // Organization tab within Update tab.
// These 2 functions don't work if included globally.
// They must follow after the 'response' is inserted into the DOM.
$(function()
{
$("#add_staff_occ_title").autocomplete
({
source: "/AutoComplete?type=occ_title&sid=" + $("#update_org_sid").val(),
minLength: 2,
select: function(event, ui)
{
$("#add_staff_occ_title").val(ui.item ? ui.item.value : "-");
}
});
});
$(function()
{
$("#add_staff_person_name").autocomplete
({
source: "/AutoComplete?type=person_name&sid=" + $("#update_org_sid").val(),
minLength: 2,
select: function(event, ui)
{
$("#add_staff_person_name").val(ui.item ? ui.item.value : "-");
}
});
});
$("#add_org_note_button").click(function(e)
{
add_org_note();
});
$("#add_staff_button").click(function(e)
{
add_staff();
});
$("#delete_org_button").click(function(e)
{
$("#confirm_delete")
.empty()
.append("Really delete " + $("#update_org_name").val() + "?")
.dialog
({
buttons:
{
Yes: function()
{
delete_org();
$(this).dialog("close");
},
No: function()
{
$(this).dialog("close");
}
},
dialogClass: "no-close",
modal: true
});
});
$("#update_org_button").click(function(e)
{
update_org();
});
},
error: function(jqXHR, status, error)
{
status_error("Cannot display organization", "HTTP error: " + error);
}
});
}
function display_person(person_id, sid)
{
$.ajax
({
data:
{
person_id: person_id,
sid: sid
},
dataType: "xml",
type: "POST",
url: "/Person/display",
success: function(response, status, jqXHR)
{
var $xml = $(response);
var error = $xml.find("error").text();
var html = $xml.find("html").text();
if (error != "")
{
status_error(error, html);
return;
}
status_ok();
$("#update_person_tab").empty().append(html);
$("#add_occ_button, #add_person_note_button, #delete_person_button, #update_person_button").button();
$("#update_person_div").tabs
({
beforeActivate: function(event, tab)
{
switch (tab.index)
{
case 0: // Update person tab.
setTimeout(function(){$("#update_person_given_names").focus();}, 10);
break;
case 1: // Add occ tab.
setTimeout(function(){$("#add_occ_org_name").focus();}, 10);
break;
case 2: // Add note tab.
setTimeout(function(){$("#person_note").focus();}, 10);
break;
}
}
});
global_tab_div.tabs("option", "active", 1); // Update tab within global tabs.
update_tab_div.tabs("option", "active", 0); // Person tab within Update tab.
// These 2 functions don't work if included globally.
// They must follow after the 'response' is inserted into the DOM.
$(function()
{
$("#add_occ_occ_title").autocomplete
({
source: "/AutoComplete?type=occ_title&sid=" + $("#update_person_sid").val(),
minLength: 2,
select: function(event, ui)
{
$("#add_occ_occ_title").val(ui.item ? ui.item.value : "-");
}
});
});
$(function()
{
$("#add_occ_org_name").autocomplete
({
source: "/AutoComplete?type=org_name&sid=" + $("#update_person_sid").val(),
minLength: 2,
select: function(event, ui)
{
$("#add_occ_org_name").val(ui.item ? ui.item.value : "-");
}
});
});
$("#add_occ_button").click(function(e)
{
add_occ();
});
$("#add_person_note_button").click(function(e)
{
add_person_note();
});
$("#delete_person_button").click(function(e)
{
$("#confirm_delete")
.empty()
.append("Really delete " + generate_update_persons_name() + "?")
.dialog
({
buttons:
{
Yes: function()
{
delete_person();
$(this).dialog("close");
htdocs/assets/templates/app/office/contacts/homepage.tx view on Meta::CPAN
},
error: function(jqXHR, status, error)
{
status_error("Cannot update note", "HTTP error: " + error);
}
});
}
function update_staff(org_name, org_id, sid)
{
$.ajax
({
data:
{
organization_id: org_id,
sid: sid
},
dataType: "xml",
type: "POST",
url: "/Organization/get_staff",
success: function(response, status, jqXHR)
{
// Step 1: Check for errors.
var $xml = $(response);
var error = $xml.find("error").text();
var html = $xml.find("html").text();
if (error != "")
{
status_error(error, html);
return;
}
// Step 2: Display updated occupation list.
$("#staff_list_div")
.empty()
.append(html);
},
error: function(jqXHR, status, error)
{
status_error("Cannot update staff for "+ org_name, "HTTP error: " + error);
}
});
}
$(document).ready(function()
{
// Set up the tabs.
global_tab_div = $("#global_tab_div")
.tabs
({
beforeActivate: function(event, tab)
{
switch (tab.index)
{
case 0: // Search tab.
setTimeout(function(){$("#search_name").focus();}, 10);
break;
case 1: // Add tab.
setTimeout(function(){$("#add_org_name").focus();}, 10);
setTimeout(function(){$("#add_person_given_names").focus();}, 10);
break;
}
}
});
global_tab_div.tabs().css('visibility','visible');
update_tab_div = $("#update_tab_div")
.tabs();
add_tab_div = $("#add_tab_div")
.tabs
({
beforeActivate: function(event, tab)
{
switch (tab.index)
{
case 0: // Add person tab.
setTimeout(function(){$("#add_person_given_names").focus();}, 10);
break;
case 1: // Add org tab.
setTimeout(function(){$("#add_org_name").focus();}, 10);
break;
}
}
});
// Prepare to add orgs.
$("#add_org_button").button();
$("#add_org_button").click(function(e)
{
add_org();
});
// Prepare to add people.
$("#add_person_button").button();
$("#add_person_button").click(function(e)
{
add_person();
});
// Prepare for reports.
$("#generate_report_button").button();
$("#generate_report_button").click(function(e)
{
generate_report();
});
// Start with the focus in the search tab's name field.
$("#search_name").focus();
$("#search_form").submit(function()
{
search();
return false;
});
// Handle the checkboxes on the Report tab.
$("input:checkbox").each(function()
{
var $t = $(this);
$t.change(function()
{
$t.val() == 1 ? $t.val(0) : $t.val(1);
});
});
});
</script>
</html>
( run in 2.882 seconds using v1.01-cache-2.11-cpan-5b529ec07f3 )