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 moved

Legend:

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

    r418 r420  
    22    'dojo/_base/array',
    33    'dojo/_base/declare',
    4     'dojo/_base/Deferred',
    5     'dojo/_base/event',
    64    'dojo/_base/lang',
     5    'dojo/when',
    76    '../store',
    87    '../app/Page',
    9     '../model/widgets/QuestionWidgetFactory',
    10     'dojo/text!./templates/viewSurvey.html'
    11 ],function(array,declare,Deferred,event,lang,store,Page,QuestionWidgetFactory,template){
     8    'dojo/text!./templates/previewSurvey.html'
     9],function(array,declare,lang,when,store,Page,template){
    1210    return declare([Page],{
    1311        templateString: template,
    14         survey: null,
    15         surveyId: "",
    16         options: null,
    17         constructor: function(){
    18             this._dataMap = {};
    19             this.options = this.options || {};
    20         },
    2112        startup: function() {
    2213            if ( this._started ) { return; }
    2314            this.inherited(arguments);
    24 
    25 
    2615            if ( this.surveyId ) {
    27                 Deferred.when(store.get(this.surveyId))
     16                when(store.get(this.surveyId))
    2817                .then(lang.hitch(this,function(survey){
    29                     if ( !survey.published ) {
    30                         this.options.preview = true;
    31                     }
    32                     if ( this.options.preview ) {
    33                         this.buttonsPane.destroyRecursive();
    34                     }
    35                     this.titleNode.innerHTML = survey.title +
    36                             (this.options.preview?' [preview]':'');
    37                     var f = new QuestionWidgetFactory();
    38                     this.survey = survey;
    39                     store.query(null,{keys:this.survey.questions,include_docs:true})
    40                     .forEach(function(question){
    41                         array.forEach(question.content || [],function(item){
    42                             var w = f.createViewWidget(item,{
    43                                 name: question.code+'.'+item.code
    44                             });
    45                             if ( w !== null ) {
    46                                 w.placeAt(this.questionsAnchor,'before');
    47                             }
    48                         },this);
    49                     },this);
     18                    this.titleNode.innerHTML = survey.title;
     19                    this.surveyWidget.set('survey',survey);
    5020                }));
    5121            } else {
    5222                throw new Error("No valid uid or survey passed!");
    5323            }
    54         },
    55         _onSubmit: function(evt) {
    56             if ( this.options.preview ) { return; }
    57             var value = this.questionsForm.get('value');
    58             this.questionsPane.set('content','<pre>'+JSON.stringify(value)+'</pre>');
    59             event.stop(evt);
    60             return false;
    61         },
    62         _onCancel: function(evt) {
    63             if ( this.options.preview ) { return; }
    64             event.stop(evt);
    65             return false;
    6624        }
    6725    });
Note: See TracChangeset for help on using the changeset viewer.