You are here

function uc_ajax_cart_block in Ubercart AJAX Cart 5

Same name and namespace in other branches
  1. 6.2 uc_ajax_cart.module \uc_ajax_cart_block()
  2. 6 uc_ajax_cart.module \uc_ajax_cart_block()

File

./uc_ajax_cart.module, line 43

Code

function uc_ajax_cart_block($op = 'list', $delta = 0, $edit = array()) {
  if ($op == 'list') {
    $blocks[0]['info'] = t('Ubercart ajax shopping cart');
    return $blocks;
  }
  elseif ($op == 'view') {
    $content = uc_cart_block($op, $delta, $edit);
    $content['content'] = '<div id="ajaxCartUpdate">' . $content['content'] . '</div>';
    return $content;
  }
  elseif ($op == 'configure') {
    $form = uc_cart_block($op, $delta, $edit);
    $form['ajaxSettings'] = array(
      '#type' => 'fieldset',
      '#collapsed' => false,
      '#title' => t('Ajax Cart Options'),
      '#description' => t('Set some options for Ajax Cart.'),
    );
    $form['ajaxSettings']['loadForm'] = array(
      '#type' => 'checkbox',
      '#return_value' => 1,
      '#title' => t('Load form.js from module directory.'),
      '#description' => t('Disabled if you load your own javascript for forms.'),
      '#default_value' => variable_get('uc_ajax_cart_js_load', 1),
    );

    /*
     * @todo not tested
    $form['ajaxSettings']['alternateJS'] = array(
        '#type' => 'textfield',
        '#title' => t('Load form.js from this location.'),
        '#description' => t('Load jQuery form handler from a different location.'),
        '#default_value' => variable_get('uc_ajax_cart_js_src', "")
    );
    */
    $form['ajaxSettings']['buttonDisable'] = array(
      '#type' => 'checkbox',
      '#return_value' => 1,
      '#title' => t('Disable button on ajax call.'),
      '#description' => t("Disable the button , so you don't have multiple requests.' "),
      '#default_value' => variable_get('uc_ajax_cart_button_disable', 1),
    );
    $form['ajaxSettings']['alternateText'] = array(
      '#type' => 'textfield',
      '#title' => t('Change button text.'),
      '#default_value' => variable_get('uc_ajax_cart_button_txt', ""),
    );
    $form['ajaxSettings']['alternateButtonClass'] = array(
      '#type' => 'textfield',
      '#title' => t('Button class for an ajax call.'),
      '#description' => t('Giving the button this class for request time.'),
      '#default_value' => variable_get('uc_ajax_cart_button_class', ""),
    );
    $form['ajaxSettings']['alternateTextCart'] = array(
      '#type' => 'textfield',
      '#title' => t('Change button text for products already in cart.'),
      '#description' => t('Be aware does not work with attributes!'),
      '#default_value' => variable_get('uc_ajax_cart_button_c', ""),
    );
    $form['#submit'] = array_merge(array(
      'uc_ajax_cart_block_submit' => array(),
    ), (array) $form['#submit']);
    return $form;
  }
  elseif ($op == 'save' && isset($edit['uc_cart_block_empty_hide'])) {
    variable_set('uc_ajax_cart_js_load', $edit['loadForm']);
    variable_set('uc_ajax_cart_js_src', $edit['alternateJS']);
    variable_set('uc_ajax_cart_button_txt', $edit['alternateText']);
    variable_set('uc_ajax_cart_button_c', $edit['alternateTextCart']);
    variable_set('uc_ajax_cart_button_class', $edit['alternateButtonClass']);
    variable_set('uc_ajax_cart_button_disable', $edit['buttonDisable']);
    uc_cart_block($op, $delta, $edit);
  }
}