diff --git a/application/nicewebpage.class.inc.php b/application/nicewebpage.class.inc.php index a56de6f76..61c2bdcaf 100644 --- a/application/nicewebpage.class.inc.php +++ b/application/nicewebpage.class.inc.php @@ -51,6 +51,7 @@ class NiceWebPage extends WebPage $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/datatable.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.positionBy.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.popupmenu.js'); + $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/searchformforeignkeys.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/search/search_form_handler.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/search/search_form_handler_history.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/search/search_form_criteria.js'); diff --git a/application/ui.searchformforeignkeys.class.inc.php b/application/ui.searchformforeignkeys.class.inc.php index 2b43e88a9..92d67d0d7 100644 --- a/application/ui.searchformforeignkeys.class.inc.php +++ b/application/ui.searchformforeignkeys.class.inc.php @@ -30,7 +30,7 @@ class UISearchFormForeignKeys { $this->m_sRemoteClass = $sTargetClass; $this->m_iInputId = $iInputId; - $this->sAttCode = $sAttCode; + $this->m_sAttCode = $sAttCode; $this->m_sNameSuffix = $sSuffix; } @@ -49,30 +49,30 @@ class UISearchFormForeignKeys $oFilter = new DBObjectSearch($this->m_sRemoteClass); $oBlock = new DisplayBlock($oFilter, 'search', false); - $sHtml .= $oBlock->GetDisplay($oPage, "SearchFormToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}", + $sHtml .= $oBlock->GetDisplay($oPage, "SearchFormToAdd_{$this->m_iInputId}", array( 'open' => $bOpen, 'menu' => false, - 'table_id' => "SearchResultsToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}", + 'table_id' => "SearchResultsToAdd_{$this->m_iInputId}", 'table_id2' => 'add_'.$this->m_sAttCode, - 'table_inner_id' => "ResultsToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}", + 'table_inner_id' => "ResultsToAdd_{$this->m_iInputId}", 'selection_mode' => true, 'cssCount' => '#count_'.$this->m_sAttCode.$this->m_sNameSuffix, 'query_params' => $oFilter->GetInternalParams(), )); - $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:'$sTitle'});"); - $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);"); + $oPage->add_ready_script("$('#dlg_{$this->m_iInputId}').dialog({ width: $(window).width()*0.8, height: $(window).height()*0.8, autoOpen: false, modal: true, resizeStop: oWForeignKeysWidget{$this->m_iInputId}.UpdateSizes });"); + $oPage->add_ready_script("$('#dlg_{$this->m_iInputId}').dialog('option', {title:'$sTitle'});"); + $oPage->add_ready_script("$('#SearchFormToAdd_{$this->m_iInputId} form').bind('submit.uilinksWizard', oWForeignKeysWidget{$this->m_iInputId}.SearchObjectsToAdd);"); + $oPage->add_ready_script("$('#SearchFormToAdd_{$this->m_iInputId}').resize(oWForeignKeysWidget{$this->m_iInputId}.UpdateSizes);"); } /** diff --git a/js/search/search_form_criteria_enum.js b/js/search/search_form_criteria_enum.js index 1914c1d95..f22464604 100644 --- a/js/search/search_form_criteria_enum.js +++ b/js/search/search_form_criteria_enum.js @@ -208,6 +208,8 @@ $(function() } } + + // Events // - Filter // Note: "keyup" event is use instead of "keydown", otherwise, the input value would not be set yet. @@ -244,6 +246,8 @@ $(function() oFilterElem.find('.sff_filter').on('click', function(){ oFilterElem.find('input').trigger('focus'); }); + + }, _prepareInOperatorWithAutocomplete: function(oOpElem, sOpIdx, oOp) { @@ -265,6 +269,27 @@ $(function() .addClass('sfc_opc_mc_items_selected') .appendTo(oOpContentElem); + + // External classes + var oFilterIconElem = oFilterElem.find('.sff_search_dialog').uniqueId(); + oFilterIconElem.attr('id', oFilterIconElem.attr('id').replace(/-/g, '_')); + var oWForeignKeysWidgetCurrent = new SearchFormForeignKeys( + oFilterIconElem.attr('id'), // id + me.options.field.target_class, // sTargetClass + me.options.field.code, // sAttCode + '', // sFilter //TODO + me.options.field.label // sTitle + ); + window['oWForeignKeysWidget' + oFilterIconElem.attr('id')] = oWForeignKeysWidgetCurrent; + oWForeignKeysWidgetCurrent.Init(); + + // model of similar code found in UIExtKeyWidget (you can find another on in UILinksWidget for example) + // oACWidget_{$this->iId} = new ExtKeyWidget('{$this->iId}', '{$this->sTargetClass}', '$sFilter', '$sTitle', true, $sWizHelper, '{$this->sAttCode}', $sJSSearchMode); + // $sMessage = Dict::S('UI:Message:EmptyList:UseSearchForm'); + // oACWidget_{$this->iId}.emptyHtml = "$sMessage
');
+ // }
+ // else
+ // {
+ // $('#label_'+me.id).addClass('dlg_loading');
+ // }
+ $('#label_'+me.id).addClass('dlg_loading');
+ var theMap = {
+ sAttCode: me.sAttCode,
+ iInputId: me.id,
+ sTitle: me.sTitle,
+ sAttCode: me.sAttCode,
+ sTargetClass: me.sTargetClass,
+ // bSearchMode: me.bSearchMode,
+ operation: 'ShowModalSearchForeignKeys'
+ };
+
+
+
+ // Make sure that we cancel any pending request before issuing another
+ // since responses may arrive in arbitrary order
+ me.StopPendingRequest();
+
+ // Run the query and get the result back directly in HTML
+ me.ajax_request = $.post( AddAppContext(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php'), theMap,
+ function(data)
+ {
+ // $('#dlg_'+me.id).html(data);
+ $('#dlg_'+me.id).empty().append($(data)); // $(data).filter(':not(script)'));
+ $('#dlg_'+me.id).dialog('open');
+ me.UpdateSizes();
+ me.UpdateButtons();
+ me.ajax_request = null;
+ FixSearchFormsDisposition();
+ me.ListResultsSearchForeignKeys();
+ },
+ 'html'
+ );
+ };
+
+ this.UpdateSizes = function()
+ {
+ var dlg = $('#dlg_'+me.id);
+ // Adjust the dialog's size to fit into the screen
+ if (dlg.width() > ($(window).width()-40))
+ {
+ dlg.width($(window).width()-40);
+ }
+ if (dlg.height() > ($(window).height()-70))
+ {
+ dlg.height($(window).height()-70);
+ }
+ var searchForm = dlg.find('div.display_block:first'); // Top search form, enclosing display_block
+ var results = $('#dr_'+me.id);
+ var oPadding = {};
+ var aKeys = ['top', 'right', 'bottom', 'left'];
+ for(k in aKeys)
+ {
+ oPadding[aKeys[k]] = 0;
+ if (dlg.css('padding-'+aKeys[k]))
+ {
+ oPadding[aKeys[k]] = parseInt(dlg.css('padding-'+aKeys[k]).replace('px', ''));
+ }
+ }
+ width = dlg.innerWidth() - oPadding['right'] - oPadding['left'] - 22; // 5 (margin-left) + 5 (padding-left) + 5 (padding-right) + 5 (margin-right) + 2 for rounding !
+ height = dlg.innerHeight() - oPadding['top'] - oPadding['bottom'] -22;
+ form_height = searchForm.outerHeight();
+ results.height(height - form_height - 40); // Leave some space for the buttons
+ };
+
+ this.UpdateButtons = function()
+ {
+ var okBtn = $('#btn_ok_'+me.id);
+ if ($('#count_'+me.id).val() > 0)
+ {
+ okBtn.removeAttr('disabled');
+ }
+ else
+ {
+ okBtn.prop('disabled', 'disabled');
+ }
+ };
+
+ this.ListResultsSearchForeignKeys = function(id)
+ {
+ var theMap = {
+ sTargetClass: me.sTargetClass,
+ iInputId: me.id,
+ sFilter: me.sFilter
+ // bSearchMode: me.bSearchMode
+ };
+
+ // Gather the parameters from the search form
+ $('#fs_'+me.id+' :input').each( function() {
+ if (this.name != '')
+ {
+ var val = $(this).val(); // supports multiselect as well
+ if (val !== null)
+ {
+ theMap[this.name] = val;
+ }
+ }
+ });
+
+
+
+ theMap['sRemoteClass'] = theMap['class']; // swap 'class' (defined in the form) and 'remoteClass'
+ theMap.operation = 'ListResultsSearchForeignKeys'; // Override what is defined in the form itself
+ theMap.sAttCode = me.sAttCode;
+ sSearchAreaId = '#dr_'+me.id;
+ //$(sSearchAreaId).html('
');
+ //// }
+ //// else
+ //// {
+ //// $('#label_'+me.id).addClass('dlg_loading');
+ //// }
+ // $('#label_'+me.id).addClass('dlg_loading');
+ //
+ // theMap['sRemoteClass'] = me.sTargetClass;
+ // theMap.operation = 'displayHierarchy';
+ //
+ // // Make sure that we cancel any pending request before issuing another
+ // // since responses may arrive in arbitrary order
+ // me.StopPendingRequest();
+ //
+ // // Run the query and display the results
+ // me.ajax_request = $.post( AddAppContext(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php'), theMap,
+ // function(data)
+ // {
+ // $('#ac_tree_'+me.id).html(data);
+ // var maxHeight = $(window).height()-110;
+ // $('#tree_'+me.id).css({maxHeight: maxHeight});
+ // },
+ // 'html'
+ // );
+ // };
+ //
+ // this.OnHKResize = function(event, ui)
+ // {
+ // var dh = ui.size.height - ui.originalSize.height;
+ // if (dh != 0)
+ // {
+ // var dlg_content = $('#dlg_tree_'+me.id+' .wizContainer');
+ // var h = dlg_content.height();
+ // dlg_content.height(h + dh);
+ // var tree = $('#tree_'+me.id);
+ // var h = tree.height();
+ // tree.height(h + dh - 1);
+ // }
+ // };
+ //
+ // this.OnHKClose = function()
+ // {
+ // if (me.bSelectMode)
+ // {
+ // $('#fstatus_'+me.id).html('');
+ // }
+ // else
+ // {
+ // $('#label_'+me.id).removeClass('dlg_loading');
+ // }
+ // $('#label_'+me.id).focus();
+ // $('#dlg_tree_'+me.id).dialog("destroy");
+ // $('#dlg_tree_'+me.id).remove();
+ // };
+ //
+ // this.DoHKOk = function()
+ // {
+ // iObjectId = $('#tree_'+me.id+' input[name=selectObject]:checked').val();
+ //
+ // $('#dlg_tree_'+me.id).dialog('close');
+ //
+ // // Query the server again to get the display name of the selected object
+ // var theMap = { sTargetClass: me.sTargetClass,
+ // iInputId: me.id,
+ // iObjectId: iObjectId,
+ // sAttCode: me.sAttCode,
+ //// bSearchMode: me.bSearchMode,
+ // operation: 'getObjectName'
+ // };
+ //
+ // // Make sure that we cancel any pending request before issuing another
+ // // since responses may arrive in arbitrary order
+ // me.StopPendingRequest();
+ //
+ // // Run the query and get the result back directly in JSON
+ // me.ajax_request = $.post( AddAppContext(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php'), theMap,
+ // function(data)
+ // {
+ // var oTemp = $('