Changeset 384


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.
Location:
Dev/branches/rest-dojo-ui
Files:
2 added
2 deleted
12 edited
1 moved

Legend:

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

    r382 r384  
    77    ],function(declare, json, lang, xhr, QueryReadStore) {
    88
    9         return declare("rft.elastic.ElasticReadStore", QueryReadStore, {
    10             fetch:function(request){
    11                 var attr = Object.keys(request.query)[0];
    12                 if (request.query[attr].length == 0) {
    13                         return 0;
    14                 }
    15                 var q = request.query[attr];
     9    return declare("rft.elastic.ElasticReadStore", QueryReadStore, {
     10        fetch:function(request){
     11            var attr = Object.keys(request.query)[0];
     12            if (request.query[attr].length == 0) {
     13                return 0;
     14            }
     15            var q = request.query[attr];
    1616
    17                 request.serverQuery = json.toJson({
    18                                                                 query:
    19                                                                 {
    20                                                                         query_string:
    21                                                                         {
    22                                                                                 default_field: attr,
    23                                                                                 query: q
    24                                                                         }
    25                                                                 }
    26                                                         });
    27                     // Call superclasses' fetch
    28                     return this.inherited("fetch", arguments);
    29                   },
    30                 _fetchItems: function(request, fetchHandler, errorHandler){
    31                         var serverQuery = request.serverQuery;
    32                         var xhrHandler = xhr.post({
     17            request.serverQuery = json.toJson({
     18                query: {
     19                    query_string: {
     20                        default_field: attr,
     21                        query: q
     22                    }
     23                }
     24            });
     25            return this.inherited(arguments);
     26          },
     27        _fetchItems: function(request, fetchHandler, errorHandler){
     28            var serverQuery = request.serverQuery;
     29            var xhrHandler = xhr.post({
    3330                url: this.url,
    3431                handleAs: "json",
    3532                postData: serverQuery
     33            }).then(lang.hitch(this, function(data){
     34                this._xhrFetchHandler(data, request, fetchHandler, errorHandler);
     35            }),function(error){
     36                errorHandler(error, request);
    3637            });
    37                         request.abort = function(){
    38                                 xhrHandler.cancel();
    39                         };
    40                         xhrHandler.addCallback(lang.hitch(this, function(data){
    41                                 this._xhrFetchHandler(data, request, fetchHandler, errorHandler);
    42                         }));
    43                         xhrHandler.addErrback(function(error){
    44                                 errorHandler(error, request);
    45                         });
    46                 },
    47                 _xhrFetchHandler: function(data, request, fetchHandler, errorHandler) {
    48                         data = this._filterResponse(data);
    49                         this._items = [];
    50                         var numHits = data.hits.total || -1;
    51                         if(numHits > 0) {
    52                                 this._items.push({i:data.hits.hits[0]._source, r:this, n:0});
    53                         }
    54                         fetchHandler(this._items, request, data.hits.total);
    55                         this._numRows = data.hits.total;
    56                 }
    57         });
     38            request.abort = function(){
     39                xhrHandler.cancel();
     40            };
     41        },
     42        _xhrFetchHandler: function(data, request, fetchHandler, errorHandler) {
     43            data = this._filterResponse(data);
     44            this._items = [];
     45            var numHits = data.hits.total || -1;
     46            if(numHits > 0) {
     47                this._items.push({i:data.hits.hits[0]._source, r:this, n:0});
     48            }
     49            fetchHandler(this._items, request, data.hits.total);
     50            this._numRows = data.hits.total;
     51        }
     52    });
    5853})
  • Dev/branches/rest-dojo-ui/client/rft/pages/session.html

    r374 r384  
    1414                        <h3>Basic</h3>
    1515                        <fieldset class="align">
    16                             <label for="titleInput">Title</label>
     16                            <label for="title">Title</label>
    1717                            <input type="text" name="title" data-dojo-type="dijit.form.TextBox" data-dojo-props="placeHolder: 'Enter title here'" />
    1818                            <br/>
    19                             <label for="descriptionInput">Description</label>
     19                            <label for="description">Description</label>
    2020                            <textarea name="description" rows="3" cols="54" data-dojo-type="dijit.form.SimpleTextarea" data-dojo-props="selectOnClick: true, placeHolder: 'Description shown in tooltips'"></textarea>
    2121                            <br/>
    22                             <label for="dateInput">Planned date</label>
     22                            <label for="plannedDate">Planned date</label>
    2323                            <input type="text" name="plannedDate" data-dojo-type="dijit.form.DateTextBox" required="required" />
    2424                        </fieldset>
     
    2626                        <h3>Accounts</h3>
    2727                        <fieldset class="align">
    28                             <label for="accountsInput">Add new</label>
    29                             <select id="accountBox"></select>
     28                            <label for="accountSelector">Add new</label>
     29                            <select data-rft-attach-point="accountSelector"></select>
    3030                            <button data-rft-attach-point="btnInvite" data-dojo-type="dijit.form.Button" data-rft-attach-event="onClick:onInvite" data-dojo-props="baseClass: 'rftBlockButton', class: 'green', iconClass: 'rftIcon rftIconPlus'">Invite</button>
    3131                            <br/><br/>
    3232                           
    33                             <div data-rft-attach-point="listViewNode" class="rftAccountListView">
     33                            <div data-rft-attach-point="accountListNode" class="rftAccountListView">
    3434                            </div>
    3535                        </fieldset>
    3636
    37                         <button data-rft-attach-point="btnPropertiesDiscard" data-dojo-type="dijit.form.Button" data-rft-attach-event="onClick:onDiscard" data-dojo-props="baseClass: 'rftLargeButton', iconClass: 'rftIcon rftIconCancel'">Discard changes</button>
    38                         <button data-rft-attach-point="btnPropertiesSave" data-dojo-type="dijit.form.Button" data-rft-attach-event="onClick:onSave" data-dojo-props="baseClass: 'rftLargeButton', iconClass: 'rftIcon rftIconAccept'">Save changes</button>
     37                        <button data-dojo-type="dijit.form.Button" data-rft-attach-event="onClick:onDiscard" data-dojo-props="baseClass: 'rftLargeButton', iconClass: 'rftIcon rftIconCancel'">Discard changes</button>
     38                        <button data-dojo-type="dijit.form.Button" data-rft-attach-event="onClick:onSave" data-dojo-props="baseClass: 'rftLargeButton', iconClass: 'rftIcon rftIconAccept'">Save changes</button>
    3939
    4040                    </div>
     
    4242                </div>
    4343                <div data-dojo-type="dijit.layout.ContentPane" title="Design">
    44                     <!--DESIGN-->
    45 
    4644                    <div class="rftSessionObject green">
    4745                        <div class="rftIcon rftIconSurvey"></div>
  • Dev/branches/rest-dojo-ui/client/rft/pages/session.js

    r374 r384  
    1 define(['dojo/_base/declare',
    2         'dojo/_base/lang',
    3         'dojo/_base/event',
    4         'dojo/_base/Deferred',
     1define([
     2    'dojo/_base/array',
     3    'dojo/_base/declare',
     4    'dojo/_base/lang',
     5    'dojo/_base/event',
     6    'dojo/_base/Deferred',
    57    'rft/elastic/ElasticSearchFilteringSelect',
    68    'rft/elastic/ElasticReadStore',
    7         'rft/store',
    8         'rft/ui/_Page',
    9         'rft/content',
     9    'rft/store',
     10    'rft/ui/_Page',
     11    'rft/content',
    1012    'rft/ui/AccountListView'
    1113    ],
    12         function(declare,lang,event,Deferred,ElasticSearchFilteringSelect,ElasticReadStore,store,_Page,content,AccountListView){
    13                 return declare('rft.pages.session',[_Page],{
    14                         session: null,
    15                         _listView: null,
     14    function(array,declare,lang,event,Deferred,ElasticSearchFilteringSelect,ElasticReadStore,store,_Page,content,AccountListView){
     15        return declare('rft.pages.session',[_Page],{
     16            session: null,
     17            _accountList: null,
    1618            _select: null,
    17                         onVisit: function() {
    18                                 if ( this.pageArgs.uid ) {
    19                                         Deferred.when(store.get(this.pageArgs.uid))
    20                                         .then(lang.hitch(this,function(obj){
    21                                                 this.session = obj;
    22                         this._setupListView();
     19            onVisit: function() {
     20                if ( this.pageArgs.uid ) {
     21                    Deferred.when(store.get(this.pageArgs.uid))
     22                    .then(lang.hitch(this,function(obj){
     23                        this.session = obj;
     24                        this._setupAccountList();
    2325                        this._refresh();
    24                                         }));
     26                    }));
    2527                    this._setupAutoComplete();
    26                                 } else {
    27                                         throw "No valid uid or session passed!";
    28                                 }
    29                         },
    30                         onLeave: function() {
    31                                 this.inherited(arguments);
    32                         },
     28                } else {
     29                    throw "No valid uid or session passed!";
     30                }
     31            },
    3332            _refresh: function() {
    3433                this.titleNode.innerHTML = this.session.title || '';
     
    4140            onSave: function(evt) {
    4241                lang.mixin(this.session,this.propertiesForm.get('value'));
     42                this.session.accounts = array.map(this._accountList.getItems(),function(item){
     43                    return store.getIdentity(item);
     44                });
    4345                store.put(this.session)
    4446                .then(function(){
     
    5557            },
    5658            _addAccount: function(item) {
    57                 if (!this.session.accounts)
    58                     this.session.accounts = [];
    59                 this.session.accounts.push(item);
    60                 this._listView.insertItem(item);
     59                this._accountList.insertItem(item);
    6160            },
    62             _removeAccount: function(item) {
    63                 this.session.accounts.splice(this.session.accounts.indexOf(item), 1);
    64             },
    65             _setupListView: function() {
    66                 this._listView = new AccountListView( {
    67                     controller: this,
    68                     removeCallback: lang.hitch(this, this._removeAccount)
    69                 }).placeAt(this.listViewNode);
    70                 for (account in this.session.accounts) {
    71                     this._listView.insertItem(this.session.accounts[account]);
     61            _setupAccountList: function() {
     62                this._accountList = new AccountListView().placeAt(this.accountListNode);
     63                this._accountList.startup();
     64                for (var account in this.session.accounts) {
     65                    this._accountList.insertItem(this.session.accounts[account]);
    7266                }
    73 
    74                 this._listView.startup();
    7567            },
    7668            _setupAutoComplete: function() {
    77 
    7869                var accountStore = new ElasticReadStore({
    7970                    url: "http://localhost:9200/rft/_search",
     
    8172                });
    8273                this._select = new ElasticSearchFilteringSelect({
    83                     name: "accountBox",
    8474                    store: accountStore,
    8575                    autoComplete: false,
     
    9080                    hasDownArrow: false,
    9181                    style: "width: 400",
    92                     searchAttr: "title",
    93                     id: "accountText"
    94                 }, "accountBox");
     82                    searchAttr: "title"
     83                }, this.accountSelector);
    9584                this._select.startup();
    9685            }
    9786
    9887
    99                 });
    100 });
     88        });
     89    });
    10190
  • Dev/branches/rest-dojo-ui/client/rft/pages/sessions.js

    r359 r384  
    1 define(['dojo/_base/declare','dojo/_base/lang','rft/store','rft/content','rft/ui/_Page','rft/ui/ObjectBox'],
    2     function(declare,lang,store,content,_Page,ObjectBox){
     1define([
     2    'dojo/_base/declare',
     3    'dojo/_base/lang',
     4    'dojo/date/stamp',
     5    'rft/store',
     6    'rft/content',
     7    'rft/ui/_Page',
     8    'rft/ui/ObjectBox'],
     9    function(declare,lang,dateStamp,store,content,_Page,ObjectBox){
    310        return declare('rft.pages.sessions',[_Page],{
    411            templateActions: null,
     
    5562            },
    5663            _publishSession: function(sessionTemplate) {
    57                 var publishDate = new Date();
    5864                var session = lang.clone(sessionTemplate);
    5965                delete session[store.idProperty];
    6066                delete session[store.revProperty];
    6167                session.type = "SessionInstance";
    62                 session.date = publishDate.getDate()+"-"+publishDate.getMonth()+"-"+publishDate.getFullYear();
     68                session.publishedDate = dateStamp.toISOString(new Date(),{zulu: true});
    6369                session.creator = "Igor Mayer";
    6470                store.add(session)
  • Dev/branches/rest-dojo-ui/client/rft/pages/survey.js

    r379 r384  
    88    'rft/store',
    99    'rft/ui/_Page',
    10     'rft/ui/OrderedDndList',
     10    'rft/ui/QuestionListView',
    1111    'rft/ui/TabbedQuestionBrowser'
    1212    ],
    1313    function(array,declare,Deferred,event,lang,content,store,_Page,
    14              OrderedDndList,TabbedQuestionBrowser){
     14             QuestionListView,TabbedQuestionBrowser){
    1515        return declare('rft.pages.survey',[_Page],{
    1616            survey: null,
     
    5858            },
    5959            _setupListView: function() {
    60                 this.questionList = new OrderedDndList({
    61                     type: 'question',
     60                this.questionList = new QuestionListView({
    6261                    region: 'center'
    6362                }).placeAt(this.surveyListViewNode);
  • Dev/branches/rest-dojo-ui/client/rft/ui/AccountListView.js

    r374 r384  
    22    'dojo/_base/declare',
    33        'dojo/_base/lang',
    4     'dijit/_WidgetBase',
    5     'dijit/_TemplatedMixin',
    6     'dijit/_WidgetsInTemplateMixin',
    7     'dijit/_Container',
     4    'dojo/dom-construct',
    85    'rft/ui/LineWithActionsWidget',
    9     'rft/ui/OrderedList',
    10     'dojo/text!./templates/AccountListView.html'
     6    'rft/ui/OrderedList'
    117        ],function(
    128        declare,
    139        lang,
    14         _WidgetBase,
    15         _TemplatedMixin,
    16         _WidgetsInTemplateMixin,
    17         _Container,
     10        domConstruct,
    1811        LineWithActionsWidget,
    19         OrderedList,
    20         templateString
     12        OrderedList
    2113                ) {
    22         return declare('rft.ui.AccountListView',[OrderedList,_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{
    23             templateString: templateString,
     14        return declare('rft.ui.AccountListView',[OrderedList],{
    2415            baseClass: 'rftAccountListView',
    25             region: 'center',
     16            type: 'account',
    2617
    27             creatorMethod: function(item, hint) {
    28                 var node;
    29 
    30                 if (hint == "avatar") {
    31                         node = document.createElement("div");
    32                         node.className = "dragAvatar";
    33                         node.innerHTML = item.title;
    34                 } else {
    35                         var w = new LineWithActionsWidget({
    36                                 title: item.title,
    37                                 'class': "green",
    38                                 actions: {
    39                                         "Remove" : {
    40                                                 callback: lang.hitch(this, function() {
    41                                                         this.removeItem(item, w);
    42                                                 }),
    43                                                 properties: {
    44                                                         blockButton: false,
    45                                                         icon: "Delete",
    46                                                         modifiers: "white"
    47                                                 }
    48                                         }
    49                                 }
    50                         });
    51                         w.startup();
    52                         node = w.domNode;
    53                 }
    54                 var fullItem = {
    55                         node: node,
    56                         data: item,
    57                         type: "ListViewItem"
    58                 };
    59                 return fullItem;
     18            _createAvatarNode: function(item){
     19                return domConstruct.create("div",{
     20                    'class': 'dragAvatar',
     21                    innerHTML: item.title
     22                });
     23            },
     24            _createListNode: function(item) {
     25                        var w = new LineWithActionsWidget({
     26                                title: item.title,
     27                                'class': "green",
     28                                actions: {
     29                                        "Remove" : {
     30                                                callback: lang.hitch(this, 'removeItem', item),
     31                                                properties: {
     32                                                        blockButton: false,
     33                                                        icon: "Delete",
     34                                                        modifiers: "white"
     35                                                }
     36                                        }
     37                                }
     38                        });
     39                        w.startup();
     40                        return w.domNode;
    6041                }
    61 
    62            
    63 
    6442        });
    65 });
     43    });
  • Dev/branches/rest-dojo-ui/client/rft/ui/CategoryListView.js

    r374 r384  
    22    'dojo/_base/declare',
    33    'dojo/_base/lang',
    4     'dijit/_WidgetBase',
    5     'dijit/_TemplatedMixin',
    6     'dijit/_WidgetsInTemplateMixin',
    7     'dijit/_Container',
    84    'rft/ui/LineWithActionsWidget',
    95    'rft/ui/List',
    10     'dojo/text!./templates/List.html'
    116    ],function(
    127        declare,
    138        lang,
    14         _WidgetBase,
    15         _TemplatedMixin,
    16         _WidgetsInTemplateMixin,
    17         _Container,
    189        LineWithActionsWidget,
    19         List,
    20         templateString
     10        List
    2111        ) {
    22         return declare('rft.ui.CategoryListView',[List,_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{
    23             templateString: templateString,
     12        return declare('rft.ui.CategoryListView',[List],{
    2413            baseClass: 'rftLineListView',
    25             region: 'center',
    2614
    27             creatorMethod: function(item, hint) {
    28                 var node;
     15            _createAvatarNode: function(item) {
     16                var node = document.createElement("div");
     17                node.className = "dragAvatar";
     18                node.innerHTML = item.title;
     19                return node;
     20            },
    2921
    30                 if (hint == "avatar") {
    31                     node = document.createElement("div");
    32                     node.className = "dragAvatar";
    33                     node.innerHTML = item.title;
    34                 } else {
    35                     var w = new LineWithActionsWidget({
    36                         title: item,
    37                         'class': "orange",
    38                         actions: {
    39                             "Remove" : {
    40                                 callback: lang.hitch(this, function() {
    41                                     this.removeItem(item, w);
    42                                 }),
    43                                 properties: {
    44                                     blockButton: false,
    45                                     icon: "Delete",
    46                                     modifiers: "white"
    47                                 }
     22            _createListNode: function(item) {
     23                var w = new LineWithActionsWidget({
     24                    title: item,
     25                    'class': "orange",
     26                    actions: {
     27                        "Remove" : {
     28                            callback: lang.hitch(this, function() {
     29                                this.removeItem(item, w);
     30                            }),
     31                            properties: {
     32                                blockButton: false,
     33                                icon: "Delete",
     34                                modifiers: "white"
    4835                            }
    4936                        }
    50                     });
    51                     w.startup();
    52                     node = w.domNode;
    53                 }
    54                 var fullItem = {
    55                     node: node,
    56                     data: item,
    57                     type: "ListViewItem"
    58                 };
    59                 return fullItem;
     37                    }
     38                });
     39                w.startup();
     40                return w.domNode;
    6041            }
     42
    6143        });
    62 });
     44    });
  • Dev/branches/rest-dojo-ui/client/rft/ui/List.js

    r374 r384  
    22    'dojo/_base/declare',
    33    'dojo/_base/lang',
     4    'dojo/dnd/Source',
     5    'dijit/_Container',
     6    'dijit/_TemplatedMixin',
    47    'dijit/_WidgetBase',
    5     'dijit/_TemplatedMixin',
    68    'dijit/_WidgetsInTemplateMixin',
    7     'dijit/_Container',
    8     'rft/ui/LineWithActionsWidget',
     9    'dijit/registry',
    910    'dojo/text!./templates/List.html'
    1011    ],function(
    1112        declare,
    1213        lang,
     14        Source,
     15        _Container,
     16        _TemplatedMixin,
    1317        _WidgetBase,
    14         _TemplatedMixin,
    1518        _WidgetsInTemplateMixin,
    16         _Container,
    17         LineWithActionsWidget,
     19        registry,
    1820        templateString
    1921        ){
     
    2224            baseClass: 'rftList',
    2325            removeCallback: null,
    24             creator: null,
    25 
    26             constructor: function() {
    27                 lang.mixin(this, arguments);
    28             },
     26            type: 'text',
     27            source: null,
    2928
    3029            postCreate: function() {
     
    3534                }
    3635
    37                 this.source = new dojo.dnd.Source(this.sourceNode, {
    38                     isSource: false,
    39                     accept: ["LineListViewItem"],
     36                this.source = new Source(this.sourceNode, {
     37                    accept: [this.type],
    4038                    horizontal: false,
    41                     withHandles: false,
    42                     selfCopy: false,
    43                     selfAccept: true,
    44                     delay: 0,
    4539                    singular: true,
    46                     creator: lang.hitch(this, this.creatorMethod)
    47                 })
     40                    creator: lang.hitch(this, this._createNode)
     41                });
    4842            },
    4943
    50             removeItem: function(item, widget) {
    51                 widget.destroy();
    52                 if(this.removeCallback)
    53                     this.removeCallback(item);
     44            _createNode: function(item, hint) {
     45                var node = hint === "avatar" ?
     46                        this._createAvatarNode(item) : this._createListNode(item);
     47                return {
     48                    node: node,
     49                    data: item,
     50                    type: this.type
     51                };
     52            },
     53            _createListNode: function(item) {},
     54            _createAvatarNode: function(item) {},
     55
     56            appendItem: function(item) {
     57                this.source.insertNodes(false,[item]);
    5458            },
    5559
    56             insertItem: function(item) {
    57                 this.source.insertNodes(false, [item]);
     60            getItems: function() {
     61                return this.source.getAllNodes()
     62                .map(function(node){
     63                    return this.source.getItem(node.id).data;
     64                },this);
     65            },
     66
     67            deleteItems: function() {
     68                this.source.getAllNodes()
     69                .forEach(function(node){
     70                    registry.byNode(node).destroy();
     71                });
     72                this.source.sync();
     73            },
     74
     75            removeItem: function(item){
     76                this.source.getAllNodes()
     77                .filter(lang.hitch(this,function(node){
     78                    return this.source.getItem(node.id).data === item;
     79                }))
     80                .forEach(lang.hitch(this,function(node){
     81                    registry.byNode(node).destroy();
     82                    this.removeCallback && this.removeCallback(item);
     83                }));
     84                this.source.sync();
    5885            }
    5986
  • Dev/branches/rest-dojo-ui/client/rft/ui/MultipleChoiceListView.js

    r383 r384  
    22    'dojo/_base/declare',
    33    'dojo/_base/lang',
    4     'dijit/_WidgetBase',
    5     'dijit/_TemplatedMixin',
    6     'dijit/_WidgetsInTemplateMixin',
    7     'dijit/_Container',
     4    'dojo/dom-construct',
    85    'rft/ui/LineWithActionsWidget',
    9     'rft/ui/OrderedList',
    10     'dojo/text!./templates/AccountListView.html'
     6    'rft/ui/OrderedList'
    117    ],function(
    128        declare,
    139        lang,
    14         _WidgetBase,
    15         _TemplatedMixin,
    16         _WidgetsInTemplateMixin,
    17         _Container,
     10        domConstruct,
    1811        LineWithActionsWidget,
    19         OrderedList,
    20         templateString
     12        OrderedList
    2113        ) {
    22         return declare('rft.ui.MultipleChoiceListView',[OrderedList,_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{
    23             templateString: templateString,
     14        return declare('rft.ui.MultipleChoiceListView',[OrderedList],{
    2415            baseClass: 'rftMultipleChoiceListView',
    25             region: 'center',
     16            type: 'multipleChoiceOption',
    2617
    27             creatorMethod: function(item, hint) {
    28                 var node;
    29 
    30                 if (hint == "avatar") {
    31                     node = document.createElement("div");
    32                     node.className = "dragAvatar";
    33                     node.innerHTML = item.title;
    34                 } else {
    35                     var w = new LineWithActionsWidget({
    36                         title: item.title,
    37                         'class': "orange",
    38                         actions: {
    39                             "Remove" : {
    40                                 callback: lang.hitch(this, function() {
    41                                     this.removeItem(item, w);
    42                                 }),
    43                                 properties: {
    44                                     blockButton: false,
    45                                     icon: "Delete",
    46                                     modifiers: "white"
    47                                 }
     18            _createAvatarNode: function(item){
     19                return domConstruct.create("div",{
     20                    'class': 'dragAvatar',
     21                    innerHTML: item.title
     22                });
     23            },
     24            _createListNode: function(item) {
     25                var w = new LineWithActionsWidget({
     26                    title: item.title,
     27                    'class': "orange",
     28                    actions: {
     29                        "Remove" : {
     30                                                callback: lang.hitch(this, 'removeItem', item),
     31                            properties: {
     32                                blockButton: false,
     33                                icon: "Delete",
     34                                modifiers: "white"
    4835                            }
    4936                        }
    50                     });
    51                     w.startup();
    52                     node = w.domNode;
    53                 }
    54                 var fullItem = {
    55                     node: node,
    56                     data: item,
    57                     type: "ListViewItem"
    58                 };
    59                 return fullItem;
     37                    }
     38                });
     39                w.startup();
     40                return w.domNode;
    6041            }
    6142        });
    62 });
     43    });
  • Dev/branches/rest-dojo-ui/client/rft/ui/OrderedList.js

    r383 r384  
    22    'dojo/_base/declare',
    33    'dojo/_base/lang',
    4     'dijit/_WidgetBase',
    5     'dijit/_TemplatedMixin',
    6     'dijit/_WidgetsInTemplateMixin',
    7     'dijit/_Container',
     4    'dijit/form/Button',
    85    'rft/ui/List',
    96    'dojo/text!./templates/OrderedList.html'
     
    118        declare,
    129        lang,
    13         _WidgetBase,
    14         _TemplatedMixin,
    15         _WidgetsInTemplateMixin,
    16         _Container,
     10        Button,
    1711        List,
    1812        templateString
    1913        ){
    20         return declare('rft.ui.OrderedList',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container,List],{
     14        return declare('rft.ui.OrderedList',[List],{
    2115            templateString: templateString,
    2216            baseClass: 'rftLineListView',
    2317
    2418            postCreate: function() {
    25                 if (this.title) {
    26                     this.titleNode.innerHTML = this.title;
    27                 } else {
    28                     this.domNode.removeChild(this.titleNode);
    29                 }
     19                this.inherited(arguments);
    3020
    31                 this.source = new dojo.dnd.Source(this.sourceNode, {
    32                     isSource: true,
    33                     accept: ["LineListViewItem"],
    34                     horizontal: false,
    35                     withHandles: false,
    36                     copyOnly: false,
    37                     selfCopy: false,
    38                     selfAccept: true,
    39                     delay: 0,
    40                     singular: true,
    41                     creator: lang.hitch(this, this.creatorMethod)
    42                 });
    43 
    44                 new dijit.form.Button({
     21                new Button({
    4522                    label: "Move up",
    4623                    showLabel: false,
     
    4926                    'class': "trans",
    5027                    onClick: lang.hitch(this, function() {
    51                         this.moveItem("up");
     28                        this._moveSelectedItem("up");
    5229                    })
    53                 }, this.btnListMoveUp);
     30                }, this.btnListMoveUp).startup();
    5431
    55                 new dijit.form.Button({
     32                new Button({
    5633                    label: "Move down",
    5734                    showLabel: false,
     
    6037                    'class': "trans",
    6138                    onClick: lang.hitch(this, function() {
    62                         this.moveItem("down");
     39                        this._moveSelectedItem("down");
    6340                    })
    64                 }, this.btnListMoveDown);
     41                }, this.btnListMoveDown).startup();
    6542            },
    6643
    67             moveItem: function(dir) {
     44            _moveSelectedItem: function(dir) {
    6845                var node = this.source.getSelectedNodes()[0];
    6946                if (node) {
     
    9269                var anchor = this.source.getSelectedNodes()[0];
    9370                if (anchor) {
    94                     this.source.insertNodes(false, [item], false, anchor);
     71                    this.source.insertNodes(false,[item], false, anchor);
    9572                } else {
    96                     this.source.insertNodes(false, [item]);
     73                    this.appendItem(item);
    9774                }
    98             },
    99             getItems: function() {
    100                 return this.source.getAllNodes()
    101                 .map(function(node){
    102                     return this.source.getItem(node.id).data;
    103                 },this);
    104             },
     75            }
     76
    10577        });
    10678    });
  • Dev/branches/rest-dojo-ui/client/rft/ui/QuestionEditorToolkit.js

    r378 r384  
    8484                        _setupListView: function() {
    8585                                this._list = new CategoryListView( {
    86                                         controller: this,
    87                                         removeCallback: lang.hitch(this, this._removeCategory),
     86                                        removeCallback: lang.hitch(this, this._removeCategory)
    8887                                }).placeAt(this.listNode);
    89                                 for (category in this._categories) {
    90                                         this._list.insertItem(this._categories[category]);
     88                                for (var category in this._categories) {
     89                                        this._list.appendItem(this._categories[category]);
    9190                                }       
    9291                                this._list.startup();
     
    124123                        _addCategory: function(item) {
    125124                                this._categories.push(item);
    126                                 this._list.insertItem(item);
     125                                this._list.appendItem(item);
    127126                        },
    128127                        _removeCategory: function(item) {
  • 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        });
  • Dev/branches/rest-dojo-ui/client/rft/ui/TabbedQuestionBrowser.js

    r382 r384  
    7777                    };
    7878                    this._fillTopicSelector(topic,category);
    79                     w.on('include',lang.hitch(this,this.onSelect));
    8079                }
    8180            },
     
    107106                    }
    108107                } else {
    109                     console.warn('Busycount <= 0 when _done is called.');
     108                    console.warn('_done() was called more times than _busy().');
    110109                }
    111110            },
    112             onSelect: function(question) {}
     111            destroy: function() {
     112                this._busyWidget.destroyRecursive();
     113                this.inherited(arguments);
     114            }
    113115        });
    114116    });
Note: See TracChangeset for help on using the changeset viewer.