2 * Contains Main class and supporting functions for ajax course layout
8 //hide content body until done loading (manipulation looks ugly elsewise)
9 //document.getElementById('content').style.display = 'none';
12 //onload object for handling scripts on page load, this insures they run in my order
13 function onload_class() {
14 this.scripts = new Array();
19 onload_class.prototype.add = function(script) {
21 YAHOO.log("onloadobj.add - adding "+script, "junk");
23 this.scripts[this.scripts.length] = script;
27 onload_class.prototype.load = function() {
28 var scriptcount = this.scripts.length;
30 YAHOO.log("onloadobj.load - loading "+scriptcount+" scripts", "info");
32 for (i=0; i<scriptcount; i++) {
33 eval(this.scripts[i]);
38 var onloadobj = new onload_class();
42 function main_class() {
44 this.portal = new php_portal_class();
46 this.blocks = new Array();
47 this.sections = new Array();
48 this.leftcolumn = null;
49 this.rightcolumn = null;
50 this.adminBlock = null;
54 //things to process onload
55 onloadobj.add('main.process_document();');
56 onloadobj.add("document.getElementById('content').style.display='block';");
58 //connection queue allows xhttp requests to be sent in order
59 this.connectQueue = [];
60 this.connectQueueHead = 0;
61 this.connectQueueConnection = null;
65 main_class.prototype.process_blocks = function() {
66 //remove unneeded icons (old school position icons and delete/hide
67 //although they will be read)
68 var rmIconClasses = ['icon up', 'icon down', 'icon right', 'icon left', 'icon delete', 'icon hide'];
69 for (var c=0; c<rmIconClasses.length; c++) {
70 els = YAHOO.util.Dom.getElementsByClassName(rmIconClasses[c]);
72 for (var x=0; x<els.length; x++) {
73 els[x].parentNode.removeChild(els[x]);
76 //process the block ids passed from php
77 var blockcount = this.portal.blocks.length;
78 YAHOO.log("main.processBlocks - processing "+blockcount+" blocks", "info");
80 for (i=0; i<blockcount; i++) {
81 this.blocks[i] = new block_class(this.portal.blocks[i][1], "blocks");
83 //put in correct side array also
84 if (this.portal.blocks[i][0] == 'l') {
85 main.leftcolumn.add_block(this.blocks[i]);
86 } else if (this.portal.blocks[i][0] == 'r') {
87 main.rightcolumn.add_block(this.blocks[i]);
91 if (this.portal.blocks[i][2] == 1) {
92 this.blocks[i].toggle_hide(null, null, true);
98 main_class.prototype.process_document = function() {
99 //process the document to get important containers
100 YAHOO.log("Processing Document", "info");
102 //process columns for blocks
103 this.leftcolumn = new column_class('left-column', "blocks", null, 'l');
104 this.rightcolumn = new column_class('right-column', "blocks", null, 'r');
108 while (document.getElementById('section-'+ct) != null) {
109 this.sections[ct] = new section_class('section-'+ct, "sections", null, ct!=0?true:false);
110 this.sections[ct].addToGroup('resources');
114 YAHOO.log("Processed "+ct+" sections");
117 this.adminBlock = YAHOO.util.Dom.getElementsByClassName('block_adminblock')[0];
118 YAHOO.log("admin - "+this.adminBlock.className);
122 main_class.prototype.mk_safe_for_transport = function(input) {
123 return input.replace(/&/i, '_.amp._');
128 main_class.prototype.get_block_index = function(el) {
129 var blockcount = this.blocks.length;
130 for (i=0; i<blockcount; i++) {
131 if (this.blocks[i] == el) {
138 main_class.prototype.get_section_index = function(el) {
139 var sectioncount = this.sections.length;
140 for (i=0; i<sectioncount; i++) {
141 if (this.sections[i] == el) {
148 main_class.prototype.mk_button = function(tag, imgSrc, attributes, imgAttributes) {
149 //create button and return object
150 var container = document.createElement(tag);
151 container.style.cursor = 'pointer';
152 var image = document.createElement('img');
154 image.setAttribute('src', main.portal.strings['pixpath']+imgSrc);
155 container.appendChild(image);
157 if (attributes != null) {
158 for (var c=0; c<attributes.length; c++) {
159 container.setAttribute(attributes[c][0], attributes[c][1]);
162 if (imgAttributes != null) {
163 for (var c=0; c<attributes.length; c++) {
164 image.setAttribute(imgAttributes[c][0], imgAttributes[c][1]);
167 image.setAttribute('hspace', '3');
172 main_class.prototype.connect = function(method, urlStub, callback, body) {
174 YAHOO.log("Making "+method+" connection to /course/rest.php?courseId="+main.portal.id+"&"+urlStub);
176 if (callback == null) {
179 return YAHOO.util.Connect.asyncRequest(method, this.portal.strings['wwwroot']+"/course/rest.php?courseId="+main.portal.id+"&"+urlStub, callback, body);
183 main_class.prototype.connectQueue_add = function(method, urlStub, callback, body) {
184 var Qlength = main.connectQueue.length;
185 main.connectQueue[Qlength] = [];
186 main.connectQueue[Qlength]['method'] = method;
187 main.connectQueue[Qlength]['urlStub'] = urlStub;
188 main.connectQueue[Qlength]['body'] = body;
190 if (main.connectQueueConnection == null || !YAHOO.util.Connect.isCallInProgress(main.connectQueueConnection)) {
191 main.connectQueue_fireNext();
196 main_class.prototype.connectQueue_fireNext = function() {
197 var head = main.connectQueueHead;
198 if (head >= main.connectQueue.length) {
203 main.connectQueue_fireNext();
206 main.connectQueueConnection = main.connect(main.connectQueue[head]['method'],
207 main.connectQueue[head]['urlStub'],
209 main.connectQueue[head]['body']);
210 main.connectQueueHead++;
214 main_class.prototype.update_marker = function(newMarker) {
215 if (this.marker != null) {
216 this.marker.toggle_highlight();
218 this.marker = newMarker;
219 this.marker.toggle_highlight();
221 this.connect('post', 'class=course&field=marker', null, 'value='+this.marker.sectionId);
225 main_class.prototype.getString = function(title, variable) {
226 if (this.portal.strings[title]) {
227 return this.portal.strings[title].replace(/_var_/, variable);
232 var main = new main_class();
235 function php_portal_class() {
240 //array of id's of blocks set at end of page load by php
241 this.blocks = new Array();
242 this.imagePath = null;
244 //flag for week fomat
250 YAHOO.log("Instantiated php_portal_class", "info");