如何 post table gui 的选定列到我在 Ilias 中的主 gui?

How to post the selected column of a table gui to my main gui in Ilias?

我目前正在为 Ilias 开发一个插件,我想在模态中有一个 table,每列都有一个单选按钮,在按下 "save"-按钮后,我想要为我的保存功能编辑所选列的 ID post。

我正在处理的问题是,保存按钮必须在模态页脚中(往返模态的约定,实际上比命令按钮漂亮得多),所以我不能使用 addCommandButton table.

的功能

我的主 GUI 中有这样的代码 class:

$modal = $factory->modal()
        ->roundtrip("title"), $this->getModalContent()
        ->withActionButtons([
            $factory->button()->standard("save", $this->ctrl->getLinkTargetByClass(myGUIClass::class, "save"))
        ]);
$modalbutton = $factory->button()->standard("open modal", "")->withOnClick($modal->getShowSignal());
$mytemplate->setVariable("SOMEVARIABLE", $renderer->render([$modalbutton, $modal]));

并且 getModalContent 函数做了一些事情然后请求 table html:

$tab = new ilMyGUIClassModalTableGUI($this, "parentCmd");
$html = $tab->getHTML();

$modalContent = $factory->legacy($html);
return $modalContent;

table GUI class 看起来像这样:

 function __construct($a_parent_obj, $a_parent_cmd)
 {
     global $DIC;

     $this->ctrl = $DIC->ctrl();
     $this->lng = $DIC->language();
     $this->access = $DIC->access();
     $this->user = $DIC->user();

     $ilUser = $DIC->user();

     $this->parent_obj = $a_parent_obj;
     $this->cur_id = //an_arbitrary_old_id;

     parent::__construct($a_parent_obj, $a_parent_cmd);
     $this->setData($this->getData());
     $this->setTitle("some title");
     $this->setLimit(9999);

     $this->addColumn("", "", "", true);
     $this->addColumn("column1");
     $this->addColumn("column2");

     $this->setEnableHeader(true);
     $this->setRowTemplate("tpl.template.html", "tplPath");
     $this->disable("footer");
     $this->setEnableTitle(true);

     $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
 }

 function getData()
 {
     return //an array with id, value_column_1, value_column_2;
 }

 protected function fillRow($a_set)
 {
     if ($this->cur_id == $a_set["id"])
     {
         $this->tpl->setVariable("CHECKED", "checked='checked'");
     }

     $this->tpl->setVariable("ID", $a_set["id"]);
     $this->tpl->setVariable("COLUMN1", $a_set["column1"]);
     $this->tpl->setVariable("COLUMN2", $a_set["column2"]);
     $this->ctrl->setParameter($this->parent_obj, "my_postvar", $a_set["id"]);
 }

当我现在点击保存按钮时,它只会获取最后设置的参数,而不是我在 $_GET 变量中选择的列之一。

是否有可能将所选列包含在 post 变量中,或者如果没有,如何为我的主 gui class 正确设置 get 变量?

非常感谢!

好问题,我最初以某种方式错过了它,但迟到总比不到好 ;-)。

这里的问题是,UI 组件中还没有可用于此场景的 Table 实现。正如您刚刚发现的那样,旧的 table 实现不能与模式一起顺利工作。

您的 table 所做的是创建表单,以便通过表单提交按钮(在您的例子中,是通过 addCommandButton 添加的按钮)发布您的值。但是,由于您不想要该按钮,因此您需要解决这个问题。在现代浏览器中,您可以通过使用属性表单在表单外设置提交按钮来解决问题,但是您仍然有问题将其应用到模态中。

所以我建议你做的是向模型的按钮添加一些 JS,阅读提交时发布的表单 (tables) 值)。看起来像:

$modal = $factory->modal()
        ->roundtrip("title"), $this->getModalContent()
        ->withActionButtons([
            $factory->button()->standard("save", "#")
            ->withOnLoadCode(function($id) {
              return "$(\"#$id\").click(function({
                        $(\"#$id_of_your_tables_form\").submit();
                     });";
        })
]); 

请注意,table 的 getId() 函数可能会帮助您找到 table 的 ID。如果不是,使用任何选择器在 dom.

中找到 tables 形式