/* See license.txt for terms of usage */ define("preview/requestBody",["domplate/domplate","i18n!nls/requestBody","core/lib","core/cookies","domplate/tabView","core/dragdrop","syntax-highlighter/shCore"],function(Domplate,Strings,Lib,Cookies,TabView,DragDrop,dp){with(Domplate){function RequestBody(){}RequestBody.prototype=domplate({render:function(e,t){var n=new TabView("requestBody");t.response.headers.length>0&&n.appendTab(new HeadersTab(t)),t.request.queryString&&t.request.queryString.length&&n.appendTab(new ParamsTab(t)),t.request.postData&&n.appendTab(new SentDataTab(t,t.request.method)),t.response.content.text&&t.response.content.text.length>0&&n.appendTab(new ResponseTab(t)),this.showCache(t)&&n.appendTab(new CacheTab(t)),this.showHtml(t)&&n.appendTab(new HtmlTab(t)),this.showDataURL(t)&&n.appendTab(new DataURLTab(t));var r=n.render(e);return n.tabs.length>0&&n.selectTabByName(n.tabs[0].id),r},showCache:function(e){return e.cache?e.cache.afterRequest?e.category=="image"?!1:!0:!1:!1},showHtml:function(e){var t=e.response.content.mimeType||"",n=e.mimeType||"";return Lib.startsWith(t,"text/html")||Lib.startsWith(n,"application/xhtml+xml")},showDataURL:function(e){return e.request.url.indexOf("data:")==0}});function HeadersTab(e){this.file=e}HeadersTab.prototype=domplate(TabView.Tab.prototype,{id:"Headers",label:Strings.Headers,bodyTag:TABLE({"class":"netInfoHeadersText netInfoText netInfoHeadersTable",cellpadding:0,cellspacing:0},TBODY(TR({"class":"netInfoResponseHeadersTitle"},TD({colspan:2},DIV({"class":"netInfoHeadersGroup"},Strings.ResponseHeaders))),TR({"class":"netInfoRequestHeadersTitle"},TD({colspan:2},DIV({"class":"netInfoHeadersGroup"},Strings.RequestHeaders))))),headerDataTag:FOR("param","$headers",TR(TD({"class":"netInfoParamName"},"$param.name"),TD({"class":"netInfoParamValue"},PRE("$param|getParamValue")))),getParamValue:function(e){return Lib.wrapText(e.value,!0)},onUpdateBody:function(e,t){this.file.response.headers&&this.insertHeaderRows(t,this.file.response.headers,"Headers","ResponseHeaders"),this.file.request.headers&&this.insertHeaderRows(t,this.file.request.headers,"Headers","RequestHeaders")},insertHeaderRows:function(e,t,n,r){var i=Lib.getElementByClass(e,"netInfo"+n+"Table"),s=Lib.getElementByClass(i,"netInfo"+r+"Title");t.length?(this.headerDataTag.insertRows({headers:t},s?s:e),Lib.removeClass(s,"collapsed")):Lib.setClass(s,"collapsed")}});function ResponseTab(e){this.file=e}ResponseTab.prototype=domplate(TabView.Tab.prototype,{id:"Response",label:Strings.Response,bodyTag:DIV({"class":"netInfoResponseText netInfoText"},PRE({"class":"javascript:nocontrols:nogutter:",name:"code"})),onUpdateBody:function(e,t){var n=Lib.getElementByClass(t,"netInfoResponseText");if(this.file.category=="image"){Lib.clearNode(n);var r=t.ownerDocument.createElement("img");r.src=this.file.href,n.appendChild(r,n)}else{Lib.clearNode(n.firstChild);var i=this.file.response.content.text,s=this.file.response.content.mimeType;s=="application/javascript"||s=="text/javascript"||s=="application/x-javascript"||s=="text/ecmascript"||s=="application/ecmascript"?(n.firstChild.innerHTML=i,dp.SyntaxHighlighter.HighlightAll(n.firstChild)):Lib.insertWrappedText(i,n.firstChild)}}});function ParamsTab(e){this.file=e}ParamsTab.prototype=domplate(HeadersTab.prototype,{id:"Params",label:Strings.URLParameters,bodyTag:TABLE({"class":"netInfoParamsText netInfoText netInfoParamsTable",cellpadding:0,cellspacing:0},TBODY()),onUpdateBody:function(e,t){if(this.file.request.queryString){var n=Lib.getElementByClass(t,"netInfoParamsText");this.insertHeaderRows(n,this.file.request.queryString,"Params")}}});function SentDataTab(e,t){t=t.charAt(0).toUpperCase()+t.slice(1).toLowerCase(),this.file=e,this.id=t,this.label=Strings[t]}SentDataTab.prototype=domplate(HeadersTab.prototype,{bodyTag:DIV({"class":"netInfo$tab.id\\Text netInfoText"},TABLE({"class":"netInfo$tab.id\\Table",cellpadding:0,cellspacing:0},TBODY())),onUpdateBody:function(e,t){var n=this.file.request.postData;if(!n)return;var r=Lib.getElementByClass(t,"netInfo"+this.id+"Text");n.mimeType=="application/x-www-form-urlencoded"?this.insertHeaderRows(r,n.params,this.id):Lib.insertWrappedText(n.text,r)}});function CookiesTab(e){this.file=e}CookiesTab.prototype=domplate(HeadersTab.prototype,{id:"Cookies",label:Strings.Cookies,bodyTag:DIV({"class":"netInfoCookiesText netInfoText"},TABLE({"class":"netInfoCookiesTable",cellpadding:0,cellspacing:0},TBODY(TR({"class":"netInfoResponseCookiesTitle"},TD({colspan:2},DIV({"class":"netInfoCookiesGroup"},Strings.ResponseCookies))),TR({"class":"netInfoRequestCookiesTitle"},TD({colspan:2},DIV({"class":"netInfoCookiesGroup"},Strings.RequestCookies)))))),onUpdateBody:function(e,t){if(file.response.cookies){var n=Lib.getElementByClass(t,"netInfoParamsText");this.insertHeaderRows(n,file.response.cookies,"Cookies","ResponseCookies")}if(file.request.cookies){var n=Lib.getElementByClass(t,"netInfoParamsText");this.insertHeaderRows(n,file.request.cookies,"Cookies","RequestCookies")}}});function CacheTab(e){this.file=e}CacheTab.prototype=domplate(HeadersTab.prototype,{id:"Cache",label:Strings.Cache,bodyTag:DIV({"class":"netInfoCacheText netInfoText"},TABLE({"class":"netInfoCacheTable",cellpadding:0,cellspacing:0},TBODY())),onUpdateBody:function(e,t){if(this.file.cache&&this.file.cache.afterRequest){var n=this.file.cache.afterRequest,r=[];for(var i in n)r.push({name:i,value:n[i]});this.insertHeaderRows(t,r,"Cache")}}});function HtmlTab(e){this.file=e}HtmlTab.prototype=domplate(HeadersTab.prototype,{id:"HTML",label:Strings.HTML,bodyTag:DIV({"class":"netInfoHtmlText netInfoText"},IFRAME({"class":"netInfoHtmlPreview",onload:"$onLoad"}),DIV({"class":"htmlPreviewResizer"})),onUpdateBody:function(e,t){this.preview=Lib.getElementByClass(t,"netInfoHtmlPreview");var n=parseInt(Cookies.getCookie("htmlPreviewHeight"));isNaN(n)||(this.preview.style.height=n+"px");var r=Lib.getElementByClass(t,"htmlPreviewResizer");this.resizer=new DragDrop.Tracker(r,{onDragStart:Lib.bind(this.onDragStart,this),onDragOver:Lib.bind(this.onDragOver,this),onDrop:Lib.bind(this.onDrop,this)})},onLoad:function(e){var t=Lib.fixEvent(e),n=Lib.getAncestorByClass(t.target,"tabHTMLBody").repObject;n.preview.contentWindow.document.body.innerHTML=n.file.response.content.text},onDragStart:function(e){var t=Lib.getBody(this.preview.ownerDocument);t.setAttribute("hResizing","true"),this.startHeight=this.preview.clientHeight},onDragOver:function(e,t){var n=this.startHeight+e.y;this.preview.style.height=n+"px",Cookies.setCookie("htmlPreviewHeight",n)},onDrop:function(e){var t=Lib.getBody(this.preview.ownerDocument);t.removeAttribute("hResizing")}});function DataURLTab(e){this.file=e}return DataURLTab.prototype=domplate(HeadersTab.prototype,{id:"DataURL",label:Strings.DataURL,bodyTag:DIV({"class":"netInfoDataURLText netInfoText"}),onUpdateBody:function(e,t){var n=Lib.getElementByClass(t,"netInfoDataURLText"),r=this.file.request.url;if(r.indexOf("data:image")==0){var i=t.ownerDocument.createElement("img");i.src=r,n.appendChild(i)}else Lib.insertWrappedText(unescape(r),n)}}),RequestBody}});