Ignore:
Timestamp:
07/24/12 16:39:41 (13 years ago)
Author:
jkraaijeveld
Message:

Can now edit basic question properties and store them.

File:
1 edited

Legend:

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

    r372 r374  
    66        'dijit/_Container',
    77        'dojo/dom-construct',
     8        'rft/store',
    89        'rft/ui/QuestionEditorPreviewItem',
     10        'rft/ui/CategoryListView',
    911        'dijit/_TemplatedMixin',
    1012        'dijit/_WidgetsInTemplateMixin',
     13        'dijit/form/ComboBox',
    1114        'dojo/text!./templates/QuestionEditorToolkit.html'
    12         ], function(declare, lang, baseArray, _WidgetBase, _Container, domConstruct, QuestionEditorPreviewItem, _TemplatedMixin, _WidgetsInTemplateMixin, template) {
     15        ], function(declare, lang, baseArray, _WidgetBase, _Container, domConstruct, store, QuestionEditorPreviewItem, CategoryListView, _TemplatedMixin, _WidgetsInTemplateMixin, ComboBox, template) {
    1316                return declare("rft.ui.QuestionEditorToolkit", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _Container], {
    1417
    1518                        templateString: template,
    16                         question: null,
     19                        _list: null,
     20                        _categorySelect: null,
     21                        _categoryStore: null,
     22                        _categories : null,
     23
     24//                      constructor: function() {
     25//                              lang.mixin(this, arguments);
     26//                      },
    1727
    1828                        postCreate: function(){
     
    4252                                this.inputsSource.insertNodes(false, inputsItems);
    4353                        },
     54                        loadQuestion: function(question) {
     55                                this.propertiesForm.set('value', question);
     56                                this._categories = question.categories;
     57                                this._setupListView();
     58                                this._setupAutoComplete();
     59                        },
     60                        onCategoryAdd: function() {
     61                                this._addCategory(this._categorySelect.get('displayedValue'));
     62                                this._categorySelect.reset();
     63                        },
    4464                        _creator: function(item, hint) {
    4565                                var node;
     
    4767                                        node = document.createElement("span");
    4868                                        node.innerHTML = item.widgetType;
    49                                         // debugger;
    5069                                        return {node: node, data: item, type: "ToolkitItem"};
    5170                                } else {
     
    6079                                }
    6180                        },
     81                        _setupListView: function() {
     82                                this._list = new CategoryListView( {
     83                                        controller: this,
     84                                        removeCallback: lang.hitch(this, this._removeCategory),
     85                                }).placeAt(this.listNode);
     86                                for (category in this._categories) {
     87                                        this._list.insertItem(this._categories[category]);
     88                                }       
     89                                this._list.startup();
     90                        },
     91                        _setupAutoComplete: function() {
     92                                this._categoryStore = new dojo.store.Memory({data: [] });
     93                                store.query("_design/default/_view/questions", {reduce:true, group:false, group_level:1})
     94                                        .forPairs(lang.hitch(this, function(value, key) {
     95                                                this._categoryStore.put({ category: key[0] });
     96                                        }));
     97                                this._categorySelect = new ComboBox( {
     98                                        id: "categoriesBox",
     99                                        name: "categories",
     100                                        store: this._categoryStore,
     101                                        searchAttr: "category"
     102                                }, "categoriesBox");
     103
     104                                this._topicStore = new dojo.store.Memory( {data: [] });
     105                                store.query("_design/default/_view/questions", {reduce:true, group:true, group_level:2})
     106                                        .forPairs(lang.hitch(this, function(value, key) {
     107                                                this._topicStore.put({ topic: key[1]});
     108                                        }));
     109                                this._topicSelect = new ComboBox( {
     110                                        id: "topicBox",
     111                                        name: "topic",
     112                                        store: this._topicStore,
     113                                        searchAttr: "topic"
     114                                }, "topicBox");
     115            },
     116                        _addCategory: function(item) {
     117                                this._categories.push(item);
     118                                this._list.insertItem(item);
     119                        },
     120                        _removeCategory: function(item) {
     121                                this._categories.splice(this._categories.indexOf(item), 1);
     122                        },
    62123                        _contentItems: function() {
    63124                                // Returns an array of objects, from which to generate buttons to populate the ToolkitContentSource list.
Note: See TracChangeset for help on using the changeset viewer.