[virtualcommons-svn] SF.net SVN: virtualcommons:[148] mentalmodels/trunk/flex/src/ customComponents
Status: Beta
Brought to you by:
alllee
From: <see...@us...> - 2009-05-28 01:22:43
|
Revision: 148 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=148&view=rev Author: seematalele Date: 2009-05-28 00:31:15 +0000 (Thu, 28 May 2009) Log Message: ----------- 2 types of Categorical questions 1)Relative - Example 2 list ?\226?\128?\156focus and goal?\226?\128?\157 but items in one list is reltaed to another item/items. 2)Simple - 1 list with choices. 1)Relative Working fine Problem: Remove Choice1 is not removing the item in the list 1 (Focus list) 2)Simple Interface is build but still needs to do lot of modification like adding list control. Modified Paths: -------------- mentalmodels/trunk/flex/src/customComponents/Categorical.mxml mentalmodels/trunk/flex/src/customComponents/Question.mxml Added Paths: ----------- mentalmodels/trunk/flex/src/customComponents/CategoricalRelative.mxml mentalmodels/trunk/flex/src/customComponents/CategoricalSimple.mxml Modified: mentalmodels/trunk/flex/src/customComponents/Categorical.mxml =================================================================== --- mentalmodels/trunk/flex/src/customComponents/Categorical.mxml 2009-05-27 20:02:40 UTC (rev 147) +++ mentalmodels/trunk/flex/src/customComponents/Categorical.mxml 2009-05-28 00:31:15 UTC (rev 148) @@ -1,7 +1,8 @@ <?xml version="1.0" encoding="utf-8"?> -<mx:Form xmlns:mx="http://www.adobe.com/2006/mxml"> +<mx:Form xmlns:mx="http://www.adobe.com/2006/mxml" currentState="none" xmlns:net="flash.net.*" xmlns:comp="customComponents.*"> <mx:Script> <![CDATA[ + import mx.collections.ArrayCollection; import mx.validators.NumberValidator; import mx.validators.Validator; import mx.events.ValidationResultEvent; @@ -13,7 +14,11 @@ [Bindable] public var formIsValid:Boolean = false; - + [Bindable] + public var header1:ArrayCollection = new ArrayCollection(); + + [Bindable] + public var header2:ArrayCollection = new ArrayCollection(); // Holds a reference to the currently focussed // control on the form. private var focussedFormControl:DisplayObject; @@ -90,20 +95,41 @@ private function showRelativeFields():void { - - vboxHeaders.visible = true; - vboxSecondHeader.visible = true; - + currentState = "relative"; + var obj:DisplayObject = canvasComponent.getChildAt(0); + var relativeInfo:CategoricalRelative = CategoricalRelative(obj); + relativeInfo.reset(); } private function showSimpleFields():void { - Alert.show("Simple"); + currentState = "simple"; + var obj:DisplayObject = canvasComponent.getChildAt(0); + var simpleInfo:CategoricalSimple = CategoricalSimple(obj); + simpleInfo.reset(); } - - ]]> + + ]]> </mx:Script> + + <mx:states> + <mx:State name="relative"> + <mx:AddChild relativeTo="{canvasComponent}"> + <comp:CategoricalRelative id="relative"/> + </mx:AddChild> + </mx:State> + + <mx:State name="simple"> + <mx:AddChild relativeTo="{canvasComponent}"> + <comp:CategoricalSimple id="simple"/> + </mx:AddChild> + </mx:State> + + <mx:State name="none"/> + + </mx:states> + <mx:FormHeading label="Categorical"/> <mx:FormItem label="Type:"> <mx:RadioButtonGroup id="type"/> @@ -111,43 +137,6 @@ <mx:RadioButton id="rdoRelative" groupName="{type}" label="Relative" click="showRelativeFields()"/> <mx:RadioButton id="rdoSimple" groupName="{type}" label="Simple" click="showSimpleFields()" /> </mx:FormItem> - <mx:VBox> - - <mx:VBox id="vboxHeaders" visible="false"> - <mx:FormItem label="Header1:"> - <mx:TextInput id="txtHeader1" change="{validateForm(event)}"/> - </mx:FormItem> + <mx:Canvas id="canvasComponent" height="100%" /> - <mx:FormItem label="Header2:"> - <mx:TextInput id="txtHeader2" change="{validateForm(event)}"/> - </mx:FormItem> - - <mx:FormItem label="Choice for Header1:"> - <mx:TextInput id="txtchoiceHeader1" change="{validateForm(event)}"/> - </mx:FormItem> - - <mx:Button id="btnaddChoice1" label="Add Choice"/> - - </mx:VBox> - - <mx:HBox visible="false" id="vboxSecondHeader"> - <mx:VBox> - <mx:Label text="" id="lblHeader1"/> - <mx:List id="lstHeader1" wordWrap="true"/> - <mx:FormItem label="Choice for Header2:"> - <mx:TextInput id="txtaddChoice2" change="{validateForm(event)}"/> - </mx:FormItem> - - </mx:VBox> - <mx:VBox> - <mx:Label text="" id="lblHeader2"/> - <mx:List id="lstHeader2" wordWrap="true"/> - <mx:Button id="btnaddChoice2" label="Add Choice"/> - </mx:VBox> - - </mx:HBox> - - </mx:VBox> - - </mx:Form> Added: mentalmodels/trunk/flex/src/customComponents/CategoricalRelative.mxml =================================================================== --- mentalmodels/trunk/flex/src/customComponents/CategoricalRelative.mxml (rev 0) +++ mentalmodels/trunk/flex/src/customComponents/CategoricalRelative.mxml 2009-05-28 00:31:15 UTC (rev 148) @@ -0,0 +1,256 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"> + + <mx:Script> + <![CDATA[ + import mx.collections.ArrayCollection; + import mx.validators.NumberValidator; + import mx.validators.Validator; + import mx.events.ValidationResultEvent; + import mx.controls.Alert; + import flash.utils.Dictionary; + + [Bindable] + public var formIsEmpty:Boolean = true; + + [Bindable] + public var formIsValid:Boolean = false; + + [Bindable] + public var header1:ArrayCollection = new ArrayCollection(); + [Bindable] + public var header:Object = new Object(); + + public var dict:Dictionary = new Dictionary(); + + [Bindable] + public var header2:ArrayCollection = new ArrayCollection(); + // 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 getDescription():String + { + return txtDescription.text; + }*/ + + + + 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 = (txtHeader1.text == "" && txtHeader2.text == "" && txtChoice1.text == "" && txtChoice2.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 + { + + txtHeader1.text = ""; + txtHeader2.text = ""; + txtChoice1.text = ""; + txtChoice2.text = ""; + } + + + private function addHeader():void + { + + lblHeader1.text = txtHeader1.text; + lblHeader2.text = txtHeader2.text; + vboxSecondHeader.visible = true; + frmitmAddChoice1.label="Choice for " + txtHeader1.text + ":"; + frmitmAddChoice2.label="Choice for " + txtHeader2.text + ":"; + + } + + private function addChoice1():void + { + if(txtChoice1.text == null || txtChoice1.text == "") + { + Alert.show("Please Enter the " + frmitmAddChoice1.label); + return; + + } + header1.addItem(txtChoice1.text); + dict[txtChoice1.text] = new ArrayCollection(); + + txtChoice1.text = ""; + + } + + private function addChoice2():void + { + if(header1.length < 0) + { + Alert.show("There are no choices for "+ txtHeader1.text +"Please Enter the " + frmitmAddChoice1.label); + return; + } + if(txtChoice2.text == null || txtChoice2.text == "") + { + Alert.show("Please Enter the " + frmitmAddChoice2.label); + return; + + } + if(lstHeader1.selectedItem == null ||lstHeader1.selectedItem == "") + { + Alert.show("Please Select the Item from " + txtHeader1. text); + return; + } + + else + { + + //header2.addItem(txtChoice2.text); + if(dict[lstHeader1.selectedItem].hasOwnProperty("addItem")) + { + dict[lstHeader1.selectedItem].addItem(txtChoice2.text); + } + else + Alert.show("addItem property is NOT suceesul"); + //header[lstHeader1.selectedItem] = txtChoice2.text; + txtChoice2.text = ""; + } + + } + + private function removeChoice1():void + { + if(lstHeader1.selectedItem == null ||lstHeader1.selectedItem == "") + { + Alert.show("Please Select the Item from " + txtHeader1. text); + return; + } + else + { + delete dict[lstHeader1.selectedItem]; + } + } + + private function removeChoice2():void + { + if(lstHeader2.selectedItem == null ||lstHeader2.selectedItem == "") + { + Alert.show("Please Select the Item from " + txtHeader1. text); + return; + } + else + { + //header1.removeItemAt(header1.getItemIndex(lstHeader2.selectedItem)); + if(dict[lstHeader1.selectedItem].hasOwnProperty("removeItemAt") && dict[lstHeader1.selectedItem].hasOwnProperty("getItemIndex")) + { + dict[lstHeader1.selectedItem].removeItemAt(dict[lstHeader1.selectedItem].getItemIndex(lstHeader2.selectedItem)); + + } + } + } + + private function showChoices():void + { + if(lstHeader1.selectedItem == null ||lstHeader1.selectedItem == "") + { + Alert.show("Please Enter the items in the " + txtHeader1. text); + return; + } + else + { + lstHeader2.dataProvider = dict[lstHeader1.selectedItem]; + } + } + ]]> + </mx:Script> + <mx:VBox id="vboxHeaders"> + <mx:FormItem label="Header1:"> + <mx:TextInput id="txtHeader1" change="{validateForm(event)}"/> + </mx:FormItem> + + <mx:FormItem label="Header2:"> + <mx:TextInput id="txtHeader2" change="{validateForm(event)}"/> + </mx:FormItem> + + <mx:Button id="btnsaveHeader" label="Save" click="addHeader()"/> + + </mx:VBox> + + <mx:HBox id="vboxSecondHeader" visible="false"> + <mx:VBox> + <mx:Label text="" id="lblHeader1" fontSize="12" fontWeight="bold" fontFamily="Verdana"/> + <mx:List id="lstHeader1" wordWrap="true" dataProvider="{header1}" allowMultipleSelection="false" click="showChoices()"/> + <mx:FormItem id="frmitmAddChoice1"> + <mx:TextInput id="txtChoice1" change="{validateForm(event)}"/> + </mx:FormItem> + + <mx:Button id="btnaddChoice1" label="Add Choice1" click="addChoice1()"/> + <mx:Button id="btnremoveChoice1" label="Remove Choice1" click="removeChoice1()"/> + + </mx:VBox> + <mx:Spacer width="50"/> + + + <mx:VBox> + <mx:Label text="" id="lblHeader2" fontWeight="bold" fontSize="12" fontFamily="Verdana"/> + <mx:List id="lstHeader2" wordWrap="false" dataProvider="{header2}" allowMultipleSelection="false" /> + + <mx:FormItem id="frmitmAddChoice2"> + <mx:TextInput id="txtChoice2" change="{validateForm(event)}"/> + </mx:FormItem> + + <mx:Button id="btnaddChoice2" label="Add Choice2" click="addChoice2()"/> + <mx:Button id="btnremoveChoice2" label="Remove Choice2" click="removeChoice2()"/> + </mx:VBox> + + + + </mx:HBox> + +</mx:VBox> Added: mentalmodels/trunk/flex/src/customComponents/CategoricalSimple.mxml =================================================================== --- mentalmodels/trunk/flex/src/customComponents/CategoricalSimple.mxml (rev 0) +++ mentalmodels/trunk/flex/src/customComponents/CategoricalSimple.mxml 2009-05-28 00:31:15 UTC (rev 148) @@ -0,0 +1,158 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"> + + <mx:Script> + <![CDATA[ + import mx.collections.ArrayCollection; + 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; + + [Bindable] + public var header:ArrayCollection = new ArrayCollection(); + + + // 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 getDescription():String + { + return txtDescription.text; + }*/ + + + + 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 = (txtHeader.text == "" && txtChoice.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 + { + + txtHeader.text = ""; + + txtChoice.text = ""; + + } + + private function showRelativeFields():void + { + vboxHeaders.visible = true; + + } + + private function showSimpleFields():void + { + vboxHeaders.visible = false; + vboxSecondHeader.visible = false; + } + + private function addHeader():void + { + + lblHeader.text = txtHeader.text; + vboxSecondHeader.visible = true; + frmitmAddChoice.label="Choice for " + txtHeader.text + ":"; + + } + + private function addChoice():void + { + if(txtChoice.text == null || txtChoice.text == "") + { + Alert.show("Please Enter the " + frmitmAddChoice.label); + return; + + } + header.addItem(txtChoice.text); + txtChoice.text = ""; + + } + + + ]]> + </mx:Script> + <mx:VBox id="vboxHeaders"> + <mx:FormItem label="Header:"> + <mx:TextInput id="txtHeader" change="{validateForm(event)}"/> + </mx:FormItem> + + <mx:Button id="btnsaveHeader" label="Save" click="addHeader()"/> + + </mx:VBox> + + <mx:HBox id="vboxSecondHeader" visible="false"> + <mx:VBox> + <mx:Label text="" id="lblHeader" fontSize="12" fontWeight="bold" fontFamily="Verdana"/> + <mx:List id="lstHeader" wordWrap="true" dataProvider="{header}" allowMultipleSelection="false"/> + <mx:FormItem id="frmitmAddChoice"> + <mx:TextInput id="txtChoice" change="{validateForm(event)}"/> + </mx:FormItem> + <mx:Button id="btnaddChoice" label="Add Choice" click="addChoice()"/> + + </mx:VBox> + + </mx:HBox> + +</mx:VBox> Modified: mentalmodels/trunk/flex/src/customComponents/Question.mxml =================================================================== --- mentalmodels/trunk/flex/src/customComponents/Question.mxml 2009-05-27 20:02:40 UTC (rev 147) +++ mentalmodels/trunk/flex/src/customComponents/Question.mxml 2009-05-28 00:31:15 UTC (rev 148) @@ -60,17 +60,20 @@ private function showQuestionType():void { - currentState = "categorical"; - var obj:DisplayObject = canvasQuestionType.getChildAt(0); + //Alert.show("selected item is: " + cmbType.selectedItem); if(cmbType.selectedItem == "Categorical") { - + currentState = "categorical"; + var obj:DisplayObject = canvasQuestionType.getChildAt(0); var categoricalInfo:Categorical = Categorical(obj); categoricalInfo.reset(); - - + } + else + { + currentState = "none"; + } } @@ -150,12 +153,7 @@ </mx:FormItem> <mx:Canvas id="canvasQuestionType" height="100%"/> - - - - - - + <mx:NumberValidator id ="validateSeqNo" source="{txtSeqNo}" property="text" minValue="1" maxValue="1000" domain="int"/> </mx:Form> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |