Skip to content

Commit

Permalink
Hacking in a quick iPhone site.
Browse files Browse the repository at this point in the history
--HG--
extra : convert_revision : b9bf07b775024dd5ccafae1915002a656bbc07a8
  • Loading branch information
lstoll committed Jun 20, 2009
1 parent 7fb5c8d commit 3f2ce68
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/templates/index.html
Expand Up @@ -26,7 +26,7 @@ <h1 class="center">Tether me!</h1>
{% endif %}
{% include form %}
<p> If you want to download the file direct on your phone, just click download</p>
<p><input type="submit" name="submit" value="Download"/></p>
<p><input type="submit" name="submit_action" value="Download"/></p>
<p> If you want the file e-mailed to your phone, fill in the address and hit send</p>
<p><label for="to">E-Mail address for your phone:</label><br><input type="text" class="title" name="to"/></p>
<input type="submit" name="submit" value="Send"/>
Expand Down
58 changes: 58 additions & 0 deletions app/templates/index_iphone.html
@@ -0,0 +1,58 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>TetherMe</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
<style type="text/css" media="screen">@import "/static/iui/iui.css";</style>
<script type="application/x-javascript" src="/static/iui/iui.js"></script>
</head>

<body>
<div class="toolbar">
<h1 id="pageTitle"></h1>
<a id="backButton" class="button" href="#"></a>
</div>

<!-- Home Page-->
<div id="home" title="TetherMe" selected="true" class="panel">
<h3>Welcome to TetherMe</h3>
<p>This site will help you get tethering up and running on your phone. Either choose your carrier from the list,
or click enter settings and type in the APN details. When you submit, you phone will prompt you to install
the profile. Once installed, look in Settings -> General -> Network -> Tethering. Turn it on, and you are
right to go! (Make sure you are running iTunes 8.2). If the option isn't there, try restarting your phone.</p>
<a class="whiteButton" href="#carriers">Choose Carrier</a>
<a class="whiteButton" href="#manual">Enter Settings</a>
</div>

<!-- Carrier List -->
<ul id="carriers" title="Carriers">
{% for carrier in carriers %}
<li><a href="/get_config/{{carrier.key}}/tether.mobileconfig" target="_self">{{carrier.name}}</a></li>
{% endfor %}
</ul>

<!-- Manual Entry -->
<form id="manual" title="Manual Entry" class="panel" action="/submit_request/" method="POST" target="_self">
<h2>APN Settings</h2>
<fieldset>
<div class="row">
<label>APN</label>
<input type="text" name="apn"/>
</div>
<div class="row">
<label>Username</label>
<input type="text" name="username"/>
</div>
<div class="row">
<label>Password</label>
<input type="text" name="password"/>
</div>
</fieldset>
<input type="hidden" name="submit_action" value="Download">
<a class="whiteButton" type="submit" href="#">Get Config</a>
</form>

</body>

</html>
40 changes: 30 additions & 10 deletions app/views.py
Expand Up @@ -2,23 +2,36 @@
from django.shortcuts import render_to_response
from django.template.loader import get_template
from django.template import Context
from django.views.decorators.cache import cache_page
from django.core.cache import cache
from app.models import *
import urllib
from google.appengine.api import mail

@cache_page(60 * 10)
def index(request):
if request.META["HTTP_USER_AGENT"].find('iPhone') >= 0:
# user is coming from iPhone. Send to iphone page
return HttpResponseRedirect('/iphone')
message = request.GET.get('message', False)
message_type = request.GET.get('message_type', '')
if request.GET.get('manual_apn', '') == 'true':
form = '_manual_apn_form.html'
else:
form = '_carrier_select_form.html'
c = {'form': form, 'message': message, 'message_type': message_type,
'carriers': Carrier.all().filter('listed =', True).order("name").fetch(1000)}
'carriers': listed_carriers()}
return render_to_response('index.html', c)

def index_iphone(request):
message = request.GET.get('message', False)
message_type = request.GET.get('message_type', '')
if request.GET.get('manual_apn', '') == 'true':
form = '_manual_apn_form.html'
else:
form = '_carrier_select_form.html'
c = {'form': form, 'message': message, 'message_type': message_type,
'carriers': listed_carriers()}
return render_to_response('index_iphone.html', c)

def get_config(request, carrier_id):
# get the carrier by ID
carrier = db.get(db.Key(carrier_id))
Expand All @@ -38,12 +51,12 @@ def get_config(request, carrier_id):

# This needs to be redone with proper forms, not this php like crap
def submit_request(request):
carrier = request.GET.get('carrier', False)
apn = request.GET.get('apn', '')
username = request.GET.get('username', '')
password = request.GET.get('password', '')
action = request.GET.get('submit', '')
to = request.GET.get('to', '')
carrier = request.REQUEST.get('carrier', False)
apn = request.REQUEST.get('apn', '')
username = request.REQUEST.get('username', '')
password = request.REQUEST.get('password', '')
action = request.REQUEST.get('submit_action', '')
to = request.REQUEST.get('to', '')

carrier_id = ''
# check to see if we have a carrier specified. If so, act on that.
Expand Down Expand Up @@ -102,4 +115,11 @@ def submit_request(request):
return HttpResponseRedirect('/?message_type=success&message=' + statusmsg)

#end


# returns the listed carriers, getting from cache if there, otherwise caching
def listed_carriers():
items = cache.get('listed_carriers')
if not items:
items = Carrier.all().filter('listed =', True).order("name").fetch(1000)
cache.set('listed_carriers', items, 10 * 60)
return items
2 changes: 1 addition & 1 deletion index.yaml
Expand Up @@ -10,7 +10,7 @@ indexes:
# automatically uploaded to the admin console when you next deploy
# your application using appcfg.py.

# Used 29 times in query history.
# Used 45 times in query history.
- kind: app_carrier
properties:
- name: listed
Expand Down
115 changes: 97 additions & 18 deletions static/iui/iui.js
Expand Up @@ -25,6 +25,8 @@ var landscapeVal = "landscape";

window.iui =
{
animOn: false, // Experimental slide animation with CSS transition disabled by default

showPage: function(page, backwards)
{
if (page)
Expand Down Expand Up @@ -153,21 +155,28 @@ window.iui =
new RegExp("^mailto:"),
new RegExp("^tel:"),
new RegExp("^http:\/\/www.youtube.com\/watch\\?v="),
new RegExp("^http:\/\/www.youtube.com\/v\/")
new RegExp("^http:\/\/www.youtube.com\/v\/"),
new RegExp("^javascript:"),

]
};

// *************************************************************************************************

addEventListener("load", function(event)
{
var page = iui.getSelectedPage();
if (page)
iui.showPage(page);

setTimeout(preloadImages, 0);
setTimeout(checkOrientAndLocation, 0);
checkTimer = setInterval(checkOrientAndLocation, 300);
var page = iui.getSelectedPage();
var locPage = getPageFromLoc();

if (page)
iui.showPage(page);

if (locPage && (locPage != page))
iui.showPage(locPage);

setTimeout(preloadImages, 0);
setTimeout(checkOrientAndLocation, 0);
checkTimer = setInterval(checkOrientAndLocation, 300);
}, false);

addEventListener("unload", function(event)
Expand All @@ -182,7 +191,7 @@ addEventListener("click", function(event)
{
function unselect() { link.removeAttribute("selected"); }

if (link.href && link.hash && link.hash != "#")
if (link.href && link.hash && link.hash != "#" && !link.target)
{
link.setAttribute("selected", "true");
iui.showPage($(link.hash.substr(1)));
Expand All @@ -203,6 +212,10 @@ addEventListener("click", function(event)
{
return;
}
else if (link.target == "_webapp")
{
location.href = link.href;
}
else if (!link.target)
{
link.setAttribute("selected", "progress");
Expand All @@ -225,6 +238,17 @@ addEventListener("click", function(event)
}
}, true);

function getPageFromLoc()
{
var page;
var result = location.hash.match(/#_([^\?_]+)/);
if (result)
page = result[1];
if (page)
page = $(page);
return page;
}

function orientChangeHandler()
{
var orientation=window.orientation;
Expand Down Expand Up @@ -307,7 +331,7 @@ function updatePage(page, fromPage)
if (!page.id)
page.id = "__" + (++newPageCount) + "__";

location.href = currentHash = hashPrefix + page.id;
location.hash = currentHash = hashPrefix + page.id;
pageHistory.push(page.id);

var pageTitle = $("pageTitle");
Expand All @@ -334,15 +358,43 @@ function updatePage(page, fromPage)
function slidePages(fromPage, toPage, backwards)
{
var axis = (backwards ? fromPage : toPage).getAttribute("axis");

clearInterval(checkTimer);

if (canDoSlideAnim() && axis != 'y')
{
slide2(fromPage, toPage, backwards, slideDone);
}
else
{
slide1(fromPage, toPage, backwards, axis, slideDone);
}

function slideDone()
{
// console.log("slideDone");
if (!hasClass(toPage, "dialog"))
fromPage.removeAttribute("selected");
checkTimer = setInterval(checkOrientAndLocation, 300);
setTimeout(updatePage, 0, toPage, fromPage);
fromPage.removeEventListener('webkitTransitionEnd', slideDone, false);
}
}

function canDoSlideAnim()
{
return (iui.animOn) && (typeof WebKitCSSMatrix == "object");
}

function slide1(fromPage, toPage, backwards, axis, cb)
{
if (axis == "y")
(backwards ? fromPage : toPage).style.top = "100%";
else
toPage.style.left = "100%";

toPage.setAttribute("selected", "true");
scrollTo(0, 1);
clearInterval(checkTimer);

toPage.setAttribute("selected", "true");
var percent = 100;
slide();
var timer = setInterval(slide, slideInterval);
Expand All @@ -353,11 +405,8 @@ function slidePages(fromPage, toPage, backwards)
if (percent <= 0)
{
percent = 0;
if (!hasClass(toPage, "dialog"))
fromPage.removeAttribute("selected");
clearInterval(timer);
checkTimer = setInterval(checkOrientAndLocation, 300);
setTimeout(updatePage, 0, toPage, fromPage);
cb();
}

if (axis == "y")
Expand All @@ -374,6 +423,33 @@ function slidePages(fromPage, toPage, backwards)
}
}

//function durationInt(dur)
//{
// var val = parseFloat(dur);
// return (dur.indexOf('ms') == -1) ? val * 1000 : val;
//}

function slide2(fromPage, toPage, backwards, cb)
{
toPage.style.webkitTransitionDuration = '0ms'; // Turn off transitions to set toPage start offset
// fromStart is always 0% and toEnd is always 0%
// iPhone won't take % width on toPage
var toStart = 'translateX(' + (backwards ? '-' : '') + window.innerWidth + 'px)';
var fromEnd = 'translateX(' + (backwards ? '100%' : '-100%') + ')';
toPage.style.webkitTransform = toStart;
toPage.setAttribute("selected", "true");
toPage.style.webkitTransitionDuration = ''; // Turn transitions back on
// var duration = durationInt(window.getComputedStyle(toPage, null).webkitTransitionDuration);
function startTrans()
{
fromPage.style.webkitTransform = fromEnd;
toPage.style.webkitTransform = 'translateX(0%)'; //toEnd
// setTimeout(cb, duration);
}
fromPage.addEventListener('webkitTransitionEnd', cb, false);
setTimeout(startTrans, 0);
}

function preloadImages()
{
var preloader = document.createElement("div");
Expand All @@ -383,7 +459,10 @@ function preloadImages()

function submitForm(form)
{
iui.showPageByHref(form.action || "POST", encodeForm(form), form.method);
if (form.getAttribute("target") != "_self")
iui.showPageByHref(form.action || "POST", encodeForm(form), form.method);
else
form.submit();
}

function encodeForm(form)
Expand Down
1 change: 1 addition & 0 deletions urls.py
Expand Up @@ -12,6 +12,7 @@
(r'^admin/delete_carrier/(.*)/$', 'app.views_admin.delete_carrier'),
(r'^get_config/(.*)/tether.mobileconfig', 'app.views.get_config'),
(r'^submit_request/$', 'app.views.submit_request'),
(r'^iphone/$', 'app.views.index_iphone'),
# Example:
# (r'^tetherme_django/', include('tetherme_django.foo.urls')),

Expand Down

0 comments on commit 3f2ce68

Please sign in to comment.