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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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)
Note: See TracChangeset for help on using the changeset viewer.