Perforce Chronicle 2012.2/486814
API Documentation

Comment_Form_Content Class Reference

A form to control how comments behave per-content-entry. More...

Inheritance diagram for Comment_Form_Content:
P4Cms_Form_SubForm

List of all members.

Public Member Functions

 init ()
 Defines the elements of the content comment sub-form.
 setDefaults ($defaults)
 Extended to enable the 'require login to post/view' checkboxes when the 'allow/show comments' checkboxes are checked.

Static Public Member Functions

static getNormalizedOptions ($options)
 Normalize the given options array to ensure it contains all of the expected options.

Protected Member Functions

 _toggleCheckbox ($checkbox)
 Get javascript code to toggle the given checkbox when called from the js event of another element in the form.

Static Protected Attributes

static $_defaultOptions

Detailed Description

A form to control how comments behave per-content-entry.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

Comment_Form_Content::_toggleCheckbox ( checkbox) [protected]

Get javascript code to toggle the given checkbox when called from the js event of another element in the form.

Parameters:
string$checkboxthe name of the checkbox to toggle
Returns:
string the js to toggle the checkbox.
    {
        return "var query = 'input[type=checkbox][name=\\'comments[" . $checkbox . "]\\']';"
            .  "var input = dojo.query(query, this.form)[0];"
            .  "dojo.attr(input, 'disabled', !this.checked);";
    }
static Comment_Form_Content::getNormalizedOptions ( options) [static]

Normalize the given options array to ensure it contains all of the expected options.

  • allowComments
  • requireLoginPost
  • requireApproval
  • showComments
  • requireLoginView
  • allowVoting
  • oneVotePerUser
Parameters:
array$optionsthe options array to normalize.
Returns:
array the normalized options.
    {
        $options = array_merge(
            static::$_defaultOptions,
            (array) $options
        );

        // cast all options to booleans.
        foreach ($options as &$option) {
            $option = ($option == true);
        }

        return $options;
    }
Comment_Form_Content::init ( )

Defines the elements of the content comment sub-form.

Called automatically when the form object is created.

    {
        $this->setLegend('Comments');

        $this->addElement(
            'checkbox',
            'allowComments',
            array(
                'label'     => 'Allow Comments',
                'value'     => true,
                'onClick'   => $this->_toggleCheckbox('requireLoginPost')
                            .  $this->_toggleCheckbox('requireApproval')
            )
        );

        $this->addElement(
            'checkbox',
            'requireLoginPost',
            array(
                'label'     => 'Require Login to Post',
                'class'     => 'sub-checkbox',
                'disabled'  => true
            )
        );

        $this->addElement(
            'checkbox',
            'requireApproval',
            array(
                'label'     => 'Require Approval',
                'class'     => 'sub-checkbox',
                'disabled'  => true
            )
        );        
        
        $this->addElement(
            'checkbox',
            'showComments',
            array(
                'label'     => 'Show Comments',
                'value'     => true,
                'onClick'   => $this->_toggleCheckbox('requireLoginView')
            )
        );

        $this->addElement(
            'checkbox',
            'requireLoginView',
            array(
                'label'     => 'Require Login to View',
                'class'     => 'sub-checkbox',
                'disabled'  => true
            )
        );

        $this->addElement(
            'checkbox',
            'allowVoting',
            array(
                'label'     => 'Allow Voting',
                'value'     => true,
                'onClick'   => $this->_toggleCheckbox('oneVotePerUser')
            )
        );

        $this->addElement(
            'checkbox',
            'oneVotePerUser',
            array(
                'label'     => 'One Vote Per-User',
                'value'     => true,
                'class'     => 'sub-checkbox',
                'disabled'  => true
            )
        );
        
        // put the checkbox inputs before their labels.
        foreach ($this->getElements() as $element) {
            P4Cms_Form::moveCheckboxLabel($element);
        }
    }
Comment_Form_Content::setDefaults ( defaults)

Extended to enable the 'require login to post/view' checkboxes when the 'allow/show comments' checkboxes are checked.

Parameters:
P4Cms_Record | array$defaultsthe default values to set on elements
Returns:
Zend_Form provides fluent interface
    {
        parent::setDefaults($defaults);

        if ($this->getValue('allowComments')) {
            $this->getElement('requireLoginPost')->setAttrib('disabled', null);
            $this->getElement('requireApproval')->setAttrib('disabled', null);
        }
        if ($this->getValue('showComments')) {
            $this->getElement('requireLoginView')->setAttrib('disabled', null);
        }
        if ($this->getValue('allowVoting')) {
            $this->getElement('oneVotePerUser')->setAttrib('disabled', null);
        }

        return $this;
    }

Member Data Documentation

Comment_Form_Content::$_defaultOptions [static, protected]
Initial value:
 array(
        'allowComments'     => true,
        'requireLoginPost'  => false,
        'requireApproval'   => false,
        'showComments'      => true,
        'requireLoginView'  => false,
        'allowVoting'       => true,
        'oneVotePerUser'    => true
    )

The documentation for this class was generated from the following file: