!function(e){var t,i,r={},a=[];t=function(t){var i=a[t],r=e("#"+t).find("."+i.tableClass);return r.children("tbody").find("input.select-on-check").filter(":checked").each(function(){e(this).closest("tr").addClass("selected")}),r.children("thead").find("th input").filter('[type="checkbox"]').each(function(){var t=this.name.substring(0,this.name.length-4)+"[]",i=e("input[name='"+t+"']",r);this.checked=i.length>0&&i.length===i.filter(":checked").length}),this},i={init:function(i){var r=e.extend({ajaxUpdate:[],ajaxVar:"ajax",ajaxType:"GET",csrfTokenName:null,csrfToken:null,pagerClass:"pager",loadingClass:"loading",filterClass:"filters",tableClass:"items",selectableRows:1},i||{});return r.tableClass=r.tableClass.replace(/\s+/g,"."),this.each(function(){var i,n,s=e(this),d=s.attr("id"),l="#"+d+" ."+r.pagerClass.replace(/\s+/g,".")+" a",c="#"+d+" ."+r.tableClass+" thead th a.sort-link",o="#"+d+" ."+r.filterClass+" input, #"+d+" ."+r.filterClass+" select";r.updateSelector=r.updateSelector.replace("{page}",l).replace("{sort}",c),r.filterSelector=r.filterSelector.replace("{filter}",o),a[d]=r,r.ajaxUpdate.length>0&&e(document).on("click.yiiGridView",r.updateSelector,function(){if(r.enableHistory&&window.History.enabled){var t=e(this).attr("href");if(t){var i=t.split("?"),a=e.deparam.querystring("?"+(i[1]||""));delete a[r.ajaxVar];var n=e.param.querystring(i[0],a);window.History.pushState({url:n},document.title,n)}}else e("#"+d).yiiGridView("update",{url:e(this).attr("href")});return!1}),e(document).on("change.yiiGridView keydown.yiiGridView",r.filterSelector,function(t){if("keydown"===t.type){if(13!==t.keyCode)return;i="keydown",n=t.target}else if("keydown"===i&&n===t.target)return i="",void(n=null);var a=e(r.filterSelector).serialize();if(void 0!==r.pageVar&&(a+="&"+r.pageVar+"=1"),r.enableHistory&&r.ajaxUpdate!==!1&&window.History.enabled){var s=e("#"+d).yiiGridView("getUrl"),l=e.deparam.querystring(e.param.querystring(s,a));delete l[r.ajaxVar];var c=e.param.querystring(s.substr(0,s.indexOf("?")),l);window.History.pushState({url:c},document.title,c)}else e("#"+d).yiiGridView("update",{data:a});return!1}),r.enableHistory&&r.ajaxUpdate!==!1&&window.History.enabled&&e(window).bind("statechange",function(){var t=window.History.getState();void 0===t.data.url&&(t.data.url=t.url),e("#"+d).yiiGridView("update",t.data)}),r.selectableRows>0?(t(this.id),e(document).on("click.yiiGridView","#"+d+" ."+r.tableClass+" > tbody > tr",function(t){var i,a,n,s,l=e(t.target);l.closest("td").is(".empty,.button-column")||"checkbox"===t.target.type&&!l.hasClass("select-on-check")||(a=e(this),i=e("#"+d),s=e("input.select-on-check",i),n=a.toggleClass("selected").hasClass("selected"),1===r.selectableRows&&(a.siblings().removeClass("selected"),s.prop("checked",!1)),e("input.select-on-check",a).prop("checked",n),e("input.select-on-check-all",i).prop("checked",s.length===s.filter(":checked").length),void 0!==r.selectionChanged&&r.selectionChanged(d))}),r.selectableRows>1&&e(document).on("click.yiiGridView","#"+d+" .select-on-check-all",function(){var t=e("#"+d),i=e("input.select-on-check",t),a=e("input.select-on-check-all",t),n=t.find("."+r.tableClass).children("tbody").children();this.checked?(n.addClass("selected"),i.prop("checked",!0),a.prop("checked",!0)):(n.removeClass("selected"),i.prop("checked",!1),a.prop("checked",!1)),void 0!==r.selectionChanged&&r.selectionChanged(d)})):e(document).on("click.yiiGridView","#"+d+" .select-on-check",!1)})},getKey:function(e){return this.children(".keys").children("span").eq(e).text()},getUrl:function(){var e=a[this.attr("id")].url;return e||this.children(".keys").attr("title")},getRow:function(e){var t=a[this.attr("id")].tableClass;return this.find("."+t).children("tbody").children("tr").eq(e).children()},getColumn:function(e){var t=a[this.attr("id")].tableClass;return this.find("."+t).children("tbody").children("tr").children("td:nth-child("+(e+1)+")")},update:function(i){var n;return i&&void 0!==i.error&&(n=i.error,delete i.error),this.each(function(){var s,d=e(this),l=d.attr("id"),c=a[l];i=e.extend({type:c.ajaxType,url:d.yiiGridView("getUrl"),success:function(i){var r=e("
"+i+"
");e.each(c.ajaxUpdate,function(t,i){var a="#"+i;e(a).replaceWith(e(a,r))}),void 0!==c.afterAjaxUpdate&&c.afterAjaxUpdate(l,i),c.selectableRows>0&&t(l)},complete:function(){r[l]=null,d.removeClass(c.loadingClass)},error:function(e,t,i){var r,a;if(0!==e.readyState&&0!==e.status&&(void 0===n||(r=n(e),void 0===r||r))){switch(t){case"timeout":a="The request timed out!";break;case"parsererror":a="Parser error!";break;case"error":a=e.status&&!/^\s*$/.test(e.status)?"Error "+e.status:"Error",e.responseText&&!/^\s*$/.test(e.responseText)&&(a=a+": "+e.responseText)}void 0!==c.ajaxUpdateError?c.ajaxUpdateError(e,t,i,a,l):a&&alert(a)}}},i||{}),"GET"===i.type?void 0!==i.data&&(i.url=e.param.querystring(i.url,i.data),i.data={}):void 0===i.data&&(i.data={},e.each(e(c.filterSelector).serializeArray(),function(){i.data[this.name]=this.value})),c.csrfTokenName&&c.csrfToken&&("string"==typeof i.data?i.data+="&"+c.csrfTokenName+"="+c.csrfToken:i.data[c.csrfTokenName]=c.csrfToken),null!=r[l]&&r[l].abort(),d.addClass(c.loadingClass),c.ajaxUpdate!==!1?(c.ajaxVar&&(i.url=e.param.querystring(i.url,c.ajaxVar+"="+l)),void 0!==c.beforeAjaxUpdate&&c.beforeAjaxUpdate(l,i),r[l]=e.ajax(i)):"GET"===i.type?window.location.href=i.url:(s=e('
').appendTo("body"),void 0===i.data&&(i.data={}),void 0===i.data.returnUrl&&(i.data.returnUrl=window.location.href),e.each(i.data,function(t,i){s.append(e('').attr("name",t).val(i))}),s.submit())})},getSelection:function(){var t=a[this.attr("id")],i=this.find(".keys span"),r=[];return this.find("."+t.tableClass).children("tbody").children().each(function(t){e(this).hasClass("selected")&&r.push(i.eq(t).text())}),r},getChecked:function(e){var t=a[this.attr("id")],i=this.find(".keys span"),r=[];return"[]"!==e.substring(e.length-2)&&(e+="[]"),this.find("."+t.tableClass).children("tbody").children("tr").children("td").children('input[name="'+e+'"]').each(function(e){this.checked&&r.push(i.eq(e).text())}),r}},e.fn.yiiGridView=function(t){return i[t]?i[t].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof t&&t?(e.error("Method "+t+" does not exist on jQuery.yiiGridView"),!1):i.init.apply(this,arguments)},e.fn.yiiGridView.settings=a,e.fn.yiiGridView.getKey=function(t,i){return e("#"+t).yiiGridView("getKey",i)},e.fn.yiiGridView.getUrl=function(t){return e("#"+t).yiiGridView("getUrl")},e.fn.yiiGridView.getRow=function(t,i){return e("#"+t).yiiGridView("getRow",i)},e.fn.yiiGridView.getColumn=function(t,i){return e("#"+t).yiiGridView("getColumn",i)},e.fn.yiiGridView.update=function(t,i){e("#"+t).yiiGridView("update",i)},e.fn.yiiGridView.getSelection=function(t){return e("#"+t).yiiGridView("getSelection")},e.fn.yiiGridView.getChecked=function(t,i){return e("#"+t).yiiGridView("getChecked",i)}}(jQuery);