Tras ver cómo hacer una calculadora con un simple formulario y un popup para mostrar el resultado, en esta tercera entrega veremos como implementar diferencias funcionalidades de Movilizer para seguir mostrando el resultado pero de distinta forma.
En el vídeo se puede ver como hacer para:
- Lanzar eventos OnChangeEvent, capturarlos, y mostrar el resultado.
- Usar dos questions para mostrar el resultado.
- Unir esas dos questions en una única pantalla y mostrar el resultado, de forma un tanto rara.
- Comunicar esas dos questions mediante eventos onExternalEvent para pintar el resultado.
Este es el código mostrado al final del vídeo:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
<MovilizerRequest systemId="${#Project#SystemID}" systemPassword="${#Project#Password}" xmlns="http://movilitas.com/movilizer/v16"> <moveletDelete moveletKey="SCN_CALCULATOR2" /> <moveletSet> <movelet moveletKey="SCN_CALCULATOR2" initialQuestionKey="SCR_CALC_CUI1" moveletType="MULTI"> <question key="SCR_CALC_CUI1" type="5"> <answer key="ANS_VALUE1" nextQuestionKey="SCR_CALC_CUI2" attributeType="2" position="1" labelFontStyle="BOLD" columnSizeType="LEFT" > <text>Value 1:</text> <valueHintText>Write the value 1 here</valueHintText> </answer> <answer key="ANS_VALUE2" nextQuestionKey="SCR_CALC_CUI2" attributeType="2" position="2" labelFontStyle="BOLD" columnSizeType="LEFT" > <text>Value 2:</text> <valueHintText>Write the value 2 here</valueHintText> </answer> <answer key="ANS_OPERATOR" nextQuestionKey="SCR_CALC_CUI2" attributeType="6" position="3" labelFontStyle="BOLD" columnSizeType="LEFT" sortAnswerItemsByClientKey="true"> <item clientKey="CK_1SUM"> <value>Addition</value> </item> <item clientKey="CK_2RES"> <value>Subtraction</value> </item> <item clientKey="CK_3MUL"> <value>Multiplcation</value> </item> <item clientKey="CK_4DIV"> <value>Division</value> </item> <text>Operator:</text> <valueHintText>Select the operator here</valueHintText> </answer> <answer key="ANS_RESULT" nextQuestionKey="SCR_CALC_CUI2" attributeType="8" position="4" labelFontStyle="BOLD" columnSizeType="LEFT"> <text>Result:</text> </answer> <onExternalEvent> function( $ref:value, $ref:data ) { if( value == "CALCULATE" ) { data = null; data["VALUE1"] = getAnswerValueByClientKey($answer:"ANS_VALUE1", null); data["VALUE2"] = getAnswerValueByClientKey($answer:"ANS_VALUE2", null); data["OPERATOR"] = getAnswerValueByClientKey($answer:"ANS_OPERATOR", null); if( data["OPERATOR"] == "CK_1SUM" ) { data["RESULT"] = data["VALUE1"] + data["VALUE2"]; } else{ if( data["OPERATOR"] == "CK_2RES" ) { data["RESULT"] = data["VALUE1"] - data["VALUE2"]; } else{ if( data["OPERATOR"] == "CK_3MUL" ) { data["RESULT"] = data["VALUE1"] * data["VALUE2"]; } else{ if( data["OPERATOR"] == "CK_4DIV" ) { data["RESULT"] = data["VALUE1"] / data["VALUE2"]; }}}} setAnswerValueByClientKey($answer:"ANS_RESULT", null, data["RESULT"]); } } </onExternalEvent> <complex linearGroupId="CUI_CALC" linearPos="0" groupTitle="Calculator" /> </question> <question key="SCR_CALC_CUI2" type="5"> <answer key="ANS_CALCULATE" nextQuestionKey="END" attributeType="14" onScreenValueChangeEventTrigger="SYNCHRONOUS" position="5" labelFontStyle="BOLD" columnSizeType="ROWS"> <text>CALCULATE</text> </answer> <onScreenValueChangeEvent> function( $ref:answerKey, $ref:clientKey, $ref:value, $ref:data ) { if( answerKey == $answer:"ANS_CALCULATE" ) { triggerExternalEvent("CALCULATE", null); } } </onScreenValueChangeEvent> <complex linearGroupId="CUI_CALC" linearPos="1" /> </question> <name>Calculator 2</name> </movelet> <participant participantKey="Test1" name="Test1" deviceAddress="${#Project#Participant}" /> </moveletSet> </MovilizerRequest> |