| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493 |
- 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');
- }
- });
-
- });
|