App-Office-Contacts

 view release on metacpan or  search on metacpan

htdocs/assets/templates/app/office/contacts/homepage.tx  view on Meta::CPAN

		</div>
	</div>
    <div id="global_report_tab"><: $html4report :></div>
    <div id="global_error_tab"><: $html4error :></div>
    <div id="global_about_tab"><: $html4about :></div>
</div>

<div id="confirm_delete" style="display: none" title="Confirm Delete">Really delete this record and all associated records?</div>

</body>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript">$.uiBackCompat = false;</script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript" src="<: $datatable_js_url :>"></script>

<script type="text/javascript">

var add_tab_div;
var global_tab_div;
var update_tab_div;

function add_occ()
{
	var occ_title = $("#add_occ_occ_title").val();
	var org_name  = $("#add_occ_org_name").val();

	if ( (occ_title == "") || (org_name == "") )
	{
		$("#add_occ_occ_title").focus();

		return;
	}

	$.ajax
	({
		data:
		{
			occupation_title:  occ_title,
			organization_name: org_name,
			person_id:         $("#update_person_id").val(),
			sid:               $("#update_person_sid").val(),
		},
		dataType: "xml",
		type: "POST",
		url: "/Occupation/add_occupation",
		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.

			$("#occ_list_div")
			.empty()
			.append(html);

			$("#status_div").val("Status: Added occupation");
			$("#add_occ_org_name").val("").focus();
			$("#add_occ_occ_title").val("");

			// Step 3: Check to see if the organization which was added
			// as an employer is currently displayed.
			// If they are visible, their list of staff must be updated.

			var visible_org_id = $("#update_org_id").val();

			if (visible_org_id == null)
			{
				return;
			}

			var ajax_org_id = $xml.find("org_id").text();

			if (visible_org_id == ajax_org_id)
			{
				update_staff(org_name, visible_org_id, $("#occ_sid").val() );
			}
		},
		error: function(jqXHR, status, error)
		{
			status_error("Cannot add " + occ_title, "HTTP error: " + error);
		}
	});
}

function add_org()
{
	$.ajax
	({
		data:
		{
			communication_type_id:   $("#add_org_communication_type_id").val(),
			email_address_1:         $("#add_org_email_address_1").val(),
			email_address_2:         $("#add_org_email_address_2").val(),
			email_address_3:         $("#add_org_email_address_3").val(),
			email_address_4:         $("#add_org_email_address_4").val(),
			email_address_type_id_1: $("#add_org_email_address_type_id_1").val(),
			email_address_type_id_2: $("#add_org_email_address_type_id_2").val(),
			email_address_type_id_3: $("#add_org_email_address_type_id_3").val(),
			email_address_type_id_4: $("#add_org_email_address_type_id_4").val(),
			facebook_tag:            $("#add_org_facebook_tag").val(),
			homepage:                $("#add_org_homepage").val(),
			id:                      $("#add_org_id").val(),
			name:                    $("#add_org_name").val(),
			phone_number_1:          $("#add_org_phone_number_1").val(),
			phone_number_2:          $("#add_org_phone_number_2").val(),
			phone_number_3:          $("#add_org_phone_number_3").val(),
			phone_number_4:          $("#add_org_phone_number_4").val(),
			phone_number_type_id_1:  $("#add_org_phone_number_type_id_1").val(),
			phone_number_type_id_2:  $("#add_org_phone_number_type_id_2").val(),
			phone_number_type_id_3:  $("#add_org_phone_number_type_id_3").val(),
			phone_number_type_id_4:  $("#add_org_phone_number_type_id_4").val(),
			role_id:                 $("#add_org_role_id").val(),
			sid:                     $("#add_org_sid").val(),
			twitter_tag:             $("#add_org_twitter_tag").val(),
			visibility_id:           $("#add_org_visibility_id").val()
		},
		dataType: "xml",
		type: "POST",
		url: "/Organization/add",
		success: function(response, status, jqXHR)
		{
			var $xml  = $(response);

htdocs/assets/templates/app/office/contacts/homepage.tx  view on Meta::CPAN


				return;
			}

			$("#person_note_list_div")
			.empty()
			.append(html);

			$("#person_note")
			.val("")
			.focus();

			$("#status_div").val("Status: Added note");
		},
		error: function(jqXHR, status, error)
		{
			status_error("Cannot add note", "HTTP error: " + error);
		}
	});
}

function add_staff()
{
	var occ_title   = $("#add_staff_occ_title").val();
	var person_name = $("#add_staff_person_name").val();

	if ( (occ_title == "") || (person_name == "") )
	{
		$("#add_staff_person_name").focus();

		return;
	}

	$.ajax
	({
		data:
		{
			occupation_title: occ_title,
			organization_id:  $("#update_org_id").val(),
			person_name:      person_name,
			sid:              $("#update_org_sid").val()
		},
		dataType: "xml",
		type: "POST",
		url: "/Occupation/add_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: Added staff member");
			$("#add_staff_person_name").val("").focus();
			$("#add_staff_occ_title").val("");

			// Step 3: Check to see if the person who was added
			// to 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)
			{
				update_occupations(person_name, visible_person_id, $("#staff_sid").val() );
			}
		},
		error: function(jqXHR, status, error)
		{
			status_error("Cannot add " + person_name, "HTTP error: " + error);
		}
	});
}

function delete_occupation(person_name, person_id, organization_id, occupation_id)
{
	$("#confirm_delete")
	.empty()
	.append("Really delete occupation for " + $("#update_person_name").val() + "?")
	.dialog
	({
		buttons:
		{
			Yes: function()
				{
					delete_persons_occupation(person_name, person_id, organization_id, occupation_id);

					$(this).dialog("close");
				},
			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
		},

htdocs/assets/templates/app/office/contacts/homepage.tx  view on Meta::CPAN

			}

			$("#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)
			{
				update_occupations(person_name, visible_person_id, $("#staff_sid").val() );
			}
		},
		error: function(jqXHR, status, error)
		{
			status_error("Cannot delete occupation for " + person_name, "HTTP error: " + error);
		}
	});
}

function delete_person_note(note_id)
{
	$("#confirm_delete")
	.empty()
	.append("Really delete note for " + $("#update_person_name").val() + "?")
	.dialog
	({
		buttons:
		{
			Yes: function()
				{
					delete_persons_note(note_id);

					$(this).dialog("close");
				},
			No: function()
				{
					$(this).dialog("close");
				}
		},
		dialogClass: "no-close",
		modal: true
	});
}

function delete_persons_occupation(person_name, person_id, organization_id, occupation_id)
{
	var sid = $("#occ_sid").val();

	$.ajax
	({
		data:
		{
			occupation_id:   occupation_id,
			organization_id: organization_id,
			person_id:       person_id,
			sid:             sid
		},
		dataType: "xml",
		type: "POST",
		url: "/Occupation/delete_occupation",
		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.

			$("#occ_list_div")
			.empty()
			.append(html);

			$("#status_div").val("Status: Deleted occupation");

			// Step 3: Check to see if the organization which was deleted
			// as an employer is currently displayed.
			// If they are visible, their list of staff must be updated.

			var visible_org_id = $("#update_org_id").val();

			if (visible_org_id == null)
			{
				return;
			}

			var ajax_org_id = $xml.find("org_id").text();

			if (visible_org_id == ajax_org_id)
			{
				update_staff($("#update_org_name").val(), visible_org_id, sid);
			}
		},
		error: function(jqXHR, status, error)
		{
			status_error("Cannot delete occupation for " + person_name, "HTTP error: " + error);
		}
	});
}

function delete_persons_note(note_id)
{
	$.ajax
	({
		data:
		{

			entity_id:   $("#update_person_id").val(),
			entity_type: "people", // Must use name of table.
			note_id:     note_id,
			sid:         $("#update_person_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;
			}

			$("#person_note_list_div")
			.empty()
			.append(html);

			$("#person_note")
			.val("")
			.focus();

			$("#status_div").val("Status: Deleted note");
		},

htdocs/assets/templates/app/office/contacts/homepage.tx  view on Meta::CPAN

			// entity, in case it is a very long list of results.

			$("#result_table").dataTable();
		},
		error: function(jqXHR, status, error)
		{
			status_error("Cannot perform search", "HTTP error: " + error);
		}
	});
}

function status_error(message, text)
{
	$("#status_div")
	.empty()
	.append(message)
	.addClass("error");

	$("#global_error_tab")
	.empty()
	.append("<p align='center'>" + text + "</p>");

	global_tab_div.tabs("option", "activate", 4); // Error tab.
}

function status_ok()
{
	$("#status_div")
	.empty()
	.append("Status: OK")
	.removeClass("error");
}

function update_occupations(person_name, person_id, sid)
{
	$.ajax
	({
		data:
		{
			person_id: person_id,
			sid:       sid
		},
		dataType: "xml",
		type: "POST",
		url: "/Person/get_occupations",
		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.

			$("#occ_list_div")
			.empty()
			.append(html);
		},
		error: function(jqXHR, status, error)
		{
			status_error("Cannot update occupations for "+ person_name, "HTTP error: " + error);
		}
	});
}

function update_org()
{
	var name = $("#update_org_name").val();

	$.ajax
	({
		data:
		{
			communication_type_id:   $("#update_org_communication_type_id").val(),
			email_address_1:         $("#update_org_email_address_1").val(),
			email_address_2:         $("#update_org_email_address_2").val(),
			email_address_3:         $("#update_org_email_address_3").val(),
			email_address_4:         $("#update_org_email_address_4").val(),
			email_address_type_id_1: $("#update_org_email_address_type_id_1").val(),
			email_address_type_id_2: $("#update_org_email_address_type_id_2").val(),
			email_address_type_id_3: $("#update_org_email_address_type_id_3").val(),
			email_address_type_id_4: $("#update_org_email_address_type_id_4").val(),
			facebook_tag:            $("#update_org_facebook_tag").val(),
			homepage:                $("#update_org_homepage").val(),
			name:                    name,
			organization_id:         $("#update_org_id").val(),
			phone_number_1:          $("#update_org_phone_number_1").val(),
			phone_number_2:          $("#update_org_phone_number_2").val(),
			phone_number_3:          $("#update_org_phone_number_3").val(),
			phone_number_4:          $("#update_org_phone_number_4").val(),
			phone_number_type_id_1:  $("#update_org_phone_number_type_id_1").val(),
			phone_number_type_id_2:  $("#update_org_phone_number_type_id_2").val(),
			phone_number_type_id_3:  $("#update_org_phone_number_type_id_3").val(),
			phone_number_type_id_4:  $("#update_org_phone_number_type_id_4").val(),
			role_id:                 $("#update_org_role_id").val(),
			sid:                     $("#update_org_sid").val(),
			twitter_tag:             $("#update_org_twitter_tag").val(),
			visibility_id:           $("#update_org_visibility_id").val()
		},
		dataType: "xml",
		type: "POST",
		url: "/Organization/update",
		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

		url: "/Note/update",
		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;
			}

			$("#person_note_list_div")
			.empty()
			.append(html);

			$("#person_note")
			.val("")
			.focus();

			$("#person_note_text").val("");

			$("#status_div").val("Status: Updated note");
		},
		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)



( run in 1.452 second using v1.01-cache-2.11-cpan-63c85eba8c4 )