MDL-15680 Began implementing a simple YUI treeview of the grade items in their categories. Will tweak this to become a form with weights in input fields, and possible drag and drop also
60
grade/edit/weights/ajax.php
Executable file
@ -0,0 +1,60 @@
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
|
||||
// If the mouse is clicked outside this element, the edit is CANCELLED (even if the mouse clicks another grade/feedback cell)
|
||||
// If ctrl-arrow is used, or if [tab] or [enter] are pressed, the edit is RECORDED and the row is updated. The previous element returns to normal
|
||||
|
||||
YAHOO.namespace("grade_edit_weights");
|
||||
YAHOO.grade_edit_weights.courseid = <?php echo $COURSE->id; ?>;
|
||||
YAHOO.grade_edit_weights.wwwroot = '<?php echo $CFG->wwwroot; ?>';
|
||||
YAHOO.grade_edit_weights.tree = null;
|
||||
YAHOO.grade_edit_weights.treedata = <?php echo $tree_json; ?>;
|
||||
|
||||
YAHOO.grade_edit_weights.buildTreeNode = function(element, parentNode) {
|
||||
var gew = YAHOO.grade_edit_weights;
|
||||
|
||||
if (parentNode === undefined) {
|
||||
parentNode = gew.tree.getRoot();
|
||||
}
|
||||
|
||||
if (element === undefined) {
|
||||
element = gew.treedata;
|
||||
}
|
||||
|
||||
if (element.item.table == 'grade_categories') {
|
||||
var tmpNode = new YAHOO.widget.TextNode(element.item.name, parentNode, parentNode.isRoot());
|
||||
for (var i = 0; i < element.children.length; i++) {
|
||||
gew.buildTreeNode(element.children[i], tmpNode, false);
|
||||
}
|
||||
} else if (element.item.itemtype == 'mod') {
|
||||
var tmpNode = new YAHOO.widget.TextNode(element.item.name, parentNode, false);
|
||||
}
|
||||
};
|
||||
|
||||
YAHOO.grade_edit_weights.init = function() {
|
||||
var gew = YAHOO.grade_edit_weights;
|
||||
var div = document.getElementById('weightstree');
|
||||
gew.tree = new YAHOO.widget.TreeView('weightstree');
|
||||
|
||||
//handler for expanding all nodes
|
||||
YAHOO.util.Event.on("expand", "click", function(e) {
|
||||
YAHOO.log("Expanding all TreeView nodes.", "info", "example");
|
||||
gew.tree.expandAll();
|
||||
YAHOO.util.Event.preventDefault(e);
|
||||
});
|
||||
|
||||
//handler for collapsing all nodes
|
||||
YAHOO.util.Event.on("collapse", "click", function(e) {
|
||||
YAHOO.log("Collapsing all TreeView nodes.", "info", "example");
|
||||
gew.tree.collapseAll();
|
||||
YAHOO.util.Event.preventDefault(e);
|
||||
});
|
||||
|
||||
gew.buildTreeNode();
|
||||
gew.tree.draw();
|
||||
};
|
||||
|
||||
YAHOO.util.Event.onDOMReady(YAHOO.grade_edit_weights.init);
|
||||
|
||||
// ]]>
|
||||
</script>
|
BIN
grade/edit/weights/img/lm.gif
Normal file
After Width: | Height: | Size: 666 B |
BIN
grade/edit/weights/img/lmh.gif
Normal file
After Width: | Height: | Size: 677 B |
BIN
grade/edit/weights/img/ln.gif
Normal file
After Width: | Height: | Size: 142 B |
BIN
grade/edit/weights/img/loading.gif
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
grade/edit/weights/img/lp.gif
Normal file
After Width: | Height: | Size: 641 B |
BIN
grade/edit/weights/img/lph.gif
Normal file
After Width: | Height: | Size: 651 B |
BIN
grade/edit/weights/img/tm.gif
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
grade/edit/weights/img/tmh.gif
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
grade/edit/weights/img/tn.gif
Normal file
After Width: | Height: | Size: 504 B |
BIN
grade/edit/weights/img/tp.gif
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
grade/edit/weights/img/tph.gif
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
grade/edit/weights/img/vline.gif
Normal file
After Width: | Height: | Size: 503 B |
120
grade/edit/weights/index.php
Executable file
@ -0,0 +1,120 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
require_once '../../../config.php';
|
||||
require_once $CFG->dirroot.'/grade/lib.php';
|
||||
require_once $CFG->dirroot.'/grade/report/lib.php'; // for preferences
|
||||
|
||||
$courseid = required_param('id', PARAM_INT);
|
||||
$action = optional_param('action', 0, PARAM_ALPHA);
|
||||
$eid = optional_param('eid', 0, PARAM_ALPHANUM);
|
||||
|
||||
require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_json', 'yui_connection', 'yui_dragdrop', 'yui_treeview'));
|
||||
|
||||
/// Make sure they can even access this course
|
||||
|
||||
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
|
||||
print_error('nocourseid');
|
||||
}
|
||||
|
||||
require_login($course);
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
require_capability('moodle/grade:manage', $context);
|
||||
|
||||
/// return tracking object
|
||||
$gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'weight', 'courseid'=>$courseid));
|
||||
$returnurl = $gpr->get_return_url(null);
|
||||
|
||||
//first make sure we have proper final grades - we need it for locking changes
|
||||
grade_regrade_final_grades($courseid);
|
||||
|
||||
// get the grading tree object
|
||||
// note: total must be first for moving to work correctly, if you want it last moving code must be rewritten!
|
||||
$gtree = new grade_tree($courseid, false, false);
|
||||
|
||||
$switch = grade_get_setting($course->id, 'aggregationposition', $CFG->grade_aggregationposition);
|
||||
|
||||
$strgrades = get_string('grades');
|
||||
$strgraderreport = get_string('graderreport', 'grades');
|
||||
$strcategoriesedit = get_string('categoriesedit', 'grades');
|
||||
$strcategoriesanditems = get_string('categoriesanditems', 'grades');
|
||||
|
||||
$navigation = grade_build_nav(__FILE__, $strcategoriesanditems, array('courseid' => $courseid));
|
||||
$moving = false;
|
||||
|
||||
switch ($action) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$CFG->stylesheets[] = $CFG->wwwroot.'/grade/edit/weights/tree.css';
|
||||
print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course));
|
||||
|
||||
/// Print the plugin selector at the top
|
||||
print_grade_plugin_selector($courseid, 'edit', 'tree');
|
||||
|
||||
print_heading(get_string('categoriesedit', 'grades'));
|
||||
$tree_json = json_encode(get_tree_json($gtree, $gtree->top_element));
|
||||
|
||||
require_once('ajax.php');
|
||||
|
||||
print_box_start('gradetreebox generalbox');
|
||||
|
||||
echo '<div id="expandcontractdiv">
|
||||
<a id="expand" href="#">Expand all</a>
|
||||
<a id="collapse" href="#">Collapse all</a>
|
||||
</div> ';
|
||||
|
||||
echo '<form method="post" action="'.$returnurl.'">';
|
||||
echo '<div id="weightstree">';
|
||||
|
||||
// print_grade_tree($gtree, $gtree->top_element, $gpr, $switch);
|
||||
//
|
||||
echo '</div>';
|
||||
echo '</form>';
|
||||
print_box_end();
|
||||
|
||||
print_footer($course);
|
||||
die;
|
||||
|
||||
function get_tree_json(&$gtree, $element) {
|
||||
|
||||
$return_array = array();
|
||||
|
||||
$object = $element['object'];
|
||||
$eid = $element['eid'];
|
||||
$object->name = $gtree->get_element_header($element, false, false, false);
|
||||
|
||||
$return_array['item'] = $object;
|
||||
|
||||
if ($element['type'] == 'category') {
|
||||
foreach($element['children'] as $child_el) {
|
||||
$return_array['children'][] = get_tree_json($gtree, $child_el);
|
||||
}
|
||||
}
|
||||
|
||||
return $return_array;
|
||||
}
|
||||
?>
|
136
grade/edit/weights/tree.css
Normal file
@ -0,0 +1,136 @@
|
||||
/* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
|
||||
|
||||
/* first or middle sibling, no children */
|
||||
.ygtvtn {
|
||||
background: url(img/tn.gif) 0 0 no-repeat;
|
||||
width:17px;
|
||||
height:22px;
|
||||
}
|
||||
|
||||
/* first or middle sibling, collapsable */
|
||||
.ygtvtm {
|
||||
background: url(img/tm.gif) 0 0 no-repeat;
|
||||
width:34px;
|
||||
height:22px; cursor:pointer
|
||||
}
|
||||
|
||||
/* first or middle sibling, collapsable, hover */
|
||||
.ygtvtmh {
|
||||
background: url(img/tmh.gif) 0 0 no-repeat;
|
||||
width:34px;
|
||||
height:22px;
|
||||
cursor:pointer
|
||||
}
|
||||
|
||||
/* first or middle sibling, expandable */
|
||||
.ygtvtp {
|
||||
background: url(img/tp.gif) 0 0 no-repeat;
|
||||
width:34px;
|
||||
height:22px;
|
||||
cursor:pointer
|
||||
}
|
||||
|
||||
/* first or middle sibling, expandable, hover */
|
||||
.ygtvtph {
|
||||
background: url(img/tph.gif) 0 0 no-repeat;
|
||||
width:34px;
|
||||
height:22px;
|
||||
cursor:pointer
|
||||
}
|
||||
|
||||
/* last sibling, no children */
|
||||
.ygtvln {
|
||||
background: url(img/ln.gif) 0 0 no-repeat;
|
||||
width:17px;
|
||||
height:22px;
|
||||
}
|
||||
|
||||
/* Last sibling, collapsable */
|
||||
.ygtvlm {
|
||||
background: url(img/lm.gif) 0 0 no-repeat;
|
||||
|
||||
width:34px;
|
||||
height:22px;
|
||||
cursor:pointer
|
||||
}
|
||||
|
||||
/* Last sibling, collapsable, hover */
|
||||
.ygtvlmh {
|
||||
background: url(img/lmh.gif) 0 0 no-repeat;
|
||||
width:34px;
|
||||
height:22px;
|
||||
cursor:pointer
|
||||
}
|
||||
|
||||
/* Last sibling, expandable */
|
||||
.ygtvlp {
|
||||
background: url(img/lp.gif) 0 0 no-repeat;
|
||||
width:34px;
|
||||
height:22px;
|
||||
cursor:pointer
|
||||
}
|
||||
|
||||
/* Last sibling, expandable, hover */
|
||||
.ygtvlph {
|
||||
background: url(img/lph.gif) 0 0 no-repeat;
|
||||
width:34px;
|
||||
height:22px;
|
||||
cursor:pointer
|
||||
}
|
||||
|
||||
/* Loading icon */
|
||||
.ygtvloading {
|
||||
background: url(img/loading.gif) 0 0 no-repeat;
|
||||
width:16px;
|
||||
height:22px;
|
||||
}
|
||||
|
||||
/* the style for the empty cells that are used for rendering the depth
|
||||
* of the node */
|
||||
.ygtvdepthcell {
|
||||
background: url(img/vline.gif) 0 0 no-repeat;
|
||||
width:17px;
|
||||
height:22px;
|
||||
}
|
||||
|
||||
.ygtvblankdepthcell {
|
||||
width:17px;
|
||||
height:22px;
|
||||
}
|
||||
|
||||
/* the style of the div around each node */
|
||||
.ygtvitem { }
|
||||
|
||||
.ygtvitem table{
|
||||
margin-bottom:0;
|
||||
}
|
||||
.ygtvitem td {
|
||||
border:none;padding:0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* the style of the div around each node's collection of children */
|
||||
.ygtvchildren { }
|
||||
* html .ygtvchildren {
|
||||
height:1%;
|
||||
}
|
||||
|
||||
/* the style of the text label in ygTextNode */
|
||||
.ygtvlabel, .ygtvlabel:link, .ygtvlabel:visited, .ygtvlabel:hover {
|
||||
margin-left:2px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#expandcontractdiv {
|
||||
border:1px dotted #dedede;
|
||||
background-color:#EBE4F2;
|
||||
margin:0 0 .5em 0;
|
||||
padding:0.4em;
|
||||
}
|
||||
|
||||
#weightstree {
|
||||
background: #fff;
|
||||
padding:1em;
|
||||
margin-top:1em;
|
||||
}
|
@ -79,15 +79,15 @@ class graded_users_iterator {
|
||||
return false;
|
||||
}
|
||||
|
||||
list($gradebookroles_sql, $params) = $DB->get_in_or_equal(explode(',', $CFG->gradebookroles));
|
||||
list($gradebookroles_sql, $params) = $DB->get_in_or_equal(explode(',', $CFG->gradebookroles), SQL_PARAMS_NAMED, 'grbr0');
|
||||
|
||||
$relatedcontexts = get_related_contexts_string(get_context_instance(CONTEXT_COURSE, $this->course->id));
|
||||
|
||||
if ($this->groupid) {
|
||||
$groupsql = "INNER JOIN {groups_members} gm ON gm.userid = u.id";
|
||||
$groupwheresql = "AND gm.groupid = ?";
|
||||
$groupwheresql = "AND gm.groupid = :groupid";
|
||||
// $params contents: gradebookroles
|
||||
$params[] = $this->groupid;
|
||||
$params['groupid'] = $this->groupid;
|
||||
} else {
|
||||
$groupsql = "";
|
||||
$groupwheresql = "";
|
||||
@ -126,7 +126,7 @@ class graded_users_iterator {
|
||||
|
||||
if (!empty($this->grade_items)) {
|
||||
$itemids = array_keys($this->grade_items);
|
||||
list($itemidsql, $grades_params) = $DB->get_in_or_equal($itemids);
|
||||
list($itemidsql, $grades_params) = $DB->get_in_or_equal($itemids, SQL_PARAMS_NAMED, 'items0');
|
||||
$params = array_merge($params, $grades_params);
|
||||
|
||||
// $params contents: gradebookroles, groupid (for $groupwheresql) and itemids
|
||||
@ -453,6 +453,14 @@ function print_grade_plugin_selector($courseid, $active_type, $active_plugin, $r
|
||||
$count++;
|
||||
}
|
||||
|
||||
if (has_capability('moodle/grade:manage', $context)) {
|
||||
$url = 'edit/weights/index.php?id='.$courseid;
|
||||
if ($active_type == 'edit' and $active_plugin == 'weights' ) {
|
||||
$active = $url;
|
||||
}
|
||||
$menu[$url] = get_string('weights', 'grades');
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
/// finally print/return the popup form
|
||||
|