We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30912
    • 463 Posts
    Hi,

    We have a MIGxDB based Inventory Manager, one of the feedback items that we have recieved is that there is no preview option for the item that is added to the database. As it stands at the moment the client has to publish the item in order to view it on the front end rather than being able to view the content directly from the Manager (preferably on the right click) and it be fed into the template so the user can view it easily.

    Any ideas how I would go about this?

    The only way I can think to do this is to create a new page with a TV selector with a list of the database items and feed it out into that page - however thats rather un user friendly which we are trying to avoid.

    Thanks

    This question has been answered by Tyreal2012. See the first response.

      • 4172
      • 5,888 Posts
      you can add additional context-menues, action-button, grid-functions and all that, which you can select from in the MIGX-CMP by creating a custom grid.config.inc.php in your packages-directory under:

      core/components/yourPackage/migxconfigs/grid/grid.config.inc.php

      with some code like that:

      <?php
      
      
      $gridcontextmenus['showMyPreview']['code']="
              m.push({
                  className : 'showMyPreview', 
                  text: 'Show Preview',
                  handler: 'this.showMyPreview'
              });
              m.push('-');
      ";
      $gridcontextmenus['showMyPreview']['handler'] = 'this.showMyPreview';
      
      
      $gridfunctions['this.showMyPreview'] = "
      showMyPreview: function(btn,e) {
              var object_id = this.menu.record.id;
              var tpl = 'mypreview.html';
              var action = 'u';
      		this.loadIframeWin(btn,e,tpl,action);
      	}    	
      ";


      and a custom migxiframe - processor under:

      core/components/yourPackage/processors/mgr/default/migxiframe.php

      with some code like that:

      <?php
      
      $config = $modx->migx->customconfigs;
      
      //todo: make this configurable
      $tpl = $modx->getOption('iframeTpl',$scriptProperties,'default.html');
      
      $tpl = $modx->getOption('core_path') .'components/yourPackage/migxtemplates/mgr/iframechunks/'.$tpl;
      
      $modx->toPlaceholders($modx->migx->config,'migx_config');
      $modx->toPlaceholders($_REQUEST,'request');
      
      
      
      return $modx->migx->renderChunk($tpl);
      
      


      and a html-template under:

      core/components/yourPackage/migxtemplates/mgr/iframechunks/mypreview.html

      with some code like that:

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
      <head>
      <title>Preview</title>
      <meta charset="utf-8" />
      <base href="[[++site_url]]" />
      
      
      </head>
      <body>
      
      <div id="content">
      <h2>Preview</h2>
      
      [[migxLoopCollection? 
      &packageName=`yourPackage`
      &classname=`yourClassname`
      &where=`{"id":"[[+request.object_id]]"}`
      &tpl=`detailTpl`
      ]]
      
      </div>
      
      </body>
      </html>
      


      now you can select a new context-menue or column-button for your grid within the MIGX-configurator.
      when you click on it in your grid you should get a new window with the preview-page in an iframe.

      I know this could be simplified a bit, but hadn't the time todo it.

      Don't forget to replace all instances of 'yourPackage' in all the code above with your packagename and 'yourClassname' with the classname of your object




      [ed. note: Bruno17 last edited this post 12 years, 10 months ago.]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 30912
        • 463 Posts
        Just wow, I'll have a review and see if i can get this working - genius as always Bruno.
        • discuss.answer
          • 30912
          • 463 Posts
          Hi Bruno,

          So i've followed this and well, I cant get it to work, it displays in the right click context but when I click 'Show Preview' i get nothing, the error console does however show this:

          [14:21:35.978] TypeError: Ext.get(...) is null 


          My files are as follows:

          core/components/inventory/migxconfigs/grid/grid.config.inc.php

          <?php
           
          $gridcontextmenus['showMyPreview']['code']="
                  m.push({
                      className : 'showMyPreview',
                      text: 'Show Preview',
                      handler: 'this.showMyPreview'
                  });
                  m.push('-');
          ";
          $gridcontextmenus['showMyPreview']['handler'] = 'this.showMyPreview';
           
           
          $gridfunctions['this.showMyPreview'] = "
          showMyPreview: function(btn,e) {
                  var object_id = this.menu.record.id;
                  var tpl = 'mypreview.html';
                  var action = 'u';
                  this.loadIframeWin(btn,e,tpl,action);
              }      
          ";
          ?>
          


          core/components/inventory/processors/mgr/default/migxiframe.php

          <?php
           
          $config = $modx->migx->customconfigs;
           
          //todo: make this configurable
          $tpl = $modx->getOption('iframeTpl',$scriptProperties,'default.html');
           
          $tpl = $modx->getOption('core_path') .'components/inventory/migxtemplates/mgr/iframechunks/'.$tpl;
           
          $modx->toPlaceholders($modx->migx->config,'migx_config');
          $modx->toPlaceholders($_REQUEST,'request');
           
           
           
          return $modx->migx->renderChunk($tpl);
          
          ?>


          should the default.html be mypreview.html?

          core/components/inventory/migxtemplates/mgr/iframechunks/mypreview.html

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
          <head>
          <title>Preview</title>
          <meta charset="utf-8" />
          <base href="[[++site_url]]" />
           
           
          </head>
          <body>
           
          <div id="content">
          <h2>Preview</h2>
           
          [[migxLoopCollection?
          &packageName=`inventory`
          &classname=`inventory`
          &where=`{"id":"[[+request.object_id]]"}`
          &tpl=`detailTpl`
          ]]
           
          </div>
           
          </body>
          </html>


          EDIT: If your table has a different prefix to modx_ dont forget the &prefix=`prefix` to the migxLoop Call

          I created a detailTpl with the fields I want to display as well.

          I ticked the box for the showPreview event in the MIGx config

          Im guessing its something i've missed in the Grid.php but I dont understand enough about it to troubleshoot.

          Many thanks.


          EDIT: Two things firstly I wasnt on the latest version, secondly, I hadnt gone to handlers and ticked this.showPreview

          Iframe now successfully loads but minus the data that should be displayed.
          [ed. note: Tyreal2012 last edited this post 12 years, 10 months ago.]
            • 4172
            • 5,888 Posts
            does it fire a request?
            what is the response, if it does?

            here is your classname and packageName missing:

            [[migxLoopCollection?
            &packageName=`yourPackage`
            &classname=`yourClassname`
            &where=`{"id":"[[+request.object_id]]"}`
            &tpl=`detailTpl`
            ]]
            

              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 30912
              • 463 Posts
              Quote from: Bruno17 at Dec 04, 2013, 08:39 AM
              does it fire a request?
              what is the response, if it does?

              here is your classname and packageName missing:

              [[migxLoopCollection?
              &packageName=`yourPackage`
              &classname=`yourClassname`
              &where=`{"id":"[[+request.object_id]]"}`
              &tpl=`detailTpl`
              ]]
              


              Yes i noticed that but i've updated my initial posting also.

              Edit (again): I get this error on preview:

              {"success":false,"message":"Access denied.","total":0,"data":[],"object":{"code":401}}

              from

              /assets/components/migx/connector.php
                • 4172
                • 5,888 Posts
                does
                [[+request.object_id]]

                return the correct id?

                does it work, when you put that snippet-call onto a resource at frontend for testing?
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 30912
                  • 463 Posts
                  It doesnt no, even by selecting an actual id doesnt display an output e.g

                   [[migxLoopCollection?
                  &packageName=`inventory`
                  &classname=`inventory`
                  &where=`{"id":"21"}`
                  &tpl=`detailTpl`
                  ]]


                  However, I might have the solution - well part of.

                  The error log is showing as this:

                  [2013-12-04 14:57:41] (ERROR in xPDO::getCount @ /var/www/vhosts/host/httpdocs/core/xpdo/xpdo.class.php : 1024) Error 42S02 executing statement:
                  Array
                  (
                  [0] => 42S02
                  [1] => 1146
                  [2] => Table 'dbase.modx_inventory' doesn't exist
                  )

                  [2013-12-04 14:57:41] (ERROR @ /index.php) Error 42S02 executing statement:
                  Array
                  (
                  [0] => 42S02
                  [1] => 1146
                  [2] => Table 'dbase.modx_inventory' doesn't exist
                  )

                  Now, the table is as_inventory not modx_inventory - so nauatlly its going to fail. Can I define a table prefix?
                  [ed. note: Tyreal2012 last edited this post 12 years, 10 months ago.]
                    • 4172
                    • 5,888 Posts
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 30912
                      • 463 Posts
                      Aha! thank you. just the ticket. I'll update my 'answer' with the detail you procided.

                      Thanks again (I really must submit these as turotials at some point on the RTFM)