Ignore:
Timestamp:
06/10/13 01:07:16 (12 years ago)
Author:
hendrikvanantwerpen
Message:

Save answers, improved response page and question widgets.

  • Warn if _ComplexValueMixin is not pout on a form element, to prevent 'name' collisions. Changed all depending widgets to <form>'s.
  • Fixed names for question widgets to actually save answers.
  • Fixed and improved response page.
  • Fixed names in MultipleChoice? widget, which behaves different for radio and check.
Location:
Dev/trunk/src/client/qed-client/pages
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/src/client/qed-client/pages/response.js

    r443 r461  
    11define([
     2    "../app/Content",
    23    "../app/Page",
    34    "../lib/async",
     
    1314    "require",
    1415    "dojo/text!./templates/response.html"
    15 ], function(Page, async, Response, Survey, SurveyRun, store, declare, event, lang, all, when, require, template) {
     16], function(Content, Page, async, Response, Survey, SurveyRun, store, declare, event, lang, all, when, require, template) {
    1617    return declare([Page],{
    1718        contextRequire: require,
     
    2425            if ( this._started ) { return; }
    2526            this.inherited(arguments);
    26             this._disableButtons();
     27            this._disableSubmit();
    2728            var surveyRunId = this.surveyRunId;
    2829            var responseId = this.options && this.options.id;
    2930            if ( surveyRunId && responseId ) {
    3031                this._loadSurveyAndResponse(surveyRunId,responseId)
    31                 .then(lang.hitch(this,"_enableButtons"));
     32                .then(lang.hitch(this, function() {
     33                    if ( this.response.publicationDate ) {
     34                        this._showInfo("<div>You already submitted your survey and cannot change it anymore. You can still view your answers here.</div>");
     35                        this._disableSubmit();
     36                    } else {
     37                        this._enableSubmit();
     38                    }
     39                }), function() {
     40                    this._showInfo("<div>The url seems to be incorrect, no survey found.</div>");
     41                });
    3242            } else {
    3343                throw new Error("No valid uid or survey passed!");
     
    4353                }
    4454                this.titleNode.innerHTML = Survey.DisplayTitle.get(surveyRun.survey);
    45                 this.surveyWidget.set('survey',surveyRun.survey);
    46                 this.responseForm.set('value',this.response.answers || {});
     55                this.surveyWidget.set('survey', surveyRun.survey);
     56                this.surveyWidget.set('value', this.response.answers || {});
    4757            }));
    4858        },
    49         _enableButtons: function() {
     59        _enableSubmit: function() {
    5060            this.submitButton.set('disabled',false);
    5161            this.continueButton.set('disabled',false);
     62            this.surveyWidget.set('disabled', false);
    5263        },
    53         _disableButtons: function() {
     64        _disableSubmit: function() {
    5465            this.submitButton.set('disabled',true);
    5566            this.continueButton.set('disabled',true);
     67            this.surveyWidget.set('disabled', true);
     68        },
     69        _showInfo: function(html) {
     70            this.infoNode.innerHTML = html;
    5671        },
    5772        _getAnswersAndSaveResponse: function() {
    58             this.response.answers = this.responseForm.get('value');
    59             console.log(this.response);
    60             return store.put(this.response);
     73            var answers = this.surveyWidget.get('value');
     74            this.response.answers = answers;
     75            return store.put(this.response).then(function(){
     76                Content.notify("Your response is saved.");
     77            }, function(err){
     78                Content.notify(err,'error');
     79            });
    6180        },
    6281        _onSubmit: function(e) {
    6382            this.response.publicationDate = store.timestamp();
    64             this._getAnswersAndSaveResponse();
    65             this.content.domNode.innerHTML = "<div>Thanks for filling in the survey.</div>";
     83            this._getAnswersAndSaveResponse()
     84            .then(function(){
     85                this._showInfo("<div>Thanks for filling in the survey. You cannot edit your answers anymore.</div>");
     86                this._disableSubmit();
     87            });
    6688            if ( e ) { event.stop(e); }
    6789            return false;
    6890        },
    6991        _onContinueLater: function(e) {
    70             this._getAnswersAndSaveResponse();
    71             this.content.domNode.innerHTML = "<div>To continue with this survey later, just save the URL in the location bar and revisit it later. Your answers will still be there.</div>";
     92            this._getAnswersAndSaveResponse()
     93            .then(lang.hitch(this,function(){
     94                this._showInfo("<div>To continue with this survey later, just save the URL in the location bar and revisit it later. Your answers will still be there.</div>");
     95            }));
    7296            if ( e ) { event.stop(e); }
    7397            return false;
  • Dev/trunk/src/client/qed-client/pages/templates/response.html

    r457 r461  
    66            <span class="headerText" data-dojo-attach-point="titleNode">Survey</span>
    77        </h2>
     8        <div data-dojo-attach-point="infoNode"></div>
    89    </div>
    910   
    1011    <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'" data-dojo-attach-point="content">
    11         <form data-dojo-type="dijit/form/Form" data-dojo-attach-point="responseForm"
    12               data-dojo-attach-event="onSubmit:_ignoreEvent" style="overflow: auto">
    13             <div data-dojo-type="../model/widgets/SurveyRenderWidget" data-dojo-attach-point="surveyWidget"></div>
    14         </form>
     12        <div name="answers" data-dojo-type="../model/widgets/SurveyRenderWidget" data-dojo-attach-point="surveyWidget"></div>
    1513    </div>
    1614   
Note: See TracChangeset for help on using the changeset viewer.