helloyou2012 / canviz

Automatically exported from code.google.com/p/canviz
0 stars 0 forks source link

add json capability to load() #52

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

Not a problem, but a requested enhancement.  Oftentimes it is necessary to
pass back from a server auxiliary data besides the xdot source:  prompts,
thumbnail data, etc.  

So I suggest that the load() method have an additional parameter: is_json.
 When true, canviz expects JSON data, and parses the xdot portion using of
it Prototype, then calls a user javascript function outside of canviz for
any postprocessing of the rest of the JSON data.

Something like:
 // ********* this part unchanged ***************
 load: function(url, url_params,is_json) {
    $('debug_output').innerHTML = '';
    new Ajax.Request(url, {
      method: 'get',
      parameters: url_params,
      onComplete: function(response) {

        // *** changed part: **************
        if(is_json) {
          this.json = response.responseText.evalJSON(true);
          this.parse(this.json.image);
          postproc_json(this.json);
        }
        else {
          this.parse(response.responseText);
        }
        // ***** end changed part *****************

      }.bind(this)
    });
  },

and the user might have, outside of canviz.js, something like:

function postproc_json(jsonresponse) {
  $('thumbnails').innerHTML = jsonresponse.thumbnails;
  $('refresh_prompt').innerHTML = jsonresponse.refresh_prompt;
  $('auxactions').innerHTML = jsonresponse.auxactions; // anything that
requires a script to run AFTER the Ajax response is complete.

  eval($('auxactions').innerHTML);
  return(true);
}

Original issue reported on code.google.com by ron.newman on 11 Jan 2009 at 6:08

GoogleCodeExporter commented 8 years ago

Original comment by ryandesi...@gmail.com on 12 Jan 2009 at 3:30

GoogleCodeExporter commented 8 years ago
We talked about this in the discussion group:

http://groups.google.com/group/canviz/browse_thread/thread/3ce5e24c272f3191

I suggested we not add this to Canviz, because it's hard to anticipate the 
needs of
every Canviz client.

Instead, Canviz will continue to provide its simple load() method, and if you 
need
more complicated loading, do it yourself in your own code, and then call your 
Canviz
object's parse() method and give it the xdot code you've loaded. See the above 
thread
for sample code.

Original comment by ryandesi...@gmail.com on 26 Jan 2009 at 10:03