TableAjax.php.init.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. jQuery(document).ready(function(){
  2. jQuery('#' + TABLE_AJAX_NODE_ID).TableAjax({
  3. checkboxes: GUI_SHOW_CHECKBOXES || 0,
  4. checkboxIdContext: CHECKBOX_ID_CONTEXT || null,
  5. namespace: NAMESPACE,
  6. url: URL_LOAD_AJAX_BASE,
  7. getCsvTheGeomAjaxUrl: URL_GET_CSV_THE_GEOM_AJAX,
  8. removeTheGeomAjaxUrl: URL_REMOVE_THE_GEOM_AJAX,
  9. moreFunctionsCellAjaxUrl: URL_MORE_FUNCTIONS_CELL_AJAX,
  10. editInlineSaveUrl: URL_EDIT_INLINE_SAVE,
  11. theGeomSaveUrl: URL_THE_GEOM_SAVE,
  12. pageSizeSave: URL_PAGE_SIZE_SAVE,
  13. hiddenColsSaveUrl: URL_HIDDEN_COLS_SAVE,
  14. editInlineUrl: URL_EDIT_INLINE,
  15. addUserTableFilterAjaxUrl: URL_ADD_USER_TABLE_FILTER_AJAX,
  16. rmUserTableFilterAjaxUrl: URL_RM_USER_TABLE_FILTER_AJAX,
  17. hasAdditionalLayers: HAS_ADDITIONAL_LAYERS,
  18. labelHtml: LABEL_HTML,
  19. userTableFilterUrl: URL_USER_TABLE_FILTER,
  20. columnPicker: true,
  21. filter: true,
  22. filterInit: FILTER_INIT,
  23. forceFilterInit: FIRCE_FILTER_INIT,
  24. debug: false,
  25. height: 400,
  26. sorting: true,
  27. paging: true,
  28. pageSize: PAGE_SIZE,
  29. pageSizes: PAGE_SIZES,
  30. tblFunctions: TABLE_FUNCTIONS,
  31. rowFunctions: ROW_FUNCTIONS,
  32. exportFields: EXPORT_FIELDS,
  33. specialFilterFunctions: SPECIAL_FILTER_FUNCTIONS,
  34. router: tableAjaxRouter,
  35. filtersClean: true,
  36. longDesc: true
  37. });
  38. });
  39. function tableAjaxRouter() {
  40. var routes = {
  41. EDIT: global[FUNCTION_EDIT_ROUTE],
  42. HIST: global[FUNCTION_HIST_ROUTE],
  43. FILES: function tableAjaxFiles(args) {
  44. var recordID = args;
  45. if (typeof args == 'object') {
  46. recordID = args.shift();
  47. recordID = parseInt(recordID);
  48. }
  49. if (typeof recordID !== 'number' || recordID <= 0) {
  50. // TODO: msg
  51. return false;
  52. }
  53. var cont = jQuery('#' + TABLE_AJAX_NODE_ID).parent();
  54. cont.hide();
  55. // remove previous task content
  56. var taskCnt = jQuery('#' + TABLE_AJAX_NODE_ID + '_task');
  57. taskCnt.parent().remove();
  58. taskCnt.remove();
  59. var taskCont = jQuery('<div class="AjaxTableCont"></div>').insertBefore(cont);
  60. jQuery('<ul class="breadcrumb">' +
  61. '<li><a href="#" onclick="return tableAjaxBackToTable();">' + LABEL_HTML + '</a></li>' +
  62. '<li class="active">Pliki</li>' +
  63. '</ul>').appendTo(taskCont);
  64. var taskCnt = jQuery('<div id="' + TABLE_AJAX_NODE_ID + '_task" class="AjaxTable-loading"></div>').appendTo(taskCont);
  65. jQuery('<span class="loading-info"> loading ...</span>').appendTo(taskCnt);
  66. jQuery.ajax({
  67. url: URL_RECORD_FILES + '&ID=' + recordID,
  68. type: 'GET',
  69. dataType: 'text',
  70. data: '',
  71. async: true,
  72. success: function(data) {
  73. taskCnt.removeClass('AjaxTable-loading');
  74. jQuery(data).appendTo(taskCnt);
  75. },
  76. error: function(jqXHR, textStatus, errorThrown) {
  77. //console.log('request error:', jqXHR.status, 'txt:', jqXHR.responseText, 'err:', jqXHR);
  78. taskCnt.removeClass('AjaxTable-loading');
  79. var txt = jqXHR.responseText || 'Error';
  80. if (jqXHR.status == 404) {
  81. jQuery('<div class="container"><div class="alert alert-danger">' + txt + '</div></div>').appendTo(taskCnt);
  82. } else {
  83. jQuery('<div class="container"><div class="alert alert-danger">' + txt + '</div></div>').appendTo(taskCnt);
  84. }
  85. }
  86. });
  87. //return false;
  88. },
  89. CREATE: TableAjax__CREATE_Route,
  90. };
  91. var routePath = location.hash;
  92. //console.log('location.hash: ' + routePath);
  93. if (location.hash == '' || location.hash == '#') {
  94. return false;
  95. }
  96. if (routePath.charAt(0) == '#') {
  97. routePath = routePath.substr(1);
  98. }
  99. //console.log('routePath: ' + routePath);
  100. var parts = routePath.split('/');
  101. var task = parts.shift();
  102. //console.log('task(' + task + ') parts:');
  103. //console.log(parts);
  104. if (task in routes && typeof routes[task] == 'function') {
  105. var con = jQuery('#' + TABLE_AJAX_NODE_ID);
  106. if (con) {
  107. var tblAjax = con.data('TableAjax');
  108. if (tblAjax) {
  109. tblAjax.popoverCellRemove();
  110. }
  111. }
  112. routes[task](parts);
  113. } else {
  114. return false;
  115. }
  116. }
  117. function tableAjaxBackToTable() {
  118. window.location.href = window.location.pathname + window.location.search;
  119. // var cont = jQuery('#' + TABLE_AJAX_NODE_ID).parent();
  120. // cont.show();
  121. // var taskCont = jQuery('#' + TABLE_AJAX_NODE_ID + '_task').parent();
  122. // taskCont.remove();
  123. //
  124. // // reload first page
  125. // var con = jQuery('#' + TABLE_AJAX_NODE_ID);
  126. // con.TableAjaxLoadPage();// TODO: load current page
  127. }
  128. function tableAjaxCopy(args) {
  129. var recordID = args;
  130. if (typeof args == 'object') {
  131. recordID = args.shift();
  132. recordID = parseInt(recordID);
  133. }
  134. if (typeof recordID !== 'number' || recordID <= 0) {
  135. // TODO: msg
  136. return false;
  137. }
  138. if (!confirm('Czy na pewno chcesz utworzyc nowy rekord na podstawie danych z rekordu ID = ' + recordID + '?')) {
  139. return false;
  140. }
  141. var cont = jQuery('#' + TABLE_AJAX_NODE_ID).parent();
  142. function notifyAjaxCallback(data) {
  143. var notify = {};
  144. notify.type = (data && data.type)? data.type : '';
  145. notify.msg = (data && data.msg)? data.msg : '';
  146. switch (notify.type) {
  147. case 'success':
  148. if (!notify.msg) notify.msg = 'OK';
  149. break;
  150. case 'info':
  151. if (!notify.msg) notify.msg = '';
  152. break;
  153. case 'error':
  154. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  155. break;
  156. case 'warning':
  157. notify.type = 'warn';
  158. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  159. break;
  160. default:
  161. notify.msg = 'Nieznany błąd';
  162. if (data && data.errorCode) notify.msg += ' ' + data.errorCode;
  163. notify.type = '';
  164. }
  165. jQuery.notify(notify.msg, notify.type);
  166. }
  167. var reqData = {};
  168. jQuery.ajax({
  169. data: reqData,
  170. dataType: 'json',
  171. type: "GET",
  172. url: URL_RECORD_COPY + '&ID=' + recordID,
  173. })
  174. .done(function(data, textStatus, jqXHR){
  175. var con = jQuery('#' + TABLE_AJAX_NODE_ID);
  176. con.TableAjaxRefresh();
  177. notifyAjaxCallback(data);
  178. })
  179. .fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
  180. if (jqXHR.responseJSON) {
  181. notifyAjaxCallback(jqXHR.responseJSON);
  182. }
  183. else {
  184. var txt = jqXHR.responseText || 'Wystąpiły błędy';
  185. if (jqXHR.status == 404) {
  186. jQuery.notify(jqXHR.responseText, 'error');
  187. } else {
  188. jQuery.notify(jqXHR.responseText, 'warn');
  189. }
  190. }
  191. });
  192. return false;
  193. }
  194. function hidePopover() {
  195. var con = jQuery('#' + TABLE_AJAX_NODE_ID);
  196. if (con) {
  197. var tblAjax = con.data('TableAjax');
  198. if (tblAjax) {
  199. tblAjax.popoverCellRemove();
  200. }
  201. }
  202. return false;
  203. }
  204. global.tableAjaxBackToTable = tableAjaxBackToTable;
  205. global.tableAjaxCopy = tableAjaxCopy;
  206. global.hidePopover = hidePopover;