Skip to content
Snippets Groups Projects
Commit f6cadac0 authored by Earl Miles's avatar Earl Miles
Browse files

Make dependent.js work with the modal and modify views panes to utilize it.

parent af1f63f6
No related branches found
No related tags found
No related merge requests found
...@@ -55,6 +55,9 @@ ...@@ -55,6 +55,9 @@
* - selector: The CSS selector to add CSS to. * - selector: The CSS selector to add CSS to.
* - argument: An array of 'key': 'value' CSS selectors to set. * - argument: An array of 'key': 'value' CSS selectors to set.
* *
* - settings
* - argument: An array of settings to add to Drupal.settings via $.extend
*
* Commands are usually created with a couple of helper functions, so they * Commands are usually created with a couple of helper functions, so they
* look like this: * look like this:
* *
...@@ -276,6 +279,21 @@ function ctools_ajax_command_css($selector, $argument) { ...@@ -276,6 +279,21 @@ function ctools_ajax_command_css($selector, $argument) {
); );
} }
/**
* Create a settings command for the AJAX responder.
*
* This will extend Drupal.settings with the given array.
*
* @param $argument
* An array of key: value pairs to add to the settings.
*/
function ctools_ajax_command_settings($argument) {
return array(
'command' => 'settings',
'argument' => $argument,
);
}
/** /**
* Force a table to be restriped. * Force a table to be restriped.
* *
......
...@@ -169,7 +169,13 @@ function ctools_modal_form_render($form_state, $output) { ...@@ -169,7 +169,13 @@ function ctools_modal_form_render($form_state, $output) {
$output = '<div class="messages">' . $messages . '</div>' . $output; $output = '<div class="messages">' . $messages . '</div>' . $output;
} }
return array(ctools_modal_command_display($title, $output)); $commands = array();
if (isset($form_state['js settings'])) {
$commands[] = ctools_ajax_command_settings($form_state['js settings']);
}
$commands[] = ctools_modal_command_display($title, $output);
return $commands;
} }
/** /**
......
...@@ -203,6 +203,10 @@ Drupal.CTools.AJAX.commands = { ...@@ -203,6 +203,10 @@ Drupal.CTools.AJAX.commands = {
$(data.selector).css(data.argument); $(data.selector).css(data.argument);
}, },
settings: function(data) {
$.extend(Drupal.settings, data.argument);
},
restripe: function(data) { restripe: function(data) {
// :even and :odd are reversed because jquery counts from 0 and // :even and :odd are reversed because jquery counts from 0 and
// we count from 1, so we're out of sync. // we count from 1, so we're out of sync.
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
function views_content_views_panes_ctools_content_types() { function views_content_views_panes_ctools_content_types() {
return array( return array(
'title' => t('View panes'), 'title' => t('View panes'),
'js' => array(drupal_get_path('module', 'ctools') . '/js/dependent.js'),
); );
} }
...@@ -291,14 +292,14 @@ function views_content_views_panes_content_type_edit_form(&$form, &$form_state) ...@@ -291,14 +292,14 @@ function views_content_views_panes_content_type_edit_form(&$form, &$form_state)
if ($allow['link_to_view'] ) { if ($allow['link_to_view'] ) {
$form['link_to_view'] = array( $form['link_to_view'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#default_value' => $conf['link_to_view'], '#default_value' => isset($conf['link_to_view']) ? $conf['link_to_view'] : $view->display_handler->get_option('link_to_view'),
'#title' => t('Link title to page'), '#title' => t('Link title to page'),
); );
} }
if ($allow['more_link']) { if ($allow['more_link']) {
$form['more_link'] = array( $form['more_link'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#default_value' => $conf['more_link'], '#default_value' => isset($conf['more_link']) ? $conf['more_link'] : $view->display_handler->get_option('more_link'),
'#title' => t('Provide a "more" link.'), '#title' => t('Provide a "more" link.'),
); );
} }
...@@ -307,11 +308,12 @@ function views_content_views_panes_content_type_edit_form(&$form, &$form_state) ...@@ -307,11 +308,12 @@ function views_content_views_panes_content_type_edit_form(&$form, &$form_state)
if (!empty($allow['feed_icons'])) { if (!empty($allow['feed_icons'])) {
$form['feed_icons'] = array( $form['feed_icons'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#default_value' => $conf['feed_icons'], '#default_value' => !empty($conf['feed_icons']),
'#title' => t('Display feed icons'), '#title' => t('Display feed icons'),
); );
} }
ctools_include('dependent');
if ($allow['use_pager']) { if ($allow['use_pager']) {
$form['pager_aligner_start'] = array( $form['pager_aligner_start'] = array(
'#value' => '<div class="option-text-aligner">', '#value' => '<div class="option-text-aligner">',
...@@ -319,15 +321,17 @@ function views_content_views_panes_content_type_edit_form(&$form, &$form_state) ...@@ -319,15 +321,17 @@ function views_content_views_panes_content_type_edit_form(&$form, &$form_state)
$form['use_pager'] = array( $form['use_pager'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Use pager'), '#title' => t('Use pager'),
'#default_value' => $conf['use_pager'], '#default_value' => isset($conf['use_pager']) ? $conf['use_pager'] : $view->display_handler->get_option('use_pager'),
'#id' => 'use-pager-checkbox', '#id' => 'use-pager-checkbox',
); );
$form['pager_id'] = array( $form['pager_id'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#default_value' => $conf['pager_id'], '#default_value' => isset($conf['pager_id']) ? $conf['pager_id'] : $view->display_handler->get_option('element_id'),
'#title' => t('Pager ID'), '#title' => t('Pager ID'),
'#size' => 4, '#size' => 4,
'#id' => 'use-pager-textfield', '#id' => 'use-pager-textfield',
'#process' => array('ctools_dependent_process'),
'#dependency' => array('use-pager-checkbox' => array(1)),
); );
$form['pager_aligner_stop'] = array( $form['pager_aligner_stop'] = array(
'#value' => '</div><div style="clear: both; padding: 0; margin: 0"></div>', '#value' => '</div><div style="clear: both; padding: 0; margin: 0"></div>',
...@@ -336,7 +340,7 @@ function views_content_views_panes_content_type_edit_form(&$form, &$form_state) ...@@ -336,7 +340,7 @@ function views_content_views_panes_content_type_edit_form(&$form, &$form_state)
if ($allow['items_per_page']) { if ($allow['items_per_page']) {
$form['items_per_page'] = array( $form['items_per_page'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#default_value' => $conf['items_per_page'], '#default_value' => isset($conf['items_per_page']) ? $conf['items_per_page'] : $view->display_handler->get_option('items_per_page'),
'#title' => t('Num items'), '#title' => t('Num items'),
'#size' => 4, '#size' => 4,
'#description' => t('Select the number of items to display, or 0 to display all results.'), '#description' => t('Select the number of items to display, or 0 to display all results.'),
...@@ -345,18 +349,16 @@ function views_content_views_panes_content_type_edit_form(&$form, &$form_state) ...@@ -345,18 +349,16 @@ function views_content_views_panes_content_type_edit_form(&$form, &$form_state)
if ($allow['offset']) { if ($allow['offset']) {
$form['offset'] = array( $form['offset'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#default_value' => $conf['offset'], '#default_value' => isset($conf['offset']) ? $conf['offset'] : $view->display_handler->get_option('offset'),
'#title' => t('Offset'), '#title' => t('Offset'),
'#size' => 4, '#size' => 4,
'#description' => t('Enter the number of items to skip; enter 0 to skip no items.'), '#description' => t('Enter the number of items to skip; enter 0 to skip no items.'),
); );
} }
if ($allow['path_override']) { if ($allow['path_override']) {
// TODO: Because javascript in the dialogs is kind of weird, dependent checkboxes
// don't work right for external modules. This needs fixing in panels itself.
$form['path'] = array( $form['path'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#default_value' => $conf['path'], '#default_value' => isset($conf['path']) ? $conf['path'] : $view->get_path(),
'#title' => t('Override path'), '#title' => t('Override path'),
'#size' => 30, '#size' => 30,
'#description' => t('If this is set, override the View URL path; this can sometimes be useful to set to the panel URL.'), '#description' => t('If this is set, override the View URL path; this can sometimes be useful to set to the panel URL.'),
...@@ -373,7 +375,9 @@ function views_content_views_panes_content_type_edit_form_submit(&$form, &$form_ ...@@ -373,7 +375,9 @@ function views_content_views_panes_content_type_edit_form_submit(&$form, &$form_
'pager_id', 'items_per_page', 'offset', 'path_override', 'path'); 'pager_id', 'items_per_page', 'offset', 'path_override', 'path');
foreach ($keys as $key) { foreach ($keys as $key) {
$form_state['conf'][$key] = $form_state['values'][$key]; if (isset($form_state['values'][$key])) {
$form_state['conf'][$key] = $form_state['values'][$key];
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment