|
@@ -14,7 +14,7 @@
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
/**
|
|
|
- * Class UIAutoCompleteWidget
|
|
|
+ * Class UIExtKeyWidget
|
|
|
* UI wdiget for displaying and editing external keys when
|
|
|
* A simple drop-down list is not enough...
|
|
|
*
|
|
@@ -61,7 +61,7 @@
|
|
|
require_once(APPROOT.'/application/webpage.class.inc.php');
|
|
|
require_once(APPROOT.'/application/displayblock.class.inc.php');
|
|
|
|
|
|
-class UIAutoCompleteWidget
|
|
|
+class UIExtKeyWidget
|
|
|
{
|
|
|
protected static $iWidgetIndex = 0;
|
|
|
protected $sAttCode;
|
|
@@ -69,7 +69,7 @@ class UIAutoCompleteWidget
|
|
|
protected $iId;
|
|
|
protected $sTitle;
|
|
|
|
|
|
- public function __construct($sAttCode, $sClass, $sTitle, $aAllowedValues, $value, $iInputId, $sNameSuffix = '', $sFieldPrefix = '', $sFormPrefix = '')
|
|
|
+ public function __construct($sAttCode, $sClass, $sTitle, $aAllowedValues, $value, $iInputId, $bMandatory, $sNameSuffix = '', $sFieldPrefix = '', $sFormPrefix = '')
|
|
|
{
|
|
|
self::$iWidgetIndex++;
|
|
|
$this->sAttCode = $sAttCode;
|
|
@@ -83,6 +83,7 @@ class UIAutoCompleteWidget
|
|
|
$this->sTargetClass = $this->oAttDef->GetTargetClass();
|
|
|
$this->sTitle = $sTitle;
|
|
|
$this->sFormPrefix = $sFormPrefix;
|
|
|
+ $this->bMandatory = $bMandatory;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -93,50 +94,74 @@ class UIAutoCompleteWidget
|
|
|
*/
|
|
|
public function Display(WebPage $oPage, $aArgs = array())
|
|
|
{
|
|
|
- if ($this->oAttDef->IsNull($this->value)) // Null values are displayed as ''
|
|
|
+ $bCreate = (UserRights::IsActionAllowed($this->sTargetClass, UR_ACTION_BULK_MODIFY) && $this->oAttDef->AllowTargetCreation());
|
|
|
+ if (count($this->aAllowedValues) < $this->oAttDef->GetMaximumComboLength())
|
|
|
{
|
|
|
- $sDisplayValue = '';
|
|
|
+ // Few choices, use a normal 'select'
|
|
|
+ $sSelectMode = 'true';
|
|
|
+ // In case there are no valid values, the select will be empty, thus blocking the user from validating the form
|
|
|
+ $sHTMLValue = "<select title=\"$sHelpText\" name=\"attr_{$this->sFieldPrefix}{$this->sAttCode}{$this->sNameSuffix}\" id=\"$this->iId\">\n";
|
|
|
+ $sHTMLValue .= "<option value=\"\">".Dict::S('UI:SelectOne')."</option>\n";
|
|
|
+ foreach($this->aAllowedValues as $key => $display_value)
|
|
|
+ {
|
|
|
+ if ((count($this->aAllowedValues) == 1) && ($this->bMandatory == 'true') )
|
|
|
+ {
|
|
|
+ // When there is only once choice, select it by default
|
|
|
+ $sSelected = ' selected';
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $sSelected = ($this->value == $key) ? ' selected' : '';
|
|
|
+ }
|
|
|
+ $sHTMLValue .= "<option value=\"$key\"$sSelected>$display_value</option>\n";
|
|
|
+ }
|
|
|
+ $sHTMLValue .= "</select>\n";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- $sDisplayValue = $this->GetObjectName($this->value);
|
|
|
- }
|
|
|
- $bCreate = UserRights::IsActionAllowed($this->sTargetClass, UR_ACTION_BULK_MODIFY);
|
|
|
- $sMessage = Dict::S('UI:Message:EmptyList:UseSearchForm');
|
|
|
- $sFormPrefix = $this->sFormPrefix;
|
|
|
- $oPage->add_ready_script(
|
|
|
-<<<EOF
|
|
|
- oACWidget_{$this->iId} = new AutocompleteWidget('$this->iId', '$this->sClass', '$this->sAttCode', '$this->sNameSuffix', oWizardHelper$sFormPrefix);
|
|
|
- oACWidget_{$this->iId}.emptyHtml = "<div style=\"background: #fff; border:0; text-align:center; vertical-align:middle;\"><p>$sMessage</p></div>";
|
|
|
-EOF
|
|
|
-);
|
|
|
- $iMinChars = $this->oAttDef->GetMinAutoCompleteChars();
|
|
|
- $iFieldSize = $this->oAttDef->GetMaxSize();
|
|
|
+ // Too many choices, use an autocomplete
|
|
|
+ $sSelectMode = 'false';
|
|
|
+
|
|
|
+ if ($this->oAttDef->IsNull($this->value)) // Null values are displayed as ''
|
|
|
+ {
|
|
|
+ $sDisplayValue = '';
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $sDisplayValue = $this->GetObjectName($this->value);
|
|
|
+ }
|
|
|
+ $sMessage = Dict::S('UI:Message:EmptyList:UseSearchForm');
|
|
|
+ $sFormPrefix = $this->sFormPrefix;
|
|
|
+ $iMinChars = $this->oAttDef->GetMinAutoCompleteChars();
|
|
|
+ $iFieldSize = $this->oAttDef->GetMaxSize();
|
|
|
+
|
|
|
+ // the input for the auto-complete
|
|
|
+ $sHTMLValue = "<input count=\"".count($this->aAllowedValues)."\" type=\"text\" id=\"label_$this->iId\" size=\"30\" maxlength=\"$iFieldSize\" value=\"$sDisplayValue\"/> ";
|
|
|
+ $sHTMLValue .= "<a class=\"no-arrow\" href=\"javascript:oACWidget_{$this->iId}.Search();\"><img style=\"border:0;vertical-align:middle;\" src=\"../images/mini_search.gif\" /></a> ";
|
|
|
+
|
|
|
+ // another hidden input to store & pass the object's Id
|
|
|
+ $sHTMLValue .= "<input type=\"hidden\" id=\"$this->iId\" name=\"attr_{$this->sFieldPrefix}{$this->sAttCode}{$this->sNameSuffix}\" value=\"$this->value\" />\n";
|
|
|
+
|
|
|
+ // Scripts to start the autocomplete and bind some events to it
|
|
|
+ $oPage->add_ready_script("\$('#label_$this->iId').autocomplete('./ajax.render.php', { scroll:true, minChars:{$iMinChars}, formatItem:formatItem, autoFill:false, matchContains:true, keyHolder:'#{$this->iId}', extraParams:{operation:'autocomplete', sclass:'$this->sClass',attCode:'".$this->sAttCode."'}});");
|
|
|
+ $oPage->add_ready_script("\$('#label_$this->iId').blur(function() { $(this).search(); } );");
|
|
|
+ $oPage->add_ready_script("\$('#label_$this->iId').result( function(event, data, formatted) { OnAutoComplete('$this->iId', event, data, formatted); } );");
|
|
|
+ $oPage->add_ready_script("\$('#ac_dlg_$this->iId').dialog({ width: $(window).width()*0.8, height: $(window).height()*0.8, autoOpen: false, modal: true, title: '$this->sTitle', resizeStop: oACWidget_{$this->iId}.UpdateSizes, close: oACWidget_{$this->iId}.OnClose });\n");
|
|
|
+ $oPage->add_at_the_end($this->GetSearchDialog($oPage)); // To prevent adding forms inside the main form
|
|
|
|
|
|
- // the input for the auto-complete
|
|
|
- $sHTMLValue = "<input count=\"".count($this->aAllowedValues)."\" type=\"text\" id=\"label_$this->iId\" size=\"30\" maxlength=\"$iFieldSize\" value=\"$sDisplayValue\"/> ";
|
|
|
- $sHTMLValue .= "<a class=\"no-arrow\" href=\"javascript:oACWidget_{$this->iId}.Search();\"><img style=\"border:0;vertical-align:middle;\" src=\"../images/mini_search.gif\" /></a> ";
|
|
|
+ }
|
|
|
if ($bCreate)
|
|
|
{
|
|
|
$sHTMLValue .= "<a class=\"no-arrow\" href=\"javascript:oACWidget_{$this->iId}.CreateObject();\"><img style=\"border:0;vertical-align:middle;\" src=\"../images/mini_add.gif\" /></a> ";
|
|
|
+ $oPage->add_at_the_end('<div id="ajax_'.$this->iId.'"></div>');
|
|
|
}
|
|
|
$sHTMLValue .= "<span id=\"v_{$this->iId}\"></span>";
|
|
|
-
|
|
|
- // another hidden input to store & pass the object's Id
|
|
|
- $sHTMLValue .= "<input type=\"hidden\" id=\"$this->iId\" name=\"attr_{$this->sFieldPrefix}{$this->sAttCode}{$this->sNameSuffix}\" value=\"$this->value\" />\n";
|
|
|
-
|
|
|
- // Scripts to start the autocomplete and bind some events to it
|
|
|
- $oPage->add_ready_script("\$('#label_$this->iId').autocomplete('./ajax.render.php', { scroll:true, minChars:{$iMinChars}, formatItem:formatItem, autoFill:false, matchContains:true, keyHolder:'#{$this->iId}', extraParams:{operation:'autocomplete', sclass:'$this->sClass',attCode:'".$this->sAttCode."'}});");
|
|
|
- $oPage->add_ready_script("\$('#label_$this->iId').blur(function() { $(this).search(); } );");
|
|
|
- $oPage->add_ready_script("\$('#label_$this->iId').result( function(event, data, formatted) { OnAutoComplete('$this->iId', event, data, formatted); } );");
|
|
|
- $oPage->add_ready_script("\$('#ac_dlg_$this->iId').dialog({ width: $(window).width()*0.8, height: $(window).height()*0.8, autoOpen: false, modal: true, title: '$this->sTitle', resizeStop: oACWidget_{$this->iId}.UpdateSizes, close: oACWidget_{$this->iId}.OnClose });\n");
|
|
|
- $oPage->add_ready_script("\$('#ac_create_$this->iId').dialog({ width: $(window).width()*0.8, height: $(window).height()*0.8, autoOpen: false, modal: true, title: '$this->sTitle'});\n");
|
|
|
- $oPage->add_at_the_end($this->GetSearchDialog($oPage)); // To prevent adding forms inside the main form
|
|
|
- if ($bCreate)
|
|
|
- {
|
|
|
- $oPage->add_at_the_end($this->GetCreationDialog($oPage)); // To prevent adding forms inside the main form
|
|
|
- }
|
|
|
-
|
|
|
+ $oPage->add_ready_script(
|
|
|
+<<<EOF
|
|
|
+ oACWidget_{$this->iId} = new ExtKeyWidget('$this->iId', '$this->sClass', '$this->sAttCode', '$this->sNameSuffix', $sSelectMode, oWizardHelper{$this->sFormPrefix});
|
|
|
+ oACWidget_{$this->iId}.emptyHtml = "<div style=\"background: #fff; border:0; text-align:center; vertical-align:middle;\"><p>$sMessage</p></div>";
|
|
|
+EOF
|
|
|
+);
|
|
|
return $sHTMLValue;
|
|
|
}
|
|
|
|
|
@@ -163,23 +188,6 @@ EOF
|
|
|
return $sHTML;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- protected function GetCreationDialog(WebPage $oPage)
|
|
|
- {
|
|
|
- $sHTML = '<div id="ac_create_'.$this->iId.'"><div class="wizContainer" style="vertical-align:top;"><div id="dcr_'.$this->iId.'">';
|
|
|
-
|
|
|
- //$sHTML .= "<form id=\"fcr_{$this->iId}\" OnSubmit=\"return oACWidget_{$this->iId}.DoCreate();\">\n";
|
|
|
- //cmdbAbstractObject::DisplayCreationForm($oPage, 'Person', null, array());
|
|
|
- //$sHTML .= "<input type=\"button\" id=\"btn_create_cancel_{$this->iId}\" value=\"".Dict::S('UI:Button:Cancel')."\" onClick=\"$('#ac_create_{$this->iId}').dialog('close');\"> ";
|
|
|
- //$sHTML .= "<input type=\"button\" id=\"btn_create_ok_{$this->iId}\" value=\"".Dict::S('UI:Button:New')."\" onClick=\"oACWidget_{$this->iId}.DoCreate();\">";
|
|
|
- //$sHTML .= "</form>\n";
|
|
|
- $sHTML .= '</div></div></div>';
|
|
|
-
|
|
|
- //$oPage->add_ready_script("$('#dc_{$this->iId}').resize(oACWidget_{$this->iId}.UpdateSizes);");
|
|
|
-
|
|
|
- return $sHTML;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Search for objects to be selected
|
|
|
* @param WebPage $oP The page used for the output (usually an AjaxWebPage)
|
|
@@ -218,8 +226,11 @@ EOF
|
|
|
*/
|
|
|
public function GetObjectCreationForm(WebPage $oPage)
|
|
|
{
|
|
|
+ $oPage->add('<div id="ac_create_'.$this->iId.'"><div class="wizContainer" style="vertical-align:top;"><div id="dcr_'.$this->iId.'">');
|
|
|
$oPage->add("<h1>".MetaModel::GetClassIcon($this->sTargetClass)." ".Dict::Format('UI:CreationTitle_Class', MetaModel::GetName($this->sTargetClass))."</h1>\n");
|
|
|
cmdbAbstractObject::DisplayCreationForm($oPage, $this->sTargetClass, null, array(), array('formPrefix' => $this->iId, 'noRelations' => true));
|
|
|
+ $oPage->add('</div></div></div>');
|
|
|
+ $oPage->add_ready_script("\$('#ac_create_$this->iId').dialog({ width: $(window).width()*0.8, height: 'auto', autoOpen: false, modal: true, title: '$this->sTitle'});\n");
|
|
|
$oPage->add_ready_script("$('#dcr_{$this->iId} form').removeAttr('onsubmit');");
|
|
|
$oPage->add_ready_script("$('#dcr_{$this->iId} form').bind('submit.uilinksWizard', oACWidget_{$this->iId}.DoCreateObject);");
|
|
|
}
|