| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- jQuery(document).ready(function(){
- jQuery('#' + TABLE_AJAX_NODE_ID).TableAjax({
- checkboxes: GUI_SHOW_CHECKBOXES || 0,
- namespace: NAMESPACE,
- url: URL_LOAD_AJAX_BASE,
- getCsvTheGeomAjaxUrl: URL_GET_CSV_THE_GEOM_AJAX,
- removeTheGeomAjaxUrl: URL_REMOVE_THE_GEOM_AJAX,
- moreFunctionsCellAjaxUrl: URL_MORE_FUNCTIONS_CELL_AJAX,
- editInlineSaveUrl: URL_EDIT_INLINE_SAVE,
- theGeomSaveUrl: URL_THE_GEOM_SAVE,
- pageSizeSave: URL_PAGE_SIZE_SAVE,
- hiddenColsSaveUrl: URL_HIDDEN_COLS_SAVE,
- editInlineUrl: URL_EDIT_INLINE,
- addUserTableFilterAjaxUrl: URL_ADD_USER_TABLE_FILTER_AJAX,
- rmUserTableFilterAjaxUrl: URL_RM_USER_TABLE_FILTER_AJAX,
- hasAdditionalLayers: HAS_ADDITIONAL_LAYERS,
- labelHtml: LABEL_HTML,
- userTableFilterUrl: URL_USER_TABLE_FILTER,
- columnPicker: true,
- filter: true,
- filterInit: FILTER_INIT,
- forceFilterInit: FIRCE_FILTER_INIT,
- debug: false,
- height: 400,
- sorting: true,
- paging: true,
- pageSize: PAGE_SIZE,
- pageSizes: PAGE_SIZES,
- tblFunctions: TABLE_FUNCTIONS,
- rowFunctions: ROW_FUNCTIONS,
- exportFields: EXPORT_FIELDS,
- specialFilterFunctions: SPECIAL_FILTER_FUNCTIONS,
- router: tableAjaxRouter,
- filtersClean: true,
- longDesc: true
- });
- });
- function tableAjaxRouter() {
- var routes = {
- EDIT: global[FUNCTION_EDIT_ROUTE],
- HIST: global[FUNCTION_HIST_ROUTE],
- FILES: function tableAjaxFiles(args) {
- var recordID = args;
- if (typeof args == 'object') {
- recordID = args.shift();
- recordID = parseInt(recordID);
- }
- if (typeof recordID !== 'number' || recordID <= 0) {
- // TODO: msg
- return false;
- }
- var cont = jQuery('#' + TABLE_AJAX_NODE_ID).parent();
- cont.hide();
- // remove previous task content
- var taskCnt = jQuery('#' + TABLE_AJAX_NODE_ID + '_task');
- taskCnt.parent().remove();
- taskCnt.remove();
- var taskCont = jQuery('<div class="AjaxTableCont"></div>').insertBefore(cont);
- jQuery('<ul class="breadcrumb">' +
- '<li><a href="#" onclick="return tableAjaxBackToTable();">' + LABEL_HTML + '</a></li>' +
- '<li class="active">Pliki</li>' +
- '</ul>').appendTo(taskCont);
- var taskCnt = jQuery('<div id="' + TABLE_AJAX_NODE_ID + '_task" class="AjaxTable-loading"></div>').appendTo(taskCont);
- jQuery('<span class="loading-info"> loading ...</span>').appendTo(taskCnt);
- jQuery.ajax({
- url: URL_RECORD_FILES + '&ID=' + recordID,
- type: 'GET',
- dataType: 'text',
- data: '',
- async: true,
- success: function(data) {
- taskCnt.removeClass('AjaxTable-loading');
- jQuery(data).appendTo(taskCnt);
- },
- error: function(jqXHR, textStatus, errorThrown) {
- //console.log('request error:', jqXHR.status, 'txt:', jqXHR.responseText, 'err:', jqXHR);
- taskCnt.removeClass('AjaxTable-loading');
- var txt = jqXHR.responseText || 'Error';
- if (jqXHR.status == 404) {
- jQuery('<div class="container"><div class="alert alert-danger">' + txt + '</div></div>').appendTo(taskCnt);
- } else {
- jQuery('<div class="container"><div class="alert alert-danger">' + txt + '</div></div>').appendTo(taskCnt);
- }
- }
- });
- //return false;
- },
- CREATE: TableAjax__CREATE_Route,
- };
- var routePath = location.hash;
- //console.log('location.hash: ' + routePath);
- if (location.hash == '' || location.hash == '#') {
- return false;
- }
- if (routePath.charAt(0) == '#') {
- routePath = routePath.substr(1);
- }
- //console.log('routePath: ' + routePath);
- var parts = routePath.split('/');
- var task = parts.shift();
- //console.log('task(' + task + ') parts:');
- //console.log(parts);
- if (task in routes && typeof routes[task] == 'function') {
- var con = jQuery('#' + TABLE_AJAX_NODE_ID);
- if (con) {
- var tblAjax = con.data('TableAjax');
- if (tblAjax) {
- tblAjax.popoverCellRemove();
- }
- }
- routes[task](parts);
- } else {
- return false;
- }
- }
- function tableAjaxBackToTable() {
- var cont = jQuery('#' + TABLE_AJAX_NODE_ID).parent();
- cont.show();
- var taskCont = jQuery('#' + TABLE_AJAX_NODE_ID + '_task').parent();
- taskCont.remove();
- // reload first page
- var con = jQuery('#' + TABLE_AJAX_NODE_ID);
- con.TableAjaxLoadPage();// TODO: load current page
- }
- function tableAjaxCopy(args) {
- var recordID = args;
- if (typeof args == 'object') {
- recordID = args.shift();
- recordID = parseInt(recordID);
- }
- if (typeof recordID !== 'number' || recordID <= 0) {
- // TODO: msg
- return false;
- }
- if (!confirm('Czy na pewno chcesz utworzyc nowy rekord na podstawie danych z rekordu ID = ' + recordID + '?')) {
- return false;
- }
- var cont = jQuery('#' + TABLE_AJAX_NODE_ID).parent();
- function notifyAjaxCallback(data) {
- var notify = {};
- notify.type = (data && data.type)? data.type : '';
- notify.msg = (data && data.msg)? data.msg : '';
- switch (notify.type) {
- case 'success':
- if (!notify.msg) notify.msg = 'OK';
- break;
- case 'info':
- if (!notify.msg) notify.msg = '';
- break;
- case 'error':
- if (!notify.msg) notify.msg = 'Wystąpiły błędy';
- break;
- case 'warning':
- notify.type = 'warn';
- if (!notify.msg) notify.msg = 'Wystąpiły błędy';
- break;
- default:
- notify.msg = 'Nieznany błąd';
- if (data && data.errorCode) notify.msg += ' ' + data.errorCode;
- notify.type = '';
- }
- jQuery.notify(notify.msg, notify.type);
- }
- var reqData = {};
- jQuery.ajax({
- data: reqData,
- dataType: 'json',
- type: "GET",
- url: URL_RECORD_COPY + '&ID=' + recordID,
- })
- .done(function(data, textStatus, jqXHR){
- var con = jQuery('#' + TABLE_AJAX_NODE_ID);
- con.TableAjaxRefresh();
- notifyAjaxCallback(data);
- })
- .fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
- if (jqXHR.responseJSON) {
- notifyAjaxCallback(jqXHR.responseJSON);
- }
- else {
- var txt = jqXHR.responseText || 'Wystąpiły błędy';
- if (jqXHR.status == 404) {
- jQuery.notify(jqXHR.responseText, 'error');
- } else {
- jQuery.notify(jqXHR.responseText, 'warn');
- }
- }
- });
- return false;
- }
- function hidePopover() {
- var con = jQuery('#' + TABLE_AJAX_NODE_ID);
- if (con) {
- var tblAjax = con.data('TableAjax');
- if (tblAjax) {
- tblAjax.popoverCellRemove();
- }
- }
- return false;
- }
- global.tableAjaxBackToTable = tableAjaxBackToTable;
- global.tableAjaxCopy = tableAjaxCopy;
- global.hidePopover = hidePopover;
|