diff --git a/application/ui.searchformforeignkeys.class.inc.php b/application/ui.searchformforeignkeys.class.inc.php new file mode 100644 index 000000000..93e511649 --- /dev/null +++ b/application/ui.searchformforeignkeys.class.inc.php @@ -0,0 +1,105 @@ + + * + */ + + +require_once(APPROOT.'/application/webpage.class.inc.php'); +require_once(APPROOT.'/application/displayblock.class.inc.php'); + +class UISearchFormForeignKeys +{ + public function __construct($sTargetClass, $iInputId, $sAttCode, $sSuffix) + { + $this->m_sRemoteClass = $sTargetClass; + $this->m_iInputId = $iInputId; + $this->sAttCode = $sAttCode; + $this->m_sNameSuffix = $sSuffix; + } + + /** + * @param WebPage $oPage + * + * @throws \CoreException + * @throws \DictExceptionMissingString + * @throws \Exception + */ + public function ShowModalSearchForeignKeys($oPage) + { + $bOpen = MetaModel::GetConfig()->Get('legacy_search_drawer_open'); + $sHtml = "
\n"; + + $oFilter = new DBObjectSearch($this->m_sRemoteClass); + + $oBlock = new DisplayBlock($oFilter, 'search', false); + $sHtml .= $oBlock->GetDisplay($oPage, "SearchFormToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}", + array( + 'open' => $bOpen, + 'menu' => false, + 'table_id' => "SearchResultsToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}", + 'table_id2' => 'add_'.$this->m_sAttCode, + 'table_inner_id' => "ResultsToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}", + 'selection_mode' => true, + 'cssCount' => '#count_'.$this->m_sAttCode.$this->m_sNameSuffix, + 'query_params' => $oFilter->GetInternalParams(), + )); + $sHtml .= "
m_sAttCode}{$this->m_sNameSuffix}\">\n"; + $sHtml .= "
m_sAttCode}{$this->m_sNameSuffix}\" style=\"vertical-align:top;background: #fff;height:100%;overflow:auto;padding:0;border:0;\">\n"; + $sHtml .= "

".Dict::S('UI:Message:EmptyList:UseSearchForm')."

\n"; + $sHtml .= "
\n"; + $sHtml .= "m_sAttCode}{$this->m_sNameSuffix}\" value=\"0\"/>"; + $sHtml .= "m_sAttCode}{$this->m_sNameSuffix}').dialog('close');\">  m_sAttCode}{$this->m_sNameSuffix}\" disabled=\"disabled\" type=\"button\" onclick=\"return oWidget{$this->m_iInputId}.DoAddObjects(this.id);\" value=\"".Dict::S('UI:Button:Add')."\">"; + $sHtml .= "
\n"; + $sHtml .= "\n"; + $oPage->add($sHtml); + $oPage->add_ready_script("$('#dlg_{$this->m_sAttCode}{$this->m_sNameSuffix}').dialog({ width: $(window).width()*0.8, height: $(window).height()*0.8, autoOpen: false, modal: true, resizeStop: oWidget{$this->m_iInputId}.UpdateSizes });"); + $oPage->add_ready_script("$('#dlg_{$this->m_sAttCode}{$this->m_sNameSuffix}').dialog('option', {title:'".addslashes(Dict::Format('UI:AddObjectsOf_Class_LinkedWith_Class', MetaModel::GetName($this->m_sLinkedClass), + MetaModel::GetName($this->m_sClass)))."'});"); + $oPage->add_ready_script("$('#SearchFormToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix} form').bind('submit.uilinksWizard', oWidget{$this->m_iInputId}.SearchObjectsToAdd);"); + $oPage->add_ready_script("$('#SearchFormToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}').resize(oWidget{$this->m_iInputId}.UpdateSizes);"); + } + + /** + * Search for objects to be linked to the current object (i.e "remote" objects) + * + * @param WebPage $oP The page used for the output (usually an AjaxWebPage) + * @param string $sRemoteClass Name of the "remote" class to perform the search on, must be a derived class of m_sRemoteClass + * + * @throws \Exception + */ + public function ListResultsSearchForeignKeys(WebPage $oP, $sRemoteClass = '') + { + if ($sRemoteClass != '') + { + // assert(MetaModel::IsParentClass($this->m_sRemoteClass, $sRemoteClass)); + $oFilter = new DBObjectSearch($sRemoteClass); + } + else + { + // No remote class specified use the one defined in the linkedset + $oFilter = new DBObjectSearch($this->m_sRemoteClass); + } + + $oBlock = new DisplayBlock($oFilter, 'list', false); + $oBlock->Display($oP, "ResultsToAdd_{$this->m_sAttCode}", + array('menu' => false, 'cssCount' => '#count_'.$this->m_sAttCode.$this->m_sNameSuffix, 'selection_mode' => true, 'table_id' => 'add_'.$this->m_sAttCode)); + } + +} \ No newline at end of file diff --git a/pages/ajax.render.php b/pages/ajax.render.php index df3a17236..fe99941d7 100644 --- a/pages/ajax.render.php +++ b/pages/ajax.render.php @@ -250,6 +250,28 @@ try $oPage->add($bRet ? 'Ok' : 'KO'); break; + // ui.searchformforeignkeys + case 'ShowModalSearchForeignKeys': + $oPage->SetContentType('text/html'); + $sAttCode = utils::ReadParam('sAttCode', ''); + $iInputId = utils::ReadParam('iInputId', ''); + $sSuffix = utils::ReadParam('sSuffix', ''); + $oWidget = new UISearchFormForeignKeys($sClass, $iInputId, $sAttCode, $sSuffix); + $oWidget->ShowModalSearchForeignKeys($oPage); + break; + + // ui.searchformforeignkeys + case 'ListResultsSearchForeignKeys': + $oPage->SetContentType('text/html'); + $sTargetClass = utils::ReadParam('sTargetClass', '', false, 'class'); + $iInputId = utils::ReadParam('iInputId', ''); + $sTitle = utils::ReadParam('sTitle', '', false, 'raw_data'); + $sSuffix = utils::ReadParam('sSuffix', ''); + $sAttCode = utils::ReadParam('sAttCode', ''); + $oWidget = new UISearchFormForeignKeys($sTargetClass, $iInputId, $sAttCode, $sSuffix); + $oWidget->GetSearchDialog($oPage, $sTitle); + break; + // ui.linkswidget case 'addObjects': $oPage->SetContentType('text/html');