@citolab/tspci-tao 2.0.9 → 2.3.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/init.mjs ADDED
@@ -0,0 +1,112 @@
1
+ import fs, { cp, mkdirSync } from "fs";
2
+ import path from "path";
3
+ import readline from "readline";
4
+ import chalk from "chalk";
5
+ import inquirer from "inquirer";
6
+ function askOption(prompt) {
7
+ const rl = readline.createInterface({
8
+ input: process.stdin,
9
+ output: process.stdout,
10
+ });
11
+ return new Promise((resolve) => {
12
+ rl.question(prompt, (option) => {
13
+ rl.close();
14
+ resolve(option);
15
+ });
16
+ });
17
+ }
18
+
19
+ function selectOptions(prompt, options) {
20
+ return inquirer.prompt([
21
+ {
22
+ type: "checkbox",
23
+ message: prompt,
24
+ name: "values",
25
+ choices: options.map((o) => ({ name: o, checked: true })),
26
+ },
27
+ ]);
28
+ }
29
+
30
+ export const init = async () => {
31
+ console.log("adding TAO support to PCI");
32
+ const PACKAGE_ROOT_PATH = process.cwd();
33
+ const packageData = JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT_PATH, "package.json"), "utf8"));
34
+ const typeIdentifer = packageData.config?.tspci?.typeIdentifier;
35
+ if (!typeIdentifer) {
36
+ console.error(
37
+ "No typeIdentifier found in package.json (config { tspci: { typeIdentifier: 'my-pci' }}). Add it and make sure it matches the PCI typeIdentifier property"
38
+ );
39
+ return;
40
+ }
41
+ // get first 5 chars of identifier
42
+ const defaultShort = typeIdentifer.length > 5 ? typeIdentifer.substring(0, 5) : typeIdentifer;
43
+ const short = (await askOption(
44
+ `Enter a short name for the PCI: (default: ${defaultShort})`
45
+ )) || defaultShort;
46
+
47
+ const defaultLabel = typeIdentifer.length > 5 ? typeIdentifer.substring(0, 5) : typeIdentifer;
48
+ const label = (await askOption(
49
+ `Enter the label of the PCI: (default: ${defaultLabel})`
50
+ )) || defaultLabel;
51
+ const scoringsMethods = await selectOptions("Which scoring methods do you want to support?", [
52
+ "MATCH_CORRECT", "NONE"
53
+ ]);
54
+ const scoreMethodArray = scoringsMethods.values
55
+
56
+ // adding short, label and typeIdentifer to packageData
57
+ packageData.config.tspci.short = short;
58
+ packageData.config.tspci.label = label;
59
+ packageData.config.tspci.typeIdentifier = typeIdentifer;
60
+ packageData.config.tspci.score = scoreMethodArray;
61
+
62
+ packageData.scripts = packageData.scripts || {};
63
+ packageData.scripts["package:tao"] = "tspci --target tao";
64
+ // store packageData
65
+ fs.writeFileSync(path.join(PACKAGE_ROOT_PATH, "package.json"), JSON.stringify(packageData, null, 2), "utf8");
66
+
67
+ console.log("Adding TAO interface to PCI");
68
+ if (!packageData.source) {
69
+ console.error("Failed implementing TAO interface; No source property found in package.json.");
70
+ }
71
+
72
+ const sourceFile = fs.readFileSync(path.join(PACKAGE_ROOT_PATH, packageData.source), "utf8");
73
+ if (sourceFile.indexOf("implements IMSpci<PropTypes>, TAOpci") === -1) {
74
+ console.log("TAO interface not implemented yet; Implementing...");
75
+ if (sourceFile.indexOf("implements IMSpci<PropTypes> {") === -1) {
76
+ console.error("Cannot implement TAOpci interface automatically. Please implement it manually.");
77
+ } else {
78
+ let newSourceFile = sourceFile.replace(
79
+ "implements IMSpci<PropTypes> {",
80
+ "implements IMSpci<PropTypes>, TAOpci {"
81
+ );
82
+ // add import { TAOpci } from "@citolab/tspci-tao"; to the top of the file
83
+ newSourceFile = `import { TAOpci } from "@citolab/tspci-tao";\r\n${newSourceFile}`;
84
+ if (newSourceFile.indexOf(" QtiVariableJSON ") === -1) {
85
+ newSourceFile = `import { QtiVariableJSON } from "@citolab/tspci";\r\n${newSourceFile}`;
86
+ }
87
+ const defaultImplementation = `
88
+ off = () => {}; // called when setting correct response in tao
89
+ on = (val) => {};
90
+ trigger = (event: string, value: any) => {
91
+ this.config.properties[event] = value;
92
+ this.render();
93
+ };
94
+ resetResponse = () => {
95
+ // used in tao to reset the response. clean-up and re-render the PCI would be best.
96
+ // this.render();
97
+ };
98
+ setResponse = (response: QtiVariableJSON) => {
99
+ // used to set the response in tao. E.g. when the item author has set a correct response. And you refresh TAO it will call this method to set the response in the PCI in the score-editor.
100
+ };
101
+ `
102
+ const lastBracket = newSourceFile.lastIndexOf("}");
103
+ newSourceFile = newSourceFile.substring(0, lastBracket) + defaultImplementation + newSourceFile.substring(lastBracket);
104
+
105
+ fs.writeFileSync(path.join(PACKAGE_ROOT_PATH, packageData.source), newSourceFile, "utf8");
106
+ console.log("TAO interface implemented");
107
+ }
108
+ } else {
109
+ console.log("TAO interface already implemented");
110
+ }
111
+ };
112
+
@@ -1,67 +1,67 @@
1
- define([
2
- 'lodash',
3
- '##typeIdentifier##/interaction/creator/widget/Widget',
4
- 'tpl!##typeIdentifier##/interaction/creator/tpl/markup'
5
- ], function(_, Widget, markupTpl){
6
-
7
- var _typeIdentifier = '##typeIdentifier##';
8
-
9
- var interactionCreator = {
10
- /**
11
- * (required) Get the typeIdentifier of the custom interaction
12
- *
13
- * @returns {String}
14
- */
15
- gettypeIdentifier : function(){
16
- return _typeIdentifier;
17
- },
18
- /**
19
- * (required) Get the widget prototype
20
- * Used in the renderer
21
- *
22
- * @returns {Object} Widget
23
- */
24
- getWidget : function(){
25
- return Widget;
26
- },
27
- /**
28
- * (optional) Get the default properties values of the pci.
29
- * Used on new pci instance creation
30
- *
31
- * @returns {Object}
32
- */
33
- getDefaultProperties : function(pci){
34
- return '##__DEFAULT_VALUES__##'
35
- },
36
- /**
37
- * (optional) Callback to execute on the
38
- * Used on new pci instance creation
39
- *
40
- * @returns {Object}
41
- */
42
- afterCreate : function(pci){
43
- pci.getResponseDeclaration().setTemplate('###_FIRST_SCORING_METHOD_###');
44
- },
45
- /**
46
- * (required) Gives the qti pci xml template
47
- *
48
- * @returns {function} handlebar template
49
- */
50
- getMarkupTemplate : function(){
51
- return markupTpl;
52
- },
53
- /**
54
- * (optional) Allows passing additional data to xml template
55
- *
56
- * @returns {function} handlebar template
57
- */
58
- getMarkupData : function(pci, defaultData){
59
- defaultData.prompt = pci.data('prompt');
60
- return defaultData;
61
- }
62
- };
63
-
64
- //since we assume we are in a tao context, there is no use to expose the a global object for lib registration
65
- //all libs should be declared here
66
- return interactionCreator;
1
+ define([
2
+ 'lodash',
3
+ '##typeIdentifier##/interaction/creator/widget/Widget',
4
+ 'tpl!##typeIdentifier##/interaction/creator/tpl/markup'
5
+ ], function(_, Widget, markupTpl){
6
+
7
+ var _typeIdentifier = '##typeIdentifier##';
8
+
9
+ var interactionCreator = {
10
+ /**
11
+ * (required) Get the typeIdentifier of the custom interaction
12
+ *
13
+ * @returns {String}
14
+ */
15
+ getTypeIdentifier : function(){
16
+ return _typeIdentifier;
17
+ },
18
+ /**
19
+ * (required) Get the widget prototype
20
+ * Used in the renderer
21
+ *
22
+ * @returns {Object} Widget
23
+ */
24
+ getWidget : function(){
25
+ return Widget;
26
+ },
27
+ /**
28
+ * (optional) Get the default properties values of the pci.
29
+ * Used on new pci instance creation
30
+ *
31
+ * @returns {Object}
32
+ */
33
+ getDefaultProperties : function(pci){
34
+ return '##__DEFAULT_VALUES__##'
35
+ },
36
+ /**
37
+ * (optional) Callback to execute on the
38
+ * Used on new pci instance creation
39
+ *
40
+ * @returns {Object}
41
+ */
42
+ afterCreate : function(pci){
43
+ pci.getResponseDeclaration().setTemplate('###_FIRST_SCORING_METHOD_###');
44
+ },
45
+ /**
46
+ * (required) Gives the qti pci xml template
47
+ *
48
+ * @returns {function} handlebar template
49
+ */
50
+ getMarkupTemplate : function(){
51
+ return markupTpl;
52
+ },
53
+ /**
54
+ * (optional) Allows passing additional data to xml template
55
+ *
56
+ * @returns {function} handlebar template
57
+ */
58
+ getMarkupData : function(pci, defaultData){
59
+ defaultData.prompt = pci.data('prompt');
60
+ return defaultData;
61
+ }
62
+ };
63
+
64
+ //since we assume we are in a tao context, there is no use to expose the a global object for lib registration
65
+ //all libs should be declared here
66
+ return interactionCreator;
67
67
  });
@@ -1,42 +1,42 @@
1
- {
2
- "model" : "IMSPCI",
3
- "typeIdentifier": "##typeIdentifier##",
4
- "label": "##label##",
5
- "short": "##short##",
6
- "description": "##description##",
7
- "version": "##version##",
8
- "author": "Citolab",
9
- "email": "getinspiredbycitolab@gmail.com",
10
- "tags": [
11
- "pci"
12
- ],
13
- "response": {
14
- "baseType": "string",
15
- "cardinality": "single"
16
- },
17
- "runtime" : {
18
- "hook" : "interaction/runtime/js/index.js",
19
- "modules" : {
20
- "##typeIdentifier##/interaction/runtime/js/index" : [
21
- "interaction/runtime/js/index.js"
22
- ]
23
- },
24
- "src" : [
25
- "./interaction/runtime/js/index.js"
26
- ]
27
- },
28
- "creator" : {
29
- "icon": "./interaction/creator/img/icon.svg",
30
- "hook": "./imsPciCreator.js",
31
- "src" : [
32
- "./imsPciCreator.js",
33
- "./interaction/creator/tpl/markup.tpl",
34
- "./interaction/creator/tpl/propertiesForm.tpl",
35
- "./interaction/creator/widget/Widget.js",
36
- "./interaction/creator/widget/states/Question.js",
37
- "./interaction/creator/widget/states/Answer.js",
38
- "./interaction/creator/widget/states/Correct.js",
39
- "./interaction/creator/widget/states/states.js"
40
- ]
41
- }
1
+ {
2
+ "model" : "IMSPCI",
3
+ "typeIdentifier": "##typeIdentifier##",
4
+ "label": "##label##",
5
+ "short": "##short##",
6
+ "description": "##description##",
7
+ "version": "##version##",
8
+ "author": "Citolab",
9
+ "email": "getinspiredbycitolab@gmail.com",
10
+ "tags": [
11
+ "pci"
12
+ ],
13
+ "response": {
14
+ "baseType": "string",
15
+ "cardinality": "single"
16
+ },
17
+ "runtime" : {
18
+ "hook" : "interaction/runtime/js/index.js",
19
+ "modules" : {
20
+ "##typeIdentifier##/interaction/runtime/js/index" : [
21
+ "interaction/runtime/js/index.js"
22
+ ]
23
+ },
24
+ "src" : [
25
+ "./interaction/runtime/js/index.js"
26
+ ]
27
+ },
28
+ "creator" : {
29
+ "icon": "./interaction/creator/img/icon.svg",
30
+ "hook": "./imsPciCreator.js",
31
+ "src" : [
32
+ "./imsPciCreator.js",
33
+ "./interaction/creator/tpl/markup.tpl",
34
+ "./interaction/creator/tpl/propertiesForm.tpl",
35
+ "./interaction/creator/widget/Widget.js",
36
+ "./interaction/creator/widget/states/Question.js",
37
+ "./interaction/creator/widget/states/Answer.js",
38
+ "./interaction/creator/widget/states/Correct.js",
39
+ "./interaction/creator/widget/states/states.js"
40
+ ]
41
+ }
42
42
  }
@@ -1,8 +1,8 @@
1
- <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
- <svg xmlns:svg="http://www.w3.org/2000/svg"
3
- xmlns="http://www.w3.org/2000/svg"
4
- height="28" width="28">
5
- <g transform="scale(0.88 0.88)">
6
- <path d="M29.164 10.472c-1.25-0.328-4.189-0.324-8.488-0.438 0.203-0.938 0.25-1.784 0.25-3.286 0-3.588-2.614-6.748-4.926-6.748-1.633 0-2.979 1.335-3 2.977-0.022 2.014-0.645 5.492-4 7.256-0.246 0.13-0.95 0.477-1.053 0.522l0.053 0.045c-0.525-0.453-1.253-0.8-2-0.8h-3c-1.654 0-3 1.346-3 3v16c0 1.654 1.346 3 3 3h3c1.19 0 2.186-0.719 2.668-1.727 0.012 0.004 0.033 0.010 0.047 0.012 0.066 0.018 0.144 0.037 0.239 0.062 0.018 0.005 0.027 0.007 0.046 0.012 0.576 0.143 1.685 0.408 4.055 0.953 0.508 0.116 3.192 0.688 5.972 0.688h5.467c1.666 0 2.867-0.641 3.582-1.928 0.010-0.020 0.24-0.469 0.428-1.076 0.141-0.457 0.193-1.104 0.023-1.76 1.074-0.738 1.42-1.854 1.645-2.58 0.377-1.191 0.264-2.086 0.002-2.727 0.604-0.57 1.119-1.439 1.336-2.766 0.135-0.822-0.010-1.668-0.389-2.372 0.566-0.636 0.824-1.436 0.854-2.176l0.012-0.209c0.007-0.131 0.013-0.212 0.013-0.5 0-1.263-0.875-2.874-2.836-3.434zM7 29c0 0.553-0.447 1-1 1h-3c-0.553 0-1-0.447-1-1v-16c0-0.553 0.447-1 1-1h3c0.553 0 1 0.447 1 1v16zM29.977 14.535c-0.020 0.494-0.227 1.465-1.977 1.465-1.5 0-2 0-2 0-0.277 0-0.5 0.224-0.5 0.5s0.223 0.5 0.5 0.5c0 0 0.438 0 1.938 0s1.697 1.244 1.6 1.844c-0.124 0.746-0.474 2.156-2.163 2.156-1.687 0-2.375 0-2.375 0-0.277 0-0.5 0.223-0.5 0.5 0 0.275 0.223 0.5 0.5 0.5 0 0 1.188 0 1.969 0 1.688 0 1.539 1.287 1.297 2.055-0.319 1.009-0.514 1.945-2.641 1.945-0.719 0-1.631 0-1.631 0-0.277 0-0.5 0.223-0.5 0.5 0 0.275 0.223 0.5 0.5 0.5 0 0 0.693 0 1.568 0 1.094 0 1.145 1.035 1.031 1.406-0.125 0.406-0.273 0.707-0.279 0.721-0.302 0.545-0.789 0.873-1.82 0.873h-5.467c-2.746 0-5.47-0.623-5.54-0.639-4.154-0.957-4.373-1.031-4.634-1.105 0 0-0.846-0.143-0.846-0.881l-0.007-13.812c0-0.469 0.299-0.893 0.794-1.042 0.062-0.024 0.146-0.050 0.206-0.075 4.568-1.892 5.959-6.040 6-9.446 0.006-0.479 0.375-1 1-1 1.057 0 2.926 2.122 2.926 4.748 0 2.371-0.096 2.781-0.926 5.252 10 0 9.93 0.144 10.812 0.375 1.094 0.313 1.188 1.219 1.188 1.531 0 0.343-0.010 0.293-0.023 0.629zM4.5 26c-0.828 0-1.5 0.672-1.5 1.5s0.672 1.5 1.5 1.5 1.5-0.672 1.5-1.5-0.672-1.5-1.5-1.5zM4.5 28c-0.275 0-0.5-0.225-0.5-0.5s0.225-0.5 0.5-0.5 0.5 0.225 0.5 0.5-0.225 0.5-0.5 0.5z"></path>
7
- </g>
8
- </svg>
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <svg xmlns:svg="http://www.w3.org/2000/svg"
3
+ xmlns="http://www.w3.org/2000/svg"
4
+ height="28" width="28">
5
+ <g transform="scale(0.88 0.88)">
6
+ <path d="M29.164 10.472c-1.25-0.328-4.189-0.324-8.488-0.438 0.203-0.938 0.25-1.784 0.25-3.286 0-3.588-2.614-6.748-4.926-6.748-1.633 0-2.979 1.335-3 2.977-0.022 2.014-0.645 5.492-4 7.256-0.246 0.13-0.95 0.477-1.053 0.522l0.053 0.045c-0.525-0.453-1.253-0.8-2-0.8h-3c-1.654 0-3 1.346-3 3v16c0 1.654 1.346 3 3 3h3c1.19 0 2.186-0.719 2.668-1.727 0.012 0.004 0.033 0.010 0.047 0.012 0.066 0.018 0.144 0.037 0.239 0.062 0.018 0.005 0.027 0.007 0.046 0.012 0.576 0.143 1.685 0.408 4.055 0.953 0.508 0.116 3.192 0.688 5.972 0.688h5.467c1.666 0 2.867-0.641 3.582-1.928 0.010-0.020 0.24-0.469 0.428-1.076 0.141-0.457 0.193-1.104 0.023-1.76 1.074-0.738 1.42-1.854 1.645-2.58 0.377-1.191 0.264-2.086 0.002-2.727 0.604-0.57 1.119-1.439 1.336-2.766 0.135-0.822-0.010-1.668-0.389-2.372 0.566-0.636 0.824-1.436 0.854-2.176l0.012-0.209c0.007-0.131 0.013-0.212 0.013-0.5 0-1.263-0.875-2.874-2.836-3.434zM7 29c0 0.553-0.447 1-1 1h-3c-0.553 0-1-0.447-1-1v-16c0-0.553 0.447-1 1-1h3c0.553 0 1 0.447 1 1v16zM29.977 14.535c-0.020 0.494-0.227 1.465-1.977 1.465-1.5 0-2 0-2 0-0.277 0-0.5 0.224-0.5 0.5s0.223 0.5 0.5 0.5c0 0 0.438 0 1.938 0s1.697 1.244 1.6 1.844c-0.124 0.746-0.474 2.156-2.163 2.156-1.687 0-2.375 0-2.375 0-0.277 0-0.5 0.223-0.5 0.5 0 0.275 0.223 0.5 0.5 0.5 0 0 1.188 0 1.969 0 1.688 0 1.539 1.287 1.297 2.055-0.319 1.009-0.514 1.945-2.641 1.945-0.719 0-1.631 0-1.631 0-0.277 0-0.5 0.223-0.5 0.5 0 0.275 0.223 0.5 0.5 0.5 0 0 0.693 0 1.568 0 1.094 0 1.145 1.035 1.031 1.406-0.125 0.406-0.273 0.707-0.279 0.721-0.302 0.545-0.789 0.873-1.82 0.873h-5.467c-2.746 0-5.47-0.623-5.54-0.639-4.154-0.957-4.373-1.031-4.634-1.105 0 0-0.846-0.143-0.846-0.881l-0.007-13.812c0-0.469 0.299-0.893 0.794-1.042 0.062-0.024 0.146-0.050 0.206-0.075 4.568-1.892 5.959-6.040 6-9.446 0.006-0.479 0.375-1 1-1 1.057 0 2.926 2.122 2.926 4.748 0 2.371-0.096 2.781-0.926 5.252 10 0 9.93 0.144 10.812 0.375 1.094 0.313 1.188 1.219 1.188 1.531 0 0.343-0.010 0.293-0.023 0.629zM4.5 26c-0.828 0-1.5 0.672-1.5 1.5s0.672 1.5 1.5 1.5 1.5-0.672 1.5-1.5-0.672-1.5-1.5-1.5zM4.5 28c-0.275 0-0.5-0.225-0.5-0.5s0.225-0.5 0.5-0.5 0.5 0.225 0.5 0.5-0.225 0.5-0.5 0.5z"></path>
7
+ </g>
8
+ </svg>
@@ -1,19 +1,19 @@
1
- <div class="pciInteraction">
2
- <style>
3
- .pciInteraction ul.pci{
4
- list-style-type: none;
5
- margin: 0 5px;
6
- padding: 0;
7
- display: inline-block;
8
- position: relative;
9
- top: 7px;
10
- }
11
- .pciInteraction ul.pci li{
12
- float: left;
13
- text-align: left;
14
- list-style-type: none;
15
- }
16
- </style>
17
- <div class="prompt">{{{prompt}}}</div>
18
- <ul class="pci"></ul>
1
+ <div class="pciInteraction">
2
+ <style>
3
+ .pciInteraction ul.pci{
4
+ list-style-type: none;
5
+ margin: 0 5px;
6
+ padding: 0;
7
+ display: inline-block;
8
+ position: relative;
9
+ top: 7px;
10
+ }
11
+ .pciInteraction ul.pci li{
12
+ float: left;
13
+ text-align: left;
14
+ list-style-type: none;
15
+ }
16
+ </style>
17
+ <div class="prompt">{{{prompt}}}</div>
18
+ <ul class="pci"></ul>
19
19
  </div>
@@ -1,8 +1,8 @@
1
- <div class="panel">
2
- <input type="text"
3
- name="identifier"
4
- value="{{identifier}}"
5
- placeholder="e.g. RESPONSE"
6
- data-validate="$notEmpty; $qtiIdentifier; $availableIdentifier(serial={{serial}});">
7
- <!-- ##_HTML_CONTROLS_## -->
1
+ <div class="panel">
2
+ <input type="text"
3
+ name="identifier"
4
+ value="{{identifier}}"
5
+ placeholder="e.g. RESPONSE"
6
+ data-validate="$notEmpty; $qtiIdentifier; $availableIdentifier(serial={{serial}});">
7
+ <!-- ##_HTML_CONTROLS_## -->
8
8
  </div>
@@ -1,15 +1,15 @@
1
- define([
2
- 'taoQtiItem/qtiCreator/widgets/interactions/customInteraction/Widget',
3
- '##typeIdentifier##/interaction/creator/widget/states/states'
4
- ], function(Widget, states){
5
-
6
- var InteractionWidget = Widget.clone();
7
-
8
- InteractionWidget.initCreator = function(){
9
- this.registerStates(states);
10
-
11
- Widget.initCreator.call(this);
12
- };
13
-
14
- return InteractionWidget;
1
+ define([
2
+ 'taoQtiItem/qtiCreator/widgets/interactions/customInteraction/Widget',
3
+ '##typeIdentifier##/interaction/creator/widget/states/states'
4
+ ], function(Widget, states){
5
+
6
+ var InteractionWidget = Widget.clone();
7
+
8
+ InteractionWidget.initCreator = function(){
9
+ this.registerStates(states);
10
+
11
+ Widget.initCreator.call(this);
12
+ };
13
+
14
+ return InteractionWidget;
15
15
  });
@@ -1,26 +1,26 @@
1
- define([
2
- 'taoQtiItem/qtiCreator/widgets/states/factory',
3
- 'taoQtiItem/qtiCreator/widgets/interactions/states/Answer',
4
- 'taoQtiItem/qtiCreator/widgets/interactions/helpers/answerState'
5
- ], function(stateFactory, Answer, answerStateHelper){
6
-
7
- var InteractionStateAnswer = stateFactory.extend(Answer, function(){
8
-
9
- //forward to one of the available sub state, according to the response processing template
10
- answerStateHelper.forward(this.widget);
11
-
12
- }, function(){
13
-
14
- });
15
-
16
- InteractionStateAnswer.prototype.initResponseForm = function initResponseForm() {
17
- answerStateHelper.initResponseForm(
18
- this.widget,
19
- {
20
- rpTemplates: ['###_RD_TEMPLATES_###'],
21
- }
22
- );
23
- };
24
-
25
- return InteractionStateAnswer;
26
- });
1
+ define([
2
+ 'taoQtiItem/qtiCreator/widgets/states/factory',
3
+ 'taoQtiItem/qtiCreator/widgets/interactions/states/Answer',
4
+ 'taoQtiItem/qtiCreator/widgets/interactions/helpers/answerState'
5
+ ], function(stateFactory, Answer, answerStateHelper){
6
+
7
+ var InteractionStateAnswer = stateFactory.extend(Answer, function(){
8
+
9
+ //forward to one of the available sub state, according to the response processing template
10
+ answerStateHelper.forward(this.widget);
11
+
12
+ }, function(){
13
+
14
+ });
15
+
16
+ InteractionStateAnswer.prototype.initResponseForm = function initResponseForm() {
17
+ answerStateHelper.initResponseForm(
18
+ this.widget,
19
+ {
20
+ rpTemplates: ['###_RD_TEMPLATES_###'],
21
+ }
22
+ );
23
+ };
24
+
25
+ return InteractionStateAnswer;
26
+ });
@@ -1,44 +1,44 @@
1
- define([
2
- "taoQtiItem/qtiCreator/widgets/states/factory",
3
- "taoQtiItem/qtiCreator/widgets/interactions/states/Correct",
4
- "lodash",
5
- ], function (stateFactory, Correct, _) {
6
- var InteractionStateCorrect = stateFactory.create(
7
- Correct,
8
- function () {
9
- var widget = this.widget;
10
- var interaction = widget.element;
11
- var responseDeclaration = interaction.getResponseDeclaration();
12
- var correct = _.values(responseDeclaration.getCorrect());
13
- // show correct response in the pci.
14
- if (correct && typeof correct[0] !== "undefined") {
15
- interaction?.setResponse && interaction.setResponse({ base: { string: correct[0] } });
16
- }
17
- },
18
- function () {
19
- var widget = this.widget;
20
- var interaction = widget.element;
21
- var responseDeclaration = interaction.getResponseDeclaration();
22
- var correct = interaction && interaction.getResponse ? interaction.getResponse() : undefined;
23
- var correctString = '';
24
- if (correct !== undefined && correct.base) {
25
- if (correct.base.string !== null && (correct.base.string !== undefined)) {
26
- correctString = correct.base.string;
27
- } else if (correct.base.integer !== null && (correct.base.integer !== undefined)) {
28
- correctString = correct.base.integer;
29
- } else if (correct.base.boolean !== null && (correct.base.boolean !== undefined)) {
30
- correctString = correct.base.boolean;
31
- }
32
- }
33
-
34
- // getResponse
35
- // var correct = _.values(responseDeclaration.getCorrect());
36
- responseDeclaration.setCorrect(correctString);
37
-
38
- interaction.resetResponse();
39
- interaction.offPci(".question");
40
- }
41
- );
42
-
43
- return InteractionStateCorrect;
44
- });
1
+ define([
2
+ "taoQtiItem/qtiCreator/widgets/states/factory",
3
+ "taoQtiItem/qtiCreator/widgets/interactions/states/Correct",
4
+ "lodash",
5
+ ], function (stateFactory, Correct, _) {
6
+ var InteractionStateCorrect = stateFactory.create(
7
+ Correct,
8
+ function () {
9
+ var widget = this.widget;
10
+ var interaction = widget.element;
11
+ var responseDeclaration = interaction.getResponseDeclaration();
12
+ var correct = _.values(responseDeclaration.getCorrect());
13
+ // show correct response in the pci.
14
+ if (correct && typeof correct[0] !== "undefined") {
15
+ interaction?.setResponse && interaction.setResponse({ base: { string: correct[0] } });
16
+ }
17
+ },
18
+ function () {
19
+ var widget = this.widget;
20
+ var interaction = widget.element;
21
+ var responseDeclaration = interaction.getResponseDeclaration();
22
+ var correct = interaction && interaction.getResponse ? interaction.getResponse() : undefined;
23
+ var correctString = '';
24
+ if (correct !== undefined && correct.base) {
25
+ if (correct.base.string !== null && (correct.base.string !== undefined)) {
26
+ correctString = correct.base.string;
27
+ } else if (correct.base.integer !== null && (correct.base.integer !== undefined)) {
28
+ correctString = correct.base.integer;
29
+ } else if (correct.base.boolean !== null && (correct.base.boolean !== undefined)) {
30
+ correctString = correct.base.boolean;
31
+ }
32
+ }
33
+
34
+ // getResponse
35
+ // var correct = _.values(responseDeclaration.getCorrect());
36
+ responseDeclaration.setCorrect(correctString);
37
+
38
+ interaction.resetResponse();
39
+ interaction.offPci(".question");
40
+ }
41
+ );
42
+
43
+ return InteractionStateCorrect;
44
+ });