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.

Location:
Dev/branches/rest-dojo-ui/client/qed/pages
Files:
3 added
5 edited
1 copied
2 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    });
  • Dev/branches/rest-dojo-ui/client/qed/pages/question.js

    r418 r420  
    11define([
    22    'dojo/_base/declare',
    3     'dojo/_base/Deferred',
    43    'dojo/_base/event',
    54    'dojo/_base/lang',
     5    'dojo/when',
    66    '../store',
    77    '../app/Content',
    88    '../app/Router',
    99    '../app/Page',
     10    '../model/classes/Question',
    1011    '../model/widgets/QuestionEditorPreview',
    1112    '../model/widgets/QuestionEditorToolkit',
    1213    'dojo/text!./templates/question.html'
    13 ],function(declare, Deferred, event, lang, store, Content, Router, Page, QuestionEditorPreview, QuestionEditorToolkit, template){
     14],function(declare, event, lang, when, store, Content, Router, Page, Question, QuestionEditorPreview, QuestionEditorToolkit, template){
    1415    return declare([Page], {
    1516        templateString: template,
     
    2627            this._setupEditor();
    2728            if (this.questionId === "new") {
    28                 this.question = { type: 'Question' };
     29                this.question = Question.create();
    2930                this._refresh();
    3031            } else {
    31                 Deferred.when(store.get(this.questionId))
     32                when(store.get(this.questionId))
    3233                .then(lang.hitch(this, function(obj) {
    3334                    this.question = obj;
     
    4041        },
    4142        _refresh: function () {
    42             this.titleNode.innerHTML = this.question.title || "";
     43            this.titleNode.innerHTML = Question.DisplayTitle.get(this.question);
    4344            this._toolkit.set('value',this.question);
    44             this._preview.appendItems(this.question.content || []);
     45            this._preview.appendItems(Question.Content.get(this.question));
    4546        },
    4647        _onSave: function(evt) {
    4748            lang.mixin(this.question, this._toolkit.get('value'));
    48             this.question.content = this._preview.getItems();
     49            Question.Content.set(this.question, this._preview.getItems());
    4950            store.put(this.question)
    5051            .then(function() {
  • Dev/branches/rest-dojo-ui/client/qed/pages/session.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    '../search',
    88    '../store',
     
    1010    '../app/Router',
    1111    '../widgets/ThresholdFilteringSelect',
     12    '../model/classes/SessionTemplate',
    1213    '../model/widgets/AccountListView',
    1314    'dojo/text!./templates/session.html'
    14 ],function(array,declare,Deferred,event,lang,search,store,Page,Router,ThresholdFilteringSelect,AccountListView,template){
     15],function(array,declare,event,lang,when,search,store,Page,Router,ThresholdFilteringSelect,SessionTemplate,AccountListView,template){
    1516    return declare([Page],{
    1617        templateString: template,
     
    3031        _loadSession: function() {
    3132            if ( this.sessionId === "new" ) {
    32                 this.session = {
    33                     type: 'SessionTemplate'
    34                 };
     33                this.session = SessionTemplate.create();
    3534            } else {
    36                 Deferred.when(store.get(this.sessionId))
     35                when(store.get(this.sessionId))
    3736                .then(lang.hitch(this,function(obj){
    3837                    this.session = obj;
     
    4342        },
    4443        _refresh: function() {
    45             this.titleNode.innerHTML = this.session.title || '';
     44            this.titleNode.innerHTML = SessionTemplate.DisplayTitle.get(this.session);
    4645            this.propertiesForm.set('value',this.session);
    4746        },
  • 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            });
  • 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    });
  • Dev/branches/rest-dojo-ui/client/qed/pages/surveys.js

    r418 r420  
    99    '../app/Page',
    1010    '../app/Router',
     11    '../model/classes/Survey',
     12    '../model/classes/SurveyRun',
    1113    '../widgets/LineWithActionsWidget',
    1214    'dojo/text!./templates/surveys.html'
    13 ],function(array,declare,lang,when,Rx,store,Content,Page,Router,LineWithActionsWidget,template){
     15],function(array,declare,lang,when,Rx,store,Content,Page,Router,Survey,SurveyRun,LineWithActionsWidget,template){
    1416    return declare([Page],{
    1517        templateString: template,
     
    4547        },
    4648        _onPreviewSurvey:function(survey){
    47             Router.go('/viewSurvey/'+store.getIdentity(survey),{preview:true});
     49            Router.go('/previewSurvey/'+store.getIdentity(survey));
    4850        },
    4951        _onRunSurvey:function(survey){
    50             this.surveyRun = {
    51                 type: 'SurveyRun',
    52                 surveyId: store.getIdentity(survey),
    53                 publicationDate: store.timestamp()
    54             };
    55             this.surveyRunDialog.set('value',this.surveyRun);
    56             this.surveyRunDialog.show();
    57         },
    58         _onSurveyRunOk: function() {
    59             var surveyRun = lang.mixin(lang.clone(this.surveyRun),this.surveyRunDialog.get('value'));
     52            var surveyRun = SurveyRun.create();
     53            SurveyRun.Survey.set(surveyRun,survey);
    6054            store.put(surveyRun)
    61             .then(lang.hitch(this,function(){
    62                 this.surveyRunDialog.hide();
    63                 this.refreshRuns();
     55            .then(lang.hitch(this,function(surveyRun){
     56                this._onRunDetails(surveyRun);
    6457            }),function(err){
    6558                Content.notify(err);
    6659            });
    6760        },
    68         _onSurveyRunCancel: function() {
    69             this.surveyRunDialog.hide();
     61        _onRunDetails: function(surveyRun) {
     62            Router.go('/surveyRun/'+store.getIdentity(surveyRun));
    7063        },
    7164        refresh: function() {
     
    8174                array.forEach(surveys,function(survey){
    8275                    var w = new LineWithActionsWidget({
    83                         title: survey.title || '(unnamed)',
     76                        title: Survey.DisplayTitle.get(survey) || '(unnamed)',
    8477                        actions: [{
    8578                            callback: lang.hitch(this,'_onPublishSurvey',survey),
     
    123116                array.forEach(surveys,function(survey){
    124117                    var w = new LineWithActionsWidget({
    125                         title: survey.title,
     118                        title: Survey.DisplayTitle.get(survey),
    126119                        actions:[{
    127120                            callback: lang.hitch(this,'_onPreviewSurvey',survey),
     
    151144                array.forEach(surveyRuns,function(surveyRun){
    152145                    var w = new LineWithActionsWidget({
    153                         title: surveyRun.title+" (from "+surveyRun.startDate+" to "+surveyRun.endDate+")",
     146                        title: SurveyRun.DisplayTitle.get(surveyRun),
    154147                        actions:[{
    155                             callback: lang.hitch(this,'_onCloseRun',surveyRun),
     148                            callback: lang.hitch(this,'_onRunDetails',surveyRun),
    156149                            properties: {
    157                                 label: 'Close',
    158                                 tooltip: 'Close survey',
    159                                 icon: 'Close'
     150                                label: 'Details',
     151                                tooltip: 'Show details for this run',
     152                                icon: 'Details'
    160153                            }
    161154                        }]
  • Dev/branches/rest-dojo-ui/client/qed/pages/templates/previewSurvey.html

    r418 r420  
    99   
    1010    <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'" data-dojo-attach-point="questionsPane">
    11         <form data-dojo-type="dijit/form/Form" data-dojo-attach-point="questionsForm"
    12               data-dojo-attach-event="onSubmit:_onSubmit"
    13               style="overflow: auto">
    14             <div data-dojo-attach-point="questionsAnchor"></div>
     11        <form data-dojo-type="dijit/form/Form" data-dojo-attach-point="questionsForm" style="overflow: auto">
     12            <div data-dojo-type="qed/model/widgets/SurveyWidget" data-dojo-attach-point="surveyWidget"></div>
    1513        </form>
    1614    </div>
    1715   
    18     <div data-dojo-attach-point="buttonsPane" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'bottom'">
    19         <button data-dojo-type="dijit/form/Button"
    20                 type="submit"
    21                 data-dojo-attach-event="onClick:_onSubmit">
    22             Submit</button>
    23         <button data-dojo-type="dijit/form/Button"
    24                 type="button"
    25                 data-dojo-attach-event="onClick:_onCancel">
    26             Cancel</button>
    27     </div>
    28 
    2916</div>
  • Dev/branches/rest-dojo-ui/client/qed/pages/templates/surveys.html

    r419 r420  
    3636    </div>
    3737
    38     <div data-dojo-type="dijit/Dialog"
    39          title="SurveyRun properties"
    40          data-dojo-attach-point="surveyRunDialog">
    41         <fieldset data-dojo-type="qed/model/widgets/SurveyRunFieldset"></fieldset>
    42         <button data-dojo-type="dijit/form/Button" data-dojo-attach-event="onClick:_onSurveyRunOk">OK</button>
    43         <button data-dojo-type="dijit/form/Button" data-dojo-attach-event="onClick:_onSurveyRunCancel">Cancel</button>
    44     </div>
    45 
    4638</div>
Note: See TracChangeset for help on using the changeset viewer.