MDL-20523 Script for upgrading sites that use the old bloglevel settings.
[moodle.git] / blog / edit_form.js
CommitLineData
cae83708 1// This file is part of Moodle - http://moodle.org/
2//
3// Moodle is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// Moodle is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
15
16//add function to clear the list of context associations
17function emptyAssocList() {
18 var modassoc = document.getElementById('id_modassoc');
19 var options = modassoc.getElementsByTagName('option');
20 while (options.length > 0) {
21 var option = options[0];
22 modassoc.removeChild(option);
23 }
24}
25
26//add function for adding an element to the list of context associations
27function addModAssoc(name, id) {
28 var modassoc = document.getElementById('id_modassoc');
29 newoption = document.createElement('option');
30 newoption.text = name;
31 newoption.value = id;
32
33 try {
34 modassoc.add(newoption, null); //standard, broken in IE
35 } catch(ex) {
36 modassoc.add(newoption);
37 }
38}
39
40//add function to add associations for a particular course
41function addCourseAssociations() {
42 var courses = document.getElementById('id_courseassoc');
43 var course = courses.options[courses.selectedIndex].value;
44 var modassoc = document.getElementById('id_modassoc');
45 var newoption = null;
46
47 emptyAssocList();
48
49 for (var mycourse in blog_edit_form_modnames) {
50 if (mycourse == course) {
51 for (var modid in blog_edit_form_modnames[mycourse]) {
52 addModAssoc(blog_edit_form_modnames[mycourse][modid], modid);
53 }
54 }
55 }
56}
57
58function select_initial_course() {
59 var course = document.getElementById('id_courseassoc');
60 var mods = document.getElementById('id_modassoc');
61 var i = 0;
62 var j = 0;
63 emptyAssocList();
64
65 for (i = 0; i < course.length; i++) {
66 if (course.options[i].value == blog_edit_existing.courseassoc) {
67 course.selectedIndex = i;
68 addCourseAssociations();
69
70 for (j = 0; j < mods.length; j++) {
71 for (var modid in blog_edit_existing.modassoc) {
72 if (mods.options[j].value == blog_edit_existing.modassoc[modid]) {
73 mods.options[j].selected = true;
74 }
75 }
76 }
77 }
78 }
79}
80