lekoala / silverstripe-pure-modal

为SilverStripe设计的简单模态框(在管理界面也适用!)

资助包维护!
lekoala

安装次数 5,904

依赖项: 0

建议者: 0

安全性: 0

星级: 10

关注者: 5

分支: 2

开放问题: 0

类型:silverstripe-vendormodule

1.2.0 2023-07-28 14:38 UTC

This package is auto-updated.

Last update: 2024-08-28 18:23:10 UTC


README

Build Status scrutinizer Code coverage

简介

为SilverStripe设计的简单模态框(在管理界面也适用!)

示例用法

只需将要在模态框中显示的内容传递给模态框。模态框将通过字段集中的按钮访问。

如果您想显示表单等,您还可以在模态框内设置iframe。

$myHtmlContent = "<p>Some content here</p>";
$ImportStuff = new PureModal('ImportStuff', 'Import Stuff', $myHtmlContent);
$fields->addFieldToTab('Root.Stuff', $ImportStuff);
$ImportStuff->setIframeAction('import_stuff');
$ImportStuff->setIframeTop(true);

以下是一个示例 import_stuff 方法

public function import_stuff(HTTPRequest $req)
{
    $Stuff = $this->getRequestedRecord();
    $fields = new FieldList([
        new FileField('File'),
        new HiddenField('StuffID', null, $Stuff->ID),
    ]);
    $actions = new FieldList([
        new FormAction('doUpload', 'Upload')
    ]);
    $form = new Form(Controller::curr(), 'MyForm', $fields, $actions);

    return PureModal::renderDialog($this, ['Form' => $form]);
}

模态操作

此功能需要我的 cms-actions 模块。

    public function getCMSActions()
    {
        $actions = parent::getCMSActions();
        $doDeny = new PureModalAction("doDeny", "Deny");
        $predefinedText = <<<TEXT
Dear Customer,

Your request has been denied.

Best regards,
TEXT;
        $iframeFields = new FieldList([
            new DropdownField("SelectReason", "Select reason"),
            new TextareaField("EnterText", "Enter custom text", $predefinedText),
        ]);
        $doDeny->setFieldList($iframeFields);
        $doDeny->setShouldRefresh(true);
        $doDeny->setDialogButtonTitle('Deny the request'); // customised modal submit button
        $actions->push($doDeny);
    }

它创建了一个按钮,该按钮打开一个包含一系列字段的模态框。这些字段将与表单一起提交。

    public function doDeny($data)
    {
        $this->DeniedReason = $data['EnterText'];
        $this->Status = "denied";
        $this->write();
        return 'Denied';
    }

您可以从模态框本身中删除提交按钮,例如,使其仅作为信息窗口。通过这样做

    public function getCMSActions()
    {
        $actions = parent::getCMSActions();
        $doDeny = new PureModalAction("noopInfo", "Information");

        // .. add fields

        $doDeny->setShowDialogButton(false);
        $actions->push($doDeny);
    }

兼容性

已测试与^5版本

维护者

LeKoala - thomas@lekoala.be