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/surveys.js

    r443 r487  
    11define([
    2     'dojo/_base/array',
    3     'dojo/_base/declare',
    4     'dojo/_base/lang',
    5     'dojo/when',
    6     '../store',
    7     '../app/Content',
    8     '../app/Page',
    9     '../app/Router',
    10     '../model/classes/Survey',
    11     '../model/classes/SurveyRun',
    12     '../widgets/LineWithActionsWidget',
    13     'dojo/text!./templates/surveys.html'
    14 ],function(array,declare,lang,when,store,Content,Page,Router,Survey,SurveyRun,LineWithActionsWidget,template){
     2    "../app/Content",
     3    "../app/Page",
     4    "../app/Router",
     5    "../model/classes/surveys",
     6    "../model/classes/surveyRuns",
     7    "../widgets/LineWithActionsWidget",
     8    "dojo/_base/array",
     9    "dojo/_base/declare",
     10    "dojo/_base/lang",
     11    "dojo/when",
     12    "dojo/text!./templates/surveys.html"
     13], function(Content, Page, Router, surveys, surveyRuns, LineWithActionsWidget, array, declare, lang, when, template) {
    1514    return declare([Page],{
    1615        templateString: template,
     
    2524        _onPublishSurvey:function(survey){
    2625            var self = this;
    27             survey.publicationDate = store.timestamp();
    28             store.put(survey).then(function(){
     26            survey.publicationDate = new Date();
     27            surveys.save(survey)
     28            .then(function(){
    2929                self.refreshDrafts();
    3030                self.refreshPublished();
     
    3535        _onDeleteSurvey:function(survey){
    3636            var self = this;
    37             store.remove(store.getIdentity(survey),store.getRevision(survey))
     37            surveys.remove(survey)
    3838            .then(function(){
    3939                self.refreshDrafts();
     
    4343        },
    4444        _onEditSurvey:function(survey){
    45             Router.go('/survey/'+store.getIdentity(survey));
     45            Router.go('/survey/'+survey._id);
    4646        },
    4747        _onPreviewSurvey:function(survey){
    48             Router.go('/previewSurvey/'+store.getIdentity(survey));
     48            Router.go('/previewSurvey/'+survey._id);
    4949        },
    5050        _onRunSurvey:function(survey){
    51             var surveyRun = SurveyRun.create();
    52             SurveyRun.Survey.set(surveyRun,survey);
    53             store.put(surveyRun)
     51            var surveyRun = surveyRuns.create();
     52            surveyRun.survey = survey;
     53            surveyRuns.save(surveyRun)
    5454            .then(lang.hitch(this,function(surveyRun){
    5555                this._onRunDetails(surveyRun);
     
    5959        },
    6060        _onRunDetails: function(surveyRun) {
    61             Router.go('/surveyRun/'+store.getIdentity(surveyRun));
     61            Router.go('/surveyRun/'+surveyRun._id);
    6262        },
    6363        refresh: function() {
     
    6868        refreshDrafts: function() {
    6969            this.draftsContainer.set('content','');
    70             when(store.query("_design/surveys/_view/drafts"),
    71                     lang.hitch(this,function(surveys) {
     70            when(surveys.query({drafts:true}), lang.hitch(this,function(surveys) {
    7271                this.draftsTab.set('title','Drafts ('+surveys.length+')');
    7372                array.forEach(surveys,function(survey){
    7473                    var w = new LineWithActionsWidget({
    75                         title: Survey.DisplayTitle.get(survey) || '(unnamed)',
     74                        title: survey.title || '(unnamed)',
    7675                        actions: [{
    7776                            callback: lang.hitch(this,'_onPublishSurvey',survey),
     
    110109        refreshPublished: function() {
    111110            this.publishedContainer.set('content','');
    112             when(store.query("_design/surveys/_view/published"),
    113                     lang.hitch(this, function(surveys) {
     111            when(surveys.query({published:true}), lang.hitch(this, function(surveys) {
    114112                this.publishedTab.set('title','Published ('+surveys.length+')');
    115113                array.forEach(surveys,function(survey){
    116114                    var w = new LineWithActionsWidget({
    117                         title: Survey.DisplayTitle.get(survey),
     115                        title: survey.title || "",
    118116                        actions:[{
    119117                            callback: lang.hitch(this,'_onPreviewSurvey',survey),
     
    138136        refreshRuns: function() {
    139137            this.runsContainer.set('content','');
    140             when(store.query("_design/default/_view/by_type",{key:'SurveyRun'}),
    141                     lang.hitch(this,function(surveyRuns){
     138            when(surveyRuns.query(), lang.hitch(this,function(surveyRuns){
    142139                this.runsTab.set('title','Runs ('+surveyRuns.length+')');
    143140                array.forEach(surveyRuns,function(surveyRun){
    144141                    var w = new LineWithActionsWidget({
    145                         title: SurveyRun.DisplayTitle.get(surveyRun),
     142                        title: surveyRun.title || "",
    146143                        actions:[{
    147144                            callback: lang.hitch(this,'_onRunDetails',surveyRun),
Note: See TracChangeset for help on using the changeset viewer.