starting to break out some Ajax crap, wheeeeee

This commit is contained in:
Dan Buch 2011-08-01 08:16:34 -04:00
parent 32e17c6754
commit 7ac24fb0e9
8 changed files with 67 additions and 38 deletions

View File

@ -322,3 +322,7 @@ div#title {
.tri-state { .tri-state {
width: 6em; width: 6em;
} }
#qsvars {
display: none;
}

View File

@ -20,20 +20,30 @@ namespace TwitterPractice.Controllers
ViewBag.HasQsVars = (Request.QueryString.Keys.Count > 0); ViewBag.HasQsVars = (Request.QueryString.Keys.Count > 0);
ViewBag.QueryString = Request.QueryString; ViewBag.QueryString = Request.QueryString;
ViewBag.Message = title; ViewBag.Message = title;
string username = Request.QueryString["username"];
if (null == username)
{
ViewBag.UserTimeline = null;
ViewBag.Username = null;
}
else
{
ViewBag.UserTimeline = _twitterModels.GetTwitterStream(username);
ViewBag.Username = username;
}
return View(); return View();
} }
public ActionResult UserTimelineFragment()
{
string username = Request.QueryString["username"];
if (null == username)
{
return new HttpNotFoundResult("you must provide a username, derp.");
}
else
{
try
{
ViewBag.UserTimeline = _twitterModels.GetTwitterStream(username);
ViewBag.Username = username;
return View();
}
catch (System.SystemException e)
{
return new HttpNotFoundResult("FAIL: " + e.Message);
}
}
}
} }
} }

View File

@ -13,7 +13,7 @@ namespace TwitterPractice.Models
requestTemplate = ConfigurationManager.AppSettings["TwitterRequestTemplate"]; requestTemplate = ConfigurationManager.AppSettings["TwitterRequestTemplate"];
} }
public JArray GetTwitterStream(string username = "meatballhat") public JArray GetTwitterStream(string username)
{ {
string requestUrl = String.Format(requestTemplate, username); string requestUrl = String.Format(requestTemplate, username);
WebClient req = new WebClient(); WebClient req = new WebClient();

View File

@ -0,0 +1,6 @@
$(function () {
$('#user-timeline-form').submit(function () {
$('#user-timeline').load('/Home/UserTimelineFragment?username=' + $('#username-input').attr('value'));
return false;
});
});

View File

@ -75,6 +75,7 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Scripts\Site.js" />
<Content Include="Content\themes\base\images\ui-bg_flat_0_aaaaaa_40x100.png" /> <Content Include="Content\themes\base\images\ui-bg_flat_0_aaaaaa_40x100.png" />
<Content Include="Content\themes\base\images\ui-bg_flat_75_ffffff_40x100.png" /> <Content Include="Content\themes\base\images\ui-bg_flat_75_ffffff_40x100.png" />
<Content Include="Content\themes\base\images\ui-bg_glass_55_fbf9ee_1x400.png" /> <Content Include="Content\themes\base\images\ui-bg_glass_55_fbf9ee_1x400.png" />
@ -150,6 +151,9 @@
<ItemGroup> <ItemGroup>
<Content Include="packages.config" /> <Content Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="Views\Home\UserTimelineFragment.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" /> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@ -1,37 +1,22 @@
@using Newtonsoft.Json.Linq; @using Newtonsoft.Json.Linq;
@{ViewBag.Title = "Home Page";} @{ViewBag.Title = "Home Page";}
<form action="" method="get"> <form id="user-timeline-form" action="" method="get">
<label for="username-input">username:</label> <label for="username-input">username:</label>
<input type="text" id="username-input" name="username" /> <input type="text" id="username-input" name="username" />
<input type="submit" name="submit" value="Submit" /> <input type="submit" name="submit" value="Show User Timeline" />
</form> </form>
<h2>@ViewBag.Message</h2> <h2>@ViewBag.Message</h2>
@if (ViewBag.HasQsVars) @if (ViewBag.HasQsVars)
{ {
<div id="qsvars">
<h3>Request Variables:</h3> <h3>Request Variables:</h3>
<ul>
@foreach (string key in ViewBag.QueryString) @foreach (string key in ViewBag.QueryString)
{ {
<li>@key = @ViewBag.QueryString[key]</li> <p class="qsvar">@key = @ViewBag.QueryString[key]</p>
} }
</ul>
}
@if (null != ViewBag.Username)
{
<div id="user-timeline">
<h4>user timeline for @ViewBag.Username</h4>
<ul id="timeline-entries">
@foreach (JObject entry in ViewBag.UserTimeline)
{
<li class="timeline-entry">
@entry["text"]
</li>
}
</ul>
</div> </div>
} }
<div id="user-timeline"></div>

View File

@ -0,0 +1,19 @@
@using Newtonsoft.Json.Linq;
@{
Layout = null;
}
@if (null != ViewBag.Username)
{
<div id="user-timeline-inner">
<h4>user timeline for @ViewBag.Username</h4>
<ul id="timeline-entries">
@foreach (JObject entry in ViewBag.UserTimeline)
{
<li class="timeline-entry">
@entry["text"]
</li>
}
</ul>
</div>
}

View File

@ -6,6 +6,7 @@
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" /> <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Site.js")" type="text/javascript"></script>
</head> </head>
<body> <body>
<div class="page"> <div class="page">