Perforce Chronicle 2012.2/486814
API Documentation

Flickr_Form_StreamWidget Class Reference

This is the flickr stream widget config form. More...

Inheritance diagram for Flickr_Form_StreamWidget:
P4Cms_Form_SubForm

List of all members.

Public Member Functions

 init ()
 Defines the elements that make up the config form.
 isValid ($data)
 Ensures that the appopriate data is entered, depending on the selected image source.
 setDefaults (array $defaults)
 Whenever values are set on the form, show/hide the appopriate source key fieldset.

Public Attributes

const DIMENSION_LARGE = 'Large'
const DIMENSION_MEDIUM = 'Medium'
const DIMENSION_SMALL = 'Small'
const DIMENSION_SQUARE = 'Square'
const DIMENSION_THUMBNAIL = 'Thumbnail'
const PAGE_SIZE = 5
const SOURCE_GROUP = 'Group'
const SOURCE_TAG = 'Tag'
const SOURCE_USER = 'User'

Static Public Attributes

static $sizeDimensions

Detailed Description

This is the flickr stream widget config form.

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

Flickr_Form_StreamWidget::init ( )

Defines the elements that make up the config form.

Form controls size of image (flickr size: square, thumb, small, medium, large, original), and source (user, topic, group). Called automatically when the form object is created.

    {
        $types = $this->addElement(
            'select',
            'sourceType',
            array(
                'label'         => 'Image Source Type',
                'multiOptions'  => array_combine($this->_definedSources, $this->_definedSources),
                'value'         => $this->_defaultSource,
                'onChange'      => 
                        "var prefix = this.id.replace(/[^-]+-sourceType$/, '');"
                      . "p4cms.ui.hide(prefix + 'config-streamSourceTag',   {duration: 0});"
                      . "p4cms.ui.hide(prefix + 'config-streamSourceUser',  {duration: 0});"
                      . "p4cms.ui.hide(prefix + 'config-streamSourceGroup', {duration: 0});"
                      . "p4cms.ui.show(prefix + 'config-streamSource' + this.value);"
            )
        );

        // control visibility based on the selected source
        $this->addElement(
            'text',
            'sourceTag',
            array( 'label'      => 'Flickr Tags')
        );

        $this->addDisplayGroup(
            array('sourceTag'),
            'streamSourceTag',
            array('style'       => 'display: none;')
        );

        $this->addElement(
            'text',
            'sourceUser',
            array('label'       => 'Flickr Username')
        );

        $this->addDisplayGroup(
            array('sourceUser'),
            'streamSourceUser',
            array('style'       => 'display: none;')
        );

        $this->addElement(
            'text',
            'sourceGroup',
            array('label'       => 'Flickr Group Id')
        );

        $this->addDisplayGroup(
            array('sourceGroup'),
            'streamSourceGroup',
            array('style'       => 'display: none;')
        );

        $size = $this->addElement(
            'select',
            'imageSize',
            array(
                'label'         => 'Image Size',
                'multiOptions'  => $this->_definedSizes,
                'value'         => $this->_defaultImageSize
            )
        );

        $this->addElement(
            'checkbox',
            'showImageTitle',
            array(
                'label'         => 'Show Image Title',
                'value'         => $this->_defaultShowTitle
            )
        );

        $this->addElement(
            'text',
            'imageDelay',
            array(
                'label'         => 'Image Delay (seconds)',
                'value'         => $this->_defaultDelay,
                'validators'    => array(
                    'digits'
                )
            )
        );
    }
Flickr_Form_StreamWidget::isValid ( data)

Ensures that the appopriate data is entered, depending on the selected image source.

Parameters:
array$datathe array of form submission data to validate
Returns:
boolean whether or not $data is valid
    {
        if (!parent::isValid($data)) {
            return false;
        }

        $sourceKey = 'source' . $data['config']['sourceType'];
        if (empty($data['config'][$sourceKey])) {
            $this->getElement($sourceKey)->addError(
                "You must enter a " . $this->getElement($sourceKey)->getLabel() . "."
            );
            return false;
        }
        return true;
    }
Flickr_Form_StreamWidget::setDefaults ( array $  defaults)

Whenever values are set on the form, show/hide the appopriate source key fieldset.

Parameters:
array$defaultsthe values to populate the form
Returns:
Widget_Form_StreamWidget provides fluent interface
    {
        if (isset($defaults['config']['sourceType'])) {
            $fieldsetName = 'streamSource' . $defaults['config']['sourceType'];
            $this->getDisplayGroup($fieldsetName)->setAttrib('style', 'display: block;');
        } else {
            $fieldsetName = 'streamSource' . $this->_defaultSource;
            $this->getDisplayGroup($fieldsetName)->setAttrib('style', 'display: block;');
        }

        return parent::setDefaults($defaults);
    }

Member Data Documentation

Flickr_Form_StreamWidget::$sizeDimensions [static]
Initial value:
 array(
        self::DIMENSION_SQUARE      => 75,
        self::DIMENSION_THUMBNAIL   => 100,
        self::DIMENSION_SMALL       => 240,
        self::DIMENSION_MEDIUM      => 500,
        self::DIMENSION_LARGE       => 640
     )

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