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 copied

Legend:

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

    r418 r420  
    11define([
    2     'dojo/_base/array',
    32    'dojo/_base/declare',
    4     'dojo/_base/Deferred',
    53    'dojo/_base/event',
    64    'dojo/_base/lang',
     5    'dojo/when',
     6    '../app/Content',
    77    '../app/Router',
     8    '../lib/func',
    89    '../store',
    910    '../app/Page',
    10     '../model/widgets/QuestionListView',
    11     '../model/widgets/TabbedQuestionBrowser',
    12     'dojo/text!./templates/survey.html'
    13 ],function(array,declare,Deferred,event,lang,Router,store,Page,
    14          QuestionListView,TabbedQuestionBrowser,template){
     11    '../model/classes/SurveyRun',
     12    'dojo/text!./templates/surveyRun.html'
     13],function(declare,event,lang,when,Content,Router,func,store,Page,SurveyRun,template){
    1514    return declare([Page],{
    1615        templateString: template,
    17         survey: null,
    18         questionList: null,
    19         _dataMap: null,
    20         constructor: function(){
    21             this._dataMap = {};
    22         },
     16        surveyRun: null,
    2317        startup: function() {
    2418            if ( this._started ) { return; }
    2519            this.inherited(arguments);
    26             if ( this.surveyId ) {
    27                 this._setupQuestionBrowser();
    28                 this._setupListView();
    29                 this._loadSurvey();
     20            this.propertiesForm.on("blur",lang.hitch(this,'_onPropChange'));
     21            if ( this.surveyRunId ) {
     22                this._loadSurveyRun();
    3023            } else {
    3124                throw "No valid uid or survey passed!";
    3225            }
    3326        },
    34         _setupQuestionBrowser: function() {
    35             this.questionBrowser = new TabbedQuestionBrowser({
    36                 region: 'center',
    37                 'class': 'blue',
    38                 include: 'published',
    39                 selectedActions: {
    40                     "Include": {
    41                         callback: lang.hitch(this,this._includeQuestion),
    42                         icon: "Accept",
    43                         description: "Include in survey"
    44                     }
    45                 },
    46                 itemActions: {
    47                     "Info": {
    48                         callback: function(item){ item.description && alert(item.description); },
    49                         icon: "Inspect",
    50                         description: "Show item description"
    51                     }
    52                 }
    53             },this.questionBrowser);
    54             this.questionBrowser.startup();
     27        _loadSurveyRun: function() {
     28            when(store.get(this.surveyRunId))
     29            .then(lang.hitch(this,function(surveyRun){
     30                this.surveyRun = surveyRun;
     31                this.refresh();
     32            }));
    5533        },
    56         _setupListView: function() {
    57             this.questionList = new QuestionListView({
    58                 region: 'center'
    59             },this.surveyListViewNode);
    60             this.questionList.startup();
     34        refresh: function() {
     35            this.titleNode.innerHTML = SurveyRun.DisplayTitle.get(this.surveyRun);
     36            this.surveyNode.set('value',SurveyRun.Survey.get(this.surveyRun));
     37            this.propertiesForm.set('value',this.surveyRun);
     38            this._onPropChange();
    6139        },
    62         _loadSurvey: function() {
    63             if ( this.surveyId === "new" ) {
    64                 this.survey = {
    65                     type: 'Survey'
    66                 };
    67                 this.refresh();
     40        _onPropChange: function(e) {
     41            var surveyRun = this.propertiesForm.get('value');
     42            if ( surveyRun.mode === "open" ) {
     43                var url = 'response.html#!/'+store.getIdentity(this.surveyRun);
     44                this.runURLNode.innerHTML = '<a target="_black" href="'+url+'">'+url+'</a>';
    6845            } else {
    69                 Deferred.when(store.get(this.surveyId))
    70                 .then(lang.hitch(this,function(survey){
    71                     this.survey = survey;
    72                     store.query(null,{keys:this.survey.questions || [], include_docs: true})
    73                     .forEach(lang.hitch(this.questionList,'appendItem'));
    74                     this.refresh();
    75                 }));
     46                this.runURLNode.innerHTML = "No general URL. Add individual respondents below.";
    7647            }
    7748        },
    78         _includeQuestion: function(question) {
    79             this.questionList.insertItem(question);
    80         },
    81         refresh: function() {
    82             this.titleNode.innerHTML = this.survey.title || "(set title in properties)";
    83             this.propertiesDialog.set('value',this.survey);
    84         },
    85         _onShowProperties: function(evt) {
    86             this.propertiesDialog.show();
    87         },
    88         _onPropertiesOk: function(evt) {
    89             this.propertiesDialog.hide();
    90             lang.mixin(this.survey, this.propertiesDialog.get('value'));
    91             this.refresh();
    92             event.stop(evt);
    93             return false;
    94         },
    95         _onPropertiesCancel: function(evt) {
    96             this.propertiesDialog.hide();
    97             this.propertiesDialog.reset('value',this.survey);
    98             event.stop(evt);
    99             return false;
    100         },
    10149        _onSave: function(evt) {
    102             this.survey.questions = array.map(this.questionList.getItems(),function(item){
    103                 return store.getIdentity(item);
    104             });
    105             store.put(this.survey)
     50            lang.mixin(this.surveyRun,this.propertiesForm.get('value'));
     51            var not = function(p){ return !p; };
     52            func.modPropIf(this.surveyRun,"startDate",not.compose(lang.isString),store.formatDate);
     53            func.modPropIf(this.surveyRun,"endDate",not.compose(lang.isString),store.formatDate);
     54            store.put(this.surveyRun)
    10655            .then(function() {
    10756                Router.go('/surveys');
     57            },function(err){
     58                Content.notify(err);
    10859            });
    10960            event.stop(evt);
     
    11263        _onDiscard: function(evt) {
    11364            Router.go('/surveys');
    114         },
    115         _onShowPreview: function() {
    116             Router.go('/viewSurvey/'+store.getIdentity(this.survey),{
    117                 preview: true
    118             });
    11965        }
    12066    });
Note: See TracChangeset for help on using the changeset viewer.