You are here

function template_preprocess_draggableviews_view_draggabletable_form in DraggableViews 6

Same name and namespace in other branches
  1. 6.3 draggableviews_theme.inc \template_preprocess_draggableviews_view_draggabletable_form()
  2. 6.2 draggableviews_theme.inc \template_preprocess_draggableviews_view_draggabletable_form()
  3. 7 draggableviews_theme.inc \template_preprocess_draggableviews_view_draggabletable_form()

File

./draggableviews_theme.inc, line 339

Code

function template_preprocess_draggableviews_view_draggabletable_form($vars) {
  global $user;

  // get view object
  $viewObj = $vars['form']['#parameters'][2];

  // add javascript
  // BE AWARE: realtimeedit module js has to be loaded first,
  // generated links should be appended in the right order

  //include realtimeedit module
  if (module_exists('realtimeedit')) {

    // check if module exists
    drupal_add_js(drupal_get_path('module', 'realtimeedit') . '/realtimeedit.js');
    drupal_add_css(drupal_get_path('module', 'realtimeedit') . '/styles.css');
  }

  // fetch expand information from database
  $result = db_query(db_rewrite_sql("SELECT parent_nid, collapsed FROM {draggableviews_collapsed} WHERE uid = %d"), $user->uid);
  $states = array();
  while ($state = db_fetch_object($result)) {
    $states[$state->parent_nid] = $state->collapsed;
  }

  // check if "expand" links should be shown
  if ($viewObj->options['tabledrag_expand']['expand_links']) {
    drupal_add_js(drupal_get_path('module', 'draggableviews') . '/draggableviews.js');
    if (count($states) == 0) {

      // let js know wether child nodes should be expanded or not
      drupal_add_js(array(
        'draggableviews' => array(
          'expand_default' => $viewObj->options['tabledrag_expand']['collapsed'] ? 1 : 0,
        ),
      ), 'setting');
    }
    else {
      drupal_add_js(array(
        'draggableviews' => array(
          'states' => $states,
        ),
      ), 'setting');
    }
    drupal_add_css(drupal_get_path('module', 'draggableviews') . '/styles.css');
  }

  //theme view
  $sets = $viewObj
    ->render_grouping($viewObj->view->result, $viewObj->options['grouping']);
  $output = '';
  foreach ($sets as $title => $records) {
    $output .= theme($viewObj
      ->theme_functions(), $viewObj->view, $viewObj->options, $records, $title);
  }
  $vars['view'] = $output;

  //render submit form
  $vars['submit_form'] = drupal_render($vars['form']);
}