diff --git a/application/ui.extkeywidget.class.inc.php b/application/ui.extkeywidget.class.inc.php index 22f12f736..15871a260 100644 --- a/application/ui.extkeywidget.class.inc.php +++ b/application/ui.extkeywidget.class.inc.php @@ -5,6 +5,7 @@ */ use Combodo\iTop\Application\UI\Base\Component\Form\FormUIBlockFactory; +use Combodo\iTop\Application\UI\Base\Component\Input\InputUIBlockFactory; use Combodo\iTop\Application\UI\Base\Layout\UIContentBlockUIBlockFactory; use Combodo\iTop\Core\MetaModel\FriendlyNameType; @@ -323,12 +324,12 @@ EOF EOF ); $sHTMLValue .= "
"; $sHTMLValue .= ""; @@ -904,7 +905,7 @@ JS { // For security reasons: check that the "proposed" class is actually a subclass of the linked class // and that the current user is allowed to create objects of this class - $aSubClasses = MetaModel::EnumChildClasses($this->sTargetClass); + $aSubClasses = MetaModel::EnumChildClasses($this->sTargetClass, ENUM_CHILD_CLASSES_ALL); $aPossibleClasses = array(); foreach($aSubClasses as $sCandidateClass) { @@ -924,6 +925,7 @@ JS $sDialogTitleEscaped = addslashes($sDialogTitle); $oPage->add_ready_script("$('#ac_create_$this->iId').dialog({ width: 'auto', height: 'auto', maxHeight: $(window).height() - 50, autoOpen: false, modal: true, title: '$sDialogTitleEscaped'});\n"); $oPage->add_ready_script("$('#ac_create_{$this->iId} form').removeAttr('onsubmit');"); + $oPage->add_ready_script("$('#ac_create_{$this->iId} form').find('select').attr('id', 'ac_create_{$this->iId}_select');"); $oPage->add_ready_script("$('#ac_create_{$this->iId} form').on('submit.uilinksWizard', oACWidget_{$this->iId}.DoSelectObjectClass);"); } diff --git a/css/backoffice/components/_field.scss b/css/backoffice/components/_field.scss index 736a756b3..daa40251e 100644 --- a/css/backoffice/components/_field.scss +++ b/css/backoffice/components/_field.scss @@ -253,3 +253,6 @@ $ibo-field--enable-bulk--checkbox--margin-left: $ibo-spacing-300 !default; margin-left: $ibo-field--enable-bulk--checkbox--margin-left; } +.ibo-input-select--action-buttons a { + @extend %ibo-hyperlink-inherited-colors; +} \ No newline at end of file diff --git a/js/extkeywidget.js b/js/extkeywidget.js index 62210f4d0..38862366f 100644 --- a/js/extkeywidget.js +++ b/js/extkeywidget.js @@ -634,7 +634,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper // will force it be of the same class as the previous call) me.sTargetClass = me.sOriginalTargetClass; - me.CreateObject(oWizHelper); + me.CreateObject(); }; this.DoSelectObjectClass = function () { @@ -646,13 +646,12 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper // Setting new target class me.sTargetClass = oSelectedClass.val(); - // Opening real creation form + me.CreateObject(true); $('#ac_create_'+me.id).dialog('close'); - me.CreateObject(); }; - this.CreateObject = function (oWizHelper) { + this.CreateObject = function (bTargetClassSelected) { if ($('#'+me.id).prop('disabled')) { return; } // Disabled, do nothing @@ -670,7 +669,8 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper sAttCode: me.sAttCode, 'json': me.oWizardHelper.ToJSON(), operation: 'objectCreationForm', - ajax_promise_id: sPromiseId + ajax_promise_id: sPromiseId, + bTargetClassSelected: bTargetClassSelected }; // Make sure that we cancel any pending request before issuing another @@ -678,6 +678,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper me.StopPendingRequest(); // Run the query and get the result back directly in HTML + var sLocalTargetClass = me.sTargetClass; // Remember the target class since it will be reset when closing the dialog me.ajax_request = $.post(AddAppContext(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php'), theMap, function (data) { $('#ajax_'+me.id).html(data); @@ -687,6 +688,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper // Modify the action of the cancel button $('#ac_create_'+me.id+' button.cancel').off('click').on('click', me.CloseCreateObject); me.ajax_request = null; + me.sTargetClass = sLocalTargetClass; // Adjust the dialog's size to fit into the screen if ($('#ac_create_'+me.id).width() > ($(window).width()-40)) { $('#ac_create_'+me.id).width($(window).width()-40); @@ -714,6 +716,10 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper $('#ac_create_'+me.id).dialog("destroy"); $('#ac_create_'+me.id).remove(); $('#ajax_'+me.id).html(''); + // Resetting target class to its original value + // (If not done, closing the dialog and trying to create a object again + // will force it be of the same class as the previous call) + me.sTargetClass = me.sOriginalTargetClass; }; this.DoCreateObject = function () { diff --git a/pages/ajax.render.php b/pages/ajax.render.php index 3b871f467..1bc92412a 100644 --- a/pages/ajax.render.php +++ b/pages/ajax.render.php @@ -410,9 +410,10 @@ try $iInputId = utils::ReadParam('iInputId', ''); $sAttCode = utils::ReadParam('sAttCode', ''); $sJson = utils::ReadParam('json', '', false, 'raw_data'); - // Building form, if target class is abstract we ask the user for the desired leaf class + $bTargetClassSelected = utils::ReadParam('bTargetClassSelected', '', false, 'raw_data'); + // Building form, if target class has child classes we ask the user for the desired leaf class, unless we've already done just that $oWidget = new UIExtKeyWidget($sTargetClass, $iInputId, $sAttCode, false); - if(MetaModel::IsAbstract($sTargetClass)) + if(!$bTargetClassSelected && MetaModel::HasChildrenClasses($sTargetClass)) { $oWidget->GetClassSelectionForm($oPage); }