MDL-45427 mod_data: Inserting tags into templates.
[moodle.git] / mod / data / data.js
CommitLineData
9d0cffa5 1/**
2 * Javascript to insert the field tags into the textarea.
3 * Used when editing a data template
4 */
5function insert_field_tags(selectlist) {
b83f54f8
DC
6 var value = selectlist.options[selectlist.selectedIndex].value;
7 var editorname = 'template';
8 if (typeof tinyMCE == 'undefined') {
43c762ef
AG
9 if (document.execCommand('insertText')) {
10 document.execCommand('insertText', false, value);
11 } else {
12 var element = document.getElementsByName(editorname)[0];
13 // For inserting when in normal textareas
14 insertAtCursor(element, value);
15 }
b83f54f8
DC
16 } else {
17 tinyMCE.execInstanceCommand(editorname, 'mceInsertContent', false, value);
18 }
9d0cffa5 19}
20
21/**
22 * javascript for hiding/displaying advanced search form when viewing
23 */
24function showHideAdvSearch(checked) {
25 var divs = document.getElementsByTagName('div');
26 for(i=0;i<divs.length;i++) {
27 if(divs[i].id.match('data_adv_form')) {
28 if(checked) {
29 divs[i].style.display = 'inline';
30 }
31 else {
32 divs[i].style.display = 'none';
33 }
34 }
35 else if (divs[i].id.match('reg_search')) {
36 if (!checked) {
37 divs[i].style.display = 'inline';
38 }
39 else {
40 divs[i].style.display = 'none';
41 }
42 }
43 }
26032c2d
DC
44}
45
e4256380
DC
46M.data_urlpicker = {};
47
48M.data_urlpicker.init = function(Y, options) {
e4256380
DC
49 options.formcallback = M.data_urlpicker.callback;
50 if (!M.core_filepicker.instances[options.client_id]) {
9d8de346 51 M.core_filepicker.init(Y, options);
e4256380
DC
52 }
53 Y.on('click', function(e, client_id) {
54 e.preventDefault();
55 M.core_filepicker.instances[client_id].show();
56 }, '#filepicker-button-'+options.client_id, null, options.client_id);
57
58};
59
60M.data_urlpicker.callback = function (params) {
cd4a1897 61 document.getElementById('field_url_'+params.client_id).value = params.url;
9d8de346 62};