Ignore:
Timestamp:
07/29/12 00:03:52 (13 years ago)
Author:
hendrikvanantwerpen
Message:
  • Cleanup of the differen ListViews?, List & OrderedList?. Based QuestionListView? on these base classes as well. Removed duplicate code.
  • Destroy busy indicator of TabbedQuestionBrowser? (because it's placed outside of the widgets DOM tree, this is not done automatically).
  • Use dojo/date/stamp module for uniform and parsable date formatting.
  • Added docs/ directory for database format documentation etc.
File:
1 moved

Legend:

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

    r383 r384  
    22    'dojo/_base/declare',
    33    'dojo/_base/lang',
    4     'dojo/dnd/Source',
    54    'dojo/dom-construct',
    6     'dijit/_Container',
    7     'dijit/_TemplatedMixin',
    8     'dijit/_WidgetBase',
    9     'dijit/_WidgetsInTemplateMixin',
    10     'dijit/form/Button',
    115    'rft/ui/LineWithActionsWidget',
    12     'dojo/text!./templates/OrderedDndList.html'
     6    'rft/ui/OrderedList'
    137    ],function(
    148        declare,
    159        lang,
    16         Source,
    1710        domConstruct,
    18         _Container,
    19         _TemplatedMixin,
    20         _WidgetBase,
    21         _WidgetsInTemplateMixin,
    22         Button,
    2311        LineWithActionsWidget,
    24         templateString
     12        OrderedList
    2513    ){
    26         return declare('rft.ui.OrderedDndList',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{
    27             templateString: templateString,
     14        return declare('rft.ui.QuestionListView',[OrderedList],{
    2815            baseClass: 'rftSurveyListView',
    29             type: 'text',
    30             source: null,
     16            type: 'question',
    3117
    32             postCreate: function() {
    33                 if (this.title) {
    34                     this.titleNode.innerHTML = this.title;
    35                 } else {
    36                     this.domNode.removeChild(this.titleNode);
    37                 }
    38 
    39                 this.source = new Source(this.sourceNode, {
    40                     accept: [this.type],
    41                     horizontal: false,
    42                     singular: true,
    43                     creator: lang.hitch(this, this._createQuestionDndItem)
     18            _createAvatarNode: function(item){
     19                return domConstruct.create("div",{
     20                    'class': 'dragAvatar',
     21                    innerHTML: item.title
    4422                });
    45 
    46                 new Button({
    47                     label: "Move up",
    48                     showLabel: false,
    49                     iconClass: "rftIcon rftIconFullArrowUp",
    50                     baseClass: "rftBlockButton",
    51                     'class': "trans",
    52                     onClick: lang.hitch(this, function() {
    53                         this._moveSelectedItem("up");
    54                     })
    55                 }, this.btnListMoveUp);
    56 
    57                 new Button({
    58                     label: "Move down",
    59                     showLabel: false,
    60                     iconClass: "rftIcon rftIconFullArrowDown",
    61                     baseClass: "rftBlockButton",
    62                     'class': "trans",
    63                     onClick: lang.hitch(this, function() {
    64                         this._moveSelectedItem("down");
    65                     })
    66                 }, this.btnListMoveDown);
    6723            },
    68             _createQuestionDndItem: function(item, hint) {
    69                 var node;
    70 
    71                 if (hint == "avatar") {
    72                     node = domConstruct.create("div",{
    73                         'class': 'dragAvatar',
    74                         innerHTML: item.title
    75                     });
    76                 } else {
    77                     var w = new LineWithActionsWidget({
    78                         title: item.title,
    79                         'class': "inheritBgColor",
    80                         actions: {
    81                             "Remove" : {
    82                                 // w not bound in hitch, because it's
    83                                 // not initialized when hitch is called.
    84                                 callback: lang.hitch(this, function(){
    85                                     this._removeItem(w);
    86                                 }),
    87                                 properties: {
    88                                     blockButton: false,
    89                                     icon: "Delete",
    90                                     modifiers: "white",
    91                                     label: "Remove"
    92                                 }
    93                             },
    94                             "Info" : {
    95                                 callback: function(){ item.description && alert(item.description); },
    96                                 properties: {
    97                                     blockButton: false,
    98                                     icon: "Inspect",
    99                                     modifiers: "white",
    100                                     label: "Show info"
    101                                 }
     24            _createListNode: function(item) {
     25                var w = new LineWithActionsWidget({
     26                    title: item.title,
     27                    'class': "inheritBgColor",
     28                    actions: {
     29                        "Remove" : {
     30                                                callback: lang.hitch(this, 'removeItem', item),
     31                            properties: {
     32                                blockButton: false,
     33                                icon: "Delete",
     34                                modifiers: "white",
     35                                label: "Remove"
     36                            }
     37                        },
     38                        "Info" : {
     39                            callback: function(){ item.description && alert(item.description); },
     40                            properties: {
     41                                blockButton: false,
     42                                icon: "Inspect",
     43                                modifiers: "white",
     44                                label: "Show info"
    10245                            }
    10346                        }
    104                     });
    105                     w.startup();
    106                     node = w.domNode;
    107                 }
    108                 return {
    109                     node: node,
    110                     data: item,
    111                     type: "question"
    112                 };
    113             },
    114             _moveSelectedItem: function(dir) {
    115                 var node = this.source.getSelectedNodes()[0];
    116                 if (node) {
    117                     if (dir == "up") {
    118                         if (node.previousSibling) {
    119                             return node.parentNode.insertBefore(node, node.previousSibling);
    120                         } else {
    121                             return false;
    122                         }
    123 
    124                     } else if (dir == "down") {
    125                         if (node.nextSibling) {
    126                             return node.parentNode.insertBefore(node.nextSibling, node);
    127                         } else {
    128                             return false;
    129                         }
    130                     } else {
    131                         throw "Invalid move direction passed!";
    13247                    }
    133                 } else {
    134                     return false;
    135                 }
    136             },
    137             insertItem: function(item) {
    138                 var anchor = this.source.getSelectedNodes()[0];
    139                 if (anchor) {
    140                     this.source.insertNodes(false,[item], false, anchor);
    141                 } else {
    142                     this.appendItem(item);
    143                 }
    144             },
    145             appendItem: function(item) {
    146                 this.source.insertNodes(false,[item]);
    147             },
    148             getItems: function() {
    149                 return this.source.getAllNodes()
    150                 .map(function(node){
    151                     return this.source.getItem(node.id).data;
    152                 },this);
    153             },
    154             deleteItems: function() {
    155                 this.source.getAllNodes()
    156                 .forEach(function(node){
    157                     node.destroy();
    15848                });
    159                 this.source.sync();
    160             },
    161             _removeItem: function(widget){
    162                 widget.destroy();
    163                 this.source.sync();
     49                w.startup();
     50                return w.domNode;
    16451            }
    16552        });
Note: See TracChangeset for help on using the changeset viewer.