GetSimple Support Forum
Problem with 3.1: Success Message with undo - from Tips & Tricks - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: General Questions and Problems (http://get-simple.info/forums/forumdisplay.php?fid=16)
+--- Thread: Problem with 3.1: Success Message with undo - from Tips & Tricks (/showthread.php?tid=3124)



Problem with 3.1: Success Message with undo - from Tips & Tricks - Petit Jean - 2012-04-26

Simply put:

http://get-simple.info/wiki/plugins:tips#success_and_error_messages

does not seem to work...
I don't get the success or error messages with the undo link.
link_manager and news_manager seem to suffer from the same defect.

Any help appreciated.


The process uses ajax and this is what jquery.getsimple.js logs as the response in the console:
Code:
[... standard header stuff here ...]

<div class="wrapper">

<div class="bodycontent clearfix">
    <div id="maincontent">
        <div class="main">
            <script type="text/javascript">
            $(function() {
                $('div.bodycontent').before('<div class="updated" style="display:block;">'+
                "The person has been deleted. <a href=\"load.php?id=person_manager&undo\">Undo<\/a>"+'</div>');
                $(".updated, .error").fadeOut(500).fadeIn(500);
            });
            </script>
            <h3 class="floated">Person Management</h3>


This seems to be the responsible part from jquery.getsimple.js:
Code:
[... whole-lot more js here ...]

$.ajax({
    type: "GET",
    url: dlink,
    success: function(response){
        console.log(response); /* LOG RESPONSE TO DETECT PROBLEMS */
            
        mytr.remove();
        if($("#pg_counter").length) {
            counter=$("#pg_counter").html();
            $("#pg_counter").html(counter-1);
        }
                            
        $('div.wrapper .updated').remove();
        $('div.wrapper .error').remove();
        if($(response).find('div.error').html()) {
            $('div.bodycontent').before('<div class="error"><p>'+ $(response).find('div.error').html() + '</p></div>');
            popAlertMsg();
        }
        if($(response).find('div.updated').html()) {
            $('div.bodycontent').before('<div class="updated"><p>'+ $(response).find('div.updated').html() + '</p></div>');
            popAlertMsg();
        }
    }
});



Problem with 3.1: Success Message with undo - from Tips & Tricks - Petit Jean - 2012-04-26

This seems to be part of the problem:
Code:
$(response).find('div.updated').html()
The javascript is not first evaluated! (look in my ajax success response)
The response is just a string, so there exists no DOM element with class "updated".

I temporarily fixed it this way in my plugin, but some core developer could think this through.

Because when you now enter the page directly via the URL you get a hidden hardcoded <div> and one from the js.

Code:
<?php
    if (isset($msg)) {
        if ($canUndo) $msg .= ' <a href="load.php?id=myplugin&undo">' . i18n_r('UNDO') . '</a>'
        ?>
        <script type="text/javascript">
        $(function() {
            $('div.bodycontent').before('<div class="<?php echo $isSuccess ? 'updated' : 'error'; ?>" style="display:block;">'+
            <?php echo json_encode($msg); ?>+'</div>');
            $(".updated, .error").fadeOut(500).fadeIn(500);
        });
        </script>
        <!-- THE DIRTY TEMPORARY FIX -->
        <div class="<?php echo $update ? 'updated' : 'error'; ?>" style="display:none;visibility:hidden;height:0;margin:0;padding:0;border:0;"><?php echo $msg; ?></div>
        <?php
    }
?>



Problem with 3.1: Success Message with undo - from Tips & Tricks - Petit Jean - 2012-04-26

From jQuery docs:

dataType
"html": Returns HTML as plain text; included script tags are evaluated when inserted in the DOM.

Obviously, the response is never inserted into the DOM


Problem with 3.1: Success Message with undo - from Tips & Tricks - shawn_a - 2012-04-26

I will take a look at this.

Redoing the notification system is something I would like to see addressed also as there are some other UX issues with it.


Problem with 3.1: Success Message with undo - from Tips & Tricks - shawn_a - 2012-04-27

sorry, reread, your trying to use a normal page also as an ajax response ?
Can you not add a querystring or something to send the response div only, and the page itself when loading directly.


Problem with 3.1: Success Message with undo - from Tips & Tricks - Petit Jean - 2012-04-27

I'm just using the "standard" build-in method.
If you delete a page from pages.php, the whole page is send as an ajax response too.

I'm new to GetSimple, so i'm conforming to it's standards, and trying to see the coherence in the code and methods.


Problem with 3.1: Success Message with undo - from Tips & Tricks - shawn_a - 2012-04-27

Petit Jean Wrote:I'm just using the "standard" build-in method.
If you delete a page from pages.php, the whole page is send as an ajax response too.

I'm new to GetSimple, so i'm conforming to it's standards, and trying to see the coherence in the code and methods.

ok ill take a look at that then, you said undo, and undo is not ajax from what i can tell.

honestly this method is a bit kludgy, extracting notification and copying its inner html to the one on the page.

Thats why this is was in the tips and tricks section, its hackey, not conformity. You will see much better conformity from the rest of the project, notifications aren't really something that's been implemented yet to be developer friendly.


Problem with 3.1: Success Message with undo - from Tips & Tricks - ccagle8 - 2012-04-28

agreed about the current notification not being the best way... it was built in pre-plugin days, and with the advent of plugins - it just doesnt work great