forked from johnculviner/FluentKnockoutHelpers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
780448c
commit a6d2d23
Showing
1 changed file
with
34 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
}); |