config.js 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696
  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.$.com/Plugins/Validation
  7. var form1 = $('#form');
  8. var error1 = $('.alert-danger', form1);
  9. var success1 = $('.alert-success', form1);
  10. $.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. App.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.$.com/Plugins/Validation
  46. var form1 = $('.form-users');
  47. var error1 = $('.alert-error', form1);
  48. var success1 = $('.alert-success', form1);
  49. $.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. var filter = $('#filter').val();
  87. var buscar_ = { };
  88. var page_ = 0;
  89. /* Table tools samples: https://www.datatables.net/release-datatables/extras/TableTools/ */
  90. $.fn.dataTableExt.oStdClasses.sFilterInput = "form-control input-medium input-inline";
  91. /* Set tabletools buttons and button container */
  92. if(filter != ""){ buscar_ = { search: filter }; }
  93. if( $('#current_page').length > 0 ){ page_ = ($('#current_page').val() - 1) * 20;}
  94. var oTable = table.dataTable({
  95. // Internationalisation. For more info refer to http://datatables.net/manual/i18n
  96. "language": {
  97. "aria": {
  98. "sortAscending": ": activate to sort column ascending",
  99. "sortDescending": ": activate to sort column descending"
  100. },
  101. "emptyTable": "No hay informacion en la tabla",
  102. "info": "Mostrando del _START_ al _END_ de _TOTAL_ registros",
  103. "infoEmpty": "No se encontraron coincidencias",
  104. "infoFiltered": "(filtrado un total de _MAX_ registros)",
  105. "lengthMenu": "Mostrar _MENU_ registros",
  106. "search": "Buscar:",
  107. "zeroRecords": "No se encontraron coincidencias",
  108. "paginate": {
  109. "sPrevious": "Ant",
  110. "sNext": "Sig"
  111. }
  112. },
  113. "order": [
  114. // [0, 'asc']
  115. ],
  116. "lengthMenu": [
  117. [20, 50, 75, 100, -1],
  118. [20, 50, 75, 100, "Todos"] // change per page values here
  119. ],
  120. "search": buscar_,
  121. // set the initial value
  122. "pageLength": 20,
  123. "iDisplayStart": page_,
  124. "dom": "<'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
  125. "fnDrawCallback": function( oSettings ) {
  126. $('a.filtros').on( 'click', function (e) {
  127. e.preventDefault();
  128. var url_ = $(this).attr('href');
  129. url_ += '?filter=' + $('#filter').val();
  130. url_ += '&current_page=' + $('#current_page').val();
  131. console.log(url_);
  132. window.location.href = url_;
  133. });
  134. $('a.filtros2').on( 'click', function (e) {
  135. e.preventDefault();
  136. var url_ = $(this).attr('href');
  137. url_ += '&filter=' + $('#filter').val();
  138. url_ += '&current_page=' + $('#current_page').val();
  139. console.log(url_);
  140. window.location.href = url_;
  141. });
  142. }
  143. });
  144. var tableWrapper = $('.tableadvanced_wrapper'); // datatable creates the table wrapper by adding with id {your_table_jd}_wrapper
  145. tableWrapper.find('.dataTables_length select').select2(); // initialize select2 dropdown
  146. if( $('#current_page').length > 0 ){
  147. $('.tableadvanced').on( 'page.dt', function () {
  148. var oSettings = oTable.fnSettings();
  149. var page = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1;
  150. $('#current_page').val(page);
  151. });
  152. }
  153. }
  154. return {
  155. //main function to initiate the module
  156. init: function () {
  157. if (!$().dataTable) {
  158. return;
  159. }
  160. initTable1();
  161. }
  162. };
  163. }();
  164. var TableAdvancedSingleSelection = function () {
  165. var initTable1 = function () {
  166. var table = $('.tableadvancedSingleSelection');
  167. $.fn.dataTableExt.oStdClasses.sFilterInput = "form-control input-medium input-inline";
  168. var oTable = table.DataTable({
  169. "language": {
  170. "aria": {
  171. "sortAscending": ": activate to sort column ascending",
  172. "sortDescending": ": activate to sort column descending"
  173. },
  174. "emptyTable": "No hay informacion en la tabla",
  175. "info": "Mostrando del _START_ al _END_ de _TOTAL_ registros",
  176. "infoEmpty": "No se encontraron coincidencias",
  177. "infoFiltered": "(filtrado un total de _MAX_ registros)",
  178. "lengthMenu": "Mostrar _MENU_ registros",
  179. "search": "Buscar:",
  180. "zeroRecords": "No se encontraron coincidencias",
  181. "paginate": {
  182. "sPrevious": "Ant",
  183. "sNext": "Sig"
  184. }
  185. },
  186. "order": [],
  187. "lengthMenu": [
  188. [20, 50, 75, 100, -1],
  189. [20, 50, 75, 100, "Todos"]
  190. ],
  191. "pageLength": 20,
  192. "tableTools": {
  193. "sRowSelect": "single"
  194. },
  195. "dom": "<'row'<'col-md-6 col-sm-12 hidden'T><'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>>"
  196. });
  197. var tableWrapper = $('.tableadvanced_wrapper');
  198. tableWrapper.find('.dataTables_length select').select2();
  199. }
  200. return {
  201. init: function () {
  202. if (!$().dataTable) {
  203. return;
  204. }
  205. initTable1();
  206. }
  207. };
  208. }();
  209. var TableWithCheckbox = function () {
  210. //var rows_selected = [];
  211. var initTableCheckbox = function () {
  212. var table = $('.tableWithCheckbox');
  213. /* Table tools samples: https://www.datatables.net/release-datatables/extras/TableTools/ */
  214. $.fn.dataTableExt.oStdClasses.sFilterInput = "form-control input-xlarge input-inline";
  215. /* Set tabletools buttons and button container */
  216. var oTable = table.dataTable({
  217. // Internationalisation. For more info refer to http://datatables.net/manual/i18n
  218. 'columnDefs': [{
  219. 'targets': 0,
  220. 'searchable':false,
  221. 'orderable':false,
  222. 'className': 'dt-body-center',
  223. 'render': function (data, type, full, meta) {
  224. return '<input type="checkbox" name="id[]">';
  225. }
  226. }],
  227. "language": {
  228. "aria": {
  229. "sortAscending": ": activate to sort column ascending",
  230. "sortDescending": ": activate to sort column descending"
  231. },
  232. "emptyTable": "No hay informacion en la tabla",
  233. "info": "Mostrando del _START_ al _END_ de _TOTAL_ registros",
  234. "infoEmpty": "No se encontraron coincidencias",
  235. "infoFiltered": "(filtrado un total de _MAX_ registros)",
  236. "lengthMenu": "Mostrar _MENU_ registros",
  237. "search": "Buscar:",
  238. "zeroRecords": "No se encontraron coincidencias",
  239. "paginate": {
  240. "sPrevious": "Ant",
  241. "sNext": "Sig"
  242. }
  243. },
  244. 'order': [3, 'asc'],
  245. "rowCallback": function(row, data, dataIndex){
  246. // Get row ID
  247. var rowId = data[0];
  248. // If row ID is in the list of selected row IDs
  249. if($.inArray(rowId, rows_selected) !== -1){
  250. $(row).find('input[type="checkbox"]').prop('checked', true);
  251. $(row).addClass('selected');
  252. }
  253. },
  254. "lengthMenu": [
  255. [20, 50, 75, 100, -1],
  256. [20, 50, 75, 100, "Todos"] // change per page values here
  257. ],
  258. // set the initial value
  259. "pageLength": -1,
  260. "dom": "<'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
  261. });
  262. var tableWrapper = $('.tableadvanced_wrapper'); // datatable creates the table wrapper by adding with id {your_table_jd}_wrapper
  263. tableWrapper.find('.dataTables_length select').select2(); // initialize select2 dropdown
  264. var table = $('.tableWithCheckbox').DataTable();
  265. // Handle click on checkbox
  266. $('.tableWithCheckbox tbody').on('click', 'input[type="checkbox"]', function(e){
  267. var $row = $(this).closest('tr');
  268. // Get row data
  269. var data = table.row($row).data();
  270. // Get row ID
  271. // var rowId = data[0];
  272. var rowId = $row.attr('id').substring($row.attr('id').indexOf('_') + 1, $row.attr('id').length);
  273. // Determine whether row ID is in the list of selected row IDs
  274. var index = $.inArray(rowId, rows_selected);
  275. // If checkbox is checked and row ID is not in list of selected row IDs
  276. if(this.checked && index === -1){
  277. rows_selected.push(rowId);
  278. // Otherwise, if checkbox is not checked and row ID is in list of selected row IDs
  279. } else if (!this.checked && index !== -1){
  280. rows_selected.splice(index, 1);
  281. }
  282. if(this.checked){
  283. $row.addClass('selected');
  284. //$row.css('background-color', '#34495E');
  285. } else {
  286. //$row.css('background-color', '#F9F9F9');
  287. $row.removeClass('selected');
  288. }
  289. // Update state of "Select all" control
  290. updateDataTableSelectAllCtrl(table);
  291. // Prevent click event from propagating to parent
  292. e.stopPropagation();
  293. });
  294. // Handle click on table cells with checkboxes
  295. $('.tableWithCheckbox').on('click', 'tbody td, thead th:first-child', function(e){
  296. $(this).parent().find('input[type="checkbox"]').trigger('click');
  297. });
  298. // Handle click on "Select all" control
  299. $('thead input[name="select_all"]', table.table().container()).on('click', function(e){
  300. if(this.checked){
  301. $('.tableWithCheckbox tbody input[type="checkbox"]:not(:checked)').trigger('click');
  302. } else {
  303. $('.tableWithCheckbox tbody input[type="checkbox"]:checked').trigger('click');
  304. }
  305. // Prevent click event from propagating to parent
  306. e.stopPropagation();
  307. });
  308. // Handle table draw event
  309. table.on('draw', function(){
  310. // Update state of "Select all" control
  311. updateDataTableSelectAllCtrl(table);
  312. });
  313. function updateDataTableSelectAllCtrl(table){
  314. var $table = table.table().node();
  315. var $chkbox_all = $('tbody input[type="checkbox"]', $table);
  316. var $chkbox_checked = $('tbody input[type="checkbox"]:checked', $table);
  317. var chkbox_select_all = $('thead input[name="select_all"]', $table).get(0);
  318. // If none of the checkboxes are checked
  319. if($chkbox_checked.length === 0){
  320. chkbox_select_all.checked = false;
  321. if('indeterminate' in chkbox_select_all){
  322. chkbox_select_all.indeterminate = false;
  323. }
  324. // If all of the checkboxes are checked
  325. } else if ($chkbox_checked.length === $chkbox_all.length){
  326. chkbox_select_all.checked = true;
  327. if('indeterminate' in chkbox_select_all){
  328. chkbox_select_all.indeterminate = false;
  329. }
  330. // If some of the checkboxes are checked
  331. } else {
  332. chkbox_select_all.checked = true;
  333. if('indeterminate' in chkbox_select_all){
  334. chkbox_select_all.indeterminate = true;
  335. }
  336. }
  337. }
  338. }
  339. return {
  340. //main function to initiate the module
  341. init: function () {
  342. if (!$().dataTable) {
  343. return;
  344. }
  345. initTableCheckbox();
  346. }
  347. };
  348. }();
  349. var tableWithCheckboxAjax = function () {
  350. //var arrayForRows = [];
  351. var initTableCheckboxAjax = function (tableClass, columns, order, extraParams, arrayForRows) {
  352. var table = $(tableClass);
  353. /* Table tools samples: https://www.datatables.net/release-datatables/extras/TableTools/ */
  354. $.fn.dataTableExt.oStdClasses.sFilterInput = "form-control input-xlarge input-inline";
  355. /* Set tabletools buttons and button container */
  356. var oTable = table.dataTable({
  357. "processing": true,
  358. "serverSide": true,
  359. "ajax": {
  360. "url": $(tableClass).data('source'),
  361. "data": function ( d ) {
  362. d.busqueda = $(tableClass).closest('.dataTables_wrapper').find('input[type="search"]').val();
  363. // son los parametros custom de cada tabla, se envia el obj.
  364. for(var param in extraParams){
  365. d[param] = extraParams[param];
  366. }
  367. }
  368. },
  369. "drawCallback": function( settings ) {
  370. arrayForRows.length = 0;
  371. },
  372. 'columns': columns,
  373. 'columnDefs': [{
  374. 'targets': 0,
  375. 'searchable':false,
  376. 'orderable':false,
  377. 'className': 'dt-body-center',
  378. 'render': function (data, type, full, meta) {
  379. return '<input type="checkbox" name="id[]">';
  380. }
  381. }],
  382. "language": {
  383. "aria": {
  384. "sortAscending": ": activate to sort column ascending",
  385. "sortDescending": ": activate to sort column descending"
  386. },
  387. "sProcessing": "Cargando...",
  388. "emptyTable": "No hay informacion en la tabla",
  389. "info": "Mostrando del _START_ al _END_ de _TOTAL_ registros",
  390. "infoEmpty": "No se encontraron coincidencias",
  391. "infoFiltered": "(filtrado un total de _MAX_ registros)",
  392. "lengthMenu": "Mostrar _MENU_ registros",
  393. "search": "Buscar:",
  394. "zeroRecords": "No se encontraron coincidencias",
  395. "paginate": {
  396. "sPrevious": "Ant",
  397. "sNext": "Sig"
  398. }
  399. },
  400. 'order': [order, 'asc'],
  401. "rowCallback": function(row, data, dataIndex){
  402. // Get row ID
  403. var rowId = data[0];
  404. // If row ID is in the list of selected row IDs
  405. if($.inArray(rowId, arrayForRows) !== -1){
  406. $(row).find('input[type="checkbox"]').prop('checked', true);
  407. $(row).addClass('selected');
  408. }
  409. },
  410. "lengthMenu": [
  411. [20, 50, 75, 100, -1],
  412. [20, 50, 75, 100, "Todos"] // change per page values here
  413. ],
  414. // set the initial value
  415. "pageLength": 20,
  416. "dom": "<'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
  417. });
  418. var tableWrapper = $('.tableadvanced_wrapper'); // datatable creates the table wrapper by adding with id {your_table_jd}_wrapper
  419. tableWrapper.find('.dataTables_length select').select2(); // initialize select2 dropdown
  420. var table = $(tableClass).DataTable();
  421. // Handle click on checkbox
  422. $(tableClass + ' tbody').on('click', 'input[type="checkbox"]', function(e){
  423. var $row = $(this).closest('tr');
  424. // Get row data
  425. var data = table.row($row).data();
  426. // Get row ID
  427. // var rowId = data[0];
  428. var rowId = $row.attr('id').substring($row.attr('id').indexOf('_') + 1, $row.attr('id').length);
  429. // Determine whether row ID is in the list of selected row IDs
  430. var index = $.inArray(rowId, arrayForRows);
  431. // If checkbox is checked and row ID is not in list of selected row IDs
  432. if(this.checked && index === -1){
  433. arrayForRows.push(rowId);
  434. // Otherwise, if checkbox is not checked and row ID is in list of selected row IDs
  435. } else if (!this.checked && index !== -1){
  436. arrayForRows.splice(index, 1);
  437. }
  438. if(this.checked){
  439. $row.addClass('selected');
  440. //$row.css('background-color', '#34495E');
  441. } else {
  442. //$row.css('background-color', '#F9F9F9');
  443. $row.removeClass('selected');
  444. }
  445. // Update state of "Select all" control
  446. updateDataTableSelectAllCtrl(table);
  447. // Prevent click event from propagating to parent
  448. e.stopPropagation();
  449. });
  450. // Handle click on table cells with checkboxes
  451. $(tableClass).on('click', 'tbody td, thead th:first-child', function(e){
  452. $(this).parent().find('input[type="checkbox"]').trigger('click');
  453. });
  454. // Handle click on "Select all" control
  455. $('thead input[name="select_all"]', table.table().container()).on('click', function(e){
  456. if(this.checked){
  457. $(tableClass + ' tbody input[type="checkbox"]:not(:checked)').trigger('click');
  458. } else {
  459. $(tableClass + ' tbody input[type="checkbox"]:checked').trigger('click');
  460. }
  461. // Prevent click event from propagating to parent
  462. e.stopPropagation();
  463. });
  464. // Handle table draw event
  465. table.on('draw', function(){
  466. // Update state of "Select all" control
  467. updateDataTableSelectAllCtrl(table);
  468. });
  469. function updateDataTableSelectAllCtrl(table){
  470. var $table = table.table().node();
  471. var $chkbox_all = $('tbody input[type="checkbox"]', $table);
  472. var $chkbox_checked = $('tbody input[type="checkbox"]:checked', $table);
  473. var chkbox_select_all = $('thead input[name="select_all"]', $table).get(0);
  474. // If none of the checkboxes are checked
  475. if($chkbox_checked.length === 0){
  476. chkbox_select_all.checked = false;
  477. if('indeterminate' in chkbox_select_all){
  478. chkbox_select_all.indeterminate = false;
  479. }
  480. // If all of the checkboxes are checked
  481. } else if ($chkbox_checked.length === $chkbox_all.length){
  482. chkbox_select_all.checked = true;
  483. if('indeterminate' in chkbox_select_all){
  484. chkbox_select_all.indeterminate = false;
  485. }
  486. // If some of the checkboxes are checked
  487. } else {
  488. chkbox_select_all.checked = true;
  489. if('indeterminate' in chkbox_select_all){
  490. chkbox_select_all.indeterminate = true;
  491. }
  492. }
  493. }
  494. }
  495. return {
  496. //main function to initiate the module
  497. init: function (tableClass, columns, order, data, arrayForRows) {
  498. if (!$().dataTable) {
  499. return;
  500. }
  501. initTableCheckboxAjax(tableClass, columns, order, data, arrayForRows);
  502. }
  503. };
  504. }();
  505. var TablePagination = function () {
  506. var initTable3 = function () {
  507. var table = $('.tablePag');
  508. // begin: third table
  509. table.dataTable({
  510. // Internationalisation. For more info refer to http://datatables.net/manual/i18n
  511. "language": {
  512. "aria": {
  513. "sortAscending": ": activate to sort column ascending",
  514. "sortDescending": ": activate to sort column descending"
  515. },
  516. "emptyTable": "No hay informacion en la tabla",
  517. "info": "Mostrando del _START_ al _END_ de _TOTAL_ registros",
  518. "infoEmpty": "No se encontraron coincidencias",
  519. "infoFiltered": "(filtrado un total de _MAX_ registros)",
  520. "lengthMenu": "Mostrar _MENU_ registros",
  521. "search": "Buscar:",
  522. "zeroRecords": "No se encontraron coincidencias"
  523. },
  524. "lengthMenu": [
  525. [20, 50, 75, 100, -1],
  526. [20, 50, 75, 100, "Todos"] // change per page values here
  527. ],
  528. // set the initial value
  529. "pageLength": 20,
  530. // Uncomment below line("dom" parameter) to fix the dropdown overflow issue in the datatable cells. The default datatable layout
  531. // setup uses scrollable div(table-scrollable) with overflow:auto to enable vertical scroll(see: assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js).
  532. // So when dropdowns used the scrollable div should be removed.
  533. "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>>",
  534. "bStateSave": true, // save datatable state(pagination, sort, etc) in cookie.
  535. "order": [
  536. [0, "asc"]
  537. ] // set first column as a default sort by asc
  538. });
  539. var tableWrapper = $('.tablePag_wrapper');
  540. // table.find('.group-checkable').change(function () {
  541. // var set = $(this).attr("data-set");
  542. // var checked = $(this).is(":checked");
  543. // $(set).each(function () {
  544. // if (checked) {
  545. // $(this).attr("checked", true);
  546. // } else {
  547. // $(this).attr("checked", false);
  548. // }
  549. // });
  550. // $.uniform.update(set);
  551. // });
  552. tableWrapper.find('.dataTables_length select').select2(); // initialize select2 dropdown
  553. }
  554. return {
  555. //main function to initiate the module
  556. init: function () {
  557. if (!$().dataTable) {
  558. return;
  559. }
  560. initTable3();
  561. }
  562. };
  563. }();
  564. var TableChecks = function () {
  565. var initTable1 = function () {
  566. var table = $('.tablechecks');
  567. // begin first table
  568. table.dataTable({
  569. // Internationalisation. For more info refer to http://datatables.net/manual/i18n
  570. "language": {
  571. "aria": {
  572. "sortAscending": ": activate to sort column ascending",
  573. "sortDescending": ": activate to sort column descending"
  574. },
  575. "emptyTable": "No hay informacion en la tabla",
  576. "info": "Mostrando del _START_ al _END_ de _TOTAL_ registros",
  577. "infoEmpty": "No se encontraron coincidencias",
  578. "infoFiltered": "(filtrado un total de _MAX_ registros)",
  579. "lengthMenu": "Mostrar _MENU_ registros",
  580. "search": "Buscar:",
  581. "zeroRecords": "No se encontraron coincidencias",
  582. "paginate": {
  583. "sPrevious": "Ant",
  584. "sNext": "Sig"
  585. }
  586. },
  587. // Or you can use remote translation file
  588. //"language": {
  589. // url: '//cdn.datatables.net/plug-ins/3cfcc339e89/i18n/Portuguese.json'
  590. //},
  591. // Uncomment below line("dom" parameter) to fix the dropdown overflow issue in the datatable cells. The default datatable layout
  592. // setup uses scrollable div(table-scrollable) with overflow:auto to enable vertical scroll(see: assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js).
  593. // So when dropdowns used the scrollable div should be removed.
  594. //"dom": "<'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r>t<'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>",
  595. "bStateSave": true, // save datatable state(pagination, sort, etc) in cookie.
  596. "columnDefs": [ {
  597. "targets": 0,
  598. "orderable": false,
  599. "searchable": false
  600. }],
  601. "lengthMenu": [
  602. [20, 50, 75, 100, -1],
  603. [20, 50, 75, 100, "Todos"] // change per page values here
  604. ],
  605. // set the initial value
  606. "pageLength": 20,
  607. "columnDefs": [{ // set default column settings
  608. 'orderable': false,
  609. 'targets': [0]
  610. }, {
  611. "searchable": false,
  612. "targets": [0]
  613. }],
  614. "order": [
  615. [1, "asc"]
  616. ] // set first column as a default sort by asc
  617. });
  618. var tableWrapper = $('.tablechecks_wrapper');
  619. table.find('.group-checkable').on('change', function () {
  620. var set = $(this).attr("data-set");
  621. var checked = $(this).is(":checked");
  622. $(set).each(function () {
  623. if (checked) {
  624. $(this).prop("checked", true);
  625. } else {
  626. $(this).prop("checked", false);
  627. }
  628. });
  629. $.uniform.update(set);
  630. });
  631. table.on('change', 'tbody tr .checkboxes', function () {
  632. $(this).parents('tr').toggleClass("active");
  633. });
  634. }
  635. return {
  636. //main function to initiate the module
  637. init: function () {
  638. if (!$().dataTable) {
  639. return;
  640. }
  641. initTable1();
  642. }
  643. };
  644. }();
  645. var handleDateFormat = function () {
  646. var shortDateFormat = 'dd/MM/yyyy';
  647. var longDateFormat = 'dd/MM/yyyy HH:mm:ss';
  648. $(".shortDateFormat").each(function (idx, elem) {
  649. if ($(elem).is(":input")) {
  650. $(elem).val($.format.date($(elem).val(), shortDateFormat));
  651. } else {
  652. $(elem).text($.format.date($(elem).text(), shortDateFormat));
  653. }
  654. });
  655. $(".longDateFormat").each(function (idx, elem) {
  656. if ($(elem).is(":input")) {
  657. $(elem).val($.format.date($(elem).val(), longDateFormat));
  658. } else {
  659. $(elem).text($.format.date($(elem).text(), longDateFormat));
  660. }
  661. });
  662. }
  663. var handleDatePickers = function () {
  664. if ($().datepicker) {
  665. $('.date-picker').datepicker({
  666. rtl: App.isRTL(),
  667. orientation: "left",
  668. autoclose: true
  669. });
  670. //$('body').removeClass("modal-open"); // fix bug when inline picker is used in modal
  671. }
  672. /* Workaround to restrict daterange past date select: http://stackoverflow.com/questions/11933173/how-to-restrict-the-selectable-date-ranges-in-bootstrap-datepicker */
  673. }
  674. var handleMultiSelect = function () {
  675. $('.searchable').multiSelect({
  676. selectableHeader: "<input type='text' class='search-input form-control' autocomplete='off' placeholder='Buscar productos disponibles'>",
  677. selectionHeader: "<input type='text' class='search-input form-control' autocomplete='off' placeholder='Buscar productos seleccionados'>",
  678. afterInit: function(ms) {
  679. var that = this,
  680. $selectableSearch = that.$selectableUl.prev(),
  681. $selectionSearch = that.$selectionUl.prev(),
  682. selectableSearchString = '#'+that.$container.attr('id')+' .ms-elem-selectable:not(.ms-selected)',
  683. selectionSearchString = '#'+that.$container.attr('id')+' .ms-elem-selection.ms-selected';
  684. that.qs1 = $selectableSearch.quicksearch(selectableSearchString)
  685. .on('keydown', function(e){
  686. if (e.which === 40){
  687. that.$selectableUl.focus();
  688. return false;
  689. }
  690. });
  691. that.qs2 = $selectionSearch.quicksearch(selectionSearchString)
  692. .on('keydown', function(e){
  693. if (e.which == 40){
  694. that.$selectionUl.focus();
  695. return false;
  696. }
  697. });
  698. },
  699. afterSelect: function(){
  700. this.qs1.cache();
  701. this.qs2.cache();
  702. },
  703. afterDeselect: function(){
  704. this.qs1.cache();
  705. this.qs2.cache();
  706. }
  707. });
  708. $('.multi-select').multiSelect({
  709. keepOrder: true,
  710. selectableOptgroup: true
  711. });
  712. $('#select-all').click(function(){
  713. $('.multi-select').multiSelect('select_all');
  714. return false;
  715. });
  716. $('#deselect-all').click(function(){
  717. $('.multi-select').multiSelect('deselect_all');
  718. return false;
  719. });
  720. }
  721. var handleNestedSelects = function (){
  722. $('select[data-option-dependent=true]').each(function (i) {
  723. var observer_dom_id = $(this).data('opt-id');
  724. var observed_dom_id = $(this).data('option-observed');
  725. var url_mask = $(this).data('option-url');
  726. var key_method = $(this).data('option-key-method');
  727. var value_method = $(this).data('option-value-method');
  728. var prompt = $('<option value=\"\">').text('Seleccione');
  729. if($(this).data('option-prompt') != undefined ){
  730. prompt = $('<option value=\"\">').text( $(this).data('option-prompt') );
  731. }
  732. // var prompt = $(this).has('option[value=]').size() ? $(this).find('option[value=]') : $('<option value=\"\">').text('Select a specialization');
  733. var regexp = /:[0-9a-zA-Z_]+:/g;
  734. var observer = $('select.' + observer_dom_id);
  735. var observed = $('.' + observed_dom_id);
  736. if (!observer.val() && observed.size() > 1) {
  737. observer.attr('disabled', true);
  738. }
  739. observed.on('change', function () {
  740. observer.empty().append(prompt);
  741. if (observed.val()) {
  742. url = url_mask.replace(regexp, observed.val());
  743. $.getJSON(url, function (data) {
  744. $.each(data, function (i, object) {
  745. observer.append($('<option>').attr('value', object[key_method]).text(object[value_method]));
  746. observer.attr('disabled', false);
  747. });
  748. });
  749. }
  750. });
  751. });
  752. }
  753. var oTable;
  754. var handleInputMasks = function () {
  755. $.extend($().inputmask.defaults, {
  756. 'autounmask': true
  757. });
  758. $(".mask_phone").inputmask("mask", {"mask": "(999) 999-9999"}); //specifying fn & options
  759. $(".mask_number").inputmask({ "mask": "9", "repeat": 10, "greedy": false }); // ~ mask "9" or mask "99" or ... mask "9999999999"
  760. $(".mask_decimal").inputmask('decimal', { rightAlignNumerics: false }); //disables the right alignment of the decimal input
  761. $(".mask_currency").inputmask('999,999,999.99', { numericInput: true });
  762. // $(".mask_rfc").inputmask("mask", {"mask":"9-a{1,3}9{1,3}" });
  763. }
  764. var TableAdvancedPrintable = function () {
  765. var initTablePrintable = function () {
  766. var filter = $('#filter').val();
  767. var buscar_ = { };
  768. var page_ = 0;
  769. $.fn.dataTableExt.oStdClasses.sFilterInput = "form-control input-medium input-inline";
  770. if(filter != ""){ buscar_ = { search: filter }; }
  771. if( $('#current_page').length > 0 ){ page_ = ($('#current_page').val() - 1) * 20;}
  772. $.extend(true, $.fn.DataTable.TableTools.classes, {
  773. "container": " pull-right margin-bottom-10",
  774. "buttons": {
  775. "normal": "btn btn-primary margin-right-10",
  776. "disabled": "disabled"
  777. },
  778. "collection": {
  779. "container": "DTTT_dropdown dropdown-menu tabletools-dropdown-menu "
  780. }
  781. });
  782. var table = $('.tableadvancedprintable');
  783. var oTable = table.dataTable({
  784. "dom": "<'row' <'col-md-12'T>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f><'col-md-6 col-sm-12'>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>",
  785. "tableTools": {
  786. "sSwfPath": "/plugins/datatables/extensions/TableTools/swf/copy_csv_xls_pdf.swf",
  787. "aButtons": [
  788. {
  789. "sExtends": "collection",
  790. "sButtonText": "Acciones <i class='fa fa-angle-down'></i>",
  791. "aButtons": [{
  792. "sExtends": "print",
  793. "footer": false,
  794. "exportOptions": {
  795. "columns": ':not(:last-child)',
  796. },
  797. "sButtonText": "Imprimir",
  798. "sInfo": 'Presiona "CTR+P" para imprmir o "ESC" para salir',
  799. "sMessage": function() {
  800. return "<h2>" + $('#title_for_print').val() + "</h2>";
  801. },
  802. "fnClick": function( nButton, oConfig ) {
  803. $(window).keyup(closePrintView);
  804. this.fnPrint( true, oConfig );
  805. }
  806. }]
  807. }]
  808. },
  809. "language": {
  810. "aria": {
  811. "sortAscending": ": activate to sort column ascending",
  812. "sortDescending": ": activate to sort column descending"
  813. },
  814. "emptyTable": "No hay informacion en la tabla",
  815. "info": "Mostrando del _START_ al _END_ de _TOTAL_ registros",
  816. "infoEmpty": "No se encontraron coincidencias",
  817. "infoFiltered": "(filtrado un total de _MAX_ registros)",
  818. "lengthMenu": "Mostrar _MENU_ registros",
  819. "search": "Buscar:",
  820. "zeroRecords": "No se encontraron coincidencias",
  821. "paginate": {
  822. "sPrevious": "Ant",
  823. "sNext": "Sig"
  824. }
  825. },
  826. "order": [
  827. // [0, 'asc']
  828. ],
  829. "lengthMenu": [
  830. [20, 50, 75, 100, -1],
  831. [20, 50, 75, 100, "Todos"] // change per page values here
  832. ],
  833. "search": buscar_,
  834. // set the initial value
  835. "pageLength": 20,
  836. "iDisplayStart": page_,
  837. "bServerSide": false,
  838. "fnDrawCallback": function( oSettings ) {
  839. $('a.filtros').on( 'click', function (e) {
  840. e.preventDefault();
  841. var url_ = $(this).attr('href');
  842. url_ += '?filter=' + $('#filter').val();
  843. url_ += '&current_page=' + $('#current_page').val();
  844. console.log(url_);
  845. window.location.href = url_;
  846. });
  847. $('a.filtros2').on( 'click', function (e) {
  848. e.preventDefault();
  849. var url_ = $(this).attr('href');
  850. url_ += '&filter=' + $('#filter').val();
  851. url_ += '&current_page=' + $('#current_page').val();
  852. console.log(url_);
  853. window.location.href = url_;
  854. });
  855. }
  856. });
  857. var closePrintView = function(e) {
  858. if(e.which == 27) {
  859. printViewClosed();
  860. }
  861. };
  862. function printViewClosed() {
  863. $(window).unbind('keyup', closePrintView);
  864. }
  865. if( $('#current_page').length > 0 ){
  866. $('.tableadvancedprintable').on( 'page.dt', function () {
  867. var oSettings = oTable.fnSettings();
  868. var page = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1;
  869. $('#current_page').val(page);
  870. });
  871. }
  872. }
  873. return {
  874. init: function () {
  875. if (!$().dataTable) {
  876. return;
  877. }
  878. initTablePrintable();
  879. }
  880. };
  881. }();
  882. var TableAdvancedPrintableAjax = function () {
  883. var initTablePrintableAjax = function () {
  884. $.fn.dataTableExt.oStdClasses.sFilterInput = "form-control input-medium input-inline";
  885. var table = $('.tableadvancedprintableAjax').DataTable({
  886. "processing": true,
  887. "serverSide": true,
  888. "ajax": {
  889. "url": $('.tableadvancedprintableAjax').data('source'),
  890. "data": function ( d ) {
  891. d.busqueda = $('input[type="search"]').val();
  892. d.location = $('#pointsale').val();
  893. d.category = $('#category').val();
  894. d.sub_category = $('#sub_category').val();
  895. }
  896. },
  897. "dom": "<'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>>",
  898. "language": {
  899. "aria": {
  900. "sortAscending": ": activate to sort column ascending",
  901. "sortDescending": ": activate to sort column descending"
  902. },
  903. "emptyTable": "No hay informacion en la tabla",
  904. "sProcessing": "Cargando...",
  905. "info": "Mostrando del _START_ al _END_ de _TOTAL_ registros",
  906. "infoEmpty": "No se encontraron coincidencias",
  907. "infoFiltered": "(filtrado un total de _MAX_ registros)",
  908. "lengthMenu": "Mostrar _MENU_ registros",
  909. "search": "Buscar:",
  910. "zeroRecords": "No se encontraron coincidencias",
  911. "paginate": {
  912. "sPrevious": "Ant",
  913. "sNext": "Sig"
  914. }
  915. },
  916. "order": [
  917. // [0, 'asc']
  918. ],
  919. "lengthMenu": [
  920. [20, 50, 75, 100, -1],
  921. [20, 50, 75, 100, "Todos"] // change per page values here
  922. ],
  923. "pageLength": 20
  924. });
  925. var closePrintView = function(e) {
  926. if(e.which == 27) {
  927. printViewClosed();
  928. }
  929. };
  930. function printViewClosed() {
  931. $(window).unbind('keyup', closePrintView);
  932. }
  933. }
  934. return {
  935. init: function () {
  936. if (!$().dataTable) {
  937. return;
  938. }
  939. initTablePrintableAjax();
  940. }
  941. };
  942. }();
  943. var TableAdvancedAjax = function () {
  944. //create JSON array for aoColumnDefs
  945. var initTableAjax = function () {
  946. var table = $('.tableadvancedAjax');
  947. var filter = $('#filter').val();
  948. var buscar_ = { };
  949. var page_ = 0;
  950. $.fn.dataTableExt.oStdClasses.sFilterInput = "form-control input-medium input-inline";
  951. if(filter != ""){ buscar_ = { search: filter }; }
  952. if( $('#current_page').length > 0 ){ page_ = ($('#current_page').val() - 1) * 20;}
  953. var oTable = table.dataTable({
  954. "processing": true,
  955. "serverSide": true,
  956. "ajax": {
  957. "url": $('.tableadvancedAjax').data('source'),
  958. "data": function ( d ) {
  959. d.busqueda = $('input[type="search"]').val();
  960. $('#filter').val(d.busqueda);
  961. }
  962. },
  963. "language": {
  964. "aria": {
  965. "sortAscending": ": activate to sort column ascending",
  966. "sortDescending": ": activate to sort column descending"
  967. },
  968. "emptyTable": "No hay informacion en la tabla",
  969. "sProcessing": "Cargando...",
  970. "info": "Mostrando del _START_ al _END_ de _TOTAL_ registros",
  971. "infoEmpty": "No se encontraron coincidencias",
  972. "infoFiltered": "(filtrado un total de _MAX_ registros)",
  973. "lengthMenu": "Mostrar _MENU_ registros",
  974. "search": "Buscar:",
  975. "zeroRecords": "No se encontraron coincidencias",
  976. "paginate": {
  977. "sPrevious": "Ant",
  978. "sNext": "Sig"
  979. }
  980. },
  981. "order": [
  982. // [0, 'asc']
  983. ],
  984. "lengthMenu": [
  985. [20, 50, 75, 100, -1],
  986. [20, 50, 75, 100, "Todos"] // change per page values here
  987. ],
  988. "dom": "<'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
  989. "search": buscar_,
  990. // set the initial value
  991. "pageLength": 20,
  992. "iDisplayStart": page_,
  993. "fnDrawCallback": function( oSettings ) {
  994. $('a.filtros').on( 'click', function (e) {
  995. e.preventDefault();
  996. var url_ = $(this).attr('href');
  997. url_ += '?filter=' + $('#filter').val();
  998. url_ += '&current_page=' + $('#current_page').val();
  999. console.log(url_);
  1000. window.location.href = url_;
  1001. });
  1002. $('a.filtros2').on( 'click', function (e) {
  1003. e.preventDefault();
  1004. var url_ = $(this).attr('href');
  1005. url_ += '&filter=' + $('#filter').val();
  1006. url_ += '&current_page=' + $('#current_page').val();
  1007. console.log(url_);
  1008. window.location.href = url_;
  1009. });
  1010. }
  1011. });
  1012. var tableWrapper = $('.tableadvancedAjax_wrapper');
  1013. tableWrapper.find('.dataTables_length select').select2();
  1014. if( $('#current_page').length > 0 ){
  1015. $('.tableadvancedAjax').on( 'page.dt', function () {
  1016. var oSettings = oTable.fnSettings();
  1017. var page = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1;
  1018. $('#current_page').val(page);
  1019. });
  1020. }
  1021. }
  1022. return {
  1023. init: function () {
  1024. if (!$().dataTable) {
  1025. return;
  1026. }
  1027. initTableAjax();
  1028. }
  1029. };
  1030. }();
  1031. var FormWizard = function () {
  1032. return {
  1033. //main function to initiate the module
  1034. init: function () {
  1035. if (!jQuery().bootstrapWizard) {
  1036. return;
  1037. }
  1038. var form = $('#submit_form');
  1039. var error = $('.alert-danger', form);
  1040. var success = $('.alert-success', form);
  1041. // jQuery.validator.setDefaults({
  1042. // doNotHideMessage: true, //this option enables to show the error/success messages on tab switch.
  1043. // errorElement: 'span', //default input error message container
  1044. // errorClass: 'help-block help-block-error', // default input error message class
  1045. // focusInvalid: false, // do not focus the last invalid input
  1046. // errorPlacement: function (error, element) { // render error placement for each input type
  1047. // if (element.attr("name") == "gender") { // for uniform radio buttons, insert the after the given container
  1048. // error.insertAfter("#form_gender_error");
  1049. // } else if (element.attr("name") == "modulos[]") { // for uniform checkboxes, insert the after the given container
  1050. // error.insertAfter("#form_payment_error");
  1051. // } else {
  1052. // error.insertAfter(element); // for other inputs, just perform default behavior
  1053. // }
  1054. // },
  1055. // invalidHandler: function (event, validator) { //display error alert on form submit
  1056. // success.hide();
  1057. // error.show();
  1058. // App.scrollTo(error, -200);
  1059. // },
  1060. // highlight: function (element) { // hightlight error inputs
  1061. // $(element)
  1062. // .closest('.form-group').removeClass('has-success').addClass('has-error'); // set error class to the control group
  1063. // },
  1064. // unhighlight: function (element) { // revert the change done by hightlight
  1065. // $(element)
  1066. // .closest('.form-group').removeClass('has-error'); // set error class to the control group
  1067. // },
  1068. // success: function (label) {
  1069. // if (label.attr("for") == "gender" || label.attr("for") == "modulos[]") { // for checkboxes and radio buttons, no need to show OK icon
  1070. // label
  1071. // .closest('.form-group').removeClass('has-error').addClass('has-success');
  1072. // label.remove(); // remove error label here
  1073. // } else { // display success icon for other inputs
  1074. // label
  1075. // .addClass('valid') // mark the current input as valid and display OK icon
  1076. // .closest('.form-group').removeClass('has-error').addClass('has-success'); // set success class to the control group
  1077. // }
  1078. // },
  1079. // submitHandler: function (form) {
  1080. // success.show();
  1081. // error.hide();
  1082. // form.submit();
  1083. // //add here some ajax code to submit your form or just call form.submit() if you want to submit the form without ajax
  1084. // }
  1085. // });
  1086. var displayConfirm = function() {
  1087. $('#tab4 .form-control-static', form).each(function(){
  1088. var input = $('[name="'+$(this).attr("data-display")+'"]', form);
  1089. if (input.is(":radio")) {
  1090. input = $('[name="'+$(this).attr("data-display")+'"]:checked', form);
  1091. }
  1092. if (input.is(":text") || input.is("textarea")) {
  1093. $(this).html(input.val());
  1094. } else if (input.is("select")) {
  1095. $(this).html(input.find('option:selected').text());
  1096. } else if (input.is(":radio") && input.is(":checked")) {
  1097. $(this).html(input.attr("data-title"));
  1098. } else if ($(this).attr("data-display") == 'modulos[]') {
  1099. var modulos = [];
  1100. $('[name="modulos[]"]:checked', form).each(function(){
  1101. modulos.push($(this).attr('data-title'));
  1102. });
  1103. $(this).html(modulos.join(" <br>"));
  1104. }
  1105. });
  1106. }
  1107. var displayConfirm = function() {
  1108. $('.form-control-static', form).each(function(){
  1109. var input = $('[name="'+$(this).attr("data-display")+'"]', form);
  1110. if (input.is(":radio")) {
  1111. input = $('[name="'+$(this).attr("data-display")+'"]:checked', form);
  1112. }
  1113. if (input.is(":text") || input.is("textarea")) {
  1114. $(this).html(input.val());
  1115. } else if (input.is("select") && !(input.attr("multiple")) ) {
  1116. $(this).html(input.find('option:selected').text());
  1117. } else if (input.is(":radio") && input.is(":checked")) {
  1118. $(this).html(input.attr("data-title"));
  1119. } else if ($(this).attr("data-display") == 'modulos[]') {
  1120. var modulos = [];
  1121. $('#modulos :selected', form).each(function(){
  1122. modulos.push($(this).html());
  1123. });
  1124. $(this).html(modulos.join(" <br>"));
  1125. }
  1126. });
  1127. }
  1128. var handleTitle = function(tab, navigation, index) {
  1129. var total = navigation.find('li').length;
  1130. var current = index + 1;
  1131. // set wizard title
  1132. $('.step-title', $('#form_wizard_1')).text('Step ' + (index + 1) + ' of ' + total);
  1133. // set done steps
  1134. jQuery('li', $('#form_wizard_1')).removeClass("done");
  1135. var li_list = navigation.find('li');
  1136. for (var i = 0; i < index; i++) {
  1137. jQuery(li_list[i]).addClass("done");
  1138. }
  1139. if (current == 1) {
  1140. $('#form_wizard_1').find('.button-previous').hide();
  1141. } else {
  1142. $('#form_wizard_1').find('.button-previous').show();
  1143. }
  1144. if (current >= total) {
  1145. $('#form_wizard_1').find('.button-next').hide();
  1146. $('#form_wizard_1').find('.button-submit').show();
  1147. displayConfirm();
  1148. } else {
  1149. $('#form_wizard_1').find('.button-next').show();
  1150. $('#form_wizard_1').find('.button-submit').hide();
  1151. }
  1152. App.scrollTo($('.page-title'));
  1153. }
  1154. // default form wizard
  1155. $('#form_wizard_1').bootstrapWizard({
  1156. 'nextSelector': '.button-next',
  1157. 'previousSelector': '.button-previous',
  1158. onTabClick: function (tab, navigation, index, clickedIndex) {
  1159. return false;
  1160. /*
  1161. success.hide();
  1162. error.hide();
  1163. if (form.valid() == false) {
  1164. return false;
  1165. }
  1166. handleTitle(tab, navigation, clickedIndex);
  1167. */
  1168. },
  1169. onNext: function (tab, navigation, index) {
  1170. // success.hide();
  1171. // error.hide();
  1172. // if (form.valid() == false) {
  1173. // return false;
  1174. // }
  1175. handleTitle(tab, navigation, index);
  1176. },
  1177. onPrevious: function (tab, navigation, index) {
  1178. // success.hide();
  1179. // error.hide();
  1180. handleTitle(tab, navigation, index);
  1181. },
  1182. onTabShow: function (tab, navigation, index) {
  1183. var total = navigation.find('li').length;
  1184. var current = index + 1;
  1185. var $percent = (current / total) * 100;
  1186. $('#form_wizard_1').find('.progress-bar').css({
  1187. width: $percent + '%'
  1188. });
  1189. }
  1190. });
  1191. $('#form_wizard_1').find('.button-previous').hide();
  1192. $('#form_wizard_1 .button-submit').click(function () {
  1193. // alert('Finished! Hope you like it :)');
  1194. if(window.location.pathname.includes('users')) {
  1195. $('#submit_form').submit();
  1196. } else {
  1197. submitForm();
  1198. }
  1199. }).hide();
  1200. }
  1201. };
  1202. }();
  1203. var FormWizard_sale_return = function () {
  1204. return {
  1205. init: function () {
  1206. if (!jQuery().bootstrapWizard) {
  1207. return;
  1208. }
  1209. var form = $('#submit_form');
  1210. var error = $('.alert-danger', form);
  1211. var success = $('.alert-success', form);
  1212. var handleTitle = function(tab, navigation, index) {
  1213. var total = navigation.find('li').length;
  1214. var current = index + 1;
  1215. jQuery('li', $('#form_wizard_product_return')).removeClass("done");
  1216. var li_list = navigation.find('li');
  1217. for (var i = 0; i < index; i++) {
  1218. jQuery(li_list[i]).addClass("done");
  1219. }
  1220. if (current == 1) {
  1221. $('#form_wizard_product_return').find('.button-previous').hide();
  1222. } else {
  1223. $('#form_wizard_product_return').find('.button-previous').show();
  1224. }
  1225. if (current >= total) {
  1226. $('#form_wizard_product_return').find('.button-next').hide();
  1227. $('#form_wizard_product_return').find('.button-submit').show();
  1228. } else {
  1229. $('#form_wizard_product_return').find('.button-next').show();
  1230. $('#form_wizard_product_return').find('.button-submit').hide();
  1231. }
  1232. // App.scrollTo($('.page-title'));
  1233. }
  1234. $('#form_wizard_product_return').bootstrapWizard({
  1235. 'nextSelector': '.button-next',
  1236. 'previousSelector': '.button-previous',
  1237. onTabClick: function (tab, navigation, index, clickedIndex) {
  1238. return false;
  1239. },
  1240. onNext: function (tab, navigation, index) {
  1241. shouldStep = nextStep(index);
  1242. if (index != 0) {
  1243. $('#form_wizard_product_return').find('.button-previous').show();
  1244. } else {
  1245. $('#form_wizard_product_return').find('.button-previous').hide();
  1246. }
  1247. if(shouldStep) {
  1248. handleTitle(tab, navigation, index);
  1249. }
  1250. return shouldStep;
  1251. },
  1252. onPrevious: function (tab, navigation, index) {
  1253. handleTitle(tab, navigation, index);
  1254. },
  1255. onTabShow: function (tab, navigation, index) {
  1256. var total = navigation.find('li').length;
  1257. var current = index + 1;
  1258. var $percent = (current / total) * 100;
  1259. $('#form_wizard_product_return').find('.progress-bar').css({
  1260. width: $percent + '%'
  1261. });
  1262. }
  1263. });
  1264. $('#form_wizard_product_return').find('.button-previous').hide();
  1265. $('#form_wizard_product_return .button-submit').click(function () {
  1266. $(this).hide();
  1267. submitForm();
  1268. }).hide();
  1269. }
  1270. };
  1271. }();
  1272. var MakeChart = function(type, data, container, categoryField, valueField) {
  1273. if(type == 'serial') {
  1274. var chart = AmCharts.makeChart(container, {
  1275. "type": 'serial',
  1276. "theme": "light",
  1277. "dataProvider": data,
  1278. "gridAboveGraphs": true,
  1279. "startDuration": 1,
  1280. "graphs": [ {
  1281. "balloonText": "[[category]]: <b>[[value]]</b>",
  1282. "fillAlphas": 0.8,
  1283. "lineAlpha": 0.2,
  1284. "type": "column",
  1285. "valueField": valueField
  1286. } ],
  1287. "chartCursor": {
  1288. "categoryBalloonEnabled": false,
  1289. "cursorAlpha": 0,
  1290. "zoomable": false
  1291. },
  1292. "categoryField": categoryField,
  1293. "categoryAxis": {
  1294. "gridPosition": "start",
  1295. "gridAlpha": 0,
  1296. "tickPosition": "start",
  1297. "tickLength": 20
  1298. }
  1299. });
  1300. } else if(type == 'pie') {
  1301. // pie chart
  1302. var chart = AmCharts.makeChart( container, {
  1303. "type": "pie",
  1304. "theme": "light",
  1305. "dataProvider": data,
  1306. "titleField": categoryField,
  1307. "valueField": valueField,
  1308. "labelRadius": 5,
  1309. "radius": "42%",
  1310. "innerRadius": "60%",
  1311. "labelText": "[[title]]",
  1312. });
  1313. }
  1314. }
  1315. $(document).on("page:change", function() {
  1316. Layout.init();
  1317. $(document).ajaxError(function(event,xhr,options,exc) {
  1318. var errors = JSON.parse(xhr.responseText);
  1319. var er ="<ul>";
  1320. for(var i = 0; i < errors.length; i++){
  1321. var list = errors[i];
  1322. er += "<li>"+list+"</li>"
  1323. }
  1324. er+="</ul>"
  1325. var kk = " <div class='alert alert-danger'><strong>Tiene un error no se puede guardar</strong><br>"+er+"</div> "
  1326. $("#error_explanation").html(kk);
  1327. });
  1328. if($('.numbersep').get(0) ){
  1329. var numbersSeparation = function () {
  1330. var numers = $('span.numbers');
  1331. return numers.each(function(){
  1332. $(this).text( $(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") );
  1333. })
  1334. }
  1335. }
  1336. if($('.nestedselect').get(0) ){
  1337. handleNestedSelects();
  1338. }
  1339. if($('.make-switch').get(0)){
  1340. $(":checkbox").bootstrapSwitch();
  1341. }
  1342. if($('.select2').get(0)){
  1343. $('select.select2').select2({
  1344. placeholder: "Seleccione",
  1345. "language": {
  1346. "noResults": function(){
  1347. return "No se encontraron coincidencias";
  1348. }
  1349. },
  1350. escapeMarkup: function (markup) {
  1351. return markup;
  1352. }
  1353. });
  1354. }
  1355. if($('#form').get(0) ){
  1356. FormValidation.init();
  1357. }
  1358. if($('.tableadvanced').get(0) ){
  1359. TableAdvanced.init();
  1360. $('.dataTables_filter input[type=search]').on( 'keyup', function () {
  1361. $('#filter').val( this.value );
  1362. } );
  1363. }
  1364. if($('.tableadvancedSingleSelection').get(0) ){
  1365. TableAdvancedSingleSelection.init();
  1366. }
  1367. if($('.tableadvancedprintable').get(0) ){
  1368. TableAdvancedPrintable.init();
  1369. $('.dataTables_filter input[type=search]').on( 'keyup', function () {
  1370. $('#filter').val( this.value );
  1371. } );
  1372. }
  1373. if($('.tableadvancedprintableAjax').get(0) ){
  1374. TableAdvancedPrintableAjax.init();
  1375. }
  1376. if($('.tableadvancedAjax').get(0) ){
  1377. TableAdvancedAjax.init();
  1378. }
  1379. if($('.tablechecks').get(0) ){
  1380. TableChecks.init();
  1381. }
  1382. if($('.tablePag').get(0) ){
  1383. TablePagination.init();
  1384. }
  1385. if($('.longDateFormat').get(0) || $('.shortDateFormat').get(0)){
  1386. handleDateFormat();
  1387. }
  1388. if($('.date-picker').get(0)){
  1389. handleDatePickers();
  1390. }
  1391. if ($('.date-range').get(0) ){
  1392. handleDateRangePickers();
  1393. }
  1394. if ($('.mask_phone').get(0) || $('.mask_number').get(0) || $('.mask_decimal').get(0) || $('.mask_currency').get(0)){
  1395. handleInputMasks();
  1396. }
  1397. if ($('.multi-select').get(0)){
  1398. handleMultiSelect();
  1399. }
  1400. if($('.tableWithCheckbox').get(0) ){
  1401. TableWithCheckbox.init();
  1402. }
  1403. // if($('.tableWithCheckboxAjax').get(0) ){
  1404. // tableWithCheckboxAjax.init();
  1405. // }
  1406. if($('.tableCheckBoxNoSearch').get(0) ){
  1407. tableCheckBoxNoSearch.init();
  1408. }
  1409. if($('#form_wizard_1').get(0) ){
  1410. FormWizard.init();
  1411. }
  1412. if($('#form_wizard_product_return').get(0) ){
  1413. FormWizard_sale_return.init();
  1414. }
  1415. // $('.form_modal').click(function () {
  1416. // var $modal = $('#form_modal');
  1417. // $modal.modal();
  1418. // });
  1419. //Override the default confirm dialog by rails
  1420. $.rails.allowAction = function(link){
  1421. if (link.data("confirm") == undefined){
  1422. return true;
  1423. }
  1424. $.rails.showConfirmationDialog(link);
  1425. return false;
  1426. }
  1427. //User click confirm button
  1428. $.rails.confirmed = function(link){
  1429. link.data("confirm", null);
  1430. link.trigger("click.rails");
  1431. }
  1432. //Display the confirmation dialog
  1433. $.rails.showConfirmationDialog = function(link){
  1434. bootbox.dialog({
  1435. message: link.data("confirm"),
  1436. buttons: {
  1437. "Cancelar": {
  1438. label: "Cancelar",
  1439. className: "btn-default"
  1440. },
  1441. success: {
  1442. label: "OK",
  1443. className: "btn-primary",
  1444. callback: function() {
  1445. $.rails.confirmed(link);
  1446. }
  1447. }
  1448. }
  1449. });
  1450. }
  1451. });