Changeset 461
- Timestamp:
- 06/10/13 01:07:16 (12 years ago)
- Location:
- Dev/trunk/src/client/qed-client
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/src/client/qed-client/model/widgets/SurveyRenderWidget.js
r457 r461 22 22 this.survey = survey; 23 23 var f = new QuestionWidgetFactory(); 24 array.forEach(Survey.Questions.get(this.survey),function(question ){25 array.forEach(question.content || [], function(item,index){24 array.forEach(Survey.Questions.get(this.survey),function(question,question_index){ 25 array.forEach(question.content || [], function(item,item_index){ 26 26 // The dot causes values to be grouped in an object! 27 item.code = question.code.toString()+'.'+index.toString();28 27 var w = f.createViewWidget(item); 29 28 if ( w !== null ) { 29 w.name = question_index.toString()+'/'+question.code.toString()+'.'+item_index.toString(); 30 30 w.placeAt(this.domNode); 31 31 } -
Dev/trunk/src/client/qed-client/model/widgets/questions/MultipleChoiceInputWidget.js
r443 r461 10 10 return declare([_ComplexValueWidget],{ 11 11 templateString: template, 12 allowMultiple: false, 12 13 startup: function() { 13 14 if ( this._started ) { return; } … … 20 21 }, this.domNode, "last"); 21 22 var input = new Ctor({ 22 name: index.toString() 23 name: this.allowMultiple === true ? index.toString() : 'choice', 24 value: item.text 23 25 }).placeAt(div); 24 26 var label = domConstruct.create("label",{ 27 for: input.id, 25 28 innerHTML: item.text 26 29 }, div); 27 30 }, this); 31 }, 32 _getValueAttr: function() { 33 var value = this.inherited(arguments); 34 if ( this.allowMultiple === true ) { 35 return value; 36 } else { 37 return value.choice; 38 } 39 }, 40 _setValueAttr: function(value) { 41 var inherited = this.getInherited(arguments); 42 if ( this.allowMultiple === true ) { 43 inherited.call(this,value); 44 } else { 45 inherited.call(this,{choice:value}); 46 } 28 47 } 29 48 }); -
Dev/trunk/src/client/qed-client/model/widgets/questions/TextInputWidget.js
r443 r461 14 14 }, 15 15 _getValueAttr: function() { 16 return this.text Box.get('value');16 return this.textArea.get('value'); 17 17 }, 18 18 _setValueAttr: function(value) { 19 return this.text Box.set('value', value);19 return this.textArea.set('value', value); 20 20 } 21 21 }); -
Dev/trunk/src/client/qed-client/model/widgets/questions/templates/HeaderConfigWidget.html
r443 r461 1 < div>1 <form> 2 2 <label for="text" class="qedLabel">Text</label> 3 3 <div class="qedField" data-dojo-type="dijit/form/TextBox" name="text"></div> 4 </ div>4 </form> -
Dev/trunk/src/client/qed-client/model/widgets/questions/templates/MultipleChoiceInputConfigRowWidget.html
r443 r461 1 < div>1 <form> 2 2 <div data-dojo-type="dijit/form/ValidationTextBox" name="text" required="required" data-dojo-attach-point="textBox"></div><div data-dojo-type="dijit/form/Button" data-dojo-attach-event="onClick:onDestroy">X</div> 3 </ div>3 </form> -
Dev/trunk/src/client/qed-client/model/widgets/questions/templates/MultipleChoiceInputConfigWidget.html
r443 r461 1 < div>1 <form> 2 2 <div> 3 3 <label class="qedLabel" for="allowMultiple">Allow multiple</label> … … 7 7 </div> 8 8 <div data-dojo-type="dijit/form/Button" data-dojo-attach-event="onClick:onAddItem">Add item</div> 9 </ div>9 </form> -
Dev/trunk/src/client/qed-client/model/widgets/questions/templates/MultipleChoiceInputWidget.html
r443 r461 1 < div>2 </ div>1 <form> 2 </form> -
Dev/trunk/src/client/qed-client/model/widgets/questions/templates/NumberInputConfigWidget.html
r443 r461 1 < div>1 <form> 2 2 <div> 3 3 <label class="qedLabel" for="text">Item/Question Text</label> … … 16 16 <div class="qedField" data-dojo-type="dijit/form/NumberTextBox" data-dojo-props="constraints:{ min: 0 }" name="places"></div> 17 17 </div> 18 </ div>18 </form> -
Dev/trunk/src/client/qed-client/model/widgets/questions/templates/NumberInputWidget.html
r443 r461 1 < div>1 <form> 2 2 <p>${text}</p> 3 3 <div class="qedField" data-dojo-attach-point="numberBox" data-dojo-type="dijit/form/NumberTextBox" name="text"></div> 4 </ div>4 </form> -
Dev/trunk/src/client/qed-client/model/widgets/questions/templates/ScaleInputConfigWidget.html
r443 r461 1 < divclass="${baseClass}">1 <form class="${baseClass}"> 2 2 <table> 3 3 <thead> … … 46 46 </tbody> 47 47 </table> 48 </ div>48 </form> -
Dev/trunk/src/client/qed-client/model/widgets/questions/templates/ScaleInputWidget.html
r443 r461 1 < divclass="${baseClass}">1 <form class="${baseClass}"> 2 2 <table> 3 3 <thead> … … 12 12 </tbody> 13 13 </table> 14 </ div>14 </form> -
Dev/trunk/src/client/qed-client/model/widgets/questions/templates/StringInputConfigWidget.html
r443 r461 1 < div>1 <form> 2 2 <label class="qedLabel" for="text">Item/Question Text</label> 3 3 <div class="qedField" data-dojo-attach-point="textBox" data-dojo-type="dijit/form/TextBox" data-dojo-props="placeholder: 'Item/Question Text'" name="text"></div> 4 </ div>4 </form> -
Dev/trunk/src/client/qed-client/model/widgets/questions/templates/StringInputWidget.html
r443 r461 1 < div>1 <form> 2 2 <p>${text}</p> 3 3 <div data-dojo-attach-point="textBox" data-dojo-type="dijit/form/TextBox" name="text"></div> 4 </ div>4 </form> -
Dev/trunk/src/client/qed-client/model/widgets/questions/templates/TextConfigWidget.html
r443 r461 1 < div>1 <form> 2 2 <label for="text" class="qedLabel">Text</label> 3 3 <textarea class="qedField" data-dojo-type="dijit/form/Textarea" name="text"></textarea> 4 </ div>4 </form> -
Dev/trunk/src/client/qed-client/model/widgets/questions/templates/TextInputConfigWidget.html
r443 r461 1 < div>1 <form> 2 2 <div> 3 3 <label class="qedLabel" for="text">Item/Question Text</label> … … 8 8 <div class="qedField" data-dojo-type="dijit/form/NumberTextBox" data-dojo-props="placeholder: 'Maximum length', constraints: { min: 0 }" name="maxLength"></div> 9 9 </div> 10 </ div>10 </form> -
Dev/trunk/src/client/qed-client/model/widgets/questions/templates/TextInputWidget.html
r443 r461 1 < div>1 <form> 2 2 <p>${text}</p> 3 3 <div class="qedField" data-dojo-attach-point="textArea" data-dojo-type="dijit/form/Textarea" name="text"></div> 4 </ div>4 </form> -
Dev/trunk/src/client/qed-client/model/widgets/templates/SurveyRenderWidget.html
r457 r461 1 < divclass="${baseClass}">2 </ div>1 <form class="${baseClass}"> 2 </form> -
Dev/trunk/src/client/qed-client/model/widgets/templates/SurveyRunWidget.html
r457 r461 1 < divclass="${baseClass}">1 <form class="${baseClass}"> 2 2 3 3 <div> … … 24 24 </div> 25 25 26 </ div>26 </form> -
Dev/trunk/src/client/qed-client/model/widgets/templates/SurveyWidget.html
r457 r461 1 <f ieldsetclass="${baseClass}">1 <form class="${baseClass}"> 2 2 <label for="title">Title</label> 3 3 <input data-dojo-type="dijit/form/TextBox" name="title"/><br/> 4 4 <label for="description">Description</label> 5 5 <input data-dojo-type="dijit/form/Textarea" name="description"/><br/> 6 </f ieldset>6 </form> -
Dev/trunk/src/client/qed-client/pages/response.js
r443 r461 1 1 define([ 2 "../app/Content", 2 3 "../app/Page", 3 4 "../lib/async", … … 13 14 "require", 14 15 "dojo/text!./templates/response.html" 15 ], function( Page, async, Response, Survey, SurveyRun, store, declare, event, lang, all, when, require, template) {16 ], function(Content, Page, async, Response, Survey, SurveyRun, store, declare, event, lang, all, when, require, template) { 16 17 return declare([Page],{ 17 18 contextRequire: require, … … 24 25 if ( this._started ) { return; } 25 26 this.inherited(arguments); 26 this._disable Buttons();27 this._disableSubmit(); 27 28 var surveyRunId = this.surveyRunId; 28 29 var responseId = this.options && this.options.id; 29 30 if ( surveyRunId && responseId ) { 30 31 this._loadSurveyAndResponse(surveyRunId,responseId) 31 .then(lang.hitch(this,"_enableButtons")); 32 .then(lang.hitch(this, function() { 33 if ( this.response.publicationDate ) { 34 this._showInfo("<div>You already submitted your survey and cannot change it anymore. You can still view your answers here.</div>"); 35 this._disableSubmit(); 36 } else { 37 this._enableSubmit(); 38 } 39 }), function() { 40 this._showInfo("<div>The url seems to be incorrect, no survey found.</div>"); 41 }); 32 42 } else { 33 43 throw new Error("No valid uid or survey passed!"); … … 43 53 } 44 54 this.titleNode.innerHTML = Survey.DisplayTitle.get(surveyRun.survey); 45 this.surveyWidget.set('survey', surveyRun.survey);46 this. responseForm.set('value',this.response.answers || {});55 this.surveyWidget.set('survey', surveyRun.survey); 56 this.surveyWidget.set('value', this.response.answers || {}); 47 57 })); 48 58 }, 49 _enable Buttons: function() {59 _enableSubmit: function() { 50 60 this.submitButton.set('disabled',false); 51 61 this.continueButton.set('disabled',false); 62 this.surveyWidget.set('disabled', false); 52 63 }, 53 _disable Buttons: function() {64 _disableSubmit: function() { 54 65 this.submitButton.set('disabled',true); 55 66 this.continueButton.set('disabled',true); 67 this.surveyWidget.set('disabled', true); 68 }, 69 _showInfo: function(html) { 70 this.infoNode.innerHTML = html; 56 71 }, 57 72 _getAnswersAndSaveResponse: function() { 58 this.response.answers = this.responseForm.get('value'); 59 console.log(this.response); 60 return store.put(this.response); 73 var answers = this.surveyWidget.get('value'); 74 this.response.answers = answers; 75 return store.put(this.response).then(function(){ 76 Content.notify("Your response is saved."); 77 }, function(err){ 78 Content.notify(err,'error'); 79 }); 61 80 }, 62 81 _onSubmit: function(e) { 63 82 this.response.publicationDate = store.timestamp(); 64 this._getAnswersAndSaveResponse(); 65 this.content.domNode.innerHTML = "<div>Thanks for filling in the survey.</div>"; 83 this._getAnswersAndSaveResponse() 84 .then(function(){ 85 this._showInfo("<div>Thanks for filling in the survey. You cannot edit your answers anymore.</div>"); 86 this._disableSubmit(); 87 }); 66 88 if ( e ) { event.stop(e); } 67 89 return false; 68 90 }, 69 91 _onContinueLater: function(e) { 70 this._getAnswersAndSaveResponse(); 71 this.content.domNode.innerHTML = "<div>To continue with this survey later, just save the URL in the location bar and revisit it later. Your answers will still be there.</div>"; 92 this._getAnswersAndSaveResponse() 93 .then(lang.hitch(this,function(){ 94 this._showInfo("<div>To continue with this survey later, just save the URL in the location bar and revisit it later. Your answers will still be there.</div>"); 95 })); 72 96 if ( e ) { event.stop(e); } 73 97 return false; -
Dev/trunk/src/client/qed-client/pages/templates/response.html
r457 r461 6 6 <span class="headerText" data-dojo-attach-point="titleNode">Survey</span> 7 7 </h2> 8 <div data-dojo-attach-point="infoNode"></div> 8 9 </div> 9 10 10 11 <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'" data-dojo-attach-point="content"> 11 <form data-dojo-type="dijit/form/Form" data-dojo-attach-point="responseForm" 12 data-dojo-attach-event="onSubmit:_ignoreEvent" style="overflow: auto"> 13 <div data-dojo-type="../model/widgets/SurveyRenderWidget" data-dojo-attach-point="surveyWidget"></div> 14 </form> 12 <div name="answers" data-dojo-type="../model/widgets/SurveyRenderWidget" data-dojo-attach-point="surveyWidget"></div> 15 13 </div> 16 14 -
Dev/trunk/src/client/qed-client/store/CouchStore.js
r446 r461 12 12 var reason = err.response && 13 13 err.response.data && 14 json.fromJson(err.response.data).reason;14 err.response.data.reason; 15 15 return reason || "Unknown error."; 16 16 } -
Dev/trunk/src/client/qed-client/widgets/_ComplexValueMixin.js
r443 r461 3 3 "dijit/form/_FormMixin", 4 4 "dojo/_base/array", 5 "dojo/_base/declare" 6 ], function(_Container, _FormMixin, array, declare) { 5 "dojo/_base/declare", 6 "dojo/_base/event" 7 ], function(_Container, _FormMixin, array, declare, event) { 7 8 return declare([_Container,_FormMixin],{ 8 9 name: "", … … 10 11 disabled: false, 11 12 readOnly: false, 13 postCreate: function() { 14 this.inherited(arguments); 15 if ( this.domNode.tagName.toLowerCase() !== "form" ) { 16 console.warn("Not scoping a _ComplexValueMixin in a form element can cause name clashes. E.g. radio buttons might stop working correctly. It is recommended to use <form> as the root element in your template for "+this.declaredClass+"."); 17 } 18 }, 12 19 _setDisabledAttr: function(value) { 13 20 this._set("disabled", value); … … 27 34 children[0].focus(); 28 35 } 36 }, 37 onSubmit: function(e) { 38 // since this widget is used to create more complex 39 // widgets within other forms, the onSubmit must either be 40 // ignored or propagated, but not handled here. 41 if ( e ) { event.stop(e); } 42 return false; 43 }, 44 _onSubmit: function(e) { 45 // since this widget is used to create more complex 46 // widgets within other forms, the onSubmit must either be 47 // ignored or propagated, but not handled here. 48 if ( e ) { event.stop(e); } 49 return false; 29 50 } 30 51 });
Note: See TracChangeset
for help on using the changeset viewer.