config.js 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709
  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. //DISABLE BUTTONS WHEN AN AJAX REQUEST IS GOING TROUGH
  1321. $(document).bind("ajaxSend", function(){
  1322. $('.disable-when-ajax').prop('disabled', true);
  1323. }).bind("ajaxComplete", function(){
  1324. $('.disable-when-ajax').prop('disabled', false);
  1325. });
  1326. $(document).on("page:change", function() {
  1327. Layout.init();
  1328. $(document).ajaxError(function(event,xhr,options,exc) {
  1329. var errors = JSON.parse(xhr.responseText);
  1330. var er ="<ul>";
  1331. for(var i = 0; i < errors.length; i++){
  1332. var list = errors[i];
  1333. er += "<li>"+list+"</li>"
  1334. }
  1335. er+="</ul>"
  1336. var kk = " <div class='alert alert-danger'><strong>Tiene un error no se puede guardar</strong><br>"+er+"</div> "
  1337. $("#error_explanation").html(kk);
  1338. });
  1339. if($('.numbersep').get(0) ){
  1340. var numbersSeparation = function () {
  1341. var numers = $('span.numbers');
  1342. return numers.each(function(){
  1343. $(this).text( $(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") );
  1344. })
  1345. }
  1346. }
  1347. if($('.nestedselect').get(0) ){
  1348. handleNestedSelects();
  1349. }
  1350. if($('.make-switch').get(0)){
  1351. $(":checkbox").bootstrapSwitch();
  1352. }
  1353. if($('.select2').get(0)){
  1354. $('select.select2').select2({
  1355. placeholder: "Seleccione",
  1356. "language": {
  1357. "noResults": function(){
  1358. return "No se encontraron coincidencias";
  1359. }
  1360. },
  1361. escapeMarkup: function (markup) {
  1362. return markup;
  1363. }
  1364. });
  1365. }
  1366. if($('.select2-allow-clear-todas').get(0)){
  1367. $('select.select2-allow-clear-todas').select2({
  1368. allowClear: true,
  1369. placeholder: "Todas",
  1370. width: null,
  1371. placeholder: "Seleccione",
  1372. "language": {
  1373. "noResults": function(){
  1374. return "No se encontraron coincidencias";
  1375. }
  1376. },
  1377. escapeMarkup: function (markup) {
  1378. return markup;
  1379. }
  1380. });
  1381. }
  1382. if($('#form').get(0) ){
  1383. FormValidation.init();
  1384. }
  1385. if($('.tableadvanced').get(0) ){
  1386. TableAdvanced.init();
  1387. $('.dataTables_filter input[type=search]').on( 'keyup', function () {
  1388. $('#filter').val( this.value );
  1389. } );
  1390. }
  1391. if($('.tableadvancedSingleSelection').get(0) ){
  1392. TableAdvancedSingleSelection.init();
  1393. }
  1394. if($('.tableadvancedprintable').get(0) ){
  1395. TableAdvancedPrintable.init();
  1396. $('.dataTables_filter input[type=search]').on( 'keyup', function () {
  1397. $('#filter').val( this.value );
  1398. } );
  1399. }
  1400. if($('.tableadvancedprintableAjax').get(0) ){
  1401. TableAdvancedPrintableAjax.init();
  1402. }
  1403. if($('.tableadvancedAjax').get(0) ){
  1404. TableAdvancedAjax.init();
  1405. }
  1406. if($('.tablechecks').get(0) ){
  1407. TableChecks.init();
  1408. }
  1409. if($('.tablePag').get(0) ){
  1410. TablePagination.init();
  1411. }
  1412. if($('.longDateFormat').get(0) || $('.shortDateFormat').get(0)){
  1413. handleDateFormat();
  1414. }
  1415. if($('.date-picker').get(0)){
  1416. handleDatePickers();
  1417. }
  1418. if ($('.date-range').get(0) ){
  1419. handleDateRangePickers();
  1420. }
  1421. if ($('.mask_phone').get(0) || $('.mask_number').get(0) || $('.mask_decimal').get(0) || $('.mask_currency').get(0)){
  1422. handleInputMasks();
  1423. }
  1424. if ($('.multi-select').get(0)){
  1425. handleMultiSelect();
  1426. }
  1427. if($('.tableWithCheckbox').get(0) ){
  1428. TableWithCheckbox.init();
  1429. }
  1430. // if($('.tableWithCheckboxAjax').get(0) ){
  1431. // tableWithCheckboxAjax.init();
  1432. // }
  1433. if($('.tableCheckBoxNoSearch').get(0) ){
  1434. tableCheckBoxNoSearch.init();
  1435. }
  1436. if($('#form_wizard_1').get(0) ){
  1437. FormWizard.init();
  1438. }
  1439. if($('#form_wizard_product_return').get(0) ){
  1440. FormWizard_sale_return.init();
  1441. }
  1442. // $('.form_modal').click(function () {
  1443. // var $modal = $('#form_modal');
  1444. // $modal.modal();
  1445. // });
  1446. //Override the default confirm dialog by rails
  1447. $.rails.allowAction = function(link){
  1448. if (link.data("confirm") == undefined){
  1449. return true;
  1450. }
  1451. $.rails.showConfirmationDialog(link);
  1452. return false;
  1453. }
  1454. //User click confirm button
  1455. $.rails.confirmed = function(link){
  1456. link.data("confirm", null);
  1457. link.trigger("click.rails");
  1458. }
  1459. //Display the confirmation dialog
  1460. $.rails.showConfirmationDialog = function(link){
  1461. bootbox.dialog({
  1462. message: link.data("confirm"),
  1463. buttons: {
  1464. "Cancelar": {
  1465. label: "Cancelar",
  1466. className: "btn-default"
  1467. },
  1468. success: {
  1469. label: "OK",
  1470. className: "btn-primary",
  1471. callback: function() {
  1472. $.rails.confirmed(link);
  1473. }
  1474. }
  1475. }
  1476. });
  1477. }
  1478. });