Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Partial Updates for Gadget ?

Vote:
 

I just yesterday started trying out gadget development and did the tutorial for a QuickChat (http://world.episerver.com/Documentation/Items/Tech-Notes/EPiServer-CMS-6/EPiServer-CMS-60/Gadgets---Tutorial/) and it's all nice and working, however the ajax update on 5 seconds is a bit anoying since it updates the entire view and not only the messages. If i start typing in the message box for a new message it will be cleared when the gadget gets refreshed.

I found a small gadget api reference (http://world.episerver.com/Documentation/Items/Tech-Notes/EPiServer-CMS-6/EPiServer-CMS-60/OnlineCenter-Developer-Documentation/) but there is no hint about how to do partial updates for a gadget like partial updates in MVC.

Does anyone know how to do this ?

#46530
Dec 16, 2010 10:03
Vote:
 

I found this old script that I think takes care of only updating the messages. QuickChat.js:

(function($) {
    quickchat = {};
    quickchat.init = function(e, gadgetContext) {
        // Reloads the gadget if it is visible
        var reload = function() {
            if (gadgetContext.isVisible()) {
                // Using the uses the gadet's ajax handler brings 
                // features such as the ajax loader and error handling 
                var routeValues = { action: "Messages" }
                var actionUrl = gadgetContext.getActionPath(routeValues);
                gadgetContext.ajax({
                    url: actionUrl,
                    dataType: "html",
                    success: successHandler
                });
            }
        };

        // Updates the messages div with new content retrieved 
        // by the ajax request
        var successHandler = function(data) {
            var chatMessages = $(".messages", gadgetContext.element);
            chatMessages.html(data);
        };

        // start reloading the messages at an interval
        setInterval(reload, 5000);
    };
})(epiJQuery);

    

#46531
Edited, Dec 16, 2010 10:18
Vote:
 

Looks promising but (var gadgetInstance = gadgetContext.instance;),
Gets a null value wich breaks on isVisible function.

anything im missing ?

#46532
Dec 16, 2010 10:31
Vote:
 

It seems the code predated the release version and some things have changed. I updated it a bit and it might work better now.

#46535
Dec 16, 2010 10:46
Vote:
 

It ain't breaking now but i can't really se any ajax updates either, it's like the 5 sec intervall ain't running.

Firebug in Firefox is not picking upp any ajax calls, not in the net tab or console tab.

Any Clues ?

#46536
Dec 16, 2010 10:56
Vote:
 

What happens if you remove the isvisible check? This really isn't a good way to debug old code ;)

#46537
Dec 16, 2010 10:59
Vote:
 

Well now it starts refresh every 5 sec, although now i get 500 errors so i gota figure that one out now.

Got it working now but my entire gadget replaced the orginal message list and now is updated. How is your Messages action setup ?

Made a new partial view for the message part and that is working nice now, only updates that part too :)

#46538
Edited, Dec 16, 2010 11:01
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.