done with exercise 2 up to creating the submit button
This commit is contained in:
parent
c6acc925a0
commit
8a0608152e
@ -1,9 +1,47 @@
|
||||
<mx:Application name=""
|
||||
xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
|
||||
<mx:Label x="54" y="25" text="Zip Code"/>
|
||||
<mx:Label x="65" y="51" text="Weight"/>
|
||||
<mx:TextInput x="128" y="23" id="zipcode"/>
|
||||
<mx:TextInput x="128" y="49" id="weight_lb"/>
|
||||
<mx:Button x="128" y="79" label="Get Shipping Options"/>
|
||||
<mx:TextArea x="339" y="24" width="198" height="77" id="shippingOptions"/>
|
||||
xmlns:mx="http://www.adobe.com/2006/mxml"
|
||||
layout="absolute"
|
||||
backgroundColor="#FFFFFF"
|
||||
backgroundImage="">
|
||||
|
||||
<mx:Script>
|
||||
<![CDATA[
|
||||
|
||||
import mx.rpc.events.ResultEvent;
|
||||
import mx.rpc.events.FaultEvent;
|
||||
import mx.controls.Alert;
|
||||
|
||||
|
||||
private function handlePlain(event:ResultEvent):void
|
||||
{
|
||||
shippingOptions.htmlText = event.result.toString();
|
||||
}
|
||||
|
||||
|
||||
private function handleFault(event:FaultEvent):void
|
||||
{
|
||||
Alert.show(event.fault.faultString, "Error");
|
||||
}
|
||||
|
||||
]]>
|
||||
</mx:Script>
|
||||
|
||||
<mx:HTTPService id="plainRPC" url="http://localhost:18080/text"
|
||||
result="handlePlain(event)"
|
||||
fault="handleFault(event)"
|
||||
resultFormat="text">
|
||||
<mx:request xmlns="">
|
||||
<zipcode>{zipcode.text}</zipcode>
|
||||
<pounds>{weight_lb.text}</pounds>
|
||||
</mx:request>
|
||||
</mx:HTTPService>
|
||||
|
||||
<mx:Label x="54" y="25" text="Zip Code"/>
|
||||
<mx:Label x="65" y="51" text="Weight"/>
|
||||
<mx:TextInput x="128" y="23" id="zipcode"/>
|
||||
<mx:TextInput x="128" y="49" id="weight_lb"/>
|
||||
<mx:Button x="128" y="79" label="Get Shipping Options"
|
||||
click="plainRPC.send();" />
|
||||
<mx:TextArea x="339" y="24" width="198" height="77" id="shippingOptions"/>
|
||||
|
||||
</mx:Application>
|
||||
|
@ -19,6 +19,7 @@ def shipping_app(environ, start_response):
|
||||
handler = {
|
||||
'text': plaintext_handler,
|
||||
'xml': xml_handler,
|
||||
'crossdomain.xml': crossdomain_xml_handler,
|
||||
}.get(path_info)
|
||||
|
||||
if handler:
|
||||
@ -48,8 +49,8 @@ def get_params(environ):
|
||||
|
||||
def xml_handler(environ, start_response):
|
||||
params = get_params(environ)
|
||||
zipcode = int(params.get('zipcode', 0))
|
||||
pounds = int(params.get('pounds', 0))
|
||||
zipcode = int(float(params.get('zipcode', 0)))
|
||||
pounds = int(float(params.get('pounds', 0)))
|
||||
|
||||
ret = ['<options>']
|
||||
for service, price in get_shipping_options(zipcode, pounds).iteritems():
|
||||
@ -67,8 +68,8 @@ def xml_handler(environ, start_response):
|
||||
|
||||
def plaintext_handler(environ, start_response):
|
||||
params = get_params(environ)
|
||||
zipcode = int(params.get('zipcode', 0))
|
||||
pounds = int(params.get('pounds', 0))
|
||||
zipcode = int(float(params.get('zipcode', 0)))
|
||||
pounds = int(float(params.get('pounds', 0)))
|
||||
|
||||
ret = []
|
||||
for service, price in get_shipping_options(zipcode, pounds).iteritems():
|
||||
@ -82,6 +83,21 @@ def plaintext_handler(environ, start_response):
|
||||
return [body]
|
||||
|
||||
|
||||
def crossdomain_xml_handler(environ, start_response):
|
||||
start_response('200 OK', [
|
||||
('content-type', 'text/xml'),
|
||||
('content-length', str(len(XD_XML))),
|
||||
])
|
||||
return [XD_XML]
|
||||
|
||||
|
||||
XD_XML = """\
|
||||
<cross-domain-policy>
|
||||
<allow-access-from domain="*"/>
|
||||
</cross-domain-policy>
|
||||
"""
|
||||
|
||||
|
||||
def get_shipping_options(zipcode, pounds):
|
||||
base_cost = (float(zipcode) / 10000.0) + (pounds * 5.0)
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user