2 * Contains Main class and supporting functions for ajax course layout
6 //hide content body until done loading (manipulation looks ugly elsewise)
7 //document.getElementById('content').style.display = 'none';
9 // If firebug console is undefined, define a fake one here
11 console.vardump = function(data) {
14 retval += key+' = '+data[key] + "\n";
20 //onload object for handling scripts on page load, this insures they run in my order
21 function onload_class() {
22 this.scripts = new Array();
27 onload_class.prototype.add = function(script) {
29 YAHOO.log("onloadobj.add - adding "+script, "junk");
31 this.scripts[this.scripts.length] = script;
35 onload_class.prototype.load = function() {
36 var scriptcount = this.scripts.length;
38 YAHOO.log("onloadobj.load - loading "+scriptcount+" scripts", "info");
40 for (i=0; i<scriptcount; i++) {
41 eval(this.scripts[i]);
46 var onloadobj = new onload_class();
50 function main_class() {
52 this.portal = new php_portal_class();
54 this.blocks = new Array();
55 this.sections = new Array();
56 this.sectiondates = {};
57 this.leftcolumn = null;
58 this.rightcolumn = null;
59 this.adminBlock = null;
60 this.tempBlock = null;
62 this.courseformat = null;
64 this.numsections = null;
65 this.lastsection = null; // real last section num including unavailable
67 //things to process onload
68 onloadobj.add('main.process_document();');
69 onloadobj.add("if (document.getElementById('content')) document.getElementById('content').style.display='block';");
71 //connection queue allows xhttp requests to be sent in order
72 this.connectQueue = [];
73 this.connectQueueHead = 0;
74 this.connectQueueConnection = null;
78 main_class.prototype.process_blocks = function() {
79 //remove unneeded icons (old school position icons and delete/hide
80 //although they will be read)
81 var rmIconClasses = ['icon up', 'icon down', 'icon right', 'icon left', 'icon delete', 'icon hide'];
82 for (var c=0; c<rmIconClasses.length; c++) {
83 els = YAHOO.util.Dom.getElementsByClassName(rmIconClasses[c]);
85 for (var x=0; x<els.length; x++) {
86 els[x].parentNode.removeChild(els[x]);
89 //process the block ids passed from php
90 var blockcount = this.portal.blocks.length;
91 YAHOO.log("main.processBlocks - processing "+blockcount+" blocks", "info");
93 for (i=0; i<blockcount; i++) {
94 this.blocks[i] = new block_class(this.portal.blocks[i][1], "blocks");
96 //put in correct side array also
97 if (this.portal.blocks[i][0] == 'l') {
98 main.leftcolumn.add_block(this.blocks[i]);
99 } else if (this.portal.blocks[i][0] == 'r') {
100 main.rightcolumn.add_block(this.blocks[i]);
104 if (this.portal.blocks[i][2] == 1) {
105 this.blocks[i].toggle_hide(null, null, true);
111 main_class.prototype.process_document = function() {
112 //process the document to get important containers
113 YAHOO.log("Processing Document", "info");
115 //process columns for blocks
116 this.leftcolumn = new column_class('left-column', "blocks", null, 'l');
117 this.rightcolumn = new column_class('right-column', "blocks", null, 'r');
121 //while (document.getElementById('section-'+ct) != null) {
122 this.courseformat = this.portal.courseformat;
123 for(var ct=0; ct <= this.portal.lastsection; ct++){
124 if (document.getElementById('section-'+ct) != null) {
125 var dragable = ((ct > 0) && (ct <= this.portal.numsections));
126 this.sections[ct] = new section_class('section-'+ct, "sections", null, dragable);
127 this.sections[ct].addToGroup('resources');
129 var sectiontitle = YAHOO.util.Selector.query('#section-'+ct+' h3.weekdates')[0];
130 if (undefined !== sectiontitle) { // Only save date for weekly format
131 this.sectiondates[ct] = sectiontitle.innerHTML;
135 this.sections[ct] = null;
140 YAHOO.log("Processed "+ct+" sections");
143 this.adminBlock = YAHOO.util.Dom.getElementsByClassName('block_adminblock')[0];
144 this.tempBlock = YAHOO.util.Dom.getElementsByClassName('tempblockhandler')[0];
148 main_class.prototype.mk_safe_for_transport = function(input) {
149 return input.replace(/&/i, '_.amp._');
154 main_class.prototype.get_block_index = function(el) {
155 var blockcount = this.blocks.length;
156 for (i=0; i<blockcount; i++) {
157 if (this.blocks[i] == el) {
164 main_class.prototype.get_section_index = function(el) {
165 var sectioncount = this.sections.length;
166 for (i=0; i<sectioncount; i++) {
167 if (this.sections[i] == el) {
174 main_class.prototype.mk_button = function(tag, imgSrc, text, attributes, imgAttributes) {
175 //Create button and return object.
176 //Set the text: the container TITLE or image ALT attributes can be overridden, eg.
177 // main.mk_button('a', main.portal.icons['move_2d'], strmove, [['title', strmoveshort]]);
178 var container = document.createElement(tag);
179 container.style.cursor = 'pointer';
180 container.setAttribute('title', text);
181 var image = document.createElement('img');
183 image.setAttribute('src', imgSrc);
184 image.setAttribute('alt', text);
185 //image.setAttribute('title', '');
186 container.appendChild(image);
188 if (attributes != null) {
189 for (var c=0; c<attributes.length; c++) {
190 if (attributes[c][0] == 'title' && this.is_ie()) {
191 image.setAttribute(attributes[c][0], attributes[c][1]); //IE hack: transfer 'title'.
193 container.setAttribute(attributes[c][0], attributes[c][1]);
197 if (imgAttributes != null) {
198 for (var c=0; c<imgAttributes.length; c++) {
199 image.setAttribute(imgAttributes[c][0], imgAttributes[c][1]);
202 image.setAttribute('hspace', '3');
207 main_class.prototype.connect = function(method, urlStub, callback, body) {
209 YAHOO.log("Making "+method+" connection to /course/rest.php?courseId="+main.portal.id+"&"+urlStub);
211 if (callback == null) {
214 success: function(response) {
215 YAHOO.log("Response from the Request: " + response.statusText + ": " + response.responseText, 'info');
217 failure: function() {
218 YAHOO.log("Response from the Request: " + response.statusText + ": " + response.responseText, 'error');
225 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);
229 main_class.prototype.connectQueue_add = function(method, urlStub, callback, body) {
230 var Qlength = main.connectQueue.length;
231 main.connectQueue[Qlength] = [];
232 main.connectQueue[Qlength]['method'] = method;
233 main.connectQueue[Qlength]['urlStub'] = urlStub;
234 main.connectQueue[Qlength]['body'] = body;
236 if (main.connectQueueConnection == null || !YAHOO.util.Connect.isCallInProgress(main.connectQueueConnection)) {
237 main.connectQueue_fireNext();
242 main_class.prototype.connectQueue_fireNext = function() {
243 var head = main.connectQueueHead;
244 if (head >= main.connectQueue.length) {
249 main.connectQueue_fireNext();
252 main.connectQueueConnection = main.connect(main.connectQueue[head]['method'],
253 main.connectQueue[head]['urlStub'],
255 main.connectQueue[head]['body']);
256 main.connectQueueHead++;
260 main_class.prototype.update_marker = function(newMarker) {
261 if (this.marker != null) {
262 this.marker.toggle_highlight();
264 this.marker = newMarker;
265 this.marker.toggle_highlight();
267 this.connect('post', 'class=course&field=marker', null, 'value='+this.marker.sectionId);
271 main_class.prototype.getString = function(identifier, variable) {
272 if (this.portal.strings[identifier]) {
273 return this.portal.strings[identifier].replace(/_var_/, variable);
277 main_class.prototype.hasString = function(identifier) {
278 if (this.portal.strings[identifier]) {
284 main_class.prototype.is_ie = function() {
285 var agent = navigator.userAgent.toLowerCase();
286 if ((agent.indexOf('msie') != -1)) {
293 var main = new main_class();
296 function php_portal_class() {
301 //array of id's of blocks set at end of page load by php
302 this.blocks = new Array();
303 this.imagePath = null;
305 //flag for week fomat
314 YAHOO.log("Instantiated php_portal_class", "info");