Ignore:
Timestamp:
12/16/12 20:07:35 (12 years ago)
Author:
hendrikvanantwerpen
Message:

We can store answers for surveys now!

Introduces SurveyRun?, which can be edited. Workflow not quite clear yet. A
running survey can be accessed to leave a response. When the response
has an ID, it is loaded (used for closed surveys and continuations). A
researcher cannot create responses yet. He should also be able to add
comments to responses (that he creates).

Introduced caching of store requests.

Factored out path matching and formatting.

Put object creation in separate classes, to localize model/storage
dependency. Not consistent at the moment.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/rest-dojo-ui/client/qed/pages/survey.js

    r418 r420  
    22    'dojo/_base/array',
    33    'dojo/_base/declare',
    4     'dojo/_base/Deferred',
    54    'dojo/_base/event',
    65    'dojo/_base/lang',
     6    'dojo/when',
    77    '../app/Router',
    88    '../store',
    99    '../app/Page',
     10    '../model/classes/Survey',
    1011    '../model/widgets/QuestionListView',
    1112    '../model/widgets/TabbedQuestionBrowser',
    1213    'dojo/text!./templates/survey.html'
    13 ],function(array,declare,Deferred,event,lang,Router,store,Page,
     14],function(array,declare,event,lang,when,Router,store,Page,Survey,
    1415         QuestionListView,TabbedQuestionBrowser,template){
    1516    return declare([Page],{
     
    1718        survey: null,
    1819        questionList: null,
    19         _dataMap: null,
    20         constructor: function(){
    21             this._dataMap = {};
    22         },
    2320        startup: function() {
    2421            if ( this._started ) { return; }
     
    6259        _loadSurvey: function() {
    6360            if ( this.surveyId === "new" ) {
    64                 this.survey = {
    65                     type: 'Survey'
    66                 };
     61                this.survey = Survey.create();
    6762                this.refresh();
    6863            } else {
    69                 Deferred.when(store.get(this.surveyId))
     64                when(store.get(this.surveyId))
    7065                .then(lang.hitch(this,function(survey){
    7166                    this.survey = survey;
    72                     store.query(null,{keys:this.survey.questions || [], include_docs: true})
    73                     .forEach(lang.hitch(this.questionList,'appendItem'));
     67                    array.forEach(Survey.Questions.get(this.survey),
     68                        lang.hitch(this.questionList,'appendItem'));
    7469                    this.refresh();
    7570                }));
     
    8075        },
    8176        refresh: function() {
    82             this.titleNode.innerHTML = this.survey.title || "(set title in properties)";
     77            this.titleNode.innerHTML = Survey.DisplayTitle.get(this.survey) || "(set title in properties)";
    8378            this.propertiesDialog.set('value',this.survey);
    8479        },
     
    10095        },
    10196        _onSave: function(evt) {
    102             this.survey.questions = array.map(this.questionList.getItems(),function(item){
    103                 return store.getIdentity(item);
    104             });
     97            this.survey.questions = this.questionList.getItems();
    10598            store.put(this.survey)
    10699            .then(function() {
     
    114107        },
    115108        _onShowPreview: function() {
    116             Router.go('/viewSurvey/'+store.getIdentity(this.survey),{
     109            Router.go('/previewSurvey/'+store.getIdentity(this.survey),{
    117110                preview: true
    118111            });
Note: See TracChangeset for help on using the changeset viewer.