? flexifilter_ui.patch Index: flexifilter-admin-component-list.tpl.php =================================================================== RCS file: flexifilter-admin-component-list.tpl.php diff -N flexifilter-admin-component-list.tpl.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ flexifilter-admin-component-list.tpl.php 2 Feb 2008 19:55:22 -0000 @@ -0,0 +1,20 @@ + + + $row): ?> + + + + + + +
+
+
+
\ No newline at end of file Index: flexifilter-admin-list.tpl.php =================================================================== RCS file: flexifilter-admin-list.tpl.php diff -N flexifilter-admin-list.tpl.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ flexifilter-admin-list.tpl.php 2 Feb 2008 19:55:22 -0000 @@ -0,0 +1,20 @@ + + + + + + + + + $row): ?> + + + + + + + + +
\ No newline at end of file Index: flexifilter.admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/flexifilter/flexifilter.admin.inc,v retrieving revision 1.13 diff -u -p -r1.13 flexifilter.admin.inc --- flexifilter.admin.inc 24 Jan 2008 01:57:10 -0000 1.13 +++ flexifilter.admin.inc 2 Feb 2008 19:55:22 -0000 @@ -4,23 +4,53 @@ /** * Generates the form for the admin overview page */ -function flexifilter_filter_list_form() { +function flexifilter_admin_list_form($form_state) { drupal_set_title("Flexifilters overview"); $path = drupal_get_path('module', 'flexifilter') .'/flexifilter.css'; drupal_add_css($path, 'module', 'all', FALSE); + if (isset($form_state['values']['enabled'])) { + foreach ($form_state['values']['enabled']['statuses'] as $fid => $value) { + if ($value == 'disabled') { + db_query('UPDATE {flexifilters} SET enabled = 0 WHERE fid = %d', $fid); + } + } + } + if (isset($form_state['values']['disabled'])) { + foreach ($form_state['values']['disabled']['statuses'] as $fid => $value) { + if ($value == 'enabled') { + db_query('UPDATE {flexifilters} SET enabled = 1 WHERE fid = %d', $fid); + } + } + } $form = array(); $form['enabled_header'] = array( '#value' => '

'. t('Enabled Flexifilters') .'

', '#suffix' => t('If a flexifilter is enabled, then it can be used within input formats, however there can only be 128 enabled at any one time.') .'
', ); - $form['enabled'] = flexifilter_filter_list_form_table(TRUE); + $form['enabled'] = flexifilter_admin_list_form_table(TRUE); $form['disabled_header'] = array( '#value' => '

'. t('Disabled Flexifilters') .'

', '#suffix' => t('If a flexifilter is disabled, then it cannot be used within input formats, although it can be used within other flexifilters.') .'
', ); - $form['disabled'] = flexifilter_filter_list_form_table(FALSE); + $form['disabled'] = flexifilter_admin_list_form_table(FALSE); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save'), + '#ahah' => array( + 'path' => 'admin/build/flexifilters/js/list_form', + 'selector' => '.flexifilter-status', + 'wrapper' => 'flexifilter-admin-list-form', + 'event' => 'change', + 'effect' => 'none', + 'method' => 'replace', + ), + ); + if (!isset($form_state['values'])) { + $form['#theme'] = 'flexifilter_filter_admin_form'; + } return $form; } @@ -29,87 +59,220 @@ function flexifilter_filter_list_form() * Helper function for flexifilter_filter_list_form. Returns the table for the overview page. * * @param $enabled - * Is TRUE if we're theming the currently enabled filters.s + * Is TRUE if we're theming the currently enabled filters. */ -function flexifilter_filter_list_form_table($enabled) { - $show_disable_link = $enabled; - $show_enable_link = !$enabled && flexifilter_get_number_enabled_filters() < FLEXIFILTER_MAX_FILTERS; - $header = array(t('Label'), t('Description'), t('Edit'), t('Delete'), t($enabled ? 'Disable' : 'Enable')); - $rows = array(); - $filters = flexifilter_get_filters(); +function flexifilter_admin_list_form_table($enabled) { + $options = array(); + if (flexifilter_get_number_enabled_filters() < FLEXIFILTER_MAX_FILTERS) { + $options['enabled'] = t('Enabled'); + } + $options['disabled'] = t('Disabled'); + $rowinfo = array(); + $statuses = array(); + $filters = flexifilter_get_filters(); foreach ($filters as $id => $filter) { if ($filter['enabled'] == $enabled) { - $row = array($filter['label'], $filter['description']); - $row[] = l(t('Edit'), 'admin/build/flexifilters/'. $id .'/edit', array(), drupal_get_destination()); - $row[] = l(t('Delete'), 'admin/build/flexifilters/'. $id .'/delete', array(), drupal_get_destination()); - if ($show_disable_link) { - $row[] = l(t('Disable'), 'admin/build/flexifilters/'. $id .'/disable', array(), drupal_get_destination()); - } - else if ($show_enable_link) { - $row[] = l(t('Enable'), 'admin/build/flexifilters/'. $id .'/enable', array(), drupal_get_destination()); - } - else { - $row[] = ''; - } - $rows[] = $row; + $rowinfo[] = array( + 'label' => $filter['label'], + 'description' => $filter['description'], + 'edit' => l(t('Edit'), 'admin/build/flexifilters/'. $id .'/edit', array(), drupal_get_destination()), + ); + $statuses[$filter['id']] = array( + '#type' => 'select', + '#title' => t('Status'), + '#options' => $options, + '#default_value' => ($enabled? 'enabled' : 'disabled'), + '#attributes' => array('class' => 'flexifilter-status'), + ); } } - if (count($rows)) { - return array('#value' => theme('table', $header, $rows, array('class' => 'flexifilters-list'))); + if (count($rowinfo)) { + return array('#theme' => 'flexifilter_admin_list', '#rowinfo' => $rowinfo, 'statuses' => $statuses, '#tree' => TRUE); } else { - return array('#value' => t('None.')); + return array('#value' => ''. t('There are no @status filters at this moment.', array('@status' => ($enabled? t('enabled') : t('disabled')))) .'
'); } } /** - * Helper function for flexifilter_filter_edit_form; removes the automatic - * naming of submit controls. - * Our forms are complex and have submit controls nested within fieldsets, - * and when pressed, we want the 'op' field to be set within the fieldset, - * not at the top level, so we have to undo the automatic naming of submit - * fields. - * This function is a brutal rip of code from _form_builder_handle_input_element - * - * @param $form A form element to reset to the normal name. - * - * @return The updated form element + * Preprocess for the admin list table + * + * Takes the separate row info and statuses and combines them into a table. */ -function flexifilter_undo_submit_default_name($form) { - $name = array_shift($form['#parents']); - $form['#name'] = $name; - if ($form['#type'] == 'file') { - // To make it easier to handle $_FILES in file.inc, we place all - // file fields in the 'files' array. Also, we do not support - // nested file names. - $form['#name'] = 'files['. $form['#name'] .']'; +function template_preprocess_flexifilter_admin_list(&$variables) { + $variables['table'] = array(); + foreach ($variables['form']['#rowinfo'] as $index => $rowinfo) { + $variables['table'][$index] = $rowinfo; } - elseif (count($form['#parents'])) { - $form['#name'] .= '['. implode('][', $form['#parents']) .']'; + $count = 0; + foreach (element_children($variables['form']['statuses']) as $key) { + unset($variables['form']['statuses'][$key]['#title']); + $variables['table'][$count]['status'] = drupal_render($variables['form']['statuses'][$key]); + $count++; } - array_unshift($form['#parents'], $name); - return $form; + $variables['label'] = t('Label'); + $variables['description'] = t('Description'); + $variables['status'] = t('Status'); +} + +function theme_flexifilter_filter_admin_form($form) { + unset($form['submit']); + return '
'. drupal_render($form) .'
'; } /** - * Helper function for flexifilter_filter_edit_components_data; converts a condition - * array from a flexifilter into a form data styled array. + * The add/edit form for flexifilters. */ -function flexifilter_filter_edit_condition_data($data) { - $condition = array( - 'class' => $data['class'], +function flexifilter_admin_edit_form($form_state, $flexifilter = 'new') { + drupal_add_js(drupal_get_path('module', 'flexifilter') .'/jquery.scrollTo.js'); + drupal_add_js(drupal_get_path('module', 'flexifilter') .'/flexifilter.js'); + drupal_add_css(drupal_get_path('module', 'flexifilter') .'/flexifilter.css'); + if (!isset($form_state['post']) || !isset($form_state['post']['fid'])) { + $data = array(); + $data['fid'] = $flexifilter == 'new' ? 'new' : $flexifilter['id']; + $data['basic'] = array(); + $data['basic']['label'] = $flexifilter == 'new' ? '' : $flexifilter['label']; + $data['basic']['description'] = $flexifilter == 'new' ? '' : $flexifilter['description']; + $data['basic']['advanced'] = $flexifilter == 'new' ? 0 : $flexifilter['advanced']; + $data['components'] = $flexifilter == 'new' ? array() : flexifilter_filter_edit_components_data($flexifilter['components']); + if (!isset($data['components']['id_prefix']) || $data['components']['id_prefix'] === 'component_new_') { + $data['components']['id_prefix'] = 'component_'. $data['fid'] .'_'; + } + if (!isset($data['components']['id_next'])) { + $data['components']['id_next'] = 0; + } + } + else { + $data = $form_state['post']; + if (!isset($data['basic']['advanced'])) { + $data['basic']['advanced'] = 0; + } + } + drupal_add_js(array('flexifilterFid' => $data['fid']), 'setting'); + $form = array(); + $form['fid'] = array( + '#type' => 'hidden', + '#value' => $data['fid'], ); - foreach ($data['settings'] as $key => $value) { - if ($key == 'conditions') { - foreach ($value as $cond_key => $cond_value) { - $condition['condition_'. $cond_key] = flexifilter_filter_edit_condition_data($cond_value); - } + $form['basic'] = array( + '#type' => 'fieldset', + '#title' => t('Settings'), + '#collapsible' => FALSE, + '#tree' => TRUE, + ); + $form['basic']['label'] = array( + '#type' => 'textfield', + '#title' => t('Label'), + '#required' => TRUE, + '#maxlength' => 127, + '#description' => t('Choose an appropriate label for this flexifilter.'), + '#default_value' => $data['basic']['label'], + ); + $form['basic']['description'] = array( + '#type' => 'textfield', + '#title' => t('Description'), + '#required' => TRUE, + '#maxlength' => 255, + '#description' => t('A short description of what this flexifilter does.'), + '#default_value' => $data['basic']['description'], + ); + $form['basic']['advanced'] = array( + '#type' => 'checkbox', + '#title' => t('Show advanced options'), + '#default_value' => $data['basic']['advanced'], + '#description' => t('Advanced options currently only include the processing step option, which allows you to place some components into the filtering preparation step. You should only do so if it is critical that they be performed in the preparation step rather than the processing step.'), + ); + $form['components'] = _flexifilter_filter_edit_form_components($data['components'], $data['components'], $data['basic']['advanced'] == 1); + $form['components']['id_prefix'] = array('#type' => 'hidden', '#value' => $data['components']['id_prefix']); + $form['components']['id_next'] = array('#type' => 'hidden', '#value' => $data['components']['id_next']); + $form['create'] = array( + '#type' => 'submit', + '#value' => $data['fid'] === 'new' ? t('Create') : t('Save'), + ); + $form['create_edit'] = array( + '#type' => 'submit', + '#value' => $data['fid'] === 'new' ? t('Create and edit') : t('Save and edit'), + ); + $form['#redirect'] = FALSE; + return $form; +} + +/** + * Generates an FAPI array for a component list + * + * @param $data FAPI values for the component list. Use flexifilter_filter_edit_components_data to + * convert a components array into coresponding FAPI values. + * @param $data_base FAPI values for the top-level component list + */ +function _flexifilter_filter_edit_form_components($data, $data_base, $show_advanced, $parent = 0, $indentation = 0) { + $components = array(); + $flexifilter_components = flexifilter_get_component_list(); + $form = array(); + foreach ($data as $key => $component) { + if (strncmp($key, $data_base['id_prefix'], strlen($data_base['id_prefix'])) == 0) { + $components[$key] = $component; + } + } + $weight = 0; + foreach ($components as $key => $component) { + $weight++; + $cid = str_replace($data_base['id_prefix'], '', $key); + $_component = $flexifilter_components[$component['class']]; + $form['labels'][] = array('#value' => theme('indentation', $indentation) . ''. $_component['label'] .''); + $form['keys'][] = array('#type' => 'hidden', '#value' => $key); + $form['cids'][] = array('#type' => 'textfield', '#attributes' => array('class' => 'flexifilter-cid'), '#value' => $cid); + $form['pids'][] = array('#type' => 'textfield', '#attributes' => array('class' => 'flexifilter-pid'), '#value' => $parent); + $form['weights'][] = array('#type' => 'weight', '#attributes' => array('class' => 'flexifilter-weight'), '#value' => $weight); + if (!isset($_component['contains_components']) || $_component['contains_components'] == FALSE) { + $form['comps'][] = array('#type' => 'markup', '#value' => ' tabledrag-leaf'); } else { - $condition['setting_'. $key] = $value; + $form['comps'][] = array('#type' => 'markup', '#value' => ''); + } + if (isset($component['components'])) { + $children = _flexifilter_filter_edit_form_components($component['components'], $data_base, $show_advanced, $cid, $indentation + 1); + foreach (array('labels', 'keys', 'cids', 'pids', 'weights', 'comps') as $key) { + foreach ($children[$key] as $value) { + $form[$key][] = $value; + } + } } } - return $condition; + if ($parent == 0) { + $form['#theme'] = 'flexifilter_admin_component_list'; + $form['#tree'] = TRUE; + } + return $form; +} + +function template_preprocess_flexifilter_admin_component_list(&$variables) { + $form = $variables['form']; + $table = array(); + foreach (array('labels', 'keys', 'cids', 'pids', 'weights', 'comps') as $index) { + foreach (element_children($form[$index]) as $key) { + $table[$key][substr($index, 0, -1)] = drupal_render($form[$index][$key]); + } + } + $variables['table'] = $table; +} + + +function flexifilter_admin_edit_component($form_state, $data) { + $components = flexifilter_get_component_list(); + $component = $components[$data['class']]; + $form['class'] = array( + '#type' => 'hidden', + '#value' => $data['class'], + ); + $form['settings']['#tree'] = TRUE; + $custom_elements = flexifilter_invoke_component($component, 'settings', $data['settings']); + if (is_array($custom_elements)) { + foreach ($custom_elements as $key => $element) { + $form['settings'][$key] = $element; + } + } + + return $form; } /** @@ -153,6 +316,34 @@ function flexifilter_filter_edit_compone return $data; } +//----------------------------------------------------------------------------------------------------------------- +//----------------------------------------------------------------------------------------------------------------- +//----------------------------- I AM NOT USING ANY FUNCTIONS BELOW THIS POINT! ------------------------------------ +//----------------------------------------------------------------------------------------------------------------- +//----------------------------------------------------------------------------------------------------------------- + + +/** + * Helper function for flexifilter_filter_edit_components_data; converts a condition + * array from a flexifilter into a form data styled array. + */ +function flexifilter_filter_edit_condition_data($data) { + $condition = array( + 'class' => $data['class'], + ); + foreach ($data['settings'] as $key => $value) { + if ($key == 'conditions') { + foreach ($value as $cond_key => $cond_value) { + $condition['condition_'. $cond_key] = flexifilter_filter_edit_condition_data($cond_value); + } + } + else { + $condition['setting_'. $key] = $value; + } + } + return $condition; +} + /** * Creates an FAPI values array for a newly created component * @@ -283,288 +474,6 @@ function flexifilter_filter_edit_form_co } /** - * Helper function for flexifilter_filter_edit_form_components; generates an FAPI array for a - * single component. - */ -function flexifilter_filter_edit_form_component($data, $new_weight, $is_first, $is_last, &$data_base, $show_advanced) { - $components = flexifilter_get_component_list(); - $component = $components[$data['class']]; - $form = array( - '#type' => 'fieldset', - '#collapsible' => TRUE, - '#collapsed' => (isset($data['op']) || isset($data['op_c']) || isset($data['is_new'])) ? FALSE : TRUE, - '#tree' => TRUE, - '#title' => $component['label'], - '#description' => $component['description'], - ); - $form['class'] = array( - '#type' => 'hidden', - '#value' => $data['class'], - ); - $form['weight'] = array( - '#type' => 'hidden', - '#value' => $new_weight, - ); - $custom_settings = array(); - foreach ($data as $key => $value) { - if (strncmp($key, 'setting_', 8) == 0) { - $custom_settings[substr($key, 8)] = $value; - } - } - $custom_elements = flexifilter_invoke_component($component, 'settings', $custom_settings); - if (is_array($custom_elements)) { - foreach ($custom_elements as $key => $element) { - $form['setting_'. $key] = $element; - } - } - if ($component['is_container']) { - if ($component['contains_condition']) { - if (isset($data['op_c'])) { - $data['condition'] = flexifilter_filter_edit_form_new_condition_data($data['set_condition']); - } - if (isset($data['condition']) && isset($data['condition']['op'])) { - $data['condition'] = array( - 'class' => '', - ); - $form['#collapsed'] = FALSE; - } - $form['condition'] = flexifilter_filter_edit_form_condition($data['condition'], $show_advanced); - if ($form['condition']['#collapsed'] == FALSE) { - $form['#collapsed'] = FALSE; - } - $conditions = flexifilter_get_condition_list($show_advanced); - $form['set_condition'] = array( - '#type' => 'select', - '#title' => t('Change condition'), - '#options' => flexifilter_get_grouped_labels($conditions), - '#description' => t('Changes the condition assocated with this component.'), - ); - $form['op_c'] = array( - '#type' => 'submit', - '#value' => t('Change'), - '#process' => array('flexifilter_undo_submit_default_name', 'form_expand_ahah'), - ); - } - if ($component['contains_components']) { - $form['components'] = flexifilter_filter_edit_form_components($data['components'], $data_base, $show_advanced); - if ($form['components']['#collapsed'] == FALSE) { - $form['#collapsed'] = FALSE; - } - } - } - if ($component['step'] == 'either') { - if ($show_advanced) { - $form['step'] = array( - '#type' => 'select', - '#title' => t('Step'), - '#options' => array( - 'process' => t('Processing'), - 'prepare' => t('Preparation'), - ), - '#description' => t('The filtering step to perform this action in.'), - '#default_value' => $data['step'], - ); - } - else { - $form['step'] = array( - '#type' => 'hidden', - '#value' => $data['step'], - ); - } - } - $form['move'] = array( - '#type' => 'select', - '#title' => t('Re/move this'), - '#options' => array(), - // If the element at the bottom is moved to the top, then the #value of 'top' will no longer be in the downdown - // and the FAPI throws a nasty validation error. Hence mark it already validated and we will do our own validation. - '#validated' => true, - ); - if (!$is_first) { - $form['move']['#options']['top'] = t('Move to top'); - $form['move']['#options']['up'] = t('Move up'); - } - if (!$is_last) { - $form['move']['#options']['down'] = t('Move down'); - $form['move']['#options']['bottom'] = t('Move to bottom'); - } - $form['move']['#options']['remove'] = t('Remove'); - $form['op'] = array( - '#type' => 'submit', - '#value' => t('Re/move'), - '#process' => array('flexifilter_undo_submit_default_name', 'form_expand_ahah'), - ); - - return $form; -} - -/** - * Helper function; sorts components by weight. - */ -function _flexifilter_components_sort_weight($a, $b) { - return ((float)$a['weight']) > ((float)$b['weight']); -} - -/** - * Generates an FAPI array for a component list - * - * @param $data FAPI values for the component list. Use flexifilter_filter_edit_components_data to - * convert a components array into coresponding FAPI values. - * @param $data_base FAPI values for the top-level component list - */ -function flexifilter_filter_edit_form_components($data, &$data_base, $show_advanced) { - $form = array( - '#type' => 'fieldset', - '#title' => t('Components'), - '#collapsed' => TRUE, - '#collapsible' => TRUE, - '#tree' => TRUE, - ); - $components = array(); - foreach ($data as $key => $component) { - if (strncmp($key, $data_base['id_prefix'], strlen($data_base['id_prefix'])) == 0) { - $components[$key] = $component; - } - } - if (isset($data['op'])) { - $components[$data_base['id_prefix'] . $data_base['id_next']] = flexifilter_filter_edit_form_new_component_data($data['new_list']); - $data_base['id_next'] = $data_base['id_next'] + 1; - } - foreach ($components as $key => $component) { - if (isset($component['op'])) { - switch ($component['move']) { - /* - Careful; this component is NOT VALIDATED by the FAPI. We only act upon certain - values ('top', 'up', 'down', 'bottom', 'remove'), which are always valid (even - if they have no effect). Other values are silently ignored. - */ - - case 'top': - $components[$key]['weight'] = -1000; - break; - - case 'up': - $components[$key]['weight'] = $component['weight'] - 1.5; - break; - - case 'down': - $components[$key]['weight'] = $component['weight'] + 1.5; - break; - - case 'bottom': - $components[$key]['weight'] = 10001; - break; - - case 'remove': - unset($components[$key]); - break; - } - $form['#collapsed'] = FALSE; - } - } - uasort($components, '_flexifilter_components_sort_weight'); - $new_weight = 0; - $last_component_weight = count($components); - foreach ($components as $key => $component) { - $new_weight = $new_weight + 1; - $form[$key] = flexifilter_filter_edit_form_component($component, $new_weight, $new_weight == 1, $new_weight == $last_component_weight, $data_base, $show_advanced); - if ($form[$key]['#collapsed'] == FALSE) { - $form['#collapsed'] = FALSE; - } - } - $form['new_list'] = array( - '#type' => 'select', - '#options' => flexifilter_get_grouped_labels(flexifilter_get_component_list($show_advanced)), - '#title' => t('Add component'), - ); - $form['op'] = array( - '#type' => 'submit', - '#value' => t('Add'), - '#process' => array('flexifilter_undo_submit_default_name', 'form_expand_ahah'), - ); - return $form; -} - -/** - * The add/edit form for flexifilters. - */ -function flexifilter_filter_edit_form($form_state, $flexifilter = 'new') { - if (!isset($form_state['post']) || !isset($form_state['post']['fid'])) { - $data = array(); - $data['fid'] = $flexifilter === 'new' ? 'new' : $flexifilter['id']; - $data['basic'] = array(); - $data['basic']['label'] = $flexifilter === 'new' ? '' : $flexifilter['label']; - $data['basic']['description'] = $flexifilter === 'new' ? '' : $flexifilter['description']; - $data['basic']['advanced'] = $flexifilter === 'new' ? 0 : $flexifilter['advanced']; - $data['components'] = $flexifilter === 'new' ? array() : flexifilter_filter_edit_components_data($flexifilter['components']); - if (!isset($data['components']['id_prefix']) || $data['components']['id_prefix'] === 'component_new_') { - $data['components']['id_prefix'] = 'component_'. $data['fid'] .'_'; - } - if (!isset($data['components']['id_next'])) { - $data['components']['id_next'] = 0; - } - $expand_root_levels = TRUE; - } - else { - $data = $form_state['post']; - if (!isset($data['basic']['advanced'])) { - $data['basic']['advanced'] = 0; - } - } - $form = array(); - $form['fid'] = array( - '#type' => 'hidden', - '#value' => $data['fid'], - ); - $form['basic'] = array( - '#type' => 'fieldset', - '#title' => t('Basic settings'), - '#collapsed' => TRUE, - '#collapsible' => TRUE, - '#tree' => TRUE, - ); - $form['basic']['label'] = array( - '#type' => 'textfield', - '#title' => t('Label'), - '#required' => TRUE, - '#maxlength' => 127, - '#description' => t('Choose an appropriate label for this flexifilter.'), - '#default_value' => $data['basic']['label'], - ); - $form['basic']['description'] = array( - '#type' => 'textfield', - '#title' => t('Description'), - '#required' => TRUE, - '#maxlength' => 255, - '#description' => t('A short description of what this flexifilter does.'), - '#default_value' => $data['basic']['description'], - ); - $form['basic']['advanced'] = array( - '#type' => 'checkbox', - '#title' => t('Show advanced options'), - '#default_value' => $data['basic']['advanced'], - '#description' => t('Advanced options currently only include the processing step option, which allows you to place some components into the filtering preparation step. You should only do so if it is critical that they be performed in the preparation step rather than the processing step.'), - ); - $form['components'] = flexifilter_filter_edit_form_components($data['components'], $data['components'], $data['basic']['advanced'] == 1); - $form['components']['id_prefix'] = array('#type' => 'hidden', '#value' => $data['components']['id_prefix']); - $form['components']['id_next'] = array('#type' => 'hidden', '#value' => $data['components']['id_next']); - if (isset($expand_root_levels) && $expand_root_levels) { - $form['basic']['#collapsed'] = FALSE; - $form['components']['#collapsed'] = FALSE; - } - $form['submit1'] = array( - '#type' => 'submit', - '#value' => $data['fid'] === 'new' ? t('Create') : t('Save'), - ); - $form['submit2'] = array( - '#type' => 'submit', - '#value' => $data['fid'] === 'new' ? t('Create and edit') : t('Save and edit'), - ); - $form['#redirect'] = FALSE; - return $form; -} - -/** * Helper function for flexifilter_filter_edit_form_components_from_data; converts a condition's * FAPI values back into a condition array. */ @@ -728,42 +637,6 @@ function flexifilter_filter_delete_form_ $form_state['redirect'] = 'admin/build/flexifilters'; } -function flexifilter_filter_disable_form($form_state, $flexifilter) { - $form = array(); - $form['fid'] = array('#type' => 'hidden', '#value' => $flexifilter['id']); - - return confirm_form($form, t('Are you sure you want to disable the flexifilter "%flexifilter"?', array('%flexifilter' => $flexifilter['label'])), 'admin/build/flexifilters', t('If you disable the flexifilter, then it cannot be used in any Input Formats.'), t('Disable'), t('Cancel')); -} - -function flexifilter_filter_disable_form_submit($form, &$form_state) { - $fid = $form_state['values']['fid']; - $filters = flexifilter_get_filters(); - $filter = $filters[$fid]; - if ($filter['enabled']) { - flexifilter_remove_from_filters($filter['delta']); - db_query('UPDATE {flexifilters} SET enabled = 0 WHERE fid = %d', $fid); - drupal_set_message(t('Flexifilter disabled.')); - } - $form_state['redirect'] = 'admin/build/flexifilters'; -} - -function flexifilter_filter_enable_form($form_state, $flexifilter) { - $form = array(); - $form['fid'] = array('#type' => 'hidden', '#value' => $flexifilter['id']); - - return confirm_form($form, t('Are you sure you want to enable the flexifilter "%flexifilter"?', array('%flexifilter' => $flexifilter['label'])), 'admin/build/flexifilters', t(''), t('Enable'), t('Cancel')); -} - -function flexifilter_filter_enable_form_submit($form, &$form_state) { - $fid = $form_state['values']['fid']; - $filters = flexifilter_get_filters(); - $filter = $filters[$fid]; - if (!$filter['enabled'] && flexifilter_get_number_enabled_filters() < FLEXIFILTER_MAX_FILTERS) { - db_query('UPDATE {flexifilters} SET enabled = 1, delta = %d WHERE fid = %d', flexifilter_get_unused_delta(), $fid); - drupal_set_message(t('Flexifilter enabled.')); - } - $form_state['redirect'] = 'admin/build/flexifilters'; -} function flexifilter_filter_export_form($form_state, $flexifilter) { $form = array(); @@ -847,4 +720,67 @@ function flexifilter_filter_default_form } flexifilter_install_flexifilters('flexifilter', $to_be_saved); $form_state['redirect'] = 'admin/build/flexifilters'; -} \ No newline at end of file +} + +function flexifilter_js($parameter = '') { + switch ($parameter) { + case 'list_form': + $form = _flexifilter_js(); + $output = '
'; + foreach (element_children($form) as $key) { + $output .= drupal_render($form[$key]); + } + drupal_json(array('status' => TRUE, 'data' => $output .'
')); + break; + case 'component_edit': + $flexifilter = flexifilter_load(arg(5)); + $component = flexifilter_js_find_component(arg(6), $flexifilter['components']); + exit(drupal_get_form('flexifilter_admin_edit_component', $component)); + break; + } +} + +function flexifilter_js_find_component($pid, $components) { + $component_final = FALSE; + foreach ($components as $component) { + if ($component['id'] == $pid) { + $component_final = $component; + } + elseif (isset($component['settings']['components']) && is_array($component['settings']['components'])) { + $component_child = flexifilter_js_find_component($pid, $component['settings']['components']); + if ($component_child != FALSE) { + $component_final = $component_child; + } + } + } + return $component_final; +} + +function _flexifilter_js() { + $form_state = array('storage' => NULL, 'submitted' => FALSE); + $form_build_id = $_POST['form_build_id']; + $form = form_get_cache($form_build_id, &$form_state); + // #parameters has $form_id, $form_state and then whatever was passed to + // drupal_get_form. + $args = $form['#parameters']; + $form_id = array_shift($args); + $form['#post'] = $_POST; + $form['#redirect'] = FALSE; + // This will set up $form_state['clicked_button'] and + // $form_state['storage']['mlid']. + drupal_process_form($form_id, $form, $form_state); + // Recreate and re-cache the form. + $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id); + // Pick up the parents of the pressed button. + $array_parents = $form_state['clicked_button']['#array_parents']; + // The last parent is the button itself, we need the wrapper instead. + $button_index = array_pop($array_parents); + while ($array_parents) { + $parent = array_shift($array_parents); + $form = $form[$parent]; + } + // Remove the button. + unset($form[$button_index]); + // Render messages and selects. + return $form; +} Index: flexifilter.components.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/flexifilter/flexifilter.components.inc,v retrieving revision 1.12 diff -u -p -r1.12 flexifilter.components.inc --- flexifilter.components.inc 22 Jan 2008 00:48:28 -0000 1.12 +++ flexifilter.components.inc 2 Feb 2008 19:55:22 -0000 @@ -21,7 +21,7 @@ function flexifilter_flexifilter_compone $components = array(); // If, While, etc. $components['flexifilter_control_if'] = array( - 'label' => t('If'), + 'label' => t('If statement'), 'description' => t('If and only if the condition is true, then the actions are performed.'), 'contains_condition' => TRUE, 'contains_components' => TRUE, @@ -30,7 +30,7 @@ function flexifilter_flexifilter_compone 'step' => 'both', ); $components['flexifilter_control_while'] = array( - 'label' => t('While'), + 'label' => t('While statement'), 'description' => t('While the condition is true, the actions are performed.'), 'contains_condition' => TRUE, 'contains_components' => TRUE, @@ -111,7 +111,7 @@ function flexifilter_flexifilter_compone // Chunks! $components['flexifilter_chunk_grab'] = array( - 'label' => t('Chunk grabber.'), + 'label' => t('Chunk grabber'), 'description' => t('Grabs chunks of text for further filtering and then sticks the filtered version back into the text.'), 'callback' => 'flexifilter_component_chunk_grab', 'group' => t('Chunks'), Index: flexifilter.css =================================================================== RCS file: flexifilter.css diff -N flexifilter.css --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ flexifilter.css 2 Feb 2008 19:55:22 -0000 @@ -0,0 +1,10 @@ +#flexifilter-components { + width: 49%; + float: left; +} +#flexifilter-component-settings { + width: 49%; + float: right; + padding-left: 10px; + margin-top: 10px; +} \ No newline at end of file Index: flexifilter.js =================================================================== RCS file: flexifilter.js diff -N flexifilter.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ flexifilter.js 2 Feb 2008 19:55:22 -0000 @@ -0,0 +1,19 @@ +(function($) { + $(function() { + $('#flexifilter-components tbody tr').each(function() { + $(this).find('td:first').bind('click', function() { + component_id = $(this).parent().find('td:last .flexifilter-cid').val(); + $('#flexifilter-components tbody tr').removeClass('flexifilter-component-highlighted'); + $.scrollTo($('#flexifilter-component-settings').offset().top - 10, 'slow'); + $('#flexifilter-component-settings').load(Drupal.settings.basePath +'admin/build/flexifilters/js/component_edit/'+ Drupal.settings.flexifilterFid +'/'+ component_id, function() { + Drupal.attachBehaviors($(this)); + $(this).css('background-color', '#FCFF97'); + $(this).animate({ 'background-color': '#ffffff' }, 'slow'); + }); + return false; + }); + }); + }); + // This is only when flexifilter.inc is included + Drupal.theme.prototype.tableDragChangedWarning = function() {}; +})(jQuery); \ No newline at end of file Index: flexifilter.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/flexifilter/flexifilter.module,v retrieving revision 1.14 diff -u -p -r1.14 flexifilter.module --- flexifilter.module 23 Jan 2008 22:43:16 -0000 1.14 +++ flexifilter.module 2 Feb 2008 19:55:23 -0000 @@ -21,7 +21,7 @@ function flexifilter_menu() { 'description' => t('Create new flexible input filters without writing any code.'), 'page callback' => 'drupal_get_form', 'access arguments' => array('administer flexifilter'), - 'page arguments' => array('flexifilter_filter_list_form'), + 'page arguments' => array('flexifilter_admin_list_form'), 'file' => 'flexifilter.admin.inc', ); $items['admin/build/flexifilters/list'] = array( @@ -57,7 +57,7 @@ function flexifilter_menu() { 'title arguments' => array(3, 'label'), 'type' => MENU_CALLBACK, 'page callback' => 'drupal_get_form', - 'page arguments' => array('flexifilter_filter_edit_form', 3), + 'page arguments' => array('flexifilter_admin_edit_form', 3), 'file' => 'flexifilter.admin.inc', ); $items['admin/build/flexifilters/%flexifilter/edit'] = array( @@ -78,23 +78,23 @@ function flexifilter_menu() { 'page arguments' => array('flexifilter_filter_delete_form', 3), 'file' => 'flexifilter.admin.inc', ); - $items['admin/build/flexifilters/%flexifilter/enable'] = array( - 'title' => t('Enable'), + $items['admin/build/flexifilters/js'] = array( + 'title' => t('JavaScript Callback'), 'type' => MENU_CALLBACK, - 'page callback' => 'drupal_get_form', - 'page arguments' => array('flexifilter_filter_enable_form', 3), - 'file' => 'flexifilter.admin.inc', - ); - $items['admin/build/flexifilters/%flexifilter/disable'] = array( - 'title' => t('Disable'), - 'type' => MENU_CALLBACK, - 'page callback' => 'drupal_get_form', - 'page arguments' => array('flexifilter_filter_disable_form', 3), + 'page callback' => 'flexifilter_js', 'file' => 'flexifilter.admin.inc', ); return $items; } +function flexifilter_theme() { + return array( + 'flexifilter_admin_list' => array('template' => 'flexifilter-admin-list', 'file' => 'flexifilter.admin.inc', 'arguments' => array('form' => NULL)), + 'flexifilter_admin_component_list' => array('template' => 'flexifilter-admin-component-list', 'file' => 'flexifilter.admin.inc', 'arguments' => array('form' => NULL)), + 'flexifilter_filter_admin_form' => array('file' => 'flexifilter.admin.inc', 'arguments' => array('form' => NULL)), + ); +} + /** * Implementation of hook_help() */ Index: jquery.scrollTo.js =================================================================== RCS file: jquery.scrollTo.js diff -N jquery.scrollTo.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ jquery.scrollTo.js 2 Feb 2008 19:55:23 -0000 @@ -0,0 +1,142 @@ +/** + * jQuery.ScrollTo + * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com + * Licensed under GPL license (http://www.opensource.org/licenses/gpl-license.php). + * Date: 1/2/2008 + * + * @projectDescription Easy element scrolling using jQuery. + * Tested with jQuery 1.2.1. On FF 2.0.0.11, IE 6, Opera 9.22 and Safari 3 beta. on Windows. + * + * @author Ariel Flesler + * @version 1.3 + * + * @id jQuery.scrollTo + * @id jQuery.fn.scrollTo + * @param {String, Number, DOMElement, jQuery, Object} target Where to scroll the matched elements. + * The different options for target are: + * - A number position (will be applied to all axes). + * - A string position ('44', '100px', '+=90', etc ) will be applied to all axes + * - A jQuery/DOM element ( logically, child of the element to scroll ) + * - A string selector, that will be relative to the element to scroll ( 'li:eq(2)', etc ) + * - A hash { top:x, left:y }, x and y can be any kind of number/string like above. + * @param {Number} duration The OVERALL length of the animation, this argument can be the settings object instead. + * @param {Object} settings Hash of settings, optional. + * @option {String} axis Which axis must be scrolled, use 'x', 'y', 'xy' or 'yx'. + * @option {Number} duration The OVERALL length of the animation. + * @option {String} easing The easing method for the animation. + * @option {Boolean} margin If true, the margin of the target element will be deducted from the final position. + * @option {Object, Number} offset Add/deduct from the end position. One number for both axis or { top:x, left:y } + * @option {Boolean} queue If true, and both axis are given, the 2nd axis will only be animated after the first one ends. + * @option {Function} onAfter Function to be called after the scrolling ends. + * @option {Function} onAfterFirst If queuing is activated, this function will be called after the first scrolling ends. + * @return {jQuery} Returns the same jQuery object, for chaining. + * + * @example $('div').scrollTo( 340 ); + * + * @example $('div').scrollTo( '+=340px', { axis:'y' } ); + * + * @example $('div').scrollTo( 'p.paragraph:eq(2)', 500, { easing:'swing', queue:true, axis:'xy' } ); + * + * @example var second_child = document.getElementById('container').firstChild.nextSibling; + * $('#container').scrollTo( second_child, { duration:500, axis:'x', onAfter:function(){ + * alert('scrolled!!'); + * }}); + * + * @example $('div').scrollTo( { top: 300, left:'+=200' }, { offset:-20 } ); + * + * Notes: + * - jQuery.scrollTo will make the whole window scroll, it accepts the same parameters as jQuery.fn.scrollTo. + * - The plugin no longer requires Dimensions. + * - If you are interested in animated anchor navigation, check http://jquery.com/plugins/project/LocalScroll. + * - The option 'margin' won't be valid, if the target is not a jQuery object or a DOM element. + * - The option 'queue' won't be taken into account, if only 1 axis is given. + */ +;(function( $ ){ + + $.scrollTo = function( target, duration, settings ){ + $( $.browser.safari ? 'body' : 'html' ).scrollTo( target, duration, settings ); + }; + + $.scrollTo.defaults = { + axis:'y', + duration:1 + }; + + $.fn.scrollTo = function( target, duration, settings ){ + if( typeof duration == 'object' ){ + settings = duration; + duration = 0; + } + settings = $.extend( {}, $.scrollTo.defaults, settings ); + if( !duration ) + duration = settings.speed || settings.duration;//backward compatibility fix + settings.queue = settings.queue && settings.axis.length == 2;//make sure the settings are given right + if( settings.queue ) + duration = Math.ceil( duration / 2 );//let's keep the overall speed, the same. + if( typeof settings.offset == 'number' ) + settings.offset = { left: settings.offset, top: settings.offset }; + + return this.each(function(){ + var elem = this, $elem = $(elem), + t = target, toff, attr = {}, + win = $elem.is('html,body'); + switch( typeof t ){ + case 'number'://will pass the regex + case 'string': + if( /^([+-]=)?\d+(px)?$/.test(t) ){ + t = { top:t, left:t }; + break;//we are done + } + t = $(t,this);// relative selector, no break! + case 'object': + if( t.is || t.style )//DOM/jQuery + toff = (t = $(t)).offset();//get the real position of the target + } + $.each( settings.axis.split(''), parse ); + animate( settings.onAfter ); + + function parse( i, axis ){ + var Pos = axis == 'x' ? 'Left' : 'Top', + pos = Pos.toLowerCase(), + key = 'scroll' + Pos, + act = elem[key]; + + if( toff ){//jQuery/DOM + attr[key] = toff[pos] + ( win ? 0 : act - $elem.offset()[pos] ); + + if( settings.margin ){//if it's a dom element, reduce the margin + attr[key] -= parseInt(t.css('margin'+Pos)) || 0; + attr[key] -= parseInt(t.css('border'+Pos+'Width')) || 0; + } + + if( settings.offset && settings.offset[pos] ) + attr[key] += settings.offset[pos]; + }else{ + attr[key] = t[pos]; + } + + if( /^\d+$/.test(attr[key]) ) + attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max(axis) );//check the limits + + if( !i && settings.queue ){//queueing each axis is required + if( act != attr[key] )//don't waste time animating, if there's no need. + animate( settings.onAfterFirst );//intermediate animation + delete attr[key];//don't animate this axis again in the next iteration. + } + }; + + function animate( callback ){ + $elem.animate( attr, duration, settings.easing, function(){ + if( callback ) + callback.call(this, $elem, attr, t ); + }); + }; + function max( axis ){ + var el = win ? $.browser.opera ? document.body : document.documentElement : elem, + Dim = axis == 'x' ? 'Width' : 'Height'; + return el['scroll'+Dim] - el['client'+Dim]; + }; + }); + }; + +})( jQuery ); \ No newline at end of file