Skip to content

Commit

Permalink
done with food groups
Browse files Browse the repository at this point in the history
  • Loading branch information
johnculviner committed Apr 22, 2013
1 parent 8fbcf7b commit cb5827c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 36 deletions.
2 changes: 1 addition & 1 deletion demo/SurveyApp.Web/App/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 9 additions & 29 deletions demo/SurveyApp.Web/App/viewmodels/foodgroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ function (foodGroupApi, foodGroup, typeMetadataHelper, app, router) {
});

self.foodGroups(wrappedFoodGroups);
ajaxLoaded();
});
};

Expand All @@ -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');
};
};
});
5 changes: 2 additions & 3 deletions demo/SurveyApp.Web/App/views/foodGroups.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
Edit Food Groups
</h1>
<div class="pull-right">
<button class="btn" data-bind="click: reset">Reset</button>
<button class="btn" data-bind="click: cancel">Cancel</button>
<button class="btn btn-primary" data-bind="command: save">Save</button>
<button class="btn btn-primary" data-bind="click: save">Save</button>
</div>
</div>

Expand Down Expand Up @@ -43,7 +42,7 @@
</thead>
<tbody>

@*a foreach on a nested element*@
@*a foreach on a nested element (foods)*@
@using (var food = foodGroup.ForEachKoComment(x => x.Foods))
{
<tr>
Expand Down
2 changes: 1 addition & 1 deletion demo/SurveyApp.Web/SurveyApp.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
<Content Include="App\main.js" />
<Content Include="App\requirePlugins\async.js" />
<Content Include="App\utility\typeMetadataHelper.js" />
<Content Include="App\viewmodels\foodgroups.js" />
<Content Include="App\viewmodels\foodGroups.js" />
<Content Include="App\viewmodels\foodGroups\foodGroup.js" />
<Content Include="App\viewmodels\surveys\addEditTechProductModal.js" />
<Content Include="App\viewmodels\surveys\relation.js" />
Expand Down
2 changes: 0 additions & 2 deletions demo/SurveyApp.Web/local.config

This file was deleted.

0 comments on commit cb5827c

Please sign in to comment.