From a84ce52ecf2bd4d0868345c3c9cf8063e0d857b6 Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Mon, 13 Oct 2008 14:38:36 +0000 Subject: [PATCH] MDL-15680 Redesigned the weights interface using table layout. It will eventually replace the current "Edit categories and items" page --- grade/edit/weights/index.php | 40 ++++++--- grade/edit/weights/lib.php | 157 +++++++++++++++++++++++--------- grade/edit/weights/tree.css | 170 +++-------------------------------- lang/en_utf8/grades.php | 1 + 4 files changed, 152 insertions(+), 216 deletions(-) diff --git a/grade/edit/weights/index.php b/grade/edit/weights/index.php index d7428b5c9b..afa8dcb139 100755 --- a/grade/edit/weights/index.php +++ b/grade/edit/weights/index.php @@ -28,14 +28,14 @@ require_once $CFG->dirroot.'/grade/lib.php'; require_once $CFG->dirroot.'/grade/report/lib.php'; // for preferences require_once $CFG->dirroot.'/grade/edit/weights/lib.php'; +require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_json', 'yui_connection', 'yui_dragdrop', 'yui_treeview')); + $courseid = required_param('id', PARAM_INT); $action = optional_param('action', 0, PARAM_ALPHA); $eid = optional_param('eid', 0, PARAM_ALPHANUM); $category = optional_param('category', null, PARAM_INT); $aggregationtype = optional_param('aggregationtype', null, PARAM_INT); -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))) { @@ -84,12 +84,10 @@ print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriese print_grade_plugin_selector($courseid, 'edit', 'tree'); print_heading(get_string('weightsedit', 'grades')); -$tree_json = json_encode(get_tree_json($gtree, $gtree->top_element)); $form_key = optional_param('sesskey', null, PARAM_ALPHANUM); -if ($form_key) { - $data = data_submitted(); +if ($form_key && $data = data_submitted()) { foreach ($data as $key => $value) { if (preg_match('/aggregation_type_([0-9]*)/', $key, $matches)) { @@ -147,25 +145,39 @@ if ($form_key) { } } -// AJAX interface not really needed: adds nice tree functions but not very useful -// require_once('ajax.php'); - -print_box_start('gradetreebox generalbox'); - // echo '
Expand all Collapse all
'; +echo ''; echo '
'; -echo ''; echo '
'; -echo build_html_tree(get_tree_json($gtree, $gtree->top_element), null, $returnurl); +echo ''; +echo build_html_tree(get_tree_json($gtree, $gtree->top_element, 0, $gpr), null, $returnurl); // print_grade_tree($gtree, $gtree->top_element, $gpr, $switch); // echo '
'; echo ''; -echo '
'; -print_box_end(); +echo ' + + +'; print_footer($course); die; diff --git a/grade/edit/weights/lib.php b/grade/edit/weights/lib.php index ef53634fa6..96149b0e0e 100644 --- a/grade/edit/weights/lib.php +++ b/grade/edit/weights/lib.php @@ -23,7 +23,8 @@ // // /////////////////////////////////////////////////////////////////////////// -function get_tree_json(&$gtree, $element, $totals=false) { +function get_tree_json(&$gtree, $element, $totals=false, $gpr) { + global $CFG, $COURSE; $return_array = array(); @@ -33,36 +34,67 @@ function get_tree_json(&$gtree, $element, $totals=false) { $return_array['item'] = $object; + $return_array['item']->actions = $gtree->get_edit_icon($element, $gpr); + $return_array['item']->actions .= $gtree->get_calculation_icon($element, $gpr); + + if ($element['type'] == 'item' or ($element['type'] == 'category' and $element['depth'] > 1)) { + if (element_deletable($element)) { + $return_array['item']->actions .= ''
+                     . get_string('delete').''; + } + $return_array['item']->actions .= ''
+                 . get_string('move').''; + } + + $return_array['item']->actions .= $gtree->get_hiding_icon($element, $gpr); + $return_array['item']->actions .= $gtree->get_locking_icon($element, $gpr); + if ($element['type'] == 'category') { foreach($element['children'] as $child_el) { if (!empty($child_el['object']->itemtype) && ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') && !$totals) { continue; } - $return_array['children'][] = get_tree_json($gtree, $child_el); + $return_array['children'][] = get_tree_json($gtree, $child_el, $totals, $gpr); } } return $return_array; } -function build_html_tree($tree, $element=null) { +function build_html_tree($tree, $element=null, $level=0) { global $CFG; - $options = array(GRADE_AGGREGATE_MEAN =>get_string('aggregatemean', 'grades'), - GRADE_AGGREGATE_WEIGHTED_MEAN =>get_string('aggregateweightedmean', 'grades'), - GRADE_AGGREGATE_WEIGHTED_MEAN2 =>get_string('aggregateweightedmean2', 'grades'), - GRADE_AGGREGATE_EXTRACREDIT_MEAN=>get_string('aggregateextracreditmean', 'grades'), - GRADE_AGGREGATE_MEDIAN =>get_string('aggregatemedian', 'grades'), - GRADE_AGGREGATE_MIN =>get_string('aggregatemin', 'grades'), - GRADE_AGGREGATE_MAX =>get_string('aggregatemax', 'grades'), - GRADE_AGGREGATE_MODE =>get_string('aggregatemode', 'grades'), - GRADE_AGGREGATE_SUM =>get_string('aggregatesum', 'grades')); + $options = array(GRADE_AGGREGATE_MEAN => get_string('aggregatemean', 'grades'), + GRADE_AGGREGATE_WEIGHTED_MEAN => get_string('aggregateweightedmean', 'grades'), + GRADE_AGGREGATE_WEIGHTED_MEAN2 => get_string('aggregateweightedmean2', 'grades'), + GRADE_AGGREGATE_EXTRACREDIT_MEAN => get_string('aggregateextracreditmean', 'grades'), + GRADE_AGGREGATE_MEDIAN => get_string('aggregatemedian', 'grades'), + GRADE_AGGREGATE_MIN => get_string('aggregatemin', 'grades'), + GRADE_AGGREGATE_MAX => get_string('aggregatemax', 'grades'), + GRADE_AGGREGATE_MODE => get_string('aggregatemode', 'grades'), + GRADE_AGGREGATE_SUM => get_string('aggregatesum', 'grades')); $html = ''; $root = false; if (is_null($element)) { - $html .= "