-
Notifications
You must be signed in to change notification settings - Fork 0
/
authorview_box2dModel.js
132 lines (116 loc) · 4.17 KB
/
authorview_box2dModel.js
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
121
122
123
124
125
126
127
128
129
130
131
132
/**
* Sets the Box2dModelNode type as an object of this view
*
* TODO: rename Box2dModelNode
*
* @constructor
*/
View.prototype.Box2dModelNode = {};
/*
* Add the name of the common component that this step will use. The
* common components will be handled by the authoring tool. You will
* need to create div elements with the appropriate id for the
* authoring tool to insert the component into. Any additional custom
* authoring components specific to your step type will be written
* by you in the generatePage() function. You may leave the array
* empty if you are not using any common components.
*
* Here are the available common components
* 'Prompt'
* 'LinkTo'
* 'StudentResponseBoxSize'
* 'RichTextEditorToggle'
* 'StarterSentenceAuthoring'
*
* If you use a common components, you must create a div with the
* appropriate id, here are the respective ids
* 'promptContainer'
* (LinkTo does not require a div)
* 'studentResponseBoxSizeContainer'
* 'richTextEditorToggleContainer'
* 'starterSentenceAuthoringContainer'
*
*
* TODO: rename Box2dModelNode
*/
View.prototype.Box2dModelNode.commonComponents = ['Prompt'];
/**
* Generates the authoring page. This function will create the authoring
* components such as textareas, radio buttons, check boxes, etc. that
* authors will use to author the step. For example if the step has a
* text prompt that the student will read, this function will create
* a textarea that will allow the author to type the text that the
* student will see. You will also need to populate the textarea with
* the pre-existing prompt if the step has been authored before.
*
* TODO: rename Box2dModelNode
*/
View.prototype.Box2dModelNode.generatePage = function(view){
this.view = view;
//get the content of the step
this.content = this.view.activeContent.getContentJSON();
//get the html element that all the authoring components will be located
var parent = document.getElementById('dynamicParent');
/*
* wipe out the div that contains the authoring components because it
* may still be populated with the authoring components from a previous
* step the author has been authoring since we re-use the div id
*/
parent.removeChild(document.getElementById('dynamicPage'));
//create a new div that will contain the authroing components
var pageDiv = createElement(document, 'div', {id:'dynamicPage', style:'width:100%;height:100%'});
pageDiv.appendChild(document.createTextNode("Prompt for Student:"));
pageDiv.appendChild(createBreak());
pageDiv.appendChild(createElement(document, 'div', {id: 'promptContainer'}));
pageDiv.appendChild(createBreak());
//add the page to the parent
parent.appendChild(pageDiv);
//populate the prompt if this step has been authored before
this.populatePrompt();
};
/**
* Get the array of common components which is an array with
* string elements being the name of the common component
*
* TODO: rename Box2dModelNode
*/
View.prototype.Box2dModelNode.getCommonComponents = function() {
return this.commonComponents;
};
/**
* Updates this content object when requested, usually when preview is to be refreshed
*
* TODO: rename Box2dModelNode
*/
View.prototype.Box2dModelNode.updateContent = function(){
/* update content object */
this.view.activeContent.setContent(this.content);
};
/**
* Populate the authoring textarea where the user types the prompt that
* the student will read
*
* TODO: rename Box2dModelNode
*/
View.prototype.Box2dModelNode.populatePrompt = function() {
//get the prompt from the content and set it into the authoring textarea
$('#promptInput').val(this.content.prompt);
};
/**
* Updates the content's prompt to match that of what the user input
*
* TODO: rename Box2dModelNode
*/
View.prototype.Box2dModelNode.updatePrompt = function(){
/* update content */
var content = this.view.getRichTextContent('promptInput');
this.content.prompt = content;
/*
* fire source updated event, this will update the preview
*/
this.view.eventManager.fire('sourceUpdated');
};
//used to notify scriptloader that this script has finished loading
if(typeof eventManager != 'undefined'){
eventManager.fire('scriptLoaded', 'vle/node/box2dModel/authorview_box2dModel.js');
};