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

    this post comes from a French topic : Ajax pour sauvegarder.
    Summary : I want to save the document with Ajax in the case I want to continue edition.
    I have an approximative solution, which does not work with FCKEditor and does not well handle special charactere :
    In content_mutate_dynamic I put
    function masave(){
    if(document.mutate.stay[1].checked){
    ggg=Form.serialize(document.mutate);
    ggg+="&ajax=true";
    ggg=ggg.replace(/\%C3\%A0/gi,escape("à"));
    ggg=ggg.replace(/\%C3\%A9/gi,escape("é"));
    ggg=ggg.replace(/\%C3\%A8/gi,escape("è"));
    ggg=ggg.replace(/\%C3\%B9/gi,escape("ù"));
    ggg=ggg.replace(/\%C3\%A2/gi,escape("â"));
    ggg=ggg.replace(/\%C3\%AA/gi,escape("ê"));
    ggg=ggg.replace(/\%C3\%BB/gi,escape("û"));
    var myAjax=new Ajax.Updater("motmpid","index.php",{	method: 'post', parameters: ggg});}
    else document.mutate.save.click();
    }

    which uses prototype.js.
    Then I call "masave()" with "Button1" of the form mutate.
    Just before the form, I put
    <div id="motmpid"></div>


    Now I turn my attention to the file save_content.processor.
    At the top I place
    $ajax=false;
    if(isset($_POST['ajax']) && $_POST['ajax']=='true') $ajax=true;

    then I use the variable $ajax at the end of the treatment :
    if($ajax){echo "Save done at ".date("H:i:s");exit;}
    		header($header);
    		break;
        default:
    		header("Location: index.php?a=7");
    	exit;
      • 20394
      • 134 Posts
      This technique could be used as well for snippets :
      ggg+="&ajax=true&a=79";

      and for chunks :
      ggg+="&ajax=true&a=24";

      Also use
      else{ document.mutate.save.click(); saveWait('mutate');}

      and remove saveWait(’mutate’); from "Button1".

      For the both you put in the "save"-files
      if($ajax){echo "Save done at ".date("H:i:s");exit;}

      just before the four (two for each file)
      if($_POST['stay']!='') {
        • 18397
        • 3,250 Posts
        Could you modify the existing MODx 0.9.2.1 files with the changes and attach them to the post so that users can easily test out your modifications?
          • 20394
          • 134 Posts
          Please find herewith four files of my modifications.

          I warn that I remove FCKEditor since I does not achieve to handle this editor :
          in content_mutate,
          //$replace_richtexteditor = array("ta");///C'est ici que l'on peut enlever FCKEditor
            • 20394
            • 134 Posts
            Here is a solution to handle special characteres.
            Forget the lines
            ggg=ggg.replace(/\%C3\%A0/gi,escape("à"));
            ggg=ggg.replace(/\%C3\%A9/gi,escape("é"));
            ggg=ggg.replace(/\%C3\%A8/gi,escape("è"));
            ggg=ggg.replace(/\%C3\%B9/gi,escape("ù"));
            ggg=ggg.replace(/\%C3\%A2/gi,escape("â"));
            ggg=ggg.replace(/\%C3\%AA/gi,escape("ê"));
            ggg=ggg.replace(/\%C3\%BB/gi,escape("û"));

            in mutate_content.

            In the save_processor and before getting the POST-variables, put :
            $ajax=false;
            if(isset($_POST['ajax']) && $_POST['ajax']=='true') $ajax=true;
            
            if($ajax){
            	foreach($_POST as $name => $value){
            	$_POST[$name]=utf8_decode($value);
            	}
            }
              • 20394
              • 134 Posts
              Pepin has given a solution to handle FCKEditor :
              txtTest = ( FCKConfig.EnableXHTML && FCKConfig.EnableSourceXHTML ? FCK.GetXHTML( FCKConfig.FormatSource ) : FCK.GetHTML( FCKConfig.FormatSource ) )


              I did not achieve to use this syntax but sure this is the right way.
              At least I notice that the name of the FCKEditor object is oFCKta and not FCK.
                • 7923
                • 4,213 Posts
                I just like to say that you are doing good work and keep it up! I think that the saving in manager should/will be changed to use some ajax functionality at some point.

                Have you by anychance looked into recreating the session to modx manager on save if it’s lost? So users wouldn’t be booted to the login screen to relogin and lost data in the process if session has expired.


                  "He can have a lollipop any time he wants to. That's what it means to be a programmer."