var PageManager2=new Class({options:{onLoad:Class.empty},initialize:function(B,A){this.pagemanager=B;this.setOptions(A);console.time("loaded");this.handleloaded.delay(500,this);console.timeEnd("loaded")},handleloaded:function(){for(var C=0;C<this.pagemanager.layerGroups.length;C++){var B=this.pagemanager.layerGroups[C];for(var A=0;A<B.layers.length;A++){var D=B.layers[A];if(!D.loadedframework){this.handleloaded.delay(500,this);return }}}this.options.onLoad()}});PageManager2.implement(new Options);function PageManager(B,C,A){this.pagetype=B;this.layerGroups=[];this.debug=false;this.concept=C;var D={x_filter:["text"],y_filter:["number"]};this.options=$merge(D,(A||{}));console.assert(this.concept,"you need to have a concept set");console.log("configuring page manager");this.configure();console.log("configured page manager; registering handlers");this.registerhandlers();console.log("registered handlers")}PageManager.prototype.addDatasetToSession=function(B,C){var A={concept:this.concept,member:B};if($defined(C)){A["like_rule_for"]=C}new Ajax("/cbi/blueprint/add_to_session",{method:"get",data:Object.toQueryString(A),onSuccess:(function(J){console.log("added dataset to session");console.log("response from add to sesh:",J);var K=Json.evaluate(J)[0];if(this.pagetype=="map"){var E=[];for(var H=0;H<K.length;H++){var L=K[H][0];var D=K[H][1];var G,F=false;for(G=0;G<D.length;G++){I=D[G];F=F||("style" in I)}if(!F){pageManager.loadDatasetInfo(B);continue}var N,I;N=new LayerGroup(L,null,false);for(G=0;G<D.length;G++){I=D[G];N.addLiteral(I,(("style" in I)&&(I["style"]=="raster")))}this.add(N,0);E.push(N)}var M=true;E.each(function(O){if(!O.datasetInfo){M=false;O.deferred.push(mapManager.refresh.bind(mapManager))}});if(M){mapManager.refresh()}console.log("refreshing map")}else{pageManager.loadDatasetInfo(B)}}).bind(this)}).request()};PageManager.prototype.removeDatasetFromSession=function(A){new Ajax("/cbi/blueprint/remove_from_session",{method:"get",data:Object.toQueryString({concept:this.concept,member:A}),onSuccess:function(){console.log("removed dataset from session")}}).request()};PageManager.prototype.configure=function(){var B;this.x_filter=this.options.x_filter;B=$("x_attribute_filter");if(B){console.log(B,B.options.length);for(var A=0;A<B.options.length;A++){if(B.options[A].value==this.x_filter[0]){B.options[A].selected=true;break}}}this.y_filter=this.options.y_filter;B=$("y_attribute_filter");if(B){for(var A=0;A<B.options.length;A++){if(B.options[A].value==this.y_filter[0]){B.options[A].selected=true;break}}}};PageManager.prototype.registerhandlers=function(){var A;A=$("x_attribute_filter");if(A){A.addEvent("change",(function(C){if(this.selectedIndex==0){return }var D=this.options[this.selectedIndex].value;C.x_filter=[D];for(var B=0;B<C.layerGroups.length;B++){C.layerGroups[B].filterByType("x",C.x_filter)}}).bind(A,this))}else{console.log("could not find x_attribute filter")}A=$("y_attribute_filter");if(A){A.addEvent("change",(function(C){if(this.selectedIndex==0){return }var D=this.options[this.selectedIndex].value;C.y_filter=[D];for(var B=0;B<C.layerGroups.length;B++){C.layerGroups[B].filterByType("y",C.y_filter)}}).bind(A,this))}else{console.log("could not find y_attribute filter")}};PageManager.prototype.loadDatasetInfo=function(B){console.log("load info for: "+String(B));console.assert(B,"datasetUuid must be set");var A=new LayerGroup(B,null);this.add(A,0);A.addVisibleLayer();return A};PageManager.prototype.addLayerGroup=function(C,A){var B=new LayerGroup(C,A);this.add(B);B.addVisibleLayer();return B};PageManager.prototype.add=function(B,C){if(C===undefined){C=this.layerGroups.length}var A=document.getElementById("visualization_members");if(C==this.layerGroups.length){A.appendChild(B.domNode)}else{var D=this.layerGroups[C];A.insertBefore(B.domNode,D.domNode)}this.layerGroups.splice(C,0,B);this.updateNumVisualizationMembers()};PageManager.prototype.moveUp=function(A){var B=this.layerGroups.indexOf(A);console.assert((B>=0),"layer group not in this page manager");this.reorder(A,B-1)};PageManager.prototype.moveDown=function(A){var B=this.layerGroups.indexOf(A);console.assert((B>=0),"layer group not in this page manager");this.reorder(A,B+1)};PageManager.prototype.reorder=function(A,B){B=Math.max(B,0);B=Math.min(B,this.layerGroups.length-1);this.removeObj(A);this.add(A,B);if(typeof (mapManager)!="undefined"){mapManager.checkModels()}};PageManager.prototype.removeObj=function(A){this.layerGroups.remove(A);$(A.domNode).remove();if((this.pagetype=="map")&&(typeof (mapManager)!="undefined")){A.layers.each(function(B){mapManager.remove(B)})}this.updateNumVisualizationMembers()};PageManager.prototype.updateNumVisualizationMembers=function(){var A="";if(this.layerGroups.length==1){A="1 Dataset"}else{A=this.layerGroups.length+" Datasets"}$("num_visualization_members").setText(A)};PageManager.prototype.remove=function(C){for(var B=0;B<this.layerGroups.length;B++){var A=this.layerGroups[B];if(A.u==C){console.log("found layergroup -- removing?");this.removeObj(A);return }}console.log("did not find layer group to remove")};PageManager.prototype.update=function(A){};PageManager.prototype.setDebug=function(A){this.debug=A};PageManager.prototype.getPageType=function(){return this.pagetype}