Changeset 478 for Dev


Ignore:
Timestamp:
10/16/13 16:05:39 (12 years ago)
Author:
hendrikvanantwerpen
Message:

Changes for response submission & deletion.

Location:
Dev/trunk/src
Files:
5 edited

Legend:

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

    r477 r478  
    6363            this.submitButton.set('disabled',false);
    6464            this.continueButton.set('disabled',false);
     65            this.cancelButton.set('disabled',false);
    6566            this.surveyWidget.set('disabled', false);
    6667        },
     
    6869            this.submitButton.set('disabled',true);
    6970            this.continueButton.set('disabled',true);
     71            this.cancelButton.set('disabled',true);
    7072            this.surveyWidget.set('disabled', true);
    7173        },
     
    8082                data:json.toJson(this.response),
    8183                headers:{"Content-Type": "application/json"}
    82             }).then(function(){
     84            }).then(lang.hitch(this,function(res){
     85                this.response._rev = res.rev;
    8386                Content.notify("Your response is saved.");
    84             }, function(err){
     87            }), function(err){
    8588                Content.notify(err,'error');
    8689            });
     
    104107            return false;
    105108        },
     109        _onCancel: function(e) {
     110            this._disableSubmit();
     111            this.surveyWidget.destroy();
     112            request('/api/responses/'+store.getIdentity(this.response)+'?rev='+store.getRevision(this.response),{
     113                method: 'DELETE',
     114                handleAs:'json',
     115                data:json.toJson(this.response),
     116                headers:{"Content-Type": "application/json"}
     117            }).then(lang.hitch(this,function(res){
     118                this._showInfo("<div>Your response has been deleted, no answers have been saved.</div>");
     119                Content.notify("Your response is deleted.");
     120            }), function(err){
     121                Content.notify(err,'error');
     122            });
     123            if ( e ) { event.stop(e); }
     124            return false;
     125        },
    106126        _ignoreEvent: function(e) {
    107127            if ( e ) { event.stop(e); }
  • Dev/trunk/src/client/qed-client/pages/templates/response.html

    r463 r478  
    2929                data-dojo-attach-point="continueButton"
    3030                data-dojo-attach-event="onClick:_onContinueLater">
    31             Continue later</button>
     31            Save & Continue later</button>
     32        <button data-dojo-type="dijit/form/Button"
     33                type="button"
     34                data-dojo-attach-point="cancelButton"
     35                data-dojo-attach-event="onClick:_onCancel">
     36            Cancel & Delete</button>
    3237    </div>
    3338
  • Dev/trunk/src/client/qed-client/store.js

    r468 r478  
    1010   
    1111    var couchStore = new CouchStore({
    12         target: 'api/data/',
     12        target: '/data/',
    1313        request: request /*,
    1414        validate: function(object) {
  • Dev/trunk/src/server/app.js

    r477 r478  
    4848
    4949    // cookies and session
    50     app.use('/api',express.bodyParser());
    5150    app.use(express.cookieParser());
    5251    app.use(express.session({ secret: "quasi experimental design" }));
     52    app.use('/api',express.bodyParser());
    5353
    5454    // passport
     
    7777    });
    7878
     79    // data is proxied to couch
     80    app.use('/data', ensureAuthenticated);
     81    app.use('/data', proxy(settings.couchDbURL));
    7982
    8083    // post to this url to login
     
    99102        });
    100103
    101     // expose everything needed to fill in responses
    102     // FIXME : this needs more security, now you can guess ids
    103     //         and get actual survey and response data!
    104     app.get(
    105         '/live',
    106         function(req,res){
    107             res.redirect('/response.html#!/55704d6a84194c2d7ba9bec93c000e75');
    108         });
    109104    app.get(
    110105        '/api/surveyRuns/:id',
     
    155150            });
    156151        });
     152    app.delete(
     153        '/api/responses/:id',
     154        function(req,res){
     155            var id = req.params.id;
     156            var rev = req.query.rev;
     157            couch.delete(id,rev).then(function(result){
     158                res.send(200, result);
     159            }, function(error){
     160                res.send(500, error);
     161            });
     162        });
    157163   
    158     // data is proxied to couch
    159     app.use('/api/data', ensureAuthenticated);
    160     app.use('/api/data', proxy(settings.couchDbURL));
    161 
    162164    // generate CSV download of responses
    163165    app.get(
     
    224226}
    225227
    226 function writeObjectsToCSVStream(objects, stream) {
     228function writeObjectsToCSVStream(objects, stream, prelude) {
    227229    var keys = _.chain(objects)
    228230                .map(_.keys)
     
    235237    });
    236238    var writer = new CSV.CsvWriter(stream);
     239    if ( prelude ) {
     240        _.forEach(prelude, function(val,key){
     241            writer.writeRecord([key,val]);
     242        });
     243    }
    237244    writer.writeRecord(keys);
    238245    _.forEach(objects, function(obj){
  • Dev/trunk/src/server/util/couch.coffee

    r477 r478  
    1515        url = "#{@url}/#{id}"
    1616        couchRequest 'PUT', url, doc
     17    delete: (id, rev) ->
     18        url = "#{@url}/#{id}?rev=#{rev}"
     19        couchRequest 'DELETE', url
    1720
    1821normalizeURL = (url) ->
Note: See TracChangeset for help on using the changeset viewer.