/**
 * Detail Preview Extension for PHPMaker 2019
 * @license (C) 2018 e.World Technology Ltd.
 */
ew.LOADING_HTML="<div class='ew-spinner'><div></div></div> "+ew.language.phrase("Loading");ew.PREVIEW_BUTTON_SELECTOR=".ew-preview-row-btn";ew.PREVIEW_OVERLAY_WIDTH=1e3;ew.addRowToTable=function(e){var t=jQuery,a=t(e),r,o,i=0;var d=a.closest("tbody");if(ew.PREVIEW_SINGLE_ROW)d.find("tr."+ew.TABLE_PREVIEW_ROW_CLASSNAME).remove();t(e.cells).each(function(){i+=this.colSpan});var s=a.nextAll("tr[data-rowindex!="+a.data("rowindex")+"]").first();if(s.hasClass(ew.TABLE_PREVIEW_ROW_CLASSNAME)){return s[0]}else if(r=d[0].insertRow(s[0]?s[0].sectionRowIndex:-1)){t(r).addClass(ew.TABLE_PREVIEW_ROW_CLASSNAME);o=t(r.insertCell(0)).addClass(ew.TABLE_LAST_COL_CLASSNAME).prop("colSpan",i)}return r};ew.showDetails=function(e){var t=jQuery,a=t(this),r=a.is("tr[data-rowindex]"),o=r?a:a.closest("tr[data-rowindex]"),i=o.closest("table");if(!o[0])return;if(!o.data("preview")){var d=ew.addRowToTable(o[0]);var s=t(d.cells[0]);var n=o.find("[class$=_preview] div.ew-preview");s.empty();s.append(t("#ew-preview").contents().clone()).find(".nav-tabs").append(n.find("li:has([data-toggle='tab'])").clone(true)).find("[data-toggle='tab']").attr("data-target","#"+s.find(".tab-pane").attr("id",ew.random()).attr("id")).first().tab("show");(ew.PREVIEW_SINGLE_ROW?i:o).find(ew.PREVIEW_BUTTON_SELECTOR).addClass("icon-expand").removeClass("icon-collapse");o.data("preview",true).find(ew.PREVIEW_BUTTON_SELECTOR).addClass("icon-collapse").removeClass("icon-expand")}else{var l=o.nextAll("tr[data-rowindex!='"+o.data("rowindex")+"']").first();if(l.hasClass(ew.TABLE_PREVIEW_ROW_CLASSNAME))l.remove();o.data("preview",false).find(ew.PREVIEW_BUTTON_SELECTOR).addClass("icon-expand").removeClass("icon-collapse")}ew.setupTable(-1,i[0],true);if(o.data("preview")===false)ew.fixLayoutHeight()};ew.detail=function(e,t){var a=jQuery,r=a(t),o=r.closest(".ew-list-option-body"),i=r.data("placement")||ew.PREVIEW_PLACEMENT,d=o.find(".dropdown-menu"),s=o.find(".btn-group");d.mouseenter(function(e){e.stopPropagation()});if(s[0]){if(i=="right")d.addClass("float-right");r=s.first()}if(r.data("bs.popover"))return;r.popover({html:true,delay:{show:100,hide:250},placement:i,trigger:"hover",container:a("#ew-tooltip")[0],content:ew.LOADING_HTML}).on("shown.bs.popover",function(e){var t=ew.PREVIEW_OVERLAY_WIDTH,d=a(r.data("bs.popover").getTipElement()).css("max-width",t+"px");if(i=="left"){var s=r.closest(".btn-group").offset();d.css({"min-width":t+"px",transform:"none",left:s.left-t-d.find(".arrow").width(),top:s.top})}else{d.css("min-width","200px")}d.find(".popover-body").html(a("#ew-preview").html());d.find(".nav-tabs").append(o.find("li:has([data-toggle='tab'])").clone(true));d.find("[data-toggle='tab']").attr("data-target","#"+d.find(".tab-pane").attr("id",ew.random()).attr("id")).data("$element",r).first().tab("show")});var n=r.data("bs.popover");a(n.getTipElement()).mouseenter(function(e){clearTimeout(n._timeout)}).mouseleave(function(e){if(a(n.getTipElement()).html().indexOf(ew.LOADING_HTML)>-1)return;n._timeout=setTimeout(function(){n.hide()},n.config.delay.hide)})};ew.tabShow=function(e){var t=jQuery,a=t(e.currentTarget),r=a.data("target"),o=t(r),i=a.data("table"),d="",s;if(!o[0])return;if(a.data("url")){s=o.data(i)||{};s.url=url=a.data("url");start=s.start||1;sort=s.sort;sortOrder=s.sortOrder}else if(a.data("start")){if(a.tooltip)a.tooltip("hide");s=o.data(i);url=s.url;s.start=start=a.data("start")||1;sort=s.sort;sortOrder=s.sortOrder}else if(a.data("sort")){s=o.data(i);url=s.url;start=s.start||1;s.sort=sort=a.data("sort");s.sortOrder=sortOrder=a.data("sortOrder");if(sort!==s.sort||sortOrder!==s.sortOrder){s.start=start=1;s.sortOrder=sortOrder=""}}o.data(i,s).empty().html(ew.LOADING_HTML);if(t.isNumber(start))d+="&start="+start;if(sort){d+="&sort="+encodeURIComponent(sort);if(sortOrder=="ASC"||sortOrder=="DESC")d+="&sortorder="+sortOrder}t.get(url+d,function(e){o.empty().html(e).append(t("div[data-table='"+i+"'][data-url='"+url+"']:first").clone());o.find(".ew-pager > div > .btn-group > .btn:not(.disabled), .ew-table-header > th > div[data-sort]").data({target:r,table:i}).click(ew.tabShow);t(document).trigger("preview",[{$tabpane:o}])})};ew.preview=function(e,t){var a=jQuery,r=t.$tabpane,e=a.Event("preview",{target:r});r.find("table."+ew.TABLE_CLASSNAME).each(ew.setupTable);ew.initTooltips(e);ew.initLightboxes(e);ew.initIcons(e);ew.lazyLoad(e);ew.fixLayoutHeight()};jQuery(document).on("preview",ew.preview);jQuery(function(e){if(ew.PREVIEW_OVERLAY)e("div.ew-preview").each(function(){e(this).parent().find("[data-action='view'],[data-action='list']").each(ew.detail)});e(ew.PREVIEW_BUTTON_SELECTOR).click(ew.showDetails);e("div.ew-preview [data-toggle='tab']").on("show.bs.tab",ew.tabShow)});