diff --git a/salsa_advocacy/salsa_advocacy.module b/salsa_advocacy/salsa_advocacy.module index bc03b62..2da19c2 100644 --- a/salsa_advocacy/salsa_advocacy.module +++ b/salsa_advocacy/salsa_advocacy.module @@ -181,6 +181,21 @@ function salsa_advocacy_petition_form($form, &$form_state, $action) { } $action_content_detail = entity_load('salsa_action_content_detail', FALSE, array('action_content_KEY' => $action_content->action_content_KEY)); $action_content_detail = reset($action_content_detail); + + // Check if progress bar is enabled. + if (!empty($action->Signature_Goal) && $action->Signatures != 'Do not show signatures') { + // Add the progress bar. + salsa_entity_add_progress_bar( + $action, + $form_state['build_info']['form_id'], + salsa_advocacy_get_supporter_actions_total($action), + $action->Signature_Goal, + $form + ); + } + // Set weight in order to display on top of supporter fieldset. + $form['progress']['#weight'] = -200; + if ($action_content_detail->Recommended_Content) { // @todo For some reason petition content are highlighted on public page, // so I added the prefix and suffix, but it can be removed if there is no need. @@ -344,6 +359,9 @@ function salsa_advocacy_petition_form_submit($form, &$form_state) { // Create a new one or update existing supporter. salsa_entity_supporter_fieldset_submit($form, $form_state); + // Clear the cached count of supporter actions on this action. + cache_clear_all('salsa_advocacy_supporter_action_count:' . $form_state['salsa_object']->action_KEY, 'cache'); + // Save comments, if any. if (!empty($form_state['values']['Comment'])) { $supporter_action_comment = new SalsaEntity(array(), 'salsa_supporter_action_comment'); @@ -506,17 +524,14 @@ function salsa_advocacy_targeted_form($form, &$form_state, $action) { } // Check if progress bar is enabled. - $field_key = variable_get('salsa_advocacy_goal_field'); + $field_key = variable_get('salsa_advocacy_targeted_goal_field'); if (!empty($action->{$field_key})) { - // Add the progress bar. - $form['progress'] = array( - '#markup' => salsa_entity_get_progress_bar( - $action, - $form_state['build_info']['form_id'], - salsa_advocacy_get_supporter_actions_total($action), - $field_key, - $form - ), + salsa_entity_add_progress_bar( + $action, + $form_state['build_info']['form_id'], + salsa_advocacy_get_supporter_actions_total($action), + $action->{$field_key}, + $form ); } @@ -1101,12 +1116,12 @@ function salsa_advocacy_settings_form($form, &$form_state) { foreach ($custom_fields as $field_name => $field) { $options[$field_name] = $field['label']; } - $form['progress']['salsa_advocacy_goal_field'] = array( + $form['progress']['ssalsa_advocacy_targeted_goal_field'] = array( '#type' => 'select', '#title' => t('Salsa Advocacy Goal Field'), '#description' => t('Salsa custom field that contains the submission goal for actions.'), '#options' => $options, - '#default_value' => variable_get('salsa_advocacy_goal_field'), + '#default_value' => variable_get('salsa_advocacy_targeted_goal_field'), '#empty_option' => t('- None -'), ); } @@ -1233,8 +1248,8 @@ function salsa_advocacy_settings_form_submit($form, &$form_state) { variable_set('salsa_advocacy_custom_fields', $custom_fields_settings); } - // Set the field for the barometer goal. - variable_set('salsa_advocacy_goal_field', $form_state['values']['salsa_advocacy_goal_field']); + // Set the field for the barometer goal targeted actions. + variable_set('salsa_advocacy_targeted_goal_field', $form_state['values']['salsa_advocacy_targeted_goal_field']); cache_clear_all('salsa_advocacy_mapping', 'cache'); cache_clear_all('salsa_advocacy_filters', 'cache'); diff --git a/salsa_donate_page/salsa_donate_page.module b/salsa_donate_page/salsa_donate_page.module index d710d74..5596d49 100644 --- a/salsa_donate_page/salsa_donate_page.module +++ b/salsa_donate_page/salsa_donate_page.module @@ -78,12 +78,12 @@ function salsa_donate_page_mollom_form_info($form_id) { } /** - * Implements hook_salsa_entity_progres_bar_labels(). + * Implements hook_salsa_entity_progress_bar_labels(). * * Add currencies to the amounts and change the labels of the donation progress * bar. */ -function salsa_donate_page_salsa_entity_progres_bar_labels(&$labels) { +function salsa_donate_page_salsa_entity_progress_bar_labels(&$labels) { $labels['goal'] = salsa_entity_get_amount($labels['goal'], TRUE); $labels['total'] = salsa_entity_get_amount($labels['total'], TRUE); $labels['goal_label'] = t('Donation goal:'); @@ -213,14 +213,12 @@ function salsa_donate_page_form($form, &$form_state, $donate_page, $view_mode) { $field_key = variable_get('salsa_donations_goal_field'); if (!empty($donate_page->{$field_key})) { - $form['Donation']['progress'] = array( - '#markup' => salsa_entity_get_progress_bar( - $donate_page, - $form_state['build_info']['form_id'], - salsa_donate_page_total_donation_amount($donate_page->donate_page_KEY), - $field_key, - $form - ), + salsa_entity_add_progress_bar( + $donate_page, + $form_state['build_info']['form_id'], + salsa_donate_page_total_donation_amount($donate_page->donate_page_KEY), + $donate_page->{$field_key}, + $form ); } diff --git a/salsa_entity.module b/salsa_entity.module index 88b67aa..57598ba 100644 --- a/salsa_entity.module +++ b/salsa_entity.module @@ -866,15 +866,7 @@ function salsa_entity_filter_info() { * @return string * The markup for the barometer. */ -function salsa_entity_get_progress_bar($salsa_object, $barometer_type, $total, $goal_field_key, &$form) { - // Add the progress bar CSS to the requesting form. - $form['#attached']['css'] = array( - array( - 'data' => drupal_get_path('module', 'salsa_entity') . '/theme/salsa_progress_bar.css' - ), - ); - - $goal = !empty($salsa_object->{$goal_field_key}) ? $salsa_object->{$goal_field_key} : NULL; +function salsa_entity_add_progress_bar($salsa_object, $barometer_type, $total, $goal, &$container) { // Don't allow rendering of progress bar without values that make sense. if (!$total && !$goal) { return ''; @@ -890,17 +882,26 @@ function salsa_entity_get_progress_bar($salsa_object, $barometer_type, $total, $ 'goal_label' => t('Goal'), 'total_label' => t('Total'), ); - drupal_alter('salsa_entity_progres_bar_labels', $labels); - - // Theme the progress bar with the collected values. - return theme('salsa_entity_progress_bar', array( - 'goal' => $labels['goal'], - 'goal_label' => $labels['goal_label'], - 'total' => $labels['total'], - 'total_label' => $labels['total_label'], - 'value' => min(round($value * 100), 100), - 'barometer_type' => $barometer_type, - )); + drupal_alter('salsa_entity_progress_bar_labels', $labels); + + // Add the progress bar CSS to the requesting form. + $container['#attached']['css'] = array( + array( + 'data' => drupal_get_path('module', 'salsa_entity') . '/theme/salsa_progress_bar.css' + ), + ); + + // Theme the progress bar with the collected values and add it to the form. + $container['progress'] = array( + '#markup' => theme('salsa_entity_progress_bar', array( + 'goal' => $labels['goal'], + 'goal_label' => $labels['goal_label'], + 'total' => $labels['total'], + 'total_label' => $labels['total_label'], + 'value' => min(round($value * 100), 100), + 'barometer_type' => $barometer_type, + )), + ); } /**