[virtualcommons-svn] SF.net SVN: virtualcommons:[141] mentalmodels/trunk/flex/src
Status: Beta
Brought to you by:
alllee
From: <see...@us...> - 2009-05-19 01:12:06
|
Revision: 141 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=141&view=rev Author: seematalele Date: 2009-05-19 01:11:57 +0000 (Tue, 19 May 2009) Log Message: ----------- Made changes in Module.mxml and InitialiseDatabase.mxml. Worked on - Validation for module - Tested and working perfectly. Added functionality of getting selected current module in the tree. This functionality is used to add block for that particular module. Modified Paths: -------------- mentalmodels/trunk/flex/src/InitialiseDatabase.mxml mentalmodels/trunk/flex/src/customComponents/Module.mxml Modified: mentalmodels/trunk/flex/src/InitialiseDatabase.mxml =================================================================== --- mentalmodels/trunk/flex/src/InitialiseDatabase.mxml 2009-05-15 22:36:12 UTC (rev 140) +++ mentalmodels/trunk/flex/src/InitialiseDatabase.mxml 2009-05-19 01:11:57 UTC (rev 141) @@ -4,6 +4,7 @@ width="760" height="510" clipContent="false" layout="absolute" currentState="none"> <mx:Script> <![CDATA[ + import mx.effects.Fade; import mx.collections.XMLListCollection; import mx.controls.Alert; @@ -51,48 +52,83 @@ { currentState = "module"; + var obj:DisplayObject = pnlComponent.getChildAt(1); + var moduleInfo:Module = Module(obj); + moduleInfo.reset(); + btnsaveModule.enabled = true; /*var saveModule:Button = new Button; - saveModule.label ="Save Module"; + var isExists:Boolean = pnlComponent.contains(saveModule as DisplayObject); + Alert.show(isExists.toString()); + if(!pnlComponent.contains(saveModule as DisplayObject)) + { + saveModule.label ="Save Module"; - pnlComponent.addChild(saveModule as DisplayObject); + pnlComponent.addChild(saveModule as DisplayObject); + } //saveModule.*/ } - private function saveModule():void + private function saveModule(event:Event):void { - - Alert.show("in add module"); + //btnsaveModule.enabled = false; + var obj:DisplayObject = pnlComponent.getChildAt(1); + var moduleInfo:Module = Module(obj); - var newNode:XML = <module/> - newNode.setLocalName("module"); + var isModuleFormValid:Boolean = moduleInfo.validateForm(event); + if(isModuleFormValid) + { + var durationflag:Boolean = this.isDurationValid(moduleInfo.getHours(),moduleInfo.getMinutes(),moduleInfo.getSeconds()); + if(durationflag) + { + Alert.show("Please enter the valid duration for the given module."); + } + else + { + var newNode:XML = <module/> + newNode.setLocalName("module"); + newNode.@title=moduleInfo.getName(); + newNode.@sequenceNo =moduleInfo.getSequenceNo(); + company.appendChild(newNode); + currentState = "none"; + btnsaveModule.enabled = false; + + } + + } + else + { + Alert.show("Please fill the form correctly"); + } - newNode.@title="first module"; - newNode.@sequenceNo ="1"; - - company.appendChild(newNode); - <!-- var newNode:XML = <employee/>; - // newNode.@name = empName.text; - var dept:XMLList =company.department.(@title == "Operations"); - if( dept.length() > 0 ) { - - dept[0].appendChild(newNode); - // empName.text = ""; - }--> } + public function isDurationValid(hours:Number,minutes:Number,seconds:Number):Boolean + { + return (hours == 0 && minutes == 0 && seconds == 0); + + } - private function addBlock():void { - var newNode:XML = <block/>; + //currentState = "block"; + btnsaveModule.enabled = true; + + + + var node:XML = tree.selectedItem as XML; + + Alert.show("Selected node is " + node.@title); + + /* var newNode:XML = <block/>; newNode.@name = "block1"; var module:XMLList =company.module.(@title == "first module"); if( module.length() > 0 ) { module[0].appendChild(newNode); // empName.text = ""; - } + }*/ + } private function addItem():void @@ -134,13 +170,26 @@ } } + + private function treeChanged(event:Event):void + { + /* var selectedNode:int; + + //selectedNode=Tree(event.target).selectedItem; + var obj:DisplayObject = tree.getChildAt(selectedNode); + var newNode:XML = XML(obj); + Alert.show("Selected node is " + newNode.toString());*/ + + } + + ]]> </mx:Script> <mx:states> <mx:State name="module"> <mx:AddChild relativeTo="{pnlComponent}"> - <comp:Module id="module"/> + <comp:Module id="module"/> </mx:AddChild> </mx:State> @@ -162,9 +211,9 @@ <mx:HDividedBox width="100%" height="100%" id="hdMain"> <mx:VBox height="100%" id="vboxLeft"> <mx:Tree id="tree" top="72" left="50" dataProvider="{companyData}" - labelFunction="treeLabel" - showRoot="true" - height="224" width="179"/> + labelFunction="treeLabel" allowMultipleSelection="false" selectable="true" + showRoot="true" change="{treeChanged(event)}" + height="224" width="179" /> <mx:Canvas height="35%"> <mx:Grid x="0" y="0"> @@ -202,9 +251,19 @@ </mx:Canvas> </mx:VBox> - <mx:Panel id = "pnlComponent" height="100%"> - + <mx:Panel id = "pnlComponent" height="100%" layout="vertical"> + <mx:HBox width="100%"> + <mx:Spacer width="40"/> + <mx:Button id = "btnsaveModule" label="Save Module" enabled="false" click="{saveModule(event)}"/> + <mx:Spacer width="40"/> + <mx:Button id = "btnsaveBlock" enabled="false" label="Save Block" /> + <mx:Spacer width="40"/> + <mx:Button id = "btnsaveItem" enabled="false" label="Save Item" /> + <mx:Spacer width="40"/> + + </mx:HBox> </mx:Panel> </mx:HDividedBox> + </mx:Application> Modified: mentalmodels/trunk/flex/src/customComponents/Module.mxml =================================================================== --- mentalmodels/trunk/flex/src/customComponents/Module.mxml 2009-05-15 22:36:12 UTC (rev 140) +++ mentalmodels/trunk/flex/src/customComponents/Module.mxml 2009-05-19 01:11:57 UTC (rev 141) @@ -1,27 +1,25 @@ <?xml version="1.0" encoding="utf-8"?> - <!--<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" > - - <mx:Label text="Module Information" fontWeight="bold" width="150" textAlign="center" fontSize="12"/> - <mx:HBox> - <mx:Label text="Sequence Number:" fontWeight="bold" width="150" textAlign="right"/> - <mx:TextInput id="txtSeqNo" width="75" maxChars="3"/> - </mx:HBox> - - <mx:HBox> - <mx:Label text="Name:" fontWeight="bold" width="150" textAlign="right"/> - <mx:TextInput id="txtName" width="120" maxChars="255"/> - </mx:HBox> - - <mx:HBox> - <mx:Label text="Duration:" fontWeight="bold" width="150" textAlign="right"/> - <mx:TextInput id="txtDuration" width="75" maxChars="6"/> - </mx:HBox> -</mx:VBox>--> + <mx:Form xmlns:mx="http://www.adobe.com/2006/mxml" width="30%" height="10%" 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; @@ -30,36 +28,113 @@ { return txtName.text; } - public function getMajor():String + /*public function getDuration():String { - return txtMajor.text; + //return txtMajor.text; + }*/ + + public function getHours():Number + { + return hours.value; + } - public function getSemester():String + public function getMinutes():Number { - return txtSemester.text; + return minutes.value; + } + public function getSeconds():Number + { + return seconds.value; + + } + 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:FormItem label="Sequence Number:"> - <mx:TextInput id="txtSeqNo" maxChars="3"/> + <mx:TextInput id="txtSeqNo" maxChars="3" change="{validateForm(event)}"/> </mx:FormItem> <mx:FormItem label="Name:"> - <mx:TextInput id="txtName"/> + <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"/> + <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"/> + <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"/> + <mx:NumericStepper id="seconds" minimum="0" maximum="60" stepSize="1" change="{getSeconds()}"/> </mx:HBox> + + </mx:FormItem> - - </mx:Form> +<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. |