Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with 3.1: Success Message with undo - from Tips & Tricks
#1
Simply put:

http://get-simple.info/wiki/plugins:tips...r_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();
        }
    }
});
Reply
#2
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
    }
?>
Reply
#3
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
Reply
#4
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.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#5
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.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#6
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.
Reply
#7
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.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#8
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
- Chris
Thanks for using GetSimple! - Download

Please do not email me directly for help regarding GetSimple. Please post all your questions/problems in the forum!
Reply




Users browsing this thread: 1 Guest(s)