Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
johnculviner committed Apr 25, 2013
1 parent 780448c commit a6d2d23
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions demo/SurveyApp.Web/App/viewmodels/surveys.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
define(['durandal/app', 'api/surveyApi', './surveys/deleteModal', './surveys/shared/locationInfo'],
function (app, surveyApi, deleteModal, locationInfo) {
function (app, surveyApi, deleteModal, locationInfo) {

return function () {
var self = this;
return function () {
var self = this;

self.surveySummaries = null; //loaded from ajax as ko.observableArray()
self.selectedSurvey = ko.observable(null);
self.surveySummaries = null; //loaded from ajax as ko.observableArray()
self.selectedSurvey = ko.observable(null);

//the router's activator calls this function and waits for the .complete jQuery Promise before
//transitioning the view in and eventually calling ko.applyBindings
self.activate = function () {
return surveyApi.getAll()
.then(function (surveys) {
//the router's activator calls this function and waits for the .complete jQuery Promise before
//transitioning the view in and eventually calling ko.applyBindings
self.activate = function () {
return surveyApi.getAll()
.then(function (surveys) {

//use ko.mapping library to convert the array to be observable for the summary view
self.surveySummaries = ko.mapping.fromJS(surveys);
//use ko.mapping library to convert the array to be observable for the summary view
self.surveySummaries = ko.mapping.fromJS(surveys);

if (self.surveySummaries().length > 0)
self.toggleSelected(self.surveySummaries()[0]);
});
};

//show summary information about a survey when selected
self.toggleSelected = function (surveySummary) {
self.selectedSurvey(surveySummary);
return true;
};
if (self.surveySummaries().length > 0)
self.toggleSelected(self.surveySummaries()[0]);
});
};

//open a modal requesting confirmation to delete the indicated modal
self.deleteSurvey = function (surveySummary) {
app.showModal(new deleteModal(surveySummary))
.then(function (deletedSurvey) {
//promise returns the deleted survey if user clicks 'delete' in modal
if (deletedSurvey)
self.surveySummaries.remove(deletedSurvey);
});
};
//show summary information about a survey when selected
self.toggleSelected = function (surveySummary) {
self.selectedSurvey(surveySummary);
return true;
};

//for locationInfo compose
self.locationInfo = locationInfo;
//open a modal requesting confirmation to delete the indicated modal
self.deleteSurvey = function (surveySummary) {
app.showModal(new deleteModal(surveySummary))
.then(function (deletedSurvey) {
//promise returns the deleted survey if user clicks 'delete' in modal
if (deletedSurvey)
self.surveySummaries.remove(deletedSurvey);
});
};
});

//for locationInfo compose
self.locationInfo = locationInfo;
};
});

0 comments on commit a6d2d23

Please sign in to comment.