var SQL_Object = null; function init_SQLTable(obj) { var qry = $(obj).attr('data-query'); if (qry==='') qry = $(obj).attr('data-query-default'); SQL_Object = { module: $(obj).attr('data-module'), sql: $(obj).attr('data-sql'), where: $(obj).attr('data-where'), query: qry, order_field: $(obj).attr('data-order-field'), order_dir: $(obj).attr('data-order-dir'), pager_limit: $(obj).attr('data-pager-limit'), actual_page: $(obj).attr('data-active-page'), template: $(obj).attr('data-template'), on_delete: $(obj).attr('data-on-delete'), id_field: $(obj).attr('data-id-field'), search: $(obj).attr('data-search'), keywords: $(obj).attr('data-keywords'), table_name: $(obj).attr('id') }; $(obj).attr('data-action',''); $(obj).attr('data-id',''); query_builder(SQL_Object,obj); } function query_builder(sql_obj,obj) { var table_body = $(obj).children('tbody'); $.getJSON(sql_obj.module+'list/',sql_obj,function(response) { $(table_body).html(response.list); $('.datepicker').datepicker({ autoclose: true }); $(".select2").select2(); $('.sql-paginator').html(response.paginator); }); } function paginator_load_page(page,table) { var table_obj = $(table); $(table_obj).attr('data-active-page',page); init_SQLTable(table_obj); } function reorder_SQLTable(field,obj) { var order = $(obj).parent('th').parent('tr').parent('thead').parent('table').attr('data-order-dir'); $(obj).parent('th').parent('tr').children('th').children('a').removeClass('active-order'); $(obj).addClass('active-order'); if (field!=='' && order!=='') { var new_order = ''; var table_obj = $(obj).parent('th').parent('tr').parent('thead').parent('table'); if (order==='ASC') { new_order = 'DESC'; $(obj).children('i').removeClass('fa-sort-asc'); $(obj).children('i').addClass('fa-sort-desc'); } else { new_order = 'ASC'; $(obj).children('i').removeClass('fa-sort-desc'); $(obj).children('i').addClass('fa-sort-asc'); } $(table_obj).attr('data-order-field',field); $(table_obj).attr('data-order-dir',new_order); init_SQLTable(table_obj); } else { return false; } } function quicksearch_SQLTable(obj,table) { var keyword = $(obj).parent('div').children('input').val(); var search_field = $(obj).attr('data-search-field'); var table_obj = $(table); $(table_obj).attr('data-keywords',keyword); //var sfields = search_field.split(','); var qry = " "+$(obj).attr('data-search-type')+" ("; keyword = keyword.toLowerCase(); temp = keyword.split(" "); $.each(temp,function(index,value) { if (index===0) { qry+= search_field+" like '%"+value+"%'"; } else { qry+= " AND "+search_field+" like '%"+value+"%'"; } }); qry+= ')'; $(table_obj).attr('data-search',qry); $(table_obj).attr('data-active-page','0'); init_SQLTable(table_obj); } function search_SQLTable(obj) { var search_field_type = ''; var field_name = ''; var operator = ''; var qry = ''; var tempval = ''; var hash = ''; var table_obj = $(obj).parent('div').parent('div').parent('div').parent('th').parent('tr').parent('thead').parent('table'); $(obj).parent('div').parent('div').parent('div').children('.search-field').each(function() { search_field_type = $(this).attr('data-search-type'); operator = $(this).attr('data-search-operator'); field_name = $(this).attr('data-search-field'); field_name = field_name.replace('_min',''); field_name = field_name.replace('_max',''); hash = '#'+$(this).attr('data-search-field'); tempval = $(hash).val(); if (search_field_type==='date') { tempval = tempval.replace(/\./g,'-'); } if (tempval && tempval!=='0' && tempval!=='') { if (search_field_type==='text') { qry+= " AND lower("+field_name+") LIKE lower('%"+tempval+"%')"; } else { qry+= " AND "+field_name+operator+"'"+tempval+"'"; } } }); $(table_obj).attr('data-query',qry); init_SQLTable(table_obj); } function search_SQLTable_normal(obj) { var search_field_type = ''; var field_name = ''; var operator = ''; var qry = ''; var tempval = ''; var hash = ''; var table_obj = $(obj).parent('div').parent('div').parent('th').parent('tr').parent('thead').parent('table'); $(obj).parent('div').parent('div').children('.search-field').each(function() { search_field_type = $(this).attr('data-search-type'); operator = $(this).attr('data-search-operator'); field_name = $(this).attr('data-search-field'); field_name = field_name.replace('_min',''); field_name = field_name.replace('_max',''); hash = '#'+$(this).attr('data-search-field'); tempval = $(hash).val(); if (search_field_type==='date') { tempval = tempval.replace(/\./g,'-'); } if (tempval && tempval!=='0' && tempval!=='') { if (search_field_type==='text') { qry+= " AND lower("+field_name+") LIKE lower('%"+tempval+"%')"; } else { qry+= " AND "+field_name+operator+"'"+tempval+"'"; } } }); $(table_obj).attr('data-query',qry); init_SQLTable(table_obj); } function detailed_search_SQLTable(obj) { var search_field_type = ''; var field_name = ''; var operator = ''; var qry = ''; var tempval = ''; var hash = ''; var table_obj = $(obj).parent('div').parent('div').parent('div').parent('th').parent('tr').parent('thead').parent('table'); $(obj).parent('div').parent('div').children('div').children('div').children('.tab-pane').each(function() { $(this).children('.search-field-detailed').each(function() { search_field_type = $(this).attr('data-search-type'); operator = $(this).attr('data-search-operator'); field_name = $(this).attr('data-search-field'); field_name = field_name.replace('_min',''); field_name = field_name.replace('_max',''); hash = '#'+$(this).attr('data-search-field')+'_detail'; tempval = $(hash).val(); if (search_field_type==='date') { tempval = tempval.replace(/\./g,'-'); } if (tempval && tempval!=='0' && tempval!=='') { if (search_field_type==='text') { qry+= " AND lower("+field_name+") LIKE lower('%"+tempval+"%')"; } else { qry+= " AND "+field_name+operator+"'"+tempval+"'"; } } }); }); $(table_obj).attr('data-query',qry); init_SQLTable(table_obj); } function delete_search_SQLTable(obj) { var table_obj = $(obj).parent('div').parent('div').parent('div').parent('th').parent('tr').parent('thead').parent('table'); $(table_obj).attr('data-query',''); init_SQLTable(table_obj); } function delete_search_SQLTable_normal(obj) { var table_obj = $(obj).parent('div').parent('div').parent('th').parent('tr').parent('thead').parent('table'); $(table_obj).attr('data-query',''); init_SQLTable(table_obj); } function detailed_delete_search_SQLTable(obj) { var table_obj = $(obj).parent('div').parent('div').parent('div').parent('th').parent('tr').parent('thead').parent('table'); $(table_obj).attr('data-query',''); $('.form-control').val(''); init_SQLTable(table_obj); } function deleterow_SQLTable(obj,id) { var table_obj = $(obj).parent('td').parent('tr').parent('tbody').parent('table'); if (window.confirm('Valóban törölni szeretné a sort?')) { $(table_obj).attr('data-action','delete'); $(table_obj).attr('data-id',id); init_SQLTable(table_obj); $(table_obj).children('thead').children('.message').children('th').children('.callout-danger').show('fast'); } } function deleterow_alternate_SQLTable(obj,id) { if (window.confirm('Valóban törölni szeretné a sort?')) { $(obj).attr('data-action','delete'); $(obj).attr('data-id',id); init_SQLTable(obj); $(obj).children('thead').children('.message').children('th').children('.callout-danger').show('fast'); } } function undeleterow_SQLTable(obj,id) { var table_obj = $(obj).parent('td').parent('tr').parent('tbody').parent('table'); if (window.confirm('Valóban vissza szeretné állítani ezt a sort?')) { $(table_obj).attr('data-action','undelete'); $(table_obj).attr('data-id',id); init_SQLTable(table_obj); $(table_obj).children('thead').children('.message').children('th').children('.callout-danger').show('fast'); } } function add_SQLTable_filter(type,filter,obj) { if (filter!=='' && type!=='') { var table_obj = $(obj).parent('li').parent('ul').parent('div').parent('th').parent('tr').parent('thead').parent('table'); $(table_obj).attr('data-filter-type',type); $(table_obj).attr('data-filter-command',filter); $(obj).parent('li').parent('ul').parent('div').children('.active-button').html(filter); init_SQLTable(table_obj); } else { return false; } } function add_SQLTable_filter_expand(type,filter,obj) { if (filter!=='' && type!=='') { var table_obj = $(obj).parent('li').parent('ul').parent('div').parent('th').parent('tr').parent('thead').parent('table'); $(table_obj).attr('data-filter-type',type); $(table_obj).attr('data-filter-command',filter); $(obj).parent('li').parent('ul').parent('div').children('.active-button').html(filter); init_SQLTable(table_obj); } else { return false; } } function add_SQLTable_limit(limit,obj,table) { if (limit!=='') { var table_obj = $(table); $(table_obj).attr('data-pager-limit',limit); $(obj).parent('li').parent('ul').parent('div').children('.active-button').html(limit+' sor'); init_SQLTable(table_obj); } else { return false; } } function show_row_SQLTable(obj,id) { if (id!=='') { var url = $(obj).attr('data-location'); window.location=url+'?id='+id; } else { return false; } } function set_SQLTable_module(module,obj) { if (module!=='') { $('#module_active').html(module); $.getJSON('/admin/properties/setmodule/',{module: module},function(response) { $('#field_list').html(response.list); $('#field_active').html(response.active); var sql_statement = " AND property_module='"+module+"' AND property_field='"+response.active+"'"; $('#properties').attr('data-query-default',sql_statement); init_SQLTable($('#properties')); }); } else { return false; } } function set_SQLTable_field(field,obj) { if (field!=='') { $('#field_active').html(field); var module = $('#module_active').html(); var sql_statement = " AND property_module='"+module+"' AND property_field='"+field+"'"; $('#properties').attr('data-query-default',sql_statement); $.post('/admin/properties/setfield/',{field: field},function(response) {}); init_SQLTable($('#properties')); } else { return false; } } function show_superfilter() { $('.superfilter').toggle(); } function set_superfilter_active(obj) { $(obj).parent('li').children('input[type="checkbox"]').attr('checked','true'); } function super_check_all(obj) { if ($(obj).is(':checked')) { //alert('ok'); $(obj).parent('li').parent('ul').children('li').children('.supercheck').prop('checked',true); } else { $(obj).parent('li').parent('ul').children('li').children('.supercheck').removeAttr('checked'); } } function supersearch(obj,table) { //var base_keyword = $(obj).children('.superfield').val(); var base_keyword = $('#search_field_keyword').val(); var sql = "SELECT * FROM viapan_persons WHERE person_status='1'"; $(obj).children('ul').children('li').each(function() { if ($(this).children('.supermini').val()!='Nincs') { if ($(this).children('.supercheck').val()==='person_born_date') { if ($('#person_born_date_min').val()!=='') { sql+= " AND person_born_date>='"+$('#person_born_date_min').val()+"'"; } if ($('#person_born_date_min').val()!=='') { sql+= " AND person_born_date<='"+$('#person_born_date_max').val()+"'"; } } else { if ($(this).children('.supermini').val()!=='') { //sql+= " AND lower(person_tags) LIKE lower('%"+$(this).children('.supermini').val()+"%')"; //sql+= " AND "+$(this).children('.supercheck').val()+" LIKE '%"+$(this).children('.supermini').val()+"%'"; } } } }); sql+= " AND lower(person_tags) LIKE lower('%"+base_keyword+"%')"; $(table).attr('data-forced-sql',sql); init_SQLTable($(table)); } function supersearch_clear(table) { $(table).attr('data-forced-sql','reset'); init_SQLTable($(table)); $('.superfield').val(''); $('#search_field_keyword').val(''); $('.supermini').val(''); } function open_group(group,obj) { //$(obj).addClass('colsep-active'); $(group).each(function() { if ($(this).hasClass('collapse-hide')) { $(this).removeClass('collapse-hide'); } else { $(this).addClass('collapse-hide'); } }); } function super_ban(obj) { var inp = $(obj).parent('li').children('.supermini'); //alert($(inp).attr('disabled')); if ($(inp).attr('disabled')==='disabled') { $(inp).val(''); $(inp).removeAttr('disabled'); } else { $(inp).val('Nincs'); $(inp).attr('disabled','true'); } } $('document').ready(function() { $('.SQLTable').each(function() { init_SQLTable($(this)); }); $('.search').on('keydown',function(event) { if (event.which === 13) { $('#gosearch').trigger('click'); } }); $('.det-search-inp').on('keydown',function(event) { if (event.which === 13) { $('#detailed_search_go').trigger('click'); } }); });