We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19315
    • 84 Posts
    Quote from: michalc at Jun 21, 2008, 06:26 AM

    I’m using this snippet in a Ditto call, so front end users can choose to edit a number of documents, all from one page. One thing I would like to do: be able for the user to manually change the order of the documents displayed.
    I have found a solution: it may be a bit dodgy, but I’ll put it here in case anyone wants to do it. First add a function to FdmDocument class in fdm.db.class.inc.php
    function setMenuIndex($newIndex) {
    	global $modx;
    	$this->Set('menuindex',$newIndex);
    	$this->Save();
    }
    The add two actions in the class CFDM in fdm.class.inc.php "moveup" and "movedown". This means in the Run() function add near the top:
    $this->link['moveup'] =str_replace('&','&',$modx->makeUrl($this->config['editorpageid'],'','&fdmaction=moveup'.'&fdmid='.$this->doc['id']));
    $this->link['movedown'] =str_replace('&','&',$modx->makeUrl($this->config['editorpageid'],'','&fdmaction=movedown'.'&fdmid='.$this->doc['id']));

    And in the switch ($this->config[’action’]) block add two cases:
    case 'moveup':
    	if ($this->user['ismoderator'] || $this->user['isauthor']) {
    		$docObj = new FdmDocument($this->doc['id']);
    
    		// Find siblings ordered by menu index
    		$parentID = $modx->getParent($this->doc['id'],1,'id');
    		$parentID = $parentID['id'];
    		$siblings = $modx->getAllChildren($parentID,'menuindex','ASC','id,menuindex,deleted,hidemenu');$test = "";
    
    		// Ignore hidden or deleted siblings
    		for ($i = 0; $i < sizeof($siblings); $i += 1) {
    			if(($siblings[$i]['deleted'] == 1) ||   $siblings[$i]['hidemenu'] == 1) {
    				array_splice($siblings,$i,1);
    				$i = $i -1;
    			}
    		}	
    	
    		// Find element to swap index with (loops from second item in array)
    		for ($i = 1; $i < sizeof($siblings); $i += 1) {
    			if($siblings[$i]['id'] == $this->doc['id']) {
    				// Swap indices
    				$partnerDocObj = new FdmDocument($siblings[$i - 1]['id']);
    				$docObj->setMenuIndex($siblings[$i - 1]['menuindex']);
    				$partnerDocObj->setMenuIndex($siblings[$i]['menuindex']);
    			}
    		}					
    		header('Location: '.$this->link['current']);
    	}
    	break;
    
    case 'movedown':
    
    	if ($this->user['ismoderator'] || $this->user['isauthor']){
    		$docObj = new FdmDocument($this->doc['id']);
    
    		// Find siblings ordered by menu index
    		$parentID = $modx->getParent($this->doc['id'],1,'id');
    		$parentID = $parentID['id'];
    		$siblings = $modx->getAllChildren($parentID,'menuindex','ASC','id,menuindex,deleted,hidemenu');$test = "";
    
    		// Ignore hidden or deleted siblings
    		for ($i = 0; $i < sizeof($siblings); $i += 1) {
    			if(($siblings[$i]['deleted'] == 1) ||   $siblings[$i]['hidemenu'] == 1) {
    				array_splice($siblings,$i,1);
    				$i = $i -1;
    			}
    		}	
    	
    		// Find element to swap index with (loops until second last item)
    		for ($i = 0; $i < sizeof($siblings)-1; $i += 1) {
    			if($siblings[$i]['id'] == $this->doc['id']) {
    				// Swap indices
    				$partnerDocObj = new FdmDocument($siblings[$i + 1]['id']);
    				$docObj->setMenuIndex($siblings[$i + 1]['menuindex']);
    				$partnerDocObj->setMenuIndex($siblings[$i]['menuindex']);
    			}
    		}					
    		header('Location: '.$this->link['current']);
    	}
    
    	break;

    And then in your template you can use [+link.moveup:esc+] and [+link.movedown:esc+] for the links to perform the action.

    There probably better ways of doing the to those more familiar with php and the modx api though.

    Michal.
      • 19315
      • 84 Posts
      Hi,

      I think I may have found a bug with FDM, in the cases where a user has two different documents open for editing at the same time (in two separate windows/tabs). It looks like no matter which document seems to be edited, the one saved (and so overwritten!) is always the one which the user most recently opened to edit (even if it is in a different window).

      Michal.

        • 25551 ☆ A M B ☆
        • 1,231 Posts
        Has anyone found that when a user edits a page that it is being unpublished when submitting changes and requires the admin to click the publish box again? Happens the first edit then after an admin says the doc is published it doesn’t happen after that?
          Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
          AugmentBLU - MODX Partner

          BLUcart - MODX Revolution E-Commerce & Shopping Cart
          • 19315
          • 84 Posts
          I do now have another issue which I didn’t have before. Every new page now always has the menu index of the model document when it is created, but perhaps it is one of my changes that has done this, but I can’t figure out why.

          Michal.

          EDIT: I have fixed this using the following code that I placed in fdm.class.inc.php, in the fillDoc function, near the top, in the block that starts with if ($_SESSION[’fdm’][’action’]==’add’ )
          // Set maxindex to be one greater than other indices
          $parentID = $_SESSION['fdm']['parent'];
          $siblingIndices = $modx->getAllChildren($parentID,'menuindex','ASC','menuindex');
          $maxIndex = $siblingIndices[sizeof($siblingIndices)-1]['menuindex'];
          $docObj->Set('menuindex',$maxIndex + 1);

            • 19315
            • 84 Posts
            (Another vote from me for the separate forum by the way!)

            I do have a problem that I can’t figure out. I have a drop down list in my form (using the select and option elements), to change a drop down list tv. The user can save a new value fine. However, the next time the document is opened for editing, the value always defaults to the one at the top of the list, i.e. there is no selected="selected" in the appropriate option element. How can I get the saved value to reappear in the form?

            Michal.

            EDIT: Ok... I have figured out a way, perhaps not the greatest, but it seems to work. In each option element, say for value VAL put:
            [*phx:if=`[+tvMyTemplateVariableName+]`:is=`VAL`:then=`selected="selected"`*] 
              • 30100
              • 58 Posts
              Is there anyone that has integrated FCKEditor with FDM? I’m trying to get it working but the only thing I know to put in the &script parameter is the code from an RichText TV with FCK:
              <script language="javascript" type="text/javascript" src="/assets/plugins/fckeditor261/fckeditor.js"></script>
              		<script language="javascript" type="text/javascript">
              			var _FileBrowserLanguage = 'php';
              			var _QuickUploadLanguage = 'php';
              
              			var FCKCustomToolbarSet = [ ['Bold','Italic','Underline','-','Link','Unlink'] ];
              			var FCKAutoLanguage = true;
              			var FCKDefaultLanguage = 'sv';
              			var FCKEditorAreaCSS = '/assets/plugins/fckeditor261/editor/css/fck_editorarea.css';
              			function FCKeditor_OnComplete(edtInstance) {
              				if (edtInstance){ // to-do: add better listener
              					edtInstance.AttachToOnSelectionChange(tvOnFCKChangeCallback);
              				}
              			};
              			
              			function tvOnFCKChangeCallback(edtInstance) {
              				if (edtInstance) {
              					elm = edtInstance.LinkedField;
              					if(elm && elm.onchange) elm.onchange();
              				}
              			}
              		</script>
              


              I now know that it’s not that easy, how do I put the richtext inside the [*content*] variable of a document, something that corresponds to TinyMCE’s "elements : "content","

              Anyone else using FDM with FCK?
                • 36416
                • 589 Posts
                Quote from: michalc at Jun 22, 2008, 02:21 PM

                EDIT: Ok... I have figured out a way, perhaps not the greatest, but it seems to work.

                Here is a bit more sophisticated way:
                http://modxcms.com/forums/index.php/topic,14977.msg104419.html#msg104419

                BTW, guess that IS a vote for separate forum, or at least topics in "Creating & repurposing content" prefixed with "FDM:"...
                  • 19315
                  • 84 Posts
                  Quote from: Eol at Jun 23, 2008, 04:17 PM

                  Here is a bit more sophisticated way:
                  http://modxcms.com/forums/index.php/topic,14977.msg104419.html#msg104419
                  Ah... that does seem quite good. Especially as with my way if I want to change the input description/values I have to change them in 2 places: the tempate of the form and the template variable, but with that only in the template variable,

                  Thanks,

                  Michal.
                    • 25551 ☆ A M B ☆
                    • 1,231 Posts
                    Anyone finding that the documents are unpublishing when a webuser is saving the changes? I can’t seem to fix this.
                      Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
                      AugmentBLU - MODX Partner

                      BLUcart - MODX Revolution E-Commerce & Shopping Cart
                      • 36416
                      • 589 Posts
                      Quote from: rossco at Jun 24, 2008, 04:45 AM

                      Anyone finding that the documents are unpublishing when a webuser is saving the changes? I can’t seem to fix this.

                      Are you changing pub_date in FDM entry form?