We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6726
    • 7,075 Posts
    Would be awesome Laurent grin !
      .: COO - Commerce Guys - Community Driven Innovation :.


      MODx est l'outil id
      • 28436
      • 242 Posts
      Hello Perrine,

      \$mm->mm_default(’cacheable’, ’0’, ’’, ’9’);

        case 'cacheable':
          			$new_value = ($new_value=='') ? 0 : $new_value;
          			$output .= '$("input[@name=cacheable]").val("'.(int)$new_value.'"); '."\n";
          			$output .= '$("input[@name=cacheablecheck]").attr("checked",""); '."\n";
          		break;

      As a new case in the mm_defautl function.

      You can change all checkboxes by this way.

      ciao, Stefan
        • 23050
        • 1,842 Posts
        Hi Stefan, thanks for your answer but no matter I put 0 or 1, the only thing which is saved is the value I put in mm.class.inc.php... not the one I use in the plugin code.

        In my case, I would like to set docs uncacheable but only for template n°9... Others must be cached.

        Hope I’m clear smiley
          • 28436
          • 242 Posts
          Hello Perrine,

          1. My piece of code above is not well tested.. This one is better

          case 'cacheable':
              $new_value = ($new_value=='') ? '0' : $new_value;
              $checked = ( $new_value=='0' ) ? '' : 'checked';
              $output .= '$("input[@name=cacheable]").val("'.(int)$new_value.'"); '."\n";
              $output .= '$("input[@name=cacheablecheck]").attr("checked","'.$checked.'"); '."\n";
          break;

          you can repeat this for all checkboxes

          2.
          I would like to set docs uncacheable but only for template n°9
          Yes, in the moment the mm_function contains no condition to check the rules for templates or roles. So all input expect the $new_value is ignored

          The solution ist simple:
          just wrap the output you want with the
          if (useThisRule($roles, $templates)) {
          function.

          for example: just the "cachable-Button", all others are global
           case 'cacheable':
          if (useThisRule($roles, $templates)) 
          {
              $new_value = ($new_value=='') ? '0' : $new_value;
              $checked = ( $new_value=='0' ) ? '' : 'checked';
              $output .= '$("input[@name=cacheable]").val("'.(int)$new_value.'"); '."\n";
              $output .= '$("input[@name=cacheablecheck]").attr("checked","'.$checked.'"); '."\n";
          }
          break;


          To add the rules/template conditon to all buttons wrap the hole "switch" block
            
            	// What's the new value, and does it include PHP?
              	$new_value = ($eval) ? eval($value) : $value;
          
          if (useThisRule($roles, $templates)) {
          
              	$output = " // ----------- Date defaults -------------- \n";
          
              	switch ($field) {
              		case 'pub_date':
              			$new_value = ($new_value=='') ? date("d-m-Y H:i:s") : $new_value;
              			$output .= '$("input[@name=pub_date]").val("'.htmlentities($new_value).'"); '."\n";
              		break;
          
                         /* 
                                           some cases
                          */
              		case 'cacheable':
              		      $new_value = ($new_value=='') ? '0' : $new_value;
              			  $checked = ( $new_value=='0' ) ? '' : 'checked';
              		      $output .= '$("input[@name=cacheable]").val("'.(int)$new_value.'"); '."\n";
              			  $output .= '$("input[@name=cacheablecheck]").attr("checked","'.$checked.'"); '."\n";
              		break;
          
                  default:
              	    return;
                  break;
              }
          }
          


          mmhh. ok. thats it, unfortunately my english spelling is not stable enough to explain things more detailed, i hope you can read the code. smiley
          so i need the global rule
           $output .= '$("input[@name=practiseMyEnglish]").attr("checked","checked"); '."\n";


          ciao, Stefan
            • 23050
            • 1,842 Posts
            Hi Stefan,

            For the first point you mention, it’s ok. I get the value defined in plugin code.

            But for 2d point, it doesn’t work.

            I wrap the cacheable case with the function :
            case 'cacheable':
                                 if (useThisRule($roles, $templates)) 
            			{
                                       $new_value = ($new_value=='') ? '0' : $new_value;
                                       $checked = ( $new_value=='0' ) ? '' : 'checked';
                                       $output .= '$("input[@name=cacheable]").val("'.(int)$new_value.'"); '."\n";
                                       $output .= '$("input[@name=cacheablecheck]").attr("checked","'.$checked.'"); '."\n";
                                 }
            			break;


            And then, I get blank page (like the problem I got before : I have to comment
            //echo '		
            		//<div id="loadingmask"> </div>
            		//<script type="text/javascript">
            			//$("#loadingmask").css( {width: "100%", height: $("body").height(), position: "absolute", zIndex: "1000", backgroundColor: "#ffffff"} );
            		//</script>	
            	//';

            in order to not have the blank mask.

            I see then the fields but cacheable button is still checked whereas I have this in the snippet code :
              \$mm->mm_default('cacheable', '0', '', '9');


            So don’t worry Stefan, I will ask users to not check this box... It’s not so difficult wink

            Thx for your help ! smiley
              • 28436
              • 242 Posts
              Hey! Dont give up the show!

              the code i wrote is working perfectly for me. But there is a different. I use another mm.inc.php.

              try
              mm->useThisRule($roles, $templates)


              good luck, Stefan
                • 23050
                • 1,842 Posts
                Yes, I use the version for PHP5.

                I now have this :

                                    case 'cacheable':
                                     if (mm->useThisRule($roles, $templates)) 
                			{
                                           $new_value = ($new_value=='') ? '0' : $new_value;
                                           $checked = ( $new_value=='0' ) ? '' : 'checked';
                                           $output .= '$("input[@name=cacheable]").val("'.(int)$new_value.'"); '."\n";
                                           $output .= '$("input[@name=cacheablecheck]").attr("checked","'.$checked.'"); '."\n";
                                     }
                			break;


                I get a blank page when editing doc... and it’s not because of the white mask... I only get the default grey from MODx ^^ There are no fields.
                  • 28436
                  • 242 Posts
                  Hello Perrine,

                  i have no more ideas...

                  i use a " 5.2.0-8+etch7" php and both files from attachment.

                  Maybe it will work for you as well.

                  ciao, Stefan
                    • 16732
                    • 592 Posts
                    Perrine try with $mm->useThisRule($roles, $templates)

                    EDIT : OPPPPSSS ! the right syntaxe is : $this->useThisRule($roles, $templates)
                      • 23050
                      • 1,842 Posts
                      No sad Each time I use useThisRule function in case ’cacheable’, I get the white mask and the plugin doesn’t work.

                      Thx Stefan wink

                      @ Laurent : do you manage to run it on your install ?

                      This discussion is closed to further replies. Keep calm and carry on.