TableAjax.php.procesInitFiltr.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 p5Utils__convertToHtml(tagName, attributes, childrens) { // ( string tagName, object attributes, array childrens )
  6. return '<' + tagName + ( attributes ? ' ' + p5Utils__convertAttrsToHtml(attributes) : '' ) + '>' + ( childrens || [] ).join("") + '</' + tagName + '>';
  7. }
  8. function p5Utils__convertAttrsToHtml(attributes) {
  9. return Object.keys(attributes).map(function (attrName) {
  10. var name = attrName;
  11. if ('className' === name) name = 'class';
  12. return '' + name + '="' + attributes[attrName] + '"'
  13. }).join(" ")
  14. }
  15. function _viewProcesInitListItem(pInitId, label, selected) {
  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 h = p5Utils__convertToHtml;
  18. return h('form', { className: "form-inline", method: "post", action: "", style: "padding: 3px 20px" }, [
  19. h('input', { type: "hidden", name: "_rootPostTask", value: "SetPermsByProces" }),
  20. h('input', { type: "hidden", name: "id_proces", value: pInitId }),
  21. h('i', {
  22. className: "glyphicon glyphicon-info-sign",
  23. style: "color:#aaa; cursor:help",
  24. onclick: jsInfo,
  25. title: "Przeglądaj proces {" + pInitId + "} " + label,
  26. onmouseover: "this.style.color = '#337AB7'", onmouseout: "this.style.color = '#aaa'"
  27. }),
  28. h('button', {
  29. className: "btn btn-link" + ( selected ? " disabled" : "" ),
  30. style: "padding:0 3px",
  31. title: "Uruchom filtr procesu {" + pInitId + "}"
  32. }, [
  33. " {" + pInitId + "} " + label,
  34. ]),
  35. ]);
  36. }
  37. function _viewProcesGotoAndRetListItem(gotoId, label, selected) {
  38. 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;";
  39. var h = p5Utils__convertToHtml;
  40. return h('form', { className: "form-inline", method: "post", action: "", style: "padding:3px 20px; margin-left:20px" }, [
  41. h('input', { type: "hidden", name: "_rootPostTask", value: "SetPermsByProces" }),
  42. h('input', { type: "hidden", name: "id_proces", value: gotoId }),
  43. h('i', {
  44. className: "glyphicon glyphicon-info-sign",
  45. style: "color:#aaa; cursor:help",
  46. title: "Przeglądaj proces {" + gotoId + "} " + label,
  47. onclick: jsInfo,
  48. onmouseover: "this.style.color = '#337AB7'", onmouseout: "this.style.color = '#aaa'"
  49. }),
  50. h('button', {
  51. className: "btn btn-link" + ( selected ? " disabled" : "" ),
  52. style: "padding:0 3px",
  53. title: "Uruchom filtr procesu {" + gotoId + "}"
  54. }, [
  55. " {" + gotoId + "} " + label,
  56. ]),
  57. ]);
  58. }
  59. function _viewProcesGotoAndRetLvl2ListItem(gotoLvl2Id, label, selected) {
  60. 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;";
  61. var h = p5Utils__convertToHtml;
  62. return h('form', { className: "form-inline", method: "post", action: "", style: "padding:3px 20px; margin-left:40px" }, [
  63. h('input', { type: "hidden", name: "_rootPostTask", value: "SetPermsByProces" }),
  64. h('input', { type: "hidden", name: "id_proces", value: gotoLvl2Id }),
  65. h('i', { className: "glyphicon glyphicon-arrow-right", style: "color:#aaa" }),
  66. h('i', {
  67. className: "glyphicon glyphicon-info-sign",
  68. style: "color:#aaa; cursor:help",
  69. title: "Przeglądaj proces {" + gotoLvl2Id + "} " + label,
  70. onclick: jsInfo,
  71. onmouseover: "this.style.color = '#337AB7'", onmouseout: "this.style.color = '#aaa'"
  72. }),
  73. h('button', {
  74. className: "btn btn-link" + ( selected ? " disabled" : "" ),
  75. style: "padding:0 3px",
  76. title: "Uruchom filtr procesu {" + gotoLvl2Id + "}"
  77. }, [
  78. " {" + gotoLvl2Id + "} " + label,
  79. ]),
  80. ]);
  81. }
  82. function _viewDropdownListItem(id, label, selected, callback) {
  83. var h = p5Utils__convertToHtml;
  84. return h('li', {
  85. style: "white-space:nowrap; overflow:hidden; max-width:500px; /* text-overflow:ellipsis; */",
  86. onmouseover: "this.style.backgroundColor='#f5f5f5'", onmouseout: "this.style.backgroundColor='#fff'",
  87. }, [
  88. callback(id, label, selected),
  89. ]);
  90. }
  91. function toggleProcesInitFiltr(n) {
  92. var $n = jQuery(n);
  93. var $ul = $n.next();
  94. if ($n.data('fetched')) return false;
  95. function parseProcesInitData(pInitData) {
  96. return (!pInitData || !pInitData.mapTree)
  97. ? '<li><a href="#">' + "Brak danych" + '</a></li>'
  98. : Object.keys(pInitData.mapTree).map(function (vInitId) {
  99. var gotoIds = pInitData.mapTree[vInitId];
  100. var sel = (pInitData.pInitListSelected && pInitData.pInitListSelected == vInitId);
  101. return [
  102. _viewDropdownListItem(vInitId, pInitData.pInitList[vInitId], sel, _viewProcesInitListItem)
  103. ].concat(
  104. (!gotoIds) ? null : Object.keys(gotoIds).map(function (gotoId) {
  105. var gotoLvl2Ids = gotoIds[gotoId];
  106. var sel = (pInitData.pInitListSelected && pInitData.pInitListSelected == vInitId);
  107. return [
  108. _viewDropdownListItem(gotoId, pInitData.pInitList[gotoId], sel, _viewProcesGotoAndRetListItem)
  109. ].concat(
  110. (!gotoLvl2Ids) ? null : Object.keys(gotoLvl2Ids).map(function (gotoLvl2Id) {
  111. // var vBool = gotoLvl2Ids[gotoLvl2Id];
  112. return _viewDropdownListItem(gotoLvl2Id, pInitData.pInitList[gotoLvl2Id], sel, _viewProcesGotoAndRetLvl2ListItem);
  113. }).join("\n")
  114. ).join("\n");
  115. }).join("\n")
  116. ).join("\n");
  117. }).join("\n")
  118. ;
  119. }
  120. jQuery.ajax({
  121. data: null,
  122. dataType: 'json',
  123. type: "GET",
  124. async: true,
  125. url: URL_GET_PROCES_INIT_FILTR
  126. })
  127. .always(function(data, textStatus, jqXHR) {
  128. var type = data.type || null,
  129. msg = data.msg || "Error",
  130. pInitData = data.pInitData || null;
  131. if (type) {
  132. if ('success' == type) {
  133. $ul.html(parseProcesInitData(pInitData));
  134. } else if ('error' == type) {
  135. $ul.html('<li><a href="#">' + msg + '</a></li>');
  136. } else {
  137. $ul.html('<li><a href="#">Wystapił błąd podczas pobierania listy procesów</a></li>');
  138. }
  139. } else {
  140. $ul.html('<li><a href="#">Wystapił błąd podczas pobierania listy procesów</a></li>');
  141. }
  142. $n.data('fetched', true);
  143. });
  144. return false;
  145. }
  146. global[JS_FUNCTION_NAME] = toggleProcesInitFiltr