source: sipes/modules_contrib/panels/panels_ipe/plugins/display_renderers/panels_renderer_ipe.class.php @ de78188

stableversion-3.0
Last change on this file since de78188 was 4f375e3, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se agrego el modulo panels

  • Propiedad mode establecida a 100644
File size: 8.3 KB
Línea 
1<?php
2
3/**
4 * Renderer class for all In-Place Editor (IPE) behavior.
5 */
6class 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    if (!is_object($content)) {
77      $content = new StdClass();
78    }
79    // Ensure that empty panes have some content.
80    if (empty($content->content)) {
81      // Get the administrative title.
82      $content_type = ctools_get_content_type($pane->type);
83      $title = ctools_content_admin_title($content_type, $pane->subtype, $pane->configuration, $this->display->context);
84
85      $content->content = t('Placeholder for empty "@title"', array('@title' => $title));
86      $pane->IPE_empty = TRUE;
87    }
88
89    return $content;
90  }
91
92  /**
93   * Add an 'empty' pane placeholder above all the normal panes.
94   *
95   * @param $region_id
96   * @param $panes
97   */
98  function render_region($region_id, $panes) {
99    // Generate this region's 'empty' placeholder pane from the IPE plugin.
100    $empty_ph = theme('panels_ipe_placeholder_pane', $region_id, $this->plugins['layout']['panels'][$region_id]);
101
102    // Wrap the placeholder in some guaranteed markup.
103    $panes['empty_placeholder'] = '<div class="panels-ipe-placeholder panels-ipe-on panels-ipe-portlet-marker panels-ipe-portlet-static">' . $empty_ph . "</div>";
104
105    // Generate this region's add new pane button. FIXME waaaaay too hardcoded
106    $panes['add_button'] = theme('panels_ipe_add_pane_button', $region_id, $this->display, $this);
107
108    $output = parent::render_region($region_id, $panes);
109    $output = theme('panels_ipe_region_wrapper', $output, $region_id, $this->display);
110    $classes = 'panels-ipe-region';
111
112    return "<div id='panels-ipe-regionid-$region_id' class='panels-ipe-region'>$output</div>";
113  }
114
115  /**
116   * AJAX entry point to create the controller form for an IPE.
117   */
118  function ajax_save_form($break = NULL) {
119    ctools_include('form');
120    if (!empty($this->cache->locked)) {
121      if ($break != 'break') {
122        $account  = user_load($this->cache->locked->uid);
123        $name     = theme('username', $account);
124        $lock_age = format_interval(time() - $this->cache->locked->updated);
125
126        $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));
127
128        $this->commands[] = array(
129          'command' => 'unlockIPE',
130          'message' => $message,
131          'break_path' => url($this->get_url('save-form', 'break'))
132        );
133        return;
134      }
135
136      // Break the lock.
137      panels_edit_cache_break_lock($this->cache);
138    }
139
140    $form_state = array(
141      'display' => &$this->display,
142      'content_types' => $this->cache->content_types,
143      'rerender' => FALSE,
144      'no_redirect' => TRUE,
145      // Panels needs this to make sure that the layout gets callbacks
146      'layout' => $this->plugins['layout'],
147    );
148
149    $output = ctools_build_form('panels_ipe_edit_control_form', $form_state);
150    if ($output) {
151      // At this point, we want to save the cache to ensure that we have a lock.
152      panels_edit_cache_set($this->cache);
153      $this->commands[] = array(
154        'command' => 'initIPE',
155        'key' => $this->clean_key,
156        'data' => $output,
157      );
158      return;
159    }
160
161    // no output == submit
162    if (!empty($form_state['clicked_button']['#save-display'])) {
163      // Saved. Save the cache.
164      panels_edit_cache_save($this->cache);
165    }
166    else {
167      // Cancelled. Clear the cache.
168      panels_edit_cache_clear($this->cache);
169    }
170
171    $this->commands[] = array(
172      'command' => 'endIPE',
173      'key' => $this->clean_key,
174      'data' => $output,
175    );
176  }
177
178  /**
179   * Create a command array to redraw a pane.
180   */
181  function command_update_pane($pid) {
182    if (is_object($pid)) {
183      $pane = $pid;
184    }
185    else {
186      $pane = $this->display->content[$pid];
187    }
188
189    $this->commands[] = ctools_ajax_command_replace("#panels-ipe-paneid-$pane->pid", $this->render_pane($pane));
190    $this->commands[] = ctools_ajax_command_changed("#panels-ipe-display-{$this->clean_key}");
191  }
192
193  /**
194   * Create a command array to add a new pane.
195   */
196  function command_add_pane($pid) {
197    if (is_object($pid)) {
198      $pane = $pid;
199    }
200    else {
201      $pane = $this->display->content[$pid];
202    }
203
204    $this->commands[] = ctools_ajax_command_append("#panels-ipe-regionid-{$pane->panel} div.panels-ipe-sort-container", $this->render_pane($pane));
205    $this->commands[] = ctools_ajax_command_changed("#panels-ipe-display-{$this->clean_key}");
206  }
207}
208
209/**
210 * FAPI callback to create the Save/Cancel form for the IPE.
211 */
212function panels_ipe_edit_control_form(&$form_state) {
213  $display = &$form_state['display'];
214  // @todo -- this should be unnecessary as we ensure cache_key is set in add_meta()
215//  $display->cache_key = isset($display->cache_key) ? $display->cache_key : $display->did;
216
217  // Annoyingly, theme doesn't have access to form_state so we have to do this.
218  $form['#display'] = $display;
219
220  $layout = panels_get_layout($display->layout);
221  $layout_panels = panels_get_regions($layout, $display);
222
223  $form['panel'] = array('#tree' => TRUE);
224  $form['panel']['pane'] = array('#tree' => TRUE);
225
226  foreach ($layout_panels as $panel_id => $title) {
227    // Make sure we at least have an empty array for all possible locations.
228    if (!isset($display->panels[$panel_id])) {
229      $display->panels[$panel_id] = array();
230    }
231
232    $form['panel']['pane'][$panel_id] = array(
233      // Use 'hidden' instead of 'value' so the js can access it.
234      '#type' => 'hidden',
235      '#default_value' => implode(',', (array) $display->panels[$panel_id]),
236    );
237  }
238
239  $form['buttons']['submit'] = array(
240    '#type' => 'submit',
241    '#value' => t('Save'),
242    '#id' => 'panels-ipe-save',
243    '#submit' => array('panels_edit_display_form_submit'),
244    '#save-display' => TRUE,
245  );
246  $form['buttons']['cancel'] = array(
247    '#type' => 'submit',
248    '#value' => t('Cancel'),
249    '#id' => 'panels-ipe-cancel',
250  );
251  return $form;
252}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.