Index: skeleton_instance.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/skeleton/skeleton_instance.inc,v retrieving revision 1.5 diff -u -r1.5 skeleton_instance.inc --- skeleton_instance.inc 19 Dec 2008 18:17:47 -0000 1.5 +++ skeleton_instance.inc 23 Dec 2008 02:35:59 -0000 @@ -18,43 +18,13 @@ * Themed HTML, including the outline form */ function skeleton_define($skeleton) { - $output = '
No skeleton templates are available to add to this outline. Add a skeleton template.
', array('@template-add-url' => url('admin/content/skeleton/template/add'))); return $output; } $templates = skeleton_get_tree($skeleton->skeleton_id); - - $output .= t('Below are the current templates assigned to this skeleton outline.
'); - $output .= t(''. l(t('Create new instance'), 'admin/content/skeleton/create/'. $skeleton->skeleton_id) .'
'; $output .= drupal_get_form('skeleton_define_form', $skeleton, $templates); - // show the remaining options - $remove = array(); - foreach ($templates as $i => $template) { - $remove[] = $template->template_id; - } - if (!empty($remove)) { - $result = db_query("SELECT template_id, template, node_type FROM {skeleton_template} WHERE template_id NOT IN (". implode(', ', $remove) .") ORDER BY template_id"); - } - else { - $result = db_query("SELECT template_id, template, node_type FROM {skeleton_template} ORDER BY template_id"); - } - $header = array(t('Id'), t('Name'), t('Node type'), array('data' => t('Options'), 'colspan' => 2)); - $rows = array(); - while ($template = db_fetch_object($result)) { - $link = l(t('Add template'), 'admin/content/skeleton/assign/add/'. $skeleton->skeleton_id .'/'. $template->template_id); - $rows[] = array($template->template_id, check_plain($template->template), $template->node_type, $link); - } - $output .= t('No skeleton templates are available to add to this outline. Add a skeleton template.
', array('@template-add-url' => url('admin/content/skeleton/template/add'))); - } - $output .= ''. l(t('Create new template'), 'admin/content/skeleton/template/add') .'
'; return $output; } @@ -76,7 +46,7 @@ // TODO -- calculate the parent and weight correctly? db_query("INSERT INTO {skeleton_data} (skeleton_id, template_id, parent, weight) VALUES (%d, %d, %d, %d)", $skeleton->skeleton_id, $template->template_id, $parent, $weight); drupal_set_message(t('Template assigned')); - drupal_goto('admin/content/skeleton/edit/'. $skeleton->skeleton_id); + drupal_goto('admin/content/skeleton/skeleton/'. $skeleton->skeleton_id . '/edit'); } elseif ($check && $action == 'remove') { // update the children with the new parent, keep the original weight @@ -91,7 +61,7 @@ // remove db_query("DELETE FROM {skeleton_data} WHERE skeleton_id = %d AND template_id = %d", $skeleton->skeleton_id, $template->template_id); drupal_set_message(t('Template removed')); - drupal_goto('admin/content/skeleton/edit/'. $skeleton->skeleton_id); + drupal_goto('admin/content/skeleton/skeleton/'. $skeleton->skeleton_id . '/edit'); } else { return 'failed'; @@ -110,7 +80,62 @@ function skeleton_define_form($form_state, $skeleton, $templates) { $form = array(); $form['#tree'] = TRUE; - $form['skeleton_id'] = array('#type' => 'value', '#value' => $skeleton->skeleton_id); + $form['skeleton_id'] = array( + '#type' => 'value', + '#value' => $skeleton->skeleton_id, + ); + // show the remaining options + $remove = array(); + foreach ($templates as $i => $template) { + $remove[] = $template->template_id; + } + if (!empty($remove)) { + $result = db_query("SELECT template_id, template, node_type, node_data FROM {skeleton_template} WHERE template_id NOT IN (". implode(', ', $remove) .") ORDER BY template_id"); + } + else { + $result = db_query("SELECT template_id, template, node_type, node_data FROM {skeleton_template} ORDER BY template_id"); + } + while ($template = db_fetch_object($result)) { + $form['available_templates'][$template->template_id] = array( + 'template_id' => array( + '#type' => 'value', + '#value' => $template->template_id, + ), + 'template' => array( + '#value' => check_plain($template->template), + ), + 'node_type' => array( + '#value' => $template-> node_type, + ), + 'link' => array( + '#value' => l(t('Add template to skeleton'), 'admin/content/skeleton/assign/add/'. $skeleton->skeleton_id .'/'. $template->template_id), + ), + ); + if (module_exists('translation')) { + $form['multilang'] = array( + '#type' => 'value', + '#value' => TRUE, + ); + $node = (object)unserialize($template->node_data); + $form['available_templates'][$template->template_id]['language'] = array( + '#value' => locale_language_name($node->language), + ); + } + } + if (empty($form['available_templates'])) { + $form['available_templates'] = array( + '#value' => t('No skeleton templates are available to add to this outline. Add a skeleton template.
', array('@template-add-url' => url('admin/content/skeleton/template/add'))), + ); + } + $form['available_templates']['create'] = array( + '#value' => ''. l(t('Create new template'), 'admin/content/skeleton/template/add') .'
', + ); + + $form['current_templates']['help_text'] = array( + '#prefix' => '', + '#suffix' => '
', + '#value' => t('Below are the current templates assigned to this skeleton outline.'), + ); foreach ($templates as $i => $template) { $options = array(0 => ''. t('If you change a template parent, all the children of that parent will be reassigned as well.') .'
'); - $form['submit'] = array('#type' => 'submit', '#value' => t('Save skeleton outline')); + $form['current_templates']['notes'] = array( + '#value' => ''. t('If you change a template parent, all the children of that parent will be reassigned as well.') .'
' + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save'), + '#weight' => 100, + ); + $form['create'] = array( + '#type' => 'submit', + '#value' => t('Create instance'), + '#submit' => array('skeleton_create_redirect'), + '#weight' => 150, + ); + $form['delete'] = array( + '#type' => 'submit', + '#value' => t('Delete'), + '#submit' => array('skeleton_delete_redirect'), + '#weight' => 200, + ); return $form; } @@ -139,7 +206,7 @@ * FormsAPI for skeleton_define() */ function skeleton_define_form_submit($form, &$form_state) { - foreach ($form_state['values'] as $key => $template) { + foreach ($form_state['values']['current_templates'] as $key => $template) { // only the numeric keys are templates, so process those if (is_numeric($key)) { db_query("UPDATE {skeleton_data} SET parent = %d, weight = %d WHERE skeleton_id = %d AND template_id = %d", $template['parent'], $template['weight'], $form_state['values']['skeleton_id'], $template['template_id']); @@ -153,29 +220,80 @@ * Formats the form in a table. */ function theme_skeleton_define_form($form) { - // Build rows + // Build current templates table. $rows = array(); - $last_region = ''; - $last_status = 1; - foreach (element_children($form) as $i) { - $template = &$form[$i]; + foreach (element_children($form['current_templates']) as $i) { + $template = &$form['current_templates'][$i]; if (isset($template['template_id'])) { - $row = array( - drupal_render($template['temp_id']), - drupal_render($template['template']), - drupal_render($template['node_type']), - drupal_render($template['parent']), - drupal_render($template['weight']), - ); - $row[] = drupal_render($template['modify']); - $row[] = drupal_render($template['delete']); - $rows[] = $row; + $row = array( + drupal_render($template['template']), + drupal_render($template['node_type']), + ); + if (!empty($form['multilang'])) { + $row[] = drupal_render($template['language']); + } + $row[] = drupal_render($template['parent']); + $row[] = drupal_render($template['weight']); + $row[] = theme('item_list', array(drupal_render($template['modify']), drupal_render($template['delete']))); + $rows[] = $row; } } - // Finish table - $header = array(t('Id'), t('Template'), t('Node type'), t('Parent'), t('Weight')); + // Finish table. + $header = array(t('Template'), t('Node type')); + if ($form['multilang']) { + $header[] = t('Language'); + } + $header[] = t('Parent'); + $header[] = t('Weight'); $header[] = array('data' => t('Operations'), 'colspan' => 2); - $output = theme('table', $header, $rows, array('id' => 'skeleton')); + $output = t('