mgComponents.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. function getItemNamespace(elId) {
  2. return jQuery('#' + elId).attr('namespace');
  3. }
  4. function getItemIndex(elId) {
  5. return jQuery('#' + elId).attr('index');
  6. }
  7. function initMassActionsOnDatatables(elId) {
  8. $('#' + elId + ' [data-check-container]').luCheckAll({
  9. onCheck: function (container, counter) {
  10. var massActions = container.find('.lu-t-c__mass-actions');
  11. massActions.find('.lu-value').html(counter);
  12. if (counter > 0) {
  13. massActions.addClass('is-open');
  14. } else {
  15. massActions.removeClass('is-open');
  16. }
  17. }
  18. });
  19. }
  20. function collectTableMassActionsData(elId) {
  21. var colectedData = {};
  22. $('#' + elId + ' [data-check-container] tbody input:checkbox.table-mass-action-check:enabled:checked')
  23. .each(function (index, value) {
  24. colectedData[index] = $(this).val();
  25. });
  26. return colectedData;
  27. }
  28. function uncheckSelectAllCheck(elId) {
  29. closeAllSelectMassActions();
  30. }
  31. function closeAllSelectMassActions() {
  32. $('.lu-t-c__mass-actions').removeClass('is-open');
  33. $('.table-mass-action-check').prop('checked', false);
  34. $('thead input:checkbox:enabled').prop('checked', false);
  35. }
  36. function initTooltipsForDatatables(elId) {
  37. $('#' + elId + ' [data-toggle="lu-tooltip"], [data-tooltip]').luTooltip({});
  38. }
  39. function initModalSelects() {
  40. $('#mgModalContainer select:not(.ajax)').each(function () {
  41. if ($(this).attr('bi-event-change')) {
  42. var biEventAction = $(this).attr('bi-event-change');
  43. $(this).selectize({
  44. plugins: ['remove_button'],
  45. onItemAdd: function (value) {
  46. if (biEventAction && typeof mgPageControler[biEventAction] === "function") {
  47. setTimeout(function () {
  48. mgPageControler[biEventAction]();
  49. }, 500);
  50. } else if (biEventAction && typeof mgPageControler.vueLoader[biEventAction] === "function") {
  51. setTimeout(function () {
  52. mgPageControler.vueLoader[biEventAction]();
  53. }, 500);
  54. } else if (biEventAction && typeof window[biEventAction] === "function") {
  55. setTimeout(function () {
  56. window[biEventAction]();
  57. }, 500);
  58. }
  59. }
  60. });
  61. } else {
  62. $(this).luSelect({});
  63. }
  64. });
  65. }
  66. function initModalTooltips() {
  67. $('#mgModalContainer [data-toggle="lu-tooltip"], [data-tooltip]').luTooltip({});
  68. }
  69. function mgFormControler(targetFormId) {
  70. this.fields = null;
  71. this.data = {};
  72. this.formId = targetFormId;
  73. this.loadFormFields = function () {
  74. var that = this;
  75. jQuery('#' + this.formId).find('input,select,textarea').each(function () {
  76. if (!jQuery(this).is(':disabled')) {
  77. var name = jQuery(this).attr('name');
  78. var value = null;
  79. if (name !== undefined) {
  80. var type = jQuery(this).attr('type');
  81. var regExp = /([a-zA-Z_0-9]+)\[([a-zA-Z_0-9]+)\]/g;
  82. var regExpLg = /([a-zA-Z_0-9]+)\[([a-zA-Z_0-9]+)\]\[([a-zA-Z_0-9]+)\]/g;
  83. if (type === 'checkbox') {
  84. var value = 'off';
  85. jQuery('#' + that.formId).find('input[name="' + name + '"]').each(function () {
  86. if (jQuery(this).is(':checked')) {
  87. value = jQuery(this).val();
  88. }
  89. });
  90. } else if (type === 'radio') {
  91. if (jQuery(this).is(':checked')) {
  92. var value = jQuery(this).val();
  93. }
  94. } else {
  95. var value = jQuery(this).val();
  96. }
  97. if (value !== null) {
  98. if (result = regExpLg.exec(name)) {
  99. if (that.data[result[1]] === undefined) {
  100. that.data[result[1]] = {};
  101. }
  102. if (that.data[result[1]][result[2]] === undefined) {
  103. that.data[result[1]][result[2]] = {};
  104. }
  105. that.data[result[1]][result[2]][result[3]] = value;
  106. } else if (result = regExp.exec(name)) {
  107. if (that.data[result[1]] === undefined) {
  108. that.data[result[1]] = {};
  109. }
  110. that.data[result[1]][result[2]] = value;
  111. } else {
  112. that.data[name] = value;
  113. }
  114. }
  115. }
  116. }
  117. });
  118. };
  119. this.getFieldsData = function () {
  120. this.loadFormFields();
  121. return {formData: this.data};
  122. };
  123. this.updateFieldsValidationMessages = function (errorsList) {
  124. jQuery('#' + this.formId).find('input,select,textarea').each(function () {
  125. if (!jQuery(this).is(':disabled')) {
  126. var name = jQuery(this).attr('name');
  127. if (name !== undefined && errorsList[name] !== undefined)
  128. {
  129. if (!jQuery(this).parents('.lu-form-group').first().hasClass('lu-is-error')) {
  130. jQuery(this).parents('.lu-form-group').first().addClass('lu-is-error');
  131. }
  132. var messagePlaceholder = jQuery(this).parents('.lu-form-group').first().children('.lu-form-feedback');
  133. if (jQuery(messagePlaceholder).length > 0)
  134. {
  135. jQuery(messagePlaceholder).html(errorsList[name].slice(-1)[0]);
  136. if (jQuery(messagePlaceholder).attr('hidden')) {
  137. jQuery(messagePlaceholder).removeAttr('hidden');
  138. }
  139. }
  140. } else if (name !== undefined) {
  141. if (jQuery(this).parents('.lu-form-group').first().hasClass('lu-is-error')) {
  142. jQuery(this).parents('.lu-form-group').first().removeClass('lu-is-error');
  143. }
  144. var messagePlaceholder = jQuery(this).next('.lu-form-feedback');
  145. if (jQuery(messagePlaceholder).length > 0) {
  146. jQuery(messagePlaceholder).html('');
  147. if (!jQuery(messagePlaceholder).attr('hidden')) {
  148. jQuery(messagePlaceholder).attr('hidden', 'hidden');
  149. }
  150. }
  151. }
  152. }
  153. });
  154. };
  155. }
  156. ;
  157. //Sortable
  158. function tldCategoriesSortableController()
  159. {
  160. var helperHeight = 0;
  161. //Add sortable for parent categories
  162. if (!$('#groupList.vSortable').hasClass('ui-sortable'))
  163. {
  164. $("#groupList.vSortable").sortable(
  165. {
  166. items: "li:not(.lu-nav--sub li, .sortable-disabled)",
  167. start: function (event, ui)
  168. {
  169. $(ui.item).find("ul").hide();
  170. $("#groupList").attr("isBeingSorted", "true");
  171. },
  172. stop: function (event, ui)
  173. {
  174. var order = [];
  175. $("#groupList .nav__item").each(function (index, element)
  176. {
  177. if ($(element).hasClass("ui-sortable-placeholder"))
  178. {
  179. return;
  180. }
  181. var catId = $(element).attr("actionid");
  182. order.push(catId);
  183. });
  184. mgPageControler.vueLoader.updateSorting(order, 'addCategoryForm', 'ModulesGarden_ProxmoxAddon_App_UI_Widget_DoeTldConfigComponents_CategoryForms_AddCategoryForm');
  185. $(ui.item).css("height", helperHeight);
  186. $(ui.item).find("a").css("height", 32);
  187. $(ui.item).find("ul").show();
  188. },
  189. sort: function (event, ui)
  190. {
  191. $("#groupList").sortable("refreshPositions");
  192. },
  193. helper: function (event, li)
  194. {
  195. helperHeight = $(li).css("height");
  196. $(li).css("height", 32);
  197. return li;
  198. },
  199. });
  200. }
  201. //Add sortable for children - this has to be refreshed per catego content load
  202. $("#groupList .nav--sub").sortable(
  203. {
  204. stop: function (event, ui)
  205. {
  206. var order = [];
  207. $(this).find(".nav__item").each(function (index, element)
  208. {
  209. if ($(element).hasClass("ui-sortable-placeholder"))
  210. {
  211. return;
  212. }
  213. var catId = $(element).attr("actionid");
  214. order.push(catId);
  215. });
  216. mgPageControler.vueLoader.updateSorting(order, 'addCategoryForm', 'ModulesGarden_ProxmoxAddon_App_UI_Widget_DoeTldConfigComponents_CategoryForms_AddCategoryForm');
  217. },
  218. });
  219. //Add Sortable on table
  220. $('#itemContentContainer tbody.vSortable').sortable(
  221. {
  222. stop: function (event, ui)
  223. {
  224. var order = [];
  225. $("#itemContentContainer tbody").find("tr").each(function (index, element)
  226. {
  227. if ($(element).hasClass("ui-sortable-placeholder"))
  228. {
  229. return;
  230. }
  231. var catId = $(element).attr("actionid");
  232. order.push(catId);
  233. });
  234. mgPageControler.vueLoader.updateSorting(order, 'assignTldForm', 'ModulesGarden_ProxmoxAddon_App_UI_Widget_DoeTldConfigComponents_CategoryForms_AssignTldForm');
  235. },
  236. helper: function (e, tr)
  237. {
  238. var $originals = tr.children();
  239. var $helper = tr.clone();
  240. $helper.children().each(function (index)
  241. {
  242. $(this).width($originals.eq(index).width() + 100);
  243. });
  244. return $helper;
  245. },
  246. });
  247. }
  248. // CUSTOM FUNCTIONS
  249. //this is example custom action, use it for non-ajax actions
  250. function custAction1(vueControler, params, event) {
  251. console.log('custAction1', vueControler, params, event);
  252. }
  253. //this is example custom action, use it for ajax actions
  254. function custAction2(vueControler, params, event) {
  255. console.log('custAction2', vueControler, params, event);
  256. }
  257. function mgEmptyToPause(name, row) {
  258. if (!row[name] || row[name] === '') {
  259. return '-';
  260. } else {
  261. return row[name];
  262. }
  263. }
  264. function newCall(data) {
  265. console.log(data);
  266. }
  267. function buildOptionTag(text, value, selected, disabled) {
  268. var option = document.createElement("option");
  269. option.text = text;
  270. option.value = value;
  271. if (selected) {
  272. option.setAttribute('selected', 'selected');
  273. }
  274. if (disabled) {
  275. option.setAttribute('disabled', 'disabled');
  276. }
  277. return option;
  278. }