text: !function(a){"use strict";var b=function(a){this.gcrud_container=a,this.search_timer=null,this.csrf_field=null,this.init=function(){this.facadeInitListeners()},this.facadeInitListeners=function(){this.datagridInit(),this.listenerSelectRow(),this.listenerLoadMoreButton(),this.listenerDeleteMultiple(),this.listenerSearchButton(),this.listenerSearchInput(),this.listenerColumnWithOrdering(),this.listenerRefreshButton(),this.listenerPrintButton(),this.listenerExportButton(),this.listenerPerPage(),this.listenerPagingButtons()}};b.SELECTOR_PAGING_PREVIOUS=".paging-previous",b.SELECTOR_PAGING_NEXT=".paging-next",b.SELECTOR_PAGING_FIRST=".paging-first",b.SELECTOR_PAGING_LAST=".paging-last",b.CLASS_DISABLED="disabled",b.CLASS_LOADING="loading-opacity",b.CLASS_PAGING_PREVIOUS="paging-previous",b.CLASS_PAGING_NEXT="paging-next",b.CLASS_PAGING_FIRST="paging-first",b.CLASS_PAGING_LAST="paging-last",b.prototype.datagridInit=function(){var b=this.gcrud_container.find(".success-message");b.is(":empty")||a.growl(b.html(),{type:"success",delay:1e4,animate:{enter:"animated bounceInDown",exit:"animated bounceOutUp"}}),1===a("#gcrud-search-form>div:first>input[type=hidden]").length&&(this.csrf_field={name:a("#gcrud-search-form>div:first>input[type=hidden]").attr("name"),value:a("#gcrud-search-form>div:first>input[type=hidden]").val()},(void 0===this.csrf_field.name||void 0===this.csrf_field.value)&&(this.csrf_field=null))},b.prototype.appendSearchClearButtons=function(){var b=this;b.gcrud_container.find(".clear-search").remove(),b.gcrud_container.find(".grocery-crud-table input.searchable-input").each(function(){return a(this).removeClass("value-not-empty"),""===a(this).val()?!0:(a(this).addClass("value-not-empty"),a(this).after('<i class="fa fa-times clear-search"></i>'),void b.gcrud_container.find(".clear-search").click(function(){a(this).closest("td").find(".searchable-input").val("").trigger("keyup")}))})},b.prototype.listenerRefreshButton=function(){var a=this;a.gcrud_container.find(".gc-refresh").click(function(){clearTimeout(a.search_timer),a.SearchAndOrderingTrigger()})},b.prototype.listenerPerPage=function(){var a=this;a.gcrud_container.find(".per_page").change(function(){a.gcrud_container.find(".page-number-hidden").val("1"),a.SearchAndOrderingTrigger()})},b.prototype.listenerExportButton=function(){var b=this;b.gcrud_container.find(".gc-export").click(function(){var c=a(this).data("url"),d="";a.each(b.gcrud_container.find("form").serializeArray(),function(a,b){d=d+'<input type="hidden" name="'+b.name+'" value="'+b.value+'">'}),""!==b.gcrud_container.find(".search-input").val()?d=d+'<input type="hidden" name="search_field" value="" /><input type="hidden" name="search_text" value="'+b.gcrud_container.find(".search-input").val()+'" />':b.gcrud_container.find(".grocery-crud-table thead input").each(function(){""===a(this).val()||a(this).is(":checkbox")||(d=d+'<input type="hidden" name="search_field[]" value="'+a(this).attr("name")+'"><input type="hidden" name="search_text[]" value="'+a(this).val()+'">')}),a("#tmp-form").remove(),a("body").after(a("<form/>").attr("id","tmp-form").attr("method","post").attr("target","_blank").attr("action",c).html(d)),a("#tmp-form").submit()})},b.prototype.listenerPrintButton=function(){var c=this;c.gcrud_container.find(".gc-print").click(function(){var d,e=a(this).data("url"),f="";""!==c.gcrud_container.find(".search-input").val()?f=f+'<input type="hidden" name="search_field" value="" /><input type="hidden" name="search_text" value="'+c.gcrud_container.find(".search-input").val()+'" />':c.gcrud_container.find(".grocery-crud-table thead input").each(function(){""===a(this).val()||a(this).is(":checkbox")||(f=f+'<input type="hidden" name="search_field[]" value="'+a(this).attr("name")+'"><input type="hidden" name="search_text[]" value="'+a(this).val()+'">')}),d=a("<form/>").attr("method","post").attr("action",e).html(f),d.ajaxSubmit({beforeSend:function(){c.gcrud_container.addClass(b.CLASS_LOADING)},complete:function(){c.gcrud_container.removeClass(b.CLASS_LOADING)},error:function(){c.gcrud_container.removeClass(b.CLASS_LOADING)},success:function(d){c.gcrud_container.removeClass(b.CLASS_LOADING),a("<div/>").html(d).printThis()}})})},b.prototype.pagingCalculations=function(){{var a=parseInt(this.gcrud_container.find(".page-number-hidden").val(),10),c=this.getMaxPaging();parseInt(this.gcrud_container.find(".per_page").val(),10)}0>=a&&(a=1,this.gcrud_container.find(".page-number-hidden").val("1"),this.gcrud_container.find(".page-number-input").val("1")),1===a?(this.gcrud_container.find(".paging-first").addClass(b.CLASS_DISABLED),this.gcrud_container.find(".paging-previous").addClass(b.CLASS_DISABLED)):(this.gcrud_container.find(".paging-first").removeClass(b.CLASS_DISABLED),this.gcrud_container.find(".paging-previous").removeClass(b.CLASS_DISABLED)),a+1>c?(this.gcrud_container.find(".paging-last").addClass(b.CLASS_DISABLED),this.gcrud_container.find(".paging-next").addClass(b.CLASS_DISABLED)):(this.gcrud_container.find(".paging-last").removeClass(b.CLASS_DISABLED),this.gcrud_container.find(".paging-next").removeClass(b.CLASS_DISABLED)),this.gcrud_container.find(".page-number-input").val(a),a>c&&(this.gcrud_container.find(".page-number-hidden").val(c),this.gcrud_container.find(".page-number-input").val(c))},b.prototype.SearchAndOrderingTrigger=function(){var c=a(".column-with-ordering.active:first").data("order-by"),d="",e=[],f=[],g=this,h=g.gcrud_container,i=g.gcrud_container.find(".search-button>input.search-input"),j=g.gcrud_container.find(".per_page").val(),k={};this.pagingCalculations(),a(".column-with-ordering.active:first").hasClass("ordering-desc")?d="desc":a(".column-with-ordering.active:first").hasClass("ordering-asc")&&(d="asc"),a(".gc-search-row input.searchable-input").each(function(){""!==a(this).val()&&(e.push(a(this).attr("name")),f.push(a(this).val()))}),e.length>0&&(i.val(""),i.trigger("blur")),""!==i.val()&&(e="",f=i.val()),k={page:h.find('input[name="page_number"]').val(),per_page:h.find(".per_page").val(),order_by:[c,d],search_field:e,search_text:f},null!==this.csrf_field&&(k[this.csrf_field.name]=this.csrf_field.value),a.ajax({beforeSend:function(){h.addClass(b.CLASS_LOADING)},complete:function(){h.removeClass(b.CLASS_LOADING)},error:function(){h.removeClass(b.CLASS_LOADING)},data:k,dataType:"json",url:ajax_list_url,success:function(c){var d,e;g.gcrud_container.addClass(b.CLASS_LOADING),g.gcrud_container.find(".select-all-none").prop("checked",!1),g.gcrud_container.find(".grocery-crud-table tbody").html(c.tbody_html),a(".current-total-results").html(c.current_total_results),c.current_total_results>10?(e=parseInt(a('input[name="page_number"]').val(),10)*j,e>c.current_total_results&&(e=c.current_total_results),a(".paging-ends").html(e)):a(".paging-ends").html(c.current_total_results),a(".paging-starts").html((parseInt(a('input[name="page_number"]').val(),10)-1)*j+1),d=a(".column-with-ordering.active:first"),d.length>0&&h.find(".grocery-crud-table").find("thead tr td:nth-child("+(d.index()+2)+"), tbody tr td:nth-child("+(d.index()+2)+")").addClass("active"),c.current_total_results<parseInt(g.gcrud_container.find(".full-total").html(),10)?g.gcrud_container.find(".full-total-container").removeClass("hidden"):g.gcrud_container.find(".full-total-container").addClass("hidden"),g.listenerLoadMoreButton(),g.appendSearchClearButtons(),g.listenerSelectRow(),g.pagingCalculations(),g.hideShowDeleteButton(),h.removeClass(b.CLASS_LOADING)},method:"post"})},b.prototype.listenerSearchInput=function(){var b=this;a(".grocery-crud-table input.searchable-input").on("keyup change",function(c){var d=9===c.keyCode||13===c.keyCode||""===a(this).val()?1:1e3;clearTimeout(b.search_timer),b.search_timer=setTimeout(function(){b.gcrud_container.find(".page-number-hidden").val("1"),b.SearchAndOrderingTrigger()},d)})},b.prototype.listenerColumnWithOrdering=function(){var c=this;a(".column-with-ordering").click(function(){var d=a(this).closest(".gc-container"),e=a.trim(a(this).text());d.addClass(b.CLASS_LOADING),a(this).closest(".grocery-crud-table").find("th.active, td.active").removeClass("active"),a(this).parent().find(".column-with-ordering").each(function(){var b=a.trim(a(this).text());a(this).html(b)}),a(this).addClass("active"),a(this).closest(".grocery-crud-table").find("thead tr td:nth-child("+(a(this).index()+2)+"), tbody tr td:nth-child("+(a(this).index()+2)+")").addClass("active"),a(this).hasClass("ordering-asc")?(a(this).closest(".grocery-crud-table").find("th").removeClass("ordering-desc").removeClass("ordering-asc"),a(this).html("<div>"+e+"</div><i class='fa fa-chevron-down'></i>"),a(this).addClass("ordering-desc").removeClass("ordering-asc")):(a(this).closest(".grocery-crud-table").find("th").removeClass("ordering-desc").removeClass("ordering-asc"),a(this).html("<div>"+e+"</div><i class='fa fa-chevron-up'></i>"),a(this).addClass("ordering-asc").removeClass("ordering-desc")),d.find('input[name="page_number"]').val("1"),d.removeClass(b.CLASS_LOADING),c.SearchAndOrderingTrigger()})},b.prototype.listenerSearchButton=function(){var b=this;a(".search-button").click(function(b){b.preventDefault();var c=a(this);c.removeClass("btn-primary").addClass("btn-default"),c.find("input.search-input").addClass("search-input-big"),setTimeout(function(){c.find("input.search-input").focus()},400),a(this).addClass("search-button-big")}),a(".search-button>input.search-input").change(function(){b.gcrud_container.find(".search-button .clear-all-search").remove(),""!==a(this).val()&&(a(this).after('<i class="fa fa-times clear-all-search"></i>'),b.gcrud_container.find(".search-button .clear-all-search").click(function(){b.gcrud_container.find(".search-button>input.search-input").val("").trigger("change")})),b.gcrud_container.find(".page-number-hidden").val("1"),b.gcrud_container.find(".searchable-input").val(""),b.SearchAndOrderingTrigger()}),a(".search-button>input.search-input").blur(function(){var c=a(this).closest(".search-button");""===a(this).val()&&c.hasClass("search-button-big")&&(b.gcrud_container.find(".search-button .clear-all-search").remove(),a(this).removeClass("search-input-big"),c.removeClass("search-button-big"),c.removeClass("btn-default").addClass("btn-primary"))})},b.prototype.getMaxPaging=function(){var a=parseInt(this.gcrud_container.find(".current-total-results").html(),10),b=parseInt(this.gcrud_container.find(".per_page").val(),10),c=0===a?1:Math.ceil(a/b);return c},b.prototype.listenerPagingButtons=function(){var c=this,d=b.SELECTOR_PAGING_PREVIOUS+", "+b.SELECTOR_PAGING_NEXT+", "+b.SELECTOR_PAGING_FIRST+","+b.SELECTOR_PAGING_LAST,e=c.gcrud_container.find(".page-number-hidden");this.gcrud_container.find(d).click(function(d){return d.preventDefault(),a(this).hasClass(b.CLASS_DISABLED)?void 0:(a(this).hasClass(b.CLASS_PAGING_PREVIOUS)?e.val(parseInt(e.val(),10)-1):a(this).hasClass(b.CLASS_PAGING_NEXT)?e.val(parseInt(e.val(),10)+1):a(this).hasClass(b.CLASS_PAGING_FIRST)?e.val("1"):a(this).hasClass(b.CLASS_PAGING_LAST)&&e.val(c.getMaxPaging()),void c.SearchAndOrderingTrigger())}),this.gcrud_container.find(".page-number-input").change(function(){e.val(isNaN(parseInt(a(this).val(),10))?"1":parseInt(a(this).val(),10)),c.SearchAndOrderingTrigger()})},b.prototype.listenerSelectRow=function(){var b=this;b.gcrud_container.find(".select-row").click(function(){a(this).is(":checked")?a(this).closest("tr").addClass("warning"):a(this).closest("tr").removeClass("warning"),b.hideShowDeleteButton()})},b.prototype.hideShowDeleteButton=function(){this.gcrud_container.find(".select-row:checked").length>0?this.gcrud_container.find(".delete-selected-button").removeClass("hidden"):this.gcrud_container.find(".delete-selected-button").addClass("hidden")},b.prototype.calculationsBeforeDelete=function(a){var b=this,c=parseInt(b.gcrud_container.find(".current-total-results").html(),10),d=parseInt(b.gcrud_container.find(".page-number-input").val(),10),e=parseInt(b.gcrud_container.find(".per_page").val(),10);d===b.getMaxPaging()&&c-a<=(b.getMaxPaging()-1)*e&&b.gcrud_container.find('input[name="page_number"]').val(b.getMaxPaging()-1),b.gcrud_container.find(".full-total").html(parseInt(b.gcrud_container.find(".full-total").html(),10)-a)},b.prototype.listenerDeleteMultiple=function(){var c=this;c.gcrud_container.find(".select-all-none").click(function(){c.gcrud_container.find(".select-row").each(a(this).is(":checked")?function(){a(this).prop("checked",!0),a(this).closest("tr").addClass("warning")}:function(){a(this).prop("checked",!1),a(this).closest("tr").removeClass("warning")}),c.hideShowDeleteButton()}),c.gcrud_container.find(".delete-selected-button").click(function(){c.gcrud_container.find(".delete-multiple-confirmation").modal(),c.gcrud_container.find(".delete-multiple-confirmation").on("hidden.bs.modal",function(){c.gcrud_container.find(".delete-multiple-confirmation-button").unbind("click")}),c.gcrud_container.find(".delete-multiple-confirmation-button").click(function(d){d.preventDefault();var e,f=c.gcrud_container.find(".delete-multiple-confirmation:first"),g=(parseInt(c.gcrud_container.find(".current-total-results").html(),10),parseInt(c.gcrud_container.find(".page-number-input").val(),10),parseInt(c.gcrud_container.find(".per_page").val(),10),[]);c.gcrud_container.find(".select-row:checked").each(function(){g.push(a(this).data("id"))}),c.calculationsBeforeDelete(g.length),e={ids:g},null!==c.csrf_field&&(e[c.csrf_field.name]=c.csrf_field.value),a.ajax({beforeSend:function(){c.gcrud_container.addClass(b.CLASS_LOADING)},error:function(){c.gcrud_container.removeClass(b.CLASS_LOADING)},data:e,method:"post",dataType:"json",url:c.gcrud_container.find(".delete-multiple-confirmation-button").data("target"),success:function(b){b.success&&a.growl(b.success_message,{type:"success",delay:1e4,animate:{enter:"animated bounceInDown",exit:"animated bounceOutUp"}}),f.modal("hide"),c.SearchAndOrderingTrigger()}})})})},b.prototype.listenerLoadMoreButton=function(){var c=this;c.gcrud_container.find("table.grocery-crud-table>tbody .dropdown").on("show.bs.dropdown",function(){a(this).find(".delete-row").click(function(d){d.preventDefault();var e=a(this);c.gcrud_container.find(".delete-confirmation-button").click(function(d){d.preventDefault();var f=c.gcrud_container.find(".delete-confirmation:first");c.calculationsBeforeDelete(1),a.ajax({beforeSend:function(){c.gcrud_container.addClass(b.CLASS_LOADING)},error:function(){c.gcrud_container.removeClass(b.CLASS_LOADING)},url:e.data("target"),dataType:"json",success:function(b){b.success&&a.growl(b.success_message,{type:"success",delay:1e4,animate:{enter:"animated bounceInDown",exit:"animated bounceOutUp"}}),f.modal("hide"),c.SearchAndOrderingTrigger()}})}),c.gcrud_container.find(".delete-confirmation").modal(),c.gcrud_container.find(".delete-confirmation").on("hidden.bs.modal",function(){c.gcrud_container.find(".delete-confirmation-button").unbind("click")})})}),c.gcrud_container.find("table.grocery-crud-table>tbody .dropdown").on("hide.bs.dropdown",function(){a(this).find(".delete-row").unbind("click")})},a.fn.datagrid=function(c){var d;return d=a.extend({default_per_page:10},c),this.each(function(){var c=new b(a(this),d);c.init()}),this}}(jQuery);