-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathjquery.php_bs_grid.min.js
8 lines (8 loc) · 16.1 KB
/
jquery.php_bs_grid.min.js
1
2
3
4
5
6
7
8
/**
* @fileOverview php_bs_grid is a jQuery helper plugin for php_bs_grid class. Project page https://github.com/pontikis/php_bs_grid
* @version 0.9.6 (16 Jul 2017)
* @licence MIT
* @author Christos Pontikis http://www.pontikis.net
* @copyright Christos Pontikis http://www.pontikis.net
*/
"use strict";!function(a){var e="php_bs_grid",_={init:function(_){var r=this;return this.each(function(){var t=r.data(e);if("undefined"==typeof t){var i=r.php_bs_grid("getDefaults");t=a.extend({},i,_)}else t=a.extend({},t,_);r.data(e,t);var l,o,p,s,n,c,m,d,u,h,v,f,k,b,g,w,x=a("#"+t.php_bs_grid_form_id),y=a("#"+t.reset_all_id),j=a("#"+t.rows_per_page_id),I=a("#"+t.columns_switcher_id),O=a("#"+t.columns_to_display_id),P=a("#"+t.addnew_record_id),D=a("#"+t.sort_simple_field_id),S=a("#"+t.sort_simple_order_id),A=a("#"+t.sort_advanced_id),C=a(t.col_sortable_selector),q=a("#"+t.go_top_id),T=a("#"+t.go_back_id),z=a("#"+t.go_forward_id),Q=a("#"+t.go_bottom_id),E=a("#"+t.go_to_page_id),M=a("#"+t.page_num_id),B=a("#"+t.total_pages_id),F=a("#"+t.export_excel_btn_id),G=a("#"+t.export_excel_id),H=a("#"+t.criteria_apply_id),J=a("#"+t.criteria_reset_id),K=a("#"+t.criteria_clear_id),L=a("#"+t.criteria_before_id),N=a("#"+t.criteria_after_id),R=j.val(),U=t.criteria,V=[],W={error:null,focus:null,text_inputs_contain_value:null,ajax_data_to_pass:{}};a.each(U,function(e,_){switch(_.type){case"text":V.push("#"+_.params_html.dropdown_id),V.push("#"+_.params_html.input_id);break;case"lookup":V.push("#"+_.params_html.dropdown_id),V.push("#"+_.params_html.dropdown_lookup_id);break;case"number":case"date":V.push("#"+_.params_html.dropdown_id),V.push("#"+_.params_html.input_id);break;case"autocomplete":V.push("#"+_.params_html.autocomplete_id),V.push("#"+_.params_html.filter_id),_.params_html.hasOwnProperty("is_null_id")&&_.params_html.is_null_id&&V.push("#"+_.params_html.is_null_id);break;case"multiselect_checkbox":a.each(_.params_html.items,function(a,e){V.push("#"+e.input_id)}),_.params_html.hasOwnProperty("is_null_id")&&_.params_html.is_null_id&&V.push("#"+_.params_html.is_null_id)}}),f=V.join(","),k=a(f),b=k.serialize(),L.val(b);var X=function(e){a.each(U,function(_,r){if(r.params_html.hasOwnProperty("elem_id_to_append")&&r.params_html.elem_id_to_append&&(p=a("#"+r.params_html.wrapper_id),s=a("#"+r.params_html.elem_id_to_append),p.append(s)),r.params_html.hasOwnProperty("elem_id_to_prepend")&&r.params_html.elem_id_to_prepend&&(p=a("#"+r.params_html.wrapper_id),n=a("#"+r.params_html.elem_id_to_prepend),p.prepend(n)),r.type===e)switch(o=a("#"+r.params_html.dropdown_id),e){case"text":l=a("#"+r.params_html.input_id),parseInt(o.val())===t.criteria_operator_text_isnull?(l.val(""),l.hide()):(l.show(),parseInt(o.val())===t.criteria_operator_text_ignore&&l.val(""));break;case"lookup":l=a("#"+r.params_html.dropdown_lookup_id),parseInt(o.val())===t.criteria_operator_lookup_ignore||parseInt(o.val())===t.criteria_operator_lookup_isnull?l.hide():l.show();break;case"number":if(l=a("#"+r.params_html.input_id),p=a("#"+r.params_html.wrapper_id),p.is(":visible")){var i=!1;if(r.params_html.hasOwnProperty("associated_criteria_name")&&r.params_html.associated_criteria_name){i=!0;var c=r.params_html.associated_criteria_name,u=U[c],f=a("#"+u.params_html.wrapper_id),k=a("#"+u.params_html.dropdown_id),b=a("#"+u.params_html.input_id)}var g=parseInt(o.val());g===t.criteria_operator_number_equal||g===t.criteria_operator_number_isnull?(g===t.criteria_operator_number_isnull&&(l.val(""),l.hide()),i&&(k.val(t.criteria_operator_number_ignore),b.val(""),f.hide())):(l.show(),g===t.criteria_operator_number_ignore&&l.val(""),i&&f.show())}break;case"date":if(l=a("#"+r.params_html.input_id),p=a("#"+r.params_html.wrapper_id),p.is(":visible")){var i=!1;if(r.params_html.hasOwnProperty("associated_criteria_name")&&r.params_html.associated_criteria_name){i=!0;var c=r.params_html.associated_criteria_name,u=U[c],f=a("#"+u.params_html.wrapper_id),k=a("#"+u.params_html.dropdown_id),b=a("#"+u.params_html.input_id)}var w=parseInt(o.val());w===t.criteria_operator_date_equal||w===t.criteria_operator_date_isnull?(w===t.criteria_operator_date_isnull&&(l.val(""),l.hide()),i&&(k.val(t.criteria_operator_date_ignore),b.val(""),f.hide())):(l.show(),w===t.criteria_operator_date_ignore&&l.val(""),i&&f.show())}break;case"autocomplete":r.params_html.display_is_null_option===t.autocomplete_display_is_null_yes&&(d=a("#"+r.params_html.filter_id),m=a("#"+r.params_html.autocomplete_id),h=a("#"+r.params_html.is_null_id),h.is(":checked")?(d.val(""),m.val(""),m.prop("disabled",!0)):m.prop("disabled",!1));break;case"multiselect_checkbox":r.params_html.display_is_null_option===t.multiselect_checkbox_display_is_null_yes&&(h=a("#"+r.params_html.is_null_id),h.is(":checked")?a.each(r.params_html.items,function(e,_){v=a("#"+_.input_id),v.prop("checked",_.default_checked_status),v.prop("disabled",!0)}):a.each(r.params_html.items,function(e,_){v=a("#"+_.input_id),v.prop("disabled",!1)}))}})},Y=function(e){var _=U[e];switch(_.type){case"text":o=a("#"+_.params_html.dropdown_id),l=a("#"+_.params_html.input_id),o.val(_.params_html.dropdown_value),l.val(_.params_html.input_value);break;case"lookup":o=a("#"+_.params_html.dropdown_id),l=a("#"+_.params_html.dropdown_lookup_id),o.val(_.params_html.dropdown_value),_.params_html.dropdown_lookup_value?l.val(_.params_html.dropdown_lookup_value):l.prop("selectedIndex",0);break;case"number":case"date":o=a("#"+_.params_html.dropdown_id),l=a("#"+_.params_html.input_id),o.val(_.params_html.dropdown_value),l.val(_.params_html.input_value);break;case"autocomplete":d=a("#"+_.params_html.filter_id),m=a("#"+_.params_html.autocomplete_id),d.val(_.params_html.filter_value),m.val(_.params_html.autocomplete_value),_.params_html.display_is_null_option===t.autocomplete_display_is_null_yes&&(h=a("#"+_.params_html.is_null_id),_.params_html.is_null_checked?h.prop("checked",!0):h.prop("checked",!1)),X("autocomplete");break;case"multiselect_checkbox":a.each(_.params_html.items,function(e,r){v=a("#"+r.input_id),-1!==jQuery.inArray(parseInt(v.val()),_.params_html.group_value)?v.prop("checked",!0):v.prop("checked",!1)}),_.params_html.display_is_null_option===t.multiselect_checkbox_display_is_null_yes&&(h=a("#"+_.params_html.is_null_id),_.params_html.is_null_checked?h.prop("checked",!0):h.prop("checked",!1)),X("multiselect_checkbox")}},Z=function(e){var _=U[e];switch(_.type){case"text":o=a("#"+_.params_html.dropdown_id),l=a("#"+_.params_html.input_id),l.val(""),o.val(t.criteria_operator_text_ignore);break;case"lookup":o=a("#"+_.params_html.dropdown_id),o.val(t.criteria_operator_lookup_ignore);break;case"number":o=a("#"+_.params_html.dropdown_id),l=a("#"+_.params_html.input_id),l.val(""),o.val(t.criteria_operator_number_ignore);break;case"date":o=a("#"+_.params_html.dropdown_id),l=a("#"+_.params_html.input_id),l.val(""),o.val(t.criteria_operator_date_ignore);break;case"autocomplete":d=a("#"+_.params_html.filter_id),m=a("#"+_.params_html.autocomplete_id),d.val(""),m.val(""),_.params_html.display_is_null_option===t.autocomplete_display_is_null_yes&&(h=a("#"+_.params_html.is_null_id),h.prop("checked",!1));break;case"multiselect_checkbox":a.each(_.params_html.items,function(e,_){a("#"+_.input_id).prop("checked",_.default_checked_status)}),_.params_html.display_is_null_option===t.multiselect_checkbox_display_is_null_yes&&(h=a("#"+_.params_html.is_null_id),h.prop("checked",!1))}},$=function(){a.each(U,function(e,_){switch(_.type){case"text":if(o=a("#"+_.params_html.dropdown_id),l=a("#"+_.params_html.input_id),parseInt(o.val())!==t.criteria_operator_text_isnull){if(l.val(a.trim(l.val())),l.val()&&(W.text_inputs_contain_value=!0),W.ajax_data_to_pass[_.params_html.input_id]=l.val(),parseInt(o.val())===t.criteria_operator_text_ignore&&l.val())return W.error=_.params_html.msg_missing_operator,W.focus=_.params_html.dropdown_id,!1;if(parseInt(o.val())!==t.criteria_operator_text_ignore&&!l.val())return W.error=_.params_html.msg_missing_value,W.focus=_.params_html.input_id,!1;if(parseInt(o.val())!==t.criteria_operator_text_ignore&&l.val()&&_.params_html.hasOwnProperty("minchars")&&_.params_html.minchars&&l.val().length<_.params_html.minchars)return W.error=_.params_html.msg_minchars,W.focus=_.params_html.input_id,!1}break;case"lookup":break;case"number":if(o=a("#"+_.params_html.dropdown_id),l=a("#"+_.params_html.input_id),parseInt(o.val())!==t.criteria_operator_number_isnull){if(l.val(a.trim(l.val())),l.val()&&(W.text_inputs_contain_value=!0),W.ajax_data_to_pass[_.params_html.dropdown_id]=o.val(),W.ajax_data_to_pass[_.params_html.input_id]=l.val(),parseInt(o.val())===t.criteria_operator_number_ignore&&l.val())return W.error=_.params_html.msg_missing_operator,W.focus=_.params_html.dropdown_id,!1;if(parseInt(o.val())!==t.criteria_operator_number_ignore&&!l.val())return W.error=_.params_html.msg_missing_value,W.focus=_.params_html.input_id,!1}break;case"date":if(o=a("#"+_.params_html.dropdown_id),l=a("#"+_.params_html.input_id),parseInt(o.val())!==t.criteria_operator_date_isnull){if(l.val(a.trim(l.val())),l.val()&&(W.text_inputs_contain_value=!0),W.ajax_data_to_pass[_.params_html.dropdown_id]=o.val(),W.ajax_data_to_pass[_.params_html.input_id]=l.val(),parseInt(o.val())===t.criteria_operator_date_ignore&&l.val())return W.error=_.params_html.msg_missing_operator,W.focus=_.params_html.dropdown_id,!1;if(parseInt(o.val())!==t.criteria_operator_date_ignore&&!l.val())return W.error=_.params_html.msg_missing_value,W.focus=_.params_html.input_id,!1}break;case"autocomplete":break;case"multiselect_checkbox":var r=0;if(a.each(_.params_html.items,function(e,_){a("#"+_.input_id).prop("checked")===!0&&(r+=1)}),0===r)return W.error=_.params_html.msg_all_deselected,W.focus=_.params_html.items[0].input_id,!1}})},aa=function(){X("text"),X("number"),X("lookup"),X("date"),X("autocomplete"),X("multiselect_checkbox")};aa(),y.click(function(){t.ajax_reset_all_url?a.ajax({url:t.ajax_reset_all_url,type:"POST",dataType:"json",success:function(a){location.href=a.current_url}}):location.href=location.href.split("?")[0]}),j.change(function(){_a("rows_per_page")}),I.click(function(){_a("columns_switcher")}),P.click(function(){location.href=t.addnew_record_url}),C.click(function(){_a("sort_simple",{col_id:a(this).attr("id")})}),A.change(function(){_a("sort_advanced")}),q.click(function(){_a("go_top")}),T.click(function(){_a("go_back")}),z.click(function(){_a("go_forward")}),Q.click(function(){_a("go_bottom")}),E.click(function(){_a("go_to_page")}),M.keypress(function(a){13===a.which&&(a.preventDefault(),E.click())}),F.click(function(){_a("export_excel")}),a.each(U,function(e,_){switch(_.type){case"text":o=a("#"+_.params_html.dropdown_id),l=a("#"+_.params_html.input_id),o.change(function(){X("text")}),l.keypress(function(a){13===a.which&&(a.preventDefault(),H.click())});break;case"number":o=a("#"+_.params_html.dropdown_id),l=a("#"+_.params_html.input_id),o.change(function(){X("number")}),l.keypress(function(a){13===a.which&&(a.preventDefault(),H.click())});break;case"lookup":o=a("#"+_.params_html.dropdown_id),l=a("#"+_.params_html.dropdown_lookup_id),o.change(function(){X("lookup")});break;case"date":o=a("#"+_.params_html.dropdown_id),l=a("#"+_.params_html.input_id),c=_.params_html.datepicker_params,_.params_html.hasOwnProperty("show_time")&&_.params_html.show_time===!0?l.datetimepicker(c):l.datepicker(c),o.change(function(){X("date")}),l.keypress(function(a){13===a.which&&(a.preventDefault(),H.click())});break;case"autocomplete":m=a("#"+_.params_html.autocomplete_id),d=a("#"+_.params_html.filter_id),u=_.params_html.autocomplete_params,u.select=function(e,r){d=a("#"+_.params_html.filter_id),d.val(r.item.id)},u.change=function(e,r){null===r.item&&(m=a("#"+_.params_html.autocomplete_id),d=a("#"+_.params_html.filter_id),m.val(""),d.val(""))},m.autocomplete(u),m.on("input",function(){d=a("#"+_.params_html.filter_id),d.val("")}),m.on("open",function(){a(".ui-autocomplete").css("width",m.css("width"))}),_.params_html.display_is_null_option===t.autocomplete_display_is_null_yes&&(h=a("#"+_.params_html.is_null_id),h.on("click",function(){m=a("#"+_.params_html.autocomplete_id),d=a("#"+_.params_html.filter_id),a(this).is(":checked")?(m.val(""),d.val(""),m.prop("disabled",!0)):m.prop("disabled",!1)}));break;case"multiselect_checkbox":_.params_html.display_is_null_option===t.multiselect_checkbox_display_is_null_yes&&(h=a("#"+_.params_html.is_null_id),h.click(function(){h.is(":checked")?a.each(_.params_html.items,function(e,_){v=a("#"+_.input_id),v.prop("checked",_.default_checked_status),v.prop("disabled",!0)}):a.each(_.params_html.items,function(e,_){v=a("#"+_.input_id),v.prop("disabled",!1)})}))}}),H.click(function(){_a("apply_criteria")}),J.click(function(){a.each(U,function(a){Y(a)}),aa()}),K.click(function(){_a("clear_criteria")});var ea=function(){N.val(g),x.submit()},_a=function(e,_){if(a.each(U,function(e,_){"autocomplete"===_.type&&(d=a("#"+_.params_html.filter_id),m=a("#"+_.params_html.autocomplete_id),d.val()||m.val(""))}),"export_excel"===e?G.val(t.export_excel_yes):G.val(t.export_excel_no),g=k.serialize(),w=b!==g,"apply_criteria"===e){if(!w)return ra(t.bs_modal_id,t.bs_modal_content_id,t.msg_criteria_not_changed),!1;if($(),W.error)return ra(t.bs_modal_id,t.bs_modal_content_id,W.error,W.focus),W={error:null,focus:null,text_inputs_contain_value:null,ajax_data_to_pass:{}},!1;W.text_inputs_contain_value&&t.ajax_validate_form_url?a.ajax({url:t.ajax_validate_form_url,type:"POST",data:W.ajax_data_to_pass,dataType:"json",success:function(a){return a.error?(ra(t.bs_modal_id,t.bs_modal_content_id,a.error,a.focus),W={error:null,focus:null,text_inputs_contain_value:null,ajax_data_to_pass:{}},!1):(M.val(t.default_page_num),void ea())}}):(M.val(t.default_page_num),ea())}else{if("clear_criteria"===e)M.val(t.default_page_num),a.each(U,function(a){Z(a)}),aa(),g=k.serialize();else{if(w)return"rows_per_page"===e&&j.val(R),ra(t.bs_modal_id,t.bs_modal_content_id,t.msg_apply_or_reset_criteria,t.criteria_apply_id),!1;switch(e){case"rows_per_page":M.val(t.default_page_num);break;case"columns_switcher":parseInt(O.val())===t.columns_default?O.val(t.columns_more):O.val(t.columns_default);break;case"sort_simple":D.val()===_.col_id?"ASC"===S.val()?S.val("DESC"):S.val("ASC"):(D.val(_.col_id),S.val("ASC"));break;case"sort_advanced":D.val(""),S.val("");break;case"go_top":M.val(t.default_page_num);break;case"go_back":M.val(+M.val()-1);break;case"go_forward":M.val(+M.val()+1);break;case"go_bottom":M.val(B.val());break;case"go_to_page":}}ea()}},ra=function(e,_,r,t){var i=a("#"+e),l=a("#"+_);if(t){var o=a("#"+t);i.on("hidden.bs.modal",function(){o.focus()})}l.html(r),i.modal("show")}})},getOption:function(a){var _=this;return _.data(e)[a]},getDefaults:function(){return{php_bs_grid_form_id:"php_bs_grid_form",reset_all_id:"reset_all",rows_per_page_id:"rows_per_page",columns_switcher_id:"columns_switcher",columns_to_display_id:"columns_to_display",addnew_record_id:"addnew_record",col_sortable_selector:"th.col-sortable",sort_simple_field_id:"sort_simple_field",sort_simple_order_id:"sort_simple_order",sort_advanced_id:"sort_advanced",go_top_id:"go_top",go_back_id:"go_back",go_forward_id:"go_forward",go_bottom_id:"go_bottom",go_to_page_id:"go_to_page",page_num_id:"page_num",total_pages_id:"total_pages",export_excel_btn_id:"export_excel_btn",export_excel_id:"export_excel",criteria_apply_id:"criteria_apply",criteria_reset_id:"criteria_reset",criteria_clear_id:"criteria_clear",criteria_before_id:"criteria_before",criteria_after_id:"criteria_after",default_page_num:1,columns_default:1,columns_more:2,export_excel_no:1,export_excel_yes:2,criteria_operator_text_ignore:1,criteria_operator_text_isnull:5,criteria_operator_number_ignore:1,criteria_operator_number_equal:2,criteria_operator_number_isnull:7,criteria_operator_lookup_ignore:1,criteria_operator_lookup_isnull:4,criteria_operator_date_ignore:1,criteria_operator_date_equal:2,criteria_operator_date_isnull:7,autocomplete_display_is_null_yes:1,multiselect_checkbox_display_is_null_yes:1}},showCriterion:function(_){var r,t=this,i=t.data(e).criteria;a.each(i,function(e,t){return e===_?(r=a("#"+t.params_html.wrapper_id),!1):void 0}),r.show(),r.children().show()}};a.fn.php_bs_grid=function(r){return _[r]?_[r].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof r&&r?void a.error("Method "+r+" does not exist on jQuery."+e):_.init.apply(this,arguments)}}(jQuery);