starting to break out some Ajax crap, wheeeeee

cat-town
Dan Buch 13 years ago
parent 32e17c6754
commit 7ac24fb0e9

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

@ -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;
return View();
}
public ActionResult UserTimelineFragment()
{
string username = Request.QueryString["username"]; string username = Request.QueryString["username"];
if (null == username) if (null == username)
{ {
ViewBag.UserTimeline = null; return new HttpNotFoundResult("you must provide a username, derp.");
ViewBag.Username = null;
} }
else else
{ {
ViewBag.UserTimeline = _twitterModels.GetTwitterStream(username); try
ViewBag.Username = username; {
} ViewBag.UserTimeline = _twitterModels.GetTwitterStream(username);
return View(); ViewBag.Username = username;
return View();
}
catch (System.SystemException e)
{
return new HttpNotFoundResult("FAIL: " + e.Message);
}
}
} }
} }
} }

@ -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();

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

@ -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.

@ -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)
{ {
<h3>Request Variables:</h3> <div id="qsvars">
<ul> <h3>Request Variables:</h3>
@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> </div>
} }
@if (null != ViewBag.Username) <div id="user-timeline"></div>
{
<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>
}

@ -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>
}

@ -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">

Loading…
Cancel
Save