[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/panels/panels_ipe/plugins/display_renderers/ -> panels_renderer_ipe.class.php (source)

   1  <?php
   2  
   3  /**
   4   * Renderer class for all In-Place Editor (IPE) behavior.
   5   */
   6  class panels_renderer_ipe extends panels_renderer_editor {
   7    // The IPE operates in normal render mode, not admin mode.
   8    var $admin = FALSE;
   9  
  10    function render() {
  11      $output = parent::render();
  12      return "<div id='panels-ipe-display-{$this->clean_key}' class='panels-ipe-display-container'>$output</div>";
  13    }
  14  
  15    function add_meta() {
  16      ctools_include('display-edit', 'panels');
  17      ctools_include('content');
  18  
  19      if (empty($this->display->cache_key)) {
  20        $this->cache = panels_edit_cache_get_default($this->display);
  21      }
  22      // @todo we may need an else to load the cache, but I am not sure we
  23      // actually need to load it if we already have our cache key, and doing
  24      // so is a waste of resources.
  25  
  26      ctools_include('cleanstring');
  27      $this->clean_key = ctools_cleanstring($this->display->cache_key);
  28      panels_ipe_get_cache_key($this->clean_key);
  29  
  30      ctools_include('ajax');
  31      ctools_include('modal');
  32      ctools_modal_add_js();
  33  
  34      ctools_add_css('panels_dnd', 'panels');
  35      ctools_add_css('panels_admin', 'panels');
  36      ctools_add_js('panels_ipe', 'panels_ipe');
  37      ctools_add_css('panels_ipe', 'panels_ipe');
  38  
  39      $settings = array(
  40        'formPath' => url($this->get_url('save-form')),
  41      );
  42      drupal_add_js(array('PanelsIPECacheKeys' => array($this->clean_key)), 'setting');
  43      drupal_add_js(array('PanelsIPESettings' => array($this->clean_key => $settings)), 'setting');
  44  
  45      jquery_ui_add(array('ui.draggable', 'ui.droppable', 'ui.sortable'));
  46      parent::add_meta();
  47    }
  48  
  49    /**
  50     * Override & call the parent, then pass output through to the dnd wrapper
  51     * theme function.
  52     *
  53     * @param $pane
  54     */
  55    function render_pane(&$pane) {
  56      $output = parent::render_pane($pane);
  57      if (empty($output)) {
  58        return;
  59      }
  60  
  61      if (empty($pane->IPE_empty)) {
  62        // Add an inner layer wrapper to the pane content before placing it into
  63        // draggable portlet
  64        $output = "<div class=\"panels-ipe-portlet-content\">$output</div>";
  65      }
  66      else {
  67        $output = "<div class=\"panels-ipe-portlet-content panels-ipe-empty-pane\">$output</div>";
  68      }
  69      // Hand it off to the plugin/theme for placing draggers/buttons
  70      $output = theme('panels_ipe_pane_wrapper', $output, $pane, $this->display, $this);
  71      return "<div id=\"panels-ipe-paneid-{$pane->pid}\" class=\"panels-ipe-portlet-wrapper panels-ipe-portlet-marker\">" . $output . "</div>";
  72    }
  73  
  74    function render_pane_content(&$pane) {
  75      $content = parent::render_pane_content($pane);
  76      // Ensure that empty panes have some content.
  77      if (empty($content->content)) {
  78        // Get the administrative title.
  79        $content_type = ctools_get_content_type($pane->type);
  80        $title = ctools_content_admin_title($content_type, $pane->subtype, $pane->configuration, $this->display->context);
  81  
  82        $content->content = t('Placeholder for empty "@title"', array('@title' => $title));
  83        $pane->IPE_empty = TRUE;
  84      }
  85  
  86      return $content;
  87    }
  88  
  89    /**
  90     * Add an 'empty' pane placeholder above all the normal panes.
  91     *
  92     * @param $region_id
  93     * @param $panes
  94     */
  95    function render_region($region_id, $panes) {
  96      // Generate this region's 'empty' placeholder pane from the IPE plugin.
  97      $empty_ph = theme('panels_ipe_placeholder_pane', $region_id, $this->plugins['layout']['panels'][$region_id]);
  98  
  99      // Wrap the placeholder in some guaranteed markup.
 100      $panes['empty_placeholder'] = '<div class="panels-ipe-placeholder panels-ipe-on panels-ipe-portlet-marker panels-ipe-portlet-static">' . $empty_ph . "</div>";
 101  
 102      // Generate this region's add new pane button. FIXME waaaaay too hardcoded
 103      $panes['add_button'] = theme('panels_ipe_add_pane_button', $region_id, $this->display, $this);
 104  
 105      $output = parent::render_region($region_id, $panes);
 106      $output = theme('panels_ipe_region_wrapper', $output, $region_id, $this->display);
 107      $classes = 'panels-ipe-region';
 108  
 109      ctools_include('cleanstring');
 110      $region_id = ctools_cleanstring($region_id);
 111      return "<div id='panels-ipe-regionid-$region_id' class='panels-ipe-region'>$output</div>";
 112    }
 113  
 114    /**
 115     * AJAX entry point to create the controller form for an IPE.
 116     */
 117    function ajax_save_form($break = NULL) {
 118      ctools_include('form');
 119      if (!empty($this->cache->locked)) {
 120        if ($break != 'break') {
 121          $account  = user_load($this->cache->locked->uid);
 122          $name     = theme('username', $account);
 123          $lock_age = format_interval(time() - $this->cache->locked->updated);
 124  
 125          $message = t("This panel is being edited by user !user, and is therefore locked from editing by others. This lock is !age old.\n\nClick OK to break this lock and discard any changes made by !user.", array('!user' => $name, '!age' => $lock_age));
 126  
 127          $this->commands[] = array(
 128            'command' => 'unlockIPE',
 129            'message' => $message,
 130            'break_path' => url($this->get_url('save-form', 'break'))
 131          );
 132          return;
 133        }
 134  
 135        // Break the lock.
 136        panels_edit_cache_break_lock($this->cache);
 137      }
 138  
 139      $form_state = array(
 140        'display' => &$this->display,
 141        'content_types' => $this->cache->content_types,
 142        'rerender' => FALSE,
 143        'no_redirect' => TRUE,
 144        // Panels needs this to make sure that the layout gets callbacks
 145        'layout' => $this->plugins['layout'],
 146      );
 147  
 148      $output = ctools_build_form('panels_ipe_edit_control_form', $form_state);
 149      if ($output) {
 150        // At this point, we want to save the cache to ensure that we have a lock.
 151        panels_edit_cache_set($this->cache);
 152        $this->commands[] = array(
 153          'command' => 'initIPE',
 154          'key' => $this->clean_key,
 155          'data' => $output,
 156        );
 157        return;
 158      }
 159  
 160      // no output == submit
 161      if (!empty($form_state['clicked_button']['#save-display'])) {
 162        // Saved. Save the cache.
 163        panels_edit_cache_save($this->cache);
 164      }
 165      else {
 166        // Cancelled. Clear the cache.
 167        panels_edit_cache_clear($this->cache);
 168      }
 169  
 170      $this->commands[] = array(
 171        'command' => 'endIPE',
 172        'key' => $this->clean_key,
 173        'data' => $output,
 174      );
 175    }
 176  
 177    /**
 178     * Create a command array to redraw a pane.
 179     */
 180    function command_update_pane($pid) {
 181      if (is_object($pid)) {
 182        $pane = $pid;
 183      }
 184      else {
 185        $pane = $this->display->content[$pid];
 186      }
 187  
 188      $this->commands[] = ctools_ajax_command_replace("#panels-ipe-paneid-$pane->pid", $this->render_pane($pane));
 189      $this->commands[] = ctools_ajax_command_changed("#panels-ipe-display-{$this->clean_key}");
 190    }
 191  
 192    /**
 193     * Create a command array to add a new pane.
 194     */
 195    function command_add_pane($pid) {
 196      if (is_object($pid)) {
 197        $pane = $pid;
 198      }
 199      else {
 200        $pane = $this->display->content[$pid];
 201      }
 202  
 203      ctools_include('cleanstring');
 204      $region_id = ctools_cleanstring($pane->panel);
 205      $this->commands[] = ctools_ajax_command_append("#panels-ipe-regionid-$region_id div.panels-ipe-sort-container", $this->render_pane($pane));
 206      $this->commands[] = ctools_ajax_command_changed("#panels-ipe-display-{$this->clean_key}");
 207    }
 208  }
 209  
 210  /**
 211   * FAPI callback to create the Save/Cancel form for the IPE.
 212   */
 213  function panels_ipe_edit_control_form(&$form_state) {
 214    $display = &$form_state['display'];
 215    // @todo -- this should be unnecessary as we ensure cache_key is set in add_meta()
 216  //  $display->cache_key = isset($display->cache_key) ? $display->cache_key : $display->did;
 217  
 218    // Annoyingly, theme doesn't have access to form_state so we have to do this.
 219    $form['#display'] = $display;
 220  
 221    $layout = panels_get_layout($display->layout);
 222    $layout_panels = panels_get_regions($layout, $display);
 223  
 224    $form['panel'] = array('#tree' => TRUE);
 225    $form['panel']['pane'] = array('#tree' => TRUE);
 226  
 227    foreach ($layout_panels as $panel_id => $title) {
 228      // Make sure we at least have an empty array for all possible locations.
 229      if (!isset($display->panels[$panel_id])) {
 230        $display->panels[$panel_id] = array();
 231      }
 232  
 233      $form['panel']['pane'][$panel_id] = array(
 234        // Use 'hidden' instead of 'value' so the js can access it.
 235        '#type' => 'hidden',
 236        '#default_value' => implode(',', (array) $display->panels[$panel_id]),
 237      );
 238    }
 239  
 240    $form['buttons']['submit'] = array(
 241      '#type' => 'submit',
 242      '#value' => t('Save'),
 243      '#id' => 'panels-ipe-save',
 244      '#submit' => array('panels_edit_display_form_submit'),
 245      '#save-display' => TRUE,
 246    );
 247    $form['buttons']['cancel'] = array(
 248      '#type' => 'submit',
 249      '#value' => t('Cancel'),
 250      '#id' => 'panels-ipe-cancel',
 251    );
 252    return $form;
 253  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7