config-09169f50be11e36c1322fef8e3510d805c097ca521881d6abb40b9a9ef32c9bc.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. var FormValidation = function () {
  2. return {
  3. //main function to initiate the module
  4. init: function () {
  5. // for more info visit the official plugin documentation:
  6. // http://docs.jquery.com/Plugins/Validation
  7. var form1 = $('#form');
  8. var error1 = $('.alert-danger', form1);
  9. var success1 = $('.alert-success', form1);
  10. jQuery.validator.setDefaults({
  11. errorElement: 'span', //default input error message container
  12. errorClass: 'help-block help-block-error', // default input error message classfocusInvalid: false, // do not focus the last invalid input
  13. ignore: "",
  14. invalidHandler: function (event, validator) { //display error alert on form submit
  15. success1.hide();
  16. error1.show();
  17. Metronic.scrollTo(error1, -200);
  18. },
  19. highlight: function (element) { // hightlight error inputs
  20. $(element)
  21. .closest('.form-group').addClass('has-error'); // set error class to the control group
  22. },
  23. unhighlight: function (element) { // revert the change done by hightlight
  24. $(element)
  25. .closest('.form-group').removeClass('has-error'); // set error class to the control group
  26. },
  27. success: function (label) {
  28. label
  29. .closest('.form-group').removeClass('has-error'); // set success class to the control group
  30. },
  31. submitHandler: function (form) {
  32. success1.show();
  33. error1.hide();
  34. form.submit();
  35. }
  36. });
  37. }
  38. };
  39. }();
  40. var FormValidationUsers = function () {
  41. return {
  42. //main function to initiate the module
  43. init: function () {
  44. // for more info visit the official plugin documentation:
  45. // http://docs.jquery.com/Plugins/Validation
  46. var form1 = $('.form-users');
  47. var error1 = $('.alert-error', form1);
  48. var success1 = $('.alert-success', form1);
  49. jQuery.validator.setDefaults({
  50. errorElement: 'span', //default input error message container
  51. errorClass: 'help-inline', // default input error message class
  52. focusInvalid: false, // do not focus the last invalid input
  53. ignore: "",
  54. invalidHandler: function (event, validator) { //display error alert on form submit
  55. success1.hide();
  56. error1.show();
  57. App.scrollTo(error1, -200);
  58. },
  59. highlight: function (element) { // hightlight error inputs
  60. $(element)
  61. .closest('.help-inline').removeClass('ok'); // display OK icon
  62. $(element)
  63. .closest('.control-group').removeClass('success').addClass('error'); // set error class to the control group
  64. },
  65. unhighlight: function (element) { // revert the change dony by hightlight
  66. $(element)
  67. .closest('.control-group').removeClass('error'); // set error class to the control group
  68. },
  69. success: function (label) {
  70. label
  71. .addClass('valid').addClass('help-inline ok') // mark the current input as valid and display OK icon
  72. .closest('.control-group').removeClass('error').addClass('success'); // set success class to the control group
  73. },
  74. submitHandler: function (form) {
  75. success1.show();
  76. error1.hide();
  77. form.submit();
  78. }
  79. });
  80. }
  81. };
  82. }();
  83. var TableAdvanced = function () {
  84. var initTable1 = function () {
  85. var table = $('.tableadvanced');
  86. /* Table tools samples: https://www.datatables.net/release-datatables/extras/TableTools/ */
  87. $.fn.dataTableExt.oStdClasses.sFilterInput = "form-control input-xlarge input-inline";
  88. /* Set tabletools buttons and button container */
  89. var oTable = table.dataTable({
  90. // Internationalisation. For more info refer to http://datatables.net/manual/i18n
  91. "language": {
  92. "aria": {
  93. "sortAscending": ": activate to sort column ascending",
  94. "sortDescending": ": activate to sort column descending"
  95. },
  96. "emptyTable": "No hay informacion en la tabla",
  97. "info": "Mostrando del _START_ al _END_ de _TOTAL_ registros",
  98. "infoEmpty": "No se encontraron coincidencias",
  99. "infoFiltered": "(filtered1 de _MAX_ registros)",
  100. "lengthMenu": "Mostrar _MENU_ registros",
  101. "search": "Buscar:",
  102. "zeroRecords": "No se encontraron coincidencias"
  103. },
  104. "order": [
  105. // [0, 'asc']
  106. ],
  107. "lengthMenu": [
  108. [20, 50, 75, 100, -1],
  109. [20, 50, 75, 100, "Todos"] // change per page values here
  110. ],
  111. // set the initial value
  112. "pageLength": 10,
  113. "dom": "<'row' <'col-md-12'T>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>" // horizobtal scrollable datatable
  114. });
  115. var tableWrapper = $('.tableadvanced_wrapper'); // datatable creates the table wrapper by adding with id {your_table_jd}_wrapper
  116. tableWrapper.find('.dataTables_length select').select2(); // initialize select2 dropdown
  117. }
  118. return {
  119. //main function to initiate the module
  120. init: function () {
  121. if (!jQuery().dataTable) {
  122. return;
  123. }
  124. initTable1();
  125. }
  126. };
  127. }();
  128. var TablePagination = function () {
  129. var initTable3 = function () {
  130. var table = $('.tablePag');
  131. // begin: third table
  132. table.dataTable({
  133. // Internationalisation. For more info refer to http://datatables.net/manual/i18n
  134. "language": {
  135. "aria": {
  136. "sortAscending": ": activate to sort column ascending",
  137. "sortDescending": ": activate to sort column descending"
  138. },
  139. "emptyTable": "No hay informacion en la tabla",
  140. "info": "Mostrando del _START_ al _END_ de _TOTAL_ registros",
  141. "infoEmpty": "No se encontraron coincidencias",
  142. "infoFiltered": "(filtered1 de _MAX_ registros)",
  143. "lengthMenu": "Mostrar _MENU_ registros",
  144. "search": "Buscar:",
  145. "zeroRecords": "No se encontraron coincidencias"
  146. },
  147. "lengthMenu": [
  148. [20, 50, 75, 100, -1],
  149. [20, 50, 75, 100, "Todos"] // change per page values here
  150. ],
  151. // set the initial value
  152. "pageLength": 10,
  153. // Uncomment below line("dom" parameter) to fix the dropdown overflow issue in the datatable cells. The default datatable layout
  154. // setup uses scrollable div(table-scrollable) with overflow:auto to enable vertical scroll(see: assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js).
  155. // So when dropdowns used the scrollable div should be removed.
  156. "dom": "<'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'>r>t<'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>",
  157. "bStateSave": true, // save datatable state(pagination, sort, etc) in cookie.
  158. "order": [
  159. [0, "asc"]
  160. ] // set first column as a default sort by asc
  161. });
  162. var tableWrapper = jQuery('.tablePag_wrapper');
  163. // table.find('.group-checkable').change(function () {
  164. // var set = jQuery(this).attr("data-set");
  165. // var checked = jQuery(this).is(":checked");
  166. // jQuery(set).each(function () {
  167. // if (checked) {
  168. // $(this).attr("checked", true);
  169. // } else {
  170. // $(this).attr("checked", false);
  171. // }
  172. // });
  173. // jQuery.uniform.update(set);
  174. // });
  175. tableWrapper.find('.dataTables_length select').select2(); // initialize select2 dropdown
  176. }
  177. return {
  178. //main function to initiate the module
  179. init: function () {
  180. if (!jQuery().dataTable) {
  181. return;
  182. }
  183. initTable3();
  184. }
  185. };
  186. }();
  187. var handleDateFormat = function () {
  188. var shortDateFormat = 'dd/MM/yyyy';
  189. var longDateFormat = 'dd/MM/yyyy HH:mm:ss';
  190. $(".shortDateFormat").each(function (idx, elem) {
  191. if (jQuery(elem).is(":input")) {
  192. jQuery(elem).val(jQuery.format.date(jQuery(elem).val(), shortDateFormat));
  193. } else {
  194. jQuery(elem).text(jQuery.format.date(jQuery(elem).text(), shortDateFormat));
  195. }
  196. });
  197. $(".longDateFormat").each(function (idx, elem) {
  198. if (jQuery(elem).is(":input")) {
  199. jQuery(elem).val(jQuery.format.date(jQuery(elem).val(), longDateFormat));
  200. } else {
  201. jQuery(elem).text(jQuery.format.date(jQuery(elem).text(), longDateFormat));
  202. }
  203. });
  204. }
  205. var handleDatePickers = function () {
  206. if (jQuery().datepicker) {
  207. $('.date-picker').datepicker({
  208. rtl: Metronic.isRTL(),
  209. orientation: "left",
  210. autoclose: true
  211. });
  212. //$('body').removeClass("modal-open"); // fix bug when inline picker is used in modal
  213. }
  214. /* Workaround to restrict daterange past date select: http://stackoverflow.com/questions/11933173/how-to-restrict-the-selectable-date-ranges-in-bootstrap-datepicker */
  215. }
  216. var handleMultiSelect = function () {
  217. $('.multi-select').multiSelect({
  218. keepOrder: true
  219. });
  220. $('#select-all').click(function(){
  221. $('.multi-select').multiSelect('select_all');
  222. return false;
  223. });
  224. $('#deselect-all').click(function(){
  225. $('.multi-select').multiSelect('deselect_all');
  226. return false;
  227. });
  228. }
  229. var oTable;
  230. var handleInputMasks = function () {
  231. $.extend($().inputmask.defaults, {
  232. 'autounmask': true
  233. });
  234. $(".mask_phone").inputmask("mask", {"mask": "(999) 999-9999"}); //specifying fn & options
  235. $(".mask_number").inputmask({ "mask": "9", "repeat": 10, "greedy": false }); // ~ mask "9" or mask "99" or ... mask "9999999999"
  236. $(".mask_decimal").inputmask('decimal', { rightAlignNumerics: false }); //disables the right alignment of the decimal input
  237. $(".mask_currency").inputmask('999,999,999.99', { numericInput: true });
  238. // $(".mask_rfc").inputmask("mask", {"mask":"9-a{1,3}9{1,3}" });
  239. }
  240. $(document).ready(function() {
  241. if($('.numbersep').get(0) ){
  242. var numbersSeparation = function () {
  243. var numers = $('span.numbers');
  244. return numers.each(function(){
  245. $(this).text( $(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") );
  246. })
  247. }
  248. }
  249. if($('#form').get(0) ){
  250. FormValidation.init();
  251. }
  252. if($('.tableadvanced').get(0) ){
  253. TableAdvanced.init();
  254. }
  255. if($('.tablePag').get(0) ){
  256. TablePagination.init();
  257. }
  258. if($('.longDateFormat').get(0) || $('.shortDateFormat').get(0)){
  259. handleDateFormat();
  260. }
  261. if($('.date-picker').get(0)){
  262. handleDatePickers();
  263. }
  264. if ($('.date-range').get(0) ){
  265. handleDateRangePickers();
  266. }
  267. if ($('.mask_phone').get(0) || $('.mask_number').get(0) || $('.mask_decimal').get(0) || $('.mask_currency').get(0)){
  268. handleInputMasks();
  269. }
  270. if ($('.multi-select').get(0)){
  271. handleMultiSelect();
  272. }
  273. // $('.form_modal').click(function () {
  274. // var $modal = $('#form_modal');
  275. // $modal.modal();
  276. // });
  277. //Override the default confirm dialog by rails
  278. $.rails.allowAction = function(link){
  279. if (link.data("confirm") == undefined){
  280. return true;
  281. }
  282. $.rails.showConfirmationDialog(link);
  283. return false;
  284. }
  285. //User click confirm button
  286. $.rails.confirmed = function(link){
  287. link.data("confirm", null);
  288. link.trigger("click.rails");
  289. }
  290. //Display the confirmation dialog
  291. $.rails.showConfirmationDialog = function(link){
  292. bootbox.dialog({
  293. message: link.data("confirm"),
  294. buttons: {
  295. "Cancelar": {
  296. label: "Cancelar",
  297. className: "btn-default"
  298. },
  299. success: {
  300. label: "OK",
  301. className: "btn-primary",
  302. callback: function() {
  303. $.rails.confirmed(link);
  304. }
  305. }
  306. }
  307. });
  308. }
  309. });