You are here

function theme_javascript_libraries_custom_form in JavaScript Libraries Manager 7

Default theme function for javascript_libraries_custom_form().

See also

block module drag and drop table construction.

File

./javascript_libraries.admin.inc, line 306
Administrative management forms for JavaScript libraries.

Code

function theme_javascript_libraries_custom_form($variables) {
  $form = $variables['form'];
  $listing = array();
  $i = 0;
  foreach (element_children($form['libraries']) as $key) {
    $i++;
    $idx = $form['libraries'][$key]['weight']['#default_value'] . '.0' . $i;
    $scope = $form['libraries'][$key]['scope']['#default_value'];
    $listing[$scope][$idx]['class'] = array(
      "draggable",
    );
    $listing[$scope][$idx]['data'][] = drupal_render($form['libraries'][$key]['name']);
    $listing[$scope][$idx]['data'][] = drupal_render($form['libraries'][$key]['extra']);
    $listing[$scope][$idx]['data'][] = drupal_render($form['libraries'][$key]['scope']);
    $listing[$scope][$idx]['data'][] = drupal_render($form['libraries'][$key]['weight']);
    $listing[$scope][$idx]['data'][] = drupal_render($form['libraries'][$key]['type']);
    $listing[$scope][$idx]['data'][] = drupal_render($form['libraries'][$key]['edit']);
    $listing[$scope][$idx]['data'][] = drupal_render($form['libraries'][$key]['delete']);
  }
  $rows = array();
  foreach ($form['page_scopes']['#value'] as $scope => $title) {
    $populated_class = !empty($listing[$scope]) ? 'region-populated' : 'region-empty';
    $top = array(
      array(
        'data' => array(
          array(
            'data' => $title,
            'colspan' => 6,
          ),
        ),
        "no_striping" => TRUE,
        'class' => array(
          'region-title',
          'region-list-' . $scope,
        ),
      ),
      array(
        'data' => array(
          array(
            'data' => t('No libraries in this scope'),
            'colspan' => 6,
          ),
        ),
        "no_striping" => TRUE,
        'class' => array(
          'region-message',
          'region-' . $scope . '-message',
          $populated_class,
        ),
      ),
    );
    $rows = array_merge($rows, $top);
    if (!empty($listing[$scope])) {
      ksort($listing[$scope], SORT_NUMERIC);
      $rows = array_merge($rows, array_values($listing[$scope]));
    }
  }
  $table_attributes = array(
    'id' => 'javascript-libraries-custom',
  );
  if ($listing) {

    // Add table javascript if there is anything to drag-n-drop.
    drupal_add_js('misc/tableheader.js');
    drupal_add_js(drupal_get_path('module', 'javascript_libraries') . '/javascript_libraries.js');
    foreach ($form['page_scopes']['#value'] as $scope => $title) {
      drupal_add_tabledrag('javascript-libraries-custom', 'match', 'sibling', 'library-region-select', 'library-region-' . $scope, NULL, FALSE);
      drupal_add_tabledrag('javascript-libraries-custom', 'order', 'sibling', 'library-weight', 'library-weight-' . $scope);
    }
  }
  else {

    // A CSS class to hide the weight column when the table is empty.
    $table_attributes['class'] = array(
      'empty',
    );
  }
  return theme('table', array(
    'header' => $form['#header'],
    'rows' => $rows,
    'attributes' => $table_attributes,
  )) . drupal_render_children($form);
}