We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19328
    • 433 Posts
    We are working on an event list based on the Articles add-on. Each event is an article. For each event, one or more locations can be set, by checking them in a list. This list is a TV type checkbox, and is populated with a SELECT statement from a list of resources with all the locations.

    The thing we're trying to do is to allow our manager users to add a new location 'on the fly', while they're editing the event. It would be very efficient if this would be possible without leaving the event-edit screen. The location has to be a resource itself, with a content field and several TV's.

    What would be a good way to accomplish this? Would it be possible to open a popup or lightbox in the manager from within the edit resource screen? Just using Quick Edit is not really an option, because you can't set TV's in the quick edit popup, and the checkbox list with locations also needs to be updated when a new location is added, and if possible, this new location should also be checked after it's added.

    Does anyone have an idea of how we should do this?

    We're using MODX Revolution 2.2.0-pl2
      • 10208 ☆ A M B ☆
      • 1,780 Posts
      Is opening a new tab not an option for the users?

      Simple... but of course not what you asked for. Plus, getting the resource to display the new location would require a refresh, regardless.

        Frogabog- MODX Websites in Portland Oregon
        "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
        Having server issues? These guys have MODX Hosting perfected - SkyToaster
        • 19328
        • 433 Posts
        Hi Frogabog, yeah, opening a new tab is our 'if all else fails' solution ;-). I just hope we'll find a more user friendly way of doing this smiley. It could be useful in a lot of situations where one resource depends on another.
          • 19328
          • 433 Posts
          I've come up with another solution to this problem: use a plugin that creates a resource for a newly entered location (in a seperated tv) and after it's created, checks it in the list. It's almost working as it should, at least for adding a resource the first time. The page reloads and the resource is added to the list and checked. But if I then add another new location and save the resource again, the page doesn't reload and the new location is not added to the list. So maybe I need a way to force reload of the page after each save. Anyone know how to do this?

          This is the plugin so far (onDocFormSave):

          To explain this a little more: when a user creates a new event, he can either (or both) check one or more existing locations in the checklist, or he can fill in details of a new location (name and telephone number). When he saves the event, the page reloads and the newly added location is already checked in the list. The fields for adding a new location are cleared.

          $tel = $resource->getTVValue('locationTelephone');
          $name = $resource->getTVValue('locationName');
          
          // if details for new location have been filled, create this location
          if ($name != '') {
            $new = $modx->newObject('modResource');
            $new->set('pagetitle', $name);
            $new->set('published', '1'); 
            $new->set('template', '2');
            $new->set('parent', '1');  	
            $new->save();
            $new->setTVValue('locationTelephone', $tel);
            $new->save();
          
            // get id of new location
            $newId = $new->get('id');
            
            // list of checked locations on event resource
            $checkedLocations = $resource->getTVValue('locationsList');
            
            //add id of newly created resource to this list
            $locationsNew = $checkedLocations.'||'.$newId;
            
            // change value of checklist tv to add new id
            $resource->setTVValue('locationsList', $locationsNew);
            
            // clear input fields for new location
            $resource->setTVValue('locationTelephone', '');
            $resource->setTVValue('locationName', ''); 
          }
          
          



          Problem: when the user has added the first location, the page has reloaded and he fills in another location and saves again, this script isn't working anymore because the page doesn't reload, thus the new location is created and not added to the checklist. Also the fields for name and telephone number are not cleared. So: how do I refresh? Or should I use a different system event or something?
            • 3749
            • 24,544 Posts
            The icons at the upper right determine what happens when you save a document -- close, continue with the same doc, or create another (new doc). It might make a difference how you have that set.


            ---------------------------------------------------------------------------------------------------------------
            PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
            MODx info for everyone: http://bobsguides.com/modx.html
              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
              • 19328
              • 433 Posts
              They are set to continue editing the same document... I don't know if that's related, because the first time I save the document everything works fine. It seems I need to find a way to refresh the whole page (tree and resource edit screen) when I save a resource the second time (so not creating, but editing). Is there a way I can do this in a plugin?
              I tried this:

              $url = 'manager/index.php?a=30&id='.$resource->get('id');
                return $modx->sendRedirect($url);
              


              but this gives me an infinite saving loop.

              Also tried:

              return $modx->event->output('<script type="text/javascript">parent.window.location.reload();</script>');
               

              but nothing happens.. and I tried:

              $modx->cacheManager->refresh(array('resource' => array('contexts' => 'web'))); 
              


              This also doesn't make the page refresh.

              I must add to my first post that the creating of the new resource for location does work, but it's just not visible until you refresh the page by yourself by pressing F5. So the code works, all I need is to refresh the edit screen after save.
                • 10208 ☆ A M B ☆
                • 1,780 Posts
                What happens when you set the icons to "create new document"? If I recall correctly, that does refresh the entire tree as well as the page to a new doc.
                  Frogabog- MODX Websites in Portland Oregon
                  "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
                  Having server issues? These guys have MODX Hosting perfected - SkyToaster