You are here

function _jeditable_ajax_load in jEditable inline content editing 6

Same name and namespace in other branches
  1. 6.2 jeditable.module \_jeditable_ajax_load()
  2. 7 jeditable.module \_jeditable_ajax_load()

Helper function to load a list of select values

1 string reference to '_jeditable_ajax_load'
jeditable_menu in ./jeditable.module
Implementation of hook_menu()

File

./jeditable.module, line 420
jeditable.module

Code

function _jeditable_ajax_load() {

  // Retrieve the values needed from the post to this page
  $array = explode('-', $_GET['id']);
  list($type, $id, $field_name) = $array;
  switch ($type) {
    case 'node':

      /** Not Implemented yet. This is a test case scenario for editing things such as a Node title **/
      $node = node_load($id);
      $value = $node->{$field};
      $value = 'Y';
      $defaults = array(
        'E' => 'Letter E',
        'M' => 'Letter M',
        'Y' => 'Letter Y',
      );
      $defaults['selected'] = $value;
      $defaults = json_encode($defaults);
      break;
    case 'cck':
      $node = node_load($id);
      $field = content_fields($field_name, $node->type);
      switch ($field['type']) {
        case 'nodereference':
          $defaults = _jeditable_get_node_reference_field_values($field);
          $defaults['selected'] = $node->{$field_name}[0]['nid'];
          $defaults = json_encode($defaults);
          break;
        case 'userreference':
          $defaults = _jeditable_get_user_reference_field_values($field);
          $defaults['selected'] = $node->{$field_name}[0]['uid'];
          $defaults = json_encode($defaults);
          break;
        case 'datetime':
          $date = new DateTime($node->{$field_name}[0]['value']);
          $date_format = date_limit_format(date_input_format(NULL, $field), $field['granularity']);
          $defaults = date_format_date($date, 'custom', $date_format);
          break;
        case 'number_decimal':
        case 'number_integer':
        case 'text':
          switch ($field['widget']['type']) {
            case 'optionwidgets_buttons':
            case 'optionwidgets_select':
              $defaults = array_values(optionwidgets_options($field));
              $defaults['selected'] = $node->{$field_name}[0]['value'];
              $defaults = json_encode($defaults);
              break;
            default:
              $defaults = $node->{$field_name}[0]['value'];
              break;
          }
          break;
        default:
          $defaults = $node->{$field_name}[0]['value'];
          break;
      }
      break;
    case 'workflow':

      /** Load the workflow states available to the current user **/
      $node = node_load($id);
      $defaults = json_encode(_jeditable_workflow_load($node, $field_name));
  }
  print $defaults;
  exit;
}