Ignore:
Timestamp:
07/13/12 15:13:46 (13 years ago)
Author:
hendrikvanantwerpen
Message:

Removed controller dependency of Selector and SurveyList?.
Selector emits events now. No id's are used, pass objects around.
Fixed selector wipe in/out confusion for first click.
Read questions from db, no mockup data used anymore in survey page.
Added some sample question to db config, because they cannot be created yet.

Location:
Dev/branches/rest-dojo-ui/client
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/rest-dojo-ui/client

    • Property svn:ignore set to

  • Dev/branches/rest-dojo-ui/client/rft/ui/SurveyListView.js

    r358 r360  
    11define([
    2         'dojo/_base/declare',
    3         'dijit/_WidgetBase',
    4         'dijit/_TemplatedMixin',
    5         'dojo/_base/lang',
    6         'dojo/fx',
    7         'dojo/_base/fx',
    8         'dijit/_WidgetsInTemplateMixin',
    9         'dijit/_Container',
    10         'rft/ui/LineWithActionsWidget',
    11         'dojo/text!./templates/SurveyListView.html'
    12         ],function(
    13                 declare,
    14                 _WidgetBase,
    15                 _TemplatedMixin,
    16                 lang,
    17                 fx,
    18                 baseFx,
    19                 _WidgetsInTemplateMixin,
    20                 _Container,
    21                 LineWithActionsWidget,
    22                 templateString
    23                 ){
    24                 return declare('rft.ui.SurveyListView',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{
    25                         templateString: templateString,
    26                         baseClass: 'rftSurveyListView',
    27                         source: null,
    28                         controller: null,
    29                         region: 'center',
     2    'dojo/_base/declare',
     3    'dijit/_WidgetBase',
     4    'dijit/_TemplatedMixin',
     5    'dojo/_base/lang',
     6    'dojo/fx',
     7    'dojo/_base/fx',
     8    'dijit/_WidgetsInTemplateMixin',
     9    'dijit/_Container',
     10    'rft/ui/LineWithActionsWidget',
     11    'dojo/text!./templates/SurveyListView.html'
     12    ],function(
     13        declare,
     14        _WidgetBase,
     15        _TemplatedMixin,
     16        lang,
     17        fx,
     18        baseFx,
     19        _WidgetsInTemplateMixin,
     20        _Container,
     21        LineWithActionsWidget,
     22        templateString
     23        ){
     24        return declare('rft.ui.SurveyListView',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{
     25            templateString: templateString,
     26            baseClass: 'rftSurveyListView',
     27            source: null,
     28            region: 'center',
    3029
    31                         postCreate: function() {
    32                                 if (this.title) {
    33                                         this.titleNode.innerHTML = this.title;
    34                                 } else {
    35                                         this.domNode.removeChild(this.titleNode);
    36                                 }
     30            postCreate: function() {
     31                if (this.title) {
     32                    this.titleNode.innerHTML = this.title;
     33                } else {
     34                    this.domNode.removeChild(this.titleNode);
     35                }
    3736
    38                                 this.source = new dojo.dnd.Source(this.sourceNode, {
    39                                         isSource: true,
    40                                         accept: ["SurveyListViewItem"],
    41                                         horizontal: false,
    42                                         withHandles: false,
    43                                         copyOnly: false,
    44                                         selfCopy: false,
    45                                         selfAccept: true,
    46                                         delay: 0,
    47                                         singular: true,
    48                                         creator: dojo.partial(this.creatorMethod, this.controller, this)
    49                                 });
     37                this.source = new dojo.dnd.Source(this.sourceNode, {
     38                    isSource: true,
     39                    accept: ["SurveyListViewItem"],
     40                    horizontal: false,
     41                    withHandles: false,
     42                    copyOnly: false,
     43                    selfCopy: false,
     44                    selfAccept: true,
     45                    delay: 0,
     46                    singular: true,
     47                    creator: lang.hitch(this, this.creatorMethod)
     48                });
    5049
    51                                 new dijit.form.Button({
    52                                         label: "Move up",
    53                                         showLabel: false,
    54                                         iconClass: "rftIcon rftIconFullArrowUp",
    55                                         baseClass: "rftBlockButton",
    56                                         class: "trans",
    57                                         onClick: lang.hitch(this, function() {
    58                                                 this.moveItem("up");
    59                                         })
    60                                 }, this.btnListMoveUp);
     50                new dijit.form.Button({
     51                    label: "Move up",
     52                    showLabel: false,
     53                    iconClass: "rftIcon rftIconFullArrowUp",
     54                    baseClass: "rftBlockButton",
     55                    'class': "trans",
     56                    onClick: lang.hitch(this, function() {
     57                        this.moveItem("up");
     58                    })
     59                }, this.btnListMoveUp);
    6160
    62                                 new dijit.form.Button({
    63                                         label: "Move down",
    64                                         showLabel: false,
    65                                         iconClass: "rftIcon rftIconFullArrowDown",
    66                                         baseClass: "rftBlockButton",
    67                                         class: "trans",
    68                                         onClick: lang.hitch(this, function() {
    69                                                 this.moveItem("down");
    70                                         })
    71                                 }, this.btnListMoveDown);
    72                         },
    73                         creatorMethod: function(controller, listView, item, hint) {
    74                                 var node,
    75                                 object = controller.getQuestion(item);
    76                                 if (!object) {
    77                                         return false;
    78                                 }
     61                new dijit.form.Button({
     62                    label: "Move down",
     63                    showLabel: false,
     64                    iconClass: "rftIcon rftIconFullArrowDown",
     65                    baseClass: "rftBlockButton",
     66                    'class': "trans",
     67                    onClick: lang.hitch(this, function() {
     68                        this.moveItem("down");
     69                    })
     70                }, this.btnListMoveDown);
     71            },
     72            creatorMethod: function(item, hint) {
     73                var node;
    7974
    80                                 if (hint == "avatar") {
    81                                         node = document.createElement("div");
    82                                         node.className = "dragAvatar";
    83                                         node.innerHTML = object.title;
    84                                 } else {
    85                                         var w = new LineWithActionsWidget({
    86                                                 title: object.title,
    87                                                 class: "inheritBgColor",
    88                                                 actions: {
    89                                                         "Remove" : {
    90                                                                 callback: lang.hitch(listView, function(evt){
    91                                                                         this.removeItem(evt);
    92                                                                 }),
    93                                                                 properties: {
    94                                                                         blockButton: false,
    95                                                                         icon: "Delete",
    96                                                                         modifiers: "white",
    97                                                                         label: "Remove"
    98                                                                 }
    99                                                         },
    100                                                         "Info" : {
    101                                                                 callback: function(){
    102                                                                         var question = controller.getQuestion(item);
    103                                                                         console.log(question);
    104                                                                         alert("info goes here yo!");
    105                                                                 },
    106                                                                 properties: {
    107                                                                         blockButton: false,
    108                                                                         icon: "Inspect",
    109                                                                         modifiers: "white",
    110                                                                         label: "Show info"
    111                                                                 }
    112                                                         }
    113                                                 }
    114                                         });
    115                                         w.startup();
    116                                         node = w.domNode;
    117                                 }
    118                                 var fullItem = {node: node, data: item, type: "SurveyListviewItem"}
    119                                 return fullItem;
    120                         },
    121                         moveItem: function(dir) {
    122                                 var node = this.source.getSelectedNodes()[0];
    123                                 if (node) {
    124                                         if (dir == "up") {
    125                                                 if (node.previousSibling) {
    126                                                         return node.parentNode.insertBefore(node, node.previousSibling);
    127                                                 } else {
    128                                                         return false;
    129                                                 }
     75                if (hint == "avatar") {
     76                    node = document.createElement("div");
     77                    node.className = "dragAvatar";
     78                    node.innerHTML = item.title;
     79                } else {
     80                    var w = new LineWithActionsWidget({
     81                        title: item.title,
     82                        'class': "inheritBgColor",
     83                        actions: {
     84                            "Remove" : {
     85                                callback: lang.hitch(this, function(){
     86                                    this.removeItem(item, w);
     87                                }),
     88                                properties: {
     89                                    blockButton: false,
     90                                    icon: "Delete",
     91                                    modifiers: "white",
     92                                    label: "Remove"
     93                                }
     94                            },
     95                            "Info" : {
     96                                callback: function(){ item.description && alert(item.description); },
     97                                properties: {
     98                                    blockButton: false,
     99                                    icon: "Inspect",
     100                                    modifiers: "white",
     101                                    label: "Show info"
     102                                }
     103                            }
     104                        }
     105                    });
     106                    w.startup();
     107                    node = w.domNode;
     108                }
     109                var fullItem = {
     110                    node: node,
     111                    data: item,
     112                    type: "SurveyListviewItem"
     113                };
     114                return fullItem;
     115            },
     116            moveItem: function(dir) {
     117                var node = this.source.getSelectedNodes()[0];
     118                if (node) {
     119                    if (dir == "up") {
     120                        if (node.previousSibling) {
     121                            return node.parentNode.insertBefore(node, node.previousSibling);
     122                        } else {
     123                            return false;
     124                        }
    130125
    131                                         } else if (dir == "down") {
    132                                                 if (node.nextSibling) {
    133                                                         return node.parentNode.insertBefore(node.nextSibling, node);
    134                                                 } else {
    135                                                         return false;
    136                                                 }
    137                                         } else {
    138                                                 throw "Invalid move direction passed!";
    139                                         }
    140                                 } else {
    141                                         return false;
    142                                 }
    143                         },
    144                         insertItem: function(objectId) {
    145                                 var anchor = this.source.getSelectedNodes()[0];
    146                                 if (anchor) {
    147                                         this.source.insertNodes(false, [objectId], false, anchor);
    148                                 } else {
    149                                         this.source.insertNodes(false, [objectId]);
    150                                 }
    151                         },
    152                         removeItem: function(evt){
    153                                 debugger;
    154                         }
    155                 });
     126                    } else if (dir == "down") {
     127                        if (node.nextSibling) {
     128                            return node.parentNode.insertBefore(node.nextSibling, node);
     129                        } else {
     130                            return false;
     131                        }
     132                    } else {
     133                        throw "Invalid move direction passed!";
     134                    }
     135                } else {
     136                    return false;
     137                }
     138            },
     139            insertItem: function(item) {
     140                var anchor = this.source.getSelectedNodes()[0];
     141                if (anchor) {
     142                    this.source.insertNodes(false,[item], false, anchor);
     143                } else {
     144                    this.source.insertNodes(false,[item]);
     145                }
     146            },
     147            removeItem: function(item,widget){
     148                widget.destroy();
     149            }
     150        });
    156151});
Note: See TracChangeset for help on using the changeset viewer.