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.listenerDeleteRowClick(),this.listenerSearchButton(),this.listenerSearchInput(),this.listenerColumnWithOrdering(),this.listenerRefreshButton(),this.listenerPrintButton(),this.listenerExportButton(),this.listenerPerPage(),this.listenerPagingButtons(),this.listenerSettingsButton(),this.checkCachedData(),this.pagingCalculations()}};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.CLASS_PER_PAGE="per_page",b.prototype.clearFilteringCache=function(){var a=this.gcrud_container.find(".search-button > input.search-input");this.gcrud_container.find(".page-number-hidden").val("1"),this.gcrud_container.find(".page-number-input").val("1"),this.gcrud_container.find(".grocery-crud-table tr:first").find(".active").removeClass("active table-active ordering-desc ordering-asc"),this.gcrud_container.find(".grocery-crud-table tr:first").find(".fa-chevron-up,.fa-chevron-down,.el-chevron-up,.el-chevron-down").remove(),this.gcrud_container.find("td.active").removeClass("active table-active"),this.gcrud_container.find("thead .value-not-empty").removeClass("value-not-empty").val(""),""!==a.val()&&a.val("").trigger("blur"),this.SearchAndOrderingTrigger(),CacheLibrary.removeLocalStorageItem("gcrud_"+unique_hash)},b.prototype.checkCachedData=function(){var c=this.gcrud_container.find("."+b.CLASS_PER_PAGE).val(),d=CacheLibrary.getLocalStorageItem("gcrud_"+unique_hash),e=!1;try{d=null!==d?JSON.parse(d):{}}catch(f){return CacheLibrary.removeLocalStorageItem("gcrud_"+unique_hash),!1}if(void 0===d.per_page||void 0===d.page||void 0===d.order_by)return CacheLibrary.removeLocalStorageItem("gcrud_"+unique_hash),!1;if(c!==d.per_page&&(this.gcrud_container.find("."+b.CLASS_PER_PAGE).val(d.per_page),e=!0),"1"!==d.page&&(this.gcrud_container.find(".page-number-hidden").val(d.page),this.gcrud_container.find(".page-number-input").val(d.page),e=!0),null!==d.order_by[0]){var g=this.gcrud_container.find(".grocery-crud-table tr:first").find(".column-with-ordering[data-order-by="+d.order_by[0]+"]").addClass("active table-active ordering-"+d.order_by[1]),h="asc"===d.order_by[1]?"fa-chevron-up el-chevron-up":"fa-chevron-down el-chevron-down";g.html("<div>"+g.text()+"</div><i class='fa el "+h+"'></i>"),e=!0}if("string"==typeof d.search_text)return a(".search-button").trigger("click"),this.gcrud_container.find(".search-button > input.search-input").val(d.search_text).trigger("change"),!0;if(d.search_text.length>0){var i=this.gcrud_container.find(".gc-search-row");a.each(d.search_field,function(a,b){i.find('input.searchable-input[name="'+b+'"]').val(d.search_text[a])}),e=!0}e&&this.SearchAndOrderingTrigger()},b.prototype.datagridInit=function(){var b,c=this.gcrud_container.find(".success-message");c.is(":empty")||a.growl(c.html(),{type:"success",delay:1e4,animate:{enter:"animated bounceInDown",exit:"animated bounceOutUp"}}),b=a("#gcrud-search-form>input[type=hidden]:first"),1===b.length&&(this.csrf_field={name:b.attr("name"),value:b.val(),csrf_cookie_name:csrf_cookie_name},(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 el el-remove 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("."+b.CLASS_PER_PAGE).change(function(){a.gcrud_container.find(".page-number-hidden").val("1"),a.SearchAndOrderingTrigger()})},b.prototype.setCsrfValue=function(){this.csrf_field.value=getCookie(this.csrf_field.csrf_cookie_name)},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+'">'}),null!==b.csrf_field&&(b.setCsrfValue(),d+='<input type="hidden" name = "'+b.csrf_field.name+'" value="'+b.csrf_field.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="";null!==c.csrf_field&&(c.setCsrfValue(),f+='<input type="hidden" name = "'+c.csrf_field.name+'" value="'+c.csrf_field.value+'"/>'),""!==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();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.datagridOnAjaxComplete=function(c){var d,e,f=this.gcrud_container.find("."+b.CLASS_PER_PAGE).val();this.gcrud_container.find(".select-all-none").prop("checked",!1),this.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)*f,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)*f+1),d=a(".column-with-ordering.active:first"),d.length>0&&this.gcrud_container.find(".grocery-crud-table").find("thead tr td:nth-child("+(d.index()+2)+"), tbody tr td:nth-child("+(d.index()+2)+")").addClass("active table-active"),c.current_total_results<parseInt(this.gcrud_container.find(".full-total").html(),10)?this.gcrud_container.find(".full-total-container").removeClass("hidden"):this.gcrud_container.find(".full-total-container").addClass("hidden"),this.listenerLoadMoreButton(),this.appendSearchClearButtons(),this.listenerSelectRow(),this.pagingCalculations(),this.hideShowDeleteButton(),this.listenerDeleteRowClick(),this.listenerFancybox()},b.prototype.listenerFancybox=function(){a(".image-thumbnail").length>0&&a(".image-thumbnail").fancybox({transitionIn:"elastic",transitionOut:"elastic",speedIn:600,speedOut:200,overlayShow:!1})},b.prototype.SearchAndOrderingTrigger=function(){{var c,d=a(".column-with-ordering.active:first").data("order-by"),e="",f=[],g=[],h=this,i=h.gcrud_container,j=h.gcrud_container.find(".search-button > input.search-input");h.gcrud_container.find("."+b.CLASS_PER_PAGE).val()}this.pagingCalculations(),a(".column-with-ordering.active:first").hasClass("ordering-desc")?e="desc":a(".column-with-ordering.active:first").hasClass("ordering-asc")&&(e="asc"),a(".gc-search-row input.searchable-input").each(function(){""!==a(this).val()&&(f.push(a(this).attr("name")),g.push(a(this).val()))}),f.length>0&&(j.val(""),j.trigger("blur")),""!==j.val()&&(f="",g=j.val()),c={page:i.find('input[name="page_number"]').val(),per_page:i.find("."+b.CLASS_PER_PAGE).val(),order_by:[d,e],search_field:f,search_text:g},CacheLibrary.setLocalStorageItem("gcrud_"+unique_hash,JSON.stringify(c)),this.sendAjaxPost(c,ajax_list_url,this.datagridOnAjaxComplete.bind(this))},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.listenerSettingsButton=function(){var b=this;this.gcrud_container.find(".settings-button-container").on("show.bs.dropdown",function(){b.clearFilteringListener(a(this))}).on("hide.bs.dropdown",function(){a(this).find(".clear-filtering").unbind("click")})},b.prototype.clearFilteringListener=function(a){var b=this;a.find(".clear-filtering").click(function(){b.clearFilteringCache()})},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 table-active"),a(this).parent().find(".column-with-ordering").each(function(){a(this).html(a.trim(a(this).text()))}),a(this).addClass("active table-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 table-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 el fa-chevron-down el-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 el fa-chevron-up el-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").addClass("btn-secondary"),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 el el-remove 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").removeClass("btn-secondary").addClass("btn-primary"))})},b.prototype.getMaxPaging=function(){var a=parseInt(this.gcrud_container.find(".current-total-results").html(),10),c=parseInt(this.gcrud_container.find("."+b.CLASS_PER_PAGE).val(),10),d=0===a?1:Math.ceil(a/c);return d},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 table-warning"):a(this).closest("tr").removeClass("warning table-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.sendAjaxPost=function(c,d,e){null!==this.csrf_field&&(this.setCsrfValue(),c[this.csrf_field.name]=this.csrf_field.value),a.ajax({beforeSend:function(){this.gcrud_container.addClass(b.CLASS_LOADING)}.bind(this),data:c,dataType:"json",url:d,success:function(a){e(a)}.bind(this),method:"post"}).always(function(){this.gcrud_container.removeClass(b.CLASS_LOADING)}.bind(this))},b.prototype.calculationsBeforeDelete=function(a){var c=this,d=parseInt(c.gcrud_container.find(".current-total-results").html(),10),e=parseInt(c.gcrud_container.find(".page-number-input").val(),10),f=parseInt(c.gcrud_container.find("."+b.CLASS_PER_PAGE).val(),10);e===c.getMaxPaging()&&d-a<=(c.getMaxPaging()-1)*f&&c.gcrud_container.find('input[name="page_number"]').val(c.getMaxPaging()-1),c.gcrud_container.find(".full-total").html(parseInt(c.gcrud_container.find(".full-total").html(),10)-a)},b.prototype.listenerDeleteMultiple=function(){var b=this;b.gcrud_container.find(".select-all-none").click(function(){b.gcrud_container.find(".select-row").each(a(this).is(":checked")?function(){a(this).prop("checked",!0),a(this).closest("tr").addClass("warning table-warning")}:function(){a(this).prop("checked",!1),a(this).closest("tr").removeClass("warning table-warning")}),b.hideShowDeleteButton()}),this.gcrud_container.find(".delete-selected-button").click(function(){var b;this.gcrud_container.find(".delete-multiple-confirmation").gc_modal(),this.gcrud_container.find(".delete-multiple-confirmation").on("hidden.bs.modal",function(){this.gcrud_container.find(".delete-multiple-confirmation-button").unbind("click")}.bind(this)),b=this.gcrud_container.find(".select-row:checked").length,1===b?(this.gcrud_container.find(".alert-delete-multiple").addClass("hidden"),this.gcrud_container.find(".alert-delete-multiple-one").removeClass("hidden")):(this.gcrud_container.find(".alert-delete-multiple").removeClass("hidden"),this.gcrud_container.find(".delete-items-amount").html(""+b),this.gcrud_container.find(".alert-delete-multiple-one").addClass("hidden")),this.gcrud_container.find(".delete-multiple-confirmation-button").click(function(b){b.preventDefault();var c,d=this.gcrud_container.find(".delete-multiple-confirmation:first"),e=[],f=this.gcrud_container.find(".delete-multiple-confirmation-button").data("target");this.gcrud_container.find(".select-row:checked").each(function(){e.push(a(this).data("id"))}),this.calculationsBeforeDelete(e.length),c={ids:e},this.sendAjaxPost(c,f,function(b){b.success?a.growl(b.success_message,{type:"success",delay:1e4,animate:{enter:"animated bounceInDown",exit:"animated bounceOutUp"}}):a.growl(b.error_message,{type:"danger",delay:1e4,animate:{enter:"animated bounceInDown",exit:"animated bounceOutUp"}}),d.gc_modal("hide"),this.SearchAndOrderingTrigger()}.bind(this))}.bind(this))}.bind(this))},b.prototype.listenerDeleteRowClick=function(c){var d=this;void 0===c&&(c=this.gcrud_container),c.find(".delete-row").click(function(c){c.preventDefault();var e=a(this);d.gcrud_container.find(".delete-confirmation-button").click(function(c){c.preventDefault();var f=d.gcrud_container.find(".delete-confirmation:first");d.calculationsBeforeDelete(1),a.ajax({beforeSend:function(){d.gcrud_container.addClass(b.CLASS_LOADING)},error:function(){d.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"}}):a.growl(b.error_message,{type:"danger",delay:1e4,animate:{enter:"animated bounceInDown",exit:"animated bounceOutUp"}}),f.gc_modal("hide"),d.SearchAndOrderingTrigger()}})}),d.gcrud_container.find(".delete-confirmation").gc_modal(),d.gcrud_container.find(".delete-confirmation").on("hidden.bs.modal",function(){d.gcrud_container.find(".delete-confirmation-button").unbind("click")})})},b.prototype.listenerLoadMoreButton=function(){var b=this;b.gcrud_container.find("table.grocery-crud-table>tbody .dropdown").on("show.bs.dropdown",function(){b.listenerDeleteRowClick(a(this))}),b.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);