How To UpdateObserver

Deprecated!

How to use the KnowWE update observer?#

Indroduction #

In KnowWE it often occurs that not only one element should be updated after a certain action. An example for this is the solutionstate panel and the questionsheet of the d3web-plugin. Both need to be updated in case the user selects an answer in the HTMLDialog.

In order to archive this the KnowWE-helper.js supplies an update function. This function - KNOWWE.helper.observer - takes advantage of the observer pattern (http://en.wikipedia.org/wiki/Observer_pattern).

The KNOWWE.helper.observer has the following functions:

Example#

Lets assume you have the following function:

    updateSolutionstate : function(){
        if(!_KS('#sstate-result')) return;
            
        var params = {
            action : 'DPSSolutionsAction',
            KWikiWeb : 'default_web'
        }

        var id = 'sstate-result';
        var options = {
            url : KNOWWE.core.util.getURL( params ),
            response : {
                action : 'insert',
                ids : [ id ]
            }
        }
        new _KA( options ).send(); 
    }

In order to register the above function to the observer you simply add the following line into the javascript...

    KNOWWE.helper.observer.subscribe( 'update', updateSolutionstate );

... and the following if you want to execute all the stored functions:

    KNOWWE.helper.observer.notify( 'update' );

Note: The old observer was extended due to the need of multiple observer objects. In order to register a function to the observer you have to supply an additional <name> which indicates the "observer object" the observable belongs to. In order to notify this "observer object" you need to call the notify function with the given <name>.

Currently used "observer objects"#

At the moment the following observer namespaces are used: