Ignore:
Timestamp:
03/05/14 22:44:48 (11 years ago)
Author:
hendrikvanantwerpen
Message:

Completed migration to API, without CouchDB proxy.

Move to API is now completed. The full API is password protected, a very
limited API is exposed for respondents, which works with secrets that
are passed in URLs.

Serverside the HTTPResult class was introduced, which is similar to
Promises, but specifically for HTTP. It carries a status code and
response and makes it easier to extract parts of async handling in
separate functions.

Fixed a bug in our schema (it seems optional attributes don't exist but
a required list does). Verification of our schema by grunt-tv4 didn't
work yet. Our schema is organized the wrong way (this is fixable),
but the json-schema schema has problems with simple types and $refs.

File:
1 edited

Legend:

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

    r466 r487  
    44    "../app/Router",
    55    "../lib/func",
    6     "../model/classes/SurveyRun",
    7     "../store",
     6    "../model/classes/responses",
     7    "../model/classes/surveyRuns",
    88    "../widgets/LineWithActionsWidget",
     9    "dojo/_base/array",
    910    "dojo/_base/declare",
    1011    "dojo/_base/event",
     
    1314    "require",
    1415    "dojo/text!./templates/surveyRun.html"
    15 ], function(Content, Page, Router, func, SurveyRun, store, LineWithActionsWidget, declare, event, lang, when, require, template) {
     16], function(Content, Page, Router, func, responses, surveyRuns, LineWithActionsWidget, array, declare, event, lang, when, require, template) {
    1617    return declare([Page],{
    1718        contextRequire: require,
     
    2425            if ( this.surveyRunId ) {
    2526                this._loadSurveyRun();
    26                 this._loadResponses();
    2727            } else {
    2828                throw "No valid uid or survey passed!";
     
    3030        },
    3131        _loadSurveyRun: function() {
    32             when(store.get(this.surveyRunId))
     32            when(surveyRuns.load(this.surveyRunId))
    3333            .then(lang.hitch(this,function(surveyRun){
    3434                this.surveyRun = surveyRun;
    3535                this.refreshSurveyRun();
     36                this._loadResponses();
    3637            }));
    3738        },
    3839        refreshSurveyRun: function() {
    39             this.titleNode.innerHTML = SurveyRun.DisplayTitle.get(this.surveyRun);
    40             this.surveySummaryWidget.set('value',SurveyRun.Survey.get(this.surveyRun));
     40            this.titleNode.innerHTML = this.surveyRun.title || "";
     41            this.surveySummaryWidget.set('value',this.surveyRun.survey);
    4142            this.surveyRunWidget.set('value',this.surveyRun);
    4243            this._onPropChange();
    4344        },
    4445        _loadResponses: function() {
    45             when(store.query("_design/responses/_view/by_surveyrun",{key:this.surveyRunId}))
    46             .forEach(lang.hitch(this,function(response){
    47                 var actions = {
    48                     view: {
    49                         callback: function(){},
    50                         properties: {
    51                             title: "View response"
    52                         }
    53                     }
    54                 };
    55                 if ( !response.publicationDate ) {
    56                     actions.remove = {
    57                         callback: function(){},
    58                         properties: {
    59                             title: "Remove response"
     46            responses.query({surveyRunId:surveyRuns.getId(this.surveyRun)})
     47            .then(lang.hitch(this,function(allResponses){
     48                array.forEach(allResponses, function(response){
     49                    var actions = {
     50                        view: {
     51                            callback: function(){},
     52                            properties: {
     53                                title: "View response"
     54                            }
    6055                        }
    6156                    };
    62                 }
    63                 var w = new LineWithActionsWidget({
    64                     actions: actions
    65                 });
    66                 var responseId = store.getIdentity(response);
    67                 w.set('title',this._link(this._getResponseURL(this.surveyRunId,responseId),responseId));
    68                 w.placeAt(this.responsesNode);
     57                    if ( !response.publicationDate ) {
     58                        actions.remove = {
     59                            callback: function(){},
     60                            properties: {
     61                                title: "Remove response"
     62                            }
     63                        };
     64                    }
     65                    var w = new LineWithActionsWidget({
     66                        actions: actions
     67                    });
     68                    var rid = responses.getId(response);
     69                    w.set('title',this._link(this._buildResponseURL(response),rid),rid);
     70                    w.placeAt(this.responsesNode);
     71                }, this);
    6972            }));
    7073        },
     
    7376            if ( surveyRun.mode === "open" ) {
    7477                this.runURLNode.innerHTML =
    75                     this._link(this._getGeneralURL(store.getIdentity(this.surveyRun)));
     78                    this._link(this._buildGeneralURL(this.surveyRun));
    7679            } else {
    7780                this.runURLNode.innerHTML =
     
    7982            }
    8083        },
    81         _getGeneralURL: function(surveyRunId) {
    82             return 'response.html#!/'+surveyRunId;
     84        _buildGeneralURL: function(surveyRun) {
     85            return 'response.html#!/surveyRuns/'+surveyRuns.getId(surveyRun)+'!secret='+surveyRun.secret;
    8386        },
    84         _getResponseURL: function(surveyRunId,responseId) {
    85             return 'response.html#!/'+surveyRunId+'!id='+responseId;
     87        _buildResponseURL: function(response) {
     88            return 'response.html#!/responses/'+responses.getId(response)+'!secret='+response.secret;
    8689        },
    8790        _link: function(url,label) {
     
    9295                lang.mixin(this.surveyRun,this.surveyRunWidget.get('value'));
    9396
    94                 var SD = SurveyRun.StartDate;
    95                 var ED = SurveyRun.EndDate;
    96                 SD.set(this.surveyRun, SD.get(this.surveyRun));
    97                 ED.set(this.surveyRun, ED.get(this.surveyRun));
    98 
    99                 store.put(this.surveyRun)
     97                surveyRuns.save(this.surveyRun)
    10098                .then(function() {
    10199                    Router.go('/surveys');
Note: See TracChangeset for help on using the changeset viewer.