Perforce Chronicle 2012.2/486814
API Documentation

Menu_Form_MenuItemContentQuick Class Reference

This form is specialized for quickly editing content menu items from the context of content editing. More...

Inheritance diagram for Menu_Form_MenuItemContentQuick:
Menu_Form_MenuItemContent Menu_Form_MenuItem P4Cms_Form

List of all members.

Public Member Functions

 init ()
 Defines the elements that make up the 'quick' content menu item form.
 isValid ($data)
 Validate the form, if item is deleted, don't validate other fields.
 setDefaults ($defaults)
 Extends parent to hide label field if using content's title.

Protected Member Functions

 _getLocations ()
 Extended to only include menus we want to show when editing content.

Detailed Description

This form is specialized for quickly editing content menu items from the context of content editing.

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

Menu_Form_MenuItemContentQuick::_getLocations ( ) [protected]

Extended to only include menus we want to show when editing content.

Returns:
P4Cms_Model_Iterator menus and menu items in a single flat list.

Reimplemented from Menu_Form_MenuItem.

    {
        $filter = new P4Cms_Record_Filter;
        $filter->add('showInContentForm', '1');
        
        return P4Cms_Menu::fetchMixed(array('filter' => $filter));
    }    
Menu_Form_MenuItemContentQuick::init ( )

Defines the elements that make up the 'quick' content menu item form.

Called automatically when the form object is created.

Reimplemented from Menu_Form_MenuItemContent.

    {
        parent::init();
        
        // remove elements we don't care to expose here.
        $remove = array('type', 'contentId', 'target', 'class', 'save');
        array_map(array($this, 'removeElement'), $remove);
        $this->removeDisplayGroup('buttons');
        
        // in content post-save (when we are actually dealing with this form),
        // we need access to fields that are normally ignored, expose them.
        $expose = array('uuid', 'menuId', 'position', 'location');
        foreach ($expose as $name) {
            $this->getElement($name)->setIgnore(false);
        }

        // tweak label element to change label and hide input by default.
        $label = $this->getElement('label');
        $label->getDecorator('htmlTag')->setOption('style', 'display: none;');
        
        // hide the onClick element while editing menu items in the context of 
        // editing content.
        $onClick = $this->getElement('onClick');
        $onClick->getDecorator('htmlTag')->setOption('style', 'display: none;');
        $onClick->getDecorator('label')->setOption('style', 'display: none;');
        
        // tweak checkbox onChange behavior for content editing context.
        // show/hide the label field and update its value as appropriate.
        $this->getElement('autoLabel')->setAttrib(
            "onClick", 
            "
            var fieldset = new dojo.NodeList(this).closest('fieldset')[0];
            var label    = dojo.query('input[type=text][name*=\'label\']', fieldset)[0];
            if (this.anim && this.anim.status() != 'stopped') {
                this.anim.stop();
            }
            if (this.checked) {
                dojo.attr(label, 'disabled', true);
                this.anim = p4cms.ui.hide(label.parentNode);
            } else {
                // update title to match content title
                var subForm  = new dojo.NodeList(this).closest('[dojotype=p4cms.content.SubForm]')[0];
                subForm      = dijit.byNode(subForm);
                var title    = dojo.query('input[name=title]', subForm.getContentEntry().domNode)[0];
                label.value = title ? title.value : '';
                
                dojo.removeAttr(label, 'disabled');
                this.anim = p4cms.ui.show(label.parentNode);
            }
            "
        );
        
        // add a button to delete the menu item.
        $this->addElement(
            'checkbox',
            'remove',
            array(
                'label'     => "Remove",
                'order'     => -1000,
                'class'     => 'menu-item-remove',
                'onClick'  => "
                    var checkbox = this;
                    p4cms.ui.hide(
                        new dojo.NodeList(checkbox).closest('fieldset')[0],
                        {onEnd: function(){dojo.attr(checkbox, 'checked', true);}}
                    );
                "
            )
        );
        $element = $this->getElement('remove');
        $this->moveCheckboxLabel($element);
        $element->getDecorator('htmlTag')->setOption('class', 'menu-item-remove');
    }
Menu_Form_MenuItemContentQuick::isValid ( data)

Validate the form, if item is deleted, don't validate other fields.

Parameters:
array$datathe data to validate.
Returns:
boolean

Reimplemented from Menu_Form_MenuItem.

    {
        // dissolve a copy of data into a new values array so
        // we can find the remove element
        $values = $data;
        if ($this->isArray()) {
            $eBelongTo = $this->getElementsBelongTo();
            $values    = $this->_dissolveArrayValue($data, $eBelongTo);
        }

        // if we are doing a remove skip other checks
        if (isset($values['remove']) && $values['remove']) {
            return true;
        }
        
        return parent::isValid($data);
    }
Menu_Form_MenuItemContentQuick::setDefaults ( defaults)

Extends parent to hide label field if using content's title.

Parameters:
P4Cms_Record | array$defaultsthe default values to set on elements
Returns:
Zend_Form provides fluent interface

Reimplemented from Menu_Form_MenuItemContent.

    {
        parent::setDefaults($defaults);
        
        $this->getElement('label')->getDecorator('htmlTag')->setOption(
            'style', 
            $this->getValue('label') ? null : 'display: none;'
        );
        
        return $this;
    }

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