Index: Dev/branches/rest-dojo-ui/client/rft/pages/survey.html
===================================================================
--- Dev/branches/rest-dojo-ui/client/rft/pages/survey.html	(revision 378)
+++ Dev/branches/rest-dojo-ui/client/rft/pages/survey.html	(revision 379)
@@ -5,5 +5,5 @@
             <h2>
                 <span class="rftIcon rftIconSurvey"></span>
-                <span class="headerText" data-dojo-attach-point="header">Survey A [editing]</span>
+                <span class="headerText" data-rft-attach-point="titleNode">Survey Editor</span>
             </h2>
         </div>
@@ -18,10 +18,46 @@
 
             <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region: 'bottom'">
-                <button data-rft-attach-point="btnProperties" data-dojo-type="dijit.form.Button" data-rft-attach-event="onClick:onProperties" data-dojo-props="baseClass: 'rftLargeButton', iconClass: 'rftIcon rftIconProperties'">Properties</button>
-                <button data-rft-attach-point="btnSave" data-dojo-type="dijit.form.Button" data-rft-attach-event="onClick:onSave" data-dojo-props="baseClass: 'rftLargeButton', iconClass: 'rftIcon rftIconAccept'">Save Changes</button>
-                <button data-rft-attach-point="btnDiscard" data-dojo-type="dijit.form.Button" data-dojo-props="baseClass: 'rftLargeButton', iconClass: 'rftIcon rftIconCancel'">Discard changes</button>
-                <button data-rft-attach-point="btnPreview" data-dojo-type="dijit.form.Button" data-dojo-props="baseClass: 'rftLargeButton', iconClass: 'rftIcon rftIconPreview'">Preview</button>
+                <button data-dojo-type="dijit.form.Button"
+                        data-rft-attach-event="onClick:_onShowProperties"
+                        data-dojo-props="baseClass: 'rftLargeButton', iconClass: 'rftIcon rftIconProperties'">
+                    Properties</button>
+                <button data-dojo-type="dijit.form.Button"
+                        data-rft-attach-event="onClick:_onSave"
+                        data-dojo-props="baseClass: 'rftLargeButton', iconClass: 'rftIcon rftIconAccept'">
+                    Save Changes</button>
+                <button data-dojo-type="dijit.form.Button"
+                        data-rft-attach-event="onClick:_onDiscard"
+                        data-dojo-props="baseClass: 'rftLargeButton', iconClass: 'rftIcon rftIconCancel'">
+                    Discard changes</button>
+                <button data-dojo-type="dijit.form.Button"
+                        data-rft-attach-event="onClick:_onShowPreview"
+                        data-dojo-props="baseClass: 'rftLargeButton', iconClass: 'rftIcon rftIconPreview'">
+                    Preview</button>
             </div>
         </div>
     </div>
+
+    <div data-dojo-type="dijit.Dialog"
+         title="Survey properties"
+         data-rft-attach-point="propertiesDialog"
+         data-rft-attach-event="onSubmit:_onPropertiesOk">
+
+        <form data-dojo-type="dijit.form.Form"
+              data-rft-attach-point="propertiesForm">
+            <label for="title">Title</label>
+            <input data-dojo-type="dijit.form.TextBox" name="title"/>
+        </form>
+            
+        <div>
+            <button data-dojo-type="dijit.form.Button"
+                    type="submit"
+                    data-rft-attach-event="onClick:_onPropertiesOk">
+                OK</button>
+            <button data-dojo-type="dijit.form.Button"
+                    type="button"
+                    data-rft-attach-event="onClick:_onPropertiesCancel">
+                Cancel</button>
+        </div>
+    </div>
+
 </div>
Index: Dev/branches/rest-dojo-ui/client/rft/pages/survey.js
===================================================================
--- Dev/branches/rest-dojo-ui/client/rft/pages/survey.js	(revision 378)
+++ Dev/branches/rest-dojo-ui/client/rft/pages/survey.js	(revision 379)
@@ -1,3 +1,4 @@
 define([
+    'dojo/_base/array',
     'dojo/_base/declare',
     'dojo/_base/Deferred',
@@ -7,11 +8,12 @@
     'rft/store',
     'rft/ui/_Page',
-    'rft/ui/SurveyListView',
+    'rft/ui/OrderedDndList',
     'rft/ui/TabbedQuestionBrowser'
     ],
-    function(declare,Deferred,event,lang,content,store,_Page,SurveyListView,TabbedQuestionBrowser){
+    function(array,declare,Deferred,event,lang,content,store,_Page,
+             OrderedDndList,TabbedQuestionBrowser){
         return declare('rft.pages.survey',[_Page],{
-            object: null,
-            listView: null,
+            survey: null,
+            questionList: null,
             _dataMap: null,
             constructor: function(){
@@ -20,29 +22,14 @@
             onVisit: function() {
                 if ( this.pageArgs.uid ) {
+                    this._setupQuestionBrowser();
+                    this._setupListView();
                     Deferred.when(store.get(this.pageArgs.uid))
                     .then(lang.hitch(this,function(obj){
-                        this.object = obj;
-                        return Deferred.when( obj.creator && store.dereference(obj.creator) );
+                        this.survey = obj;
+                        this.refresh();
                     }));
-                    this._setupQuestionBrowser();
-                    this._setupListView();
                 } else {
                     throw "No valid uid or survey passed!";
                 }
-            },
-            onProperties: function(evt) {
-
-            },
-            onSave: function(evt) {
-//                lang.mixin(this.object, this.propertiesForm.get('value'));
-                store.put(this.object)
-                .then(function() { 
-                    content.goTo('surveys');
-                });
-                event.stop(evt);
-                return false;
-            },
-            _goToPreview: function() {
-                content.goTo('surveyAdvanced', {uid: this.object._id});
             },
             _setupQuestionBrowser: function() {
@@ -52,5 +39,5 @@
                     selectedActions: {
                         "Include": {
-                            callback: lang.hitch(this,this.includeQuestion),
+                            callback: lang.hitch(this,this._includeQuestion),
                             icon: "Accept",
                             description: "Include in survey"
@@ -67,13 +54,51 @@
                 this.questionBrowser.startup();
             },
-            /* ListView code */
-            includeQuestion: function(question) {
-                var item = this.listView.insertItem(question);
+            _includeQuestion: function(question) {
+                this.questionList.insertItem(question);
             },
             _setupListView: function() {
-                this.listView = new SurveyListView({
-                    controller: this
+                this.questionList = new OrderedDndList({
+                    type: 'question',
+                    region: 'center'
                 }).placeAt(this.surveyListViewNode);
-                this.listView.startup();
+                this.questionList.startup();
+            },
+            refresh: function() {
+                this.titleNode.innerHTML = this.survey.title || "(set title in properties)";
+                this.propertiesForm.set('value',this.survey);
+                store.query(null,{keys:this.survey.questions,include_docs:true})
+                .forEach(lang.hitch(this.questionList,'appendItem'));
+            },
+            _onShowProperties: function(evt) {
+                this.propertiesDialog.show();
+            },
+            _onPropertiesOk: function(evt) {
+                this.propertiesDialog.hide();
+                lang.mixin(this.survey, this.propertiesForm.get('value'));
+                this.refresh();
+                event.stop(evt);
+                return false;
+            },
+            _onPropertiesCancel: function(evt) {
+                this.propertiesDialog.hide();
+                this.propertiesForm.set('value',this.survey);
+                event.stop(evt);
+                return false;
+            },
+            _onSave: function(evt) {
+                this.survey.questions = array.map(this.questionList.getItems(),function(item){
+                    return store.getIdentity(item);
+                });
+                store.put(this.survey)
+                .then(function() { 
+                    content.goTo('surveys');
+                });
+                event.stop(evt);
+                return false;
+            },
+            _onDiscard: function(evt) {
+            },
+            _onShowPreview: function() {
+                content.goTo('surveyAdvanced', {uid: store.getIdentity(this.survey)});
             }
         });
Index: Dev/branches/rest-dojo-ui/client/rft/run.js
===================================================================
--- Dev/branches/rest-dojo-ui/client/rft/run.js	(revision 378)
+++ Dev/branches/rest-dojo-ui/client/rft/run.js	(revision 379)
@@ -8,4 +8,5 @@
     'dojo/data/ObjectStore',
     'dojo/store/JsonRest',
+    'dijit/Dialog',
     'dijit/InlineEditBox',
     'dijit/MenuBar',
Index: Dev/branches/rest-dojo-ui/client/rft/store.js
===================================================================
--- Dev/branches/rest-dojo-ui/client/rft/store.js	(revision 378)
+++ Dev/branches/rest-dojo-ui/client/rft/store.js	(revision 379)
@@ -141,5 +141,5 @@
                 var dfd = new Deferred();
                 var queryOpts = {};
-                if ( query === undefined ) {
+                if ( !query ) {
                     query = '_all_docs';
                 }
Index: Dev/branches/rest-dojo-ui/client/rft/ui/OrderedDndList.js
===================================================================
--- Dev/branches/rest-dojo-ui/client/rft/ui/OrderedDndList.js	(revision 379)
+++ Dev/branches/rest-dojo-ui/client/rft/ui/OrderedDndList.js	(revision 379)
@@ -0,0 +1,166 @@
+define([
+    'dojo/_base/declare',
+    'dojo/_base/lang',
+    'dojo/dnd/Source',
+    'dojo/dom-construct',
+    'dijit/_Container',
+    'dijit/_TemplatedMixin',
+    'dijit/_WidgetBase',
+    'dijit/_WidgetsInTemplateMixin',
+    'dijit/form/Button',
+    'rft/ui/LineWithActionsWidget',
+    'dojo/text!./templates/OrderedDndList.html'
+    ],function(
+        declare,
+        lang,
+        Source,
+        domConstruct,
+        _Container,
+        _TemplatedMixin,
+        _WidgetBase,
+        _WidgetsInTemplateMixin,
+        Button,
+        LineWithActionsWidget,
+        templateString
+    ){
+        return declare('rft.ui.OrderedDndList',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{
+            templateString: templateString,
+            baseClass: 'rftSurveyListView',
+            type: 'text',
+            source: null,
+
+            postCreate: function() {
+                if (this.title) {
+                    this.titleNode.innerHTML = this.title;
+                } else {
+                    this.domNode.removeChild(this.titleNode);
+                }
+
+                this.source = new Source(this.sourceNode, {
+                    accept: [this.type],
+                    horizontal: false,
+                    singular: true,
+                    creator: lang.hitch(this, this._createQuestionDndItem)
+                });
+
+                new Button({
+                    label: "Move up",
+                    showLabel: false,
+                    iconClass: "rftIcon rftIconFullArrowUp",
+                    baseClass: "rftBlockButton",
+                    'class': "trans",
+                    onClick: lang.hitch(this, function() {
+                        this._moveSelectedItem("up");
+                    })
+                }, this.btnListMoveUp);
+
+                new Button({
+                    label: "Move down",
+                    showLabel: false,
+                    iconClass: "rftIcon rftIconFullArrowDown",
+                    baseClass: "rftBlockButton",
+                    'class': "trans",
+                    onClick: lang.hitch(this, function() {
+                        this._moveSelectedItem("down");
+                    })
+                }, this.btnListMoveDown);
+            },
+            _createQuestionDndItem: function(item, hint) {
+                var node;
+
+                if (hint == "avatar") {
+                    node = domConstruct.create("div",{
+                        'class': 'dragAvatar',
+                        innerHTML: item.title
+                    });
+                } else {
+                    var w = new LineWithActionsWidget({
+                        title: item.title,
+                        'class': "inheritBgColor",
+                        actions: {
+                            "Remove" : {
+                                // w not bound in hitch, because it's
+                                // not initialized when hitch is called.
+                                callback: lang.hitch(this, function(){
+                                    this._removeItem(w);
+                                }),
+                                properties: {
+                                    blockButton: false,
+                                    icon: "Delete",
+                                    modifiers: "white",
+                                    label: "Remove"
+                                }
+                            },
+                            "Info" : {
+                                callback: function(){ item.description && alert(item.description); },
+                                properties: {
+                                    blockButton: false,
+                                    icon: "Inspect",
+                                    modifiers: "white",
+                                    label: "Show info"
+                                }
+                            }
+                        }
+                    });
+                    w.startup();
+                    node = w.domNode;
+                }
+                return {
+                    node: node,
+                    data: item,
+                    type: "question"
+                };
+            },
+            _moveSelectedItem: function(dir) {
+                var node = this.source.getSelectedNodes()[0];
+                if (node) {
+                    if (dir == "up") {
+                        if (node.previousSibling) {
+                            return node.parentNode.insertBefore(node, node.previousSibling);
+                        } else {
+                            return false;
+                        }
+
+                    } else if (dir == "down") {
+                        if (node.nextSibling) {
+                            return node.parentNode.insertBefore(node.nextSibling, node);
+                        } else {
+                            return false;
+                        }
+                    } else {
+                        throw "Invalid move direction passed!";
+                    }
+                } else {
+                    return false;
+                }
+            },
+            insertItem: function(item) {
+                var anchor = this.source.getSelectedNodes()[0];
+                if (anchor) {
+                    this.source.insertNodes(false,[item], false, anchor);
+                } else {
+                    this.appendItem(item);
+                }
+            },
+            appendItem: function(item) {
+                this.source.insertNodes(false,[item]);
+            },
+            getItems: function() {
+                return this.source.getAllNodes()
+                .map(function(node){
+                    return this.source.getItem(node.id).data;
+                },this);
+            },
+            deleteItems: function() {
+                this.source.getAllNodes()
+                .forEach(function(node){
+                    node.destroy();
+                });
+                this.source.sync();
+            },
+            _removeItem: function(widget){
+                widget.destroy();
+                this.source.sync();
+            }
+        });
+    });
Index: Dev/branches/rest-dojo-ui/client/rft/ui/SurveyListView.js
===================================================================
--- Dev/branches/rest-dojo-ui/client/rft/ui/SurveyListView.js	(revision 378)
+++ 	(revision )
@@ -1,151 +1,0 @@
-define([
-    'dojo/_base/declare',
-    'dijit/_WidgetBase',
-    'dijit/_TemplatedMixin',
-    'dojo/_base/lang',
-    'dojo/fx',
-    'dojo/_base/fx',
-    'dijit/_WidgetsInTemplateMixin',
-    'dijit/_Container',
-    'rft/ui/LineWithActionsWidget',
-    'dojo/text!./templates/SurveyListView.html'
-    ],function(
-        declare,
-        _WidgetBase,
-        _TemplatedMixin,
-        lang,
-        fx,
-        baseFx,
-        _WidgetsInTemplateMixin,
-        _Container,
-        LineWithActionsWidget,
-        templateString
-        ){
-        return declare('rft.ui.SurveyListView',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{
-            templateString: templateString,
-            baseClass: 'rftSurveyListView',
-            source: null,
-            region: 'center',
-
-            postCreate: function() {
-                if (this.title) {
-                    this.titleNode.innerHTML = this.title;
-                } else {
-                    this.domNode.removeChild(this.titleNode);
-                }
-
-                this.source = new dojo.dnd.Source(this.sourceNode, {
-                    isSource: true,
-                    accept: ["SurveyListViewItem"],
-                    horizontal: false,
-                    withHandles: false,
-                    copyOnly: false,
-                    selfCopy: false,
-                    selfAccept: true,
-                    delay: 0,
-                    singular: true,
-                    creator: lang.hitch(this, this.creatorMethod)
-                });
-
-                new dijit.form.Button({
-                    label: "Move up",
-                    showLabel: false,
-                    iconClass: "rftIcon rftIconFullArrowUp",
-                    baseClass: "rftBlockButton",
-                    'class': "trans",
-                    onClick: lang.hitch(this, function() {
-                        this.moveItem("up");
-                    })
-                }, this.btnListMoveUp);
-
-                new dijit.form.Button({
-                    label: "Move down",
-                    showLabel: false,
-                    iconClass: "rftIcon rftIconFullArrowDown",
-                    baseClass: "rftBlockButton",
-                    'class': "trans",
-                    onClick: lang.hitch(this, function() {
-                        this.moveItem("down");
-                    })
-                }, this.btnListMoveDown);
-            },
-            creatorMethod: function(item, hint) {
-                var node;
-
-                if (hint == "avatar") {
-                    node = document.createElement("div");
-                    node.className = "dragAvatar";
-                    node.innerHTML = item.title;
-                } else {
-                    var w = new LineWithActionsWidget({
-                        title: item.title,
-                        'class': "inheritBgColor",
-                        actions: {
-                            "Remove" : {
-                                callback: lang.hitch(this, function(){
-                                    this.removeItem(item, w);
-                                }),
-                                properties: {
-                                    blockButton: false,
-                                    icon: "Delete",
-                                    modifiers: "white",
-                                    label: "Remove"
-                                }
-                            },
-                            "Info" : {
-                                callback: function(){ item.description && alert(item.description); },
-                                properties: {
-                                    blockButton: false,
-                                    icon: "Inspect",
-                                    modifiers: "white",
-                                    label: "Show info"
-                                }
-                            }
-                        }
-                    });
-                    w.startup();
-                    node = w.domNode;
-                }
-                var fullItem = {
-                    node: node,
-                    data: item,
-                    type: "SurveyListViewItem"
-                };
-                return fullItem;
-            },
-            moveItem: function(dir) {
-                var node = this.source.getSelectedNodes()[0];
-                if (node) {
-                    if (dir == "up") {
-                        if (node.previousSibling) {
-                            return node.parentNode.insertBefore(node, node.previousSibling);
-                        } else {
-                            return false;
-                        }
-
-                    } else if (dir == "down") {
-                        if (node.nextSibling) {
-                            return node.parentNode.insertBefore(node.nextSibling, node);
-                        } else {
-                            return false;
-                        }
-                    } else {
-                        throw "Invalid move direction passed!";
-                    }
-                } else {
-                    return false;
-                }
-            },
-            insertItem: function(item) {
-                var anchor = this.source.getSelectedNodes()[0];
-                if (anchor) {
-                    this.source.insertNodes(false,[item], false, anchor);
-                } else {
-                    this.source.insertNodes(false,[item]);
-                }
-            },
-            removeItem: function(item,widget){
-                widget.destroy();
-            }
-        });
-});
Index: Dev/branches/rest-dojo-ui/client/rft/ui/templates/OrderedDndList.html
===================================================================
--- Dev/branches/rest-dojo-ui/client/rft/ui/templates/OrderedDndList.html	(revision 379)
+++ Dev/branches/rest-dojo-ui/client/rft/ui/templates/OrderedDndList.html	(revision 379)
@@ -0,0 +1,11 @@
+<div>
+	<h3 data-dojo-attach-point="titleNode"></h3>
+	<div data-dojo-attach-point="sourceNode" id="DERPDERP" class="${baseClass}Content"></div>
+	<div data-dojo-attach-point="buttonsNode" class="floatRight">
+		<span>Move selected: </span>
+		<button data-dojo-attach-point="btnListMoveUp" ></button>
+		<button data-dojo-attach-point="btnListMoveDown"></button>
+	</div>
+	<div data-dojo-attach-point="containerNode">
+	</div>
+</div>
Index: Dev/branches/rest-dojo-ui/client/rft/ui/templates/SurveyListView.html
===================================================================
--- Dev/branches/rest-dojo-ui/client/rft/ui/templates/SurveyListView.html	(revision 378)
+++ 	(revision )
@@ -1,11 +1,0 @@
-<div>
-	<h3 data-dojo-attach-point="titleNode"></h3>
-	<div data-dojo-attach-point="sourceNode" id="DERPDERP" class="${baseClass}Content"></div>
-	<div data-dojo-attach-point="buttonsNode" class="floatRight">
-		<span>Move selected: </span>
-		<button data-dojo-attach-point="btnListMoveUp" ></button>
-		<button data-dojo-attach-point="btnListMoveDown"></button>
-	</div>
-	<div data-dojo-attach-point="containerNode">
-	</div>
-</div>
