TableAjax.php.init.js 6.0 KB

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