Changeset 376


Ignore:
Timestamp:
07/25/12 16:04:02 (13 years ago)
Author:
jkraaijeveld
Message:

Started the QuestionEditorPreview? bit - now works with headers and texts, fully stores and restores this in order properly.

Note: there must be a better way for this, but seeing as all content pieces can differ greatly I couldn't think of a way to make it properly generic. @Hendrik: need discussion about this.

Note2: Currently I don't use any internal events in the question editor. Not sure if it would be a lot better we would.

Location:
Dev/branches/rest-dojo-ui/client/rft
Files:
3 added
6 edited

Legend:

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

    r374 r376  
    3939            _refresh: function () {
    4040                this._toolkit.loadQuestion(this.question);
     41                this._preview.insertObjects(this.question.content || []);
    4142            },
    4243            _onSave: function() {
    4344                lang.mixin(this.question, this._toolkit.propertiesForm.get('value'));
    4445                this.question.categories = this._toolkit._categories;
     46                this.question.content = this._preview.getContent();
    4547                store.put(this.question)
    4648                .then(function() {
     
    5052            },
    5153            _onDiscard: function() {
    52                 this._toolkit.propertiesForm.reset();
    5354                content.goTo('questions');
    5455                return false;
     
    7172            },
    7273            _setupEditor: function() {
    73 //                this.toolkit = new rft.ui.QuestionEditorToolkit( { question: this.question } );
    7474                this._toolkit = new rft.ui.QuestionEditorToolkit();
    7575                this._toolkit.placeAt("QuestionEditorToolkit");
  • Dev/branches/rest-dojo-ui/client/rft/run.js

    r374 r376  
    4242    'rft/ui/Selector',
    4343    'rft/ui/TitleGroup',
    44    
     44    'rft/ui/PreviewWidgets/HeaderItem',
     45    'rft/ui/PreviewWidgets/TextItem',
    4546    // pages -> load dynamically?
    4647    'rft/pages/index',
  • Dev/branches/rest-dojo-ui/client/rft/ui/QuestionEditorPreview.js

    r366 r376  
    4545                                                item: item
    4646                                        });
    47                                         return {node: previewItem.domNode, data: item, type: "PreviewItem"};
     47                                        return {node: previewItem.domNode, data: previewItem, type: item.type};
    4848                                        break;                                 
    4949                                }                               
     
    5959                                return innerWidget;
    6060                        },
    61                         InsertObjects: function(/*Array*/objects) {
     61                        insertObjects: function(/*Array*/objects) {
    6262                                // This takes an array of objects {data:{//props}, type:[//types]}. Node is NOT included!
    6363                                objects.forEach(function(item){
     
    6565                                }, this);
    6666                        },
    67                         RemoveObject: function(widget) {
     67                        getContent: function() {
     68                                content = [];
     69                                var nodes = this.dndSource.getAllNodes();
     70                                for (var i = 0; i < nodes.length; i++) {
     71                                        content.push(this.dndSource.getItem(nodes[i].id).data.getContent());
     72                                }
     73                                return content;
    6874                        },
    69                         GetNodeList: function() {
     75                        getNodeList: function() {
    7076                                return this.dndSource.getAllNodes();
    7177                        },
  • Dev/branches/rest-dojo-ui/client/rft/ui/QuestionEditorPreviewItem.js

    r370 r376  
    99        'dijit/_WidgetsInTemplateMixin',
    1010        'dijit/form/TextBox',
     11        'rft/ui/PreviewWidgets/HeaderItem',
     12        'rft/ui/PreviewWidgets/TextItem',
    1113        'dojo/text!./templates/QuestionEditorPreviewItem.html',
    12         ], function(declare, fx, _WidgetBase, domClass, lang, on, _TemplatedMixin, _WidgetsInTemplateMixin, TextBox, templateFull) {
     14        ], function(declare, fx, _WidgetBase, domClass, lang, on, _TemplatedMixin, _WidgetsInTemplateMixin, TextBox, HeaderItem, TextItem, templateFull) {
    1315                return declare("rft.ui.QuestionEditorPreviewItem", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
    1416
     
    2022                        foldDuration: [250, 250],
    2123                        animation: null,
    22                        
     24                        _editing: false,
     25
    2326                        postCreate: function() {
    2427                                this.foldButtonNode.onClick = lang.hitch(this, this.toggleFold);
     28                                this.removeButtonNode.onClick = lang.hitch(this, this.removeObject);
     29                                this.editButtonNode.onClick = lang.hitch(this, this.toggleEdit);
    2530                                if (this.item) {
    2631                                        this._createInnerWidget();
     
    3237                                        this.titleNode.innerHTML = title;
    3338                                });
     39                        },
     40                        toggleEdit: function() {
     41                                if(this._editing) {
     42                                        this.editButtonNode.iconNode.className = this.editButtonNode.iconNode.className.replace("rftIconAccept", "rftIconEdit");
     43                                        this.editButtonNode.set("label", "Edit");
     44                                        this.innerWidget.save();
     45                                }
     46                                else {
     47                                        this.editButtonNode.iconNode.className = this.editButtonNode.iconNode.className.replace("rftIconEdit", "rftIconAccept");
     48                                        this.editButtonNode.set("label", "Save");
     49                                        this.innerWidget.edit();
     50                                }
     51                                this._editing = !this._editing;
    3452                        },
    3553                        toggleFold: function() {
     
    6583                                }
    6684                        },
     85                        getContent: function() {
     86                                return {        data: this.innerWidget.getContent(),
     87                                                        type: this.item.type };
     88                        },
     89                        removeObject: function(widget) {
     90                                this.destroyRecursive();
     91                        },
    6792                        _createInnerWidget: function() {
    6893                                // This always creates a textbox as innerwidget pending creation of actual innerWidgets.
    6994                                // Introduce a better way to create these widgets than a switch statement, based on item.widgetType? Perhaps "new eval(item.widgetType)({});" ?
     95                                this.innerWidget = eval("new "+ this.item.type + "({ disabled: true });");
     96                                this.innerWidget.setContent(this.item.data);
     97                                this.titleNode.innerHTML = this.item.type;
     98                                /*
    7099                                switch (this.item.widgetType) {
    71100                                        default:
    72                                         this.innerWidget = new TextBox();
     101                                        this.innerWidget = new HeaderItem({ disabled: true });
     102                                        this.titleNode.innerHTML = "Header";
    73103                                        break;
    74                                 }
     104                                }*/
    75105                                this.innerWidget.placeAt(this.containerNode);
    76106                        }
  • Dev/branches/rest-dojo-ui/client/rft/ui/QuestionEditorToolkit.js

    r375 r376  
    134134                                        objectData: {
    135135                                                _id: null,
    136                                                 widgetType: "rft.surveyContent.HeaderDialog",
     136                                                type: "HeaderItem",
    137137                                                widgetProps: {}
    138138                                        },
     
    143143                                        objectData: {
    144144                                                _id: null,
    145                                                 widgetType: "rft.surveyContent.TextDialog",
     145                                                type: "TextItem",
    146146                                                widgetProps: {}
    147147                                        },
  • Dev/branches/rest-dojo-ui/client/rft/ui/templates/QuestionEditorPreviewItem.html

    r366 r376  
    44                <span class="floatRight">
    55                        <button class="blue" data-dojo-type="dijit.form.Button" data-dojo-props="baseClass: 'rftBlockButton', showLabel: false, iconClass: 'rftIcon rftIconHalfArrowUp'" data-dojo-attach-point="foldButtonNode">Fold</button>
    6                         <button class="blue" data-dojo-type="dijit.form.Button" data-dojo-props="baseClass: 'rftBlockButton', showLabel: false, iconClass: 'rftIcon rftIconDelete'">Remove</button>
     6                        <button class="blue" data-dojo-type="dijit.form.Button" data-dojo-attach-point="removeButtonNode" data-dojo-props="baseClass: 'rftBlockButton', showLabel: false, iconClass: 'rftIcon rftIconDelete'">Remove</button>
    77                </span>
    88        </div>
     
    1515        <div class="bottomBorder inheritBgColor light" data-dojo-attach-point="bottomBorderNode">
    1616                <span class="floatRight">
    17                         <button class="trans" data-dojo-type="dijit.form.Button" data-dojo-props="baseClass: 'rftBlockButton', iconClass: 'rftIcon rftIconEdit'">Edit</button>
     17                        <button class="trans" data-dojo-type="dijit.form.Button" data-dojo-attach-point="editButtonNode" data-dojo-props="baseClass: 'rftBlockButton', iconClass: 'rftIcon rftIconEdit'">Edit</button>
    1818                </span>
    1919        </div>
Note: See TracChangeset for help on using the changeset viewer.