From 0aa0de9f1c4a1b67a1f5b2a17f5d92a868076cc5 Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Tue, 26 Nov 2013 11:16:11 +0000 Subject: [PATCH] Make sure that we attach ONLY the elements that are visible in the form when using the "select all" mode for managing 1:n links. SVN:trunk[2984] --- js/linksdirectwidget.js | 12 ++++++++++-- pages/ajax.render.php | 17 +++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/js/linksdirectwidget.js b/js/linksdirectwidget.js index ac5e190ae4..5884a84ffe 100644 --- a/js/linksdirectwidget.js +++ b/js/linksdirectwidget.js @@ -232,7 +232,8 @@ $(function() iKey = parseInt(this.value, 10); // Numbers are in base 10 oParams.aAlreadyLinked.push(iKey); } - ); oParams.operation = 'searchObjectsToAdd2'; + ); + oParams.operation = 'searchObjectsToAdd2'; oParams['class'] = this.options.class_name; oParams.real_class = ''; oParams.att_code = this.options.att_code; @@ -325,11 +326,18 @@ $(function() _onDoAdd:function() { var oParams = this._getSelection('selectObject'); - this.oDlg.dialog('close'); oParams.operation = 'doAddObjects2'; oParams['class'] = this.options.class_name; oParams.att_code = this.options.att_code; oParams.iInputId = this.id; + + // Retrieve the 'filter' definition, BEFORE closing the dialog and destroying its contents + var table = $('#ResultsToAdd_'+this.id).find('table.listResults')[0]; + oParams.filter = table.config.filter; + oParams.extra_params = table.config.extra_params; + + this.oDlg.dialog('close'); + var me = this; $.post(this.options.submit_to, oParams, function(data) { var oInserted = $(data); diff --git a/pages/ajax.render.php b/pages/ajax.render.php index 4b14b2960b..75c235f08d 100644 --- a/pages/ajax.render.php +++ b/pages/ajax.render.php @@ -336,14 +336,27 @@ try $sAttCode = utils::ReadParam('att_code', ''); $iInputId = utils::ReadParam('iInputId', ''); $iCurrObjectId = utils::ReadParam('iObjId', 0); - $sFilter = utils::ReadParam('filter', ''); + $sFilter = utils::ReadParam('filter', '', false, 'raw_data'); if ($sFilter != '') { $oFullSetFilter = DBObjectSearch::unserialize($sFilter); } else { - $oFullSetFilter = new DBObjectSearch($sRemoteClass); + $oLinksetDef = MetaModel::GetAttributeDef($sClass, $sAttCode); + $valuesDef = $oLinksetDef->GetValuesDef(); + if ($valuesDef === null) + { + $oFullSetFilter = new DBObjectSearch($oLinksetDef->GetLinkedClass()); + } + else + { + if (!$valuesDef instanceof ValueSetObjects) + { + throw new Exception('Error: only ValueSetObjects are supported for "allowed_values" in AttributeLinkedSet ('.$this->sClass.'/'.$this->sAttCode.').'); + } + $oFullSetFilter = DBObjectSearch::FromOQL($valuesDef->GetFilterExpression()); + } } $oWidget = new UILinksWidgetDirect($sClass, $sAttCode, $iInputId); $oWidget->DoAddObjects($oPage, $oFullSetFilter);