[3959b2a] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /** |
---|
| 4 | * @file |
---|
| 5 | * This file will define the administrative methods of services |
---|
| 6 | */ |
---|
| 7 | function theme_services_resource_table($variables) { |
---|
| 8 | $table = $variables; |
---|
| 9 | |
---|
| 10 | drupal_add_css(drupal_get_path('module', 'services') . '/css/services.admin.css'); |
---|
| 11 | drupal_add_js(drupal_get_path('module', 'services') . '/js/services.admin.js'); |
---|
| 12 | drupal_add_js('misc/tableselect.js'); |
---|
| 13 | |
---|
| 14 | // Create header for resource selection table. |
---|
| 15 | $header = array( |
---|
| 16 | theme('table_select_header_cell'), |
---|
| 17 | array('data' => t('Resource'), 'class' => 'resource_method'), |
---|
| 18 | array('data' => t('Description'), 'class' => 'resource_description'), |
---|
| 19 | array('data' => t('Alias'), 'class' => 'resource_alias'), |
---|
| 20 | ); |
---|
| 21 | |
---|
| 22 | // Define the images used to expand/collapse the method groups. |
---|
| 23 | $js = array( |
---|
| 24 | 'images' => array( |
---|
| 25 | theme('image', 'misc/menu-collapsed.png', 'Expand', 'Expand'), |
---|
| 26 | theme('image', 'misc/menu-expanded.png', 'Collapsed', 'Collapsed'), |
---|
| 27 | ), |
---|
| 28 | ); |
---|
| 29 | |
---|
| 30 | // Cycle through each method group and create a row. |
---|
| 31 | $rows = array(); |
---|
| 32 | foreach (element_children($table) as $key) { |
---|
| 33 | $element = &$table[$key]; |
---|
| 34 | $row = array(); |
---|
| 35 | |
---|
| 36 | // Make the class name safe for output on the page by replacing all |
---|
| 37 | // non-word/decimal characters with a dash (-). |
---|
| 38 | $method_class = drupal_strtolower(trim(preg_replace("/[^\w\d]/", "-", $key))); |
---|
| 39 | |
---|
| 40 | // Select the right "expand"/"collapse" image, depending on whether the |
---|
| 41 | // category is expanded (at least one method selected) or not. |
---|
| 42 | $collapsed = !empty($element['#collapsed']); |
---|
| 43 | $image_index = $collapsed ? 0 : 0; |
---|
| 44 | |
---|
| 45 | // Place-holder for checkboxes to select group of methods. |
---|
| 46 | $row[] = array('id' => $method_class, 'class' => 'resource-select-all'); |
---|
| 47 | |
---|
| 48 | // Expand/collapse image and group title. |
---|
| 49 | $row[] = array( |
---|
| 50 | 'data' => '<div class="resource-image" id="resource-method-group-' . $method_class . '"></div>' . |
---|
| 51 | '<label for="' . $method_class . '-select-all" class="resource-group-label">' . $key . '</label>', |
---|
| 52 | 'class' => 'resource-group-label', |
---|
| 53 | ); |
---|
| 54 | |
---|
| 55 | $row[] = array( |
---|
| 56 | 'data' => ' ', |
---|
| 57 | 'class' => 'resource-group-description', |
---|
| 58 | ); |
---|
| 59 | $row[] = array( |
---|
| 60 | 'data' => drupal_render($element[$method_class . '-alias']), |
---|
| 61 | 'class' => 'resource-group-alias', |
---|
| 62 | ); |
---|
| 63 | $rows[] = array('data' => $row, 'class' => 'resource-group'); |
---|
| 64 | |
---|
| 65 | // Add individual methods to group. |
---|
| 66 | $current_js = array( |
---|
| 67 | 'methodClass' => $method_class . '-method', |
---|
| 68 | 'methodNames' => array(), |
---|
| 69 | 'imageDirection' => $image_index, |
---|
| 70 | 'clickActive' => FALSE, |
---|
| 71 | ); |
---|
| 72 | |
---|
| 73 | // Cycle through each method within the current group. |
---|
| 74 | foreach (element_children($element) as $method_name) { |
---|
| 75 | if (!strpos($method_name, 'alias') && $method_name != 'alias') { |
---|
| 76 | $method = $element[$method_name]; |
---|
| 77 | $row = array(); |
---|
| 78 | |
---|
| 79 | $current_js['methodNames'][] = $method['#id']; |
---|
| 80 | |
---|
| 81 | // Store method title and description so that checkbox won't render them. |
---|
| 82 | $title = $method['#title']; |
---|
| 83 | $description = $method['#description']; |
---|
| 84 | |
---|
| 85 | unset($method['#description']); |
---|
| 86 | unset($method['#title']); |
---|
| 87 | |
---|
| 88 | // Test name is used to determine what methods to run. |
---|
| 89 | $method['#name'] = $method_name; |
---|
| 90 | $row[] = array( |
---|
| 91 | 'data' => drupal_render($method), |
---|
| 92 | 'class' => 'resource-method-select', |
---|
| 93 | ); |
---|
| 94 | $row[] = array( |
---|
| 95 | 'data' => '<label for="' . $method['#id'] . '">' . $title . '</label>', |
---|
| 96 | 'class' => 'resource-method-label', |
---|
| 97 | ); |
---|
| 98 | $row[] = array( |
---|
| 99 | 'data' => '<div class="description">' . $description . '</div>', |
---|
| 100 | 'class' => 'resource-method-description', |
---|
| 101 | ); |
---|
| 102 | $row[] = array( |
---|
| 103 | 'data' => '<div class="alias"> </div>', |
---|
| 104 | 'class' => 'resource-method-alias', |
---|
| 105 | ); |
---|
| 106 | //$rows[] = array('data' => $row, 'class' => $test_class . '-test ' . ($collapsed ? 'js-hide' : '')); |
---|
| 107 | $rows[] = array('data' => $row, 'class' => $method_class . '-method ' . ($collapsed ? 'js-hide' : '')); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | } |
---|
| 111 | $js['resource-method-group-' . $method_class] = $current_js; |
---|
| 112 | unset($table[$key]); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | // Add js array of settings. |
---|
| 116 | drupal_add_js(array('resource' => $js), 'setting'); |
---|
| 117 | |
---|
| 118 | if (empty($rows)) { |
---|
| 119 | return '<strong>' . t('No resourcess to display.') . '</strong>'; |
---|
| 120 | } |
---|
| 121 | else { |
---|
| 122 | return theme('table', $header, $rows, array('id' => 'resource-form-table')); |
---|
| 123 | //return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'resource-form-table'))); |
---|
| 124 | } |
---|
| 125 | } |
---|