Commit dc3ec4ee authored by merlinofchaos's avatar merlinofchaos

UI checkpoint checkin.

parent 9cb53fce
......@@ -38,41 +38,66 @@
margin-top: 0;
}
.views-tabset .views-tab-area {
.views-tabset .views-display {
border: 1px solid black;
margin-left: 119px; /* 120 -1 causes borders to overlap */
min-height: 300px;
_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%;
padding: 0;
margin: 0;
float: left;
min-height: 300px;
_height: 300px;
min-height: 273px;
_height: 274px;
}
.views-tab-area .tab-section .inside {
.views-display .tab-section .inside {
margin: 0;
padding: 2px 5px;
}
.views-tab-area .tab-section .links {
.views-display .tab-section .links {
float: right;
}
.views-tab-area .tab-section .links a {
.views-display .tab-section .links a {
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%;
background-color: #ccc;
}
.views-tab-area dl {
.views-display dl {
margin: 0;
}
......@@ -99,3 +124,10 @@
float: right;
}
#views-ajax-pad {
display: none;
}
html.js #views-ajax-pad {
display: block;
}
......@@ -90,20 +90,18 @@ function views_ui_list_views() {
* Page callback to add a new view.
*/
function views_ui_add_page() {
$view = views_new_view();
return drupal_get_form('views_ui_add_form', $view);
return drupal_get_form('views_ui_add_form');
}
/**
* 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['name'] = array(
'#type' => 'textfield',
'#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.'),
'#default_value' => $view->name,
'#required' => TRUE,
);
......@@ -111,14 +109,12 @@ function views_ui_add_form(&$form_state, $view) {
'#type' => 'textfield',
'#title' => t('View description'),
'#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(
'#type' => 'textfield',
'#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.'),
'#default_value' => $view->tag,
// TODO: This should be an autocomplete field.
);
......@@ -126,20 +122,9 @@ function views_ui_add_form(&$form_state, $view) {
'#type' => 'radios',
'#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>.'),
'#default_value' => 'node', // default to node views.
'#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(
'#type' => 'submit',
......@@ -148,8 +133,6 @@ function views_ui_add_form(&$form_state, $view) {
'#submit' => array('views_ui_add_form_submit'),
);
$form_state['view'] = $view;
return $form;
}
......@@ -165,62 +148,46 @@ function views_ui_add_form_validate($form, &$form_state) {
* Process the add view form
*/
function views_ui_add_form_submit($form, &$form_state) {
$view = $form_state['view'];
$view = views_new_view();
$view->name = $form_state['values']['name'];
$view->description = $form_state['values']['description'];
$view->tag = $form_state['values']['tag'];
$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);
$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) {
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);
}
function views_ui_edit_view(&$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'),
);
/**
* The main edit view form, which is really just a save/cancel/delete button.
*/
function views_ui_edit_view_form(&$form_state, $view) {
$form['buttons']['save'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#validate' => array('views_ui_edit_form_validate'),
'#submit' => array('views_ui_edit_form_submit'),
'#validate' => array('views_ui_edit_view_form_validate'),
'#submit' => array('views_ui_edit_view_form_submit'),
);
$form['buttons']['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
'#submit' => array('views_ui_edit_form_cancel'),
'#submit' => array('views_ui_edit_view_form_cancel'),
);
if (is_numeric($view->vid)) {
$form['buttons']['delete'] = array(
'#type' => 'submit',
'#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) {
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.
*
......@@ -273,9 +202,8 @@ function views_ui_add_display_form_submit($form, &$form_state) {
* here than you might find in most forms.
*/
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 = '';
$save_button = drupal_get_form('views_ui_edit_view_form', $view);
if (!empty($view->changed)) {
if (!is_numeric($view->vid)) {
......@@ -292,24 +220,20 @@ function theme_views_ui_edit_view($view) {
$table['table']['base']['title'] : t('Unknown or missing table name');
$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>.',
array('!name' => $link, '@base' => $base_table));
$output .= t('View %name, displaying items of type <b>@base</b>.',
array('%name' => $view->name, '@base' => $base_table));
$output .= '</div>';
views_include('tabs');
$tabs = new views_tabset;
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.
if (empty($default_display)) {
$title .= t(' (Default)');
$default_display = TRUE;
}
$tabs->set($display->id, $title, $body);
}
// 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);
$output .= $tabs->render();
......@@ -320,8 +244,8 @@ function theme_views_ui_edit_view($view) {
$output .= $message;
$output .= '</div>';
// Render any of the form that is extra.
// $output .= drupal_render($form);
// Render the actual form here
$output .= $save_button;
views_add_css('admin');
views_add_js('ajax');
......@@ -337,40 +261,86 @@ function theme_views_ui_edit_view($view) {
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);
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)));
}
// 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;
}
$left = $middle = $right = '';
// init the new display handler with data.
$display->handler->init($view, $display);
}
$top = $left = $middle = $right = '';
$left = t('Basic display info goes here ') . $title;
// If this form was submitted it was already handled, so force it not to
// submit again.
$middle = '<dl>';
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);
}
$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('argument', $view);
$middle .= views_ui_add_info('filter', $view);
$middle .= '</dl>';
$right = '<dl>';
$right .= '<dl>';
$right .= views_ui_add_info('field', $view);
$right .= views_ui_add_info('sort', $view);
$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="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->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);
}
......@@ -389,28 +359,175 @@ function views_ui_standard_form_buttons(&$form, $form_id) {
'#value' => t('Accept'),
'#submit' => array($form_id . '_submit'),
);
$cancel_submit = function_exists($form_id . '_cancel') ? $form_id . '_cancel' : 'views_ui_standard_cancel';
$form['buttons']['cancel'] = array(
'#type' => 'submit',
'#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.
/**
* 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.
*/
function views_ui_remove_display_form_submit($form, &$form_state) {
// Create the new display
$plugin = views_fetch_plugin_data('display', $form_state['view']->display[$id]->display_plugin);
if (empty($plugin['no remove'])) {
$id = $form_state['display_id'];
$form_state['view']->display[$id]->deleted = TRUE;
// 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['display_id']);
}
/**
* Submit handler to add a restore a removed display to a view.
*/
function views_ui_remove_display_form_restore($form, &$form_state) {
// Create the new display
$id = $form_state['display_id'];
$form_state['view']->display[$id]->deleted = FALSE;
// 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['display_id']);
}
/**
* Page callback to edit details of a view.
*/
function views_ui_edit_details($view, $js) {
if ($js == 'nojs') {
function views_ui_edit_details($js, $view) {
if (!$js) {
return drupal_get_form('views_ui_edit_details_form', $view);
}
else {
views_include('ajax');
$form_state = views_ajax_form('views_ui_edit_details_form', $view);
// regenerate the tabset, set it to replace
return views_ui_regenerate_tabs();
return views_ui_regenerate_tabs($form_state['view']);
}
}
......@@ -452,48 +569,96 @@ function views_ui_edit_details_form_submit($form, &$form_state) {
}
/**
* AJAX callback to add a display.
* Page callback to edit options on a display of a view.
*/
function views_ui_add_display($view) {
function views_ui_edit_display($js, $view, $display_id, $section) {
if (!$js) {
return drupal_get_form('views_ui_edit_display_form', $view, $display_id, $section);
}
else {
views_include('ajax');
$form_state = views_ajax_form('views_ui_add_display_form', $view);
$view = $form_state['view'];
$id = $form_state['id'];
$form_state = views_ajax_form('views_ui_edit_display_form', $view, $display_id, $section);
return views_ui_regenerate_tabs($form_state['view'], $display_id);
}
}
/**
* Form constructor callback to edit display of a view
*/
function views_ui_edit_display_form(&$form_state, $view, $display_id, $section) {
$display = &$view->display[$display_id];
if (empty($display->handler)) {
$display->handler = views_get_plugin('display', $display->display_plugin);
if (empty($display->handler)) {
return array();
}
list($title, $body) = views_ui_print_display($view, $view->display[$id]);
// init the new display handler with data.
$display->handler->init($view, $display);
}
// $body = '<div id="views-tab-' . $id . '" class="views-tab">' . $body . "</div>\n";
$output = new stdClass;
$output->tab = array('#views-tab-' . $id => array('title' => $title, 'body' => $body));
$form_state['view'] = $view;
$form_state['display_id'] = $display_id;
$form_state['section'] = $section;
$display->handler->options_form($form, $form_state);
views_ui_standard_form_buttons($form, 'views_ui_edit_display_form');
return $form;
}
views_ajax_render($output);
function views_ui_edit_display_form_validate($form, &$form_state) {
$display = &$form_state['view']->display[$form_state['display_id']];
$display->handler->options_validate($form, $form_state);
}
/**
* Submit handler for views_ui_edit_display_form
*/
function views_ui_edit_display_form_submit($form, &$form_state) {
$display = &$form_state['view']->display[$form_state['display_id']];
$display->handler->options_submit($form, $form_state);
// Remove the handler so that it doesn't get saved into the cache.
unset($display->handler);
views_ui_cache_set($form_state['view']);
if (empty($form_state['ajax'])) {
drupal_set_message(t('Your changes have been saved.'));
$form_state['redirect'] = 'admin/build/views/edit/' . $form_state['view']->name;
}
}
/**
* Page callback to rearrange a section.
*/
function views_ui_rearrange_section($view, $js, $section, $display_id) {
if ($js == 'nojs') {
return drupal_get_form('views_ui_rearrange_form', $view, $section, $display_id);
function views_ui_rearrange_section($js, $view, $section, $display_id) {
if (!$js) {
$output = drupal_get_form('views_ui_rearrange_form', $view, $section, $display_id);
return $output;
}
else {
views_include('ajax');
$form_state = views_ajax_form('views_ui_rearrange_form', t('Rearrange @section', array('@section' => $section)), $_GET['q'], $view, $section, $display_id);
// regenerate the tabset, set it to replace
return views_ui_regenerate_tabs();
return views_ui_regenerate_tabs($form_state['view'], $display_id);
}
}