Changeset 370


Ignore:
Timestamp:
07/23/12 13:07:24 (13 years ago)
Author:
hendrikvanantwerpen
Message:

Seperated question browser in TabbedQuestionBrowser? widget.
Made configuring Selector actions more flexible (both for top actions and item actions).
Fixed lowercase/uppercase problem in SurveyListView?.
Fixed whitespace and toolyip in LineWithActionsWidget?.
Added question browser to questions page. Removed the old dialog that was there and redirect to questionEditor page.

Location:
Dev/branches/rest-dojo-ui/client/rft
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/rest-dojo-ui/client/rft/pages/questions.html

    r358 r370  
    1 <div data-dojo-type="rft.pages.questions">
    2     <h1>Questions</h1>
    3     <div data-dojo-type="dijit.form.Button" data-rft-attach-event="onClick:onNewQuestion" data-dojo-props="baseClass: 'rftLargeButton', iconClass:'rftIcon rftIconQuestion'">New question</div>
    4     <div data-rft-attach-point="list">
    5     </div>
    6     <div data-dojo-type="dijit.Dialog" title="Question" data-rft-attach-point="questionDialog">
    7         <form data-dojo-type="dijit.form.Form" data-rft-attach-point="questionForm" data-rft-attach-event="onSubmit:onSaveQuestion">
    8             <div data-dojo-type="rft.ui.QuestionWidget" data-rft-attach-point="questionWidget"></div>
    9             <div style="float: right;">
    10                 <button type="button" data-dojo-type="dijit.form.Button" data-rft-attach-event="onClick:onCancelQuestion">Cancel</button>
    11                 <button type="submit" data-dojo-type="dijit.form.Button">Save</button>
    12             </div>
    13         </form>
     1<div data-dojo-type="rft.pages.questions" class="blue">
     2    <div data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="region:'center'" style="height: 500px;">
     3
     4        <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'top'">
     5            <h2>
     6                <span class="rftIcon rftIconQuestion"></span>
     7                <span class="headerText">Questions</span>
     8            </h2>
     9        </div>
     10       
     11        <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'center'">
     12            <div data-rft-attach-point="questionBrowser"></div>
     13        </div>
     14
     15        <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'bottom'">
     16            <div data-dojo-type="dijit.form.Button" data-rft-attach-event="onClick:onNewQuestion" data-dojo-props="baseClass: 'rftLargeButton', iconClass:'rftIcon rftIconQuestion'">New question</div>
     17        </div>
     18
    1419    </div>
    1520</div>
  • Dev/branches/rest-dojo-ui/client/rft/pages/questions.js

    r366 r370  
    1 define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/event',
    2     'dojo/_base/Deferred','rft/store','rft/ui/_Page','rft/ui/AccordionList', 'rft/content'],
    3     function(declare,lang,event,Deferred,store,_Page,AccordionList,content) {
     1define([
     2    'dojo/_base/declare',
     3    'dojo/_base/Deferred',
     4    'dojo/_base/event',
     5    'dojo/_base/lang',
     6    'rft/content',
     7    'rft/store',
     8    'rft/ui/_Page',
     9    'rft/ui/TabbedQuestionBrowser'
     10    ],function(declare,Deferred,event,lang,content,store,_Page,TabbedQuestionBrowser) {
    411        return declare('rft.pages.questions',[_Page],{
    512            constructor: function() {
    613                this.inherited(arguments);
    7                 this.questions = {};
    814            },
    915            onVisit: function() {
    10                 debugger;
    11                 this._list = new AccordionList({
    12                     actions: {
     16                this.questionBrowser = new TabbedQuestionBrowser({
     17                    region: 'center',
     18                    'class': 'blue',
     19                    itemActions: {
    1320                        'Edit': {
    14                             callback: lang.hitch(this,'_editQuestion'),
    15                             properties: {
    16                                 blockButton: true,
    17                                 icon: "Edit",
    18                                 label: "Edit"
    19                             }
     21                            callback: lang.hitch(this,"onEditQuestion"),
     22                               icon: 'Edit',
     23                               description: 'Edit question'
    2024                        }
    21 
    22                        
    23                     },
    24                     idProperty: store.idProperty,
    25                     categoryProperty: 'category',
    26                     titleProperty: 'title'
    27                 },this.list);
    28                 this._list.startup();
    29                 this._refresh();
     25                    }
     26                },this.questionBrowser);
     27                this.questionBrowser.startup();
    3028            },
    3129            _refresh: function() {
     
    3836                Deferred.when(store.add({type:'Question'}))
    3937                .then(lang.hitch(this,function(question){
    40                     this._editQuestion(question);
     38                    this.onEditQuestion(question);
    4139                }));
    4240            },
    43             _editQuestion: function(question) {
     41            onEditQuestion: function(question) {
    4442                content.goTo("question", {uid: question._id});
    45                 // this.questionForm.reset();
    46                 // this.questionWidget.set('value',question);
    47                 // this.questionDialog.show();
    48             },
    49             onSaveQuestion: function(evt) {
    50                 var value = this.questionWidget.get('value');
    51                 Deferred.when(store.put(value))
    52                 .then(lang.hitch(this,function(){
    53                     this.questionDialog.hide();
    54                     this.questionForm.reset();
    55                     this._refresh();
    56                 }));
    57                 event.stop(evt);
    58                 return false;
    59             },
    60             onCancelQuestion: function() {
    61                 this.questionDialog.hide();
    62                 this.questionForm.reset();
    6343            }
    6444        });
  • Dev/branches/rest-dojo-ui/client/rft/pages/survey.html

    r369 r370  
    1010       
    1111        <div data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="region:'center'">
    12             <div data-rft-attach-point="tabList" data-dojo-type="dijit.layout.TabContainer" class="blue" data-dojo-props="tabPosition:'left-h',region:'center'">
    13                 <!-- tabs go here -->
    14             </div>
     12            <div data-rft-attach-point="questionBrowser"></div>
    1513        </div>
    1614       
     
    2119            <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region: 'bottom'">
    2220                <button data-rft-attach-point="btnProperties" data-dojo-type="dijit.form.Button" data-rft-attach-event="onClick:onProperties" data-dojo-props="baseClass: 'rftLargeButton', iconClass: 'rftIcon rftIconProperties'">Properties</button>
    23                 <button data-rft-attach-point="btnSave" data-dojo-type="dijit.form.Button" data-dojo-props="baseClass: 'rftLargeButton' data-rft-attach-event="onClick:onSave", iconClass: 'rftIcon rftIconAccept'">Save Changes</button>
     21                <button data-rft-attach-point="btnSave" data-dojo-type="dijit.form.Button" data-rft-attach-event="onClick:onSave" data-dojo-props="baseClass: 'rftLargeButton', iconClass: 'rftIcon rftIconAccept'">Save Changes</button>
    2422                <button data-rft-attach-point="btnDiscard" data-dojo-type="dijit.form.Button" data-dojo-props="baseClass: 'rftLargeButton', iconClass: 'rftIcon rftIconCancel'">Discard changes</button>
    2523                <button data-rft-attach-point="btnPreview" data-dojo-type="dijit.form.Button" data-dojo-props="baseClass: 'rftLargeButton', iconClass: 'rftIcon rftIconPreview'">Preview</button>
  • Dev/branches/rest-dojo-ui/client/rft/pages/survey.js

    r369 r370  
    1 define(['dojo/_base/declare',
     1define([
     2    'dojo/_base/declare',
     3    'dojo/_base/Deferred',
     4    'dojo/_base/event',
    25    'dojo/_base/lang',
    3     'dojo/_base/event',
    4     'dojo/_base/Deferred',
    5     'dojo/on',
    6     'rft/ui/Selector',
    7     'rft/ui/SurveyListView',
    8     'dijit/layout/ContentPane',
     6    'rft/content',
    97    'rft/store',
    108    'rft/ui/_Page',
    11     'rft/content',
    12     'dojo/store/Cache',
    13     'dojo/store/Memory' ],
    14     function(declare,lang,event,Deferred,on,Selector,SurveyListView,ContentPane,store,_Page,content,Cache,Memory){
     9    'rft/ui/SurveyListView',
     10    'rft/ui/TabbedQuestionBrowser'
     11    ],
     12    function(declare,Deferred,event,lang,content,store,_Page,SurveyListView,TabbedQuestionBrowser){
    1513        return declare('rft.pages.survey',[_Page],{
    1614            object: null,
     
    2725                        return Deferred.when( obj.creator && store.dereference(obj.creator) );
    2826                    }));
    29                     this._setupButtons();
    3027                    this._setupQuestionBrowser();
    3128                    this._setupListView();
     
    4946                content.goTo('surveyAdvanced', {uid: this.object._id});
    5047            },
    51             _setupButtons: function() {
    52                 this.btnSave.on("click", lang.hitch(this, this.onSave));
    53                 this.btnPreview.on("click", lang.hitch(this, this._goToPreview));
    54             },
    5548            _setupQuestionBrowser: function() {
    56                 this.tabList.watch("selectedChildWidget",lang.hitch(this,function(name,oldTab,newTab){
    57                     this._fillCategoryTab(newTab.__category);
    58                 }));
    59                 store.query('_design/default/_view/questions', {reduce:true,group:true,group_level:1})
    60                 .forPairs(lang.hitch(this,function(value,key){
    61                     this._createCategoryTab(key[0],value);
    62                 }));
    63             },
    64             _createCategoryTab: function(category,count) {
    65                 if (this._dataMap[category] === undefined) {
    66                     var categoryTab = new ContentPane({
    67                         __category: category,
    68                         title: category+" ("+count+")"
    69                     });
    70                     categoryTab.startup();
    71                     this._dataMap[category] = {
    72                         _widget: categoryTab
    73                     };
    74                     this.tabList.addChild(categoryTab);
    75                 }
    76             },
    77             _fillCategoryTab: function(category) {
    78                 var categoryMap = this._dataMap[category];
    79                 if (!categoryMap._filled) {
    80                     categoryMap._filled = true;
    81                     store.query('_design/default/_view/questions', {reduce:true,group:true,group_level:2,startkey:[category],endkey:[category,{}]})
    82                     .forPairs(lang.hitch(this,function(value,key){
    83                         this._createTopicSelector(key[1],category,value);
    84                     }));
    85                 }
    86             },
    87             _createTopicSelector: function(topic,category,count){
    88                 var categoryMap = this._dataMap[category];
    89                 if (categoryMap[topic] === undefined) {
    90                     var w = new Selector({
    91                         __category: category,
    92                         __topic: topic,
    93                         title: topic+" ("+count+")"
    94                     }).placeAt(categoryMap._widget.containerNode);
    95                     w.startup();
    96                     categoryMap[topic] = {
    97                         _widget: w
    98                     };
    99                     this._fillTopicSelector(topic,category);
    100                     w.on('include',lang.hitch(this,this.includeQuestion));
    101                 }
    102             },
    103             _fillTopicSelector: function(topic,category) {
    104                 var categoryMap = this._dataMap[category];
    105                 var topicMap = categoryMap[topic];
    106                 if (!topicMap._filled) {
    107                     store.query('_design/default/_view/questions', {reduce:false,include_docs:true,key:[category,topic]})
    108                     .forEach(lang.hitch(this,function(value){
    109                         topicMap._widget.addItem(value);
    110                     }));
    111                 }
     49                this.questionBrowser = new TabbedQuestionBrowser({
     50                    region: 'center',
     51                    'class': 'blue',
     52                    selectedActions: {
     53                        "Include": {
     54                            callback: lang.hitch(this,this.includeQuestion),
     55                            icon: "Accept",
     56                            description: "Include in survey"
     57                        }
     58                    },
     59                    itemActions: {
     60                        "Info": {
     61                            callback: function(item){ item.description && alert(item.description); },
     62                            icon: "Inspect",
     63                            description: "Show item description"
     64                        }
     65                    }
     66                },this.questionBrowser);
     67                this.questionBrowser.startup();
    11268            },
    11369            /* ListView code */
  • Dev/branches/rest-dojo-ui/client/rft/ui

    • Property svn:ignore set to
      .QuestionEditorPreviewItem.js.swp
  • Dev/branches/rest-dojo-ui/client/rft/ui/LineWithActionsWidget.js

    r356 r370  
    4040                                                        label: "Default",
    4141                                                        iconClass: 'rftIcon rftIcon'+this.actions[action].properties.icon,
    42                                                         title: action,
    43                                                         onClick: lang.hitch(this, dojo.partial(function(ac, e){
    44                                                                 lang.hitch(this, this.actions[ac].callback )(e);
    45                                                                 event.stop(e);
    46                                                                 return false;
    47                                                         }, action))
     42                                                        title: this.actions[action].properties.tooltip,
     43                            onClick: lang.hitch(this, function(action, e){
     44                                action.callback && action.callback(e);
     45                                event.stop(e);
     46                                return false;
     47                            }, this.actions[action])
    4848                                                }, this.actions[action].properties);
    49                                                         properties["class"] = properties.modifiers;
    50                                                         new Button(properties).placeAt(this.buttonsNode);
    51                                                 } else {
    52                                                         properties = lang.mixin({
    53                                                                 baseClass: 'rftInlineButton',
    54                                                                 modifiers: 'black',
    55                                                                 label: "Default",
    56                                                                 showLabel: false,
    57                                                                 iconClass: 'rftIcon rftIcon'+this.actions[action].properties.icon,
    58                                                                 title: action,
    59                                                                 onClick: lang.hitch(this, dojo.partial(function(ac, e){
    60                                                                         lang.hitch(this, this.actions[ac].callback)(e);
    61                                                                         event.stop(e);
    62                                                                         return false;
    63                                                                 }, action))
    64                                                         }, this.actions[action].properties);
    65                                                         properties["class"] = properties.modifiers;
    66                                                         new Button(properties).placeAt(this.buttonsNode);
    67                                                 }
    68                                         }
    69                                 },
    70                                 refresh: function() {
    71                                         this.titleNode.innerHTML = this.title;
    72                                 },
    73                                 _onClick: function(e){
    74                                         var preventDefault = this.onClick(e) === false;
    75                                         if (preventDefault) {
    76                                                 event.stop(e);
    77                                         }
    78                                         return !preventDefault;
    79                                 },
    80                                 onClick: function(e) {
    81                                 },
    82                                 _setTitleAttr: function(value){
    83                                         this.title = value;
    84                                         this.refresh();
    85                                 }
    86                         });
    87 });
     49                        properties["class"] = properties.modifiers;
     50                        new Button(properties).placeAt(this.buttonsNode);
     51                    } else {
     52                        properties = lang.mixin({
     53                            baseClass: 'rftInlineButton',
     54                            modifiers: 'black',
     55                            label: "Default",
     56                            showLabel: false,
     57                            iconClass: 'rftIcon rftIcon'+this.actions[action].properties.icon,
     58                            title: this.actions[action].properties.tooltip,
     59                            onClick: lang.hitch(this, function(action, e){
     60                                action.callback && action.callback(e);
     61                                event.stop(e);
     62                                return false;
     63                            }, this.actions[action])
     64                        }, this.actions[action].properties);
     65                        properties["class"] = properties.modifiers;
     66                        new Button(properties).placeAt(this.buttonsNode);
     67                    }
     68                }
     69            },
     70            refresh: function() {
     71                this.titleNode.innerHTML = this.title;
     72            },
     73            _onClick: function(e){
     74                var preventDefault = this.onClick(e) === false;
     75                if (preventDefault) {
     76                    event.stop(e);
     77                }
     78                return !preventDefault;
     79            },
     80            onClick: function(e) {
     81            },
     82            _setTitleAttr: function(value){
     83                this.title = value;
     84                this.refresh();
     85            }
     86        });
     87    });
  • Dev/branches/rest-dojo-ui/client/rft/ui/QuestionEditorPreviewItem.js

    r366 r370  
    88        'dijit/_TemplatedMixin',
    99        'dijit/_WidgetsInTemplateMixin',
    10         'dijit/form/Textbox',
     10        'dijit/form/TextBox',
    1111        'dojo/text!./templates/QuestionEditorPreviewItem.html',
    12         ], function(declare, fx, _WidgetBase, domClass, lang, on, _TemplatedMixin, _WidgetsInTemplateMixin, Textbox, templateFull) {
     12        ], function(declare, fx, _WidgetBase, domClass, lang, on, _TemplatedMixin, _WidgetsInTemplateMixin, TextBox, templateFull) {
    1313                return declare("rft.ui.QuestionEditorPreviewItem", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
    1414
     
    7070                                switch (this.item.widgetType) {
    7171                                        default:
    72                                         this.innerWidget = new Textbox();
     72                                        this.innerWidget = new TextBox();
    7373                                        break;
    7474                                }
  • Dev/branches/rest-dojo-ui/client/rft/ui/Selector.js

    r364 r370  
    3030        return declare('rft.ui.Selector',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{
    3131            templateString: templateString,
    32             title: "",
    3332            baseClass: 'rftSelector',
    3433            modifiers: 'blue',
     34
     35            title: "",
     36            selectedActions: null,
     37            itemActions: null,
     38            // main selector action: Object
     39            //    title:
     40            //    description:
     41            //    icon:
     42
    3543            _folded: true,
    3644            _titleLine: null,
     
    4250                domClass.add(this.selectedColorNode, "pending");
    4351
     52                this._createTitleLine();
     53                this._createSelectorLine();
     54
     55                fx.wipeOut({
     56                    node: this.optionsNode
     57                }).play();
     58            },
     59            _createTitleLine: function() {
     60                var actions = {};
     61                var action = null;
     62                if ( this.selectedActions !== null ) {
     63                    for (var actionName in this.selectedActions) {
     64                        action = this.selectedActions[actionName];
     65                        actions[actionName] = {
     66                            callback: action.callback &&
     67                                    lang.hitch(this,this._onSelectedAction,
     68                                            action.callback),
     69                            properties: {
     70                                 blockButton: true,
     71                                 modifiers: this.modifiers,
     72                                 label: action.title || actionName,
     73                                 icon: action.icon,
     74                                 tooltip: action.description
     75                             }
     76
     77                        };
     78                    }
     79                }
     80
    4481                this._titleLine = new LineWithActionsWidget({
    4582                    title: this.title,
    4683                    modifiers: this.modifiers,
    47                     actions: {
    48                         "Include in survey" : {
    49                             callback: lang.hitch(this, this._onInclude),
    50                             properties: {
    51                                 blockButton: true,
    52                                 modifiers: this.modifiers,
    53                                 icon: "Accept",
    54                                 label: "Include"
    55                             }
    56                         }
    57                     }
     84                    actions: actions
    5885                },this.titleNode);
    5986                this._titleLine.startup();
    60 
     87            },
     88            _createSelectorLine: function() {
    6189                this._selectorLine = new LineWithActionsWidget({
    6290                    title: 'None',
     
    76104                this._selectorLine.startup();
    77105                this._selectorLine.on('click',lang.hitch(this, this.onToggle));
    78 
    79                 fx.wipeOut({
    80                     node: this.optionsNode
    81                 }).play();
    82106            },
    83107            _onSelect: function(item, widget) {
     
    97121                this.onSelect(item);
    98122            },
    99             _onInclude: function() {
    100                 if (this._selectedItem) {
    101                     this.onInclude(this._selectedItem);
     123            _onSelectedAction: function(callback) {
     124                if (this._selectedItem && callback) {
     125                    callback(this._selectedItem);
    102126                }
    103127            },
     
    126150                return false;
    127151            },
     152
    128153            addItem: function(item) {
    129                 var w = new LineWithActionsWidget({
    130                     title: item.title,
    131                     actions: {
    132                         "Info" : {
    133                             callback: function() {
    134                                 item.description && alert(item.description);
    135                             },
     154                var actions = {};
     155                var action;
     156                if (this.itemActions) {
     157                    for (var actionName in this.itemActions) {
     158                        action = this.itemActions[actionName];
     159                        actions[actionName] = {
     160                            callback: function(){action.callback && action.callback(item);},
    136161                            properties: {
    137162                                blockButton: false,
    138163                                showLabel: false,
    139                                 icon: "Inspect"
     164                                icon: action.icon,
     165                                tooltip: action.description
    140166                            }
    141167                        }
    142168                    }
     169                }
     170                var w = new LineWithActionsWidget({
     171                    title: item.title,
     172                    actions: actions
    143173                }).placeAt(this.optionsNode);
    144174                w.startup();
    145175                w.on("click", lang.hitch(this, this._onSelect, item, w));
    146176            },
    147             onSelect: function(item) {},
    148             onInclude: function(item) {}
     177
     178            onSelect: function(item) {}
    149179        });
    150180});
  • Dev/branches/rest-dojo-ui/client/rft/ui/SurveyListView.js

    r360 r370  
    110110                    node: node,
    111111                    data: item,
    112                     type: "SurveyListviewItem"
     112                    type: "SurveyListViewItem"
    113113                };
    114114                return fullItem;
Note: See TracChangeset for help on using the changeset viewer.