Ignore:
Timestamp:
12/27/12 17:46:05 (12 years ago)
Author:
hendrikvanantwerpen
Message:

Show responses with links in SurveyRun? overview.

File:
1 edited

Legend:

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

    r420 r421  
    1010    '../app/Page',
    1111    '../model/classes/SurveyRun',
     12    '../widgets/LineWithActionsWidget',
    1213    'dojo/text!./templates/surveyRun.html'
    13 ],function(declare,event,lang,when,Content,Router,func,store,Page,SurveyRun,template){
     14],function(declare,event,lang,when,Content,Router,func,store,Page,SurveyRun,LineWithActionsWidget,template){
    1415    return declare([Page],{
    1516        templateString: template,
     
    2122            if ( this.surveyRunId ) {
    2223                this._loadSurveyRun();
     24                this._loadResponses();
    2325            } else {
    2426                throw "No valid uid or survey passed!";
     
    2931            .then(lang.hitch(this,function(surveyRun){
    3032                this.surveyRun = surveyRun;
    31                 this.refresh();
     33                this.refreshSurveyRun();
    3234            }));
    3335        },
    34         refresh: function() {
     36        refreshSurveyRun: function() {
    3537            this.titleNode.innerHTML = SurveyRun.DisplayTitle.get(this.surveyRun);
    3638            this.surveyNode.set('value',SurveyRun.Survey.get(this.surveyRun));
     
    3840            this._onPropChange();
    3941        },
     42        _loadResponses: function() {
     43            when(store.query("_design/responses/_view/by_surveyrun",{key:this.surveyRunId}))
     44            .forEach(lang.hitch(this,function(response){
     45                var actions = {
     46                    view: {
     47                        callback: function(){},
     48                        properties: {
     49                            title: "View response"
     50                        }
     51                    }
     52                };
     53                if ( !response.publicationDate ) {
     54                    actions.remove = {
     55                        callback: function(){},
     56                        properties: {
     57                            title: "Remove response"
     58                        }
     59                    };
     60                }
     61                var w = new LineWithActionsWidget({
     62                    actions: actions
     63                });
     64                var responseId = store.getIdentity(response);
     65                w.set('title',this._link(this._getResponseURL(this.surveyRunId,responseId),responseId));
     66                w.placeAt(this.responsesNode);
     67            }));
     68        },
    4069        _onPropChange: function(e) {
    4170            var surveyRun = this.propertiesForm.get('value');
    4271            if ( surveyRun.mode === "open" ) {
    43                 var url = 'response.html#!/'+store.getIdentity(this.surveyRun);
    44                 this.runURLNode.innerHTML = '<a target="_black" href="'+url+'">'+url+'</a>';
     72                this.runURLNode.innerHTML = this._link(this._getGeneralURL(store.getIdentity(this.surveyRun)));
    4573            } else {
    4674                this.runURLNode.innerHTML = "No general URL. Add individual respondents below.";
    4775            }
     76        },
     77        _getGeneralURL: function(surveyRunId) {
     78            return 'response.html#!/'+surveyRunId;
     79        },
     80        _getResponseURL: function(surveyRunId,responseId) {
     81            return 'response.html#!/'+surveyRunId+'!id='+responseId;
     82        },
     83        _link: function(url,label) {
     84            return '<a target="_black" href="'+url+'">'+(label || url)+'</a>';
    4885        },
    4986        _onSave: function(evt) {
Note: See TracChangeset for help on using the changeset viewer.