TableAjax.php.procesInitFiltr.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 _viewDropdown_item_infoLink(id, label) {
  16. var h = p5Utils__convertToHtml;
  17. var viewProcessLink = "procesy5.php?task=PROCES_VIEW_LIST&id_proces=" + id + "&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1";
  18. return h('i', {
  19. className: "glyphicon glyphicon-info-sign",
  20. style: "color:#aaa; cursor:help; vertical-align:middle",
  21. title: "Przeglądaj proces {" + id + "} " + label,
  22. onclick: "window.open('" + viewProcessLink + "');return false;",
  23. onmouseover: "this.style.color = '#337AB7'", onmouseout: "this.style.color = '#aaa'"
  24. });
  25. }
  26. function _viewDropdown_item_setPermsLink(id, label, selected) {
  27. var h = p5Utils__convertToHtml;
  28. return h('button', {
  29. className: "btn btn-link" + (selected ? " disabled" : ""),
  30. style: "padding:0 3px",
  31. title: "Uruchom filtr procesu {" + id + "}"
  32. }, [
  33. " {" + id + "} " + label,
  34. ]);
  35. }
  36. function _viewDropdown_listItem(id, label, selected, deepLevel, showArrowIcon) { // showArrowIcon: if process type === goto_and_return
  37. var h = p5Utils__convertToHtml;
  38. var marginLeft = 20 * (deepLevel || 0);
  39. return h('li', {
  40. style: "white-space:nowrap; overflow:hidden; max-width:500px; /* text-overflow:ellipsis; */",
  41. onmouseover: "this.style.backgroundColor='#f5f5f5'", onmouseout: "this.style.backgroundColor='#fff'",
  42. }, [
  43. h('form', { className: "form-inline", method: "post", action: "", style: "padding:3px 20px; margin-left:" + marginLeft + "px" }, [
  44. h('input', { type: "hidden", name: "_rootPostTask", value: "SetPermsByProces" }),
  45. h('input', { type: "hidden", name: "id_proces", value: id }),
  46. (showArrowIcon)
  47. ? h('i', { className: "glyphicon glyphicon-arrow-right", style: "color:#aaa; vertical-align:middle; margin-right:2px" })
  48. : null,
  49. _viewDropdown_item_infoLink(id, label),
  50. _viewDropdown_item_setPermsLink(id, label, selected),
  51. ]),
  52. ]);
  53. }
  54. function toggleProcesInitFiltr(n) {
  55. var $n = jQuery(n);
  56. var $ul = $n.next();
  57. if ($n.data('fetched')) return false;
  58. function parseProcesInitData(pInitData) {
  59. return (!pInitData || !pInitData.mapTree)
  60. ? '<li><a href="#">' + "Brak danych" + '</a></li>'
  61. : Object.keys(pInitData.mapTree).map(function (vInitId) {
  62. var gotoIds = pInitData.mapTree[vInitId];
  63. var sel = (pInitData.pInitListSelected && pInitData.pInitListSelected == vInitId);
  64. return [
  65. _viewDropdown_listItem(vInitId, pInitData.pInitList[vInitId], sel, deepLvl = 0, showArrowIcon = false)
  66. ].concat(
  67. (!gotoIds) ? null : Object.keys(gotoIds).map(function (gotoId) {
  68. var gotoLvl2Ids = gotoIds[gotoId];
  69. var sel = (pInitData.pInitListSelected && pInitData.pInitListSelected == vInitId);
  70. return [
  71. _viewDropdown_listItem(gotoId, pInitData.pInitList[gotoId], sel, deepLvl = 1, showArrowIcon = true)
  72. ].concat(
  73. (!gotoLvl2Ids) ? null : Object.keys(gotoLvl2Ids).map(function (gotoLvl2Id) {
  74. // var vBool = gotoLvl2Ids[gotoLvl2Id];
  75. return _viewDropdown_listItem(gotoLvl2Id, pInitData.pInitList[gotoLvl2Id], sel, deepLvl = 2, showArrowIcon = true);
  76. }).join("\n")
  77. ).join("\n");
  78. }).join("\n")
  79. ).join("\n");
  80. }).join("\n")
  81. ;
  82. }
  83. jQuery.ajax({
  84. data: null,
  85. dataType: 'json',
  86. type: "GET",
  87. async: true,
  88. url: URL_GET_PROCES_INIT_FILTR
  89. })
  90. .always(function(data, textStatus, jqXHR) {
  91. var type = data.type || null,
  92. msg = data.msg || "Error",
  93. pInitData = data.pInitData || null;
  94. if (type) {
  95. if ('success' == type) {
  96. $ul.html(parseProcesInitData(pInitData));
  97. } else if ('error' == type) {
  98. $ul.html('<li><a href="#">' + msg + '</a></li>');
  99. } else {
  100. $ul.html('<li><a href="#">Wystapił błąd podczas pobierania listy procesów</a></li>');
  101. }
  102. } else {
  103. $ul.html('<li><a href="#">Wystapił błąd podczas pobierania listy procesów</a></li>');
  104. }
  105. $n.data('fetched', true);
  106. });
  107. return false;
  108. }
  109. global[JS_FUNCTION_NAME] = toggleProcesInitFiltr