Permalink
Browse files

demo 2 completed

  • Loading branch information...
1 parent 19e5639 commit 1a3a3370eb2899f5085bc46b874c4bacef77ee58 @subsonic subsonic committed Jul 4, 2012
Binary file not shown.
Binary file not shown.
@@ -43,9 +43,6 @@
<Reference Include="Cassette.Views">
<HintPath>..\packages\Cassette.Views.1.2.1\lib\net40\Cassette.Views.dll</HintPath>
</Reference>
- <Reference Include="Cassette.Web">
- <HintPath>..\packages\Cassette.Web.1.2.1\lib\net40\Cassette.Web.dll</HintPath>
- </Reference>
<Reference Include="EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\EntityFramework.4.1.10331.0\lib\EntityFramework.dll</HintPath>
@@ -74,10 +71,6 @@
<Reference Include="Microsoft.Scripting.Metadata">
<HintPath>..\packages\IronRuby.1.1.3\Lib\Microsoft.Scripting.Metadata.dll</HintPath>
</Reference>
- <Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
- <Private>True</Private>
- <HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
- </Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.4.0.8\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
@@ -113,9 +106,6 @@
<Reference Include="System.Configuration" />
<Reference Include="System.Web.Services" />
<Reference Include="System.EnterpriseServices" />
- <Reference Include="WebActivator">
- <HintPath>..\packages\WebActivator.1.5.1\lib\net40\WebActivator.dll</HintPath>
- </Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CassetteConfiguration.cs" />
@@ -66,3 +66,7 @@ button.link
border:0;
}
+.inlineForm
+{
+ display : inline
+}
@@ -20,50 +20,38 @@
self.Notes.remove(note);
});
};
- self.canRefund = ko.computed(function () {
+ self.shippable = ko.computed(function () {
+ return self.Status() === "paid";
+ });
+ self.refundable = ko.computed(function () {
return self.Status() === "paid";
});
self.refundOrder = function () {
return MusicStore.refundOrder(order, function (result) {
- //load the status
- //transactions
- //notes
self.Status(result.order.Status);
self.Transactions(result.order.Transactions);
self.Notes(result.order.Notes);
});
};
-
+ self.shipOrder = function () {
+ return MusicStore.shipOrder(order, function (result) {
+ self.Status(result.order.Status);
+ self.Notes(result.order.Notes);
+ });
+ };
self.addNote = function () {
var note = $("#newNote").val();
var newNote = { OrderId: self.OrderId(), Note: note };
MusicStore.addNote(newNote, function (result) {
- console.log(result);
if (result.success)
self.Notes.push(result.newNote);
});
};
- self.parseDate = function (jsonDate) {
- var re = /-?\d+/;
- var m = re.exec(jsonDate);
- var d = new Date(parseInt(m[0]));
- var curr_date = d.getDate();
- var curr_month = d.getMonth() + 1; //Months are zero based
- var curr_year = d.getFullYear();
- return curr_month + "-" + curr_date + "-" + curr_year + " " + d.getHours() + ":" + d.getMinutes();
- };
self.saveOrder = function () {
-
var data = $("#orderForm").serialize();
- $.post("/orders/edit/" + order.OrderId, data, function (result) {
- if (result.success) {
- notifier.success(result.message);
- } else {
- notifier.alert(result.message);
- }
- });
+ MusicStore.saveOrder(data);
};
};
@@ -78,16 +66,25 @@ MusicStore = function () {
}
}
};
-
- var _canRefund = function (order) {
- return order.Status === "paid";
+ var _saveOrder = function (order, callback) {
+ $.post("/orders/edit/", order, function (result) {
+ _notify(result);
+ callback(result);
+ });
};
+
var _refundOrder = function (order, callback) {
$.post("/orders/refund/", { id: order.OrderId }, function (result) {
_notify(result);
callback(result);
});
};
+ var _shipOrder = function (order, callback) {
+ $.post("/orders/ship/", { id: order.OrderId }, function (result) {
+ _notify(result);
+ callback(result);
+ });
+ }
var _deleteNote = function (note, callback) {
$.post("/ordernotes/delete/", { id: note.Id }, function (result) {
_notify(result);
@@ -104,18 +101,60 @@ MusicStore = function () {
return {
deleteNote: _deleteNote,
addNote: _addNote,
- canRefund: _canRefund,
- refundOrder : _refundOrder
+ refundOrder: _refundOrder,
+ shipOrder: _shipOrder,
+ saveOrder : _saveOrder
}
} ();
-var loadOrder = function () {
- orderManager = new OrderManager(window.order);
- ko.applyBindings(orderManager);
-
+var loadCustomBindings = function () {
+
+ this.parseDate = function (jsonDate) {
+ var re = /-?\d+/;
+ var m = re.exec(jsonDate);
+ var d = new Date(parseInt(m[0]));
+ var curr_date = d.getDate();
+ var curr_month = d.getMonth() + 1; //Months are zero based
+ var curr_year = d.getFullYear();
+ return curr_month + "-" + curr_date + "-" + curr_year + " " + d.getHours() + ":" + d.getMinutes();
+ };
+
+ ko.bindingHandlers.dateText = {
+
+ init: function (element, value) {
+ var val = value();
+ $(element).text(this.parseDate(val));
+ }
+ }
+
};
$().ready(function () {
- loadOrder();
+ orderManager = new OrderManager(window.order);
+ loadCustomBindings();
+ ko.applyBindings(orderManager);
+
+ //wire events
+ $("#addNote").click(function (evt) {
+ orderManager.addNote();
+ });
+
+ $("#notesList").delegate(".removeNote", "click", function () {
+ orderManager.deleteNote(ko.dataFor(this));
+ });
+
+ $("#orderForm").submit(function (evt) {
+ evt.preventDefault();
+ orderManager.saveOrder();
+ });
+
+ $(".refundButton").click(orderManager.refundOrder);
+ $("#shipButton").click(orderManager.shipOrder);
+
+
+ orderManager.Notes.subscribe(function () {
+ $("#notesList").effect("highlight");
+ });
+
});
Binary file not shown.
Binary file not shown.
@@ -45,27 +45,22 @@ public ViewResult Index()
{
return Json(new { success = false, message = "Can't refund this order, there was an error", order = order });
}
-
- //TempData["message"] = "Order Refunded";
- //return RedirectToAction("edit", new {id = id});
- }
- public ActionResult Void(int id)
- {
- var order = db.Orders.Find(id);
- order.Status = "voided";
- order.Notes = new List<OrderNote>();
- order.Notes.Add(new OrderNote { Note = "Order Voidedby " + User.Identity.Name, CreatedOn = DateTime.Now });
- TempData["message"] = "Order Voided by " + User.Identity.Name;
- return RedirectToAction("edit", new { id = id });
}
+
public ActionResult Ship(int id)
{
var order = db.Orders.Find(id);
order.Status = "shipped";
- order.Notes = new List<OrderNote>();
order.Notes.Add(new OrderNote { Note = "Order Shipped by " + User.Identity.Name, CreatedOn = DateTime.Now });
- TempData["message"] = "Order Shipped by " + User.Identity.Name;
- return RedirectToAction("edit", new { id = id });
+ //have to flush the changes here
+ db.SaveChanges();
+ order = db.Orders
+ .Include("Transactions")
+ .Include("OrderDetails")
+ .Include("Notes")
+ .Where(x => x.OrderId == id).FirstOrDefault();
+ return Json(new { success = true, message = "Order Shipped! Wahoo!", order = order });
+
}
//
// GET: /Default1/Details/5
@@ -168,7 +163,7 @@ public ActionResult Edit(int id, FormCollection form)
if (ModelState.IsValid)
{
db.Entry(order).State = EntityState.Modified;
- return Json(new { success = true, message = "Order Saved!" });
+ return Json(new { success = true, message = "Order Saved!", order = order });
}
else
{
@@ -29,7 +29,6 @@ C:\projects\mvcmusic\MvcMusicStore\obj\Debug\MvcMusicStore.csprojResolveAssembly
C:\projects\mvcmusic\MvcMusicStore\bin\AjaxMin.dll
C:\projects\mvcmusic\MvcMusicStore\bin\Cassette.dll
C:\projects\mvcmusic\MvcMusicStore\bin\Cassette.Views.dll
-C:\projects\mvcmusic\MvcMusicStore\bin\Cassette.Web.dll
C:\projects\mvcmusic\MvcMusicStore\bin\IronRuby.dll
C:\projects\mvcmusic\MvcMusicStore\bin\IronRuby.Libraries.dll
C:\projects\mvcmusic\MvcMusicStore\bin\IronRuby.Libraries.Yaml.dll
@@ -38,12 +37,10 @@ C:\projects\mvcmusic\MvcMusicStore\bin\Microsoft.Dynamic.dll
C:\projects\mvcmusic\MvcMusicStore\bin\Microsoft.Practices.ServiceLocation.dll
C:\projects\mvcmusic\MvcMusicStore\bin\Microsoft.Scripting.dll
C:\projects\mvcmusic\MvcMusicStore\bin\Microsoft.Scripting.Metadata.dll
-C:\projects\mvcmusic\MvcMusicStore\bin\Microsoft.Web.Infrastructure.dll
C:\projects\mvcmusic\MvcMusicStore\bin\Newtonsoft.Json.dll
C:\projects\mvcmusic\MvcMusicStore\bin\Pandora.dll
C:\projects\mvcmusic\MvcMusicStore\bin\SassAndCoffee.Core.dll
C:\projects\mvcmusic\MvcMusicStore\bin\SassAndCoffee.Ruby.dll
-C:\projects\mvcmusic\MvcMusicStore\bin\WebActivator.dll
C:\projects\mvcmusic\MvcMusicStore\bin\AjaxMin.pdb
C:\projects\mvcmusic\MvcMusicStore\bin\Microsoft.Practices.ServiceLocation.pdb
C:\projects\mvcmusic\MvcMusicStore\bin\Microsoft.Practices.ServiceLocation.xml
Binary file not shown.
Binary file not shown.
@@ -1,23 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="AjaxMin" version="4.46.4422.26284" targetFramework="net40" />
- <package id="Cassette" version="1.2.1" targetFramework="net40" />
- <package id="Cassette.Views" version="1.2.1" targetFramework="net40" />
- <package id="Cassette.Web" version="1.2.1" targetFramework="net40" />
- <package id="CommonServiceLocator" version="1.0" targetFramework="net40" />
+ <package id="AjaxMin" version="4.46.4422.26284" />
+ <package id="Cassette" version="1.2.1" />
+ <package id="Cassette.Views" version="1.2.1" />
+ <package id="CommonServiceLocator" version="1.0" />
<package id="EntityFramework" version="4.1.10331.0" />
- <package id="IronRuby" version="1.1.3" targetFramework="net40" />
+ <package id="IronRuby" version="1.1.3" />
<package id="jQuery" version="1.5.1" />
<package id="jQuery.UI.Combined" version="1.8.11" />
<package id="jQuery.Validation" version="1.8.0" />
<package id="jQuery.vsdoc" version="1.5.1" />
- <package id="Jurassic" version="2.1.1" targetFramework="net40" />
+ <package id="Jurassic" version="2.1.1" />
<package id="knockoutjs" version="2.1.0" targetFramework="net40" />
- <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
<package id="Modernizr" version="1.7" />
<package id="Mvc3CodeTemplatesCSharp" version="3.0.11214.0" targetFramework="net40" />
- <package id="Newtonsoft.Json" version="4.0.8" targetFramework="net40" />
- <package id="SassAndCoffee.Core" version="2.0.2.0" targetFramework="net40" />
- <package id="SassAndCoffee.Ruby" version="2.0.2.0" targetFramework="net40" />
- <package id="WebActivator" version="1.5.1" targetFramework="net40" />
+ <package id="Newtonsoft.Json" version="4.0.8" />
+ <package id="SassAndCoffee.Core" version="2.0.2.0" />
+ <package id="SassAndCoffee.Ruby" version="2.0.2.0" />
</packages>
Oops, something went wrong.

0 comments on commit 1a3a337

Please sign in to comment.