-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathhml_form_js.php
303 lines (252 loc) · 9 KB
/
hml_form_js.php
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This page contains the code for the modal popup dialog
*
* @package mod
* @subpackage helixmedia
* @author Tim Williams for Streaming LTD
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
require_login();
header("Content-Type: text/javascript");
global $CFG;
?>
var activity_dialog;
var gotIn = false;
var medial_interval;
function maintainSession() {
var xmlDoc = null;
if (typeof window.ActiveXObject != 'undefined' )
xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
else
xmlDoc = new XMLHttpRequest();
console.log("MEDIAL: Maintaining Moodle session while dialog is open");
xmlDoc.open("GET", "<?php $CFG->wwwroot; ?>/mod/helixmedia/session.php" , true);
xmlDoc.send();
setTimeout(maintainSession, <?php echo ($CFG->sessiontimeout / 2) * 1000; ?>);
}
function checkStatus()
{
var xmlDoc = null;
if (typeof window.ActiveXObject != 'undefined' )
xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
else
xmlDoc = new XMLHttpRequest();
var params = "resource_link_id="+resID+"&user_id="+userID+"&oauth_consumer_key="+oauthConsumerKey;
xmlDoc.open("POST", statusURL , false);
xmlDoc.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlDoc.send(params);
if (xmlDoc.responseText=="IN")
gotIn=true;
if (xmlDoc.responseText!="OUT" || gotIn==false) {
if (medial_interval == null) {
medial_interval = setInterval(checkStatus, 2000);
}
} else {
<?php
$modconfig = get_config("helixmedia");
$delay = intval($modconfig->modal_delay);
if ($delay == 0) {
echo "closeDialogue();\n";
} else {
if ($delay > 0) {
echo "setTimeout(closeDialogue, ".($delay * 1000).");\n";
}
}
?>
}
}
function closeDialogue()
{
clearInterval(medial_interval);
var tframe = document.getElementById("thumbframe");
if (tframe != null && typeof(thumburl) != "undefined")
tframe.contentWindow.location = thumburl;
activity_dialog.hide();
setTimeout(function() {
document.getElementById('yui_act_sel_dialog').innerHTML = "";
}, 500);
var mform1 = document.getElementById("mform1");
if (mform1 == null) {
var elements = document.getElementsByClassName("mform");
mform1 = elements[0];
}
if (mform1 != null)
{
if (typeof mform1.elements['helixassign_activated'] != "undefined")
{
mform1.elements['helixassign_activated'].value = "1";
}
else
if (typeof mform1.elements['helixfeedback_activated'] != "undefined")
{
mform1.elements['helixfeedback_activated'].value = "1";
}
}
activity_dialog = null;
// Sometimes the yui_act_sel_dialog_mask element get duplicated (bug in Moodle?) and only one will be
// unmasked when the dialog is closed. So we need to find the duplicates and then hide them as well. Using the
// the id doesn't work because it only finds the first duplicate so we need to search for the mask class.
var maskdivs = document.getElementsByClassName("mask");
for (i=0; i < maskdivs.length; i++) {
if (maskdivs[i].id == "yui_act_sel_dialog_mask") {
maskdivs[i].style.display = "none";
}
}
while (maskdivs.length>1) {
maskdivs[0].parentNode.removeChild(maskdivs[0]);
maskdivs = document.getElementsByClassName("mask");
}
}
YUI().use('yui2-container', 'yui2-connection', function(Y) {
var YAHOO = Y.YUI2;
YUI().use('node-base', function(Y) {
function init() {
//We need to create a hidden div to act as the container for the modal popup
var yui_act_sel_dialog = Y.one('#yui_act_sel_dialog');
if (!yui_act_sel_dialog) {
var el = document.createElement('div');
el.id = 'yui_act_sel_dialog';
document.getElementsByTagName('body')[0].appendChild(el);
}
//links which have the pop_up_selector_link class will be turned into modal form windows
Y.all(".pop_up_selector_link").on('click', function(e) {
var a = new com.uol.PopupHandler(e.currentTarget.get('href'), false);
a.ajax();
if (e.preventDefault) {
e.preventDefault();
}
return false;
});
}
Y.on("domready", init);
});
if (typeof com == 'undefined') {
var com = {};
}
if (typeof com.uol == 'undefined') {
com.uol = {};
}
(function() {
/**
* Constructor for the PopupHandler class
* @param url
*/
this.PopupHandler = function(url) {
this.url = url;
this.setWindowSize();
this.url += '&w='+this.width+'&h='+this.height;
},
this.PopupHandler.prototype.setWindowSize = function() {
var wWidth = 0;
var wHeight = 0;
var top;
wWidth = document.documentElement.clientWidth;
wHeight = document.documentElement.clientHeight;
top = document.documentElement.scrollTop;
if (this.detectMobile()) {
this.width = wWidth;
this.height = wHeight;
} else {
this.width = wWidth-6;
this.height = wHeight;
}
if (this.width > 1000) {
this.width = 1000;
}
if (this.height > 1400) {
this.height = 1400;
}
this.y = top;
this.x = (wWidth-this.width)/2;
if (this.x > 8) {
this.x = this.x-8;
} else {
this.x = 0;
}
},
this.PopupHandler.prototype.detectMobile = function() {
if( navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)
){
return true;
} else {
return false;
}
},
/**
* Method to call load the form
*/
this.PopupHandler.prototype.ajax = function() {
//Assignment call to solve the scope problem in ajax_callback
this.ajax_callback.argument[0] = this.width;
this.ajax_callback.argument[1] = this.height;
this.ajax_callback.argument[2] = this.x;
this.ajax_callback.argument[3] = this.y;
var furl = this.url;
var nameEle = document.getElementById("id_name");
if (nameEle != null) {
furl += "&name="+encodeURIComponent(nameEle.value);
}
var introEle = document.getElementById("id_introeditor");
if (introEle != null) {
furl+="&intro="+encodeURIComponent(introEle.value.replace(/<(?:.|\n)*?>/gm, '').substring(0,1000));
}
// Make the ajax call.
YAHOO.util.Connect.asyncRequest('GET', furl, this.ajax_callback, null);
},
this.PopupHandler.prototype.ajax_callback = {
success: function(e) {
document.getElementById('yui_act_sel_dialog').innerHTML = e.responseText;
activity_dialog = new YAHOO.widget.Dialog('yui_act_sel_dialog', {
x: e.argument[2],
y: e.argument[3],
modal: true,
width: e.argument[0] + 'px',
height: e.argument[1] + 'px',
iframe: false,
zIndex: 9999,
fixedcenter: false,
visible: false,
close: true,
constraintoviewport: false,
postmethod: 'async',
hideaftersubmit:true
});
activity_dialog.render();
activity_dialog.show();
YAHOO.util.Event.removeListener(activity_dialog.close, "click");
YAHOO.util.Event.addListener(activity_dialog.close, "click", closeDialogue);
if(doStatusCheck) {
setTimeout(checkStatus, 5000);
}
setTimeout(maintainSession, <?php echo ($CFG->sessiontimeout / 2) * 1000; ?>);
}
,
failure: function(e) {
alert("Browser error: Couldn't open modal dialogue");
},
argument: []
}
}).call(com.uol);
});