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';
11 // If firebug console is undefined, define a fake one here
13 console.vardump = function(data) {
16 retval += key+' = '+data[key] + "\n";
22 //onload object for handling scripts on page load, this insures they run in my order
23 function onload_class() {
24 this.scripts = new Array();
29 onload_class.prototype.add = function(script) {
31 YAHOO.log("onloadobj.add - adding "+script, "junk");
33 this.scripts[this.scripts.length] = script;
37 onload_class.prototype.load = function() {
38 var scriptcount = this.scripts.length;
40 YAHOO.log("onloadobj.load - loading "+scriptcount+" scripts", "info");
42 for (i=0; i<scriptcount; i++) {
43 eval(this.scripts[i]);
48 var onloadobj = new onload_class();
52 function main_class() {
54 this.portal = new php_portal_class();
56 this.blocks = new Array();
57 this.sections = new Array();
58 this.sectiondates = {};
59 this.leftcolumn = null;
60 this.rightcolumn = null;
61 this.adminBlock = null;
62 this.tempBlock = null;
65 this.courseformat = null;
66 this.numsections = null;
68 //things to process onload
69 onloadobj.add('main.process_document();');
70 onloadobj.add("document.getElementById('content').style.display='block';");
72 //connection queue allows xhttp requests to be sent in order
73 this.connectQueue = [];
74 this.connectQueueHead = 0;
75 this.connectQueueConnection = null;
79 main_class.prototype.process_blocks = function() {
80 //remove unneeded icons (old school position icons and delete/hide
81 //although they will be read)
82 var rmIconClasses = ['icon up', 'icon down', 'icon right', 'icon left', 'icon delete', 'icon hide'];
83 for (var c=0; c<rmIconClasses.length; c++) {
84 els = YAHOO.util.Dom.getElementsByClassName(rmIconClasses[c]);
86 for (var x=0; x<els.length; x++) {
87 els[x].parentNode.removeChild(els[x]);
90 //process the block ids passed from php
91 var blockcount = this.portal.blocks.length;
92 YAHOO.log("main.processBlocks - processing "+blockcount+" blocks", "info");
94 for (i=0; i<blockcount; i++) {
95 this.blocks[i] = new block_class(this.portal.blocks[i][1], "blocks");
97 //put in correct side array also
98 if (this.portal.blocks[i][0] == 'l') {
99 main.leftcolumn.add_block(this.blocks[i]);
100 } else if (this.portal.blocks[i][0] == 'r') {
101 main.rightcolumn.add_block(this.blocks[i]);
105 if (this.portal.blocks[i][2] == 1) {
106 this.blocks[i].toggle_hide(null, null, true);
112 main_class.prototype.process_document = function() {
113 //process the document to get important containers
114 YAHOO.log("Processing Document", "info");
116 //process columns for blocks
117 this.leftcolumn = new column_class('left-column', "blocks", null, 'l');
118 this.rightcolumn = new column_class('right-column', "blocks", null, 'r');
120 this.courseformat = this.portal.courseformat;
122 var tr_sections = YAHOO.util.Dom.getElementsByClassName('section main', 'tr');
123 for (var ct=0; ct<tr_sections.length; ct++) {
124 this.sections[ct] = new section_class(tr_sections[ct].id, "sections", null, ct!=0?true:false);
125 this.sections[ct].addToGroup('resources');
127 var sectiontitle = YAHOO.util.Selector.query('#section-'+ct+' h3.weekdates')[0];
128 if (undefined !== sectiontitle) { // Only save date for weekly format
129 this.sectiondates[ct] = sectiontitle.innerHTML;
134 YAHOO.log("Processed "+ct+" sections");
137 this.adminBlock = YAHOO.util.Dom.getElementsByClassName('block_adminblock')[0];
138 this.tempBlock = YAHOO.util.Dom.getElementsByClassName('tempblockhandler')[0];
140 YAHOO.log("admin - "+this.adminBlock.className);
144 main_class.prototype.mk_safe_for_transport = function(input) {
145 return input.replace(/&/i, '_.amp._');
150 main_class.prototype.get_block_index = function(el) {
151 var blockcount = this.blocks.length;
152 for (i=0; i<blockcount; i++) {
153 if (this.blocks[i] == el) {
160 main_class.prototype.get_section_index = function(el) {
161 var sectioncount = this.sections.length;
162 for (i=0; i<sectioncount; i++) {
163 if (this.sections[i] == el) {
169 main_class.prototype.mk_button = function(tag, imgSrc, text, attributes, imgAttributes) {
170 //Create button and return object.
171 //Set the text: the container TITLE or image ALT attributes can be overridden, eg.
172 // main.mk_button('a', '/i/move_2d.gif', strmove, [['title', strmoveshort]]);
173 var container = document.createElement(tag);
174 container.style.cursor = 'pointer';
175 container.setAttribute('title', text);
176 var image = document.createElement('img');
178 image.setAttribute('src', main.portal.strings['pixpath']+imgSrc);
179 image.setAttribute('alt', text);
180 //image.setAttribute('title', '');
181 container.appendChild(image);
183 if (attributes != null) {
184 for (var c=0; c<attributes.length; c++) {
185 if (attributes[c][0] == 'title' && this.is_ie()) {
186 image.setAttribute(attributes[c][0], attributes[c][1]); //IE hack: transfer 'title'.
188 container.setAttribute(attributes[c][0], attributes[c][1]);
192 if (imgAttributes != null) {
193 for (var c=0; c<imgAttributes.length; c++) {
194 image.setAttribute(imgAttributes[c][0], imgAttributes[c][1]);
197 image.setAttribute('hspace', '3');
202 main_class.prototype.connect = function(method, urlStub, callback, body) {
204 YAHOO.log("Making "+method+" connection to /course/rest.php?courseId="+main.portal.id+"&"+urlStub);
206 if (callback == null) {
209 success: function(response) {
210 YAHOO.log("Response from the Request: " + response.statusText + ": " + response.responseText, 'info');
212 failure: function() {
213 YAHOO.log("Response from the Request: " + response.statusText + ": " + response.responseText, 'error');
220 return YAHOO.util.Connect.asyncRequest(method, this.portal.strings['wwwroot']+"/course/rest.php?courseId="+main.portal.id+"&sesskey="+this.portal.strings['sesskey']+"&"+urlStub, callback, body);
224 main_class.prototype.connectQueue_add = function(method, urlStub, callback, body) {
225 var Qlength = main.connectQueue.length;
226 main.connectQueue[Qlength] = [];
227 main.connectQueue[Qlength]['method'] = method;
228 main.connectQueue[Qlength]['urlStub'] = urlStub;
229 main.connectQueue[Qlength]['body'] = body;
231 if (main.connectQueueConnection == null || !YAHOO.util.Connect.isCallInProgress(main.connectQueueConnection)) {
232 main.connectQueue_fireNext();
237 main_class.prototype.connectQueue_fireNext = function() {
238 var head = main.connectQueueHead;
239 if (head >= main.connectQueue.length) {
244 main.connectQueue_fireNext();
247 main.connectQueueConnection = main.connect(main.connectQueue[head]['method'],
248 main.connectQueue[head]['urlStub'],
250 main.connectQueue[head]['body']);
251 main.connectQueueHead++;
255 main_class.prototype.update_marker = function(newMarker) {
256 if (this.marker != null) {
257 this.marker.toggle_highlight();
259 this.marker = newMarker;
260 this.marker.toggle_highlight();
262 this.connect('post', 'class=course&field=marker', null, 'value='+this.marker.sectionId);
266 main_class.prototype.getString = function(identifier, variable) {
267 if (this.portal.strings[identifier]) {
268 return this.portal.strings[identifier].replace(/_var_/, variable);
272 main_class.prototype.is_ie = function() {
273 var agent = navigator.userAgent.toLowerCase();
274 if ((agent.indexOf('msie') != -1)) {
281 var main = new main_class();
284 function php_portal_class() {
289 //array of id's of blocks set at end of page load by php
290 this.blocks = new Array();
291 this.imagePath = null;
293 //flag for week fomat
299 YAHOO.log("Instantiated php_portal_class", "info");