View source
<?php
class slickgrid_views_plugin extends views_plugin_style {
function option_definition() {
$options = parent::option_definition();
$options['grouping_field'] = array(
'default' => NULL,
);
$options['collapse_groups_by_default'] = array(
'default' => FALSE,
);
$options['collapsible_taxonomy_field'] = array(
'default' => NULL,
);
$options['enableColumnResize'] = array(
'default' => TRUE,
);
$options['enableColumnReorder'] = array(
'default' => TRUE,
);
$options['select_columns'] = array(
'default' => TRUE,
);
$options['delete_nodes'] = array(
'default' => TRUE,
);
$options['asyncEditorLoading'] = array(
'default' => TRUE,
);
$options['autoEdit'] = array(
'default' => FALSE,
);
$options['forceFitColumns'] = array(
'default' => false,
);
$options['multi_edit'] = array(
'default' => false,
);
$options['undo'] = array(
'default' => false,
);
$options['viewport_height'] = array(
'default' => 500,
);
$options['rowHeight'] = array(
'default' => 30,
);
return $options;
}
function sanitize_columns($columns, $fields = NULL) {
$sanitized = array();
if ($fields === NULL) {
$fields = $this->display->handler
->get_option('fields');
}
foreach ($fields as $field => $info) {
$sanitized[$field] = $field;
}
if (is_array($columns)) {
foreach ($columns as $field => $column) {
if (!isset($sanitized[$field])) {
continue;
}
$column_name = key($column);
if ($field == $column_name || $columns[$column_name] == $column && !empty($sanitized[$column_name])) {
$sanitized[$field] = $column;
}
}
}
return $sanitized;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$handlers = $this->display->handler
->get_handlers('field');
$columns = $this
->sanitize_columns($this->options['columns']);
$field_names = $this->display->handler
->get_field_labels();
if (empty($columns)) {
$form['error_markup'] = array(
'#value' => t('You need at least one field before you can configure your slickgrid settings'),
'#prefix' => '<div class="error form-item description">',
'#suffix' => '</div>',
);
return;
}
$collapsible_taxonomy_options = array(
'' => t('<None>'),
);
foreach ($columns as $field => $column) {
if ($handlers[$field]->options['exclude']) {
continue;
}
$form['columns'][$field]['width'] = array(
'#type' => 'textfield',
'#default_value' => $this->options['columns'][$field]['width'] ? $this->options['columns'][$field]['width'] : 100,
'#size' => 10,
'#maxlength' => 10,
);
if ($handlers[$field]
->click_sortable()) {
$form['columns'][$field]['sortable'] = array(
'#type' => 'checkbox',
'#default_value' => $this->options['columns'][$field]['sortable'] ? $this->options['columns'][$field]['sortable'] : false,
'#size' => 10,
);
}
$filters = array();
if (isset($handlers[$field]->content_field['widget']['type'])) {
$filters['field_type'] = $handlers[$field]->content_field['widget']['type'];
}
else {
$filters['field_type'] = $handlers[$field]->table . '_' . $handlers[$field]->real_field;
}
if ($filters['field_type'] == 'term_node_tid') {
$collapsible_taxonomy_options[$field] = $field_names[$field];
}
foreach (slickgrid_get_plugin_types() as $plugin_type => $plugin_label) {
if (($plugin_type == 'editor' || $plugin_type == 'validator') && !$this
->is_editable($handlers[$field], $filters['field_type'])) {
$form['columns'][$field][$plugin_type] = array(
'#value' => t('This field cannot be edited.'),
);
continue;
}
$filters['plugin_type'] = $plugin_type;
$plugins = slickgrid_get_plugins($filters);
if (count($plugins)) {
$form['columns'][$field][$plugin_type] = array(
'#type' => 'select',
'#default_value' => $this->options['columns'][$field][$plugin_type] ? $this->options['columns'][$field][$plugin_type] : '',
'#options' => $this
->get_plugin_options($plugins),
);
}
else {
$form['columns'][$field][$plugin_type] = array(
'#value' => t('No %plugin_label plugins for this field.', array(
'%plugin_label' => strtolower($plugin_label),
)),
);
}
}
$form['columns'][$field]['name'] = array(
'#value' => $field_names[$field],
);
}
if ($this
->uses_fields()) {
$options = array(
'' => t('<None>'),
);
$options += $this->display->handler
->get_field_labels();
if (count($options) > 1) {
$form['grouping_field'] = array(
'#type' => 'select',
'#title' => t('Grouping field'),
'#options' => $options,
'#default_value' => $this->options['grouping_field'],
'#description' => t('You may optionally specify a field by which to group the records. Leave blank to not group.'),
);
$form['collapse_groups_by_default'] = array(
'#type' => 'checkbox',
'#title' => t('Collapse groups'),
'#description' => t('All groups should be collapsed by default.'),
'#default_value' => $this->options['collapse_groups_by_default'],
);
}
if (count($collapsible_taxonomy_options) > 1) {
$form['collapsible_taxonomy_field'] = array(
'#type' => 'select',
'#title' => t('Collapsible taxonomy field'),
'#options' => $collapsible_taxonomy_options,
'#default_value' => $this->options['collapsible_taxonomy_field'],
'#description' => t('You may optionally specify a collapsible taxonomy field. Setting this will add a taxonomy parent relationship & ordering to the view.'),
);
}
}
$form['enableColumnResize'] = array(
'#type' => 'checkbox',
'#title' => t('Enable resizing columns'),
'#default_value' => $this->options['enableColumnResize'],
);
$form['enableColumnReorder'] = array(
'#type' => 'checkbox',
'#title' => t('Enable reordering columns'),
'#default_value' => $this->options['enableColumnReorder'],
);
$form['select_columns'] = array(
'#type' => 'checkbox',
'#title' => t('Column visibility'),
'#description' => t('Allow users to show & hide columns'),
'#default_value' => $this->options['select_columns'],
);
$form['delete_nodes'] = array(
'#title' => t('Delete nodes'),
'#description' => t('Allow users to delete nodes from within the slickgrid.'),
'#type' => 'checkbox',
'#default_value' => $this->options['delete_nodes'],
);
$form['asyncEditorLoading'] = array(
'#type' => 'checkbox',
'#title' => t('A sync editor loading'),
'#default_value' => $this->options['asyncEditorLoading'],
);
$form['autoEdit'] = array(
'#type' => 'checkbox',
'#title' => t('Auto edit'),
'#default_value' => $this->options['autoEdit'],
'#description' => t('Activate edit on entry to cell, otherwise double click to edit.'),
);
$form['forceFitColumns'] = array(
'#type' => 'checkbox',
'#title' => t('Force fit columns'),
'#default_value' => $this->options['forceFitColumns'],
'#description' => t('Force column widths to fit the grid.'),
);
$form['multi_edit'] = array(
'#type' => 'checkbox',
'#title' => t('Multi-edit'),
'#description' => t('Users can select & edit multiple nodes at once.'),
'#default_value' => $this->options['multi_edit'],
);
$form['undo'] = array(
'#type' => 'checkbox',
'#title' => t('Undo'),
'#description' => t('Allow users to undo updates. Warning: if turned on, all updates will create a node revision.'),
'#default_value' => $this->options['undo'],
);
$form['viewport_height'] = array(
'#title' => t('Viewport height'),
'#type' => 'textfield',
'#default_value' => $this->options['viewport_height'],
'#size' => 10,
'#maxlength' => 10,
);
$form['rowHeight'] = array(
'#title' => t('Row height'),
'#type' => 'textfield',
'#default_value' => $this->options['rowHeight'],
'#size' => 10,
'#maxlength' => 10,
);
$form['#theme'] = 'slickgrid_views_plugin_table';
}
function options_submit() {
slickgrid_delete_settings(array(
'view_name' => $this->view->name,
));
}
function query() {
$this->view->query
->add_field('node', 'type');
}
function is_editable($handler, $field_type) {
if (in_array($handler->table, array(
'term_node',
'term_data',
'vocabulary',
))) {
if (!(is_array($handler->options['vids']) && slickgrid_taxonomy_field_get_vid($handler))) {
return FALSE;
}
}
if (in_array($field_type, array(
'node_nid',
'node_type',
))) {
return FALSE;
}
return TRUE;
}
function get_plugin_options($plugins) {
$options = array(
'' => 'None',
);
return $options + (array) array_map(create_function('$plugins', 'return $plugins["description"];'), $plugins);
}
}