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 moved

Legend:

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

    r378 r379  
    11define([
    22    'dojo/_base/declare',
     3    'dojo/_base/lang',
     4    'dojo/dnd/Source',
     5    'dojo/dom-construct',
     6    'dijit/_Container',
     7    'dijit/_TemplatedMixin',
    38    'dijit/_WidgetBase',
    4     'dijit/_TemplatedMixin',
    5     'dojo/_base/lang',
    6     'dojo/fx',
    7     'dojo/_base/fx',
    89    'dijit/_WidgetsInTemplateMixin',
    9     'dijit/_Container',
     10    'dijit/form/Button',
    1011    'rft/ui/LineWithActionsWidget',
    11     'dojo/text!./templates/SurveyListView.html'
     12    'dojo/text!./templates/OrderedDndList.html'
    1213    ],function(
    1314        declare,
     15        lang,
     16        Source,
     17        domConstruct,
     18        _Container,
     19        _TemplatedMixin,
    1420        _WidgetBase,
    15         _TemplatedMixin,
    16         lang,
    17         fx,
    18         baseFx,
    1921        _WidgetsInTemplateMixin,
    20         _Container,
     22        Button,
    2123        LineWithActionsWidget,
    2224        templateString
    23         ){
    24         return declare('rft.ui.SurveyListView',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{
     25    ){
     26        return declare('rft.ui.OrderedDndList',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{
    2527            templateString: templateString,
    2628            baseClass: 'rftSurveyListView',
     29            type: 'text',
    2730            source: null,
    28             region: 'center',
    2931
    3032            postCreate: function() {
     
    3537                }
    3638
    37                 this.source = new dojo.dnd.Source(this.sourceNode, {
    38                     isSource: true,
    39                     accept: ["SurveyListViewItem"],
     39                this.source = new Source(this.sourceNode, {
     40                    accept: [this.type],
    4041                    horizontal: false,
    41                     withHandles: false,
    42                     copyOnly: false,
    43                     selfCopy: false,
    44                     selfAccept: true,
    45                     delay: 0,
    4642                    singular: true,
    47                     creator: lang.hitch(this, this.creatorMethod)
     43                    creator: lang.hitch(this, this._createQuestionDndItem)
    4844                });
    4945
    50                 new dijit.form.Button({
     46                new Button({
    5147                    label: "Move up",
    5248                    showLabel: false,
     
    5551                    'class': "trans",
    5652                    onClick: lang.hitch(this, function() {
    57                         this.moveItem("up");
     53                        this._moveSelectedItem("up");
    5854                    })
    5955                }, this.btnListMoveUp);
    6056
    61                 new dijit.form.Button({
     57                new Button({
    6258                    label: "Move down",
    6359                    showLabel: false,
     
    6662                    'class': "trans",
    6763                    onClick: lang.hitch(this, function() {
    68                         this.moveItem("down");
     64                        this._moveSelectedItem("down");
    6965                    })
    7066                }, this.btnListMoveDown);
    7167            },
    72             creatorMethod: function(item, hint) {
     68            _createQuestionDndItem: function(item, hint) {
    7369                var node;
    7470
    7571                if (hint == "avatar") {
    76                     node = document.createElement("div");
    77                     node.className = "dragAvatar";
    78                     node.innerHTML = item.title;
     72                    node = domConstruct.create("div",{
     73                        'class': 'dragAvatar',
     74                        innerHTML: item.title
     75                    });
    7976                } else {
    8077                    var w = new LineWithActionsWidget({
     
    8380                        actions: {
    8481                            "Remove" : {
     82                                // w not bound in hitch, because it's
     83                                // not initialized when hitch is called.
    8584                                callback: lang.hitch(this, function(){
    86                                     this.removeItem(item, w);
     85                                    this._removeItem(w);
    8786                                }),
    8887                                properties: {
     
    107106                    node = w.domNode;
    108107                }
    109                 var fullItem = {
     108                return {
    110109                    node: node,
    111110                    data: item,
    112                     type: "SurveyListViewItem"
     111                    type: "question"
    113112                };
    114                 return fullItem;
    115113            },
    116             moveItem: function(dir) {
     114            _moveSelectedItem: function(dir) {
    117115                var node = this.source.getSelectedNodes()[0];
    118116                if (node) {
     
    142140                    this.source.insertNodes(false,[item], false, anchor);
    143141                } else {
    144                     this.source.insertNodes(false,[item]);
     142                    this.appendItem(item);
    145143                }
    146144            },
    147             removeItem: function(item,widget){
     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();
     158                });
     159                this.source.sync();
     160            },
     161            _removeItem: function(widget){
    148162                widget.destroy();
     163                this.source.sync();
    149164            }
    150165        });
    151 });
     166    });
Note: See TracChangeset for help on using the changeset viewer.