Ignore:
Timestamp:
07/26/12 21:57:20 (13 years ago)
Author:
hendrikvanantwerpen
Message:

Changed SurveyListView? to more general OrderedDndList?.
Survey page has rudimentary properties dialog and saves included questions.
Fixed bug in store for null question.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/rest-dojo-ui/client/rft/pages/survey.js

    r370 r379  
    11define([
     2    'dojo/_base/array',
    23    'dojo/_base/declare',
    34    'dojo/_base/Deferred',
     
    78    'rft/store',
    89    'rft/ui/_Page',
    9     'rft/ui/SurveyListView',
     10    'rft/ui/OrderedDndList',
    1011    'rft/ui/TabbedQuestionBrowser'
    1112    ],
    12     function(declare,Deferred,event,lang,content,store,_Page,SurveyListView,TabbedQuestionBrowser){
     13    function(array,declare,Deferred,event,lang,content,store,_Page,
     14             OrderedDndList,TabbedQuestionBrowser){
    1315        return declare('rft.pages.survey',[_Page],{
    14             object: null,
    15             listView: null,
     16            survey: null,
     17            questionList: null,
    1618            _dataMap: null,
    1719            constructor: function(){
     
    2022            onVisit: function() {
    2123                if ( this.pageArgs.uid ) {
     24                    this._setupQuestionBrowser();
     25                    this._setupListView();
    2226                    Deferred.when(store.get(this.pageArgs.uid))
    2327                    .then(lang.hitch(this,function(obj){
    24                         this.object = obj;
    25                         return Deferred.when( obj.creator && store.dereference(obj.creator) );
     28                        this.survey = obj;
     29                        this.refresh();
    2630                    }));
    27                     this._setupQuestionBrowser();
    28                     this._setupListView();
    2931                } else {
    3032                    throw "No valid uid or survey passed!";
    3133                }
    32             },
    33             onProperties: function(evt) {
    34 
    35             },
    36             onSave: function(evt) {
    37 //                lang.mixin(this.object, this.propertiesForm.get('value'));
    38                 store.put(this.object)
    39                 .then(function() {
    40                     content.goTo('surveys');
    41                 });
    42                 event.stop(evt);
    43                 return false;
    44             },
    45             _goToPreview: function() {
    46                 content.goTo('surveyAdvanced', {uid: this.object._id});
    4734            },
    4835            _setupQuestionBrowser: function() {
     
    5239                    selectedActions: {
    5340                        "Include": {
    54                             callback: lang.hitch(this,this.includeQuestion),
     41                            callback: lang.hitch(this,this._includeQuestion),
    5542                            icon: "Accept",
    5643                            description: "Include in survey"
     
    6754                this.questionBrowser.startup();
    6855            },
    69             /* ListView code */
    70             includeQuestion: function(question) {
    71                 var item = this.listView.insertItem(question);
     56            _includeQuestion: function(question) {
     57                this.questionList.insertItem(question);
    7258            },
    7359            _setupListView: function() {
    74                 this.listView = new SurveyListView({
    75                     controller: this
     60                this.questionList = new OrderedDndList({
     61                    type: 'question',
     62                    region: 'center'
    7663                }).placeAt(this.surveyListViewNode);
    77                 this.listView.startup();
     64                this.questionList.startup();
     65            },
     66            refresh: function() {
     67                this.titleNode.innerHTML = this.survey.title || "(set title in properties)";
     68                this.propertiesForm.set('value',this.survey);
     69                store.query(null,{keys:this.survey.questions,include_docs:true})
     70                .forEach(lang.hitch(this.questionList,'appendItem'));
     71            },
     72            _onShowProperties: function(evt) {
     73                this.propertiesDialog.show();
     74            },
     75            _onPropertiesOk: function(evt) {
     76                this.propertiesDialog.hide();
     77                lang.mixin(this.survey, this.propertiesForm.get('value'));
     78                this.refresh();
     79                event.stop(evt);
     80                return false;
     81            },
     82            _onPropertiesCancel: function(evt) {
     83                this.propertiesDialog.hide();
     84                this.propertiesForm.set('value',this.survey);
     85                event.stop(evt);
     86                return false;
     87            },
     88            _onSave: function(evt) {
     89                this.survey.questions = array.map(this.questionList.getItems(),function(item){
     90                    return store.getIdentity(item);
     91                });
     92                store.put(this.survey)
     93                .then(function() {
     94                    content.goTo('surveys');
     95                });
     96                event.stop(evt);
     97                return false;
     98            },
     99            _onDiscard: function(evt) {
     100            },
     101            _onShowPreview: function() {
     102                content.goTo('surveyAdvanced', {uid: store.getIdentity(this.survey)});
    78103            }
    79104        });
Note: See TracChangeset for help on using the changeset viewer.