Find form now autopopulates the section drop down after you choose the cemetery

git-svn-id: https://rosehill.googlecode.com/svn/branches/php@28 100bd78a-fc82-11de-b5bc-ffd2847a4b57
This commit is contained in:
inghamn 2010-01-06 17:10:08 +00:00
parent 83af615ad8
commit 4cb6876aed
6 changed files with 98 additions and 109 deletions

View File

@ -15,7 +15,7 @@ $return_url = isset($this->return_url) ? $this->return_url : BASE_URL.'/intermen
<table>
<tr><td><label for="interment-cemetery_id" class="required">Cemetery</label></td>
<td><select name="interment[cemetery_id]" id="interment-cemetery_id"
onchange="populateSections(this.options[this.selectedIndex].value)">
onchange="COB.populateSections(this.options[this.selectedIndex].value,'interment-section_id','<?php echo BASE_URL; ?>')">
<option></option>
<?php
$list = new CemeteryList();
@ -90,27 +90,3 @@ $return_url = isset($this->return_url) ? $this->return_url : BASE_URL.'/intermen
</button>
</fieldset>
</form>
<script type="text/javascript">
function populateSections(cemetery_id) {
var url = '<?php echo BASE_URL; ?>/cemeteries/viewCemetery.php?format=json;cemetery_id=' + cemetery_id;
YAHOO.util.Connect.asyncRequest('GET',url,{
success : function (o) {
var select = document.getElementById('interment-section_id');
select.innerHTML = '';
select.appendChild(document.createElement('option'));
var sections = YAHOO.lang.JSON.parse(o.responseText).sections
for (i in sections) {
var option = document.createElement('option');
option.setAttribute('value',sections[i].id);
option.appendChild(document.createTextNode(sections[i].code));
select.appendChild(option);
}
},
failure : function (o) {
}
});
}
</script>

View File

@ -1,6 +1,6 @@
<?php
/**
* @copyright 2009 City of Bloomington, Indiana
* @copyright 2009-2010 City of Bloomington, Indiana
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* @author Cliff Ingham <inghamn@bloomington.in.gov>
*/
@ -18,31 +18,44 @@
value="<?php echo isset($_GET['firstname']) ? View::escape($_GET['firstname']) : ''; ?>" />
</td>
</tr>
<?php
$cemeteries = new CemeteryList();
$cemeteries->find();
foreach ($cemeteries as $cemetery) {
$name = View::escape($cemetery->getName());
$fieldname = 'sections_'.$cemetery->getId();
echo "
<tr><td><label for=\"\">$name Sections</label></td>
<td><select name=\"$fieldname\">
<option value=\"\">All</option>
";
foreach ($cemetery->getSections() as $section) {
$selected = (isset($_GET[$fieldname]) && $_GET[$fieldname]==$section->getId())
<tr><td><label for="cemetery_id">Cemetery</label></td>
<td><select name="cemetery_id" id="cemetery_id"
onchange="COB.populateSections(this.options[this.selectedIndex].value,'section_id','<?php echo BASE_URL; ?>')">
<option></option>
<?php
$cemeteries = new CemeteryList();
$cemeteries->find();
foreach ($cemeteries as $cemetery) {
$name = View::escape($cemetery->getName());
$selected = (isset($_GET['cemetery_id']) && $_GET['cemetery_id']==$cemetery->getId())
? 'selected="selected"'
: '';
$name = View::escape($section);
echo "<option value=\"{$section->getId()}\" $selected>$name</option>";
}
echo "
</select>
</td>
</tr>
";
}
?>
echo "<option value=\"{$cemetery->getId()}\" $selected>$name</option>";
}
?>
</select>
</td>
</tr>
<tr><td><label for="section_id">Section</label></td>
<td><select name="section_id" id="section_id">
<option></option>
<?php
if (isset($_GET['cemetery_id'])) {
$sections = new SectionList(array('cemetery_id'=>$_GET['cemetery_id']));
foreach ($sections as $section) {
$name = $section->getName()
? View::escape($section->getName())
: View::escape($section->getCode());
$selected = isset($_GET['section_id']) && $section->getId()==$_GET['section_id']
? 'selected="selected"'
: '';
echo "<option value=\"{$section->getId()}\" $selected>$name</option>";
}
}
?>
</select>
</td>
</tr>
</table>
<div>
<button type="submit" class="search">Search</button>

View File

@ -16,7 +16,7 @@ $return_url = $this->return_url ? $this->return_url : BASE_URL.'/interments';
<table>
<tr><td><label for="interment-cemetery_id" class="required">Cemetery</label></td>
<td><select name="interment[cemetery_id]" id="interment-cemetery_id"
onchange="populateSections(this.options[this.selectedIndex].value)">
onchange="COB.populateSections(this.options[this.selectedIndex].value,'interment-section_id','<?php echo BASE_URL; ?>')">
<option></option>
<?php
$list = new CemeteryList();
@ -128,27 +128,3 @@ $return_url = $this->return_url ? $this->return_url : BASE_URL.'/interments';
</button>
</fieldset>
</form>
<script type="text/javascript">
function populateSections(cemetery_id) {
var url = '<?php echo BASE_URL; ?>/cemeteries/viewCemetery.php?format=json;cemetery_id=' + cemetery_id;
YAHOO.util.Connect.asyncRequest('GET',url,{
success : function (o) {
var select = document.getElementById('interment-section_id');
select.innerHTML = '';
select.appendChild(document.createElement('option'));
var sections = YAHOO.lang.JSON.parse(o.responseText).sections
for (i in sections) {
var option = document.createElement('option');
option.setAttribute('value',sections[i].id);
option.appendChild(document.createTextNode(sections[i].code));
select.appendChild(option);
}
},
failure : function (o) {
}
});
}
</script>

View File

@ -4,54 +4,47 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* @author Cliff Ingham <inghamn@bloomington.in.gov>
*/
$currentPage = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$knownFields = array('lastname','firstname');
$cemeteries = new CemeteryList();
$cemeteries->find();
foreach ($cemeteries as $cemetery) {
$knownFields[] = 'section_'.$cemetery->getId();
}
$knownFields = array('lastname','firstname','cemetery_id','section_id');
$search = array();
foreach ($_GET as $field=>$value) {
if ($value) {
if (false !== strpos($field,'section')) {
try {
$section = new Section($value);
$search['section_id'] = $section->getId();
}
catch (Exception $e) {
// Just ignore any unknown sections
}
}
else {
if (in_array($field,$knownFields)) {
$search[$field] = $value;
}
if (in_array($field,$knownFields)) {
$search[$field] = $value;
}
}
}
if (count($search)) {
$order = isset($_GET['sort']) ? $_GET['sort'] : null;
$intermentList = new IntermentList($search,$order,50,$currentPage);
}
$template = new Template();
$template->blocks[] = new Block('interments/findForm.inc');
if (isset($intermentList)) {
$template->blocks[] = new Block('interments/intermentList.inc',
array('intermentList'=>$intermentList));
}
else {
if (userIsAllowed('Interments')) {
// Only the HTML version will include the findForm, addForm, and about page.
$template = isset($_GET['format']) ? new Template('default',$_GET['format']) : new Template();
if ($template->outputFormat=='html') {
$template->blocks[] = new Block('interments/findForm.inc');
if (userIsAllowed('Interments') && !count($search)) {
$return_url = new URL($_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
$template->blocks[] = new Block('interments/addIntermentForm.inc',
array('return_url'=>$return_url));
}
$template->blocks['panel-one'][] = new Block('about.inc');
}
$template->blocks['panel-one'][] = new Block('about.inc');
// All output formats will include the list of interments
if (count($search)) {
$order = isset($_GET['sort']) ? $_GET['sort'] : null;
if ($template->outputFormat=='html') {
$currentPage = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$intermentList = new IntermentList($search,$order,50,$currentPage);
}
else {
$intermentList = new IntermentList();
$intermentList->find();
}
$template->blocks[] = new Block('interments/intermentList.inc',
array('intermentList'=>$intermentList));
}
echo $template->render();

29
html/js/functions.js Normal file
View File

@ -0,0 +1,29 @@
/**
* @copyright 2010 City of Bloomington, Indiana
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* @author Cliff Ingham <inghamn@bloomington.in.gov>
*/
var COB = {};
COB.populateSections = function(cemetery_id,select_id,BASE_URL) {
var url = BASE_URL + '/cemeteries/viewCemetery.php?format=json;cemetery_id=' + cemetery_id;
YAHOO.util.Connect.asyncRequest('GET',url,{
success : function (o) {
var select = document.getElementById(select_id);
select.innerHTML = '';
select.appendChild(document.createElement('option'));
var sections = YAHOO.lang.JSON.parse(o.responseText).sections
for (i in sections) {
var option = document.createElement('option');
option.setAttribute('value',sections[i].id);
option.appendChild(document.createTextNode(sections[i].code));
select.appendChild(option);
}
},
failure : function (o) {
}
});
}

View File

@ -15,5 +15,7 @@
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/connection/connection-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/datasource/datasource-min.js"></script>
<script type="text/javascript" src="<?php echo BASE_URL; ?>/js/functions.js"></script>
<title>Cemeteries</title>
</head>