|
1 | 1 |
|
2 | 2 | var settings = { |
3 | | - timeToCheck: 1, |
4 | | - tabTogo: null, |
5 | | - defaulTabId: null, |
6 | 3 | defaultAction: 1, |
7 | 4 | targetUrl: null, |
8 | 5 | targetId: null, |
9 | | - lmsBaseJumpUrl: '../../../jump_to_id/', |
10 | 6 | message: null, |
11 | 7 | conditionReached: null, |
12 | 8 | inStudioRuntime: false |
13 | 9 | }; |
14 | 10 |
|
15 | 11 | var actions = { |
16 | 12 | noAct: 'No action', |
17 | | - redirectTab: 'to_unit', |
18 | 13 | redirectUrl: 'to_url', |
19 | 14 | redirectJump: 'to_jump', |
20 | 15 | show_message: 'display_message' |
@@ -44,17 +39,15 @@ var uiSelectors = { |
44 | 39 | }; |
45 | 40 |
|
46 | 41 | var viewblocks = { |
47 | | - seqContent: $('#seq_content'), |
| 42 | + seqContent: $('#course-content'), |
| 43 | + loadingMessageHtml: "<div><p>Loading, please wait...</p></div>", |
48 | 44 | hideNotAllowedOption: function hideNotAllowedOption() { |
49 | 45 | $(uiSelectors.settingsFields).hide(); |
50 | 46 | $(uiSelectors.settingsFields).filter('[data-field-name="condition"]').show(); |
51 | 47 | $(uiSelectors.settingsFields).filter('[data-field-name="action"]').show(); |
52 | 48 | $(uiSelectors.settingsFields).filter('[data-field-name="operator"]').show(); |
53 | 49 |
|
54 | 50 | switch ($(uiSelectors.action).val()) { |
55 | | - case actions.redirectTab: |
56 | | - $(uiSelectors.settingsFields).filter('[data-field-name="tab_to"]').show(); |
57 | | - break; |
58 | 51 | case actions.redirectUrl: |
59 | 52 | $(uiSelectors.settingsFields).filter('[data-field-name="target_url"]').show(); |
60 | 53 | break; |
@@ -89,81 +82,27 @@ var viewblocks = { |
89 | 82 | switch (settings.defaultAction) { |
90 | 83 | case actions.noAct: |
91 | 84 | break; |
92 | | - case actions.redirectTab: |
93 | | - viewblocks.seqContent.empty(); |
94 | | - window.flowControlTimeoutID = window.setTimeout(redirectToTab, |
95 | | - settings.timeToCheck, |
96 | | - settings.tabTogo); |
97 | | - break; |
98 | 85 | case actions.redirectUrl: |
99 | | - viewblocks.seqContent.empty(); |
100 | | - location.href = settings.targetUrl; |
| 86 | + viewblocks.seqContent.html(viewblocks.loadingMessageHtml); |
| 87 | + window.parent.location.href = settings.targetUrl; |
101 | 88 | break; |
102 | 89 | case actions.redirectJump: |
103 | | - viewblocks.seqContent.empty(); |
104 | | - location.href = settings.targetId; |
| 90 | + viewblocks.seqContent.html(viewblocks.loadingMessageHtml); |
| 91 | + window.parent.location.href = getJumpToIdUrl(settings.targetId); |
105 | 92 | break; |
106 | 93 | case actions.show_message: |
107 | | - $('#course-content').html(settings.message); |
| 94 | + viewblocks.seqContent.html(settings.message); |
108 | 95 | break; |
109 | 96 | } |
110 | 97 | } |
111 | 98 | } |
112 | 99 | }; |
113 | 100 |
|
114 | | -var getActiveTab = function getActiveTab() { |
115 | | - // return the active sequential button |
116 | | - $tab = $('#course-content #sequence-list button.active')[0]; |
117 | | - |
118 | | - return $tab; |
119 | | -}; |
120 | | - |
121 | | -var execControl = function execControl(arg) { |
122 | | - // Find the target tab |
123 | | - var $target = $('#sequence-list button').filter(function filterFunc() { |
124 | | - return $(this).attr('id') === arg; |
125 | | - }); |
126 | | - |
127 | | - // Do the action |
128 | | - $target.click(); |
129 | | - // TODO: can we make this silent. E.g. that it does not post to /handler/xmodule_handler/goto_position |
130 | | -}; |
131 | | - |
132 | | -var redirectToTab = function redirectToTab(arg) { |
133 | | - var $activeTab = getActiveTab(); |
134 | | - var currentID = $activeTab.id; |
135 | | - var allTabs = $('#sequence-list button'); |
136 | | - var firstTabIndex = 0; |
137 | | - var firstTab = 'tab_' + firstTabIndex; |
138 | | - var lastTabIndex = allTabs.length - 1; |
139 | | - var lastTab = 'tab_' + lastTabIndex; |
140 | | - |
141 | | - if (currentID === arg) { |
142 | | - window.clearTimeout(window.flowControlTimeoutID); |
143 | | - } else { |
144 | | - var whereTo = null; |
145 | | - if (settings.defaulTabId > lastTabIndex) { |
146 | | - whereTo = lastTab; |
147 | | - } |
148 | | - if (settings.defaulTabId < firstTabIndex) { |
149 | | - whereTo = firstTab; |
150 | | - } |
151 | | - if (firstTabIndex <= settings.defaulTabId && settings.defaulTabId <= lastTabIndex) { |
152 | | - whereTo = arg; |
153 | | - } |
154 | | - |
155 | | - execControl(whereTo); |
156 | | - window.flowControlTimeoutID = window.setTimeout(redirectToTab, settings.timeToCheck, whereTo); |
157 | | - } |
158 | | -}; |
159 | | - |
160 | 101 | function FlowControlGoto(runtime, element, options) { |
161 | 102 | // Getting settings varibales to apply flow control |
162 | | - settings.tabTogo = options.default; |
163 | 103 | settings.defaultAction = options.action; |
164 | 104 | settings.targetUrl = options.target_url; |
165 | | - settings.targetId = settings.lmsBaseJumpUrl + options.target_id; |
166 | | - settings.defaulTabId = options.default_tab_id; |
| 105 | + settings.targetId = options.target_id; |
167 | 106 | settings.message = options.message; |
168 | 107 | settings.inStudioRuntime = options.in_studio_runtime; |
169 | 108 |
|
@@ -202,3 +141,16 @@ function StudioFlowControl(runtime, element) { |
202 | 141 | $(uiSelectors.visibility).hide(); |
203 | 142 | $(uiSelectors.duplicate).hide(); |
204 | 143 | } |
| 144 | + |
| 145 | +function getCourseIdByUrl() { |
| 146 | + const regex = /(?:block-v1:)(.+)(?:\+type)/; |
| 147 | + const result = window.location.href.match(regex); |
| 148 | + if (result) { |
| 149 | + return result[1]; |
| 150 | + } |
| 151 | + return null; |
| 152 | +} |
| 153 | + |
| 154 | +function getJumpToIdUrl(id) { |
| 155 | + return `${window.location.origin}/courses/course-v1:${getCourseIdByUrl()}/jump_to_id/${id}`; |
| 156 | +} |
0 commit comments