We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    Have you tried calling $resource->save()?
      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
    • Yes. no dice.
        • 3749
        • 24,544 Posts
        How about attaching it to OnBeforeDocFormSave?
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 33996
          • 20 Posts
          Quote from: BobRay at Oct 03, 2014, 09:47 PM
          If it's a new resource, you also have to add this:

          $modx->reloadContext('web'); /* or whatever context the resource is in */

          This way to refresh the resource is working very well but it is -in my case- very very slow too (more than half a second on my server).

          Could there be another faster way to have just the resource information updated without replaying all the re-initialisation of the context?
            • 3749
            • 24,544 Posts
            It might work to delete specific cache files, but I doubt it. MODX uses the resourceMap, which is context-specific, and the only way I know of to update it is to reload the context. I don't think just deleting the context cache file would speed things up any.

            In theory, you could rewrite the context cache file yourself and just add the new resource's ID, but it would be tricky. It's in the core\cache\context_settings\web\context.cache.php file. If you look at that file, you can see why it takes time to regenerate it.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 33996
              • 20 Posts
              ourf... I wasn't aware of such cache file... I understand now the time to regenerate it (7Mb at the moment)...
              I will try to investigate all these cache mecanisms and files I have trouble to really understand...
              Thank you for the lead.


              Quote from: BobRay at Nov 14, 2015, 06:59 AM
              It might work to delete specific cache files, but I doubt it. MODX uses the resourceMap, which is context-specific, and the only way I know of to update it is to reload the context. I don't think just deleting the context cache file would speed things up any.

              In theory, you could rewrite the context cache file yourself and just add the new resource's ID, but it would be tricky. It's in the core\cache\context_settings\web\context.cache.php file. If you look at that file, you can see why it takes time to regenerate it.
                • 14504
                • 3 Posts
                Hi there,

                I am also trying to refresh a resource in the manager when saved. My plugin fires OnDocFormSave. What I'm trying to do is have the plugin save a TV value (which it already does successfully), then reload the page so that the user can see the value that has been saved in the DB. I've tried all of the above proposed solutions with no luck. I really don't want to add "reload the page after saving" to the user training process - it is so easily forgotten and bad user experience. There must be a solution that works!

                In my case, the plugin is creating MailChimp campaigns and saving the campaign id in a TV so that future saves update the campaign instead of creating a new one.

                Your help would be appreciated greatly! Been using MODX for almost 8 yrs now...love it.
                  • 14504
                  • 3 Posts
                  Quote from: johnfeezer at Feb 01, 2016, 03:54 PM
                  Hi there,

                  I am also trying to refresh a resource in the manager when saved. My plugin fires OnDocFormSave. What I'm trying to do is have the plugin save a TV value (which it already does successfully), then reload the page so that the user can see the value that has been saved in the DB. I've tried all of the above proposed solutions with no luck. I really don't want to add "reload the page after saving" to the user training process - it is so easily forgotten and bad user experience. There must be a solution that works!

                  In my case, the plugin is creating MailChimp campaigns and saving the campaign id in a TV so that future saves update the campaign instead of creating a new one.

                  Your help would be appreciated greatly! Been using MODX for almost 8 yrs now...love it.

                  Ok, never mind! Some minor modifications to Gary Nutting's solution seems to be working perfectly.

                  His original solution:
                  <?php
                  $modx->regClientStartupHTMLBlock('
                      <script type="text/javascript">
                              Ext.override(MODx.panel.Resource, {
                                  originalSuccess: MODx.panel.Resource.prototype.success
                                  ,success: function(o) {
                                      this.originalSuccess(o);
                                      var tv = Ext.get("tv1").dom.value;
                                      if (tv && tv == "1") {
                                          MODx.loadPage(location.href);
                                      }
                                  }
                              });
                      </script>    
                  ');
                  
                    • 39501
                    • 163 Posts
                    Just leaving this here incase anybody else wants to:

                    1. refresh the manager so a tv value that was set programmatically will be displayed on refresh
                    2. only refresh the manager page if a tv checkbox is set to 1 (checked)

                    case 'OnDocFormPrerender':
                    
                            $modx->regClientStartupHTMLBlock('
                                <script type="text/javascript">
                                        Ext.override(MODx.panel.Resource, {
                                            originalSuccess: MODx.panel.Resource.prototype.success
                                            ,success: function(o) {
                                                this.originalSuccess(o);
                                                
                                                var tv = Ext.get("tv62-0").dom.checked;
                                                
                                                if (tv && tv == "1") {
                                                    var url = location.href, i = url.indexOf("?") + 3;
                                                    MODx.loadPage(url.substr(i));
                                                }
                                            }
                                        });
                                </script>    
                            ');
                    
                                    
                    break;
                    


                    In my particular scenario, I created a checkbox tv and moved it into "modx-resource-main-right" using form customisation.

                    Next, I needed to find out the ID of my TV by viewing the source of the manager. It gave me an ID of "tv62-0". Do not use ExtJS generated ID's as these change over time (you might think everything is working, only to find out an hour later it has stopped working).

                    The problem with my ID is that the value was always set to "1", even if the checkbox was checked or not. The fields that did change the values dynamically had ExtJs generated IDs. So by adding "dom.checked" rather than "dom.value" we have something to hook on to (unless you find another way of searching for an element by name rather than ID!)

                    var tv = Ext.get("tv62-0").dom.checked;
                    


                    Good luck! [ed. note: jonleverrier last edited this post 6 years, 6 months ago.]
                      • 46006
                      • 17 Posts
                      I realise this is an old thread, but for those of you still looking for quick solution to the problem of 'refreshing/reloading' a resource after saving, then you can always add the following code to this file at line 210:

                      File:
                      manager/assets/modext/widgets/resource/modx.panel.resource.js

                      Code:
                      location.reload();

                      *Please note: editing core files is highly discouraged, however, I have used this option (as all other solutions failed to work) - plus, I keep a changelog for all MODx projects.