DataExplorer.Sidebar=function(){function h(h){n=$("#schema");t=$("#history");u=n.add(t);s=h;r=$(h.panel);i=r.add(h.toolbar);f=i.find("#schema-toggle").on("click",o);c();DataExplorer.options.User.isAuthenticated&&(e=new DataExplorer.DeferredRequest({url:"/users/save-preference/:id/HideSchema".format({id:DataExplorer.options.User.id})}),DataExplorer.options.User.hideSchema&&o(!1,!0))}function c(){var t=!0;n.TextAreaResizer(l,{offsetTop:n.find(".heading").outerHeight(),resizeSelector:"ul"});n.addClass("cm-s-"+s.editorTheme);n.on("click",".schema-table",function(){$(this).next("dl").toggle()});n.find(".expand").on("click",function(){n.find("dl").show()});n.find(".collapse").on("click",function(){n.find("dl").hide()});n.find(".sort").on("click",function(){a(t=!t);$(this).prop("title","sort "+(t?"alphabetically":"normally")).toggleClass("icon-sort-by-alphabet",t).toggleClass("icon-sort-by-order",!t)})}function o(n,t){n!==!!n&&(n=f.hasClass("hidden"));n||u.hide();t!==!0?i.animate({width:n?"70%":"100%"},"fast",function(){n&&u.show()}):i.css("width",n?"70%":"100%");f.text((n?"hide":"show")+" sidebar").toggleClass("hidden",!n);e&&e.request({value:!n})}function l(){var u=r.outerHeight(),f=u-n.outerHeight(),i=t.children("ul"),e=t.outerHeight()-i.height();i.height(f-e)}function a(t){n.children("ul").sortChildren(function(n){var i=$(n);return i.children("dl").sortChildren(function(n){return n.tagName!=="DT"?!1:t?parseInt(n.getAttribute("data-order")):n[_textContent]},function(n,t){var i=getNextElementSibling(t);n.appendChild(t);n.appendChild(i)}),t?parseInt(n.getAttribute("data-order")):i.children(".schema-table").text()})}function v(n){if(n.created){var i=n.created.replace(/\.\d+Z/,"Z"),r="/"+n.siteName+"/revision/"+n.querySetId+"/"+n.revisionId+"/"+n.slug;n.parentId&&t.find("#revision-"+n.parentId).addClass("parent");t.find(".empty").remove();t.find(".selected").removeClass("selected");t.children("ul").prepend('<li id="revision-'+n.revisionId+'" class="selected"><a href="'+r+'"><span class="revision-info">'+n.revisionId+'<\/span><\/a><span class="relativetime" title="'+i+'"><\/span><div style="clear:both"><\/div><\/li>');t.find("li:last").addClass("last");window.history&&window.history.pushState&&document.URL.indexOf("query/edit")==-1&&window.history.pushState(null,"","/"+n.siteName+"/query/edit/"+n.querySetId)}t.find(".relativetime").each(function(){this[_textContent]=Date.parseTimestamp(this.title).toRelativeTimeMini()})}var n,t,s,r,i,u,f,e;return{init:h,toggle:o,updateHistory:v}}();DataExplorer.TableHelpers=function(){function u(u){var f=document.getElementById("schema");t=u;$("ul .schema-table",f).each(function(){var a=this[_textContent],e=t[a.toCamelCase()],u,l,s;if(e){var v=i.cloneNode(!0),y=r.cloneNode(!0),o=n.cloneNode(!0),p=$(o);this.appendChild(v);o.children[0][_textContent]=a;o.children[0].appendChild(y);$(y).click(function(){p.hide()});var w=o.getElementsByTagName("table")[0],h=w.children[1],b=w.children[0].children[0],c=h.children[0];for(h.removeChild(c),u=0;u<e.columns.length;++u)b.appendChild(document.create("th",{text:e.columns[u].name})),c.appendChild(document.create("td",{className:e.columns[u].type.toLowerCase()}));for(u=0;u<e.rows.length;++u){for(l=c.cloneNode(!0),s=0;s<e.columns.length;++s)l.children[s][_textContent]=e.rows[u][s];h.appendChild(l)}f.insertBefore(o,f.children[0]);$(v).click(function(){return p.show(),!1})}})}function f(n){$("#schema .table-data-wrapper").css({height:n+"px"})}var t,i=document.create("i",{className:"icon-info button table-data",title:"show the contents of this table"}),r=document.create("i",{className:"icon-remove button table-data-close",title:"hide the contents of this table"}),n=document.create("div",{className:"table-data-panel hidden"});return n.appendChild(document.create("span",{className:"schema-table"})),n.appendChild(function(){var t=document.create("div",{className:"table-data-wrapper"}),n=document.createElement("table"),i=document.createElement("thead"),r=document.createElement("tbody");return t.appendChild(n),n.appendChild(i),n.appendChild(r),i.appendChild(document.createElement("tr")),r.appendChild(document.createElement("tr")),t}()),{init:u,resize:f}}()