Ver Fonte

Added javascript code to allow drag and drop of a field to a different region.

Chun-Huai Cheng há 9 anos atrás
pai
commit
c11e301c37

+ 33 - 0
tripal_panes/theme/js/tripal_panes.admin.js

@@ -7,6 +7,39 @@
   Drupal.behaviors.tripalPane = {
     attach: function (context, settings) {
     	Drupal.behaviors.fieldUIDisplayOverview = {};
+    	rearrangeRegion ();
     }
   };
+  
+  function rearrangeRegion () {
+	  // For each field, make sure the selected value matches the region where it resides
+	  $('#field-display-overview tr.tabledrag-leaf').each(function () {
+		  // ID
+		  var id = $(this).attr('id');
+		  // Get the region
+		  var region = getRegion (this).attr('class');
+		  var regex = /region-title region-(.+)-title/;
+		  var match = regex.exec(region);
+		  var region_id = match[1].replace('-', '_');
+		  var select = $(this).find('div.form-item-fields-' + id + '-region select');
+		  $(select).children().each(function() {
+			  if ($(this).val() == region_id) {
+				  $(this).attr('selected', 'true');
+			  } else {
+				  $(this).attr('selected', null);
+			  }
+		  });
+	  });
+  }
+  
+  function getRegion (field) {
+	  var previous = $(field).prev();
+	  var region = null;
+	  if ($(previous).hasClass('region-title')) {
+		  region =  previous;
+	  } else {
+		  region = getRegion (previous);
+	  }
+	  return region;
+  }
 })(jQuery);

+ 4 - 1
tripal_panes/tripal_panes.module

@@ -16,8 +16,11 @@ function tripal_panes_init() {
  * or layout of fields attached to an entity.
  */
 function tripal_panes_form_field_ui_display_overview_form_alter(&$form, &$form_state, $form_id) {
+  // Only modify the form for Tripal Content Type
+  if ($form['#entity_type'] != 'TripalEntity') {
+    return;
+  }
   drupal_add_js(drupal_get_path('module','tripal_panes') . '/theme/js/tripal_panes.admin.js');
-  drupal_set_message('For the Tripal v3.0a release there are two bugs to keep in mind. Dragging fields outside of a their assigned pane does not yet work. Use the "Region" select box instead. Also, dragging a field may set it\'s format to "hidden" in which case you will want to set it back', 'warning');
   drupal_add_css(drupal_get_path('module','tripal_panes') . '/theme/css/tripal_panes.css');
 
   $entity_type = $form['#entity_type'];