1010use Combodo \iTop \Application \UI \Base \Component \Dashlet \DashletFactory ;
1111use Combodo \iTop \Application \UI \Base \Component \DataTable \DataTableUIBlockFactory ;
1212use Combodo \iTop \Application \UI \Base \Component \Field \FieldUIBlockFactory ;
13+ use Combodo \iTop \Application \UI \Base \Component \Form \FormUIBlockFactory ;
1314use Combodo \iTop \Application \UI \Base \Component \Html \Html ;
1415use Combodo \iTop \Application \UI \Base \Component \Panel \Panel ;
1516use Combodo \iTop \Application \UI \Base \Component \Panel \PanelUIBlockFactory ;
@@ -319,34 +320,70 @@ function GetRuleResultFilter($iRuleId, $oDefinitionFilter, $oAppContext, $aParam
319320 $ oP ->AddUiBlock (TitleUIBlockFactory::MakeForPage (Dict::S ('UI:Audit:Interactive:Selection:Title ' )));
320321
321322 $ sAuditUrl = utils::GetAbsoluteUrlAppRoot ()."pages/audit.php?operation=audit " ;
323+ $ sAllDomainUrl = $ sAuditUrl ;
324+ $ sOpenDashlet = '' ;
322325 $ sGetParams = '' ;
323326
324327 if ($ bHasAudiFilter ) {
328+ $ aAuditPreferences = appUserPreferences::GetPref ('audit_pref ' , []);
329+ IssueLog::Error ('bbb ' .json_encode ($ aAuditPreferences ));
325330 $ oPanel = PanelUIBlockFactory::MakeNeutral ('' ,Dict::S ('UI:Audit:Interactive:Selection:SubTitleParams ' ));
326331 $ sPanelFilterId =$ oPanel ->GetId ();
327- $ oP ->AddUiBlock ($ oPanel );
332+ $ oForm = FormUIBlockFactory::MakeStandard ('audit_filter_form ' );
333+ $ oForm ->AddSubBlock ($ oPanel );
334+ $ oP ->AddUiBlock ($ oForm );
328335
329336 while ($ oAuditFilter = $ oAuditFilterSet ->Fetch ()) {
330-
331- $ sCurrentValue = utils::ReadParam ($ oAuditFilter -> Get ( ' placeholder ' ), '' );
337+ $ sPlaceholder = $ oAuditFilter -> Get ( ' placeholder ' );
338+ $ sCurrentValue = utils::ReadParam ($ sPlaceholder , isset ( $ aAuditPreferences [ $ sPlaceholder ])? $ aAuditPreferences [ $ sPlaceholder ]: '' );
332339
333340 $ oBlock = FieldUIBlockFactory::MakeStandard ($ oAuditFilter ->Get ('label ' ));
334341 $ oBlock ->SetAttLabel ($ oAuditFilter ->Get ('label ' ))
335- ->AddDataAttribute ("input-id " , $ oAuditFilter -> Get ( ' placeholder ' ) )
342+ ->AddDataAttribute ("input-id " , $ sPlaceholder )
336343 ->AddDataAttribute ("input-type " , 'input-type ' );
337344 $ oValue = UIContentBlockUIBlockFactory::MakeStandard ("" , ["form-field-content " , "ibo-input-field-wrapper " ]);
338345 $ oValue ->AddSubBlock ($ oAuditFilter ->GetFieldBlock ($ oP , $ sCurrentValue ));
346+ $ oP ->add_ready_script ('$("# ' .$ sPlaceholder .'").on("change", enableDisableButton) ' );
339347 $ oBlock ->AddSubBlock ($ oValue );
340348 $ oPanel ->AddSubBlock ($ oBlock );
341349
342350 //for links
343- $ sGetParams .= $ oAuditFilter -> Get ( ' placeholder ' ) .'=$("[name= ' .$ oAuditFilter -> Get ( ' placeholder ' ) .']").val(); ' ;
344- $ sAuditUrl .= '& ' .$ oAuditFilter -> Get ( ' placeholder ' ) .'= \'+ ' .$ oAuditFilter -> Get ( ' placeholder ' ) .'+ \'' ;
351+ $ sGetParams .= $ sPlaceholder .'=$("[name= ' .$ sPlaceholder .']").val(); ' ;
352+ $ sAuditUrl .= '& ' .$ sPlaceholder .'= \'+ ' .$ sPlaceholder .'+ \'' ;
345353
346354 //for JS
347- $ aAllFields [$ oAuditFilter -> Get ( ' placeholder ' ) ] = 0 ;
355+ $ aAllFields [$ sPlaceholder ] = 0 ;
348356 }
349- $ sAllDomainUrl = 'javascript: ' .$ sGetParams .' window.location = \'' .$ sAuditUrl .'\'' ;
357+
358+ $ sSavePrefJs = <<<EOF
359+ function saveAuditPref(paramFunction){
360+ var aPref = {};
361+ $('#audit_filter_form input').each(function(){
362+ if($(this).attr('name')!=undefined){
363+ if($(this).val()!=undefined){
364+ aPref[$(this).attr('name')] = $(this).val();
365+ } else {
366+ aPref[$(this).attr('name')] = '';
367+ }
368+ }
369+ });
370+ $('#audit_filter_form select').each(function(){
371+ if($(this).attr('name')!=undefined){
372+ if($(this).val()!=undefined){
373+ aPref[$(this).attr('name')] = $(this).val();
374+ } else {
375+ aPref[$(this).attr('name')] = '';
376+ }
377+ }
378+ });
379+ $.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php',
380+ {operation: 'set_pref', code: 'audit_pref', value: aPref})
381+ .done(paramFunction);
382+ }
383+ EOF ;
384+ $ oP ->add_script ($ sSavePrefJs );
385+ $ sAllDomainUrl = '# ' ;
386+ $ sOpenDashlet = 'saveAuditPref(function(){ ' .$ sGetParams .' window.location = \'' .$ sAuditUrl .'\';});stop_propagation(event); ' ;
350387 }
351388 $ oP ->AddUiBlock (TitleUIBlockFactory::MakeNeutral (Dict::S ('UI:Audit:Interactive:Selection:SubTitle ' ),2 ));
352389
@@ -368,6 +405,18 @@ function GetRuleResultFilter($iRuleId, $oDefinitionFilter, $oAppContext, $aParam
368405 $ iCategoryCount ,
369406 Dict::S ('UI:Audit:Interactive:Selection:BadgeAll ' )
370407 ));
408+ if ($ bHasAudiFilter ) {
409+ foreach ($ aAllFields as $ sPlaceholder => $ iValue ) {
410+ if ($ sFieldCondition != '' ){
411+ $ sFieldCondition .= ' && ' ;
412+ }
413+ $ sFieldCondition .= '$("[name= ' . $ sPlaceholder . ']").val() != "" ' ;
414+ }
415+ if ($ sFieldCondition != '' ) {
416+ $ sEnableDisableButtonJS .= 'if( ' . $ sFieldCondition . '){ $("# ' . $ oAllCategoriesDashlet ->GetId () . ' a").removeClass("ibo-dashlet-badge--disabled"); } else { $("# ' . $ oAllCategoriesDashlet ->GetId () . ' a").addClass("ibo-dashlet-badge--disabled"); } ' ;
417+ }
418+ $ oP ->add_ready_script ('$("# ' .$ oAllCategoriesDashlet ->GetId ().' a").click(function(){ ' .$ sOpenDashlet .'}); ' );
419+ }
371420 $ oDashboardColumn ->AddUIBlock ($ oAllCategoriesDashlet );
372421 $ oP ->AddUiBlock ($ oDashboardRow );
373422
@@ -396,7 +445,8 @@ function GetRuleResultFilter($iRuleId, $oDefinitionFilter, $oAppContext, $aParam
396445
397446 if ($ bHasAudiFilter ) {
398447 //modif URLLink In order to send params
399- $ sDomainUrl = 'javascript: ' .$ sGetParams .' window.location = \'' .$ sDomainUrl .'\'' ;
448+ $ sOpenDashlet = 'saveAuditPref(function(){ ' .$ sGetParams .' window.location = \'' .$ sDomainUrl .'\';});stop_propagation(event); ' ;
449+ $ sDomainUrl = '# ' ;
400450 }
401451
402452 $ oDomainBlock = DashletFactory::MakeForDashletBadge ($ sIconUrl , $ sDomainUrl , $ iCategoryCount , $ oAuditDomain ->Get ('name ' ));
@@ -406,7 +456,7 @@ function GetRuleResultFilter($iRuleId, $oDefinitionFilter, $oAppContext, $aParam
406456 $ iDomainCnt ++;
407457 if ($ bHasAudiFilter ) {
408458 $ sFieldCondition = '' ;
409- //JS sEnableDisableButtonJS .= 'if ('.implode(' && ', array_keys($aAllFields)).' == 0) {';
459+
410460 $ aDependentFields = $ oAuditDomain ->GetDependentFields ();
411461 foreach ($ aDependentFields as $ sPlaceholder ) {
412462 if ($ sFieldCondition != '' ){
@@ -418,18 +468,22 @@ function GetRuleResultFilter($iRuleId, $oDefinitionFilter, $oAppContext, $aParam
418468 $ sEnableDisableButtonJS .= 'if( ' . $ sFieldCondition . '){ $("# ' . $ oDomainDashlet ->GetId () . ' a").removeClass("ibo-dashlet-badge--disabled"); } else { $("# ' . $ oDomainDashlet ->GetId () . ' a").addClass("ibo-dashlet-badge--disabled"); } ' ;
419469 $ oP ->add_ready_script ('$("# ' . $ oDomainDashlet ->GetId () . ' a").addClass("ibo-dashlet-badge--disabled") ' );
420470 }
471+ $ oP ->add_ready_script ('$("# ' .$ oDomainBlock ->GetId ().' a").click(function(){ ' .$ sOpenDashlet .'}); ' );
421472 $ oDomainBlock ->SetClassDescription ($ oDomainBlock ->GetClassDescription () . Dict::Format ('Class:AuditDomain/Select:DependentFields ' , implode (', <br>- ' , $ aDependentFields )));
422473 }
423474 }
424475 $ oP ->AddUiBlock ($ oDashboardRow );
425476 if ($ bHasAudiFilter ) {
426477 //add function in order to disable some audit button if necessaries values are not selected
478+
479+ $ oP ->add_script ('function enableDisableButton() { ' .$ sEnableDisableButtonJS .'} ' );
427480 $ sListFieldsJS = implode (', ' , array_keys ($ aAllFields ));
428481 $ sJS = <<<JS
429482 var observerOrgFromId = new MutationObserver(function(mutations) {
430483 mutations.forEach(function(mutationRecord) {
431484 if ($.inArray(mutationRecord.target.id, [ $ sListFieldsJS])) {
432- $ sEnableDisableButtonJS
485+ console.warn('llllaaaa');
486+ enableDisableButton();
433487 }
434488 });
435489 });
@@ -439,6 +493,8 @@ function GetRuleResultFilter($iRuleId, $oDefinitionFilter, $oAppContext, $aParam
439493 });
440494JS ;
441495 $ oP ->add_ready_script ($ sJS );
496+ // initialise state of dashlet buttons
497+ $ oP ->add_ready_script ('enableDisableButton(); ' );
442498 }
443499
444500 break ;
0 commit comments