HomeHelpTrac

Changeset 15719 for trunk/templates


Ignore:
Timestamp:
12/01/11 01:57:07 (6 months ago)
Author:
Alexander Trofimov
Message:

Grid - automated activation/deactivation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/templates/base/scripts/BxBaseGrid.php

    r15716 r15719  
    6363            ),             
    6464            $iAffected ? array() : array('msg' => _t("_sys_grid_delete_failed"))  
     65        )); 
     66    } 
     67 
     68    public function performActionEnable() { 
     69 
     70        $iAffected = 0; 
     71        $aIds = bx_get('ids'); 
     72        if (!$aIds || !is_array($aIds)) { 
     73            $this->_echoResultJson(array()); 
     74            exit; 
     75        } 
     76 
     77        foreach ($aIds as $mixedId) 
     78            $iAffected += $this->_enable($mixedId, (int)bx_get('checked')) ? 1 : 0; 
     79 
     80        $sAction = (int)bx_get('checked') ? 'enable' : 'disable'; 
     81        echo $this->_echoResultJson(array( 
     82            $sAction => $aIds, 
    6583        )); 
    6684    } 
     
    233251     */ 
    234252    protected function _isRowDisabled($aRow) { 
     253        if (isset($aRow[$this->_aOptions['field_active']]) && !$this->_switcherState2Checked($aRow[$this->_aOptions['field_active']])) 
     254            return true; 
    235255        return false; 
    236256    } 
     
    246266 
    247267    /** 
    248      * Is checkbox is checked by default ? 
     268     * Is checkbox checked by default ? 
    249269     * By default no one checkbox is selected. 
    250270     * @return boolean 
     
    252272    protected function _isCheckboxSelected($mixedValue, $sKey, $aField, $aRow) { 
    253273        return false; 
     274    } 
     275 
     276    /** 
     277     * Is switcher on by default ? 
     278     * By default no one switcher is on. 
     279     * @return boolean 
     280     */ 
     281    protected function _isSwitcherOn($mixedValue, $sKey, $aField, $aRow) { 
     282        return $this->_switcherState2Checked($mixedValue); 
     283    } 
     284 
     285    /** 
     286     * Convert switcher checked status to the actual value ? 
     287     * @return boolean 
     288     */ 
     289    protected function _switcherChecked2State($isChecked) { 
     290        return $isChecked ? 1 : 0; 
     291    } 
     292 
     293    /** 
     294     * Convert switcher value to checked(boolean) value ? 
     295     * @return boolean 
     296     */ 
     297    protected function _switcherState2Checked($mixedState) { 
     298        return $mixedState ? true : false; 
    254299    } 
    255300 
     
    305350        $sVal = $aRow[$this->_aOptions['field_id']]; 
    306351        return '<td ' . $sAttr . '><input type="checkbox" name="'. $this->_sObject . '_check" value="' . $sVal . '" ' . $sDisabled . ' ' . $sSelected . '/></td>';  
     352    } 
     353 
     354    protected function _getCellSwitcher ($mixedValue, $sKey, $aField, $aRow) { 
     355        $sAttr = $this->_convertAttrs( 
     356            $aField, 'attr_cell', 
     357            'bx-def-padding-sec-bottom bx-def-padding-sec-top', // add default classes 
     358            isset($aField['width']) ? 'width:' . $aField['width'] : false  // add default styles 
     359        ); 
     360 
     361        bx_import('BxTemplFormView'); 
     362        $oForm = new BxTemplFormView(array()); 
     363        $oForm->addCssJs(); 
     364        $aInput = array( 
     365            'type' => 'switcher', 
     366            'name' => $this->_sObject . '_switch_' . $aRow[$this->_aOptions['field_id']], 
     367            'caption' => '', 
     368            'attrs' => array ( 
     369                'bx_grid_action_single' => 'enable', 
     370                'bx_grid_action_confirm' => '', 
     371                'bx_grid_action_data' => $aRow[$this->_aOptions['field_id']], 
     372            ), 
     373            'value' => $aRow[$this->_aOptions['field_id']], 
     374            'checked' => $this->_isSwitcherOn(isset($aRow[$this->_aOptions['field_active']]) ? $aRow[$this->_aOptions['field_active']] : false, $sKey, $aField, $aRow), 
     375        ); 
     376        $sSwitcher = $oForm->genInput($aInput); 
     377        return '<td ' . $sAttr . '>' . $sSwitcher . '</td>';  
    307378    } 
    308379 
     
    413484    } 
    414485 
     486    protected function _enable ($mixedId, $isChecked) { 
     487        $oDb = BxDolDb::getInstance(); 
     488        $sTable = $this->_aOptions['table']; 
     489        $sFieldId = $this->_aOptions['field_id']; 
     490        $sFieldActive = $this->_aOptions['field_active']; 
     491        $sQuery = $oDb->prepare("UPDATE `{$sTable}` SET `$sFieldActive` = ? WHERE `{$sFieldId}` = ?", $this->_switcherChecked2State($isChecked), $mixedId);         
     492        return $oDb->query($sQuery); 
     493    } 
     494 
    415495    protected function _addJsCss() { 
    416496 
Note: See TracChangeset for help on using the changeset viewer.