Commit dc3ec4ee authored by merlinofchaos's avatar merlinofchaos

UI checkpoint checkin.

parent 9cb53fce
...@@ -38,41 +38,66 @@ ...@@ -38,41 +38,66 @@
margin-top: 0; margin-top: 0;
} }
.views-tabset .views-tab-area { .views-tabset .views-display {
border: 1px solid black; border: 1px solid black;
margin-left: 119px; /* 120 -1 causes borders to overlap */ margin-left: 119px; /* 120 -1 causes borders to overlap */
min-height: 300px; min-height: 300px;
_height: 300px; /* stupid IE hack */ _height: 300px; /* stupid IE hack */
} }
.views-tabset .views-display-deleted {
background-color: #eee;
}
.views-tabset .views-display .top {
padding: 2px 5px;
border-left: 1px solid black;
border-right: 1px solid black;
border-bottom: 2px solid black;
}
.views-tab-area .tab-section { .views-tabset .views-display .top .display-description {
margin-left: 1em;
font-style: italic;
overflow: hide;
white-space: nowrap;
}
.views-display .tab-section {
width: 33%; width: 33%;
padding: 0; padding: 0;
margin: 0; margin: 0;
float: left; float: left;
min-height: 300px; min-height: 273px;
_height: 300px; _height: 274px;
} }
.views-tab-area .tab-section .inside { .views-display .tab-section .inside {
margin: 0; margin: 0;
padding: 2px 5px; padding: 2px 5px;
} }
.views-tab-area .tab-section .links { .views-display .tab-section .links {
float: right; float: right;
} }
.views-tab-area .tab-section .links a { .views-display .tab-section .links a {
font-size: small; font-size: small;
} }
.views-tab-area .middle { .views-display .form-submit {
margin: 0;
}
.views-display #views-add-display-form {
float: right;
}
.views-display .middle {
width: 34%; width: 34%;
background-color: #ccc; background-color: #ccc;
} }
.views-tab-area dl { .views-display dl {
margin: 0; margin: 0;
} }
...@@ -99,3 +124,10 @@ ...@@ -99,3 +124,10 @@
float: right; float: right;
} }
#views-ajax-pad {
display: none;
}
html.js #views-ajax-pad {
display: block;
}
...@@ -90,20 +90,18 @@ function views_ui_list_views() { ...@@ -90,20 +90,18 @@ function views_ui_list_views() {
* Page callback to add a new view. * Page callback to add a new view.
*/ */
function views_ui_add_page() { function views_ui_add_page() {
$view = views_new_view(); return drupal_get_form('views_ui_add_form');
return drupal_get_form('views_ui_add_form', $view);
} }
/** /**
* Form constructor callback to create the views Add Form, phase 1. * Form constructor callback to create the views Add Form, phase 1.
*/ */
function views_ui_add_form(&$form_state, $view) { function views_ui_add_form(&$form_state) {
$form = array(); $form = array();
$form['name'] = array( $form['name'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('View name'), '#title' => t('View name'),
'#description' => t('This is the unique name of the view. It must contain only alphanumeric characters and underscores; it is used to identify the view internally and to generate unique theming template names for this view. If overriding a module provided view, the name must not be changed or instead a new view will be created.'), '#description' => t('This is the unique name of the view. It must contain only alphanumeric characters and underscores; it is used to identify the view internally and to generate unique theming template names for this view. If overriding a module provided view, the name must not be changed or instead a new view will be created.'),
'#default_value' => $view->name,
'#required' => TRUE, '#required' => TRUE,
); );
...@@ -111,14 +109,12 @@ function views_ui_add_form(&$form_state, $view) { ...@@ -111,14 +109,12 @@ function views_ui_add_form(&$form_state, $view) {
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('View description'), '#title' => t('View description'),
'#description' => t('This description will appear on the Views administrative UI to tell you what the view is about.'), '#description' => t('This description will appear on the Views administrative UI to tell you what the view is about.'),
'#default_value' => $view->description,
); );
$form['tag'] = array( $form['tag'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('View tag'), '#title' => t('View tag'),
'#description' => t('Enter an optional tag for this view; it is used only to help sort views on the administrative page.'), '#description' => t('Enter an optional tag for this view; it is used only to help sort views on the administrative page.'),
'#default_value' => $view->tag,
// TODO: This should be an autocomplete field. // TODO: This should be an autocomplete field.
); );
...@@ -126,21 +122,10 @@ function views_ui_add_form(&$form_state, $view) { ...@@ -126,21 +122,10 @@ function views_ui_add_form(&$form_state, $view) {
'#type' => 'radios', '#type' => 'radios',
'#title' => t('View type'), '#title' => t('View type'),
'#description' => t('The view type is the primary table for which information is being retrieved. The view type controls what arguments, fields, sort criteria and filters are available, so once this is set it <strong>cannot be changed</strong>.'), '#description' => t('The view type is the primary table for which information is being retrieved. The view type controls what arguments, fields, sort criteria and filters are available, so once this is set it <strong>cannot be changed</strong>.'),
'#default_value' => 'node', // default to node views.
'#options' => views_fetch_base_table_names(), '#options' => views_fetch_base_table_names(),
'#default_value' => $view->base_table,
'#disabled' => !empty($view->vid) && $view->vid != 'new',
); );
if (empty($view->vid) || $view->vid == 'new') {
$form['displays'] = array(
'#type' => 'checkboxes',
'#title' => t('Initial displays'),
'#description' => t('Select which displays you would like to have automatically created with this view.'),
'#options' => views_fetch_plugin_names('display'),
'#required' => TRUE,
);
}
$form['submit'] = array( $form['submit'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Next'), '#value' => t('Next'),
...@@ -148,8 +133,6 @@ function views_ui_add_form(&$form_state, $view) { ...@@ -148,8 +133,6 @@ function views_ui_add_form(&$form_state, $view) {
'#submit' => array('views_ui_add_form_submit'), '#submit' => array('views_ui_add_form_submit'),
); );
$form_state['view'] = $view;
return $form; return $form;
} }
...@@ -165,62 +148,46 @@ function views_ui_add_form_validate($form, &$form_state) { ...@@ -165,62 +148,46 @@ function views_ui_add_form_validate($form, &$form_state) {
* Process the add view form * Process the add view form
*/ */
function views_ui_add_form_submit($form, &$form_state) { function views_ui_add_form_submit($form, &$form_state) {
$view = $form_state['view']; $view = views_new_view();
$view->name = $form_state['values']['name']; $view->name = $form_state['values']['name'];
$view->description = $form_state['values']['description']; $view->description = $form_state['values']['description'];
$view->tag = $form_state['values']['tag']; $view->tag = $form_state['values']['tag'];
$view->base_table = $form_state['values']['base_table']; $view->base_table = $form_state['values']['base_table'];
foreach (array_keys(array_filter($form_state['values']['displays'])) as $display_id) {
// TODO: Should there be information in here to identify default style plugins
// for displays?
$view->add_display($display_id);
}
views_ui_cache_set($view); views_ui_cache_set($view);
$form_state['redirect'] ='admin/build/views/edit/' . $view->name; $form_state['redirect'] ='admin/build/views/edit/' . $view->name;
} }
/** /**
* The main view edit form * The main view edit page
*/ */
function views_ui_edit_page($view) { function views_ui_edit_page($view) {
drupal_set_title(t('Edit view "%view"', array('%view' => $view->name))); drupal_set_title(t('Edit view "%view"', array('%view' => $view->name)));
// return drupal_get_form('views_ui_edit_view', $view);
return theme('views_ui_edit_view', $view); return theme('views_ui_edit_view', $view);
} }
function views_ui_edit_view(&$form_state, $view) { /**
* The main edit view form, which is really just a save/cancel/delete button.
$form['display']['display'] = array( */
'#type' => 'select', function views_ui_edit_view_form(&$form_state, $view) {
'#options' => views_fetch_plugin_names('display'),
);
$form['display']['add_display'] = array(
'#type' => 'submit',
'#value' => t('Add display'),
);
$form['buttons']['save'] = array( $form['buttons']['save'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Save'), '#value' => t('Save'),
'#validate' => array('views_ui_edit_form_validate'), '#validate' => array('views_ui_edit_view_form_validate'),
'#submit' => array('views_ui_edit_form_submit'), '#submit' => array('views_ui_edit_view_form_submit'),
); );
$form['buttons']['cancel'] = array( $form['buttons']['cancel'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Cancel'), '#value' => t('Cancel'),
'#submit' => array('views_ui_edit_form_cancel'), '#submit' => array('views_ui_edit_view_form_cancel'),
); );
if (is_numeric($view->vid)) { if (is_numeric($view->vid)) {
$form['buttons']['delete'] = array( $form['buttons']['delete'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Delete'), '#value' => t('Delete'),
'#submit' => array('views_ui_edit_form_delete'), '#submit' => array('views_ui_edit_view_form_delete'),
); );
} }
...@@ -228,44 +195,6 @@ function views_ui_edit_view(&$form_state, $view) { ...@@ -228,44 +195,6 @@ function views_ui_edit_view(&$form_state, $view) {
return $form; return $form;
} }
/**
* Form to add a display to a view.
*/
function views_ui_add_display_form(&$form_state, $view) {
$form['js'] = array(
'#type' => 'hidden',
'#value' => FALSE,
);
$form['display']['display'] = array(
'#type' => 'select',
'#options' => views_fetch_plugin_names('display'),
);
$form['display']['add_display'] = array(
'#type' => 'submit',
'#value' => t('Add display'),
'#submit' => array('views_ui_add_display_form_submit'),
);
$form['#id'] = 'views-add-display-form';
$form['#attributes'] = array('class' => 'views-ajax-form');
drupal_add_js(array('views' => array('forms' => array('views-add-display-form' => url('admin/build/views/add-display/' . $view->name, array('absolute' => true))))), 'setting');
$form_state['view'] = $view;
return $form;
}
/**
* Submit handler to add a display to a view.
*/
function views_ui_add_display_form_submit($form, &$form_state) {
$plugin = $form_state['values']['display'];
$form_state['id'] = $form_state['view']->add_display($plugin);
views_ui_cache_set($form_state['view']);
$form_state['redirect'] = array($_GET['q'], array('fragment' => 'views-tab-' . $form_state['id']));
}
/** /**
* Display the edit view form. * Display the edit view form.
* *
...@@ -273,9 +202,8 @@ function views_ui_add_display_form_submit($form, &$form_state) { ...@@ -273,9 +202,8 @@ function views_ui_add_display_form_submit($form, &$form_state) {
* here than you might find in most forms. * here than you might find in most forms.
*/ */
function theme_views_ui_edit_view($view) { function theme_views_ui_edit_view($view) {
// Do this first so the form will get processed right away if necessary:
$display_button = drupal_get_form('views_ui_add_display_form', $view);
$output = ''; $output = '';
$save_button = drupal_get_form('views_ui_edit_view_form', $view);
if (!empty($view->changed)) { if (!empty($view->changed)) {
if (!is_numeric($view->vid)) { if (!is_numeric($view->vid)) {
...@@ -292,24 +220,20 @@ function theme_views_ui_edit_view($view) { ...@@ -292,24 +220,20 @@ function theme_views_ui_edit_view($view) {
$table['table']['base']['title'] : t('Unknown or missing table name'); $table['table']['base']['title'] : t('Unknown or missing table name');
$output .= '<div class="views-basic-info">'; $output .= '<div class="views-basic-info">';
$link = l($view->name, "admin/build/views/details/$view->name/nojs", array('attributes' => array('class' => 'views-ajax-link'))); $output .= t('View %name, displaying items of type <b>@base</b>.',
$output .= t('View !name, displaying items of type <b>@base</b>.', array('%name' => $view->name, '@base' => $base_table));
array('!name' => $link, '@base' => $base_table));
$output .= '</div>'; $output .= '</div>';
views_include('tabs'); views_include('tabs');
$tabs = new views_tabset; $tabs = new views_tabset;
foreach ($view->display as $display) { foreach ($view->display as $display) {
list($title, $body) = views_ui_print_display($view, $display); list($title, $body) = views_ui_display_tab($view, $display);
// The first display is the default. // The first display is the default.
if (empty($default_display)) {
$title .= t(' (Default)');
$default_display = TRUE;
}
$tabs->set($display->id, $title, $body); $tabs->set($display->id, $title, $body);
} }
// This is the area that will render beneath the links // This is the area that will render beneath the links
$display_button = drupal_get_form('views_ui_add_display_form', $view);
$tabs->add_extra($display_button); $tabs->add_extra($display_button);
$output .= $tabs->render(); $output .= $tabs->render();
...@@ -320,8 +244,8 @@ function theme_views_ui_edit_view($view) { ...@@ -320,8 +244,8 @@ function theme_views_ui_edit_view($view) {
$output .= $message; $output .= $message;
$output .= '</div>'; $output .= '</div>';
// Render any of the form that is extra. // Render the actual form here
// $output .= drupal_render($form); $output .= $save_button;
views_add_css('admin'); views_add_css('admin');
views_add_js('ajax'); views_add_js('ajax');
...@@ -337,40 +261,86 @@ function theme_views_ui_edit_view($view) { ...@@ -337,40 +261,86 @@ function theme_views_ui_edit_view($view) {
return $output; return $output;
} }
function views_ui_print_display($view, $display) { function views_ui_display_tab($view, &$display) {
$plugin = views_fetch_plugin_data('display', $display->display_plugin); $plugin = views_fetch_plugin_data('display', $display->display_plugin);
if (empty($plugin)) { if (empty($plugin)) {
return array(t('Invalid'), t("Error: Display @display refers to a plugin named '@plugin', but that plugin doesn't exist!", array('@display' => $display->id, '@plugin' => $display->display_plugin))); return array(t('Invalid'), t("Error: Display @display refers to a plugin named '@plugin', but that plugin doesn't exist!", array('@display' => $display->id, '@plugin' => $display->display_plugin)));
} }
// TODO: We probably need this settable on the display object itself.
$title = $plugin['title'];
if (empty($display->handler)) {
$display->handler = views_get_plugin('display', $display->display_plugin);
if (empty($display->handler)) {
return FALSE;
}
// init the new display handler with data.
$display->handler->init($view, $display);
}
$top = $left = $middle = $right = '';
$left = $middle = $right = ''; // If this form was submitted it was already handled, so force it not to
// submit again.
$left = t('Basic display info goes here ') . $title; if (empty($plugin['no remove'])) {
if (!empty($_POST['form_id']) && $_POST['form_id'] == 'views_ui_remove_display_form') {
unset($_POST['form_id']);
}
$top .= drupal_get_form('views_ui_remove_display_form', $view, $display->id);
}
$middle = '<dl>'; $top .= '<span class="display-title">' . check_plain($display->display_title) . '</span>';
$top .= '<span class="display-description">' . check_plain($plugin['help']) . '</span>';
$left .= '<dl>';
// If this is the default display, add some basic stuff here.
if ($display->id == 'default') {
$tag = empty($view->tag) ? t('None') : $view->tag;
$left .= '<dt>' . t('View tag: !tag', array('!tag' => l($tag, "admin/build/views/nojs/details/$view->name", array('attributes' => array('class' => 'views-ajax-link'))))) . '</dt>';
}
$left .= $display->handler->options_summary();
$left .= '</dl>';
$middle .= '<dl>';
$middle .= views_ui_add_info('relationship', $view); $middle .= views_ui_add_info('relationship', $view);
$middle .= views_ui_add_info('argument', $view); $middle .= views_ui_add_info('argument', $view);
$middle .= views_ui_add_info('filter', $view); $middle .= views_ui_add_info('filter', $view);
$middle .= '</dl>'; $middle .= '</dl>';
$right = '<dl>'; $right .= '<dl>';
$right .= views_ui_add_info('field', $view); $right .= views_ui_add_info('field', $view);
$right .= views_ui_add_info('sort', $view); $right .= views_ui_add_info('sort', $view);
$right .= '</dl>'; $right .= '</dl>';
$body = '<div class="left tab-section"><div class="inside">' . $left . '</div></div>';
$body = '<div class="top"><div class="inside">' . $top . '</div></div>';
$body .= '<div class="left tab-section"><div class="inside">' . $left . '</div></div>';
$body .= '<div class="middle tab-section"><div class="inside">' . $middle . '</div></div>'; $body .= '<div class="middle tab-section"><div class="inside">' . $middle . '</div></div>';
$body .= '<div class="right tab-section"><div class="inside">' . $right . '</div></div>'; $body .= '<div class="right tab-section"><div class="inside">' . $right . '</div></div>';
return array($title, $body); $body = '<div class="views-display views-display-' . $display->id . (empty($display->deleted) ? '' : ' views-display-deleted') . '">' . $body . '</div>';
return array($display->display_title, $body);
} }
function views_ui_regenerate_tabs() { function views_ui_regenerate_tabs($view, $display_id = NULL) {
if (empty($display_id)) {
$displays = array_keys($view->display);
}
elseif (!is_array($display_id)) {
$displays = array($display_id);
}
else {
$displays = $display_id;
}
$object = new stdClass; $object = new stdClass;
$object->replace = array('#a' => 'b'); $object->replace = array();
foreach ($displays as $id) {
list($title, $body) = views_ui_display_tab($view, $view->display[$id]);
$object->replace['#views-tab-' . $id] = $body;
$object->replace['#views-tab-title-' . $id] = $title;
}
views_ajax_render($object); views_ajax_render($object);
} }
...@@ -389,28 +359,175 @@ function views_ui_standard_form_buttons(&$form, $form_id) { ...@@ -389,28 +359,175 @@ function views_ui_standard_form_buttons(&$form, $form_id) {
'#value' => t('Accept'), '#value' => t('Accept'),
'#submit' => array($form_id . '_submit'), '#submit' => array($form_id . '_submit'),
); );
$cancel_submit = function_exists($form_id . '_cancel') ? $form_id . '_cancel' : 'views_ui_standard_cancel';
$form['buttons']['cancel'] = array( $form['buttons']['cancel'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Cancel'), '#value' => t('Cancel'),
'#submit' => array($form_id . '_cancel'), '#submit' => array($cancel_submit),
); );
} }
function views_ui_standard_cancel($form, &$form_state) {
$form_state['redirect'] = 'admin/build/views/edit/' . $form_state['view']->name;
}
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Various subforms for editing the pieces of a view. // Various subforms for editing the pieces of a view.
/**
* AJAX callback to add a display.
*/
function views_ui_add_display($js, $view) {
if (!$js) {
return drupal_get_form('views_ui_add_display_form', $view);
}
views_include('ajax');
$form_state = views_ajax_form('views_ui_add_display_form', $view);
$view = $form_state['view'];
$id = $form_state['id'];
list($title, $body) = views_ui_display_tab($view, $view->display[$id]);
$output = new stdClass;
$output->tab = array('#views-tab-' . $id => array('title' => $title, 'body' => $body));
views_ajax_render($output);
}
/**
* Form to add a display to a view.
*/
function views_ui_add_display_form(&$form_state, $view) {
$form['display']['display'] = array(
'#type' => 'select',
'#options' => views_fetch_plugin_names('display'),
);
$form['display']['add_display'] = array(
'#type' => 'submit',
'#value' => t('Add display'),
'#submit' => array('views_ui_add_display_form_submit'),
);
$form['#id'] = 'views-add-display-form';
$form['#attributes'] = array('class' => 'views-ajax-form');
$form['#action'] = url("admin/build/views/nojs/add-display/$view->name");
$form_state['view'] = $view;
return $form;
}
/**
* Submit handler to add a display to a view.
*/
function views_ui_add_display_form_submit($form, &$form_state) {
// Create the new display
$plugin = $form_state['values']['display'];
$form_state['id'] = $form_state['view']->add_display($plugin);
// Store in cache
views_ui_cache_set($form_state['view']);
// Send it back
$form_state['redirect'] = array('admin/build/views/edit/' . $form_state['view']->name, NULL, 'views-tab-' . $form_state['id']);
}
/**
* AJAX callback to add a display.
*/
function views_ui_remove_display($js, $view, $display_id) {
if (!$js) {
return drupal_get_form('views_ui_remove_display_form', $view, $display_id);
}
views_include('ajax');
$form_state = views_ajax_form('views_ui_remove_display_form', $view, $display_id);
// regenerate the tabset, set it to replace. Use $form_state['view'] here to get
// the modifications.
return views_ui_regenerate_tabs($form_state['view'], $display_id);
}
/**
* Form to add a display to a view.
*/
function views_ui_remove_display_form(&$form_state, $view, $display_id) {
if (empty($view->display[$display_id]->deleted)) {
$form['display'] = array(
'#prefix' => '<div class="display-button remove-display">',
'#suffix' => '</div>',
);
$form['remove_display'] = array(
'#type' => 'submit',
'#value' => t('Remove display'),
'#submit' => array('views_ui_remove_display_form_submit'),
);
}
else {
$form['display'] = array(
'#prefix' => '<div class="display-button restore-display">',
'#suffix' => '</div>',
);
$form['restore_display'] = array(
'#type' => 'submit',
'#value' => t('Restore display'),
'#submit' => array('views_ui_remove_display_form_restore'),
);
}
$form['#action'] = url("admin/build/views/nojs/remove-display/$view->name/$display_id");
$form['#id'] = 'views-add-display-form';
$form['#attributes'] = array('class' => 'views-ajax-form');
$form_state['view'] = $view;
$form_state['display_id'] = $display_id;
return $form;
}
/**
* Submit handler to add a remove to a display from a view.
*/