mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
Merged from 1.7
This commit is contained in:
parent
7f40a229a4
commit
e1c15ef7c9
@ -1,34 +1,42 @@
|
||||
/*
|
||||
* library for ajaxcourse formats, the classes and related functions for sections and resources
|
||||
* this library requires a 'main' object created in calling document
|
||||
/**
|
||||
* library for ajaxcourse formats, the classes and related functions for
|
||||
* sections and resources.
|
||||
*
|
||||
* This library requires a 'main' object created in calling document.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
function section_class(id,group,config,isDraggable) {
|
||||
this.init_section(id,group,config,isDraggable);
|
||||
/**
|
||||
* section_class
|
||||
*/
|
||||
function section_class(id, group, config, isDraggable) {
|
||||
this.init_section(id, group, config, isDraggable);
|
||||
}
|
||||
|
||||
YAHOO.extend(section_class, YAHOO.util.DDProxy);
|
||||
|
||||
|
||||
section_class.prototype.debug = true;
|
||||
|
||||
|
||||
section_class.prototype.init_section = function(id, group,config,isDraggable) {
|
||||
if (!id) { return; } // id would be the html id attribute.
|
||||
section_class.prototype.init_section = function(id, group, config, isDraggable) {
|
||||
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.is = 'section';
|
||||
this.sectionId = null; // Section number. This is NOT the section id from
|
||||
// the database.
|
||||
|
||||
if (!isDraggable) {
|
||||
this.initTarget(id,group,config);
|
||||
this.initTarget(id, group, config);
|
||||
this.removeFromGroup('sections');
|
||||
} else {
|
||||
this.init(id,group,config);
|
||||
this.handle = null;
|
||||
} else {
|
||||
this.init(id, group, config);
|
||||
this.handle = null;
|
||||
}
|
||||
|
||||
this.createFrame();
|
||||
@ -50,14 +58,15 @@ section_class.prototype.init_section = function(id, group,config,isDraggable) {
|
||||
this.showOnlyButton = null;
|
||||
this.init_buttons();
|
||||
|
||||
if (isDraggable)this.add_handle();
|
||||
|
||||
if (this.debug)YAHOO.log("init_section "+id+" draggable="+isDraggable);
|
||||
|
||||
|
||||
if (YAHOO.util.Dom.hasClass(this.getEl(),'hidden'))
|
||||
if (isDraggable) {
|
||||
this.add_handle();
|
||||
}
|
||||
if (this.debug) {
|
||||
YAHOO.log("init_section "+id+" draggable="+isDraggable);
|
||||
}
|
||||
if (YAHOO.util.Dom.hasClass(this.getEl(),'hidden')) {
|
||||
this.toggle_hide(null,null,true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
section_class.prototype.init_buttons = function() {
|
||||
@ -65,26 +74,25 @@ section_class.prototype.init_buttons = function() {
|
||||
|
||||
//clear all but show only button
|
||||
var commandContainerCount = commandContainer.childNodes.length;
|
||||
for (var i=(commandContainerCount-1);i>0;i--) {
|
||||
for (var i=(commandContainerCount-1); i>0; i--) {
|
||||
commandContainer.removeChild(commandContainer.childNodes[i])
|
||||
}
|
||||
|
||||
if (!this.isWeekFormat) {
|
||||
var highlightbutton = main.mk_button('div','/pix/i/marker.gif');
|
||||
YAHOO.util.Event.addListener(highlightbutton,'click',this.mk_marker,this,true);
|
||||
var highlightbutton = main.mk_button('div', '/pix/i/marker.gif');
|
||||
YAHOO.util.Event.addListener(highlightbutton, 'click', this.mk_marker, this, true);
|
||||
commandContainer.appendChild(highlightbutton);
|
||||
this.highlightButton = highlightbutton;
|
||||
}
|
||||
var viewbutton = main.mk_button('div','/pix/i/hide.gif');
|
||||
YAHOO.util.Event.addListener(viewbutton,'click',this.toggle_hide,this,true);
|
||||
var viewbutton = main.mk_button('div', '/pix/i/hide.gif');
|
||||
YAHOO.util.Event.addListener(viewbutton, 'click', this.toggle_hide, this,true);
|
||||
commandContainer.appendChild(viewbutton);
|
||||
this.viewButton = viewbutton;
|
||||
}
|
||||
|
||||
|
||||
section_class.prototype.add_handle = function() {
|
||||
var handleRef = main.mk_button('div','/pix/i/move_2d.gif',[['style','cursor:move']]);
|
||||
YAHOO.util.Dom.generateId(handleRef,'sectionHandle');
|
||||
var handleRef = main.mk_button('a', '/pix/i/move_2d.gif', [['style','cursor:move']]);
|
||||
YAHOO.util.Dom.generateId(handleRef, 'sectionHandle');
|
||||
|
||||
this.handle = handleRef;
|
||||
|
||||
@ -92,7 +100,6 @@ section_class.prototype.add_handle = function() {
|
||||
this.setHandleElId(this.handle.id);
|
||||
}
|
||||
|
||||
|
||||
section_class.prototype.process_section = function() {
|
||||
this.content_td = this.getEl().childNodes[1];
|
||||
|
||||
@ -119,22 +126,22 @@ section_class.prototype.process_section = function() {
|
||||
if (this.resources_ul == null) {
|
||||
this.resources_ul = document.createElement('ul');
|
||||
this.resources_ul.className='section';
|
||||
this.content_td.insertBefore(this.resources_ul, this.content_td.childNodes[2]);
|
||||
this.content_td.insertBefore(this.resources_ul, this.content_td.childNodes[1]);
|
||||
}
|
||||
|
||||
var resource_count = this.resources_ul.getElementsByTagName('li').length;
|
||||
|
||||
for (var i=0;i<resource_count;i++) {
|
||||
var resource = this.resources_ul.getElementsByTagName('li')[i];
|
||||
if (YAHOO.util.Dom.hasClass(resource,'resource')) {
|
||||
this.resources[this.resources.length] = new resource_class(resource.id,'resources',null,this);
|
||||
if (YAHOO.util.Dom.hasClass(resource, 'resource')) {
|
||||
this.resources[this.resources.length] = new resource_class(resource.id, 'resources', null, this);
|
||||
if (this.debug)YAHOO.log("Found resource");
|
||||
} else {
|
||||
this.resources[this.resources.length] = new activity_class(resource.id,'resources',null,this);
|
||||
this.resources[this.resources.length] = new activity_class(resource.id, 'resources', null, this);
|
||||
}
|
||||
}
|
||||
|
||||
this.summary = YAHOO.util.Dom.getElementsByClassName('summary',null,this.getEl())[0].firstChild.data || '';
|
||||
this.summary = YAHOO.util.Dom.getElementsByClassName('summary', null, this.getEl())[0].firstChild.data || '';
|
||||
}
|
||||
|
||||
section_class.prototype.startDrag = function(x, y) {
|
||||
@ -148,14 +155,14 @@ section_class.prototype.startDrag = function(x, y) {
|
||||
this.getDragEl().innerHTML = '';
|
||||
|
||||
var targets = YAHOO.util.DDM.getRelated(this, true);
|
||||
if (this.debug)YAHOO.log(this.sectionId + " startDrag "+targets.length + " targets");
|
||||
if (this.debug)YAHOO.log(this.id + " startDrag, "+targets.length + " targets");
|
||||
}
|
||||
|
||||
section_class.prototype.onDragDrop = function(e, id) {
|
||||
// get the drag and drop object that was targeted
|
||||
var target = YAHOO.util.DDM.getDDById(id);
|
||||
|
||||
if (this.debug)YAHOO.log("Section dropped on id="+id+" el = "+this.getEl().id+" x="+YAHOO.util.Dom.getXY(this.getDragEl()));
|
||||
if (this.debug)YAHOO.log("Section dropped on id="+id+" (I am "+this.getEl().id+") x="+YAHOO.util.Dom.getXY(this.getDragEl()));
|
||||
|
||||
this.move_to_section(target);
|
||||
|
||||
@ -220,7 +227,6 @@ section_class.prototype.move_to_section = function(target) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
section_class.prototype.swap_with_section = function(sectionIn) {
|
||||
var tmpStore = null;
|
||||
|
||||
@ -285,7 +291,6 @@ section_class.prototype.mk_marker = function() {
|
||||
|
||||
main.connect('post','class=course&field=marker',null,'value=0');
|
||||
this.toggle_highlight();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,15 +306,18 @@ section_class.prototype.changeId = function(newId) {
|
||||
}
|
||||
|
||||
section_class.prototype.get_resource_index = function(el) {
|
||||
for (var x=0;x<this.resources.length;x++)
|
||||
if (this.resources[x]==el)
|
||||
for (var x=0;x<this.resources.length;x++) {
|
||||
if (this.resources[x]==el) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
YAHOO.log("Could not find resource to remove "+el.getEl().id,"error");
|
||||
return -1;
|
||||
}
|
||||
|
||||
section_class.prototype.remove_resource = function(el) {
|
||||
var resourceCount = this.resources.length;
|
||||
|
||||
if (resourceCount == 1) {
|
||||
if (this.resources[0] == el)
|
||||
this.resources = new Array();
|
||||
@ -328,8 +336,6 @@ section_class.prototype.remove_resource = function(el) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//remove "text" nodes to keep DOM clean
|
||||
var childIndex = null;
|
||||
var childrenCount = this.resources_ul.childNodes.length;
|
||||
@ -342,8 +348,7 @@ section_class.prototype.remove_resource = function(el) {
|
||||
if (el.getEl().parentNode != null)
|
||||
el.getEl().parentNode.removeChild(el.getEl());
|
||||
|
||||
this.write_sequence_list();
|
||||
|
||||
this.write_sequence_list();
|
||||
}
|
||||
|
||||
section_class.prototype.insert_resource = function(el, targetel) {
|
||||
@ -410,37 +415,39 @@ section_class.prototype.insert_resource = function(el, targetel) {
|
||||
|
||||
section_class.prototype.write_sequence_list = function(toReturn) {
|
||||
var listOutput = '';
|
||||
|
||||
for (var i=0;i<this.resources.length;i++) {
|
||||
listOutput += this.resources[i].id;
|
||||
if (i != (this.resources.length-1))
|
||||
if (i != (this.resources.length-1)) {
|
||||
listOutput += ',';
|
||||
}
|
||||
}
|
||||
if (toReturn) {
|
||||
return listOutput;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Resource Class extends util.DDProxy
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* resource_class extends util.DDProxy
|
||||
*/
|
||||
function resource_class(id,group,config,parentObj) {
|
||||
|
||||
this.init_resource(id,group,config,parentObj);
|
||||
}
|
||||
|
||||
YAHOO.extend(resource_class, YAHOO.util.DDProxy);
|
||||
|
||||
|
||||
resource_class.prototype.debug = true;
|
||||
|
||||
|
||||
resource_class.prototype.init_resource = function(id,group,config,parentObj) {
|
||||
if (!id) {
|
||||
YAHOO.log("Init resource, NO ID FOUND!",'error');
|
||||
return;
|
||||
}
|
||||
|
||||
this.is = 'resource';
|
||||
this.init(id,group,config);
|
||||
this.createFrame();
|
||||
@ -449,8 +456,9 @@ resource_class.prototype.init_resource = function(id,group,config,parentObj) {
|
||||
this.id = this.getEl().id.replace(/module-/i,'');
|
||||
|
||||
this.hidden = false;
|
||||
if (YAHOO.util.Dom.hasClass(this.getEl().getElementsByTagName('a')[0],'dimmed'))
|
||||
if (YAHOO.util.Dom.hasClass(this.getEl().getElementsByTagName('a')[0],'dimmed')) {
|
||||
this.hidden = true;
|
||||
}
|
||||
this.hiddenStored = null;
|
||||
|
||||
this.linkContainer = this.getEl().getElementsByTagName('a')[0];
|
||||
@ -462,8 +470,9 @@ resource_class.prototype.init_resource = function(id,group,config,parentObj) {
|
||||
|
||||
this.parentObj = parentObj;
|
||||
|
||||
if (this.debug)YAHOO.log("init_resource "+id+" parent = "+parentObj.getEl().id);
|
||||
|
||||
if (this.debug) {
|
||||
YAHOO.log("init_resource "+id+" parent = "+parentObj.getEl().id);
|
||||
}
|
||||
}
|
||||
|
||||
resource_class.prototype.init_buttons = function() {
|
||||
@ -472,12 +481,12 @@ resource_class.prototype.init_buttons = function() {
|
||||
YAHOO.log('Cannot find command container for '+this.getEl().id,'error');
|
||||
return;
|
||||
}
|
||||
|
||||
this.commandContainer = commandContainer;
|
||||
|
||||
//find edit button
|
||||
var updateButton = null;
|
||||
var buttons = commandContainer.getElementsByTagName('a');
|
||||
|
||||
for (var x=0;x<buttons.length;x++) {
|
||||
if (buttons[x].title == main.portal.strings['update']) {
|
||||
updateButton = buttons[x];
|
||||
@ -489,17 +498,13 @@ resource_class.prototype.init_buttons = function() {
|
||||
|
||||
commandContainer.innerHTML = '';
|
||||
|
||||
|
||||
//add move-handle
|
||||
var handleRef = main.mk_button('a','/pix/i/move_2d.gif',[['style','cursor:move']],[['height','11'],['width','11'],['hspace','2'],['border','0']]);
|
||||
YAHOO.util.Dom.generateId(handleRef,'sectionHandle');
|
||||
this.handle = handleRef;
|
||||
|
||||
commandContainer.appendChild(handleRef);
|
||||
this.setHandleElId(this.handle.id);
|
||||
|
||||
|
||||
|
||||
//add edit button back in
|
||||
commandContainer.appendChild(updateButton);
|
||||
|
||||
@ -508,14 +513,14 @@ resource_class.prototype.init_buttons = function() {
|
||||
YAHOO.util.Event.addListener(button,'click',this.delete_button,this,true);
|
||||
commandContainer.appendChild(button);
|
||||
|
||||
if (this.hidden)
|
||||
var button = main.mk_button('a','/pix/t/show.gif');
|
||||
else
|
||||
var button = main.mk_button('a','/pix/t/hide.gif');
|
||||
if (this.hidden) {
|
||||
var button = main.mk_button('a','/pix/t/show.gif');
|
||||
} else {
|
||||
var button = main.mk_button('a','/pix/t/hide.gif');
|
||||
}
|
||||
YAHOO.util.Event.addListener(button,'click',this.toggle_hide,this,true);
|
||||
commandContainer.appendChild(button);
|
||||
this.viewButton = button;
|
||||
|
||||
}
|
||||
|
||||
resource_class.prototype.toggle_hide = function(target,e,superficial,force) {
|
||||
@ -544,12 +549,12 @@ resource_class.prototype.toggle_hide = function(target,e,superficial,force) {
|
||||
}
|
||||
|
||||
resource_class.prototype.delete_button = function() {
|
||||
if (this.debug)YAHOO.log("Deleting "+this.getEl().id+"from parent "+this.parentObj.getEl().id);
|
||||
|
||||
if (this.debug) {
|
||||
YAHOO.log("Deleting "+this.getEl().id+"from parent "+this.parentObj.getEl().id);
|
||||
}
|
||||
if (!confirm(main.getString('deletecheck',main.getString(this.is)+" "+this.id))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.getEl().parentNode.removeChild(this.getEl());
|
||||
this.parentObj.remove_resource(this);
|
||||
|
||||
@ -557,9 +562,10 @@ resource_class.prototype.delete_button = function() {
|
||||
}
|
||||
|
||||
resource_class.prototype.update_index = function(index) {
|
||||
if (this.debug)YAHOO.log("update Index for resource "+this.getEl().id+"to"+index);
|
||||
}
|
||||
|
||||
if (this.debug) {
|
||||
YAHOO.log("update Index for resource "+this.getEl().id+"to"+index);
|
||||
}
|
||||
}
|
||||
|
||||
resource_class.prototype.startDrag = function(x, y) {
|
||||
//operates in intersect mode
|
||||
@ -569,8 +575,9 @@ resource_class.prototype.startDrag = function(x, y) {
|
||||
this.getDragEl().innerHTML = '';
|
||||
|
||||
var targets = YAHOO.util.DDM.getRelated(this, true);
|
||||
if (this.debug)YAHOO.log(this.id + " startDrag "+targets.length + " targets");
|
||||
|
||||
if (this.debug) {
|
||||
YAHOO.log(this.id + " startDrag "+targets.length + " targets");
|
||||
}
|
||||
}
|
||||
|
||||
resource_class.prototype.onDragDrop = function(e, ids) {
|
||||
@ -611,15 +618,17 @@ resource_class.prototype.endDrag = function() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* activity Class extends resource class
|
||||
*/
|
||||
|
||||
/**
|
||||
* activity_class extends resource class
|
||||
*/
|
||||
function activity_class(id,group,config,parentObj) {
|
||||
this.init_activity(id,group,config,parentObj);
|
||||
}
|
||||
|
||||
YAHOO.extend(activity_class, resource_class);
|
||||
|
||||
|
||||
activity_class.prototype.init_activity = function(id,group,config,parentObj) {
|
||||
if (!id) {
|
||||
YAHOO.log("Init activity, NO ID FOUND!",'error');
|
||||
@ -634,8 +643,9 @@ activity_class.prototype.init_activity = function(id,group,config,parentObj) {
|
||||
this.groupButton= null;
|
||||
this.init_activity_button();
|
||||
|
||||
if (this.debug)YAHOO.log("--init_activity "+id);
|
||||
|
||||
if (this.debug) {
|
||||
YAHOO.log("--init_activity "+id);
|
||||
}
|
||||
}
|
||||
|
||||
activity_class.prototype.groupImages = ['/pix/t/groupn.gif','/pix/t/groups.gif','/pix/t/groupv.gif'];
|
||||
@ -660,15 +670,14 @@ activity_class.prototype.get_current_group = function(id) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
activity_class.prototype.toggle_group = function() {
|
||||
this.currentGroup++;
|
||||
if (this.currentGroup > 2)
|
||||
if (this.currentGroup > 2) {
|
||||
this.currentGroup = 0;
|
||||
|
||||
}
|
||||
this.groupButton.getElementsByTagName('img')[0].src = main.portal.wwwroot + this.groupImages[this.currentGroup];
|
||||
|
||||
main.connect('post','class=resource&field=groupmode',null,'value='+this.currentGroup+'&id='+this.id);
|
||||
|
Loading…
x
Reference in New Issue
Block a user