Ignore:
Timestamp:
03/13/14 00:44:08 (11 years ago)
Author:
hendrikvanantwerpen
Message:
  • Added open item options to singe and multiple choice.
  • Question view widgets are forms again, because we needed the control.
  • Multiple and singel choice share their widgets.
  • QuestionEditorPreview? now has items that were already there close, but opens newly dropped items.
  • PreviewItems? will save modified value even when we change to view before the widget loses its focus (which causes a change event).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/src/client/qed-client/model/widgets/questions/MultipleChoiceInputWidget.js

    r510 r511  
    11define([
    2     "dijit/_Container",
    3     "dijit/_TemplatedMixin",
    4     "dijit/_WidgetBase",
    5     "dijit/_WidgetsInTemplateMixin",
     2    "../../../widgets/_ComplexValueWidget",
    63    "dijit/form/CheckBox",
     4    "dijit/form/RadioButton",
     5    "dijit/form/TextBox",
    76    "dojo/_base/array",
    87    "dojo/_base/declare",
     8    "dojo/_base/lang",
    99    "dojo/dom-construct",
    1010    "dojo/text!./templates/MultipleChoiceInputWidget.html"
    11 ], function(_Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, CheckBox, array, declare, domConstruct, template) {
    12     return declare([_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{
     11], function(_ComplexValueWidget, CheckBox, RadioButton, TextBox, array, declare, lang, domConstruct, template) {
     12    return declare([_ComplexValueWidget],{
    1313        templateString: template,
     14        baseClass: 'qedMultipleChoiceWidget',
     15        allowMultiple: false,
    1416        startup: function() {
    1517            if ( this._started ) { return; }
    1618            this.inherited(arguments);
    1719
     20            var Ctor = this.allowMultiple ? CheckBox : RadioButton;
     21
     22            var input;
    1823            domConstruct.empty(this.domNode);
    1924            array.forEach(this.items, function(item){
    2025                var div = domConstruct.create("div", {
    2126                }, this.domNode, "last");
    22                 var input = new CheckBox({
    23                     name: this.code + item.subcode,
    24                     value: 1
     27                input = new Ctor({
     28                    name: this.code + (this.allowMultiple?item.subcode:this.subcode),
     29                    value: this.allowMultiple ? 1 : item.value
    2530                }).placeAt(div);
    2631                var label = domConstruct.create("label",{
     
    2934                }, div);
    3035            }, this);
     36           
     37            if ( this.lastItemIsOpen && input ) {
     38                this.lastItem = input;
     39                var openItemDiv = domConstruct.create("div", {
     40                }, this.domNode, "last");
     41                this.openItemTextBox = new TextBox({
     42                    name: this.code + this.lastItemIsOpen.subcode,
     43                    disabled: true,
     44                    readOnly: true,
     45                    'class': 'openItem'
     46                });
     47                this.openItemTextBox.placeAt(openItemDiv);
     48                this.own(this.lastItem.on(
     49                    'change',lang.hitch(this,'_handleOpenItemChange')));
     50            }
     51        },
     52        _setDisabledAttr: function() {
     53            this.inherited(arguments);
     54            this._handleOpenItemChange();
     55        },
     56        _setReadOnlyAttr: function() {
     57            this.inherited(arguments);
     58            this._handleOpenItemChange();
     59        },
     60        _handleOpenItemChange: function() {
     61            if ( this.lastItem ) {
     62                var value = this.allowMultiple ?
     63                            this.lastItem.get('value') :
     64                            this.lastItem.get('value')[0];
     65                var enabled = !(this.readOnly || this.disabled) && value;
     66                this.openItemTextBox.set('disabled',!enabled);
     67                this.openItemTextBox.set('readOnly',!enabled);
     68            }
    3169        }
    3270    });
Note: See TracChangeset for help on using the changeset viewer.