TableAjax.php.init.js 6.1 KB

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