[virtualcommons-svn] SF.net SVN: virtualcommons:[171] mentalmodels/trunk/flex/src
Status: Beta
Brought to you by:
alllee
From: <kj...@us...> - 2009-07-05 23:47:59
|
Revision: 171 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=171&view=rev Author: kjonas Date: 2009-07-05 23:47:57 +0000 (Sun, 05 Jul 2009) Log Message: ----------- trying to re-commit restructured folders, new features with FisheryExperimentShell.mxml (InformationWindowPopup.mxml, etc) Modified Paths: -------------- mentalmodels/trunk/flex/src/_InstructionsTest.mxml Added Paths: ----------- mentalmodels/trunk/flex/src/FisheryExperimentShell.mxml mentalmodels/trunk/flex/src/custom/ mentalmodels/trunk/flex/src/custom/FisheryExperimentKalin.mxml mentalmodels/trunk/flex/src/custom/InformationWindowPopup.mxml mentalmodels/trunk/flex/src/custom/InstructionPage.mxml mentalmodels/trunk/flex/src/custom/SocioDemographicPage.mxml mentalmodels/trunk/flex/src/custom/TimeLabel.mxml mentalmodels/trunk/flex/src/custom/db/ mentalmodels/trunk/flex/src/custom/db/Block.mxml mentalmodels/trunk/flex/src/custom/db/Module.mxml mentalmodels/trunk/flex/src/custom/db/Question.mxml mentalmodels/trunk/flex/src/custom/db/QuestionGroup.mxml mentalmodels/trunk/flex/src/custom/db/questions/ mentalmodels/trunk/flex/src/custom/db/questions/Categorical.mxml mentalmodels/trunk/flex/src/custom/db/questions/CategoricalQuestion.mxml mentalmodels/trunk/flex/src/custom/db/questions/CategoricalRelative.mxml mentalmodels/trunk/flex/src/custom/db/questions/CategoricalSimple.mxml mentalmodels/trunk/flex/src/custom/db/questions/Psychometric.mxml mentalmodels/trunk/flex/src/custom/questions/ mentalmodels/trunk/flex/src/custom/questions/CategoricalQuestionC.mxml mentalmodels/trunk/flex/src/custom/questions/TextQuestionC.mxml Removed Paths: ------------- mentalmodels/trunk/flex/src/FisheryExperimentKalin.mxml Deleted: mentalmodels/trunk/flex/src/FisheryExperimentKalin.mxml =================================================================== --- mentalmodels/trunk/flex/src/FisheryExperimentKalin.mxml 2009-07-05 19:50:39 UTC (rev 170) +++ mentalmodels/trunk/flex/src/FisheryExperimentKalin.mxml 2009-07-05 23:47:57 UTC (rev 171) @@ -1,308 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:net="flash.net.*" xmlns:comp="custom.*" - backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#FFFFFF, #B0B0FF]" - width="100%" height="100%" clipContent="false" layout="absolute" - currentState="socioDemographic" initialize="init()"> - - <mx:states> - <mx:State name="socioDemographic"> - <mx:AddChild relativeTo="{content}"> - <comp:SocioDemographicPage id="socioDemographic" - x="{(content.width-socioDemographic.width)/2}" - y="{(content.height-socioDemographic.height)/2}"/> - </mx:AddChild> - <mx:SetProperty target="{content}" name="x"/> - <mx:SetStyle target="{content}" name="horizontalCenter" value="0"/> - </mx:State> - - <mx:State name="instructions"> - <mx:AddChild relativeTo="{content}"> - <!--<comp:InstructionPage id="instructions" initialize="instructions.init(makeBlock())"/>--> - <comp:InstructionPage id="instructions" initialize="instructions.initModule(currModule)"/> - </mx:AddChild> - </mx:State> - - <mx:State name="wait"> - <mx:AddChild relativeTo="{content}"> - <mx:Label id="lblWaiting" text="Waiting for next Module from server..." fontSize="16"/> - </mx:AddChild> - </mx:State> - - <mx:State name="none"> - <mx:AddChild relativeTo="{content}"> - <mx:Label id="end" text="Thank you for playing!" fontSize="30"/> - </mx:AddChild> - </mx:State> - </mx:states> - - - - <!-- <mx:Canvas id="content" x="5" y="5" width="750" height="470"/> --> - <mx:Canvas id="content" x="0" y="0" width="100%" height="100%"/> - <mx:Canvas id="expiredContent" x="-1" y="-1" width="1" height="1" visible="false"/> - - <mx:Button id="btnBack" label="« Back" click="back()" left="8" bottom="8" enabled="false"/> - <mx:Button id="btnAccept" label="Accept" click="accept()" left="{(width-btnAccept.width)/2}" bottom="10"/> - <mx:Button id="btnForward" label="Forward »" click="forward()" right="8" bottom="8" enabled="false"/> - - <mx:RemoteObject id="ss" destination="studentService" fault="faultHandler(event)" result="resultHandler(event)"/> - <mx:Producer id="producer" destination="DataPush" acknowledge="ack(event)"/> - <mx:Consumer id="consumer" destination="DataPush" message="messageHandler(event.message)" /> - <mx:Script> - <![CDATA[ - import actionscript.*; - import actionscript.questions.*; - import custom.*; - import mx.controls.Label; - import mx.controls.Alert; - import mx.collections.ArrayCollection; - import flash.sampler.getInvocationCount; - import mx.rpc.events.ResultEvent; - import mx.rpc.events.FaultEvent; - import mx.messaging.messages.IMessage; - import mx.messaging.events.MessageAckEvent; - import mx.messaging.events.MessageFaultEvent; - import mx.messaging.FlexClient; - import mx.messaging.messages.AsyncMessage; - - - // - // Important Variables - // - public var currModule:Module = null; - - private var shared:SharedObject; - private var flushMessage:String; - [Bindable] - public var Id : uint; - - [Bindable] - public var randomNumbers:String; - private function ack(event:MessageAckEvent):void - { - //chart.setVisible(true); - randomNumbers = event.message.body as String; - //Alert.show("in ack method" + randomNumbers); - } - private function resultHandler(event:ResultEvent):void - { - Id = event.result as uint; - -// Alert.show("Student id is " + Id ); - consumer.disconnect(); - } - - private function faultHandler(event:FaultEvent):void - { -// Alert.show("event fault is " + event.fault.faultDetail); - } - - private function handleFault(event:MessageFaultEvent):void - { -// Alert.show("Message event fault is " + event.faultString); - } - - - private function messageHandler(message:IMessage):void - { - randomNumbers = message.body as String; -// Alert.show( ""+randomNumbers); - } - - public function init():void - { - - } - - private function getModule():Module - { - // server request here - - currModule = null; - return currModule; // set to null for now (clear old) - } - - public function back():Boolean - { - if(content.numChildren == 0) - { return false; } - var obj:DisplayObject = content.getChildAt(0); - - if(obj is InstructionPage) - { - try - { - return (InstructionPage)(obj).back(); - } - catch(err:Error){} - } - return false; - } - - public function forward():Boolean - { - if(content.numChildren == 0) - { return false; } - var obj:DisplayObject = content.getChildAt(0); - - if(obj is InstructionPage) - { - try - { - return (InstructionPage)(obj).forward(); - } - catch(err:Error){} - } - return false; - } - - public function accept():Boolean - { - if(content.numChildren == 0) - { return false; } - - var obj:DisplayObject = content.getChildAt(0); - var returnValue:Boolean = false; - - if(obj is SocioDemographicPage) - { - var Id:uint = 0; - if( (SocioDemographicPage)(obj).accept() ) - { - obj.visible = false; - expiredContent.addChild(obj); - - // - // TEMPORARY CODE - // comments indicate changes to be made for legitimate server communication - // - currModule = new Module(); //delete - currModule.blocks = new ArrayCollection(); //delete - currModule.blocks.addItem(makeBlock()); //delete - currModule.blocks.addItem(makeBlock()); //delete - currentState = "instructions"; //change to state "wait", which will call getModule() - // - // END TEMPORARY CODE - // - - - var info:SocioDemographicPage = SocioDemographicPage(obj); - /* Alert.show(info.getGender()); - Alert.show(info.getMajor()); - Alert.show(info.getSemester()); - Alert.show(info.getYear());*/ - Id=ss.createStudent(info.getYear(), info.getSemester(), info.getGender(),info.getMajor()); -// Alert.show("Before invoking createstudent()"); - - btnBack.enabled = true; - btnForward.enabled = true; - - returnValue = true; - } - } - if(obj is InstructionPage) - { - try - { - if( (InstructionPage)(obj).accept() ) - { - obj.visible = false; - expiredContent.addChild(obj); - currentState = "wait"; - //consumer.subscribe(); - returnValue = true; - } - } - catch(err:Error){} - } - - btnBack.enabled = btnForward.enabled = currentState == "instructions"; - - return returnValue; - } - - public function makeBlock():Block - { - var block1:Block = new Block(); - try{ - var questionGroups1:ArrayCollection = new ArrayCollection(); - var qg0:QuestionGroup = new QuestionGroup(); - var qg1:QuestionGroup = new QuestionGroup(); - var qg2:QuestionGroup = new QuestionGroup(); - var qg3:QuestionGroup = new QuestionGroup(); - var qg4:QuestionGroup = new QuestionGroup(); - var qg5:QuestionGroup = new QuestionGroup(); - var qg6:QuestionGroup = new QuestionGroup(); - qg0.questions = new ArrayCollection(); - qg1.questions = new ArrayCollection(); - qg2.questions = new ArrayCollection(); - qg3.questions = new ArrayCollection(); - qg4.questions = new ArrayCollection(); - qg5.questions = new ArrayCollection(); - qg6.questions = new ArrayCollection(); - block1.questionGroups = new ArrayCollection(); - - // create questions - var ddq1:Question = new Question(); - ddq1.question = "dayByDayDecisionsQuestion"; - ddq1.type = "dayByDayDecisions"; - - var cat1:Categorical = new Categorical(); - cat1.question = "categoricalQuestion"; - cat1.type = "categorical"; - cat1.topics = new ArrayCollection(); - cat1.specifics = new ArrayCollection(); - - var for1:ForecastingPeople = new ForecastingPeople(); - var for2:ForecastingFish = new ForecastingFish(); - - var psy1:PsychometricQuestion = new PsychometricQuestion(); - psy1.question = "psychometricQuestion"; - psy1.type = "psychometric"; - psy1.numberOfIntervals = 10; - psy1.choices = new ArrayCollection(); - psy1.choices.addItem("Highly Agree"); - psy1.choices.addItem("Highly Neutral"); - psy1.choices.addItem("Highly Disagree"); - - var str1:Question = new Question(); - str1.question = "strategyDesignQuestion"; - str1.type = "strategyDesign"; - - var txt1:Question = new Question(); - txt1.question = "textQuestion"; - txt1.type = "text"; - - // insert questions into groups - qg0.questions.addItem(ddq1); - qg1.questions.addItem(cat1); - qg2.questions.addItem(for1); - qg3.questions.addItem(for2); - qg4.questions.addItem(psy1); - qg5.questions.addItem(str1); - qg6.questions.addItem(txt1); - - qg1.description = "testDesc"; - qg1.header = "testHead"; - - block1.questionGroups.addItem(qg0); - block1.questionGroups.addItem(qg1); - block1.questionGroups.addItem(qg2); - block1.questionGroups.addItem(qg3); - block1.questionGroups.addItem(qg4); - block1.questionGroups.addItem(qg5); - block1.questionGroups.addItem(qg6); - - - }catch(errObject:Error){ - Alert.show("block creation failure\n" + - errObject.message + "\n" + errObject.getStackTrace()); - } - return block1; - } - - ]]> - </mx:Script> - -</mx:Application> - Added: mentalmodels/trunk/flex/src/FisheryExperimentShell.mxml =================================================================== --- mentalmodels/trunk/flex/src/FisheryExperimentShell.mxml (rev 0) +++ mentalmodels/trunk/flex/src/FisheryExperimentShell.mxml 2009-07-05 23:47:57 UTC (rev 171) @@ -0,0 +1,106 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" + backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#FFFFFF, #B0B0FF]" + layout="horizontal" + width="100%" height="100%" xmlns:custom="custom.*"> + + <mx:VBox id="vbxInfo"> + <mx:TitleWindow id="InformationWindowA" width="300" height="200" title="Information Window A" + clipContent="true" horizontalScrollPolicy="on" verticalScrollPolicy="on"> + <mx:Label text="InfoA"/> + </mx:TitleWindow> + <mx:HBox id="hbxPickerA"> + <mx:ComboBox id="cbxPickerA"/> + <mx:Button id="btnPickerA" label="Pop Up" click="popupInformationWindow(1)"/> + </mx:HBox> + + <mx:TitleWindow id="InformationWindowB" width="300" height="200" title="Information Window B" + clipContent="true" horizontalScrollPolicy="on" verticalScrollPolicy="on"> + <mx:Label text="InfoB"/> + </mx:TitleWindow> + <mx:HBox id="hbxPickerB"> + <mx:ComboBox id="cbxPickerB"/> + <mx:Button id="btnPickerB" label="{btnPickerA.label}" click="popupInformationWindow(2)"/> + </mx:HBox> + <mx:Button id="btnResetPopups" label="Reset Popups" click="closedFunction()"/> + </mx:VBox> + + <mx:VBox id="vbxContent" horizontalAlign="center" verticalAlign="middle" + width="{this.width - 400}" + height="{this.height - 80}"> + <custom:FisheryExperimentKalin id="fisheryContent"/> + </mx:VBox> + + <mx:Script> + <![CDATA[ + import mx.skins.halo.TitleBackground; + import custom.InformationWindowPopup; + import mx.managers.PopUpManager; + + public var popupA:InformationWindowPopup = null; + public var popupB:InformationWindowPopup = null; + + public function popupInformationWindow(source:int):void + { + var popupNew:InformationWindowPopup = PopUpManager.createPopUp(this, InformationWindowPopup, false) as InformationWindowPopup; + popupNew.closedFunction = closedFunction; + popupNew.horizontalScrollPolicy = "on"; + popupNew.verticalScrollPolicy = "on"; + + var old:TitleWindow = null; + + if(source == 1) + { + old = InformationWindowA; + popupA = popupNew; + btnPickerA.enabled = cbxPickerA.enabled = false; + } + else if(source == 2) + { + old = InformationWindowB; + popupB = popupNew; + btnPickerB.enabled = cbxPickerB.enabled = false; + } + else + { + return; + } + + while(old != null && old.numChildren > 0) + { + popupNew.addChild(old.removeChildAt(0)) + } + + PopUpManager.centerPopUp(popupNew); + } + + public function closedFunction():void + { + if(popupA != null) + { + while(popupA.numChildren > 0) + { + InformationWindowA.addChild(popupA.removeChildAt(0)) + } + PopUpManager.removePopUp(popupA); + popupA = null; + } + + if(popupB != null) + { + while(popupB.numChildren > 0) + { + InformationWindowB.addChild(popupB.removeChildAt(0)) + } + PopUpManager.removePopUp(popupB); + popupB = null; + } + + btnPickerA.enabled = btnPickerB.enabled = true; + cbxPickerA.enabled = cbxPickerB.enabled = true; + } + + ]]> + </mx:Script> + +</mx:Application> Modified: mentalmodels/trunk/flex/src/_InstructionsTest.mxml =================================================================== --- mentalmodels/trunk/flex/src/_InstructionsTest.mxml 2009-07-05 19:50:39 UTC (rev 170) +++ mentalmodels/trunk/flex/src/_InstructionsTest.mxml 2009-07-05 23:47:57 UTC (rev 171) @@ -1,10 +1,48 @@ <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:comp="custom.*" xmlns:as="actionscript.*" - layout="vertical" - backgroundGradientColors="[#FFFFFF, #B0B0FF]"> - + layout="horizontal" + backgroundGradientColors="[#FFFFFF, #B0B0FF]"> + + <mx:VBox id="vbxInfo"> + <mx:TitleWindow id="InformationWindowA" width="300" height="200" title="Information Window A"/> + <mx:HBox id="hbxPickerA"> + <mx:ComboBox id="cbxPickerA"/> + <mx:Button id="btnPickerA" click="popupInformationWindow(1)"/> + </mx:HBox> + + <mx:TitleWindow id="InformationWindowB" width="300" height="200" title="Information Window B"/> + <mx:HBox id="hbxPickerB"> + <mx:ComboBox id="cbxPickerB"/> + <mx:Button id="btnPickerB" click="popupInformationWindow(2)"/> + </mx:HBox> + </mx:VBox> + <mx:Script> <![CDATA[ + import custom.InformationWindowPopup; + import mx.managers.PopUpManager; + + public function popupInformationWindow(source:int):void + { +// Alert.cancelLabel = "Close"; +// var flags:uint = Alert.NONMODAL | Alert.CANCEL; +// var alert:Alert = Alert.show("::","Information Window",flags,null,null,null,Alert.CANCEL) + + var win:InformationWindowPopup = PopUpManager.createPopUp(this, InformationWindowPopup, false) as InformationWindowPopup; + PopUpManager.centerPopUp(win); + win.closedFunction = closedFunction; + } + + public function closedFunction():void + { + btnPickerA.label += "."; + } + + ]]> + </mx:Script> + + <mx:Script> + <![CDATA[ import custom.questions.CategoricalQuestionC; import actionscript.* import actionscript.questions.*; @@ -86,13 +124,15 @@ ]]> </mx:Script> - <mx:HBox> - <mx:Button id="back" click="iPage.back()" label="back"/> - <mx:Button id="forward" click="iPage.forward()" label="forward"/> - </mx:HBox> + <mx:VBox id="vbxContent" minWidth="700" horizontalAlign="center"> + <mx:HBox> + <mx:Button id="back" click="iPage.back()" label="back"/> + <mx:Button id="forward" click="iPage.forward()" label="forward"/> + </mx:HBox> + + <mx:Text id="debug" text=""/> + + <comp:InstructionPage id="iPage" preinitialize="fillBlock()" initialize="iPage.init(block1)"/> + </mx:VBox> - <mx:Text id="debug" text=""/> - - <comp:InstructionPage id="iPage" preinitialize="fillBlock()" initialize="iPage.init(block1)"/> - </mx:Application> Added: mentalmodels/trunk/flex/src/custom/FisheryExperimentKalin.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/FisheryExperimentKalin.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/FisheryExperimentKalin.mxml 2009-07-05 23:47:57 UTC (rev 171) @@ -0,0 +1,308 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:net="flash.net.*" xmlns:comp="custom.*" + clipContent="false" verticalScrollPolicy="off" horizontalScrollPolicy="off" + currentState="socioDemographic" initialize="init()" + width="100%" height="100%"> + + <mx:states> + <mx:State name="socioDemographic"> + <mx:AddChild relativeTo="{content}"> + <comp:SocioDemographicPage id="socioDemographic" + x="{(content.width-socioDemographic.width)/2}" + y="{(content.height-socioDemographic.height)/2}"/> + </mx:AddChild> + <mx:SetProperty target="{content}" name="x"/> + <mx:SetStyle target="{content}" name="horizontalCenter" value="0"/> + </mx:State> + + <mx:State name="instructions"> + <mx:AddChild relativeTo="{content}"> + <!--<comp:InstructionPage id="instructions" initialize="instructions.init(makeBlock())"/>--> + <comp:InstructionPage id="instructions" initialize="instructions.initModule(currModule)"/> + </mx:AddChild> + </mx:State> + + <mx:State name="wait"> + <mx:AddChild relativeTo="{content}"> + <mx:Label id="lblWaiting" text="Waiting for next Module from server..." fontSize="16"/> + </mx:AddChild> + </mx:State> + + <mx:State name="none"> + <mx:AddChild relativeTo="{content}"> + <mx:Label id="end" text="Thank you for playing!" fontSize="30"/> + </mx:AddChild> + </mx:State> + </mx:states> + + + + <!-- <mx:Canvas id="content" x="5" y="5" width="750" height="470"/> --> + <mx:Canvas id="content" x="0" y="0" width="100%" height="100%"/> + <mx:Canvas id="expiredContent" x="-1" y="-1" width="1" height="1" visible="false"/> + + <mx:Button id="btnBack" label="« Back" click="back()" left="8" bottom="8" enabled="false"/> + <mx:Button id="btnAccept" label="Accept" click="accept()" left="{(width-btnAccept.width)/2}" bottom="10"/> + <mx:Button id="btnForward" label="Forward »" click="forward()" right="8" bottom="8" enabled="false"/> + + <mx:RemoteObject id="ss" destination="studentService" fault="faultHandler(event)" result="resultHandler(event)"/> + <mx:Producer id="producer" destination="DataPush" acknowledge="ack(event)"/> + <mx:Consumer id="consumer" destination="DataPush" message="messageHandler(event.message)" /> + <mx:Script> + <![CDATA[ + import actionscript.*; + import actionscript.questions.*; + import custom.*; + import mx.controls.Label; + import mx.controls.Alert; + import mx.collections.ArrayCollection; + import flash.sampler.getInvocationCount; + import mx.rpc.events.ResultEvent; + import mx.rpc.events.FaultEvent; + import mx.messaging.messages.IMessage; + import mx.messaging.events.MessageAckEvent; + import mx.messaging.events.MessageFaultEvent; + import mx.messaging.FlexClient; + import mx.messaging.messages.AsyncMessage; + + + // + // Important Variables + // + public var currModule:Module = null; + + private var shared:SharedObject; + private var flushMessage:String; + [Bindable] + public var Id : uint; + + [Bindable] + public var randomNumbers:String; + private function ack(event:MessageAckEvent):void + { + //chart.setVisible(true); + randomNumbers = event.message.body as String; + //Alert.show("in ack method" + randomNumbers); + } + private function resultHandler(event:ResultEvent):void + { + Id = event.result as uint; + +// Alert.show("Student id is " + Id ); + consumer.disconnect(); + } + + private function faultHandler(event:FaultEvent):void + { +// Alert.show("event fault is " + event.fault.faultDetail); + } + + private function handleFault(event:MessageFaultEvent):void + { +// Alert.show("Message event fault is " + event.faultString); + } + + + private function messageHandler(message:IMessage):void + { + randomNumbers = message.body as String; +// Alert.show( ""+randomNumbers); + } + + public function init():void + { + + } + + private function getModule():Module + { + // server request here + + currModule = null; + return currModule; // set to null for now (clear old) + } + + public function back():Boolean + { + if(content.numChildren == 0) + { return false; } + var obj:DisplayObject = content.getChildAt(0); + + if(obj is InstructionPage) + { + try + { + return (InstructionPage)(obj).back(); + } + catch(err:Error){} + } + return false; + } + + public function forward():Boolean + { + if(content.numChildren == 0) + { return false; } + var obj:DisplayObject = content.getChildAt(0); + + if(obj is InstructionPage) + { + try + { + return (InstructionPage)(obj).forward(); + } + catch(err:Error){} + } + return false; + } + + public function accept():Boolean + { + if(content.numChildren == 0) + { return false; } + + var obj:DisplayObject = content.getChildAt(0); + var returnValue:Boolean = false; + + if(obj is SocioDemographicPage) + { + var Id:uint = 0; + if( (SocioDemographicPage)(obj).accept() ) + { + obj.visible = false; + expiredContent.addChild(obj); + + // + // TEMPORARY CODE + // comments indicate changes to be made for legitimate server communication + // + currModule = new Module(); //delete + currModule.blocks = new ArrayCollection(); //delete + currModule.blocks.addItem(makeBlock()); //delete + currModule.blocks.addItem(makeBlock()); //delete + currentState = "instructions"; //change to state "wait", which will call getModule() + // + // END TEMPORARY CODE + // + + + var info:SocioDemographicPage = SocioDemographicPage(obj); + /* Alert.show(info.getGender()); + Alert.show(info.getMajor()); + Alert.show(info.getSemester()); + Alert.show(info.getYear());*/ + Id=ss.createStudent(info.getYear(), info.getSemester(), info.getGender(),info.getMajor()); +// Alert.show("Before invoking createstudent()"); + + btnBack.enabled = true; + btnForward.enabled = true; + + returnValue = true; + } + } + if(obj is InstructionPage) + { + try + { + if( (InstructionPage)(obj).accept() ) + { + obj.visible = false; + expiredContent.addChild(obj); + currentState = "wait"; + //consumer.subscribe(); + returnValue = true; + } + } + catch(err:Error){} + } + + btnBack.enabled = btnForward.enabled = currentState == "instructions"; + + return returnValue; + } + + public function makeBlock():Block + { + var block1:Block = new Block(); + try{ + var questionGroups1:ArrayCollection = new ArrayCollection(); + var qg0:QuestionGroup = new QuestionGroup(); + var qg1:QuestionGroup = new QuestionGroup(); + var qg2:QuestionGroup = new QuestionGroup(); + var qg3:QuestionGroup = new QuestionGroup(); + var qg4:QuestionGroup = new QuestionGroup(); + var qg5:QuestionGroup = new QuestionGroup(); + var qg6:QuestionGroup = new QuestionGroup(); + qg0.questions = new ArrayCollection(); + qg1.questions = new ArrayCollection(); + qg2.questions = new ArrayCollection(); + qg3.questions = new ArrayCollection(); + qg4.questions = new ArrayCollection(); + qg5.questions = new ArrayCollection(); + qg6.questions = new ArrayCollection(); + block1.questionGroups = new ArrayCollection(); + + // create questions + var ddq1:Question = new Question(); + ddq1.question = "dayByDayDecisionsQuestion"; + ddq1.type = "dayByDayDecisions"; + + var cat1:Categorical = new Categorical(); + cat1.question = "categoricalQuestion"; + cat1.type = "categorical"; + cat1.topics = new ArrayCollection(); + cat1.specifics = new ArrayCollection(); + + var for1:ForecastingPeople = new ForecastingPeople(); + var for2:ForecastingFish = new ForecastingFish(); + + var psy1:PsychometricQuestion = new PsychometricQuestion(); + psy1.question = "psychometricQuestion"; + psy1.type = "psychometric"; + psy1.numberOfIntervals = 10; + psy1.choices = new ArrayCollection(); + psy1.choices.addItem("Highly Agree"); + psy1.choices.addItem("Highly Neutral"); + psy1.choices.addItem("Highly Disagree"); + + var str1:Question = new Question(); + str1.question = "strategyDesignQuestion"; + str1.type = "strategyDesign"; + + var txt1:Question = new Question(); + txt1.question = "textQuestion"; + txt1.type = "text"; + + // insert questions into groups + qg0.questions.addItem(ddq1); + qg1.questions.addItem(cat1); + qg2.questions.addItem(for1); + qg3.questions.addItem(for2); + qg4.questions.addItem(psy1); + qg5.questions.addItem(str1); + qg6.questions.addItem(txt1); + + qg1.description = "testDesc"; + qg1.header = "testHead"; + + block1.questionGroups.addItem(qg0); + block1.questionGroups.addItem(qg1); + block1.questionGroups.addItem(qg2); + block1.questionGroups.addItem(qg3); + block1.questionGroups.addItem(qg4); + block1.questionGroups.addItem(qg5); + block1.questionGroups.addItem(qg6); + + + }catch(errObject:Error){ + Alert.show("block creation failure\n" + + errObject.message + "\n" + errObject.getStackTrace()); + } + return block1; + } + + ]]> + </mx:Script> + +</mx:Canvas> + Added: mentalmodels/trunk/flex/src/custom/InformationWindowPopup.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/InformationWindowPopup.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/InformationWindowPopup.mxml 2009-07-05 23:47:57 UTC (rev 171) @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" + layout="vertical" + title="Information Window Popup" + showCloseButton="true" + close="titleWindow_close(event);" + width="700" height="500"> + + <mx:Script> + <![CDATA[ + import mx.events.CloseEvent; + import mx.managers.PopUpManager; + + public var closedFunction:Function = null; + public var valid:Boolean = true; + + private function titleWindow_close(evt:CloseEvent):void + { + closedFunction.call(); + } + ]]> + </mx:Script> + +</mx:TitleWindow> Added: mentalmodels/trunk/flex/src/custom/InstructionPage.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/InstructionPage.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/InstructionPage.mxml 2009-07-05 23:47:57 UTC (rev 171) @@ -0,0 +1,173 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:comp="custom.*" xmlns:as="actionscript.*"> + + <mx:Script> + <![CDATA[ + import actionscript.Module; + import custom.questions.forecasting.*; + import mx.controls.Alert; + import actionscript.Block; + import actionscript.PageDisplay; + import mx.collections.ArrayCollection; + + [Bindable] public var module:Module; + [Bindable] public var currBlock:int = 0; + [Bindable] public var block:Block; + [Bindable] public var pageDisplay:PageDisplay; + [Bindable] public var numPages:int = 1; + [Bindable] public var currPage:int = 0; + + public var savedForecastPeople:ArrayCollection = null; + + + public function initModule(newModule:actionscript.Module):void + { + module = newModule; + currBlock = 0; + init(module.blocks.getItemAt(currBlock) as Block); + } + + public function init(newBlock:Block):void + { + block = newBlock; + try{ +// debug.text += "creating pageDisplay...\n"; + var minPagesRead:int = 0; + if(block != null && block.questionGroups != null) + { + minPagesRead = block.questionGroups.length + } + pageDisplay = new PageDisplay(block, minPagesRead); + if(pageDisplay == null) + { + debug.text += "pageDisplay is null"; + } +// pageDisplay = new PageDisplay(block, block.questionGroups.length); + + + + }catch(errObject:Error){ + debug.text += "pageDisplay creation failure\n" + + errObject.message +"\n"+ errObject.getStackTrace() +"\n"; +// Alert.show(debug.text); + } + +// debug.text += "setting currPage...\n"; + currPage = pageDisplay.currentPageNumber; +// debug.text += "setting numPages...\n"; + numPages = pageDisplay.pages.length; + +// debug.text += "adding currentPage...\n"; + content.addChild(pageDisplay.currentPage); +// debug.text += "currentPage added.\n"; + } + + public function back():Boolean + { + preTurn(); + var pageSuccess:Boolean = pageDisplay.prevPage(); + if(pageSuccess) + { + postTurn(); + } + return pageSuccess; + } + + public function forward():Boolean + { + preTurn(); + var pageSuccess:Boolean = pageDisplay.nextPage(); + if(pageSuccess) + { + postTurn(); + } + return pageSuccess; + } + private function preTurn():void + { + var currPageArray:Array = (pageDisplay.currentPage as VBox).getChildren(); + for(var i:int = 0; i < currPageArray.length; i++) + { + if(currPageArray[i] is ForecastingPeopleQuestionC) + { + savedForecastPeople = (currPageArray[i] as ForecastingPeopleQuestionC).save(); + } + } + } + private function postTurn():void + { + currPage = pageDisplay.currentPageNumber; + currPageLabel.text = "Page " + (currPage+1) + " / " + numPages; + + content.removeAllChildren(); + content.addChild(pageDisplay.currentPage); + + var currPageArray:Array = (pageDisplay.currentPage as VBox).getChildren(); + for(var i:int = 0; i < currPageArray.length; i++) + { + if(currPageArray[i] is ForecastingFishQuestionC) + { + (currPageArray[i] as ForecastingFishQuestionC).loadPeopleOnly(savedForecastPeople); + } + } + + } + + public function accept():Boolean // true iff completely finished with module + { + try + { + if(pageDisplay.finished()) + { + //switch blocks within module + var nextBlock:int = currBlock+1; + if(nextBlock < module.blocks.length) + { + content.removeAllChildren(); + + currBlock = nextBlock; + init(module.blocks.getItemAt(currBlock) as Block); + numPages = 1; + return false; + } + else + { + //server stuff goes here + + return true; // module finished + } + } + else + { + Alert.show("Cannot advance.\nTry looking at every page."); + } + return false; + } + catch(err:Error) + { + Alert.show("accepterror"+err.message+err.getStackTrace()); + } + return false; + } + + public function save():ArrayCollection + { + var saveArray:ArrayCollection = new ArrayCollection(); + saveArray.addItem(block); + return saveArray; + } + + public function load(loadArray:ArrayCollection):void + { + block = (loadArray.getItemAt(0) as Block); + } + + ]]> + </mx:Script> + + <mx:Label id="currPageLabel" text="Page {(currPage+1)} / {numPages}"/> +<mx:Text id="debug" text="{pageDisplay.msg}" width="300"/> + + <mx:VBox id="content"/> + +</mx:VBox> Added: mentalmodels/trunk/flex/src/custom/SocioDemographicPage.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/SocioDemographicPage.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/SocioDemographicPage.mxml 2009-07-05 23:47:57 UTC (rev 171) @@ -0,0 +1,137 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" verticalAlign="middle" horizontalAlign="center"> + + <mx:Script> + <![CDATA[ + import mx.collections.ArrayCollection; + + public function getGender():String + { + if(radioMale.selected) { return "M"; } + if(radioFemale.selected) { return "F"; } + return "Err"; + } + public function getYear():String + { + return txtYear.text; + } + public function getMajor():String + { + return txtMajor.text; + } + public function getSemester():String + { + return txtSemester.text; + } + + public function accept():Boolean + { + // if any field is of improper length, this section is not completed + // flag/unflag an area with red if incomplete/complete + var ready:Boolean=true; + var bgcolor:String = "backgroundColor"; + var red:String = "#FF0000"; + var white:String = "#FFFFFF"; + + if(getGender().length != 1) // "M", "F", "Err" + { + boxGender.setStyle(bgcolor, red); + ready=false; + }else{ + boxGender.setStyle(bgcolor, ""); + } + + if(getYear().length != 4 || Number(getYear()) < 1900) + { + txtYear.setStyle(bgcolor, red); + ready=false; + }else{ + txtYear.setStyle(bgcolor, white); + } + + if(getMajor().length == 0) + { + txtMajor.setStyle(bgcolor, red); + ready=false; + }else{ + txtMajor.setStyle(bgcolor, white); + } + + if(getSemester().length == 0) + { + txtSemester.setStyle(bgcolor, red); + ready=false; + }else{ + txtSemester.setStyle(bgcolor, white); + } + + enable(!ready); + return ready; + } + + public function enable(enabled:Boolean=true):void + { + boxGender.enabled = enabled; + txtYear.enabled = enabled; + txtMajor.enabled = enabled; + txtSemester.enabled = enabled; + } + + public function save():ArrayCollection + { + var saveArray:ArrayCollection = new ArrayCollection(); + saveArray.addItem(getGender()); + saveArray.addItem(getYear()); + saveArray.addItem(getMajor()); + saveArray.addItem(getSemester()); + return saveArray; + } + + public function load(loadArray:ArrayCollection):void + { + var gender:String = (loadArray.getItemAt(0) as String); + if(gender != null && gender.length == 1) + { + radioMale.selected = (gender == "M"); + radioFemale.selected = (gender == "F"); + } + txtYear.text = (loadArray.getItemAt(1) as String); + txtMajor.text = (loadArray.getItemAt(2) as String); + txtSemester.text = (loadArray.getItemAt(3) as String); + } + + ]]> + </mx:Script> + + <mx:VBox id="content"> + <mx:VBox width="220" horizontalAlign="center"> + <mx:Label text="Personal Data" fontSize="18"/> + <mx:Label text="Please fill out the following fields:"/> + </mx:VBox> + + <mx:HBox> + <mx:Label text="Gender:" fontWeight="bold" width="100" textAlign="right"/> + <mx:HBox id="boxGender"> + <mx:RadioButtonGroup id="gender"/> + <mx:RadioButton groupName="{gender}" label="M" id="radioMale"/> + <mx:RadioButton groupName="{gender}" label="F" id="radioFemale"/> + </mx:HBox> + </mx:HBox> + + <mx:HBox> + <mx:Label text="Year of Birth:" fontWeight="bold" width="100" textAlign="right"/> + <mx:TextInput id="txtYear" width="75" maxChars="4"/> + </mx:HBox> + + <mx:HBox> + <mx:Label text="Major:" fontWeight="bold" width="100" textAlign="right"/> + <mx:TextInput id="txtMajor" width="120" maxChars="100"/> + </mx:HBox> + + <mx:HBox> + <mx:Label text="Semester:" fontWeight="bold" width="100" textAlign="right"/> + <mx:TextInput id="txtSemester" width="75" maxChars="6"/> + </mx:HBox> + </mx:VBox> + +</mx:VBox> Added: mentalmodels/trunk/flex/src/custom/TimeLabel.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/TimeLabel.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/TimeLabel.mxml 2009-07-05 23:47:57 UTC (rev 171) @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" + creationComplete="init()"> + + <mx:Script> + <![CDATA[ + [Bindable] private var showTime:String; + + private function init():void{ + // Update every second + var tmr:Timer = new Timer(1000); + tmr.addEventListener(TimerEvent.TIMER, changeTime); + tmr.start(); + } + + private function changeTime(event:TimerEvent):void{ + // Get Server Time + var serv:Date = new Date(); // *fix this* + + // Display Server Time + showTime = serv.toLocaleTimeString(); + } + ]]> + </mx:Script> + + <mx:Label text="{showTime}"/> + +</mx:Canvas> Added: mentalmodels/trunk/flex/src/custom/db/Block.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/db/Block.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/db/Block.mxml 2009-07-05 23:47:57 UTC (rev 171) @@ -0,0 +1,166 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:Form xmlns:mx="http://www.adobe.com/2006/mxml"> +<mx:Script> + <![CDATA[ + import mx.validators.NumberValidator; + import mx.validators.Validator; + import mx.events.ValidationResultEvent; + import mx.controls.Alert; + + [Bindable] + public var formIsEmpty:Boolean = true; + + [Bindable] + public var formIsValid:Boolean = false; + + + // Holds a reference to the currently focussed + // control on the form. + private var focussedFormControl:DisplayObject; + + public function getSequenceNo():String + { + return txtSeqNo.text; + } + public function getName():String + { + return txtName.text; + } + /*public function getDuration():String + { + //return txtMajor.text; + }*/ + + public function getHours():Number + { + return hours.value; + + } + public function getMinutes():Number + { + return minutes.value; + + } + public function getSeconds():Number + { + return seconds.value; + + } + + public function setSequenceNo(seqNo:String):void + { + txtSeqNo.text = seqNo; + } + public function setName(name:String):void + { + txtName.text = name; + } + + + public function setHours(hour:Number):void + { + hours.value = hour; + + } + public function setMinutes(min:Number):void + { + minutes.value = min; + + } + public function setSeconds(sec:Number):void + { + seconds.value = sec; + + } + + + + public function validateForm(event:Event):Boolean + { + // Save a reference to the currently focussed form control + // so that the isValid() helper method can notify only + // the currently focussed form control and not affect + // any of the other form controls. + focussedFormControl = event.target as DisplayObject; + + // Mark the form as valid to start with + formIsValid = true; + + // Check if form is empty + formIsEmpty = (txtSeqNo.text == "" && txtName.text == ""); + + // Run each validator in turn, using the isValid() + // helper method and update the value of formIsValid + // accordingly. + validate(validateSeqNo); + return formIsValid; + + } + + private function validate(validator:Validator):Boolean + { + // Get a reference to the component that is the + // source of the validator. + var validatorSource:DisplayObject = validator.source as DisplayObject; + + // Suppress events if the current control being validated is not + // the currently focussed control on the form. This stops the user + // from receiving visual validation cues on other form controls. + // var suppressEvents:Boolean = (validatorSource != focussedFormControl); + var suppressEvents:Boolean = false; + // Carry out validation. Returns a ValidationResultEvent. + // Passing null for the first parameter makes the validator + // use the property defined in the property tag of the + // <mx:Validator> tag. + var event:ValidationResultEvent = validator.validate(null, suppressEvents); + + // Check if validation passed and return a boolean value accordingly. + var currentControlIsValid:Boolean = (event.type == ValidationResultEvent.VALID); + + // Update the formIsValid flag + formIsValid = formIsValid && currentControlIsValid; + + return currentControlIsValid; + } + + public function reset():void + { + txtSeqNo.text =""; + txtName.text = ""; + hours.value =0; + minutes.value =0; + seconds.value =0; + txtSeqNo.errorString =""; + txtName.errorString =""; + + } + + + + ]]> + </mx:Script> + <mx:FormHeading label="Block Information"/> + <mx:FormItem label="Sequence Number:"> + <mx:TextInput id="txtSeqNo" maxChars="3" change="{validateForm(event)}"/> + </mx:FormItem> + <mx:FormItem label="Description:"> + <mx:TextArea id="txtName" change="{validateForm(event)}"/> + </mx:FormItem> + +<mx:FormItem label="Duration(hr:min:sec):"> + <mx:HBox> + <!--<mx:TextInput id="txtDuration" maxChars="8"/>--> + <mx:NumericStepper id="hours" minimum="0" maximum="12" stepSize="1" change="{getHours()}"/> + <mx:Label text=":" textAlign="center"/> + <mx:NumericStepper id="minutes" minimum="0" maximum="60" stepSize="1" change="{getMinutes()}"/> + <mx:Label text=":" textAlign="center"/> + <mx:NumericStepper id="seconds" minimum="0" maximum="60" stepSize="1" change="{getSeconds()}"/> + </mx:HBox> + + + + +</mx:FormItem> +<mx:NumberValidator id ="validateSeqNo" source="{txtSeqNo}" property="text" minValue="1" maxValue="1000" domain="int"/> + +</mx:Form> Added: mentalmodels/trunk/flex/src/custom/db/Module.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/db/Module.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/db/Module.mxml 2009-07-05 23:47:57 UTC (rev 171) @@ -0,0 +1,169 @@ +<?xml version="1.0" encoding="utf-8"?> + + +<mx:Form xmlns:mx="http://www.adobe.com/2006/mxml" width="30%" height="100%" autoLayout="true"> +<mx:Script> + <![CDATA[ + import mx.validators.NumberValidator; + import mx.validators.Validator; + import mx.events.ValidationResultEvent; + import mx.controls.Alert; + + [Bindable] + public var formIsEmpty:Boolean = true; + + [Bindable] + public var formIsValid:Boolean = false; + + + // Holds a reference to the currently focussed + // control on the form. + private var focussedFormControl:DisplayObject; + + public function getSequenceNo():String + { + return txtSeqNo.text; + } + public function getName():String + { + return txtName.text; + } + /*public function getDuration():String + { + //return txtMajor.text; + }*/ + + public function getHours():Number + { + return hours.value; + + } + public function getMinutes():Number + { + return minutes.value; + + } + public function getSeconds():Number + { + return seconds.value; + + } + + public function setSequenceNo(seqNo:String):void + { + txtSeqNo.text = seqNo; + } + public function setName(name:String):void + { + txtName.text = name; + } + + + public function setHours(hour:Number):void + { + hours.value = hour; + + } + public function setMinutes(min:Number):void + { + minutes.value = min; + + } + public function setSeconds(sec:Number):void + { + seconds.value = sec; + + } + + + + public function validateForm(event:Event):Boolean + { + // Save a reference to the currently focussed form control + // so that the isValid() helper method can notify only + // the currently focussed form control and not affect + // any of the other form controls. + focussedFormControl = event.target as DisplayObject; + + // Mark the form as valid to start with + formIsValid = true; + + // Check if form is empty + formIsEmpty = (txtSeqNo.text == "" && txtName.text == ""); + + // Run each validator in turn, using the isValid() + // helper method and update the value of formIsValid + // accordingly. + validate(validateSeqNo); + return formIsValid; + + } + + private function validate(validator:Validator):Boolean + { + // Get a reference to the component that is the + // source of the validator. + var validatorSource:DisplayObject = validator.source as DisplayObject; + + // Suppress events if the current control being validated is not + // the currently focussed control on the form. This stops the user + // from receiving visual validation cues on other form controls. + // var suppressEvents:Boolean = (validatorSource != focussedFormControl); + var suppressEvents:Boolean = false; + // Carry out validation. Returns a ValidationResultEvent. + // Passing null for the first parameter makes the validator + // use the property defined in the property tag of the + // <mx:Validator> tag. + var event:ValidationResultEvent = validator.validate(null, suppressEvents); + + // Check if validation passed and return a boolean value accordingly. + var currentControlIsValid:Boolean = (event.type == ValidationResultEvent.VALID); + + // Update the formIsValid flag + formIsValid = formIsValid && currentControlIsValid; + + return currentControlIsValid; + } + + public function reset():void + { + txtSeqNo.text =""; + txtName.text = ""; + hours.value =0; + minutes.value =0; + seconds.value =0; + txtSeqNo.errorString =""; + txtName.errorString =""; + + } + + + + ]]> + </mx:Script> + <mx:FormHeading label="Module Information"/> + <mx:FormItem label="Sequence Number:"> + <mx:TextInput id="txtSeqNo" maxChars="3" change="{validateForm(event)}"/> + </mx:FormItem> + <mx:FormItem label="Name:"> + <mx:TextInput id="txtName" change="{validateForm(event)}"/> + </mx:FormItem> + +<mx:FormItem label="Duration(hr:min:sec):"> + <mx:HBox> + <!--<mx:TextInput id="txtDuration" maxChars="8"/>--> + <mx:NumericStepper id="hours" minimum="0" maximum="12" stepSize="1" change="{getHours()}"/> + <mx:Label text=":" textAlign="center"/> + <mx:NumericStepper id="minutes" minimum="0" maximum="60" stepSize="1" change="{getMinutes()}"/> + <mx:Label text=":" textAlign="center"/> + <mx:NumericStepper id="seconds" minimum="0" maximum="60" stepSize="1" change="{getSeconds()}"/> + </mx:HBox> + + + + +</mx:FormItem> +<mx:NumberValidator id ="validateSeqNo" source="{txtSeqNo}" property="text" minValue="1" maxValue="1000" domain="int"/> + + +</mx:Form> Added: mentalmodels/trunk/flex/src/custom/db/Question.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/db/Question.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/db/Question.mxml 2009-07-05 23:47:57 UTC (rev 171) @@ -0,0 +1,213 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:Form xmlns:mx="http://www.adobe.com/2006/mxml" width="80%" height="100%" currentState="none" xmlns:net="flash.net.*" xmlns:comp="customComponents.db.questions.*"> + <mx:Script> + <![CDATA[ + import mx.validators.NumberValidator; + import mx.validators.Validator; + import mx.events.ValidationResultEvent; + import mx.controls.Alert; + + [Bindable] + public var formIsEmpty:Boolean = true; + + [Bindable] + public var formIsValid:Boolean = false; + + public var questionInfo:Object; + // Holds a reference to the currently focussed + // control on the form. + private var focussedFormControl:DisplayObject; + + public function getSequenceNo():String + { + return txtSeqNo.text; + } + public function getQuestion():String + { + return txtQuestion.text; + } + + public function getType():String + { + return String(cmbType.selectedItem); + } + + public function setSequenceNo(seqNo:String):void + { + txtSeqNo.text = seqNo; + } + public function setQuestion(question:String):void + { + txtQuestion.text = question; + } + + public function setQuestionInfo():void + { + + } + + public function getQuestionInfo():Object + { + return questionInfo; + + } + + public function setType(type:String):void + { + cmbType.selectedItem = type; + if(cmbType.selectedItem == "Categorical") + { + currentState = "categorical"; + var catobj:DisplayObject = canvasQuestionType.getChildAt(0); + var categoricalInfo:Categorical = Categorical(catobj); + categoricalInfo.reset(); + + } + if(cmbType.selectedItem == "Psychometric") + { + currentState = "psychometric"; + var psychobj:DisplayObject = canvasQuestionType.getChildAt(0); + var psychometricInfo:Psychometric = Psychometric(psychobj); + psychometricInfo.reset(); + + } + if(cmbType.selectedItem == "Text") + { + currentState = "none"; + } + } + + + + public function validateForm(event:Event):Boolean + { + // Save a reference to the currently focussed form control + // so that the isValid() helper method can notify only + // the currently focussed form control and not affect + // any of the other form controls. + focussedFormControl = event.target as DisplayObject; + + // Mark the form as valid to start with + formIsValid = true; + + // Check if form is empty + formIsEmpty = (txtSeqNo.text == "" && txtQuestion.text == "" && cmbType.selectedItem == "-Select-"); + + // Run each validator in turn, using the isValid() + // helper method and update the value of formIsValid + // accordingly. + validate(validateSeqNo); + + return formIsValid; + + } + + private function showQuestionType():void + { + + if(cmbType.selectedItem == "Categorical") + { + currentState = "categorical"; + var catobj:DisplayObject = canvasQuestionType.getChildAt(0); + questionInfo = Categorical(catobj); + questionInfo.reset(); + + } + if(cmbType.selectedItem == "Psychometric") + { + currentState = "psychometric"; + var psychobj:DisplayObject = canvasQuestionType.getChildAt(0); + questionInfo = Psychometric(psychobj); + questionInfo.reset(); + + } + if(cmbType.selectedItem == "Text") + { + currentState = "none"; + } + + } + + + private function validate(validator:Validator):Boolean + { + // Get a reference to the component that is the + // source of the validator. + var validatorSource:DisplayObject = validator.source as DisplayObject; + + // Suppress events if the current control being validated is not + // the currently focussed control on the form. This stops the user + // from receiving visual validation cues on other form controls. + // var suppressEvents:Boolean = (validatorSource != focussedFormControl); + var suppressEvents:Boolean = false; + // Carry out validation. Returns a ValidationResultEvent. + // Passing null for the first parameter makes the validator + // use the property defined in the property tag of the + // <mx:Validator> tag. + var event:ValidationResultEvent = validator.validate(null, suppressEvents); + + // Check if validation passed and return a boolean value accordingly. + var currentControlIsValid:Boolean = (event.type == ValidationResultEvent.VALID); + + // Update the formIsValid flag + formIsValid = formIsValid && currentControlIsValid; + + return currentControlIsValid; + } + + public function reset():void + { + currentState = "none"; + txtSeqNo.text =""; + txtQuestion.text = ""; + + txtSeqNo.errorString =""; + txtQuestion.errorString =""; + cmbType.selectedIndex = 0; + + + } + + ]]> + </mx:Script> + <mx:states> + <mx:State name="categorical"> + <mx:AddChild relativeTo="{canvasQuestionType}"> + <comp:Categorical id="categorical"/> + </mx:AddChild> + </mx:State> + + <mx:State name="psychometric"> + <mx:AddChild relativeTo="{canvasQuestionType}"> + <comp:Psychometric id="psychometric"/> + </mx:AddChild> + </mx:State> + <mx:State name="none" /> + + </mx:states> + + + <mx:FormHeading label="Question"/> + <mx:FormItem label="Sequence Number:"> + <mx:TextInput id="txtSeqNo" maxChars="3" change="{validateForm(event)}"/> + </mx:FormItem> + <mx:FormItem label="Question:"> + <mx:TextArea id="txtQuestion" change="{validateForm(event)}"/> + </mx:FormItem> + <mx:FormItem label="Select Question Type:"> + <mx:ComboBox id="cmbType" change="{showQuestionType()}" width="100%"> + <mx:ArrayCollection> + <mx:String>-Select-</mx:String> + <mx:String>Categorical</mx:String> + <mx:String>Psychometric</mx:String> + <mx:String>Text</mx:String> + </mx:ArrayCollection> + </mx:ComboBox> + + </mx:FormItem> + + <mx:Canvas id="canvasQuestionType" height="100%"/> + +<mx:NumberValidator id ="validateSeqNo" source="{txtSeqNo}" property="text" minValue="1" maxValue="1000" domain="int"/> + +</mx:Form> Added: mentalmodels/trunk/flex/src/custom/db/QuestionGroup.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/db/QuestionGroup.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/db/QuestionGroup.mxml 2009-07-05 23:47:57 UTC (rev 171) @@ -0,0 +1,127 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:Form xmlns:mx="http://www.adobe.com/2006/mxml"> + <mx:Script> + <![CDATA[ + import mx.validators.NumberValidator; + import mx.validators.Validator; + import mx.events.ValidationResultEvent; + import mx.controls.Alert; + + [Bindable] + public var formIsEmpty:Boolean = true; + + [Bindable] + public var formIsValid:Boolean = false; + + + // Holds a reference to the currently focussed + // control on the form. + private var focussedFormControl:DisplayObject; + + public function getSequenceNo():String + { + return txtSeqNo.text; + } + public function getHeader():String + { + return txtHeader.text; + } + public function getDescription():String + { + return txtDescription.text; + } + + public function setSequenceNo(seqNo:String):void + { + txtSeqNo.text = seqNo; + } + public function setHeader(header:String):void + { + txtHeader.text = header; + } + + + public function setDescription(description:String):void + { + txtDescription.text = description; + + } + + + public function validateForm(event:Event):Boolean + { + // Save a reference to the currently focussed form control + // so that the isValid() helper method can notify only + // the currently focussed form control and not affect + // any of the other form controls. + focussedFormControl = event.target as DisplayObject; + + // Mark the form as valid to start with + formIsValid = true; + +... [truncated message content] |