TableAjax.php.init.js 6.1 KB

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