Changeset 381


Ignore:
Timestamp:
07/27/12 14:42:38 (13 years ago)
Author:
jkraaijeveld
Message:

Created the IntegerInput? inner widget. Stores properly and allows for a lot of customization.

Location:
Dev/branches/rest-dojo-ui/client/rft
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/rest-dojo-ui/client/rft/css/layout.css

    r377 r381  
    494494    overflow: auto;
    495495}
     496
     497
     498/* Two column tables */
     499.labelsAndValues-labelCell {
     500  padding-left: 5px;
     501}
     502
     503.labelsAndValues-valueCell {
     504  padding-left: 20px;
     505}
  • Dev/branches/rest-dojo-ui/client/rft/run.js

    r379 r381  
    2727    'dijit/form/ComboBox',
    2828    'dijit/form/Select',
     29    'dijit/form/NumberSpinner',
    2930    'dojox/grid/DataGrid',
    3031    'dojox/widget/TitleGroup',
     
    4344    'rft/ui/Selector',
    4445    'rft/ui/TitleGroup',
    45     /*PreviewWidgets*/
    4646    'rft/ui/InnerWidgetFactory',
    4747    // pages -> load dynamically?
  • Dev/branches/rest-dojo-ui/client/rft/ui/InnerWidgetFactory.js

    r378 r381  
    1 define( ['dojo', 'dijit'],
    2         function(dojo, dijit) {
     1define( ['dojo', 'dijit', 'dojo/_base/lang', 'dojox/layout/TableContainer',
     2                 'dijit/layout/StackContainer'],
     3        function(dojo, dijit, lang, TableContainer, StackContainer) {
    34                dojo.provide('rft.ui.InnerWidgetFactory');
    4                 dojo.provide('rft.ui.HeaderItem');
    55                dojo.declare('rft.ui.InnerWidgetFactory', [],{
    66                        /* No default type, all should be valid */
     
    2424                        createFreeTextInputWidget: function(options) {
    2525                                return new rft.ui.FreeTextInput();
     26                        },
     27                        createIntegerInputWidget: function(options) {
     28                                var integerWidget = new rft.ui.IntegerInput();
     29                                integerWidget.setObject(options);
     30                                return integerWidget;
    2631                        }
    2732                });
     
    6671                        }
    6772                });
     73
     74                dojo.declare('rft.ui.IntegerInput', StackContainer, {
     75                        _numberSpinner:  null,
     76                        _simpleTable: null,
     77                        _editWidgets: null,
     78                        _editTable: null,
     79                        postCreate: function() {
     80                                this.inherited(arguments);
     81                                this._numberSpinner = new dijit.form.NumberSpinner( { title: "Answer", value: 0 });     
     82                                this._numberSpinner.startup();
     83                                this._simpleTable = new TableContainer({ cols: 1, customClass: "labelsAndValues", labelWidth : 150} );
     84                                this._simpleTable.addChild(this._numberSpinner);
     85                               
     86                                this._editTable = new TableContainer({ cols: 1, customClass: "labelsAndValues"} );
     87
     88                                this.addChild(this._simpleTable);
     89                        },
     90                        edit: function() {
     91                                this.removeChild(this._simpleTable);
     92                                this.addChild(this._editTable);
     93                        },
     94                        save: function () {
     95                                for (widget in this._editWidgets) {
     96                                        var w = this._editWidgets[widget];
     97                                        if (w.value) {
     98                                                if (w.constraint)
     99                                                        this._numberSpinner.constraints[w.field] = w.value;
     100                                                else
     101                                                        this._numberSpinner.set(w.field, w.value);
     102                                        }
     103                                }
     104                                this.removeChild(this._editTable);
     105                                this.addChild(this._simpleTable);
     106                                this._simpleTable.layout();
     107                        },
     108                        setObject: function(object) {
     109                                if(object.contents) {
     110                                        lang.mixin(this._numberSpinner, object.contents);
     111                                        this._setupEditWidgets(object.contents);
     112                                }
     113                                else {
     114                                        //Create widgets with default values
     115                                        this._setupEditWidgets(this.getObject().contents);
     116                                }
     117                        },
     118                        _setupEditWidgets: function(contents) {
     119                                //Set up widgets which should appear once edit is pressed.
     120                                this._editWidgets = [];
     121                                this._editWidgets.push(new dijit.form.NumberSpinner( { field: "value", title: "Default value" }))
     122                                this._editWidgets.push(new dijit.form.NumberSpinner( { field: "smallDelta", title: "Increment size" }));
     123                                this._editWidgets.push(new dijit.form.NumberSpinner( { constraint: true, field: "max", title: "Maximum value" }));
     124                                this._editWidgets.push(new dijit.form.NumberSpinner( { constraint: true, field: "min", title: "Minimum value" }));
     125                                this._editWidgets.push(new dijit.form.TextBox ( { field: "invalidMessage", title: "Invalid message" }));
     126                                this._editWidgets.push(new dijit.form.TextBox ( { field: "title", title: "Label" }));
     127                                for (widget in this._editWidgets) {
     128                                        var w = this._editWidgets[widget];
     129                                        if (w.constraint)
     130                                                w.set('value', contents.constraints[w.field]);
     131                                        else
     132                                                w.set('value', contents[w.field]);
     133                                        this._editTable.addChild(w);
     134                                }
     135                                this._editTable.startup();
     136                        },
     137                        getObject: function() {
     138
     139                                return { widgetType: 'IntegerInput',
     140                                                 contents:
     141                                                 {
     142                                                        value: this._numberSpinner.value,
     143                                                    smallDelta: this._numberSpinner.smallDelta,
     144                                                        constraints: this._numberSpinner.constraints,
     145                                                        invalidMessage: this._numberSpinner.invalidMessage,
     146                                                        title: this._numberSpinner.title
     147                                                 }
     148                                };
     149                        }
     150                });
    68151        }
    69152)
  • Dev/branches/rest-dojo-ui/client/rft/ui/QuestionEditorPreviewItem.js

    r378 r381  
    4141                                        this.editButtonNode.iconNode.className = this.editButtonNode.iconNode.className.replace("rftIconAccept", "rftIconEdit");
    4242                                        this.editButtonNode.set("label", "Edit");
     43                                        this.innerWidget.save();
    4344                                }
    4445                                else {
    4546                                        this.editButtonNode.iconNode.className = this.editButtonNode.iconNode.className.replace("rftIconEdit", "rftIconAccept");
    4647                                        this.editButtonNode.set("label", "Save");
     48                                        this.innerWidget.edit();
    4749                                }
    4850                                this._editing = !this._editing;
     
    102104                                        break;
    103105                                }*/
     106                                this.innerWidget.startup();
    104107                                this.innerWidget.placeAt(this.containerNode);
    105108                        }
Note: See TracChangeset for help on using the changeset viewer.