webApp.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. (function ($) {
  2. $.fn.webApp_grid = function (options) {
  3. var settings = $.extend({
  4. height : '100%',
  5. autowidth : true,
  6. pager : true,
  7. toppager : true,
  8. subGrid : false,
  9. subGridUrl : '',
  10. subGridModel : [],
  11. actionNavOptions: null
  12. }, options);
  13. var grid = this;
  14. this.jqGrid({
  15. url : settings.jsonUrl,
  16. datatype : "json",
  17. height : settings.height,
  18. autowidth : settings.autowidth,
  19. colModel : settings.colModel,
  20. rowNum : settings.rowsPerPage,
  21. rowList : [30, 50, 100],
  22. loadonce : false,
  23. mtype : "POST",
  24. pager : settings.pager,
  25. toppager : settings.toppager,
  26. sortname : settings.sortName,
  27. sortorder : settings.sortOrder,
  28. viewrecords : true,
  29. multiselect : true,
  30. guiStyle : "bootstrap",
  31. iconSet : "fontAwesome",
  32. subGrid : settings.subGrid,
  33. subGridRowExpanded: function (subgrid_id, row_id) {
  34. var sg_tableID = subgrid_id + "_t";
  35. jQuery("#" + subgrid_id).html("<table id='" + sg_tableID + "' class'scroll'></table>");
  36. jQuery("#" + sg_tableID).jqGrid({
  37. url : settings.subGridUrl + '?id=' + encodeURIComponent(row_id),
  38. datatype : "json",
  39. mtype : 'POST',
  40. colModel : settings.subGridModel,
  41. height : '100%',
  42. autowidth: true,
  43. rowNum : 10,
  44. idPrefix : "s_" + row_id + "_"
  45. });
  46. },
  47. actionsNavOptions : settings.actionNavOptions
  48. });
  49. if (settings.filterToolbar)
  50. this.jqGrid('filterToolbar', {stringResult: false, searchOnEnter: true, autosearch: true});
  51. $(window).on("resize", function () {
  52. var newWidth = grid.closest(".ui-jqgrid").parent().width();
  53. grid.jqGrid("setGridWidth", newWidth, true);
  54. });
  55. return this;
  56. };
  57. $.webApp_modal = function (message, title, buttons, size) {
  58. if (title == null)
  59. title = 'Mensaje';
  60. if (buttons == null)
  61. buttons = [{text: 'Aceptar', close: true}];
  62. var dialog = $("#myModal");
  63. var htmlButtons = '';
  64. var n = 0;
  65. buttons.forEach(function (b) {
  66. if (!('close' in b))
  67. b.close = true;
  68. htmlButtons += '<button type="button" class="btn ' + (n == 0 ? 'btn-primary' : 'btn-secondary') + '"' + (b.close ? ' data-dismiss="modal"' : '') + ' id="modal-button-' + n + '">' + b.text + '</button>';
  69. n++;
  70. });
  71. if (dialog.length == 0) {
  72. var sizeHtml;
  73. if (size == 'L')
  74. sizeHtml = ' modal-lg';
  75. else if (size == 'S')
  76. sizeHtml = ' modal-sm';
  77. else
  78. sizeHtml = '';
  79. var html =
  80. '<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">' +
  81. '<div class="modal-dialog' + sizeHtml + '" role="document">' +
  82. '<div class="modal-content">' +
  83. '<div class="modal-header">' +
  84. '<h5 class="modal-title">' + title + '</h5>' +
  85. '</div>' +
  86. '<div class="modal-body">' + message + '</div>' +
  87. '<div class="modal-footer">' + htmlButtons + '</div>' +
  88. '</div>' +
  89. '</div>' +
  90. '</div>';
  91. $("body").append(html);
  92. dialog = $("#myModal");
  93. } else {
  94. $(".modal-title", dialog).html(title);
  95. $(".modal-body", dialog).html(message);
  96. $(".modal-footer", dialog).html(htmlButtons);
  97. $(".modal-dialog", dialog).removeClass('modal-lg');
  98. $(".modal-dialog", dialog).removeClass('modal-sm');
  99. if (size == 'L')
  100. $(".modal-dialog", dialog).addClass('modal-lg');
  101. else if (size == 'S')
  102. $(".modal-dialog", dialog).addClass('modal-sm');
  103. }
  104. if (htmlButtons == '')
  105. $(".modal-footer", dialog).hide();
  106. else
  107. $(".modal-footer", dialog).show();
  108. n = 0;
  109. buttons.forEach(function (b) {
  110. if (b.eventFunction)
  111. $("#modal-button-" + n).click(b.eventFunction);
  112. n++;
  113. });
  114. dialog.modal();
  115. };
  116. }(jQuery));