TableAjax.php.init.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. selectedFunctions: SELECTED_FUNCTIONS,
  35. router: tableAjaxRouter,
  36. filtersClean: true,
  37. longDesc: true
  38. });
  39. });
  40. function tableAjaxRouter() {
  41. var routes = {
  42. EDIT: global[FUNCTION_EDIT_ROUTE],
  43. HIST: global[FUNCTION_HIST_ROUTE],
  44. FILES: function tableAjaxFiles(args) {
  45. var recordID = args;
  46. if (typeof args == 'object') {
  47. recordID = args.shift();
  48. recordID = parseInt(recordID);
  49. }
  50. if (typeof recordID !== 'number' || recordID <= 0) {
  51. // TODO: msg
  52. return false;
  53. }
  54. var cont = jQuery('#' + TABLE_AJAX_NODE_ID).parent();
  55. cont.hide();
  56. // remove previous task content
  57. var taskCnt = jQuery('#' + TABLE_AJAX_NODE_ID + '_task');
  58. taskCnt.parent().remove();
  59. taskCnt.remove();
  60. var taskCont = jQuery('<div class="AjaxTableCont"></div>').insertBefore(cont);
  61. jQuery('<ul class="breadcrumb">' +
  62. '<li><a href="#" onclick="return tableAjaxBackToTable();">' + LABEL_HTML + '</a></li>' +
  63. '<li class="active">Pliki</li>' +
  64. '</ul>').appendTo(taskCont);
  65. var taskCnt = jQuery('<div id="' + TABLE_AJAX_NODE_ID + '_task" class="AjaxTable-loading"></div>').appendTo(taskCont);
  66. jQuery('<span class="loading-info"> loading ...</span>').appendTo(taskCnt);
  67. jQuery.ajax({
  68. url: URL_RECORD_FILES + '&ID=' + recordID,
  69. type: 'GET',
  70. dataType: 'text',
  71. data: '',
  72. async: true,
  73. success: function(data) {
  74. taskCnt.removeClass('AjaxTable-loading');
  75. jQuery(data).appendTo(taskCnt);
  76. },
  77. error: function(jqXHR, textStatus, errorThrown) {
  78. //console.log('request error:', jqXHR.status, 'txt:', jqXHR.responseText, 'err:', jqXHR);
  79. taskCnt.removeClass('AjaxTable-loading');
  80. var txt = jqXHR.responseText || 'Error';
  81. if (jqXHR.status == 404) {
  82. jQuery('<div class="container"><div class="alert alert-danger">' + txt + '</div></div>').appendTo(taskCnt);
  83. } else {
  84. jQuery('<div class="container"><div class="alert alert-danger">' + txt + '</div></div>').appendTo(taskCnt);
  85. }
  86. }
  87. });
  88. //return false;
  89. },
  90. CREATE: TableAjax__CREATE_Route,
  91. };
  92. var routePath = location.hash;
  93. //console.log('location.hash: ' + routePath);
  94. if (location.hash == '' || location.hash == '#') {
  95. return false;
  96. }
  97. if (routePath.charAt(0) == '#') {
  98. routePath = routePath.substr(1);
  99. }
  100. //console.log('routePath: ' + routePath);
  101. var parts = routePath.split('/');
  102. var task = parts.shift();
  103. //console.log('task(' + task + ') parts:');
  104. //console.log(parts);
  105. if (task in routes && typeof routes[task] == 'function') {
  106. var con = jQuery('#' + TABLE_AJAX_NODE_ID);
  107. if (con) {
  108. var tblAjax = con.data('TableAjax');
  109. if (tblAjax) {
  110. tblAjax.popoverCellRemove();
  111. }
  112. }
  113. routes[task](parts);
  114. } else {
  115. return false;
  116. }
  117. }
  118. function tableAjaxBackToTable() {
  119. window.location.href = window.location.pathname + window.location.search;
  120. // var cont = jQuery('#' + TABLE_AJAX_NODE_ID).parent();
  121. // cont.show();
  122. // var taskCont = jQuery('#' + TABLE_AJAX_NODE_ID + '_task').parent();
  123. // taskCont.remove();
  124. //
  125. // // reload first page
  126. // var con = jQuery('#' + TABLE_AJAX_NODE_ID);
  127. // con.TableAjaxLoadPage();// TODO: load current page
  128. }
  129. function tableAjaxCopy(args) {
  130. var recordID = args;
  131. if (typeof args == 'object') {
  132. recordID = args.shift();
  133. recordID = parseInt(recordID);
  134. }
  135. if (typeof recordID !== 'number' || recordID <= 0) {
  136. // TODO: msg
  137. return false;
  138. }
  139. if (!confirm('Czy na pewno chcesz utworzyc nowy rekord na podstawie danych z rekordu ID = ' + recordID + '?')) {
  140. return false;
  141. }
  142. var cont = jQuery('#' + TABLE_AJAX_NODE_ID).parent();
  143. function notifyAjaxCallback(data) {
  144. var notify = {};
  145. notify.type = (data && data.type)? data.type : '';
  146. notify.msg = (data && data.msg)? data.msg : '';
  147. switch (notify.type) {
  148. case 'success':
  149. if (!notify.msg) notify.msg = 'OK';
  150. break;
  151. case 'info':
  152. if (!notify.msg) notify.msg = '';
  153. break;
  154. case 'error':
  155. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  156. break;
  157. case 'warning':
  158. notify.type = 'warn';
  159. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  160. break;
  161. default:
  162. notify.msg = 'Nieznany błąd';
  163. if (data && data.errorCode) notify.msg += ' ' + data.errorCode;
  164. notify.type = '';
  165. }
  166. jQuery.notify(notify.msg, notify.type);
  167. }
  168. var reqData = {};
  169. jQuery.ajax({
  170. data: reqData,
  171. dataType: 'json',
  172. type: "GET",
  173. url: URL_RECORD_COPY + '&ID=' + recordID,
  174. })
  175. .done(function(data, textStatus, jqXHR){
  176. var con = jQuery('#' + TABLE_AJAX_NODE_ID);
  177. con.TableAjaxRefresh();
  178. notifyAjaxCallback(data);
  179. })
  180. .fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
  181. if (jqXHR.responseJSON) {
  182. notifyAjaxCallback(jqXHR.responseJSON);
  183. }
  184. else {
  185. var txt = jqXHR.responseText || 'Wystąpiły błędy';
  186. if (jqXHR.status == 404) {
  187. jQuery.notify(jqXHR.responseText, 'error');
  188. } else {
  189. jQuery.notify(jqXHR.responseText, 'warn');
  190. }
  191. }
  192. });
  193. return false;
  194. }
  195. function hidePopover() {
  196. var con = jQuery('#' + TABLE_AJAX_NODE_ID);
  197. if (con) {
  198. var tblAjax = con.data('TableAjax');
  199. if (tblAjax) {
  200. tblAjax.popoverCellRemove();
  201. }
  202. }
  203. return false;
  204. }
  205. global.tableAjaxBackToTable = tableAjaxBackToTable;
  206. global.tableAjaxCopy = tableAjaxCopy;
  207. global.hidePopover = hidePopover;