[virtualcommons-svn] SF.net SVN: virtualcommons:[214] mentalmodels/trunk/flex/src/ InitialiseDataba
Status: Beta
Brought to you by:
alllee
From: <kj...@us...> - 2009-08-04 18:34:44
|
Revision: 214 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=214&view=rev Author: kjonas Date: 2009-08-04 18:34:30 +0000 (Tue, 04 Aug 2009) Log Message: ----------- Fixed spacing in InitialiseDatabase.mxml Modified Paths: -------------- mentalmodels/trunk/flex/src/InitialiseDatabase.mxml Modified: mentalmodels/trunk/flex/src/InitialiseDatabase.mxml =================================================================== --- mentalmodels/trunk/flex/src/InitialiseDatabase.mxml 2009-08-04 06:05:21 UTC (rev 213) +++ mentalmodels/trunk/flex/src/InitialiseDatabase.mxml 2009-08-04 18:34:30 UTC (rev 214) @@ -2,27 +2,26 @@ <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:net="flash.net.*" xmlns:comp="custom.db.questions.*" xmlns:basicComp="custom.db.*" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#FFFFFF, #80FFAA]" width="100%" height="100%" clipContent="false" layout="absolute" currentState="none" initialize="init()"> - <mx:Script> - <![CDATA[ - import mx.binding.utils.BindingUtils; - - - import actionscript.Block; - import actionscript.Module; - import actionscript.questions.Question; - import actionscript.QuestionGroup; - import actionscript.questions.Categorical; - import actionscript.questions.CategoricalOption; - import actionscript.questions.Psychometric; - - - import mx.collections.ArrayCollection; - import mx.effects.Fade; - - import mx.collections.XMLListCollection; - import mx.controls.Alert; - import mx.rpc.events.FaultEvent; - import mx.rpc.events.ResultEvent; + <mx:Script> + <![CDATA[ + import mx.binding.utils.BindingUtils; + + import actionscript.Block; + import actionscript.Module; + import actionscript.questions.Question; + import actionscript.QuestionGroup; + import actionscript.questions.Categorical; + import actionscript.questions.CategoricalOption; + import actionscript.questions.Psychometric; + + + import mx.collections.ArrayCollection; + import mx.effects.Fade; + + import mx.collections.XMLListCollection; + import mx.controls.Alert; + import mx.rpc.events.FaultEvent; + import mx.rpc.events.ResultEvent; /**** * Sample exmaple of Survey Questions structure @@ -54,8 +53,7 @@ so when module info is transfered to the server, it should return the id for that module */ - [Bindable] - private var survey:XML = + [Bindable] private var survey:XML = <list> <module title="Survey Questions" id="0" sequenceNo="0" hours="0" min="0" sec="0"/> </list>; @@ -76,8 +74,7 @@ * * ***/ - [Bindable] - private var categoricalQuestions:XML = + [Bindable] private var categoricalQuestions:XML = <list> <categorical type="Categorical Questions" id="0"/> @@ -88,50 +85,45 @@ * <psychometric scale="bipolar" id="2" choices="good,better,best" maxSliderValue="21" /> **/ - [Bindable] - private var psychometricQuestions:XML = + [Bindable] private var psychometricQuestions:XML = <list> <psychometric scale="Psychometric Questions" id="0" choices="none" maxSliderValue="0"/> </list>; - [Bindable] - private var surveyData:XMLListCollection = new XMLListCollection(survey.module); - - private var CategoricalquestionsData:XMLListCollection = new XMLListCollection(categoricalQuestions.categorical); - - private var PsychometricquestionsData:XMLListCollection = new XMLListCollection(psychometricQuestions.psychometric); - - public var tempQuestion:ArrayCollection = new ArrayCollection(); - - - - private function init():void - { - roQuestionCreator.initializeData(); - } - - private function resultInitializeDataHandler(event:ResultEvent):void - { - //Alert.show(event.result.toString()); + [Bindable] private var surveyData:XMLListCollection = new XMLListCollection(survey.module); + + private var CategoricalquestionsData:XMLListCollection = new XMLListCollection(categoricalQuestions.categorical); + + private var PsychometricquestionsData:XMLListCollection = new XMLListCollection(psychometricQuestions.psychometric); + + public var tempQuestion:ArrayCollection = new ArrayCollection(); + + private function init():void + { + roQuestionCreator.initializeData(); + } + + private function resultInitializeDataHandler(event:ResultEvent):void + { + //Alert.show(event.result.toString()); var modulelist:ArrayCollection = new ArrayCollection(); modulelist = event.result as ArrayCollection; - + - if(modulelist != null) - { - for(var i:int = 0 ; i < modulelist.length ; i++) - { - var module:actionscript.Module = new actionscript.Module(); - module = modulelist[i]; - - - //create module node and add into the tree - var newModuleNode:XML = createModuleNode(module); - - survey.appendChild(newModuleNode); - - //if any blocks, add into the module + if(modulelist != null) + { + for(var i:int = 0 ; i < modulelist.length ; i++) + { + var module:actionscript.Module = new actionscript.Module(); + module = modulelist[i]; + + //create module node and add into the tree + var newModuleNode:XML = createModuleNode(module); + + survey.appendChild(newModuleNode); + + //if any blocks, add into the module if(module.blocks != null) { for(var blockCounter:int = 0; blockCounter < module.blocks.length; blockCounter++) @@ -141,8 +133,8 @@ var newBlockNode:XML = createBlockNode(block); newModuleNode.appendChild(newBlockNode); - + if(block.questionGroups != null) { //if any question Group, add into the block @@ -163,236 +155,234 @@ newQuestionGroupNode.appendChild(newQuestionNode); } } - } } } } - } - - } - - } - - private function createModuleNode(module:actionscript.Module):XML - { - - - var newModuleNode:XML = <module/>; - newModuleNode.setLocalName("module"); - newModuleNode.@title= module.description; - newModuleNode.@sequenceNo = module.sequenceNo; - newModuleNode.@hours = module.getHours(); - newModuleNode.@min = module.getMinutes(); - newModuleNode.@sec = module.getSeconds(); - newModuleNode.@id = module.id; - - - return newModuleNode; - - } - - private function createBlockNode(block:actionscript.Block):XML - { - var newBlockNode:XML = <block/>; - newBlockNode.setLocalName("block"); - newBlockNode.@name = block.description; - newBlockNode.@sequenceNo = block.sequenceNo; - newBlockNode.@hours = block.getHours(); - newBlockNode.@min = block.getMinutes(); - newBlockNode.@sec = block.getSeconds(); - newBlockNode.@id = block.id; - - return newBlockNode; - - } - - private function createQuestionGroupNode(questionGroup:actionscript.QuestionGroup):XML - { - var newNode:XML = <questiongroup/>; - newNode.setLocalName("questiongroup"); - newNode.@header = questionGroup.header; - newNode.@description = questionGroup.description; - newNode.@sequenceNo = questionGroup.sequenceNo; - newNode.@hours = questionGroup.getHours(); - newNode.@min = questionGroup.getMinutes(); - newNode.@sec = questionGroup.getSeconds(); - newNode.@id = questionGroup.id; - - return newNode; - - } - - private function createQuestionNode(question:actionscript.questions.Question):XML - { - var newQNode:XML = <question/>; - newQNode.setLocalName("question"); - var choices:String=""; - if(question.type.toLowerCase() == "psychometric") + } + } + } + + private function createModuleNode(module:actionscript.Module):XML { - var psychometricResult:actionscript.questions.Psychometric = actionscript.questions.Psychometric(question); - /*Alert.show("Id is: " + psychometricResult.id); - Alert.show("Question is: " + psychometricResult.question); - Alert.show("Type is: " + psychometricResult.type); - Alert.show("SeQNo is: " + psychometricResult.sequenceNo);*/ + var newModuleNode:XML = <module/>; + newModuleNode.setLocalName("module"); + newModuleNode.@title= module.description; + newModuleNode.@sequenceNo = module.sequenceNo; + newModuleNode.@hours = module.getHours(); + newModuleNode.@min = module.getMinutes(); + newModuleNode.@sec = module.getSeconds(); + newModuleNode.@id = module.id; - var newPNode:XML = <psychometric/>; - newPNode.setLocalName("psychometric"); - newPNode.@id = psychometricResult.id; - newPNode.@scale = psychometricResult.scale; - newPNode.@maxSliderValue = psychometricResult.maxSliderValue; - - newQNode.@sequenceNo = psychometricResult.sequenceNo; - newQNode.@title = psychometricResult.question; - newQNode.@type = psychometricResult.type; - newQNode.@id = psychometricResult.id; - //Check if this question is for communication round. - newQNode.@communication = psychometricResult.communicationQ; - - choices = ""; - if(psychometricResult.choices != null) - { - //Alert.show("choices is eqaul to : " + choices); - for(var k:int = 0; k < psychometricResult.choices.length; k++) - { - if(choices == "") - { - //Alert.show("choices is eqaul to : " + choices); - choices = psychometricResult.choices[k]; - } - else - { - choices = choices + psychometricResult.choices[k]; - } - choices = choices + "," - } - //Alert.show("choices are: " + choices); - - newPNode.@choices = choices; - } - psychometricQuestions.appendChild(newPNode); - + return newModuleNode; } - else if(question.type.toLowerCase() == "categorical") + + private function createBlockNode(block:actionscript.Block):XML { - var categoricalResult:actionscript.questions.Categorical = actionscript.questions.Categorical(question); + var newBlockNode:XML = <block/>; + newBlockNode.setLocalName("block"); + newBlockNode.@name = block.description; + newBlockNode.@sequenceNo = block.sequenceNo; + newBlockNode.@hours = block.getHours(); + newBlockNode.@min = block.getMinutes(); + newBlockNode.@sec = block.getSeconds(); + newBlockNode.@id = block.id; - newQNode.@sequenceNo = categoricalResult.sequenceNo; - newQNode.@title = categoricalResult.question; - newQNode.@type = categoricalResult.type; - newQNode.@id = categoricalResult.id; - newQNode.@communication = categoricalResult.communicationQ; - /*var questionGroup:XMLList =survey.module.block.questiongroup.(@header == node.@header); - - if( questionGroup.length() > 0 ) - { - questionGroup[0].appendChild(newQNode); - currentState = "none"; - btnsaveQuestion.enabled = false; - }*/ - //false means it is simple type, otherwise it is relative type - var flagType:Boolean = false; - - var newCNode:XML = <categorical/>; - newCNode.setLocalName("categorical"); - newCNode.@id = categoricalResult.id; - categoricalQuestions.appendChild(newCNode); - - if(categoricalResult.categoricalOptions != null) + return newBlockNode; + } + + private function createQuestionGroupNode(questionGroup:actionscript.QuestionGroup):XML + { + var newNode:XML = <questiongroup/>; + newNode.setLocalName("questiongroup"); + newNode.@header = questionGroup.header; + newNode.@description = questionGroup.description; + newNode.@sequenceNo = questionGroup.sequenceNo; + newNode.@hours = questionGroup.getHours(); + newNode.@min = questionGroup.getMinutes(); + newNode.@sec = questionGroup.getSeconds(); + newNode.@id = questionGroup.id; + + return newNode; + } + + private function createQuestionNode(question:actionscript.questions.Question):XML + { + var newQNode:XML = <question/>; + newQNode.setLocalName("question"); + var choices:String=""; + if(question.type.toLowerCase() == "psychometric") { + var psychometricResult:actionscript.questions.Psychometric = actionscript.questions.Psychometric(question); + /*Alert.show("Id is: " + psychometricResult.id); + Alert.show("Question is: " + psychometricResult.question); + Alert.show("Type is: " + psychometricResult.type); + Alert.show("SeQNo is: " + psychometricResult.sequenceNo);*/ + + var newPNode:XML = <psychometric/>; + newPNode.setLocalName("psychometric"); + newPNode.@id = psychometricResult.id; + newPNode.@scale = psychometricResult.scale; + newPNode.@maxSliderValue = psychometricResult.maxSliderValue; + + newQNode.@sequenceNo = psychometricResult.sequenceNo; + newQNode.@title = psychometricResult.question; + newQNode.@type = psychometricResult.type; + newQNode.@id = psychometricResult.id; + //Check if this question is for communication round. + newQNode.@communication = psychometricResult.communicationQ; + + choices = ""; + if(psychometricResult.choices != null) + { + //Alert.show("choices is eqaul to : " + choices); + for(var k:int = 0; k < psychometricResult.choices.length; k++) + { + if(choices == "") + { + //Alert.show("choices is eqaul to : " + choices); + choices = psychometricResult.choices[k]; + } + else + { + choices = choices + psychometricResult.choices[k]; + } + choices = choices + "," + } + //Alert.show("choices are: " + choices); + + newPNode.@choices = choices; + } + psychometricQuestions.appendChild(newPNode); + } + else if(question.type.toLowerCase() == "categorical") + { + var categoricalResult:actionscript.questions.Categorical = actionscript.questions.Categorical(question); + + newQNode.@sequenceNo = categoricalResult.sequenceNo; + newQNode.@title = categoricalResult.question; + newQNode.@type = categoricalResult.type; + newQNode.@id = categoricalResult.id; + newQNode.@communication = categoricalResult.communicationQ; + /*var questionGroup:XMLList =survey.module.block.questiongroup.(@header == node.@header); + + if( questionGroup.length() > 0 ) + { + questionGroup[0].appendChild(newQNode); + currentState = "none"; + btnsaveQuestion.enabled = false; + }*/ + //false means it is simple type, otherwise it is relative type + var flagType:Boolean = false; + + var newCNode:XML = <categorical/>; + newCNode.setLocalName("categorical"); + newCNode.@id = categoricalResult.id; + categoricalQuestions.appendChild(newCNode); + + if(categoricalResult.categoricalOptions != null) + { - for(var i:int = 0; i < categoricalResult.categoricalOptions.length ; i++) - { - var options:actionscript.questions.CategoricalOption = new actionscript.questions.CategoricalOption(); - options = actionscript.questions.CategoricalOption(categoricalResult.categoricalOptions.getItemAt(i)); - var newOptionNode:XML = <option/>; - newOptionNode.setLocalName("option"); - newOptionNode.@name = options.optionKey; - if(options.choices.length == 0) - { - flagType = false - } - else - { - flagType = true; - choices=""; - - for(k = 0; k < options.choices.length; k++) + for(var i:int = 0; i < categoricalResult.categoricalOptions.length ; i++) + { + var options:actionscript.questions.CategoricalOption = new actionscript.questions.CategoricalOption(); + options = actionscript.questions.CategoricalOption(categoricalResult.categoricalOptions.getItemAt(i)); + var newOptionNode:XML = <option/>; + newOptionNode.setLocalName("option"); + newOptionNode.@name = options.optionKey; + if(options.choices.length == 0) { - - if(choices == "") - { - choices = options.choices[k]; - } - else - { - choices = choices + options.choices[k]; - } - choices = choices + "," + flagType = false + } + else + { + flagType = true; + choices=""; - } - //Alert.show("choices are: " + choices); - - newOptionNode.@choices = choices; - } - if(flagType) - newCNode.@type = "relative"; - else - newCNode.@type = "simple"; - newCNode.appendChild(newOptionNode); - } + for(k = 0; k < options.choices.length; k++) + { + + if(choices == "") + { + choices = options.choices[k]; + } + else + { + choices = choices + options.choices[k]; + } + choices = choices + "," + } + //Alert.show("choices are: " + choices); + + newOptionNode.@choices = choices; + } + if(flagType) + { + newCNode.@type = "relative"; + } + else + { + newCNode.@type = "simple"; + } + newCNode.appendChild(newOptionNode); + } + } } - + //if question type is strategy, day by day decision, forecasting fish, forecasting fishermen + else + { + newQNode.@sequenceNo = question.sequenceNo; + newQNode.@title = question.question; + newQNode.@type = question.type; + newQNode.@id = question.id; + newQNode.@communication = question.communicationQ; + //Alert.show("communication : " + question.communicationQ); + } + return newQNode; } - //if question type is strategy, day by day decision, forecasting fish, forecasting fishermen - else + + private function faultHandler(event:FaultEvent):void { - newQNode.@sequenceNo = question.sequenceNo; - newQNode.@title = question.question; - newQNode.@type = question.type; - newQNode.@id = question.id; - newQNode.@communication = question.communicationQ; - //Alert.show("communication : " + question.communicationQ); - } - return newQNode; - - } - - private function faultHandler(event:FaultEvent):void - { Alert.show("event fault is " + event.fault.getStackTrace()); - } + } - private function treeLabel(item:Object):String - { + private function treeLabel(item:Object):String + { var node:XML = XML(item); if( node.localName() == "module" ) + { return node.@title; - + } else if( node.localName() == "block" ) + { return node.@name; - + } else if( node.localName() == "questiongroup" ) + { return node.@header; - + } else if( node.localName() == "question" ) + { return node.@type; - + } else + { return null; - + } } private function treeLabelPsychometricQ(item:Object):String { var node:XML = XML(item); if( node.localName() == "psychometric" ) + { return node.@scale; - + } else + { return node.@name; - + } } private function treeLabelCategoricalQ(item:Object):String @@ -400,18 +390,20 @@ var node:XML = XML(item); if( node.localName() == "categorical" ) + { return node.@type; - + } else + { return node.@name; + } } - public function isDurationValid(hours:Number,minutes:Number,seconds:Number):Boolean - { + public function isDurationValid(hours:Number,minutes:Number,seconds:Number):Boolean + { return (hours == 0 && minutes == 0 && seconds == 0); - - } + } //Module Functionality Start private function addModule():void @@ -464,7 +456,9 @@ Alert.show("Sequence number : " + seqNo + " already exists!"); } else + { roQuestionCreator.saveModule(seqNo, title, getDuration(moduleInfo.getHours(),moduleInfo.getMinutes(),moduleInfo.getSeconds())); + } } else @@ -477,7 +471,9 @@ Alert.show("Sequence number : " + seqNo + " already exists!"); } else + { roQuestionCreator.updateModule(moduleInfo.getId(),seqNo, title, getDuration(moduleInfo.getHours(),moduleInfo.getMinutes(),moduleInfo.getSeconds())); + } } @@ -530,7 +526,9 @@ moduleXML.@sec = module.getSeconds(); } else + { Alert.show("Error in updating module!"); + } } @@ -597,43 +595,44 @@ //check the sequence number first, if sequence number already exists throw an error, otherwise create block var checkSeqNoBlock:XMLList = module.block.(@sequenceNo == blockInfo.getSequenceNo()); - if(blockInfo.getId() == 0) - { - if(checkSeqNoBlock.length() > 0) - { - Alert.show("Sequence number " + blockInfo.getSequenceNo() + " already exists!"); - } - else - { - roQuestionCreator.saveBlock(int(blockInfo.getSequenceNo()),blockInfo.getName(),getDuration(blockInfo.getHours(),blockInfo.getMinutes(),blockInfo.getSeconds()),int(module[0].@id)); - } - } - else - { - //Alert.show("length : " + checkSeqNoBlock.length().toString()); - //check if the sequence number exists, do not update the module - if(checkSeqNoBlock.length() > 1) - { - Alert.show("Sequence number : " + blockInfo.getSequenceNo() + " already exists!"); - } - else - roQuestionCreator.updateBlock(blockInfo.getId(), int(blockInfo.getSequenceNo()),blockInfo.getName(),getDuration(blockInfo.getHours(),blockInfo.getMinutes(),blockInfo.getSeconds()),int(module[0].@id)); - } - - currentState = "none"; - btnsaveBlock.enabled = false; + if(blockInfo.getId() == 0) + { + if(checkSeqNoBlock.length() > 0) + { + Alert.show("Sequence number " + blockInfo.getSequenceNo() + " already exists!"); + } + else + { + roQuestionCreator.saveBlock(int(blockInfo.getSequenceNo()),blockInfo.getName(),getDuration(blockInfo.getHours(),blockInfo.getMinutes(),blockInfo.getSeconds()),int(module[0].@id)); + } + } + else + { + //Alert.show("length : " + checkSeqNoBlock.length().toString()); + //check if the sequence number exists, do not update the module + if(checkSeqNoBlock.length() > 1) + { + Alert.show("Sequence number : " + blockInfo.getSequenceNo() + " already exists!"); + } + else + { + roQuestionCreator.updateBlock(blockInfo.getId(), int(blockInfo.getSequenceNo()),blockInfo.getName(),getDuration(blockInfo.getHours(),blockInfo.getMinutes(),blockInfo.getSeconds()),int(module[0].@id)); + } } - } - } - - else - { - Alert.show("Please fill the form correctly"); - return; - } - } - - } + + currentState = "none"; + btnsaveBlock.enabled = false; + } + } + } + + else + { + Alert.show("Please fill the form correctly"); + return; + } + } + } //when block is created, the result will come to resultSaveBlockHandler public function resultSaveBlockHandler(event:ResultEvent):void @@ -652,9 +651,9 @@ } } else + { Alert.show("Error in creating Block!"); - - + } } public function resultUpdateBlockHandler(event:ResultEvent):void @@ -674,133 +673,135 @@ } } else + { Alert.show("Error in creating Block!"); + } } //Block functioanlity End //QuestionGroup functionality Start - private function addQuestionGroup():void - { - currentState = "questionGroup"; - var obj:DisplayObject = pnlComponent.getChildAt(1); - var questionGroupInfo:custom.db.QuestionGroup = custom.db.QuestionGroup(obj); - questionGroupInfo.reset(); + private function addQuestionGroup():void + { + currentState = "questionGroup"; + var obj:DisplayObject = pnlComponent.getChildAt(1); + var questionGroupInfo:custom.db.QuestionGroup = custom.db.QuestionGroup(obj); + questionGroupInfo.reset(); + + btnsaveModule.enabled = false; + btnsaveBlock.enabled = false; + btnsaveQuestionGroup.enabled = true; + btnsaveQuestion.enabled = false; + + } - btnsaveModule.enabled = false; - btnsaveBlock.enabled = false; - btnsaveQuestionGroup.enabled = true; - btnsaveQuestion.enabled = false; - - } - - private function saveQuestionGroup(event:Event):void - { - - var selectedNode:XML = tree.selectedItem as XML; - var obj:DisplayObject = pnlComponent.getChildAt(1); - var questionGroupInfo:custom.db.QuestionGroup = custom.db.QuestionGroup(obj); - - if(tree.selectedItem == null) - { + private function saveQuestionGroup(event:Event):void + { + + var selectedNode:XML = tree.selectedItem as XML; + var obj:DisplayObject = pnlComponent.getChildAt(1); + var questionGroupInfo:custom.db.QuestionGroup = custom.db.QuestionGroup(obj); + + if(tree.selectedItem == null) + { Alert.show("Please select the block from tree to which Question Group should be added."); return; - } - else - { - - //if(tree.getParentItem(tree.selectedItem) == null) - if(selectedNode.localName() == "module") - { - Alert.show("You can not add QuestionGroup to Module."); - return; - } - else - { - if(selectedNode.localName() == "questiongroup" && questionGroupInfo.getId() == 0) - { - Alert.show("You can not add QuestionGroup to QuestionGroup."); - return; - } - - else - { - //find out the parent module - var parentModule:XML = tree.getParentItem(tree.selectedItem) as XML; - - var isQuestionGroupFormValid:Boolean = questionGroupInfo.validateForm(event); - - if(isQuestionGroupFormValid) - { - var durationflag:Boolean = this.isDurationValid(questionGroupInfo.getHours(),questionGroupInfo.getMinutes(),questionGroupInfo.getSeconds()); - if(durationflag) - { - Alert.show("Please enter the valid duration for the given module."); - } - else - { - var node:XML; - /** - * Check if the selected node is block, if it is new Question Group needs to be created. - else if selected node is Question Group, then Question Group needs to be updated.*/ - - if(selectedNode.localName() == "block") - { - node = selectedNode; - } - else if(selectedNode.localName() == "questiongroup") - { - var parentNode:XML = tree.getParentItem(tree.selectedItem) as XML; - node = parentNode; - } - var block:XMLList = survey.module.block.(@id == node.@id); - //Alert.show("block id is : " + block.@id + "length is: " + block.length().toString()); - if( block.length() > 0 ) - { - //check the sequence number first, if sequence number already exists throw an error, otherwise create module - var checkSeqNoQuestionGroup:XMLList = block.questiongroup.(@sequenceNo == questionGroupInfo.getSequenceNo()); - //Alert.show("length : " + checkSeqNoQuestionGroup.length().toString()); - if(questionGroupInfo.getId() == 0) + } + else + { + + //if(tree.getParentItem(tree.selectedItem) == null) + if(selectedNode.localName() == "module") + { + Alert.show("You can not add QuestionGroup to Module."); + return; + } + else + { + if(selectedNode.localName() == "questiongroup" && questionGroupInfo.getId() == 0) + { + Alert.show("You can not add QuestionGroup to QuestionGroup."); + return; + } + else + { + //find out the parent module + var parentModule:XML = tree.getParentItem(tree.selectedItem) as XML; + + var isQuestionGroupFormValid:Boolean = questionGroupInfo.validateForm(event); + + if(isQuestionGroupFormValid) + { + var durationflag:Boolean = this.isDurationValid(questionGroupInfo.getHours(),questionGroupInfo.getMinutes(),questionGroupInfo.getSeconds()); + if(durationflag) + { + Alert.show("Please enter the valid duration for the given module."); + } + else + { + var node:XML; + /** + * Check if the selected node is block, if it is new Question Group needs to be created. + else if selected node is Question Group, then Question Group needs to be updated.*/ + + if(selectedNode.localName() == "block") + { + node = selectedNode; + } + else if(selectedNode.localName() == "questiongroup") + { + var parentNode:XML = tree.getParentItem(tree.selectedItem) as XML; + node = parentNode; + } + var block:XMLList = survey.module.block.(@id == node.@id); + //Alert.show("block id is : " + block.@id + "length is: " + block.length().toString()); + if( block.length() > 0 ) + { + //check the sequence number first, if sequence number already exists throw an error, otherwise create module + var checkSeqNoQuestionGroup:XMLList = block.questiongroup.(@sequenceNo == questionGroupInfo.getSequenceNo()); + //Alert.show("length : " + checkSeqNoQuestionGroup.length().toString()); + if(questionGroupInfo.getId() == 0) + { + if(checkSeqNoQuestionGroup.length() > 0) + { + Alert.show("Sequence number " + questionGroupInfo.getSequenceNo() + " already exists!"); + } + else + { + roQuestionCreator.saveQuestionGroup(int(questionGroupInfo.getSequenceNo()),questionGroupInfo.getHeader(),questionGroupInfo.getDescription(),getDuration(questionGroupInfo.getHours(),questionGroupInfo.getMinutes(),questionGroupInfo.getSeconds()),int(block[0].@id)); + } + } + else + { + //Alert.show("length : " + checkSeqNoQuestionGroup.length().toString()); + //check if the sequence number exists, do not update the module + if(checkSeqNoQuestionGroup.length() > 1) + { + Alert.show("Sequence number : " + questionGroupInfo.getSequenceNo() + " already exists!"); + } + else + { + roQuestionCreator.updateQuestionGroup(int(questionGroupInfo.getSequenceNo()),questionGroupInfo.getHeader(),questionGroupInfo.getDescription(),getDuration(questionGroupInfo.getHours(),questionGroupInfo.getMinutes(),questionGroupInfo.getSeconds()),int(block[0].@id),questionGroup.getId()); + } + + } + currentState = "none"; + btnsaveQuestionGroup.enabled = false; + } + } + } + else { - if(checkSeqNoQuestionGroup.length() > 0) - { - Alert.show("Sequence number " + questionGroupInfo.getSequenceNo() + " already exists!"); - } - else - { - roQuestionCreator.saveQuestionGroup(int(questionGroupInfo.getSequenceNo()),questionGroupInfo.getHeader(),questionGroupInfo.getDescription(),getDuration(questionGroupInfo.getHours(),questionGroupInfo.getMinutes(),questionGroupInfo.getSeconds()),int(block[0].@id)); - } - } - else - { - //Alert.show("length : " + checkSeqNoQuestionGroup.length().toString()); - //check if the sequence number exists, do not update the module - if(checkSeqNoQuestionGroup.length() > 1) - { - Alert.show("Sequence number : " + questionGroupInfo.getSequenceNo() + " already exists!"); - } - else - roQuestionCreator.updateQuestionGroup(int(questionGroupInfo.getSequenceNo()),questionGroupInfo.getHeader(),questionGroupInfo.getDescription(),getDuration(questionGroupInfo.getHours(),questionGroupInfo.getMinutes(),questionGroupInfo.getSeconds()),int(block[0].@id),questionGroup.getId()); - - } - currentState = "none"; - btnsaveQuestionGroup.enabled = false; - } - - } - } - else - { - Alert.show("Please fill the form correctly"); - return; - } - } - } - } - } + Alert.show("Please fill the form correctly"); + return; + } + } + } + } + } - //when QuestionGroup is created, the result will come to resultSaveQuestionGroupHandler + //when QuestionGroup is created, the result will come to resultSaveQuestionGroupHandler public function resultSaveQuestionGroupHandler(event:ResultEvent):void { var questionGroup:actionscript.QuestionGroup = actionscript.QuestionGroup(event.result as Object); @@ -820,8 +821,9 @@ } } else + { Alert.show("Error in creating QuestionGroup!"); - + } } //when QuestionGroup is updated, the result will come to resultUpdateQuestionGroupHandler @@ -838,8 +840,8 @@ //Alert.show("Length is: " + questionGroupXML.length()); if(questionGroupXML.length() > 0) { - // Alert.show("header is :" + questionGroup.header); - // Alert.show("questionGroup description is :" + questionGroup.description); + //Alert.show("header is :" + questionGroup.header); + //Alert.show("questionGroup description is :" + questionGroup.description); //Alert.show("questionGroup.sequenceNo is :" + questionGroup.sequenceNo); questionGroupXML[0].@header = questionGroup.header; @@ -852,106 +854,106 @@ } } else + { Alert.show("Error in updating QuestionGroup!"); - } + } + } - //QuestionGroup functionality End - - - //Question functionality Start - private function addQuestion():void - { - currentState = "question"; - var obj:DisplayObject = pnlComponent.getChildAt(1); - var questionInfo:custom.db.Question = custom.db.Question(obj); - questionInfo.reset(); + //QuestionGroup functionality End - btnsaveModule.enabled = false; - btnsaveBlock.enabled = false; - btnsaveQuestionGroup.enabled = false; - btnsaveQuestion.enabled = true; - } - - private function QuestionHandler(event:Event):void - { - if(question.cmbType.selectedItem.data.toString().toLowerCase() == "psychometric") + + //Question functionality Start + private function addQuestion():void { - currentState = "psychometric"; - psychometric.reset(); - } - else if(question.cmbType.selectedItem.data.toString().toLowerCase() == "categorical") - { - currentState = "categorical"; - categorical.reset(); - } - else - { currentState = "question"; + var obj:DisplayObject = pnlComponent.getChildAt(1); + var questionInfo:custom.db.Question = custom.db.Question(obj); + questionInfo.reset(); + btnsaveModule.enabled = false; + btnsaveBlock.enabled = false; + btnsaveQuestionGroup.enabled = false; + btnsaveQuestion.enabled = true; } - - } - - private function CategoricalTypeHandler(event:Event):void - { - if(categorical.cmbType.selectedItem.toString().toLowerCase() == "relative") + + private function QuestionHandler(event:Event):void { - currentState = "relative"; - categoricalRelative.reset(); + if(question.cmbType.selectedItem.data.toString().toLowerCase() == "psychometric") + { + currentState = "psychometric"; + psychometric.reset(); + } + else if(question.cmbType.selectedItem.data.toString().toLowerCase() == "categorical") + { + currentState = "categorical"; + categorical.reset(); + } + else + { + currentState = "question"; + } } - else if(categorical.cmbType.selectedItem.toString().toLowerCase() == "simple") - { - currentState = "simple"; - categoricalSimple.reset(); - } - } + private function CategoricalTypeHandler(event:Event):void + { + if(categorical.cmbType.selectedItem.toString().toLowerCase() == "relative") + { + currentState = "relative"; + categoricalRelative.reset(); + } + else if(categorical.cmbType.selectedItem.toString().toLowerCase() == "simple") + { + currentState = "simple"; + categoricalSimple.reset(); + } + + } - private function saveQuestion(event:Event):void - { - var selectedNode:XML = tree.selectedItem as XML; - var node:XML; - - if(tree.selectedItem == null) - { + private function saveQuestion(event:Event):void + { + var selectedNode:XML = tree.selectedItem as XML; + var node:XML; + + if(tree.selectedItem == null) + { Alert.show("Please select the block from tree to which Question Group should be added."); return; - } - else - { - if(selectedNode.localName().toString().toLowerCase() == "module" || selectedNode.localName().toString().toLowerCase() == "block") - { - Alert.show("You can not add Question to Module or Block."); - return; - } - else - { - if(selectedNode.localName().toString().toLowerCase() == "questiongroup") - { - node = selectedNode; - } - else if(selectedNode.localName().toString().toLowerCase() == "question") - { - var parentNode:XML = tree.getParentItem(tree.selectedItem) as XML; - node = parentNode; - } - - - var obj:DisplayObject = pnlComponent.getChildAt(1); - var questionInfo:custom.db.Question = custom.db.Question(obj); - var isQuestionFormValid:Boolean = questionInfo.validateForm(event); - - if(isQuestionFormValid) - { - //Alert.show("Parent id: " + node.@id); - //check the sequence number first, if sequence number already exists throw an error, otherwise create Question - - var questionGroup:XMLList = survey.module.block.questiongroup.(@id == node.@id); - //Alert.show("Parent children length: " + questionGroup.children().length()); - if(questionGroup.length() > 0 ) - { - var checkSeqNoQuestion:XMLList = questionGroup.question.(@sequenceNo == questionInfo.getSequenceNo()); - //Alert.show("checkSeqNoQuestion length: " + checkSeqNoQuestion.length()); + } + else + { + if(selectedNode.localName().toString().toLowerCase() == "module" || selectedNode.localName().toString().toLowerCase() == "block") + { + Alert.show("You can not add Question to Module or Block."); + return; + } + else + { + if(selectedNode.localName().toString().toLowerCase() == "questiongroup") + { + node = selectedNode; + } + else if(selectedNode.localName().toString().toLowerCase() == "question") + { + var parentNode:XML = tree.getParentItem(tree.selectedItem) as XML; + node = parentNode; + } + + + var obj:DisplayObject = pnlComponent.getChildAt(1); + var questionInfo:custom.db.Question = custom.db.Question(obj); + var isQuestionFormValid:Boolean = questionInfo.validateForm(event); + + if(isQuestionFormValid) + { + //Alert.show("Parent id: " + node.@id); + //check the sequence number first, if sequence number already exists throw an error, otherwise create Question + + var questionGroup:XMLList = survey.module.block.questiongroup.(@id == node.@id); + //Alert.show("Parent children length: " + questionGroup.children().length()); + if(questionGroup.length() > 0 ) + { + var checkSeqNoQuestion:XMLList = questionGroup.question.(@sequenceNo == questionInfo.getSequenceNo()); + //Alert.show("checkSeqNoQuestion length: " + checkSeqNoQuestion.length()); if(currentState == "psychometric") { var psychobj:DisplayObject = pnlComponent.getChildAt(2); @@ -991,7 +993,6 @@ } } - else if(currentState == "relative") { var catobj:DisplayObject = pnlComponent.getChildAt(3); @@ -1044,8 +1045,8 @@ var catSimpleobj:DisplayObject = pnlComponent.getChildAt(3); var compCategoricalSimple:custom.db.questions.CategoricalSimple = custom.db.questions.CategoricalSimple(catSimpleobj); var categoricalSimpleQuestion:actionscript.questions.Categorical = new actionscript.questions.Categorical(); - - + + var Simpledict:Dictionary = new Dictionary(); Simpledict = compCategoricalSimple.getDictionary(); for (var option:Object in Simpledict) @@ -1118,202 +1119,198 @@ Alert.show("Sequence number " + questionInfo.getSequenceNo() + " already exists!"); } else + { roQuestionCreator.updateQuestion(question,int(node.@id), questionInfo.getId()); - } - - } - } - } - - - } - } - - } + } + } + } + } + } + } + } + } - public function resultSaveQuestionHandler(event:ResultEvent):void - { - var question_Object:actionscript.questions.Question = actionscript.questions.Question(event.result as Object); - if(question_Object != null) + public function resultSaveQuestionHandler(event:ResultEvent):void { + var question_Object:actionscript.questions.Question = actionscript.questions.Question(event.result as Object); + if(question_Object != null) + { var newQuestionNode:XML = createQuestionNode(question_Object); //Alert.show("question_Object.questionGroup.id " + question_Object.questionGroup.id); var questionGroup:XMLList = survey.module.block.questiongroup.(@id == question_Object.questionGroup.id); //Alert.show("question_Object.questionGroup.length " + questionGroup.length()); if( questionGroup.length() > 0 ) { - questionGroup[0].appendChild(newQuestionNode); - currentState = "none"; + questionGroup[0].appendChild(newQuestionNode); + currentState = "none"; btnsaveQuestion.enabled = false; - } + } + } + else + { + Alert.show("Error in creating Question!"); + } } - else - Alert.show("Error in creating Question!"); - - } - - public function resultUpdateQuestionHandler(event:ResultEvent):void - { - var question:actionscript.questions.Question = actionscript.questions.Question(event.result as Object); - if(question == null) + public function resultUpdateQuestionHandler(event:ResultEvent):void { - Alert.show("Error in creating Question!"); + var question:actionscript.questions.Question = actionscript.questions.Question(event.result as Object); + if(question == null) + { + Alert.show("Error in creating Question!"); + } + else + { + var newNode:XML = <question/>; + newNode.setLocalName("question"); + var newQNode:XML = <question/>; + newQNode.setLocalName("question"); + var choices:String=""; + if(question.type.toLowerCase() == "psychometric") + { + var psychometricResult:actionscript.questions.Psychometric = actionscript.questions.Psychometric(question); + /*Alert.show("Id is: " + psychometricResult.id); + Alert.show("Question is: " + psychometricResult.question); + Alert.show("Type is: " + psychometricResult.type); + Alert.show("SeQNo is: " + psychometricResult.sequenceNo);*/ + + var newPNode:XML = <psychometric/>; + newPNode.setLocalName("psychometric"); + var psychometricList:XMLList = psychometricQuestions.psychometric.(@id == psychometricResult.id); + + if( psychometricList.length() > 0 ) + { + newPNode.@scale = psychometricResult.scale; + newPNode.@maxSliderValue = psychometricResult.maxSliderValue; + + newQNode.@sequenceNo = psychometricResult.sequenceNo; + newQNode.@title = psychometricResult.question; + newQNode.@type = psychometricResult.type; + newQNode.@communication = psychometricResult.communicationQ; + choices = ""; + if(psychometricResult.choices != null) + { + for(var k:int = 0; k < psychometricResult.choices.length; k++) + { + if(choices == "") + { + choices = psychometricResult.choices[k]; + } + else + { + choices = choices + psychometricResult.choices[k]; + } + choices = choices + "," + } + newPNode.@choices = choices; + } + } + } + else if(question.type.toLowerCase() == "categorical") + { + var categoricalResult:actionscript.questions.Categorical = actionscript.questions.Categorical(question); + newQNode.@sequenceNo = categoricalResult.sequenceNo; + newQNode.@title = categoricalResult.question; + newQNode.@type = categoricalResult.type; + newQNode.@id = categoricalResult.id; + newQNode.@communication = categoricalResult.communicationQ; + //flagType false means it is simple type, otherwise it is relative type + var flagType:Boolean = false; + + var newCNode:XML = <categorical/>; + newCNode.setLocalName("categorical"); + + var categoricalList:XMLList = categoricalQuestions.categorical.(@id == categoricalResult.id); + + if( categoricalList.length() > 0 ) + { + //remove all the <option> tags and then add those rather than modifying those. It is simple. + var children:XMLList = categoricalList.children(); + + for(var l:Number=0; l < children.length(); l++) + { + delete children[i]; + } + + if(categoricalResult.categoricalOptions != null) + { + for(var i:int = 0; i < categoricalResult.categoricalOptions.length ; i++) + { + var options:actionscript.questions.CategoricalOption = new actionscript.questions.CategoricalOption(); + options = actionscript.questions.CategoricalOption(categoricalResult.categoricalOptions.getItemAt(i)); + var newOptionNode:XML = <option/>; + newOptionNode.setLocalName("option"); + newOptionNode.@name = options.optionKey; + if(options.choices.length == 0) + { + flagType = false + } + else + { + flagType = true; + choices=""; + + for(k = 0; k < options.choices.length; k++) + { + if(choices == "") + { + choices = options.choices[k]; + } + + else + { + choices = choices + options.choices[k]; + } + + choices = choices + "," + } + newOptionNode.@choices = choices; + } + if(flagType) + { + newCNode.@type = "relative"; + } + else + { + newCNode.@type = "simple"; + } + newCNode.appendChild(newOptionNode); + } + } + } + } + } } - else - { - var newNode:XML = <question/>; - newNode.setLocalName("question"); - var newQNode:XML = <question/>; - newQNode.setLocalName("question"); - var choices:String=""; - if(question.type.toLowerCase() == "psychometric") + //Question functionality Stop + + public function removeItem():void { - var psychometricResult:actionscript.questions.Psychometric = actionscript.questions.Psychometric(question); - /*Alert.show("Id is: " + psychometricResult.id); - Alert.show("Question is: " + psychometricResult.question); - Alert.show("Type is: " + psychometricResult.type); - Alert.show("SeQNo is: " + psychometricResult.sequenceNo);*/ + currentState = "none"; + btnsaveModule.enabled = false; + btnsaveBlock.enabled = false; + btnsaveQuestion.enabled = false; + btnsaveQuestionGroup.enabled = false; - var newPNode:XML = <psychometric/>; - newPNode.setLocalName("psychometric"); - var psychometricList:XMLList = psychometricQuestions.psychometric.(@id == psychometricResult.id); - - if( psychometricList.length() > 0 ) - { - newPNode.@scale = psychometricResult.scale; - newPNode.@maxSliderValue = psychometricResult.maxSliderValue; - - newQNode.@sequenceNo = psychometricResult.sequenceNo; - newQNode.@title = psychometricResult.question; - newQNode.@type = psychometricResult.type; - newQNode.@communication = psychometricResult.communicationQ; - choices = ""; - if(psychometricResult.choices != null) - { - - for(var k:int = 0; k < psychometricResult.choices.length; k++) - { - if(choices == "") - choices = psychometricResult.choices[k]; - - else - choices = choices + psychometricResult.choices[k]; - - choices = choices + "," - - } - - newPNode.@choices = choices; - } - - } - - } - else if(question.type.toLowerCase() == "categorical") - { - var categoricalResult:actionscript.questions.Categorical = actionscript.questions.Categorical(question); - - newQNode.@sequenceNo = categoricalResult.sequenceNo; - newQNode.@title = categoricalResult.question; - newQNode.@type = categoricalResult.type; - newQNode.@id = categoricalResult.id; - newQNode.@communication = categoricalResult.communicationQ; - //flagType false means it is simple type, otherwise it is relative type - var flagType:Boolean = false; - - var newCNode:XML = <categorical/>; - newCNode.setLocalName("categorical"); - - var categoricalList:XMLList = categoricalQuestions.categorical.(@id == categoricalResult.id); - - if( categoricalList.length() > 0 ) - { - //remove all the <option> tags and then add those rather than modifying those. It is simple. - var children:XMLList = categoricalList.children(); - - for(var l:Number=0; l < children.length(); l++) - { - delete children[i]; - } - - - if(categoricalResult.categoricalOptions != null) + var node:XML = XML(tree.selectedItem); + if( node == null ) + { + Alert.show("Please select the Item from tree."); + return; + } + + var children:XMLList = XMLList(node.parent()).children(); + for(var i:Number=0; i < children.length(); i++) + { + if( children[i].@name == node.@name ) { - - for(var i:int = 0; i < categoricalResult.categoricalOptions.length ; i++) - { - var options:actionscript.questions.CategoricalOption = new actionscript.questions.CategoricalOption(); - options = actionscript.questions.CategoricalOption(categoricalResult.categoricalOptions.getItemAt(i)); - var newOptionNode:XML = <option/>; - newOptionNode.setLocalName("option"); - newOptionNode.@name = options.optionKey; - if(options.choices.length == 0) - { - flagType = false - } - else - { - flagType = true; - choices=""; - - for(k = 0; k < options.choices.length; k++) - { - if(choices == "") - choices = options.choices[k]; - - else - choices = choices + options.choices[k]; - - choices = choices + "," - } - newOptionNode.@choices = choices; - } - if(flagType) - newCNode.@type = "relative"; - else - newCNode.@type = "simple"; - newCNode.appendChild(newOptionNode); - } + delete children[i].@*; } } - } - } - - } - //Question functionality Stop - public function removeItem():void - { - currentState = "none"; - btnsaveModule.enabled = false; - btnsaveBlock.enabled = false; - btnsaveQuestion.enabled = false; - btnsaveQuestionGroup.enabled = false; - - var node:XML = XML(tree.selectedItem); - if( node == null ) - { - Alert.show("Please select the Item from tree."); - return; - - } - - var children:XMLList = XMLList(node.parent()).children(); - for(var i:Number=0; i < children.length(); i++) - { - - if( children[i].@name == node.@name ) - { - delete children[i].@*; - } - - } - - } + } - private function treeChanged(event:Event):void + private function treeChanged(event:Event):void { var selectedNode:int; @@ -1451,14 +1448,10 @@ for(var i:int = 0; i < outputchoices.length; i++) { - dict[str].addItem(outputchoices[i]); - } - } compRelative.setDictionary(dict); -... [truncated message content] |