AdminPageFramework_Form_View___Script_RepeatableSection::getEnabler PHP Method

getEnabler() public static method

public static getEnabler ( $sContainerTagID, $iSectionCount, $aSettings, $oMsg )
    public static function getEnabler($sContainerTagID, $iSectionCount, $aSettings, $oMsg)
    {
        if (empty($aSettings)) {
            return '';
        }
        if (in_array($sContainerTagID, self::$_aSetContainerIDsForRepeatableSections)) {
            return '';
        }
        self::$_aSetContainerIDsForRepeatableSections[$sContainerTagID] = $sContainerTagID;
        new self($oMsg);
        $aSettings = self::getAsArray($aSettings) + array('min' => 0, 'max' => 0);
        $_sAdd = $oMsg->get('add_section');
        $_sRemove = $oMsg->get('remove_section');
        $_sVisibility = $iSectionCount <= 1 ? " style='display:none;'" : "";
        $_sSettingsAttributes = self::getDataAttributes($aSettings);
        $_sButtons = "<div class='admin-page-framework-repeatable-section-buttons' {$_sSettingsAttributes} >" . "<a class='repeatable-section-remove-button button-secondary repeatable-section-button button button-large' href='#' title='{$_sRemove}' {$_sVisibility} data-id='{$sContainerTagID}'>-</a>" . "<a class='repeatable-section-add-button button-secondary repeatable-section-button button button-large' href='#' title='{$_sAdd}' data-id='{$sContainerTagID}'>+</a>" . "</div>";
        $_sButtonsHTML = '"' . $_sButtons . '"';
        $_aJSArray = json_encode($aSettings);
        $_sScript = <<<JAVASCRIPTS
jQuery( document ).ready( function() {

    // Adds the buttons
    jQuery( '#{$sContainerTagID} .admin-page-framework-section-caption' ).each( function(){
        
        jQuery( this ).show();
        
        var _oButtons = jQuery( {$_sButtonsHTML} );
        if ( jQuery( this ).children( '.admin-page-framework-collapsible-section-title' ).children( 'fieldset' ).length > 0 ) {
            _oButtons.addClass( 'section_title_field_sibling' );
        }
        var _oCollapsibleSectionTitle = jQuery( this ).find( '.admin-page-framework-collapsible-section-title' );
        if ( _oCollapsibleSectionTitle.length ) {
            _oButtons.find( '.repeatable-section-button' ).removeClass( 'button-large' );
            _oCollapsibleSectionTitle.prepend( _oButtons );
        } else {
            jQuery( this ).prepend( _oButtons );
        }
        
    } );
    // Update the fields     
    jQuery( '#{$sContainerTagID}' ).updateAdminPageFrameworkRepeatableSections( {$_aJSArray} ); 
});            
JAVASCRIPTS;
        return "<script type='text/javascript' class='admin-page-framework-section-repeatable-script'>" . '/* <![CDATA[ */' . $_sScript . '/* ]]> */' . "</script>";
    }

Usage Example

 private function _getSubSections($_aOutputs, $_sSectionsID, $_aSection, $_aSubSections)
 {
     if (!empty($_aSection['repeatable'])) {
         $_aOutputs['section_contents'][] = AdminPageFramework_Form_View___Script_RepeatableSection::getEnabler($_sSectionsID, $_aOutputs['count_subsections'], $_aSection['repeatable'], $this->oMsg);
         $_aOutputs['section_contents'][] = $this->_getRepeatableSectionFlagTag($_aSection);
     }
     if (!empty($_aSection['sortable'])) {
         $_aOutputs['section_contents'][] = AdminPageFramework_Form_View___Script_SortableSection::getEnabler($_sSectionsID, $_aSection['sortable'], $this->oMsg);
         $_aOutputs['section_contents'][] = $this->_getSortableSectionFlagTag($_aSection);
     }
     $_aSubSections = $this->numerizeElements($_aSubSections);
     foreach ($_aSubSections as $_iIndex => $_aFields) {
         $_oEachSectionArguments = new AdminPageFramework_Form_Model___Format_EachSection($_aSection, $_iIndex, $_aSubSections, $_sSectionsID);
         $_aOutputs = $this->_getSectionTableWithTabList($_aOutputs, $_oEachSectionArguments->get(), $_aFields);
     }
     return $_aOutputs;
 }
AdminPageFramework_Form_View___Script_RepeatableSection