TableAjax.php.procesInitFiltr.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // @require variables:
  2. if ('undefined' === typeof JS_FUNCTION_NAME) throw "Missing JS_FUNCTION_NAME";
  3. if ('undefined' === typeof URL_GET_PROCES_INIT_FILTR) throw "Missing URL_GET_PROCES_INIT_FILTR";
  4. if ('undefined' === typeof ID_ZASOB) throw "Missing ID_ZASOB";
  5. function toggleProcesInitFiltr(n) {
  6. var $n = jQuery(n);
  7. var $ul = $n.next();
  8. if ($n.data('fetched')) return false;
  9. function parseProcesInitData(pInitData) {
  10. var procesInitMapHtml = '';
  11. if (!pInitData) {
  12. return '<li><a href="#">' + "Brak danych" + '</a></li>';
  13. } else {
  14. function _viewProcesInitListItem(pInitId, gotoIds, pInitList) {
  15. var label = pInitList[pInitId];
  16. var jsInfo = "window.open('procesy5.php?task=PROCES_VIEW_LIST&id_proces=" + pInitId + "&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1');return false;";
  17. var out = '<a href="index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces=' + pInitId + '&MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=' + ID_ZASOB + '" title="' + "{" + pInitId + "} " + label + '">';// TODO: change to _route=ViewTableAjax&typeName=p5_default_db:{tblName}
  18. out += ' <i class="glyphicon glyphicon-info-sign"';
  19. out += ' onclick="' + jsInfo + '"';
  20. out += ' style="color:#aaa;"';
  21. out += ' onmouseover="' + "this.style.color='#337AB7'" + '"';
  22. out += ' onmouseout="' + "this.style.color='#aaa'" + '"></i>';
  23. out += " {" + pInitId + "} " + label;
  24. out += '</a>';
  25. return out;
  26. }
  27. function _viewProcesGotoAndRetListItem(gotoId, pInitList) {
  28. var label = pInitList[gotoId];
  29. var jsInfo = "window.open('procesy5.php?task=PROCES_VIEW_LIST&id_proces=" + gotoId + "&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1');return false;";
  30. var out = '';
  31. out += '<a href="index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces=' + gotoId + '&MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=' + ID_ZASOB + '" title="' + "{" + gotoId + "} " + label + '">';// TODO: change to _route=ViewTableAjax&typeName=p5_default_db:{tblName}
  32. out += ' <span style="padding:10px;"></span>';
  33. out += ' <i class="glyphicon glyphicon-arrow-right" style="color:#aaa"></i>';
  34. out += ' <i class="glyphicon glyphicon-info-sign"';
  35. out += ' onclick="' + jsInfo + '"';
  36. out += ' style="color:#aaa;"';
  37. out += ' onmouseover="' + "this.style.color='#337AB7'" + '"';
  38. out += ' onmouseout="' + "this.style.color='#aaa'" + '"></i>';
  39. out += " {" + gotoId + "} " + label;
  40. out += '</a>';
  41. return out;
  42. }
  43. function _viewProcesGotoAndRetLvl2ListItem(gotoLvl2Id, pInitList) {
  44. var label = pInitList[gotoLvl2Id];
  45. var jsInfo = "window.open('procesy5.php?task=PROCES_VIEW_LIST&id_proces=" + gotoLvl2Id + "&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1');return false;";
  46. var out = '';
  47. out += '<a href="index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces=' + gotoLvl2Id + '&MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=' + ID_ZASOB + '" title="' + "{" + gotoLvl2Id + "} " + label + '">';// TODO: change to _route=ViewTableAjax&typeName=p5_default_db:{tblName}
  48. out += ' <span style="padding:20px;"></span>';
  49. out += ' <i class="glyphicon glyphicon-arrow-right" style="color:#aaa"></i>';
  50. out += ' <i class="glyphicon glyphicon-info-sign"';
  51. out += ' onclick="' + jsInfo + '"';
  52. out += ' style="color:#aaa;"';
  53. out += ' onmouseover="' + "this.style.color='#337AB7'" + '"';
  54. out += ' onmouseout="' + "this.style.color='#aaa'" + '"></i>';
  55. out += " {" + gotoLvl2Id + "} " + label;
  56. out += '</a>';
  57. return out;
  58. }
  59. var sel = '',
  60. liStyle = "white-space:nowrap; overflow:hidden; max-width:500px; /* text-overflow:ellipsis; */";
  61. $.map(pInitData.mapTree, function(gotoIds, vInitId) {
  62. sel = (pInitData.pInitListSelected && pInitData.pInitListSelected == vInitId)? ' class="disabled"' : '';
  63. procesInitMapHtml += '<li' + sel + ' style="' + liStyle + '">';
  64. procesInitMapHtml += _viewProcesInitListItem(vInitId, gotoIds, pInitData.pInitList);
  65. procesInitMapHtml += '</li>' + "\n";
  66. $.map(gotoIds, function(gotoLvl2Ids, gotoId) {
  67. sel = (pInitData.pInitListSelected && pInitData.pInitListSelected == vInitId)? ' class="disabled"' : '';
  68. procesInitMapHtml += '<li' + sel + ' style="' + liStyle + '">';
  69. procesInitMapHtml += _viewProcesGotoAndRetListItem(gotoId, pInitData.pInitList);
  70. procesInitMapHtml += '</li>' + "\n";
  71. $.map(gotoLvl2Ids, function(vBool, gotoLvl2Id) {
  72. sel = (pInitData.pInitListSelected && pInitData.pInitListSelected == vInitId)? ' class="disabled"' : '';
  73. procesInitMapHtml += '<li' + sel + ' style="' + liStyle + '">';
  74. procesInitMapHtml += _viewProcesGotoAndRetLvl2ListItem(gotoLvl2Id, pInitData.pInitList);
  75. procesInitMapHtml += '</li>' + "\n";
  76. });
  77. });
  78. });
  79. }
  80. return procesInitMapHtml;
  81. }
  82. jQuery.ajax({
  83. data: null,
  84. dataType: 'json',
  85. type: "GET",
  86. async: true,
  87. url: URL_GET_PROCES_INIT_FILTR
  88. })
  89. .always(function(data, textStatus, jqXHR) {
  90. var type = data.type || null,
  91. msg = data.msg || "Error",
  92. pInitData = data.pInitData || null;
  93. if (type) {
  94. if ('success' == type) {
  95. $ul.html(parseProcesInitData(pInitData));
  96. } else if ('error' == type) {
  97. $ul.html('<li><a href="#">' + msg + '</a></li>');
  98. } else {
  99. $ul.html('<li><a href="#">Wystapił błąd podczas pobierania listy procesów</a></li>');
  100. }
  101. } else {
  102. $ul.html('<li><a href="#">Wystapił błąd podczas pobierania listy procesów</a></li>');
  103. }
  104. $n.data('fetched', true);
  105. });
  106. return false;
  107. }
  108. global[JS_FUNCTION_NAME] = toggleProcesInitFiltr