发表于 2020-12-16 10:03:16

二次开发- 修改界面-显示额外信息

本帖最后由 adminlily 于 2020-12-16 10:08 编辑

丰富显示对象先决条件:您必须熟悉教程中使用的语法 并且已经创建了一个扩展.
学习:在对象的显示屏上添加信息
水平:[ ttps://www.itophub.io/wiki/page?id=level&dataflt%5B0%5D=level_%3DIntermediate]中间
域:[ ttps://www.itophub.io/wiki/page?id=domains&dataflt%5B0%5D=domains_%3DPHP]PHP,[ ttps://www.itophub.io/wiki/page?id=domains&dataflt%5B0%5D=domains_%3DPresentation]Presentation
最低版本:2.1.0
https://www.itophub.io/lib/images/smileys/fixme.gif添加示例结果的屏幕截图。添加说明以显示各种示例及其带来的内容。
发送邮件团队成员
在此示例中,我们将特性添加到对象详细信息的现有选项卡中。我们希望供应可以直接在您的常用发送邮件发送邮件中打开新的发送邮件表单,并且团队成员已添加到TO字段中。
我们将只在显示团队成员的选项卡中添加一个mailto html链接,其中包含要使用的发送邮件地址的列表。当显示特定的对象时,处理显示关系选项卡的职能是DisplayBareRelations()
[ ttps://www.itophub.io/wiki/page?do=export_code&id=2_7_0%3Acustomization%3Adisplay-bare-relation&codeblock=0]class:Team
function DisplayBareRelations(WebPage $oPage, $bEditMode = false){// We call the parent class otherwise all relations tab will be missingparent::DisplayBareRelations($oPage, $bEditMode);// If your new behavior should be limited to the read mode (or not)if (!$bEditMode){    // We assume the Team class as a 'persons_list' attribute    $oToNotify = $this->Get('persons_list');    $aMailList = ();    while ($oContact = $oToNotify->Fetch()) {      $aMailList[] = $oContact->Get('email');    }    $sMailList = (', ', $aMailList);    if ($sMailList != '')    { // The oPage object contains multiple tabs      // We want to put our link on a particular tab known by its label      $sTabName = $oPage->FindTab('/^' . Dict::S
('Class:Team/Attribute:persons_list') . '/');      // Set that Tab as the current one      // If no Tab with that name exists, it creates a new one after the current
tab      $oPage->SetCurrentTab($sTabName);      // Add an hyperlink at the end of that tab      $sLink = "<br>&nbsp;<a href=\"mailto:?to={$sMailList}\">Open mailer</a>";      // As when writing on an oPage, it writes on the current tab      $oPage->Add($sLink);    }}};');}}
如果要分发扩展名,则应使用其他方法:

[*]APIiApplicationUIExtension 使用OnDisplayRelations()方法,
[*]或与功能的新菜单


显示适用于工单的KnownErrors
在此示例中,我们将向UserRequest显示添加一个选项卡。在此选项卡中,我们将显示相关的对象,但关系要比LinkedSet属性更复杂。
已知错误没有直接链接到iTop默认数据模型中的UserRequest,但是它们链接到FunctionalCI,而FunctionalCI链接到工单,因此,按照这两种关系,我们可以在UserRequest上提出可能适用于该工单的已知错误. .
如以上示例所示,我们将只编写一个PHP方法来丰富UserRequest类的显示。
[ ttps://www.itophub.io/wiki/page?do=export_code&id=2_7_0%3Acustomization%3Adisplay-bare-relation&codeblock=1]class:UserRequest
function DisplayBareRelations(WebPage $oPage, $bEditMode = false){   // Mandatory, to get the other tabs displayed as well   parent::DisplayBareRelations($oPage, $bEditMode);   // If the UserRequest is in Read mode    // and the KnownError option has been selected at iTop setup   if ((!$bEditMode) && (MetaModel::IsValidClass('KnownError')))   {      //Search for known errors related to FunctionalCI      // ...linked to current UserRequest      $iTicketID = $this->GetKey();      // We create a Search (definition) with an OQL      // Note {$iTicketID} in the OQL will be replaced by the true value      $oSearch = new DBObjectSearch::FromOQL("         SELECT KnownError AS ke          JOIN lnkErrorToFunctionalCI AS l1 ON l1.error_id=ke.id          JOIN FunctionalCI AS ci ON l1.functionalci_id=ci.id          JOIN lnkFunctionalCIToTicket AS l2 ON l2.functionalci_id=ci.id          WHERE l2.ticket_id={$iTicketID}");      // We get a set of Known Error objects, using the above Search      $oKnownErrorSet = new CMDBObjectSet($oSearch);      // Now that we have the Set we can count them      $iNumberKE = $oKnownErrorSet->();      // Here we have decided to always create a new Known Error tab      // but you could decide to display the tab only if there are some Known
Errors      if ($iNumberKE > 0)      {// here we use the standard iTop way to display tab with data inside         $oPage->SetCurrentTab(Dict::S('Class:UserRequest:KnownErrorList') . "
({$iNumberKE})");      } else {   // or without data inside with no brackets and no count         $oPage->SetCurrentTab(Dict::S('Class:UserRequest:KnownErrorList'));      }      // We create a Block made of the Known Error in a 'list' mode      // The Block just need a DBObjectSearch and not the Set itself      // GetFilter() retrieve that Search from the Set      $oBlock = new DisplayBlock($oKnownErrorSet->GetFilter(), 'list', false);      // 'menu' says if the list will offer a menu      // 'display_limit' says if we display in page mode or all objects at once      $aExtraParam = ('menu' => true, 'display_limit' => false);      // Display the block in the page with a Title (optional), and extra params      $oBlock->Display($oPage, Dict::S('Class:UserRequest:KnownErrorList'),
$aExtraParam);   }}您可以使用相同的方法来显示简单关系的过滤视图。例如,在“团队”类上,显示分配给该团队的“公开工单”。如果使用2.7.X及更低版本中的AttributeLinkedSetIndirect进行此操作,则无法过滤该列表,并且会减慢性能的速度。
从2.6.0版开始,可以使用AttributeDashboard
问题和答案
问题:我的对象没有完全显示,关系选项卡丢失了吗?
答:您是否一直在呼叫parent::DisplayBareRelations($oPage, $bEditMode);用你的方法?
问题:选项卡标题为Class:UserRequest:KnownErrorList,如何解决?
答:您必须定义一个字典条目 用于Class:UserRequest:KnownErrorList
在剪贴板中复制数据
本示例使用iTop中包含的Javascript库(从2.7.0开始):剪贴板
https://www.itophub.io/lib/images/smileys/fixme.gif粗略的例子,需要更多的工作…
[ ttps://www.itophub.io/wiki/page?do=export_code&id=2_7_0%3Acustomization%3Adisplay-bare-relation&codeblock=2]class:Organization
function DisplayBareRelations(WebPage $oPage, $bEditMode = false){parent::DisplayBareRelations($oPage, $bEditMode);if ((!$bEditMode){    $oPage->SetCurrentTab("Authorized users ($iCount)");    $oPage->table($aDisplayConfig, $aDisplayData);    $oSearch = DBObjectSearch::FromOQL("SELECT Organization WHERE (id=:org_id OR
managed_by_id=:org_id)");    $oSet = new DBObjectSet($oSearch, ('name' => true), ('org_id' => $this->GetKey
()));    $sOrgs ='';    while ($aRow = $oSet->FetchAssoc())    {      $oPerson = $aRow['Organization'];      // If not the first one, add the | separator      if ($sOrgs!='') $sOrgs = $sOrgs ."|";      $sOrgs = $sOrgs . "allowed_org_id:" . $oPerson->GetKey();    }    $oPage->Add("<p><input id='MyOrgs'value='{$sOrgs}'/>");    $oPage->add_linked_script
("//cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.4.0/clipboard.min.js");    $oPage->Add('<button class="button" id="copy-button" data-clipboard-
target="#MyOrgs">Copy</button><p>');    $oPage->add_ready_script('new Clipboard("#copy-button");');}}

页: [1]
查看完整版本: 二次开发- 修改界面-显示额外信息