Changeset 477 for Dev


Ignore:
Timestamp:
08/06/13 01:48:17 (12 years ago)
Author:
hendrikvanantwerpen
Message:

Quick hack to allow responding despite not being authenticated. Something like tokes need to be added.

Location:
Dev/trunk/src
Files:
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/src/client/qed-client/css/fonts.less

    r447 r477  
    33    font-size: @font_size;
    44    color: @text;
     5    &.light {
     6        color: black; // FIXME : hack for readability
     7    }
    58
    69    a {
  • Dev/trunk/src/client/qed-client/css/layout.less

    r443 r477  
    77    height: 100%;
    88    background-color: @base;
     9    .light {
     10        background-color: white; // FIXME : hack for readability
     11    }
    912}
  • Dev/trunk/src/client/qed-client/model/widgets/TabbedQuestionBrowser.js

    r443 r477  
    7878                    title: (topic || '[No topic]')+" ("+count+")",
    7979                    selectedActions: this.selectedActions,
    80                     itemActions: this.itemActions
     80                    itemActions: this.itemActions,
     81                    itemTitle: this._itemTitle
    8182                }).placeAt(categoryMap._widget.containerNode);
    8283                w.startup();
     
    8788            }
    8889        },
     90        _itemTitle: function(item) {
     91            var title = '['+item.code+']'+item.title;
     92            if ( this.include === 'all' ) {
     93                title += (item.publicationDate?' (published on '+item.publicationDate+')':' (unpublished)');
     94            }
     95            return title;
     96        },
    8997        _fillTopicSelector: function(topic,category) {
    9098            var categoryMap = this._dataMap[category];
     
    93101                topicMap._filled = true;
    94102                this._busy();
    95                 store.query(this._query, {reduce:false,include_docs:true,key:[category,topic]})
    96                 .forEach(lang.hitch(this,function(value){
    97                     var title;
    98                     if ( this.include === 'all' ) {
    99                         title = value.title+(value.publicationDate?' (published on '+value.publicationDate+')':' (unpublished)');
    100                     }
    101                     topicMap._widget.addItem(value,title);
     103                store.query(this._query, {
     104                    reduce:false,
     105                    include_docs:true,
     106                    key:[category,topic]
     107                }).forEach(lang.hitch(this,function(value){
     108                    topicMap._widget.addItem(value);
    102109                })).then(lang.hitch(this,function(){
    103110                    this._done();
  • Dev/trunk/src/client/qed-client/pages/response.js

    r461 r477  
    99    "dojo/_base/declare",
    1010    "dojo/_base/event",
     11    "dojo/_base/json",
    1112    "dojo/_base/lang",
    1213    "dojo/promise/all",
     14    "dojo/request",
    1315    "dojo/when",
    1416    "require",
    1517    "dojo/text!./templates/response.html"
    16 ], function(Content, Page, async, Response, Survey, SurveyRun, store, declare, event, lang, all, when, require, template) {
     18], function(Content, Page, async, Response, Survey, SurveyRun, store, declare, event, json, lang, all, request, when, require, template) {
    1719    return declare([Page],{
    1820        contextRequire: require,
     
    3739                        this._enableSubmit();
    3840                    }
    39                 }), function() {
     41                }), lang.hitch(this,function() {
    4042                    this._showInfo("<div>The url seems to be incorrect, no survey found.</div>");
    41                 });
     43                }));
    4244            } else {
    4345                throw new Error("No valid uid or survey passed!");
     
    4547        },
    4648        _loadSurveyAndResponse: function(surveyRunId,responseId){
    47             return all([store.get(surveyRunId),store.get(responseId)])
     49            return all([request.get('/api/surveyRuns/'+surveyRunId,{handleAs:'json'}),
     50                        request.get('/api/responses/'+responseId,{handleAs:'json'})])
    4851            .then(lang.hitch(this,function(surveyAndResponse){
    4952                var surveyRun = surveyAndResponse[0];
     
    7376            var answers = this.surveyWidget.get('value');
    7477            this.response.answers = answers;
    75             return store.put(this.response).then(function(){
     78            return request.put('/api/responses/'+store.getIdentity(this.response),{
     79                handleAs:'json',
     80                data:json.toJson(this.response),
     81                headers:{"Content-Type": "application/json"}
     82            }).then(function(){
    7683                Content.notify("Your response is saved.");
    7784            }, function(err){
     
    8289            this.response.publicationDate = store.timestamp();
    8390            this._getAnswersAndSaveResponse()
    84             .then(function(){
     91            .then(lang.hitch(this,function(){
    8592                this._showInfo("<div>Thanks for filling in the survey. You cannot edit your answers anymore.</div>");
    8693                this._disableSubmit();
    87             });
     94            }));
    8895            if ( e ) { event.stop(e); }
    8996            return false;
  • Dev/trunk/src/client/qed-client/response.js

    r443 r477  
    11define([
    2     'dojo/date',
    3     'dojo/date/locale',
    4     'dojo/hash',
    5     'dojo/parser',
    6     './store',
    7     './app/Content',
    8     './app/Page',
    9     './app/Path',
    10     './lib/async',
    11     './model/classes/Response',
    12     './model/classes/SurveyRun',
    13     './pages/response',
    14     'dojo/domReady!',
    15     './stddeps'
    16 ],function(date,locale,hash,parser,store,Content,Page,Path,async,Response,SurveyRun,ResponsePage) {
     2    "./app/Content",
     3    "./app/Page",
     4    "./app/Path",
     5    "./lib/async",
     6    "./model/classes/Response",
     7    "./model/classes/SurveyRun",
     8    "./pages/response",
     9    "./store",
     10    "dojo/_base/json",
     11    "dojo/date",
     12    "dojo/date/locale",
     13    "dojo/hash",
     14    "dojo/parser",
     15    "dojo/request",
     16    "./stddeps",
     17    "dojo/domReady!"
     18], function(Content, Page, Path, async, Response, SurveyRun, ResponsePage, store, json, date, locale, hash, parser, request) {
    1719    parser.parse();
    1820    Content.startup();
     
    4951    }
    5052
    51     store.get(surveyRunId)
     53    request.get('/api/surveyRuns/'+surveyRunId,{handleAs:'json'})
    5254    .then(function(surveyRun){
    5355        checkDates(surveyRun);
     
    5860                var response = Response.create();
    5961                response.surveyRunId = surveyRunId;
    60                 return store.put(response).then(function(res){
    61                     return store.getIdentity(res);
     62                return request.post('/api/responses',{
     63                    handleAs:'json',
     64                    data:json.toJson(response),
     65                    headers:{"Content-Type": "application/json"}
     66                }).then(function(res){
     67                    return res.id;
    6268                });
    6369            } else {
  • Dev/trunk/src/client/qed-client/widgets/Selector.js

    r472 r477  
    1818], function(LineWithActionsWidget, _Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, registry, baseArray, declare, event, lang, Source, domClass, domConstruct, fx, query, templateString) {
    1919
     20    function get(selector, item) {
     21        if ( lang.isFunction(selector) ) {
     22            return selector(item);
     23        } else {
     24            return item[selector || 'title'];
     25        }
     26    }
     27   
    2028    return declare([_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{
    2129        templateString: templateString,
     
    2533        selectedActions: null,
    2634        itemActions: null,
     35        itemTitle: 'title',
    2736        // main selector action: Object
    2837        //    title:
     
    111120            this._selectedItem = item;
    112121            this.onToggle();
    113             this._selectorLine.set("title", item.title);
     122            this._selectorLine.set("title", get(this.itemTitle,item));
    114123            baseArray.forEach(this.optionsNode.childNodes, function(node){
    115124                var line = registry.byNode(node);
     
    174183            return domConstruct.create("div",{
    175184                'class': 'dragAvatar',
    176                 innerHTML: item.title
     185                innerHTML: get(this.itemTitle,item)
    177186            });
    178187        },
     
    197206            }
    198207            var w = new LineWithActionsWidget({
    199                 title: item.title,
     208                title: get(this.itemTitle,item),
    200209                actions: actions
    201210            });
  • Dev/trunk/src/client/response.html

    r452 r477  
    66        <link rel="stylesheet" type="text/css" href="qed-client/css/qed.css" />
    77    </head>
    8     <body id="rft" class="dijitReset claro">
     8    <body id="rft" class="dijitReset claro light" >
    99        <script type="text/javascript">
    1010            var dojoConfig = {
  • Dev/trunk/src/server/app.js

    r475 r477  
    4848
    4949    // cookies and session
    50     app.use('/api/login',express.bodyParser());
     50    app.use('/api',express.bodyParser());
    5151    app.use(express.cookieParser());
    5252    app.use(express.session({ secret: "quasi experimental design" }));
     
    9999        });
    100100
     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        });
     109    app.get(
     110        '/api/surveyRuns/:id',
     111        function(req,res){
     112            var id = req.params.id;
     113            couch.get(id).then(function(result){
     114                if ( result.type === 'SurveyRun') {
     115                    res.send(200, result);
     116                } else {
     117                    res.send(404, {error: "Cannot find survey run "+id});
     118                }
     119            }, function(error){
     120                res.send(404, {error: "Cannot find survey run "+id});
     121            });
     122        });
     123    app.get(
     124        '/api/responses/:id',
     125        function(req,res){
     126            var id = req.params.id;
     127            couch.get(id).then(function(result){
     128                if ( result.type === 'Response') {
     129                    res.send(200, result);
     130                } else {
     131                    res.send(404, {error: "Cannot find response "+id});
     132                }
     133            }, function(error){
     134                res.send(404, {error: "Cannot find response "+id});
     135            });
     136        });
     137    app.post(
     138        '/api/responses',
     139        function(req,res){
     140            console.log(req.body);
     141            couch.post(req.body).then(function(result){
     142                res.send(200, result);
     143            }, function(error){
     144                res.send(500, error);
     145            });
     146        });
     147    app.put(
     148        '/api/responses/:id',
     149        function(req,res){
     150            var id = req.params.id;
     151            couch.put(id,req.body).then(function(result){
     152                res.send(200, result);
     153            }, function(error){
     154                res.send(500, error);
     155            });
     156        });
     157   
    101158    // data is proxied to couch
    102159    app.use('/api/data', ensureAuthenticated);
     
    135192function responseToVariables(response) {
    136193    var result = flattenObject(response.answers);
    137     result.respondent = response.id;
    138194    return result;
    139195}
     
    143199    (function agg(val,key,res){
    144200        if ( _.isObject(val) ) {
    145             _.forEach(val, function(v,k){
    146                 agg(v,(key ? key+'.' : '')+k,res);
    147             });
     201            var keys = _.keys(val);
     202            // FIXME : dirty hack for questions with only one input
     203            if ( keys.length === 1 ) {
     204                agg(val[keys[0]],key,res);
     205            } else {
     206                _.forEach(val, function(v,k){
     207                    agg(v,(key ? key+'.' : '')+k,res);
     208                });
     209            }
    148210        } else if ( _.isArray(val) ) {
    149             _.forEach(val, function(v,i){
    150                 agg(v,(key ? key+'.' : '')+i,res);
    151             });
     211            // FIXME : dirty hack for questions with only one input
     212            if ( val.length === 1 ) {
     213                agg(val[0],key,res);
     214            } else {
     215                _.forEach(val, function(v,i){
     216                    agg(v,(key ? key+'.' : '')+i,res);
     217                });
     218            }
    152219        } else {
    153220            res[key] = val;
  • Dev/trunk/src/server/config/couchdb-design-docs.js

    r464 r477  
    3333                map: function(doc){
    3434                    emit(doc.type, doc);
     35                }
     36            },
     37            typeless: {
     38                map: function(doc){
     39                    if ( !doc.type ) {
     40                        emit(doc._id, doc);
     41                    }
    3542                }
    3643            }
  • Dev/trunk/src/server/util/couch.coffee

    r475 r477  
    99        url = "#{@url}/#{id}"
    1010        couchRequest 'GET', url
     11    post: (doc) ->
     12        url = "#{@url}"
     13        couchRequest 'POST', url, doc
    1114    put: (id, doc) ->
    1215        url = "#{@url}/#{id}"
Note: See TracChangeset for help on using the changeset viewer.