<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal"
creationComplete="init();onCreationComplete();" currentState="loading"
xmlns:yahoo="com.yahoo.webapis.maps.*"
paddingTop="5" paddingBottom="5" paddingLeft="5" paddingRight="5">
<mx:Script>
<![CDATA[
include "actionscript/yahooMap.as";
import mx.printing.*;
import print.Info;
import mx.controls.*;
import mx.collections.*;
import mx.controls.dataGridClasses.DataGridColumn;
[Bindable]
public var filteredXML:XMLList;
private var regNameFilter:RegExp;
private var regWheelchair:RegExp;
private var regWifi:RegExp;
private var regLanguates:RegExp;
private var regHoursOpenFilter:RegExp;
private var selWheelchairA:String;
private var selWheelchairB:String;
private var selWifiA:String;
private var selWifiB:String;
private var selHoursDay:String;
[Bindable]
private var daysOpenComboList:Array;
[Bindable]
private var languageComboList:Array;
private function setFilterFunction():void {
regNameFilter = new RegExp("^"+branch.text, "i")
if (wheelchair.selected) {
regWheelchair = new RegExp("yes");}
else {
regWheelchair = new RegExp("yes"+"|"+"no");
}
if (wifi.selected) {
regWifi = new RegExp("yes");}
else {
regWifi = new RegExp("yes"+"|"+"no");
}
switch (daysOpen.selectedLabel) {
case "any day" :
regHoursOpenFilter = new RegExp("[1-9]"+"|"+"Closed");
selHoursDay = "sunday";
break;
default :
regHoursOpenFilter = new RegExp("[1-9]");
selHoursDay = daysOpen.selectedLabel;
break;
}
filteredXML = libraryXML.branch.((regNameFilter.test(@name)) &&
(regWheelchair.test(options.@wheelchair)) &&
(regWifi.test(options.@wifi)) &&
(languages.attribute(language.selectedItem.data) == "yes") &&
(regHoursOpenFilter.test(hoursopen.child(selHoursDay).@hours))
);
}
[Bindable]
private var daysOpenComboListArray:Array = [
{label:"any day"},
{label:"sunday"},
{label:"monday"},
{label:"tuesday"},
{label:"wednesday"},
{label:"thursday"},
{label:"friday"},
{label:"saturday"}
];
[Bindable]
private var languageComboListArray:Array = [
{label:"english", data:"english"},
{label:"cantonese", data:"chineseCantonese"},
{label:"mandarin", data:"chineseMandarin"},
{label:"spanish", data:"spanish"},
{label:"german", data:"german"},
{label:"japanese", data:"japanese"},
{label:"vietnamese", data:"vietnamese"},
{label:"french", data:"french"},
{label:"russian", data:"russian"},
{label:"greek", data:"greek"},
{label:"tagalog", data:"tagalog"},
{label:"chaozou", data:"chineseChaozou"},
{label:"taishan", data:"chineseTaishan"},
{label:"kejia", data:"chineseKejia"},
{label:"armenian", data:"armenian"}
];
private function init():void {
branch.text = "";
wheelchair.selected = false;
wifi.selected = false;
languageComboList = new Array();
languageComboList = languageComboListArray;
daysOpenComboList = new Array();
daysOpenComboList = daysOpenComboListArray;
filteredXML = libraryXML.branch;
}
private function about():void {
var aboutText:String= "Please forward comments to: \n\n" +
"Randy Fong \n" +
"SFlibraryMap@randallfonginc.net \n\n" +
"Information on this website was derived from information found on " +
"the San Francisco Public Library website at http://sfpl.lib.ca.us. \n\n";
Alert.show(aboutText,"About Us");
}
<!-- Special e4x Display of data in a Datagrid -->
protected function displayAddress(row:Object, column:DataGridColumn):String {
return row.contact.@address + " " + row.contact.@cross ;
}
private function filterData():void {
filteredXML = libraryXML.branch.(regfilter.test(@name));
}
private function printMap():void {
var pj:FlexPrintJob = new FlexPrintJob();
if (pj.start() != true) {
return
}
pj.addObject(mapPanel, FlexPrintJobScaleType.SHOW_ALL);
pj.send();
}
private function printBranch():void {
if (libraryDG.selectedIndex == -1) {
return
}
var pjBranch:FlexPrintJob = new FlexPrintJob();
if (pjBranch.start() != true) {
return
}
var info:Info = new Info();
this.addChild(info);
info.branch.text = libraryDG.selectedItem.@name + " Branch";
info.address.text = libraryDG.selectedItem.contact.@address
info.cityStateZip.text = "San Francisco, CA " + libraryDG.selectedItem.contact.@zip;
info.phone.text = libraryDG.selectedItem.contact.@phone;
info.notes.text = libraryDG.selectedItem.notes.@comment;
info.sunday.text = " Sunday: " + libraryDG.selectedItem.hoursopen.sunday.@hours;
info.monday.text = " Monday: " + libraryDG.selectedItem.hoursopen.monday.@hours;
info.tuesday.text = " Tuesday: " + libraryDG.selectedItem.hoursopen.tuesday.@hours;
info.wednesday.text = " Wednesday: " + libraryDG.selectedItem.hoursopen.wednesday.@hours;
info.thursday.text = " Thursday: " + libraryDG.selectedItem.hoursopen.thursday.@hours;
info.friday.text = " Friday: " + libraryDG.selectedItem.hoursopen.friday.@hours;
info.saturday.text = " Saturday: " + libraryDG.selectedItem.hoursopen.saturday.@hours;
info.wifi.text = " Wifi Internet: " + libraryDG.selectedItem.options.@wifi;
info.wheelchair.text = "Wheelchair Access: " + libraryDG.selectedItem.options.@wheelchair;
pjBranch.addObject(info, FlexPrintJobScaleType.SHOW_ALL);
pjBranch.send();
removeChild(info);
}
]]>
</mx:Script>
<mx:XML id="libraryXML" source="xml/libraries.xml" format="e4x" />
<mx:Panel id="mapPanel" width="800" height="100%" title="Map of SF Libraries" verticalAlign="center" horizontalAlign="center" backgroundColor="333333">
<yahoo:YahooMapService id="myAS2Map" UUID="{UNIQUEID}" swfDomId="{SWFDOMID}" apiId="{YAHOOAPIKEY}" mapURL = "{MAPSWF}" scaleContent="false" width="100%" height="100%" />
</mx:Panel>
<mx:VBox width="100%" height="100%">
<mx:Panel width="100%" height="120" paddingLeft="10" paddingTop="10" title="Selection" >
<mx:HBox>
<mx:TextInput id="branch" width="110" change="setFilterFunction()" />
<mx:Label text="branch " />
<mx:CheckBox id="wheelchair" label="wheelchair" change="setFilterFunction()" />
<mx:CheckBox id="wifi" label="wifi" change="setFilterFunction()" />
</mx:HBox>
<mx:HBox>
<mx:ComboBox id="language" dataProvider="{languageComboList}" rowCount="10" change="setFilterFunction()" />
<mx:Label text="language " />
<mx:ComboBox id="daysOpen" dataProvider="{daysOpenComboList}" rowCount="8" change="setFilterFunction()" />
<mx:Label text="day open" />
</mx:HBox>
</mx:Panel>
<mx:Panel width="100%" height="100%" title="Results" >
<mx:DataGrid id="libraryDG" dataProvider="{filteredXML}" width="100%" height="100%" click="printBranch()">
<mx:columns>
<mx:DataGridColumn headerText="Branch" dataField="@name"/>
<mx:DataGridColumn headerText="Address" labelFunction="displayAddress" />
</mx:columns>
</mx:DataGrid>
<mx:HBox width="100%" height="35" horizontalAlign="center" paddingTop="10">
<mx:Button id="btnApplyToMap" label="Map Results" click="setMarkerByAddress(filteredXML)" />
<mx:Button id="btnShowAllBranches" label="Reset Selection" click="init()" />
<mx:Button id="btnPrintMap" label="PrintMap" click="printMap()" />
<mx:Button id="btnAbout" label="About" click="about()" />
</mx:HBox>
</mx:Panel>
</mx:VBox>
<mx:states>
<mx:State name="loading">
<mx:AddChild relativeTo="{mapPanel}" position="lastChild">
<mx:Spacer height="50" />
<mx:ProgressBar labelPlacement="bottom" id="progressBar" indeterminate="true" enabled="true" label="Please wait, loading map..." verticalCenter="0" horizontalCenter="0"/>
</mx:AddChild>
<mx:SetStyle name="horizontalAlign" value="center" />
<mx:SetStyle name="verticalAlign" value="middle" />
<mx:SetProperty target="{myAS2Map}" name="includeInLayout" value="false" />
</mx:State>
</mx:states>
</mx:Application>