From cb5827cbb425f3764c3aa1ad9cd9c5184d7d2bec Mon Sep 17 00:00:00 2001 From: John Culviner Date: Mon, 22 Apr 2013 00:37:56 -0500 Subject: [PATCH] done with food groups --- demo/SurveyApp.Web/App/main.js | 2 +- .../App/viewmodels/foodgroups.js | 38 +++++-------------- .../SurveyApp.Web/App/views/foodGroups.cshtml | 5 +-- demo/SurveyApp.Web/SurveyApp.Web.csproj | 2 +- demo/SurveyApp.Web/local.config | 2 - 5 files changed, 13 insertions(+), 36 deletions(-) delete mode 100644 demo/SurveyApp.Web/local.config diff --git a/demo/SurveyApp.Web/App/main.js b/demo/SurveyApp.Web/App/main.js index 6be22d8..440a045 100644 --- a/demo/SurveyApp.Web/App/main.js +++ b/demo/SurveyApp.Web/App/main.js @@ -47,7 +47,7 @@ define(['durandal/app', 'durandal/viewLocator', 'durandal/system', 'durandal/vie //ex: visiting '#/surveys' results in 'viewmodels/surveys' router.mapNav('surveys'); - router.mapNav('foodgroups', 'viewmodels/foodgroups', 'Food Groups'); + router.mapNav('foodGroups', 'viewmodels/foodGroups', 'Food Groups'); //creates a route for showing a particular survey //':id' extracts the value and it is passed as an argument into the 'activate' function of the viewmodel diff --git a/demo/SurveyApp.Web/App/viewmodels/foodgroups.js b/demo/SurveyApp.Web/App/viewmodels/foodgroups.js index f335030..55db118 100644 --- a/demo/SurveyApp.Web/App/viewmodels/foodgroups.js +++ b/demo/SurveyApp.Web/App/viewmodels/foodgroups.js @@ -20,7 +20,6 @@ function (foodGroupApi, foodGroup, typeMetadataHelper, app, router) { }); self.foodGroups(wrappedFoodGroups); - ajaxLoaded(); }); }; @@ -46,34 +45,15 @@ function (foodGroupApi, foodGroup, typeMetadataHelper, app, router) { }); }; + self.save = function() { + foodGroupApi.post(ko.mapping.toJS(self.foodGroups)) + .then(function() { + router.navigateTo('#/surveys'); + }); + }; - function ajaxLoaded() { - self.dirtyFlag = new ko.DirtyFlag(self.foodGroups, false, ko.mapping.toJSON); //kolite plugin - - ko.validation.init({ grouping: { deep: true } }); - self.validator = ko.validatedObservable(self.foodGroups()); //knockout validation plugin - - self.save = ko.asyncCommand({ //kolite plugin - execute: function () { - foodGroupApi.post(ko.mapping.toJS(self.foodGroups)) - .then(function () { - self.dirtyFlag().reset(); - router.navigateTo('#/surveys'); - }); - }, - canExecute: function (isExecuting) { - return !isExecuting && self.dirtyFlag().isDirty() && self.validator().isValid(); - } - }); - - var resetCopy = ko.mapping.toJS(self.foodGroups); - self.reset = function () { - ko.mapping.fromJS(resetCopy, {}, self.foodGroups); - }; - - self.cancel = function () { - router.navigateTo('#/surveys'); - }; - } + self.cancel = function () { + router.navigateTo('#/surveys'); + }; }; }); \ No newline at end of file diff --git a/demo/SurveyApp.Web/App/views/foodGroups.cshtml b/demo/SurveyApp.Web/App/views/foodGroups.cshtml index a59604a..c2c6106 100644 --- a/demo/SurveyApp.Web/App/views/foodGroups.cshtml +++ b/demo/SurveyApp.Web/App/views/foodGroups.cshtml @@ -10,9 +10,8 @@ Edit Food Groups
- - +
@@ -43,7 +42,7 @@ - @*a foreach on a nested element*@ + @*a foreach on a nested element (foods)*@ @using (var food = foodGroup.ForEachKoComment(x => x.Foods)) { diff --git a/demo/SurveyApp.Web/SurveyApp.Web.csproj b/demo/SurveyApp.Web/SurveyApp.Web.csproj index 257cb13..9a85704 100644 --- a/demo/SurveyApp.Web/SurveyApp.Web.csproj +++ b/demo/SurveyApp.Web/SurveyApp.Web.csproj @@ -183,7 +183,7 @@ - + diff --git a/demo/SurveyApp.Web/local.config b/demo/SurveyApp.Web/local.config deleted file mode 100644 index afbd7e4..0000000 --- a/demo/SurveyApp.Web/local.config +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file