Perforce Chronicle 2012.2/486814
API Documentation
|
A form to control how comments behave per-content-entry. More...
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 |
A form to control how comments behave per-content-entry.
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.
string | $checkbox | the name of the checkbox to toggle |
{ 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.
array | $options | the options array to normalize. |
{ $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.
P4Cms_Record | array | $defaults | the default values to set on elements |
{ 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; }
Comment_Form_Content::$_defaultOptions [static, protected] |
array( 'allowComments' => true, 'requireLoginPost' => false, 'requireApproval' => false, 'showComments' => true, 'requireLoginView' => false, 'allowVoting' => true, 'oneVotePerUser' => true )