Index: editablefields.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/editablefields/editablefields.module,v
retrieving revision 1.3.2.17.2.12
diff -u -p -r1.3.2.17.2.12 editablefields.module
--- editablefields.module	26 Mar 2010 11:35:22 -0000	1.3.2.17.2.12
+++ editablefields.module	16 Jun 2010 18:07:11 -0000
@@ -80,8 +80,7 @@ function editablefields_field_formatter_
  * Theme the editable field.
  */
 function theme_editablefields_formatter_editable($element) {
-  static $js_ready;
-
+  
   $field_name = $element['#field_name'];
   $field = content_fields($field_name);
 //  $node = $element['#node'];
@@ -104,20 +103,9 @@ function theme_editablefields_formatter_
   else {
     $formatter_name = 'default';
     if ($formatter = _content_get_formatter($formatter_name, $field['type'])) {
-      if (!isset($js_ready)) {
-        $js_ready = TRUE;
-        drupal_add_js('misc/jquery.form.js');
-        drupal_add_js(drupal_get_path('module', 'editablefields') . '/editablefields.js');
-        drupal_add_css(drupal_get_path('module', 'editablefields') . '/editablefields.css');
-
-        $settings = array(
-          'url_html' => url('editablefields_html', array('absolute' => TRUE)),
-          'url_submit' => url('editablefields_submit', array('absolute' => TRUE)),
-          'url_view' => url('editablefields_view', array('absolute' => TRUE)),
-          'clicktoedit_message' => '<div class="editablefields_clicktoedit_message">'. t('[edit]') .'</div>',
-        );
-        drupal_add_js(array('editablefields' => $settings), 'setting');
-      }
+      // Load required javascripts.
+      editablefields_load_js();
+      
       $theme = $formatter['module'] . '_formatter_' . $formatter_name;
       $class = "editablefields";
       if ($element['#formatter'] == 'clicktoedit') {
@@ -151,6 +139,28 @@ function theme_editablefields_formatter_
 }
 
 /**
+ * Load required javascripts.
+ */
+function editablefields_load_js() {
+  static $js_ready;
+
+  if (!isset($js_ready)) {
+    $js_ready = TRUE;
+    drupal_add_js('misc/jquery.form.js');
+    drupal_add_js(drupal_get_path('module', 'editablefields') . '/editablefields.js');
+    drupal_add_css(drupal_get_path('module', 'editablefields') . '/editablefields.css');
+
+    $settings = array(
+      'url_html' => url('editablefields_html', array('absolute' => TRUE)),
+      'url_submit' => url('editablefields_submit', array('absolute' => TRUE)),
+      'url_view' => url('editablefields_view', array('absolute' => TRUE)),
+      'clicktoedit_message' => '<div class="editablefields_clicktoedit_message">'. t('[edit]') .'</div>',
+    );
+    drupal_add_js(array('editablefields' => $settings), 'setting');
+  }
+}
+
+/**
  * Implementation of hook_forms().
  */
 function editablefields_forms() {
@@ -166,23 +176,45 @@ function editablefields_forms() {
  * Form builder callback.
  */
 function editablefields_form_builder(&$form_state, $node, $field_name, $delta) {
-  $field = content_fields($field_name);
+  if (strpos($field_name, 'field_') === 0) {
+    $field = content_fields($field_name);
+
+    $form = array('#node' => $node);
+  //  $form_state = array('values' => array($field['field_name'] => $default_value));
+    module_load_include('inc', 'content', 'includes/content.node_form');
+    $form['#field_info'] = array($field['field_name'] => $field);
+    $form = content_field_form($form, $form_state, $field, $delta);
+
+    unset($form[$field_name]['#title']);
+    if (is_array($form[$field_name][0]) && !is_array($form[$field_name][1])) {
+      unset($form[$field_name][0]['#title']);
+    }
+
+    $form['#field_info'] = array($field['field_name'] => $field);
+    $form['#pre_render'] = array('_editablefields_pre_render');
 
-  $form = array('#node' => $node);
-//  $form_state = array('values' => array($field['field_name'] => $default_value));
-  module_load_include('inc', 'content', 'includes/content.node_form');
-  $form['#field_info'] = array($field['field_name'] => $field);
-  $form = content_field_form($form, $form_state, $field, $delta);
-
-  unset($form[$field_name]['#title']);
-  if (is_array($form[$field_name][0]) && !is_array($form[$field_name][1])) {
-    unset($form[$field_name][0]['#title']);
+    return $form;
   }
+  else {
+    // Retrieve node form.
+    $form_id = $node->type . '_node_form';
 
-  $form['#field_info'] = array($field['field_name'] => $field);
-  $form['#pre_render'] = array('_editablefields_pre_render');
+    module_load_include('inc', 'node', 'node.pages');
+    $form = call_user_func_array('drupal_retrieve_form', array($form_id, $form_state, $node));
+    $form_build_id = 'form-'. md5(uniqid(mt_rand(), TRUE));
+    $form['#build_id'] = $form_build_id;
+    drupal_prepare_form($form_id, $form, $form_state);
+
+    // @todo Find the way to find required item in node form.
+    if ($field_name == 'sell_price') {
+      $form_element = $form['base']['prices']['sell_price'];
+      $form = array('sell_price' => $form_element);
+      unset($form['sell_price']['#description']);
+      unset($form['sell_price']['#title']);
+    }
 
-  return $form;
+    return $form;
+  }
 }
 
 /**
@@ -211,29 +243,50 @@ function editablefields_view() {
   // this required traversing the entire node to get the field (and doesn't work
   // for checkboxes anyway)
 
-  $field = content_fields($field_name, $node->type);
+  if (strpos('field_', $field_name) === 0) {
+    $field = content_fields($field_name, $node->type);
 
-  $field['display_settings']['label']['format']='hidden';
-  // We have 2 reasonable choices here. We COULD use 'clicktoedit' and end up
-  // with the same HTML - then we could strip that HTML down to remove the
-  // surrounding 'click to edit' div (which we dont want, as we'll be replacing
-  // the html inside one of those div's)
-  // or we can simply use the 'defualt' formatter - which wont have the click to
-  // edit inside it  - and is hard coded into this module (for now) anyway!
-  $field['display_settings']['full']['format']='default';
-  $html=content_view_field($field,$node);
-  
-  $messages = drupal_get_messages('status', TRUE);
-  if (count($messages) > 0) {
-    foreach ($messages as $type => $messages) {
-      foreach ($messages as $message) {
-        $output .= '<div class="messages ' . $type . '">' . $message . "</div>";
+    $field['display_settings']['label']['format']='hidden';
+    // We have 2 reasonable choices here. We COULD use 'clicktoedit' and end up
+    // with the same HTML - then we could strip that HTML down to remove the
+    // surrounding 'click to edit' div (which we dont want, as we'll be replacing
+    // the html inside one of those div's)
+    // or we can simply use the 'defualt' formatter - which wont have the click to
+    // edit inside it  - and is hard coded into this module (for now) anyway!
+    $field['display_settings']['full']['format']='default';
+    $html=content_view_field($field,$node);
+
+    $messages = drupal_get_messages('status', TRUE);
+    if (count($messages) > 0) {
+      foreach ($messages as $type => $messages) {
+        foreach ($messages as $message) {
+          $output .= '<div class="messages ' . $type . '">' . $message . "</div>";
+        }
       }
     }
+
+    $object = new stdClass();
+    $object->content = $output . $html.drupal_render($node->content[$field_name]);
   }
+  else {
+    if ($field_name == 'sell_price') {
+      $context = array(
+        'revision' => 'themed',
+        'type' => 'product',
+        'class' => array(
+          'product',
+        ),
+        'field' => 'sell_price',
+        'subject' => array(
+          'node' => $node,
+        ),
+      );
+      $options = array('label' => FALSE);
 
-  $object = new stdClass();
-  $object->content = $output . $html.drupal_render($node->content[$field_name]);
+      $object = new stdClass();
+      $object->content =  uc_price($node->sell_price, $context, $options);
+    }
+  }
   drupal_json($object);
   exit();
 }
@@ -330,8 +383,14 @@ function editablefields_submit() {
       drupal_set_header('Content-Type: text; charset=utf-8');
     }
     else {
-      drupal_set_header('HTTP/1.1 404 Not Found');
-      print t('No field found, of name: %field', array('%field' => $field_name));
+      if (isset($node->{$field_name})) {
+        $node->{$field_name} = $form_state['values'][$field_name];
+          node_save($node);
+      }
+      else {
+        drupal_set_header('HTTP/1.1 404 Not Found');
+        print t('No field found, of name: %field', array('%field' => $field_name));
+      }
     }
   }
   else {
