? hosting.oct.21.x.patch
Index: hosting.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/hosting/hosting.info,v
retrieving revision 1.6
diff -u -r1.6 hosting.info
--- hosting.info	19 Jun 2008 21:17:31 -0000	1.6
+++ hosting.info	21 Oct 2008 12:42:45 -0000
@@ -1,4 +1,4 @@
 name = Hosting
 description = Allow this Drupal site to deploy hosted sites.
 package = Hosting
-dependencies = provision views views_ui hosting_task hosting_client hosting_db_server hosting_package hosting_platform hosting_site hosting_web_server
+dependencies = provision views views_ui hosting_task hosting_client hosting_db_server hosting_package hosting_platform hosting_site hosting_web_server ahah_forms dynamic_subform
Index: package/hosting_package.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/hosting/package/hosting_package.module,v
retrieving revision 1.11
diff -u -r1.11 hosting_package.module
--- package/hosting_package.module	14 Oct 2008 22:03:27 -0000	1.11
+++ package/hosting_package.module	21 Oct 2008 12:42:57 -0000
@@ -33,8 +33,19 @@
   return hosting_access($op, $node);
 }
 
-function hosting_get_profiles() {
-  $profiles = _hosting_package_load(array('package_type' => 'profile'));
+function hosting_get_profiles($platform) {
+  if(!$platform) {
+    $platform = HOSTING_DEFAULT_PLATFORM;
+  }
+  $result = db_query('SELECT n.nid FROM {node} n LEFT JOIN {hosting_package} hp ON n.nid = hp.nid 
+                                                 LEFT JOIN {hosting_package_release} hpr ON hp.nid = hpr.package 
+                                                 LEFT JOIN {hosting_package_instance} hpi ON hpr.nid = hpi.release_id 
+                                                 LEFT JOIN {hosting_platform} l ON hpi.rid = l.nid 
+                                                 WHERE l.nid = %d AND hp.package_type = "profile"', $platform);
+
+  while ($nid = db_fetch_object($result)) {
+    $profiles[$nid->nid] = node_load(array('nid' => $nid->nid));
+  }
 
   foreach ($profiles as $profile) {
     $return[$profile->nid] = $profile->title;
@@ -42,8 +53,8 @@
   return $return;
 }
 
-function hosting_get_profile_languages() {
-  $result = db_query("SELECT DISTINCT(language) FROM {hosting_package_languages}");
+function hosting_get_profile_languages($profile) {
+  $result = db_query("SELECT DISTINCT(language) FROM {hosting_package_languages} WHERE nid = %d", $profile);
   while ($language = db_fetch_object($result)) {
     $languages[] = $language->language;
   }
Index: site/hosting_site.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/hosting/site/hosting_site.module,v
retrieving revision 1.25
diff -u -r1.25 hosting_site.module
--- site/hosting_site.module	20 Oct 2008 16:56:25 -0000	1.25
+++ site/hosting_site.module	21 Oct 2008 12:43:00 -0000
@@ -203,49 +203,14 @@
     $form['client'] = array('#type' => 'value', '#value' => key($clients));
   }
 
-  $platforms = _hosting_get_platforms();
-  if (sizeof($platforms) > 1) {
-    $form['platform'] = array(
-      '#type' => 'radios',
-      '#title' => t('Platform'),
-      '#description' => t('The platform you want the site to be hosted on.'),
-      '#options' => $platforms,
-      '#default_value' => $node->platform ? $node->platform : HOSTING_DEFAULT_PLATFORM,
-    );
-  }
-  else {
-    $form['platform'] = array('#type' => 'value', '#value' => key($platforms));
-  }
-
-
-  $profiles = hosting_get_profiles();
-  if (sizeof($profiles) > 1) {
-    $form['profile'] = array(
-      '#type' => 'radios',
-      '#title' => t('Install profile'),
-      '#description' => t('The type of site to install.'),
-      '#options' => $profiles,
-      '#default_value' => $node->prNULLe,
-    );
-  }
-  else {
-    $form['profile'] = array('#type' => 'value', '#value' => key($profiles));
-  }
-
-  $languages = hosting_get_profile_languages();
-  // @todo Implement jquery AHAH selectors, to filter the available languages.
-  if (sizeof($languages) > 1) {
-    $form['language'] = array(
-      '#type' => 'radios',
-      '#title' => t('Language'),
-      '#description' => t('The type of site to install.'),
-      '#options' => $languages,
-      '#default_value' => ($node->language) ? $node->language : 'en',
-    );
-  }
-  else {
-    $form['language'] = array('#type' => 'value', '#value' => 'en');
-  }
+  // Placeholder for AHAH subform
+  $form['site_subform'] = array(
+    '#type' => 'item',
+    '#prefix' => '<div id = "hosting-site-subform">',
+    '#suffix' => '</div>',
+  );
+  // Pre-embed the AHAH subform
+  $form['site_subform'] += dynamic_subform_get_embedded('site_node_form', 'hosting_site_subform', array());
 
   $db_servers = _hosting_get_db_servers();
   if (sizeof($db_servers) > 1) {
@@ -265,6 +230,89 @@
   return $form;
 }
 
+
+
+// AHAH function to render the subform
+function _hosting_site_ahah_subform() {
+  $subform = dynamic_subform_get_prepped('site_node_form', 'hosting_site_subform');
+  print drupal_render($subform);
+  exit();
+}
+
+// The AHAH subform
+function hosting_site_subform($form_values) {
+  $form = array();
+
+  $platforms = _hosting_get_platforms();
+  if (sizeof($platforms) > 1) {
+    $form['platform'] = array(
+      '#type' => 'radios',
+      '#title' => t('Platform'),
+      '#description' => t('The platform you want the site to be hosted on.'),
+      '#options' => $platforms,
+      '#default_value' => $node->platform,
+      '#attributes' => array('class' => 'hosting-platform-options'),
+      '#ahah_bindings' => array (
+        array(
+          'wrapper' => 'hosting-site-subform',
+          'selector' => 'input.hosting-platform-options',
+          'event' => 'click',
+          'path' => 'hosting/site/hosting_site_ahah_subform',
+        ),
+        array(
+          'wrapper' => 'hosting-site-subform',
+          'selector' => 'input.hosting-profile-options',
+          'event' => 'click',
+          'path' => 'hosting/site/hosting_site_ahah_subform',
+        ),
+      )
+    );
+  }
+  else {
+    if ($platforms) {
+      $platforms = HOSTING_DEFAULT_PLATFORM;
+    }
+    $form['platform'] = array('#type' => 'value', '#value' => key($platforms));
+  }
+  
+  // If a platform is selected, load the relavant profiles
+  if ($form_values['platform']) {
+    $profiles = hosting_get_profiles($form_values['platform']);
+    if (sizeof($profiles) > 1) {
+      $form['profile'] = array(
+        '#type' => 'radios',
+        '#title' => t('Install profile'),
+        '#description' => t('The type of site to install.'),
+        '#options' => $profiles,
+        '#default_value' => $node->profile,
+        '#attributes' => array('class' => 'hosting-profile-options'),
+      );
+    }
+    else {
+      $form['profile'] = array('#type' => 'value', '#value' => key($profiles));
+    }
+  }
+
+  // If a profile is selected, load the relavant languages
+  if ($form_values['profile']) {
+    $languages = hosting_get_profile_languages($form_values['profile']);
+    if (sizeof($languages) > 1) {
+      $form['language'] = array(
+        '#type' => 'radios',
+        '#title' => t('Language'),
+        '#description' => t('The language of your site.'),
+        '#options' => $languages,
+        '#default_value' => ($node->language) ? $node->language : 'en',
+      );
+    }
+    else {
+      $form['language'] = array('#type' => 'hidden', '#value' => 'en');
+    }
+  }
+
+  return $form;
+}
+
 function _hosting_site_validate_fqdn($fqdn) {
   # regex is an implementation of RFC1035
   return preg_match("/^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.?)+$/i", $fqdn);
@@ -503,5 +551,14 @@
     'type' => MENU_CALLBACK,
     'access' => TRUE
   );
+  $items[] = array(
+    'path' => 'hosting/site/hosting_site_ahah_subform',
+    'callback' => '_hosting_site_ahah_subform',
+    'type' => MENU_CALLBACK,
+    'access' => TRUE,
+  );
+
+
+
   return $items;
 }
