Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: dodyg/hobi-hobi
base: c88aaf0d8f
...
head fork: dodyg/hobi-hobi
compare: a5822d5b36
  • 2 commits
  • 9 files changed
  • 0 commit comments
  • 1 contributor
Commits on Oct 08, 2012
Dody Gunawinata Start integrating angular.js a76a6ca
Commits on Oct 10, 2012
Dody Gunawinata Make typscript to execute only at debug
Add the first implementation of angular.js to the blog system.
a5822d5
BIN  HobiHobi.Web.v11.suo
View
Binary file not shown
23 HobiHobi.Web/Areas/Manage/Views/Blog/Index.cshtml
View
@@ -1,6 +1,6 @@
@{
ViewBag.Title = ViewBag.BlogTitle;
- Layout = "~/Areas/Manage/Views/Shared/_Layout.cshtml";
+ Layout = "~/Areas/Manage/Views/Shared/_LayoutApp.cshtml";
}
<h2>@ViewBag.BlogTitle</h2>
@@ -19,14 +19,16 @@
<div id="message"></div>
-<form id="new_post">
- <span id="post_content_count">280</span><br />
- <textarea class="input-xxlarge" id="post_content" name="content" onkeyup="countChar(this)"></textarea>
- <br />
- <input type="url" id="post_link" class="input-xxlarge" name="link" placeholder="Link"/>
- <br />
- <button type="submit" class="btn btn-primary">Post</button>
-</form>
+<div data-ng-controller="PostController">
+ <form novalidate>
+ <span id="post_content_count">280</span><br />
+ <textarea class="input-xxlarge" data-ng-model="post.content" onkeyup="countChar(this)" required></textarea>
+ <br />
+ <input type="url" class="input-xxlarge" data-ng-model="post.link" placeholder="Link"/>
+ <br />
+ <button class="btn btn-primary" data-ng-click="newPost(post)">Post</button>
+ </form>
+</div>
<table class="table" id="posts"></table>
@@ -52,8 +54,9 @@
</div>
</div>
+
@section JsInline{
-
+ <script src="/Scripts/angular.min.js"></script>
<script src="/Scripts/App/blog.js"></script>
<script id="tmpl-posts" type="text/template">
3  HobiHobi.Web/Areas/Manage/Views/Shared/_Layout.cshtml
View
@@ -41,8 +41,5 @@
display: block;
}
</style>
-
- </style>
-
</body>
</html>
45 HobiHobi.Web/Areas/Manage/Views/Shared/_LayoutApp.cshtml
View
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<html ng-app>
+<head>
+ <title>@ViewBag.Title</title>
+ <link href="/site/css/@HobiHobi.Web.MvcApplication.CommonCssTag" rel="stylesheet" type="text/css" />
+ <link href="/Content/Manage.css" rel="stylesheet" />
+ <script src="/site/js/@HobiHobi.Web.MvcApplication.CommonJsTag" type="text/javascript"></script>
+ @RenderSection("HeadInline", false)
+
+</head>
+
+<body>
+ <div class="container">
+ <div class="row">
+ <div class="span2" style="padding-top:60px;">
+ @RenderSection("SideNavigation", false)
+ </div>
+ <div class="span10">
+ @RenderBody()
+ </div>
+ </div>
+ </div>
+ @RenderSection("CssInline", false)
+ @RenderSection("JsInline", false)
+
+ <div id="loading_div" style="display:none;">
+ <img src="/images/ajax_spinner.gif" alt="wait" />
+ </div>
+
+ <style type="text/css">
+ #loading_div {
+ height: 400px;
+ position: relative;
+ }
+ #loading_div img{
+ position: absolute;
+ left: 50%;
+ top: 50%;
+ margin-left: -32px; /* -1 * image width / 2 */
+ margin-top: -32px; /* -1 * image height / 2 */
+ display: block;
+ }
+ </style>
+</body>
+</html>
3  HobiHobi.Web/Controllers/SiteController.cs
View
@@ -54,8 +54,7 @@ public ActionResult Js()
"/scripts/jquery.validate.min",
"/scripts/jquery.validate.unobtrusive.min",
"/scripts/jquery.slug",
- "/scripts/jquery.xml2json",
- "/scripts/angular.min"
+ "/scripts/jquery.xml2json"
};
var js = HttpContext.Cache["JS"] as string;
5 HobiHobi.Web/HobiHobi.Web.csproj
View
@@ -365,6 +365,9 @@
<ItemGroup>
<Content Include="Views\List\Blogs.cshtml" />
</ItemGroup>
+ <ItemGroup>
+ <Content Include="Areas\Manage\Views\Shared\_LayoutApp.cshtml" />
+ </ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
@@ -381,7 +384,7 @@
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
- <Target Name="TypeScriptCompile" BeforeTargets="Build">
+ <Target Name="TypeScriptCompile" BeforeTargets="Build" Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<Message Text="Compiling TypeScript files" />
<Exec Command="&quot;$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc&quot; -target ES5 @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
</Target>
64 HobiHobi.Web/Scripts/App/blog.js
View
@@ -1,3 +1,34 @@
+function PostController($scope) {
+ $scope.master = {
+ };
+ $scope.newPost = function (post) {
+ var activeTab = $('#feed_tabs li.active a');
+ var id = activeTab.data('id');
+ var doc = {
+ feedId: id,
+ content: post.content,
+ link: null
+ };
+ if(post.link !== undefined) {
+ doc.link = post.link;
+ }
+ $scope.post = angular.copy($scope.master);
+ var json = JSON.stringify(doc);
+ $.ajax('/manage/blog/createpost', {
+ data: json,
+ type: 'POST',
+ contentType: 'application/json; charset=utf-8',
+ dataType: 'json'
+ }).done(function (payload) {
+ var template = $('#tmpl-single-post').html();
+ var compiled = _.template(template, {
+ post: payload.Data
+ });
+ $('#posts').prepend(compiled);
+ inform('Your post is successfully added');
+ });
+ };
+}
function countChar(val) {
var len = val.value.length;
if(len >= 280) {
@@ -72,39 +103,6 @@ $('#save_new_feed').click(function () {
}
});
});
-$('#new_post').submit(function () {
- var content = $.trim($('#post_content').val());
- if(content.length == 0) {
- return false;
- }
- var activeTab = $('#feed_tabs li.active a');
- var id = activeTab.data('id');
- var doc = {
- feedId: id,
- content: content,
- link: null
- };
- var link = $('#post_link').val();
- if(link.length > 0) {
- doc.link = link;
- }
- var json = JSON.stringify(doc);
- $.ajax('/manage/blog/createpost', {
- data: json,
- type: 'POST',
- contentType: 'application/json; charset=utf-8',
- dataType: 'json'
- }).done(function (payload) {
- var template = $('#tmpl-single-post').html();
- var compiled = _.template(template, {
- post: payload.Data
- });
- $('#posts').prepend(compiled);
- postFormReset();
- inform('Your post is successfully added');
- });
- return false;
-});
function postFormReset() {
$('#post_content').val('');
$('#post_link').val('');
78 HobiHobi.Web/Scripts/App/blog.ts
View
@@ -1,5 +1,42 @@
declare var $;
declare var _;
+declare var angular;
+
+function PostController($scope) {
+ $scope.master = {};
+ $scope.newPost = function (post) {
+ var activeTab = $('#feed_tabs li.active a');
+ var id = activeTab.data('id');
+
+ var doc = {
+ feedId : id,
+ content : post.content,
+ link : null
+ };
+
+ if (post.link !== undefined)
+ doc.link = post.link;
+
+ $scope.post = angular.copy($scope.master);
+
+ var json = JSON.stringify(doc);
+
+ $.ajax('/manage/blog/createpost', {
+ data: json,
+ type: 'POST',
+ contentType: 'application/json; charset=utf-8',
+ dataType: 'json'
+ }).done(function (payload) {
+
+ //insert the data into the list
+ var template = $('#tmpl-single-post').html();
+ var compiled = _.template(template, { post: payload.Data });
+ $('#posts').prepend(compiled);
+
+ inform('Your post is successfully added');
+ });
+ }//end of $scope.newPost
+}
function countChar(val) {
var len = val.value.length;
@@ -42,14 +79,12 @@ function load(feedId) {
}
-
$('a[data-toggle="tab"]').on('shown', function (e) {
var id = $(e.target).data('id');
$('#feed_tab_link').attr('href', '/f/' + $(e.target).data('url'));//switch the link to the rendering of the blog
load(id);
})
-
$('#feed_new').click(function () {
$('#feed_create').modal();
});
@@ -89,50 +124,13 @@ $('#save_new_feed').click(function () {
});
});
-$('#new_post').submit(function () {
- var content = $.trim($('#post_content').val());
- if (content.length == 0)
- return false;
-
- var activeTab = $('#feed_tabs li.active a');
- var id = activeTab.data('id');
-
- var doc = {
- feedId : id,
- content : content,
- link : null
- };
-
- var link = $('#post_link').val();
-
- if (link.length > 0)
- doc.link = link;
-
- var json = JSON.stringify(doc);
-
- $.ajax('/manage/blog/createpost', {
- data: json,
- type: 'POST',
- contentType: 'application/json; charset=utf-8',
- dataType: 'json'
- }).done(function (payload) {
- //insert the data into the list
- var template = $('#tmpl-single-post').html();
- var compiled = _.template(template, { post: payload.Data });
- $('#posts').prepend(compiled);
- postFormReset();
- inform('Your post is successfully added');
- });
-
- return false;
-});
function postFormReset() {
$('#post_content').val('');//reset the content
$('#post_link').val('');
}
-function inform(msg : String, target : any = undefined) {
+function inform(msg : string, target : any = undefined) {
if (target === undefined)
$('#message').removeClass().addClass('alert alert-success').html(msg).show().fadeOut(3000);
else
808 HobiHobi.Web/Scripts/angular.min.js
View
397 additions, 411 deletions not shown

No commit comments for this range

Something went wrong with that request. Please try again.