source: Dev/trunk/src/client/qed-client/widgets/ObjectBox.js @ 510

Last change on this file since 510 was 510, checked in by hendrikvanantwerpen, 11 years ago
  • Factored out general object mapping and iteration.
  • Split widgets for multiplechoice and singlechoice.
  • Restored readOnly/disabled setting for QuestionEditorPreviewItem? on innerWidget (since view innerWidget is not a form anymore, we cannot just set it on that, we iterate over all form children now).
File size: 2.7 KB
Line 
1define([
2    "../lib/object",
3    "./LineWithActionsWidget",
4    "dijit/_TemplatedMixin",
5    "dijit/_WidgetBase",
6    "dijit/_WidgetsInTemplateMixin",
7    "dojo/_base/declare",
8    "dojo/_base/lang",
9    "dojo/text!./templates/ObjectBox.html"
10], function(objectFuns, LineWithActionsWidget, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, declare, lang, template) {
11    return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
12        baseClass: "rftObjectBox",
13        templateString: template,
14        value: null,
15        actions: null,
16        startup: function() {
17            if ( this._started ){ return; }
18            this.inherited(arguments);
19            this.line1 = new LineWithActionsWidget({
20                actions: {
21                    "inspectIcon": {
22                        callback: lang.hitch(this, this._showInfoBox),
23                        properties: {
24                            blockButton: false,
25                            icon: "Inspect"
26                        }
27                    }
28                }
29            }).placeAt(this.line1Node);
30            this.line2 = new LineWithActionsWidget({
31            }).placeAt(this.line2Node);
32            var line3Actions = this._createLine3Actions();
33            this.line3 = new LineWithActionsWidget({
34                actions: line3Actions
35            }).placeAt(this.line3Node);
36            this.line1.startup();
37            this.line2.startup();
38            this.line3.startup();
39            this.inherited(arguments);
40        },
41        _createLine3Actions: function() {
42            return objectFuns.map(this.actions,function(value,name){
43                return {
44                    callback: lang.hitch(this, function(callback){
45                        if ( this.value ) { callback(this.value); }
46                    }, value),
47                    properties: {
48                        blockButton: true,
49                        label: name,
50                        icon: name.charAt(0).toUpperCase()+name.slice(1)
51                    }
52                };
53            },this);
54        },
55        _showInfoBox: function() {},
56        _setValueAttr: function(value) {
57            this.value = value;
58            this._refresh();
59        },
60        _getValueAttr: function(value) {
61            this.value = value;
62        },
63        _refresh: function() {
64            if ( this.value !== null ) {
65                this.iconNode.className = "rftIcon typeIcon rftIcon"+(this.value.type || '');
66                this.line1.set('title', this.value.title || '');
67                this.line2.set('title', this.value.subTitle || '');
68                this.line3.set('title', this.value.lowerTitle || '');
69            }
70        }
71    });
72});
Note: See TracBrowser for help on using the repository browser.