config.js 55 KB

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