Przejdź do głównej treści
Kod
<?php

require_once(MOD_PATH . 'ADocuments/plugins/buttons/AbstractCustomStateButton.inc');

final class SageStateButton extends AbstractCustomStateButton
{

    protected static $cMethods = [
        'saveAndSend'
    ];

    public function getCallableMethods()
    {
        return self::$cMethods;
    }

    public static function saveAndSend($params = [])
    {

        $pData = JSON::toArray($params);
        $state = isset($pData['state']) ? $pData['state'] : FALSE;
        $parent = isset($pData['parent']) ? $pData['parent'] : FALSE;
        $dialog = isset($pData['dialog']) ? $pData['dialog'] : FALSE;
        $afterSubmit = isset($pData['afterSubmit']) ? $pData['afterSubmit'] : FALSE;

        $pData['state'] = 'fireStage';

        DialogForm::ssetSData($dialog, [__CLASS__ => $pData]);

        JScript::add('(function() {' . $afterSubmit . '})()');
    }

    public static function getSaveAndSendButton($data = [], $toHtml = TRUE)
    {

        $HWND = Application::registerClass(Application::makeRelativePath(__FILE__), __CLASS__);

        $pData = JSON::toArray($data);
        $state = isset($pData['state']) ? $pData['state'] : FALSE;
        $parent = isset($pData['parent']) ? $pData['parent'] : FALSE;
        $dialog = isset($pData['dialog']) ? $pData['dialog'] : FALSE;
        $afterSubmit = isset($pData['afterSubmit']) ? $pData['afterSubmit'] : FALSE;

        $saveAndSendButton = new StateButton($parent . 'saveAndSendButton');
        $saveAndSendButton->mainCaption = Translator::translate('Zapisz i wyślij');
        $saveAndSendButton->width = '180px';
        $saveAndSendButton->height = '100px';
        $saveAndSendButton->clearMoreMenu();

        if ($state == 'fireStage') {
            $state = 'saveAndSend';
            DialogForm::ssetSData($dialog, [__CLASS__ => NULL]);
        }

        if ($state == 'saveAndSend') {
            $saveAndSendStates = [
                'sendFile' => [
                    'icon' => 'save-as',
                    'caption' => Translator::translate('Zapisz i wyślij'),
                    'title' => Translator::translate('Kliknij aby zapisać dokument i wysłać'),
                    'onClick' => '$A1(\'' . $HWND . '\', \'\', ' . (int)array_search('saveAndSend', self::$cMethods) . ', ({state:\'saveAndSend\', parent:\'' . $parent . '\', dialog:\'' . $dialog . '\', afterSubmit:\'' . addslashes($afterSubmit) . '\'}).toJSONString(), \'\')'
                ]
            ];

            $saveAndSendButton->setStates($saveAndSendStates);
            $saveAndSendButton->selectState('sendFile');
        }

        return $saveAndSendButton;
    }

    public static function plug($parent, $data)
    {

        $dialog = $parent->getDialog();

        $sData = DialogForm::sgetSData($dialog->name);

        $state = 'saveAndSend';
        if (isset($sData[__CLASS__]['state'])) {
            $state = $sData[__CLASS__]['state'];
        }

        if ($state == 'fireStage') {
            $ptstid = 30; // OKREŚŁ ID ETAPU DO WYKONANIA            
            $dialog->on('save',
                function ($dialogObject, $documentBean) use ($ptstid) {
                    JScript::addAfter('App.openDialogByCls(\'P_WORKFLOW\', null, ({clsnam:\'DOCUMENT\', keyval:\'' . $documentBean->get('doc_id') . '\', ptstid:\'' . $ptstid . '\'}).toJSONString())');
                }
            );
        }

        $params = ['state' => $state, 'parent' => $parent->name, 'dialog' => $dialog->name, 'afterSubmit' => $dialog->onbSaveClick];

        $saveAndSendButton = self::getSaveAndSendButton($params, FALSE);

        return $saveAndSendButton;
    }
}