//
/**
 * event.fetcher.js
 * 
 * Is used to fetch a single Event from the Hope EventManager for rendering.
 * 
 * @author Ryan Hardy
 * @version 1.0
 */
(function() {
    var ns = jwyre.module("wendigo");
    var ens = jwyre.module("org.hopesb.Event");
    ens.render = ens.render || function() {};
        
    var isDebug = jwyre.parseBoolean("false", false);
    ns.loadMappings("hope", "do");
    var req = ns._createRequest("getEvent");
    
    /**
     * Load the JSON rendering of an Event or all Events.
     * 
     */
    jwyre.load(function() {
       var appId = null;
       ns.doAjax({
           "request" : req,
           "paramAdder" : function(qry) {
                //if an appId is provided, get single Event
                //if appId is null, get all Event objects
                qry.add("appId", appId); 
           },
           "doWait" : false,
           "callback" : function(json) {
               if (appId == null) {
                   var evts = JSON.parse(json.events, function(k,v) { return v; });
                   org.hopesb.Event.render(evts, json.pageLinks);
               } else {
                   var evt = JSON.parse(json.event, function(k,v) { return v; });
                   org.hopesb.Event.render(evt);
               }
           }
           
           
       });  

    });
    
})();
