Skip to content
Snippets Groups Projects
Commit 148725bc authored by Dan Morrison's avatar Dan Morrison
Browse files

First commit to public CVS, transfer from sandbox (contributions/sandbox/dman/advancedform)

parents
No related branches found
Tags 7.x-1.0-beta3
No related merge requests found
ADVANCED FORM
===============================================================================
A UI tweak to /hide/ certain features or the form interface from normal use,
but still have them available on the page for validation and quick access.
This slims down the UI to make things seem simpler, without overloading the
maintenance tasks with layers of permissions, or removing any control from the
user.
USAGE
-------------------------------------------------------------------------------
When enabled, any configured form can have elements hidden (by css) for
normal use, and a small client-side button [Advanced] can be pressed to reveal
the rest of the form as needed.
CONFIGURATION
-------------------------------------------------------------------------------
The syntax for defining which form elements are 'hidden' is based entirely on
css selectors, with some shortcuts.
node-form:[#revision-information]
- will hide the revision information fieldset on node forms.
block-admin-configure:[#user-specific-visibility-settings]
- will remove a seldom-used option from block admin pages.
Use firebug or similar to find the correct selectors to choose your target form
elements.
A number of additional css classes are inserted into the form element for
additional, specific control.
Taxonomy terms selected on node forms are also set as context classes, so it's
possible to define rules that only apply when a certain term is selected in the
form.
More instructions are on the config page, which can be found at
'/admin/settings/advancedform'
To debug the css or see how it works, look at the path '/advancedform_css'
SEE ALSO
-------------------------------------------------------------------------------
Written with reference to formfilter.module which does a similar job through
access restrictions, whereas I want to trust my users, but avoid confusing
them. And clean up my own admin edit interface.
http://drupal.org/project/formfilter
This module is intended to be more lightweight than formfilter,
and does not have such an extensive admin UI.
vertical_tabs.module is excellent, and takes a different approach at minimizing
the screen size and hiding unwanted elements.
*This module has not been tested with and may not work well with vertical_tabs*
OTHERS:
nodeformsettings http://drupal.org/project/nodeformsettings
- a set of custom UI tweaks, half of which can now be done by this module.
compact forms http://drupal.org/project/compact_forms
- marginally tidies up some forms on the client side.
form defaults http://drupal.org/project/formdefaults
- advertises a UI for form_alter type operations. Untested
BACKGROUND
-------------------------------------------------------------------------------
This is more useful for in-house development with a set of trusted content
editors. It was built for tutoring, where I needed to be able to demonstrate
the functionality of the site as editors would see it, yet still have access
to admin functions without messing around with switchuser etc.
So I switched off the clutter.
Collapsed fieldsets are a good start, but there's still too many of them by
the time we start with ecommerce products etc.
Note this 'permission' isn't actually secure - the full form is still
available to browser hacks - like disable css or js
CSS-hide trick for context-sensitive forms developed by dman 2006
; $Id$
name = Advanced Form
description = Provides a UI for simplifying forms by temporarily hiding some fields.
core = "6.x"
<?php
// $Id$
/**
* Implementation of hook_install().
*/
function advancedform_install() {
// Set a high weight so the module is called after other modules that
// modify forms.
db_query('UPDATE {system} SET weight = 20 WHERE name = "advancedform"');
drupal_set_message(t("Advanced Form has been enabled. Visit !settings to check the rules.", array('!settings' => l('admin/settings/advancedform', t('settings')))));
}
function advancedform_uninstall() {
variable_del('advancedform_rules_global');
}
\ No newline at end of file
/**
* Use a selector to choose which elements get displayed on a page.
* @author dman dan@coders.co.nz
*/
Drupal.behaviors.advancedform = function(context) {
$('form.advancedform-unfiltered') // to be unobtrusive, we start as normal, then hide.
.removeClass('advancedform-unfiltered')
.addClass('advancedform-filtered')
.css('position', 'relative')
.append("<div class='advancedform-toggle' title='Some form elements may be hidden. Switch this form between full and partial detail'>Switch to Advanced</div>")
$('.advancedform-toggle').click(
function(){
if($(this).html() == 'Switch to Advanced') {
$(this).html('Switch to Filtered');
var originalBG = $('form').css("background-color");
$('form').removeClass('advancedform-filtered')
.animate({opacity:.5},300)
.animate({opacity:1},300)
}
else if($(this).html() == 'Switch to Filtered') {
$('form').addClass('advancedform-filtered')
.animate({opacity:.5},300)
.animate({opacity:1},300)
$(this).html('Switch to Advanced');
}
}
);
// Also capture any changes on any taxonomy selectors
// and insert that data into the form top
// Could usually use
// $("#vocabularies-wrapper select").change(
// but if working with node_form_rearrange, there's no vocab wrapper.
// Instead use a class we inserted in pre-render
$("select.taxonomy-select").change(
function(){
// remove previous selections
var previous_selections = $(this).data('advancedform');
console.log('unsetting previous ' + previous_selections);
for (selection_id in previous_selections) {
$('form.advancedform-filtered').removeClass(previous_selections[selection_id]);
}
// Add selected (and remember them here)
var selected_values = {}
$(':selected', this).each(function(i, selected){
var selected_text = Drupal.advancedform_safe_id($(selected).text());
console.log('chosen ' + selected_text);
selected_values[selected_text] = selected_text;
$('form.advancedform-filtered').addClass(selected_text);
});
$(this).data('advancedform', selected_values);
}
);
// Trigger it once to update the current display
$('select.taxonomy-select').trigger('change');
}
/**
* util function
*/
Drupal.advancedform_safe_id = function(string) {
var re = new RegExp('[^a-z0-9]', 'gi');
return string.replace(re, '-').toLowerCase();
}
\ No newline at end of file
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment