示例#1
0
 public function GetSiloSelectionForm()
 {
     // List of visible Organizations
     $iCount = 0;
     $oSet = null;
     if (MetaModel::IsValidClass('Organization')) {
         // Display the list of *favorite* organizations... but keeping in mind what is the real number of organizations
         $aFavoriteOrgs = appUserPreferences::GetPref('favorite_orgs', null);
         $oSearchFilter = new DBObjectSearch('Organization');
         $oSearchFilter->SetModifierProperty('UserRightsGetSelectFilter', 'bSearchMode', true);
         $oSet = new CMDBObjectSet($oSearchFilter);
         $iCount = $oSet->Count();
         // total number of existing Orgs
         // Now get the list of Orgs to be displayed in the menu
         $oSearchFilter = DBObjectSearch::FromOQL(ApplicationMenu::GetFavoriteSiloQuery());
         $oSearchFilter->SetModifierProperty('UserRightsGetSelectFilter', 'bSearchMode', true);
         if (!empty($aFavoriteOrgs)) {
             $oSearchFilter->AddCondition('id', $aFavoriteOrgs, 'IN');
         }
         $oSet = new CMDBObjectSet($oSearchFilter);
         // List of favorite orgs
     }
     switch ($iCount) {
         case 0:
             // No such dimension/silo => nothing to select
             $sHtml = '<div id="SiloSelection"><!-- nothing to select --></div>';
             break;
         case 1:
             // Only one possible choice... no selection, but display the value
             $oOrg = $oSet->Fetch();
             $sHtml = '<div id="SiloSelection">' . $oOrg->GetName() . '</div>';
             $sHtml .= '';
             break;
         default:
             $sHtml = '';
             $oAppContext = new ApplicationContext();
             $iCurrentOrganization = $oAppContext->GetCurrentValue('org_id');
             $sHtml = '<div id="SiloSelection">';
             $sHtml .= '<form style="display:inline" action="' . utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php">';
             //<select class="org_combo" name="c[org_id]" title="Pick an organization" onChange="this.form.submit();">';
             $sFavoriteOrgs = '';
             $oWidget = new UIExtKeyWidget('Organization', 'org_id', '', true);
             $sHtml .= $oWidget->Display($this, 50, false, '', $oSet, $iCurrentOrganization, 'org_id', false, 'c[org_id]', '', array('iFieldSize' => 20, 'iMinChars' => MetaModel::GetConfig()->Get('min_autocomplete_chars'), 'sDefaultValue' => Dict::S('UI:AllOrganizations')), null, 'select', false);
             $this->add_ready_script('$("#org_id").bind("extkeychange", function() { $("#SiloSelection form").submit(); } )');
             $this->add_ready_script("\$('#label_org_id').click( function() { \$(this).val(''); \$('#org_id').val(''); return true; } );\n");
             // Add other dimensions/context information to this form
             $oAppContext->Reset('org_id');
             // org_id is handled above and we want to be able to change it here !
             $oAppContext->Reset('menu');
             // don't pass the menu, since a menu may expect more parameters
             $sHtml .= $oAppContext->GetForForm();
             // Pass what remains, if anything...
             $sHtml .= '</form>';
             $sHtml .= '</div>';
     }
     return $sHtml;
 }