Best JavaScript code snippet using argos
trunk_groups.js
Source:trunk_groups.js
1//= require bootstrap.min2//= require modernizr.min3//= require toggles.min4//= require retina.min5//= require jquery.cookies6//= require jquery.gritter.min7//= require bootstrap-wizard.min8//= require jquery.gritter.min9//= require select2.min10//= require jquery_nested_form11//= require jquery.validate.min12//= require jquery.datatables.min13//= require custom14//= require_self15var App = App || {};16$(document).ready(function() {17 App.AdminIngressTrunkFormHandler = (function($) {18 var urls; 19 var $call_limit_spinner, $cps_limit_spinner, $profit_margin_value_spinner,20 $profit_margin_pc_spinner, $try_timeout_spinner, $pdd_timeout_spinner,21 $ring_timeout_spinner, $decimal_points_spinner, $max_duration_spinner,22 $max_cost_spinner;23 var init = function(toggleStatuses) {24 $(".select2").select2({25 width: '75%'26 });27 $("#ingress_trunk_carrier_id").select2({28 width: '75%',29 }).on('change', function() {30 var val = $(this).val();31 32 $.get(urls[4], {'carrier_id': val}, function(data) {33 $('#ingress_trunk_reg_user').val(data);34 }, 'html');35 });36 $("#ingress_trunk_profit_margin_type").select2({37 width: '75%',38 }).on('change', function() {39 var val = $(this).val();40 41 if(val == '0') {42 $('label#profit_margin_type_msg').hide();43 $('#profit_margin_value_cont').show();44 $('#profit_margin_pc_cont').hide();45 }46 else if(val == '1') {47 $('label#profit_margin_type_msg').hide();48 $('#profit_margin_value_cont').hide();49 $('#profit_margin_pc_cont').show();50 }51 else {52 $('label#profit_margin_type_msg').show();53 $('#profit_margin_value_cont').hide();54 $('#profit_margin_pc_cont').hide();55 }56 });57 $('#ingress_trunk_ingress_type').select2({58 width: '75%'59 }).on('change', function() {60 var val = $(this).val();61 if(val == '0') {62 $('span#registration_fields').show();63 $('span#ip_auth_fields').hide();64 }65 else if(val == '1') {66 $('span#registration_fields').hide();67 $('span#ip_auth_fields').show();68 }69 else {70 $('span#registration_fields').hide();71 $('span#ip_auth_fields').hide();72 }73 });74 $(document).on('nested:fieldRemoved', function(event){75 event.field.removeClass('fields');76 77 $('.add_nested_fields').removeClass('disabled');78 79 if($('div.fields').filter(":visible").length < 1) {80 $('table#host_headings').hide();81 $('div#add_host_warning').show();82 }83 });84 $(document).on('nested:fieldAdded', function(event){85 if($("span#ip_auth_fields .fields").length >= 12) {86 $('.add_nested_fields').addClass('disabled');87 }88 $('table#host_headings').show();89 $('div#add_host_warning').hide();90 $('.tooltips').tooltip({ container: 'body'});91 });92 $('.generate_random').click( function(){93 $(this).siblings('.form-control').val(randomAlphaString(10));94 });95 $('.cancel-form').click(function(e) {96 window.location.href = urls[0];97 return false;98 });99 $call_limit_spinner = $('#call_limit_spinner').spinner({100 numberFormat: "n",101 step: 10,102 min: 0,103 max: 10000,104 value: 0105 });106 $cps_limit_spinner = $('#cps_limit_spinner').spinner({107 numberFormat: "n",108 step: 5,109 min: 0,110 max: 500,111 value: 0112 });113 $profit_margin_value_spinner = $('#profit_margin_value_spinner').spinner({114 numberFormat: "n",115 step: 1,116 min: -500,117 max: 500,118 value: 0119 });120 $profit_margin_pc_spinner = $('#profit_margin_pc_spinner').spinner({121 numberFormat: "n",122 step: 0.01,123 min: -1,124 max: 1,125 value: 0126 });127 $try_timeout_spinner = $('#try_timeout_spinner').spinner({128 numberFormat: "n",129 step: 1,130 min: 1,131 max: 60,132 value: 2133 });134 $pdd_timeout_spinner = $('#pdd_timeout_spinner').spinner({135 numberFormat: "n",136 step: 1,137 min: 1,138 max: 60,139 value: 6140 });141 $ring_timeout_spinner = $('#ring_timeout_spinner').spinner({142 numberFormat: "n",143 step: 1,144 min: 1,145 max: 120,146 value: 60147 });148 $decimal_points_spinner = $('#decimal_points_spinner').spinner({149 numberFormat: "n",150 step: 1,151 min: 2,152 max: 8,153 value: 4154 });155 $max_duration_spinner = $('#max_duration_spinner').spinner({156 numberFormat: "n",157 step: 100,158 min: 60,159 max: 7200,160 value: 7200161 });162 $max_cost_spinner = $('#max_cost_spinner').spinner({163 numberFormat: "n",164 step: 0.01,165 min: 0,166 max: 1,167 value: 0168 });169 $("#siptrace_activation_tgl").toggles({ on: toggleStatuses[0], checkbox: $("#sip_trace_tgl_chkbox"), 'event': 'toggle', text: {on: "Yes", off: "No"}});170 $("#media_bypass_activation_tgl").toggles({ on: toggleStatuses[1], checkbox: $("#media_bypass_tgl_chkbox"), 'event': 'toggle', text: {on: "Yes", off: "No"}});171 $("#lrn_block_activation_tgl").toggles({ on: toggleStatuses[2], checkbox: $("#lrn_block_tgl_chkbox"), 'event': 'toggle', text: {on: "Yes", off: "No"}});172 $("#block_wireless_activation_tgl").toggles({ on: toggleStatuses[3], checkbox: $("#block_wireless_tgl_chkbox"), 'event': 'toggle', text: {on: "Yes", off: "No"}});173 $.validator.addMethod("cid", function(value, element) {174 return this.optional(element) || /^[\d\+]+$/.test(value);175 }, "Only digits and '+' sign is allowed");176 $.validator.addMethod("techprefix", function(value, element) {177 return this.optional(element) || /^[\d#]+$/.test(value);178 }, "Only digits and '#' is allowed");179 validationOptions = {180 debug : false,181 ignoreTitle: true,182 highlight : function(element) {183 $(element).closest('.form-group').removeClass('has-success').addClass('has-error');184 },185 success : function(element) {186 $(element).closest('.form-group').removeClass('has-error');187 },188 submitHandler : function(form) {189 // do other things for a valid form190 if (validateSpinners() && validateIPAuthentication()) {191 form.submit();192 }193 },194 errorPlacement: function(error, element) {195 if (element.attr("id") == "ingress_trunk_reg_user") {196 $("#rgn_username_error").html(error);197 }198 else if(element.attr("id") == "ingress_trunk_reg_password") {199 $("#rgn_password_error").html(error);200 }201 else {202 // the default error placement for the rest203 error.insertAfter(element);204 }205 },206 rules : {207 "ingress_trunk[carrier_id]": {208 required: true,209 digits: true210 },211 "ingress_trunk[routing_id]": {212 required: true,213 digits: true214 },215 "ingress_trunk[rate_sheet_id]": {216 required: true,217 digits: true218 },219 "ingress_trunk[tech_prefix]": {220 techprefix: true221 },222 "ingress_trunk[reg_user]": {223 required: function() {224 return $('#ingress_trunk_ingress_type').val() == '0'225 },226 minlength: 5,227 maxlength: 25,228 remote : {229 url : urls[3],230 type : "get"231 }232 },233 "ingress_trunk[reg_password]": {234 required: function() {235 return $('#ingress_trunk_ingress_type').val() == '0'236 },237 minlength: 5,238 maxlength: 25239 },240 "ingress_trunk[profit_margin_type]": {241 required: true,242 digits: true243 },244 "ingress_trunk[force_cid]": {245 cid: true246 },247 "ingress_trunk[name]" : {248 required : true,249 minlength: 3,250 maxlength: 25,251 remote : {252 url : urls[1],253 type : "get",254 }255 }256 },257 messages : {258 "ingress_trunk[name]" : {259 remote : "This trunk name already exists with us."260 },261 "ingress_trunk[reg_user]" : {262 remote : "This username already exists with us."263 }264 }265 };266 $editFormValidator = $('#editIngressTrunkForm').validate($.extend(true, {}, validationOptions, {267 rules: {268 "ingress_trunk[name]": {remote: {269 data: {id: $('#ingress_trunk_id').val()}270 }},271 "ingress_trunk[reg_user]": {remote: {272 data: {id: $('#ingress_trunk_id').val()}273 }}274 }275 }));276 277 $newFormValidator = $('#newIngressTrunkForm').validate($.extend(true, {}, validationOptions, {}));278 $('#editIngressTrunkWizard').bootstrapWizard({279 'nextSelector' : '.next',280 'previousSelector' : '.previous',281 onNext : function(tab, navigation, index) {282 if(index == 2) return true;283 return validateEditForm() && validateIPAuthentication();284 },285 onPrevious : function(tab, navigation, index) {286 return validateEditForm() && validateSpinners();287 },288 onTabClick: function(tab, navigation, index) {289 return validateEditForm() && validateSpinners() && validateIPAuthentication();290 }291 });292 $('#newIngressTrunkWizard').bootstrapWizard({293 'nextSelector' : '.next',294 'previousSelector' : '.previous',295 onNext : function(tab, navigation, index) {296 if(index == 2) return true;297 $('#newFormFinishBtn').addClass('disabled');298 299 if(validateNewForm() && validateSpinners() && validateIPAuthentication()) {300 if (index == 1) {301 $('#newFormFinishBtn').removeClass('disabled');302 }303 304 return true;305 }306 307 return false;308 },309 onPrevious : function(tab, navigation, index) {310 $('#newFormFinishBtn').addClass('disabled');311 return true;312 },313 onTabClick: function(tab, navigation, index) {314 return false;315 }316 });317 };318 var validateSpinners = function() {319 var isValid = true;320 $.each([$call_limit_spinner, $cps_limit_spinner, $profit_margin_value_spinner,321 $profit_margin_pc_spinner, $try_timeout_spinner, $pdd_timeout_spinner,322 $ring_timeout_spinner, $decimal_points_spinner, $max_duration_spinner,323 $max_cost_spinner], function(i, $el) {324 var errorMsg = '';325 var value = $el.spinner("value");326 var min = $el.spinner("option", "min");327 var max = $el.spinner("option", "max");328 var id = $el.attr('id');329 330 if($el.is(':visible')) {331 if(value == null){332 errorMsg = 'Please input a number.';333 isValid = false; 334 }335 else if($.inArray(i, [0, 1, 4, 5, 6, 7, 8]) >= 0 && /\D/.test(value)) {336 errorMsg = 'Please input a integer value.';337 isValid = false; 338 }339 else if(i == 2 && !(/^\-?[0-9]+$/.test(value))) {340 errorMsg = 'Please input a integer value.';341 isValid = false; 342 }343 else {344 if(value < min || value > max) {345 errorMsg = 'Please select the value that lie between ' + min + ' to ' + max + '.';346 isValid = false;347 } 348 }349 } 350 351 if(errorMsg != '') {352 $('#'+id+'_error').html(errorMsg);353 $('.'+id+'_group').removeClass('has-success').addClass('has-error'); 354 }355 else {356 $('#'+id+'_error').html('');357 $('.'+id+'_group').removeClass('has-error'); 358 }359 });360 361 return isValid;362 }363 var validateIPAuthentication = function() {364 if($('#ingress_trunk_ingress_type').val() != '1') return true;365 366 var error = false;367 var postData = new Array();368 369 if($("span#ip_auth_fields .fields").length < 1) {370 $('.settings-err-msg').html('Please add atleast one host.').show();371 return false;372 }373 $("span#ip_auth_fields .fields").each(function() {374 $('.settings-err-msg').hide();375 $ip_address = $(this).find('.ip_address');376 $subnet = $(this).find('.subnet');377 $port = $(this).find('.port');378 postData.push([$ip_address.val(), $subnet.val(), $port.val()]);379 380 $ip_address.removeClass('settings-error');381 $subnet.removeClass('settings-error');382 $port.removeClass('settings-error');383 if($.trim($ip_address.val()) == '' || !( /^(([1-9]?\d|1\d\d|2[0-5][0-5]|2[0-4]\d)\.){3}([1-9]?\d|1\d\d|2[0-5][0-5]|2[0-4]\d)$/i.test($ip_address.val()))) {384 $ip_address.addClass('settings-error');385 error = true;386 }387 if($.trim($subnet.val()) == '' || !(/^\d+$/.test($subnet.val())) || parseInt($subnet.val()) < 0 || parseInt($subnet.val()) > 32) {388 $subnet.addClass('settings-error');389 error = true;390 }391 if($.trim($port.val()) == '' || !(/^\d+$/.test($port.val())) || parseInt($port.val()) < 0 || parseInt($port.val()) > 65535) {392 $port.addClass('settings-error');393 error = true;394 }395 });396 if(error) {397 $('.settings-err-msg').html('Please fix the error(s) for field(s) marked in red. Hover over fields to check valid values.').show();398 }399 else {400 $.ajax({401 type: "POST",402 async: false,403 url: urls[2],404 data: {'data': postData, 'id': $('#ingress_trunk_id').val()},405 dataType: 'json',406 success: function(response) {407 if(response.length == 0) {408 error = false;409 }410 else {411 $('.settings-err-msg').html('Row(s) '+ response.join(', ') +' already exists with us. The combination of Host, Subnet and Port should be unique.').show();412 error = true; 413 }414 },415 error: function() {416 error = true;417 }418 });419 }420 return !error;421 };422 var validateNewForm = function() {423 var $valid = $('#newIngressTrunkForm').valid();424 425 if (!$valid) {426 $newFormValidator.focusInvalid();427 return false;428 }429 430 return true;431 };432 var validateEditForm = function() {433 var $valid = $('#editIngressTrunkForm').valid();434 435 if (!$valid) {436 $editFormValidator.focusInvalid();437 return false;438 }439 440 return true;441 };442 var resetSpinnersTo = function(values) {443 $call_limit_spinner.spinner("value", values[0]);444 $cps_limit_spinner.spinner("value", values[1]);445 $profit_margin_value_spinner.spinner("value", values[2]);446 $profit_margin_pc_spinner.spinner("value", values[3]);447 $try_timeout_spinner.spinner("value", values[4]);448 $pdd_timeout_spinner.spinner("value", values[5]);449 $ring_timeout_spinner.spinner("value", values[6]);450 $decimal_points_spinner.spinner("value", values[7]);451 $max_duration_spinner.spinner("value", values[8]);452 $max_cost_spinner.spinner("value", values[9]);453 };454 var setUrls = function(arr) {455 urls = arr;456 }457 return {458 init: init,459 setUrls: setUrls,460 resetSpinnersTo: resetSpinnersTo461 };462 463 })(jQuery);464 App.AdminIngressTrunkListHandler = (function($) {465 var urls, destroy_trunk, disable_trunk, enable_trunk,466 bulk_operation = false; 467 var init = function(options) {468 $(document).on('click', 'a.close_modal', function() {469 $(this).parents('.modal').modal('hide'); 470 bulk_operation = false;471 });472 $("#carrier_select").select2({473 width: '225px'474 }).on('change', function() {475 $('#ingress_trunks_table').DataTable().columns(2).search($(this).val()).draw();476 });477 if(options[0] > 0) {478 $("#carrier_select").select2('val', options[0]);479 }480 $("div.checkbox_toggler_container").on('click', '.result_select_all', function() {481 $("div.ingress-trunks-container input.trunk-cb:checkbox:not(:checked)").attr('checked', true); 482 toggleGroupButtons();483 });484 485 $("div.checkbox_toggler_container").on('click', '.result_deselect_all', function() {486 $("div.ingress-trunks-container input.trunk-cb:checkbox:checked").attr('checked', false);487 toggleGroupButtons();488 });489 490 $("div.checkbox_toggler_container").on('click', '.result_invert_sel', function() {491 $("div.ingress-trunks-container input.trunk-cb:checkbox").click();492 toggleGroupButtons();493 });494 $("div.ingress-trunks-container").on('click', 'input.trunk-cb:checkbox', function() {495 toggleGroupButtons();496 });497 $('table#ingress_trunks_table').on('click', '.trunk_destroy', function() {498 destroy_trunk = $(this).data('trunk-id');499 $('.delete-trunk-confirm-dlg').modal('show');500 return false;501 });502 $('#del_trunk_confirm_ok').click(function () {503 if(bulk_operation) {504 $('form#selected_trunks_form').submit();505 }506 else {507 var link = "a#trunk_" + destroy_trunk + "_destroy_link";508 $(link).click();509 }510 511 $('.delete-trunk-confirm-dlg').modal('hide');512 bulk_operation = false;513 });514 $('table#ingress_trunks_table').on('click', '.trunk_disable', function() {515 disable_trunk = $(this).data('trunk-id');516 $('.disable-trunk-confirm-dlg').modal('show');517 return false;518 });519 $('#disable_trunk_confirm_ok').click(function () {520 if(bulk_operation) {521 $('form#selected_trunks_form').submit();522 }523 else {524 var link = "a#trunk_" + disable_trunk + "_disable_link";525 $(link).click(); 526 }527 528 $('.disable-trunk-confirm-dlg').modal('hide');529 bulk_operation = false;530 });531 $('table#ingress_trunks_table').on('click', '.trunk_enable', function() {532 enable_trunk = $(this).data('trunk-id');533 $('.enable-trunk-confirm-dlg').modal('show');534 return false;535 });536 $('#enable_trunk_confirm_ok').click(function () {537 if(bulk_operation) {538 $('form#selected_trunks_form').submit();539 }540 else {541 var link = "a#trunk_" + enable_trunk + "_enable_link";542 $(link).click();543 }544 $('.enable-trunk-confirm-dlg').modal('hide');545 bulk_operation = false;546 });547 $('button.btn_change_all_status').click(function() {548 bulk_operation = true;549 $('form#selected_trunks_form').attr('action', $(this).data('url'));550 });551 $('#ingress_trunks_table').DataTable({552 resposive: true,553 /*"sDom": '<"top"l>rt<"bottom"ip><"clear">',*/554 "lengthMenu": [ [5, 10, 25, 50, 100, -1], [5, 10, 25, 50, 100, "All"] ],555 "displayLength": 25,556 "columnDefs":[557 {558 "targets" : 'no-sort',559 "orderable" : false,560 },561 {562 "targets": 0,563 "createdCell": function (td, cellData, rowData, row, col) {564 $(td).addClass('text-center').html('<input type="checkbox" name="ingress_trunk_ids[]" class="trunk-cb" value="'+ cellData +'">');565 }566 },567 {568 "targets": 5,569 "createdCell": function (td, cellData, rowData, row, col) {570 if(cellData) {571 $(td).html('<span class="label label-success">Activated</span>');572 }573 else {574 $(td).html('<span class="label label-warning">Deactivated</span>');575 }576 }577 },578 {579 "targets": 6,580 "createdCell": function (td, cellData, rowData, row, col) {581 innerHtml = '';582 if(cellData[4]) {583 if(cellData[0]) {584 innerHtml += ' <a href="#" rel="nofollow" data-trunk-id="'+ rowData[0] +'" title="Deactivate" class="btn btn-warning btn-xs trunk_disable"><span class="glyphicon glyphicon-lock"></a> ';585 innerHtml += ' <a href="/ingress_trunks/'+ rowData[0] +'/deactivate" rel="nofollow" data-remote="true" data-method="put" id="trunk_'+ rowData[0] +'_disable_link"></a>'; 586 }587 }588 else {589 if(cellData[1]) {590 innerHtml += ' <a href="#" rel="nofollow" data-trunk-id="'+ rowData[0] +'" title="Activate" class="btn btn-primary btn-xs trunk_enable"><span class="glyphicon glyphicon-check"></a> ';591 innerHtml += ' <a href="/ingress_trunks/'+ rowData[0] +'/activate" rel="nofollow" data-remote="true" data-method="put" id="trunk_'+ rowData[0] +'_enable_link"></a>'; 592 }593 594 }595 596 if(cellData[2]) {597 innerHtml += ' <a class="btn btn-default btn-xs" title="Modify" href="/ingress_trunks/'+ rowData[0] +'/edit"><span class="glyphicon glyphicon-edit"></span></a>'; 598 }599 600 if(cellData[3]) {601 innerHtml += ' <a href="#" rel="nofollow" data-trunk-id="'+ rowData[0] +'" title="Delete" class="btn btn-danger btn-xs trunk_destroy"><span class="glyphicon glyphicon-trash"></span></a> ';602 innerHtml += ' <a href="/ingress_trunks/'+ rowData[0] +'" rel="nofollow" data-remote="true" data-method="delete" id="trunk_'+ rowData[0] +'_destroy_link"></a>'; 603 }604 605 $(td).html(innerHtml);606 }607 }608 ],609 "order": [[ 1, "desc" ]],610 "processing": true,611 "serverSide": true,612 "deferLoading": true,613 "ajax": {614 url: urls[0],615 method: 'post',616 data: {617 page: function() {618 return $('#ingress_trunks_table').DataTable().page.info().page + 1;619 }620 } 621 },622 "language": {623 "paginate": {624 "previous": "<<",625 "next": ">>"626 },627 "processing": "Processing... " + window.ajax_loader628 },629 "fnDrawCallback": function() { 630 var paginateRow = $(this).parent().children('div.dataTables_paginate');631 var pageCount = Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength);632 633 if (pageCount > 1) {634 paginateRow.css("display", "block");635 } else {636 paginateRow.css("display", "none");637 }638 $(this).find('input.trunk-cb:checkbox').attr('checked', false);639 toggleGroupButtons();640 }641 });642 };643 var toggleGroupButtons = function() {644 if ($("div.ingress-trunks-container input.trunk-cb:checkbox:checked").length > 0) {645 $('button.btn_change_all_status, #btn_remove_all').removeClass('disabled'); 646 } 647 else {648 $('button.btn_change_all_status, #btn_remove_all').addClass('disabled');649 }650 };651 var setUrls = function(arr) {652 urls = arr;653 }654 return {655 init: init,656 setUrls: setUrls657 };658 659 })(jQuery);660 App.CarrierIngressTrunkFormHandler = (function($) {661 var urls, dirtyValues;662 var $call_limit_spinner, $cps_limit_spinner;663 var init = function(toggleStatuses) {664 $(".select2").select2({665 width: '75%'666 });667 $('span#ip_auth_fields').on('keyup', 'input[type="text"]', function() {668 console.log('Values changed...');669 dirtyValues[3] = true;670 });671 $('#ingress_trunk_ingress_type').select2({672 width: '75%'673 }).on('change', function() {674 var val = $(this).val();675 if(val == '0') {676 $('span#registration_fields').show();677 $('span#ip_auth_fields').hide();678 }679 else if(val == '1') {680 $('span#registration_fields').hide();681 $('span#ip_auth_fields').show();682 }683 else {684 $('span#registration_fields').hide();685 $('span#ip_auth_fields').hide();686 }687 });688 $(document).on('nested:fieldRemoved', function(event){689 event.field.removeClass('fields');690 691 $('.add_nested_fields').removeClass('disabled');692 693 if($('div.fields').filter(":visible").length < 1) {694 $('table#host_headings').hide();695 $('div#add_host_warning').show();696 }697 dirtyValues[3] = true;698 });699 $(document).on('nested:fieldAdded', function(event){700 if($("span#ip_auth_fields .fields").length >= 12) {701 $('.add_nested_fields').addClass('disabled');702 }703 $('table#host_headings').show();704 $('div#add_host_warning').hide();705 $('.tooltips').tooltip({ container: 'body'});706 dirtyValues[3] = true;707 });708 $('.generate_random').click( function(){709 $(this).siblings('.form-control').val(randomAlphaString(10));710 });711 $('.cancel-form').click(function(e) {712 window.location.href = urls[0];713 return false;714 });715 $call_limit_spinner = $('#call_limit_spinner').spinner({716 numberFormat: "n",717 step: 10,718 min: 0,719 max: 10000,720 value: 0721 }).spinner('disable');722 $cps_limit_spinner = $('#cps_limit_spinner').spinner({723 numberFormat: "n",724 step: 5,725 min: 0,726 max: 500,727 value: 0728 }).spinner('disable');729 $("#media_bypass_activation_tgl").toggles({ on: toggleStatuses[1], checkbox: $("#media_bypass_tgl_chkbox"), 'event': 'toggle', text: {on: "Yes", off: "No"}});730 $("#lrn_block_activation_tgl").toggles({ drag:false, click: false, on: toggleStatuses[2], 'event': 'toggle', text: {on: "Yes", off: "No"}});731 $("#block_wireless_activation_tgl").toggles({ on: toggleStatuses[3], checkbox: $("#block_wireless_tgl_chkbox"), 'event': 'toggle', text: {on: "Yes", off: "No"}});732 $.validator.addMethod("cid", function(value, element) {733 return this.optional(element) || /^[\d\+]+$/.test(value);734 }, "Only digits and '+' sign is allowed");735 validationOptions = {736 debug : false,737 ignoreTitle: true,738 highlight : function(element) {739 $(element).closest('.form-group').removeClass('has-success').addClass('has-error');740 },741 success : function(element) {742 $(element).closest('.form-group').removeClass('has-error');743 },744 submitHandler : function(form) {745 // do other things for a valid form746 if (validateIPAuthentication()) {747 if(otpAuthRequired()) {748 App.OTPAuth.showDialog('trunk_update', function() {749 $('#otpid').val(App.OTPAuth.getOTPId());750 $('#otpcode').val(App.OTPAuth.getOTPCode()); 751 form.submit();752 });753 }754 else {755 form.submit(); 756 }757 }758 },759 errorPlacement: function(error, element) {760 if (element.attr("id") == "ingress_trunk_reg_user") {761 $("#rgn_username_error").html(error);762 }763 else if(element.attr("id") == "ingress_trunk_reg_password") {764 $("#rgn_password_error").html(error);765 }766 else {767 // the default error placement for the re768 error.insertAfter(element);769 }770 },771 rules : {772 "ingress_trunk[reg_user]": {773 required: function() {774 return $('#ingress_trunk_ingress_type').val() == '0'775 },776 minlength: 5,777 maxlength: 25,778 remote : {779 url : urls[3],780 type : "get"781 }782 },783 "ingress_trunk[reg_password]": {784 required: function() {785 return $('#ingress_trunk_ingress_type').val() == '0'786 },787 minlength: 5,788 maxlength: 25789 },790 "ingress_trunk[force_cid]": {791 cid: true792 }793 },794 messages : {795 "ingress_trunk[reg_user]" : {796 remote : "This username already exists with us."797 }798 }799 };800 $editFormValidator = $('#editIngressTrunkForm').validate($.extend(true, {}, validationOptions, {801 rules: {802 "ingress_trunk[reg_user]": {remote: {803 data: {id: $('#ingress_trunk_id').val()}804 }}805 }806 }));807 $('#editIngressTrunkWizard').bootstrapWizard({808 'nextSelector' : '.next',809 'previousSelector' : '.previous',810 onNext : function(tab, navigation, index) {811 if(index == 2) return true;812 return validateEditForm() && validateIPAuthentication();813 },814 onPrevious : function(tab, navigation, index) {815 return validateEditForm();816 },817 onTabClick: function(tab, navigation, index) {818 return validateEditForm() && validateIPAuthentication();819 }820 });821 };822 var otpAuthRequired = function() {823 if($('#ingress_trunk_ingress_type').val() != dirtyValues[0]) {824 console.log('ingress type changed.');825 return true;826 }827 if($('#ingress_trunk_ingress_type').val() == '0') {828 if($.trim($('#ingress_trunk_reg_user').val()) != dirtyValues[1]) {829 console.log('username is changed.');830 return true;831 }832 if($.trim($('#ingress_trunk_reg_password').val()) != dirtyValues[2]) {833 console.log('password is changed.');834 return true;835 } 836 }837 else {838 if(dirtyValues[3]) {839 console.log('host changed.');840 return true;841 }842 }843 return false;844 }845 var setDirtyValues = function(values) {846 dirtyValues = values;847 }848 var validateIPAuthentication = function() {849 if($('#ingress_trunk_ingress_type').val() != '1') return true;850 851 var error = false;852 var postData = new Array();853 854 if($("span#ip_auth_fields .fields").length < 1) {855 $('.settings-err-msg').html('Please add atleast one host.').show();856 return false;857 }858 $("span#ip_auth_fields .fields").each(function() {859 $('.settings-err-msg').hide();860 $ip_address = $(this).find('.ip_address');861 $subnet = $(this).find('.subnet');862 $port = $(this).find('.port');863 postData.push([$ip_address.val(), $subnet.val(), $port.val()]);864 865 $ip_address.removeClass('settings-error');866 $subnet.removeClass('settings-error');867 $port.removeClass('settings-error');868 if($.trim($ip_address.val()) == '' || !( /^(([1-9]?\d|1\d\d|2[0-5][0-5]|2[0-4]\d)\.){3}([1-9]?\d|1\d\d|2[0-5][0-5]|2[0-4]\d)$/i.test($ip_address.val()))) {869 $ip_address.addClass('settings-error');870 error = true;871 }872 if($.trim($subnet.val()) == '' || !(/^\d+$/.test($subnet.val())) || parseInt($subnet.val()) < 0 || parseInt($subnet.val()) > 32) {873 $subnet.addClass('settings-error');874 error = true;875 }876 877 if($.trim($port.val()) == '' || !(/^\d+$/.test($port.val())) || parseInt($port.val()) < 0 || parseInt($port.val()) > 65535) {878 $port.addClass('settings-error');879 error = true;880 }881 });882 if(error) {883 $('.settings-err-msg').html('Please fix the error(s) for field(s) marked in red. Hover over fields to check valid values.').show();884 }885 else {886 $.ajax({887 type: "POST",888 async: false,889 url: urls[2],890 data: {'data': postData, 'id': $('#ingress_trunk_id').val()},891 dataType: 'json',892 success: function(response) {893 if(response.length == 0) {894 error = false;895 }896 else {897 $('.settings-err-msg').html('Row(s) '+ response.join(', ') +' already exists with us. The combination of Host, Subnet and Port should be unique.').show();898 error = true; 899 }900 },901 error: function() {902 error = true;903 }904 });905 }906 return !error;907 };908 var validateEditForm = function() {909 var $valid = $('#editIngressTrunkForm').valid();910 911 if (!$valid) {912 $editFormValidator.focusInvalid();913 return false;914 }915 916 return true;917 };918 var resetSpinnersTo = function(values) {919 $call_limit_spinner.spinner("value", values[0]);920 $cps_limit_spinner.spinner("value", values[1]);921 };922 var setUrls = function(arr) {923 urls = arr;924 }925 return {926 init: init,927 setUrls: setUrls,928 resetSpinnersTo: resetSpinnersTo,929 setDirtyValues: setDirtyValues930 };931 932 })(jQuery);933 App.CarrierIngressTrunkListHandler = (function($) {934 var urls, destroy_trunk, disable_trunk, enable_trunk,935 bulk_operation = false;936 var init = function(toggleStatuses) {937 $(document).on('click', 'a.close_modal', function() {938 $(this).parents('.modal').modal('hide'); 939 bulk_operation = false;940 });941 $("div.checkbox_toggler_container").on('click', '.result_select_all', function() {942 $("div.ingress-trunks-container input.trunk-cb:checkbox:not(:checked)").attr('checked', true); 943 toggleGroupButtons();944 });945 946 $("div.checkbox_toggler_container").on('click', '.result_deselect_all', function() {947 $("div.ingress-trunks-container input.trunk-cb:checkbox:checked").attr('checked', false);948 toggleGroupButtons();949 });950 951 $("div.checkbox_toggler_container").on('click', '.result_invert_sel', function() {952 $("div.ingress-trunks-container input.trunk-cb:checkbox").click();953 toggleGroupButtons();954 });955 $("div.ingress-trunks-container").on('click', 'input.trunk-cb:checkbox', function() {956 toggleGroupButtons();957 });958 $('table#ingress_trunks_table').on('click', '.trunk_disable', function() {959 disable_trunk = $(this).data('trunk-id');960 $('.disable-trunk-confirm-dlg').modal('show');961 return false;962 });963 $('#disable_trunk_confirm_ok').click(function () {964 if(bulk_operation) {965 App.OTPAuth.showDialog('trunk_bulk_actdeact', function() {966 $('#otpid').val(App.OTPAuth.getOTPId());967 $('#otpcode').val(App.OTPAuth.getOTPCode()); 968 $('form#selected_trunks_form').submit();969 App.OTPAuth.hideDialog();970 });971 }972 else {973 var link = "a#trunk_" + disable_trunk + "_disable_link";974 App.OTPAuth.showDialog('trunk_act_deact', function() {975 var data = {otpid: App.OTPAuth.getOTPId(), 976 otpcode: App.OTPAuth.getOTPCode()};977 978 $(link).attr('href', $(link).attr('href') + "?" + jQuery.param(data));979 $(link).click();980 981 App.OTPAuth.hideDialog();982 });983 }984 985 $('.disable-trunk-confirm-dlg').modal('hide');986 bulk_operation = false;987 });988 $('table#ingress_trunks_table').on('click', '.trunk_enable', function() {989 enable_trunk = $(this).data('trunk-id');990 $('.enable-trunk-confirm-dlg').modal('show');991 return false;992 });993 $('#enable_trunk_confirm_ok').click(function () {994 if(bulk_operation) {995 App.OTPAuth.showDialog('trunk_bulk_actdeact', function() {996 $('#otpid').val(App.OTPAuth.getOTPId());997 $('#otpcode').val(App.OTPAuth.getOTPCode()); 998 $('form#selected_trunks_form').submit();999 App.OTPAuth.hideDialog();1000 });1001 }1002 else {1003 var link = "a#trunk_" + enable_trunk + "_enable_link";1004 App.OTPAuth.showDialog('trunk_act_deact', function() {1005 var data = {otpid: App.OTPAuth.getOTPId(), 1006 otpcode: App.OTPAuth.getOTPCode()};1007 1008 $(link).attr('href', $(link).attr('href') + "?" + jQuery.param(data));1009 $(link).click();1010 1011 App.OTPAuth.hideDialog();1012 });1013 }1014 $('.enable-trunk-confirm-dlg').modal('hide');1015 bulk_operation = false;1016 });1017 $('button.btn_change_all_status').click(function() {1018 bulk_operation = true;1019 $('form#selected_trunks_form').attr('action', $(this).data('url'));1020 });1021 $('#ingress_trunks_table').DataTable({1022 resposive: true,1023 /*"sDom": '<"top"l>rt<"bottom"ip><"clear">',*/1024 "lengthMenu": [ [5, 10, 25, 50, 100, -1], [5, 10, 25, 50, 100, "All"] ],1025 "columnDefs":[1026 {1027 "targets" : 'no-sort',1028 "orderable" : false,1029 },1030 {1031 "targets": 0,1032 "createdCell": function (td, cellData, rowData, row, col) {1033 $(td).addClass('text-center').html('<input type="checkbox" name="ingress_trunk_ids[]" class="trunk-cb" value="'+ cellData +'">');1034 }1035 },1036 {1037 "targets": 4,1038 "createdCell": function (td, cellData, rowData, row, col) {1039 if(cellData) {1040 $(td).html('<span class="label label-success">Activated</span>');1041 }1042 else {1043 $(td).html('<span class="label label-warning">Deactivated</span>');1044 }1045 }1046 },1047 {1048 "targets": 5,1049 "createdCell": function (td, cellData, rowData, row, col) {1050 innerHtml = '';1051 if(cellData[3]) {1052 if(cellData[0]) {1053 innerHtml += ' <a href="#" rel="nofollow" data-trunk-id="'+ rowData[0] +'" title="Deactivate" class="btn btn-warning btn-xs trunk_disable"><span class="glyphicon glyphicon-lock"></a> ';1054 innerHtml += ' <a href="/ingress_trunks/'+ rowData[0] +'/deactivate" rel="nofollow" data-remote="true" data-method="put" id="trunk_'+ rowData[0] +'_disable_link"></a>'; 1055 }1056 }1057 else {1058 if(cellData[1]) {1059 innerHtml += ' <a href="#" rel="nofollow" data-trunk-id="'+ rowData[0] +'" title="Activate" class="btn btn-primary btn-xs trunk_enable"><span class="glyphicon glyphicon-check"></a> ';1060 innerHtml += ' <a href="/ingress_trunks/'+ rowData[0] +'/activate" rel="nofollow" data-remote="true" data-method="put" id="trunk_'+ rowData[0] +'_enable_link"></a>'; 1061 }1062 }1063 1064 if(cellData[2]) {1065 innerHtml += ' <a class="btn btn-default btn-xs" title="Modify" href="/ingress_trunks/'+ rowData[0] +'/edit"><span class="glyphicon glyphicon-edit"></span></a>'; 1066 }1067 1068 $(td).html(innerHtml);1069 }1070 }1071 ],1072 "order": [[ 1, "desc" ]],1073 "processing": true,1074 "serverSide": true,1075 "ajax": {1076 url: urls[0],1077 method: 'post',1078 data: {1079 page: function() {1080 return $('#ingress_trunks_table').DataTable().page.info().page + 1;1081 }1082 } 1083 },1084 "language": {1085 "paginate": {1086 "previous": "<<",1087 "next": ">>"1088 },1089 "processing": "Processing... " + window.ajax_loader1090 },1091 "fnDrawCallback": function() { 1092 var paginateRow = $(this).parent().children('div.dataTables_paginate');1093 var pageCount = Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength);1094 1095 if (pageCount > 1) {1096 paginateRow.css("display", "block");1097 } else {1098 paginateRow.css("display", "none");1099 }1100 $(this).find('input.trunk-cb:checkbox').attr('checked', false);1101 toggleGroupButtons();1102 }1103 });1104 };1105 var toggleGroupButtons = function() {1106 if ($("div.ingress-trunks-container input.trunk-cb:checkbox:checked").length > 0) {1107 $('button.btn_change_all_status').removeClass('disabled'); 1108 } 1109 else {1110 $('button.btn_change_all_status').addClass('disabled');1111 }1112 };1113 var setUrls = function(arr) {1114 urls = arr;1115 }1116 return {1117 init: init,1118 setUrls: setUrls1119 };1120 1121 })(jQuery);1122 App.EgressTrunkFormHandler = (function($) {1123 var urls; 1124 var $call_limit_spinner, $cps_limit_spinner, $profit_margin_value_spinner,1125 $profit_margin_pc_spinner, $try_timeout_spinner, $pdd_timeout_spinner,1126 $ring_timeout_spinner, $decimal_points_spinner, $max_duration_spinner,1127 $max_cost_spinner, $top_down_depth_spinner;1128 var init = function(toggleStatuses) {1129 $(".select2").select2({1130 width: '75%'1131 });1132 $("#egress_trunk_routing_strategy").select2({1133 width: '75%',1134 }).on('change', function() {1135 var val = $(this).val();1136 $('#top_down_depth_cont').hide();1137 if(val == '1') {1138 $('#top_down_depth_cont').show();1139 }1140 });1141 $("#egress_trunk_profit_margin_type").select2({1142 width: '75%',1143 }).on('change', function() {1144 var val = $(this).val();1145 1146 if(val == '0') {1147 $('label#profit_margin_type_msg').hide();1148 $('#profit_margin_value_cont').show();1149 $('#profit_margin_pc_cont').hide();1150 }1151 else if(val == '1') {1152 $('label#profit_margin_type_msg').hide();1153 $('#profit_margin_value_cont').hide();1154 $('#profit_margin_pc_cont').show();1155 }1156 else {1157 $('label#profit_margin_type_msg').show();1158 $('#profit_margin_value_cont').hide();1159 $('#profit_margin_pc_cont').hide();1160 }1161 });1162 $(document).on('nested:fieldRemoved', function(event){1163 event.field.removeClass('fields');1164 1165 $('.add_nested_fields').removeClass('disabled');1166 1167 if($('div.fields').filter(":visible").length < 1) {1168 $('table#host_headings').hide();1169 $('div#add_host_warning').show();1170 }1171 });1172 $(document).on('nested:fieldAdded', function(event){1173 if($("span#ip_auth_fields .fields").length >= 12) {1174 $('.add_nested_fields').addClass('disabled');1175 }1176 $('table#host_headings').show();1177 $('div#add_host_warning').hide();1178 $('.tooltips').tooltip({ container: 'body'});1179 });1180 $('.cancel-form').click(function(e) {1181 window.location.href = urls[0];1182 return false;1183 });1184 $top_down_depth_spinner = $('#top_down_depth_spinner').spinner({1185 numberFormat: "n",1186 step: 1,1187 min: 0,1188 max: 10,1189 value: 01190 });1191 $call_limit_spinner = $('#call_limit_spinner').spinner({1192 numberFormat: "n",1193 step: 10,1194 min: 0,1195 max: 10000,1196 value: 01197 });1198 $cps_limit_spinner = $('#cps_limit_spinner').spinner({1199 numberFormat: "n",1200 step: 5,1201 min: 0,1202 max: 500,1203 value: 01204 });1205 $profit_margin_value_spinner = $('#profit_margin_value_spinner').spinner({1206 numberFormat: "n",1207 step: 1,1208 min: -500,1209 max: 500,1210 value: 01211 });1212 $profit_margin_pc_spinner = $('#profit_margin_pc_spinner').spinner({1213 numberFormat: "n",1214 step: 0.01,1215 min: -1,1216 max: 1,1217 value: 01218 });1219 $try_timeout_spinner = $('#try_timeout_spinner').spinner({1220 numberFormat: "n",1221 step: 1,1222 min: 1,1223 max: 60,1224 value: 21225 });1226 $pdd_timeout_spinner = $('#pdd_timeout_spinner').spinner({1227 numberFormat: "n",1228 step: 1,1229 min: 1,1230 max: 60,1231 value: 61232 });1233 $ring_timeout_spinner = $('#ring_timeout_spinner').spinner({1234 numberFormat: "n",1235 step: 1,1236 min: 1,1237 max: 120,1238 value: 601239 });1240 $decimal_points_spinner = $('#decimal_points_spinner').spinner({1241 numberFormat: "n",1242 step: 1,1243 min: 2,1244 max: 8,1245 value: 41246 });1247 $max_duration_spinner = $('#max_duration_spinner').spinner({1248 numberFormat: "n",1249 step: 100,1250 min: 60,1251 max: 7200,1252 value: 72001253 });1254 $max_cost_spinner = $('#max_cost_spinner').spinner({1255 numberFormat: "n",1256 step: 0.01,1257 min: 0,1258 max: 1,1259 value: 01260 });1261 $("#siptrace_activation_tgl").toggles({ on: toggleStatuses[0], checkbox: $("#sip_trace_tgl_chkbox"), 'event': 'toggle', text: {on: "Yes", off: "No"}});1262 $("#media_bypass_activation_tgl").toggles({ on: toggleStatuses[1], checkbox: $("#media_bypass_tgl_chkbox"), 'event': 'toggle', text: {on: "Yes", off: "No"}});1263 $("#lrn_block_activation_tgl").toggles({ on: toggleStatuses[2], checkbox: $("#lrn_block_tgl_chkbox"), 'event': 'toggle', text: {on: "Yes", off: "No"}});1264 $("#block_wireless_activation_tgl").toggles({ on: toggleStatuses[3], checkbox: $("#block_wireless_tgl_chkbox"), 'event': 'toggle', text: {on: "Yes", off: "No"}});1265 $.validator.addMethod("cid", function(value, element) {1266 return this.optional(element) || /^[\d\+]+$/.test(value);1267 }, "Only digits and '+' sign is allowed");1268 $.validator.addMethod("techprefix", function(value, element) {1269 return this.optional(element) || /^[\d#]+$/.test(value);1270 }, "Only digits and '#' is allowed");1271 validationOptions = {1272 debug : false,1273 ignoreTitle: true,1274 highlight : function(element) {1275 $(element).closest('.form-group').removeClass('has-success').addClass('has-error');1276 },1277 success : function(element) {1278 $(element).closest('.form-group').removeClass('has-error');1279 },1280 submitHandler : function(form) {1281 // do other things for a valid form1282 if (validateSpinners() && validateIPAuthentication()) {1283 form.submit();1284 }1285 },1286 rules : {1287 "egress_trunk[carrier_id]": {1288 required: true,1289 digits: true1290 },1291 "egress_trunk[rate_sheet_id]": {1292 required: true,1293 digits: true1294 },1295 "egress_trunk[tech_prefix]": {1296 techprefix: true1297 },1298 "egress_trunk[profit_margin_type]": {1299 required: true,1300 digits: true1301 },1302 "eggress_trunk[force_cid]": {1303 cid: true1304 },1305 "egress_trunk[name]" : {1306 required : true,1307 minlength: 3,1308 maxlength: 25,1309 remote : {1310 url : urls[1],1311 type : "get",1312 }1313 }1314 },1315 messages : {1316 "egress_trunk[name]" : {1317 remote : "This trunk name already exists with us."1318 }1319 }1320 };1321 $editFormValidator = $('#editEgressTrunkForm').validate($.extend(true, {}, validationOptions, {1322 rules: {1323 "egress_trunk[name]": {remote: {1324 data: {id: $('#egress_trunk_id').val()}1325 }},1326 }1327 }));1328 1329 $newFormValidator = $('#newEgressTrunkForm').validate($.extend(true, {}, validationOptions, {}));1330 $('#editEgressTrunkWizard').bootstrapWizard({1331 'nextSelector' : '.next',1332 'previousSelector' : '.previous',1333 onNext : function(tab, navigation, index) {1334 if(index == 2) return true;1335 return validateEditForm() && validateIPAuthentication();1336 },1337 onPrevious : function(tab, navigation, index) {1338 return validateEditForm() && validateSpinners();1339 },1340 onTabClick: function(tab, navigation, index) {1341 return validateEditForm() && validateSpinners() && validateIPAuthentication();1342 }1343 });1344 $('#newEgressTrunkWizard').bootstrapWizard({1345 'nextSelector' : '.next',1346 'previousSelector' : '.previous',1347 onNext : function(tab, navigation, index) {1348 if(index == 2) return true;1349 $('#newFormFinishBtn').addClass('disabled');1350 1351 if(validateNewForm() && validateSpinners() && validateIPAuthentication()) {1352 if (index == 1) {1353 $('#newFormFinishBtn').removeClass('disabled');1354 }1355 1356 return true;1357 }1358 1359 return false;1360 },1361 onPrevious : function(tab, navigation, index) {1362 $('#newFormFinishBtn').addClass('disabled');1363 return true;1364 },1365 onTabClick: function(tab, navigation, index) {1366 return false;1367 }1368 });1369 };1370 var validateSpinners = function() {1371 var isValid = true;1372 $.each([$call_limit_spinner, $cps_limit_spinner, $profit_margin_value_spinner,1373 $profit_margin_pc_spinner, $try_timeout_spinner, $pdd_timeout_spinner,1374 $ring_timeout_spinner, $decimal_points_spinner, $max_duration_spinner,1375 $max_cost_spinner, $top_down_depth_spinner], function(i, $el) {1376 var errorMsg = '';1377 var value = $el.spinner("value");1378 var min = $el.spinner("option", "min");1379 var max = $el.spinner("option", "max");1380 var id = $el.attr('id');1381 1382 if($el.is(':visible')) {1383 if(value == null){1384 errorMsg = 'Please input a number.';1385 isValid = false; 1386 }1387 else if($.inArray(i, [0, 1, 4, 5, 6, 7, 8, 10]) >= 0 && /\D/.test(value)) {1388 errorMsg = 'Please input a integer value.';1389 isValid = false; 1390 }1391 else if(i == 2 && !(/^\-?[0-9]+$/.test(value))) {1392 errorMsg = 'Please input a integer value.';1393 isValid = false; 1394 }1395 else {1396 if(value < min || value > max) {1397 errorMsg = 'Please select the value that lie between ' + min + ' to ' + max + '.';1398 isValid = false;1399 } 1400 }1401 } 1402 1403 if(errorMsg != '') {1404 $('#'+id+'_error').html(errorMsg);1405 $('.'+id+'_group').removeClass('has-success').addClass('has-error'); 1406 }1407 else {1408 $('#'+id+'_error').html('');1409 $('.'+id+'_group').removeClass('has-error'); 1410 }1411 });1412 1413 return isValid;1414 }1415 var validateIPAuthentication = function() {1416 var error = false;1417 var postData = new Array();1418 1419 if($("span#ip_auth_fields .fields").length < 1) {1420 $('.settings-err-msg').html('Please add atleast one host.').show();1421 return false;1422 }1423 $("span#ip_auth_fields .fields").each(function() {1424 $('.settings-err-msg').hide();1425 $ip_address = $(this).find('.ip_address');1426 $subnet = $(this).find('.subnet');1427 $port = $(this).find('.port');1428 postData.push([$ip_address.val(), $subnet.val(), $port.val()]);1429 1430 $ip_address.removeClass('settings-error');1431 $subnet.removeClass('settings-error');1432 $port.removeClass('settings-error');1433 if($.trim($ip_address.val()) == '' || !( /^(([1-9]?\d|1\d\d|2[0-5][0-5]|2[0-4]\d)\.){3}([1-9]?\d|1\d\d|2[0-5][0-5]|2[0-4]\d)$/i.test($ip_address.val()))) {1434 $ip_address.addClass('settings-error');1435 error = true;1436 }1437 if($.trim($subnet.val()) == '' || !(/^\d+$/.test($subnet.val())) || parseInt($subnet.val()) < 0 || parseInt($subnet.val()) > 32) {1438 $subnet.addClass('settings-error');1439 error = true;1440 }1441 if($.trim($port.val()) == '' || !(/^\d+$/.test($port.val())) || parseInt($port.val()) < 0 || parseInt($port.val()) > 65535) {1442 $port.addClass('settings-error');1443 error = true;1444 }1445 });1446 if(error) {1447 $('.settings-err-msg').html('Please fix the error(s) for field(s) marked in red. Hover over fields to check valid values.').show();1448 }1449 else {1450 $.ajax({1451 type: "POST",1452 async: false,1453 url: urls[2],1454 data: {'data': postData, 'id': $('#egress_trunk_id').val()},1455 dataType: 'json',1456 success: function(response) {1457 if(response.length == 0) {1458 error = false;1459 }1460 else {1461 $('.settings-err-msg').html('Row(s) '+ response.join(', ') +' already exists with us. The combination of Host, Subnet and Port should be unique.').show();1462 error = true; 1463 }1464 },1465 error: function() {1466 error = true;1467 }1468 });1469 }1470 return !error;1471 };1472 var validateNewForm = function() {1473 var $valid = $('#newEgressTrunkForm').valid();1474 1475 if (!$valid) {1476 $newFormValidator.focusInvalid();1477 return false;1478 }1479 1480 return true;1481 };1482 var validateEditForm = function() {1483 var $valid = $('#editEgressTrunkForm').valid();1484 1485 if (!$valid) {1486 $editFormValidator.focusInvalid();1487 return false;1488 }1489 1490 return true;1491 };1492 var resetSpinnersTo = function(values) {1493 $call_limit_spinner.spinner("value", values[0]);1494 $cps_limit_spinner.spinner("value", values[1]);1495 $profit_margin_value_spinner.spinner("value", values[2]);1496 $profit_margin_pc_spinner.spinner("value", values[3]);1497 $try_timeout_spinner.spinner("value", values[4]);1498 $pdd_timeout_spinner.spinner("value", values[5]);1499 $ring_timeout_spinner.spinner("value", values[6]);1500 $decimal_points_spinner.spinner("value", values[7]);1501 $max_duration_spinner.spinner("value", values[8]);1502 $max_cost_spinner.spinner("value", values[9]);1503 $top_down_depth_spinner.spinner("value", values[10]);1504 };1505 var setUrls = function(arr) {1506 urls = arr;1507 }1508 return {1509 init: init,1510 setUrls: setUrls,1511 resetSpinnersTo: resetSpinnersTo1512 };1513 1514 })(jQuery);1515 App.EgressTrunkListHandler = (function($) {1516 var urls, destroy_trunk, disable_trunk, enable_trunk,1517 bulk_operation = false; 1518 var init = function(options) {1519 $(document).on('click', 'a.close_modal', function() {1520 $(this).parents('.modal').modal('hide'); 1521 bulk_operation = false;1522 });1523 $("#carrier_select").select2({1524 width: '225px'1525 }).on('change', function() {1526 $('#egress_trunks_table').DataTable().columns(2).search($(this).val()).draw();1527 });1528 if(options[0] > 0) {1529 $("#carrier_select").select2('val', options[0]);1530 }1531 $("div.checkbox_toggler_container").on('click', '.result_select_all', function() {1532 $("div.egress-trunks-container input.trunk-cb:checkbox:not(:checked)").attr('checked', true); 1533 toggleGroupButtons();1534 });1535 1536 $("div.checkbox_toggler_container").on('click', '.result_deselect_all', function() {1537 $("div.egress-trunks-container input.trunk-cb:checkbox:checked").attr('checked', false);1538 toggleGroupButtons();1539 });1540 1541 $("div.checkbox_toggler_container").on('click', '.result_invert_sel', function() {1542 $("div.egress-trunks-container input.trunk-cb:checkbox").click();1543 toggleGroupButtons();1544 });1545 $("div.egress-trunks-container").on('click', 'input.trunk-cb:checkbox', function() {1546 toggleGroupButtons();1547 });1548 $('table#egress_trunks_table').on('click', '.trunk_destroy', function() {1549 destroy_trunk = $(this).data('trunk-id');1550 $('.delete-trunk-confirm-dlg').modal('show');1551 return false;1552 });1553 $('#del_trunk_confirm_ok').click(function () {1554 if(bulk_operation) {1555 $('form#selected_trunks_form').submit();1556 }1557 else {1558 var link = "a#trunk_" + destroy_trunk + "_destroy_link";1559 $(link).click(); 1560 }1561 1562 $('.delete-trunk-confirm-dlg').modal('hide');1563 bulk_operation = false;1564 });1565 $('table#egress_trunks_table').on('click', '.trunk_disable', function() {1566 disable_trunk = $(this).data('trunk-id');1567 $('.disable-trunk-confirm-dlg').modal('show');1568 return false;1569 });1570 $('#disable_trunk_confirm_ok').click(function () {1571 if(bulk_operation) {1572 $('form#selected_trunks_form').submit();1573 }1574 else {1575 var link = "a#trunk_" + disable_trunk + "_disable_link";1576 $(link).click(); 1577 }1578 1579 $('.disable-trunk-confirm-dlg').modal('hide');1580 bulk_operation = false;1581 });1582 $('table#egress_trunks_table').on('click', '.trunk_enable', function() {1583 enable_trunk = $(this).data('trunk-id');1584 $('.enable-trunk-confirm-dlg').modal('show');1585 return false;1586 });1587 $('#enable_trunk_confirm_ok').click(function () {1588 if(bulk_operation) {1589 $('form#selected_trunks_form').submit();1590 }1591 else {1592 var link = "a#trunk_" + enable_trunk + "_enable_link";1593 $(link).click();1594 }1595 $('.enable-trunk-confirm-dlg').modal('hide');1596 bulk_operation = false;1597 });1598 $('button.btn_change_all_status').click(function() {1599 bulk_operation = true;1600 $('form#selected_trunks_form').attr('action', $(this).data('url'));1601 });1602 $('#egress_trunks_table').DataTable({1603 resposive: true,1604 /*"sDom": '<"top"l>rt<"bottom"ip><"clear">',*/1605 "lengthMenu": [ [5, 10, 25, 50, 100, -1], [5, 10, 25, 50, 100, "All"] ],1606 "displayLength": 25,1607 "columnDefs":[1608 {1609 "targets" : 'no-sort',1610 "orderable" : false,1611 },1612 {1613 "targets": 0,1614 "createdCell": function (td, cellData, rowData, row, col) {1615 $(td).addClass('text-center').html('<input type="checkbox" name="egress_trunk_ids[]" class="trunk-cb" value="'+ cellData +'">');1616 }1617 },1618 {1619 "targets": 5,1620 "createdCell": function (td, cellData, rowData, row, col) {1621 innerHtml = '';1622 if(cellData) {1623 innerHtml += ' <a href="#" rel="nofollow" data-trunk-id="'+ rowData[0] +'" title="Deactivate" class="btn btn-warning btn-xs trunk_disable"><span class="glyphicon glyphicon-lock"></a> ';1624 innerHtml += ' <a href="/egress_trunks/'+ rowData[0] +'/deactivate" rel="nofollow" data-remote="true" data-method="put" id="trunk_'+ rowData[0] +'_disable_link"></a>';1625 }1626 else {1627 innerHtml += ' <a href="#" rel="nofollow" data-trunk-id="'+ rowData[0] +'" title="Activate" class="btn btn-primary btn-xs trunk_enable"><span class="glyphicon glyphicon-check"></a> ';1628 innerHtml += ' <a href="/egress_trunks/'+ rowData[0] +'/activate" rel="nofollow" data-remote="true" data-method="put" id="trunk_'+ rowData[0] +'_enable_link"></a>';1629 }1630 1631 innerHtml += ' <a class="btn btn-default btn-xs" title="Modify" href="/egress_trunks/'+ rowData[0] +'/edit"><span class="glyphicon glyphicon-edit"></span></a>';1632 innerHtml += ' <a href="#" rel="nofollow" data-trunk-id="'+ rowData[0] +'" title="Delete" class="btn btn-danger btn-xs trunk_destroy"><span class="glyphicon glyphicon-trash"></span></a> ';1633 innerHtml += ' <a href="/egress_trunks/'+ rowData[0] +'" rel="nofollow" data-remote="true" data-method="delete" id="trunk_'+ rowData[0] +'_destroy_link"></a>';1634 $(td).html(innerHtml);1635 }1636 }1637 ],1638 "order": [[ 1, "desc" ]],1639 "processing": true,1640 "serverSide": true,1641 "deferLoading": true,1642 "ajax": {1643 url: urls[0],1644 method: 'post',1645 data: {1646 page: function() {1647 return $('#egress_trunks_table').DataTable().page.info().page + 1;1648 }1649 } 1650 },1651 "language": {1652 "paginate": {1653 "previous": "<<",1654 "next": ">>"1655 },1656 "processing": "Processing... " + window.ajax_loader1657 },1658 "fnDrawCallback": function() { 1659 var paginateRow = $(this).parent().children('div.dataTables_paginate');1660 var pageCount = Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength);1661 1662 if (pageCount > 1) {1663 paginateRow.css("display", "block");1664 } else {1665 paginateRow.css("display", "none");1666 }1667 $(this).find('input.trunk-cb:checkbox').attr('checked', false);1668 toggleGroupButtons();1669 }1670 });1671 };1672 var toggleGroupButtons = function() {1673 if ($("div.egress-trunks-container input.trunk-cb:checkbox:checked").length > 0) {1674 $('button.btn_change_all_status, #btn_remove_all').removeClass('disabled'); 1675 } 1676 else {1677 $('button.btn_change_all_status, #btn_remove_all').addClass('disabled');1678 }1679 };1680 var setUrls = function(arr) {1681 urls = arr;1682 }1683 return {1684 init: init,1685 setUrls: setUrls1686 };1687 1688 })(jQuery);...
users.js
Source:users.js
1//= require bootstrap.min2//= require modernizr.min3//= require toggles.min4//= require retina.min5//= require jquery.cookies6//= require bootstrap-wizard.min7//= require jquery.validate.min8//= require select2.min9//= require jquery.datatables.min10//= require jquery.gritter.min11//= require custom12//= require_self13var App = App || {};14jQuery(document).ready(function() {15 App.UserFormHandler = (function($) {16 var urls;17 var init = function() {18 $(".select2").select2({19 width: '100%',20 });21 $('#cancelForm').click(function(e) {22 e.preventDefault();23 document.location.href="/users";24 });25 $.validator.addMethod("passwordRules", function(value, element) {26 return this.optional(element) || /\d+/.test(value);27 }, "Password must contain atleast one number.");28 validationOptions = {29 debug : false,30 ignoreTitle: true,31 highlight : function(element) {32 $(element).closest('.form-group').removeClass('has-success').addClass('has-error');33 },34 success : function(element) {35 $(element).closest('.form-group').removeClass('has-error');36 },37 submitHandler : function(form) {38 form.submit();39 },40 rules : {41 "user[name]" : {42 required : true,43 minlength: 2,44 maxlength: 25,45 },46 "user[username]" : {47 required : true,48 minlength: 3,49 maxlength: 25,50 remote : {51 url : urls[0],52 type : "get",53 data : {54 user_id: function() {55 return $("#user_id").val();56 }57 }58 }59 },60 "user[email]" : {61 required : true,62 email : true,63 minlength : 5,64 maxlength : 255,65 remote : {66 url : urls[1],67 type : "get",68 data : {69 user_id: function() {70 return $("#user_id").val();71 }72 }73 }74 },75 "user[password]" : {76 minlength : 5,77 maxlength : 15,78 passwordRules: true79 },80 "user[password_confirmation]" : {81 equalTo : "#user_password"82 },83 "user[role_ids][]" : {84 required : true,85 },86 /*87 "user[address1]" : {88 required : true,89 minlength : 1,90 maxlength : 5091 },92 93 "user[city]" : {94 required : true,95 minlength : 2,96 maxlength : 2597 },98 99 "user[state]" : {100 required : true101 },102 103 "user[country]" : {104 required : true105 },106 107 "user[timezone]" : {108 required : true109 },110 111 "user[phone1]" : {112 required: true,113 minlength: 6,114 digits : true115 },116 "user[zip]" : {117 required: true,118 minlength: 6,119 digits : true120 },121 "user[phone2]" : {122 digits : true123 },124 "user[mobile]" : {125 required: true,126 minlength: 10,127 digits : true128 }129 */130 },131 messages : {132 "user[username]" : {133 remote : "This Username already exists with us."134 },135 "user[email]" : {136 remote : "This Email already exists with us."137 }138 }139 };140 141 $editFormValidator = $('#editUserForm').validate($.extend(true, {}, validationOptions));142 $newFormValidator = $('#newUserForm').validate($.extend(true, {}, validationOptions, {143 rules: {144 "user[password]": { required: true },145 "user[email]": {remote: {146 data: {user_id: -1}147 }},148 "user[username]": {remote: {149 data: {user_id: -1}150 }}151 }152 }));153 //init bootstrap wizard154 $('#editUserWizard').bootstrapWizard({155 'nextSelector' : '.next',156 'previousSelector' : '.previous',157 onNext : function(tab, navigation, index) {158 return validateEditForm();159 },160 onPrevious : function(tab, navigation, index) {161 return validateEditForm();162 },163 onTabClick: function(tab, navigation, index) {164 return validateEditForm();165 }166 });167 $('#newUserWizard').bootstrapWizard({168 'nextSelector' : '.next',169 'previousSelector' : '.previous',170 onNext : function(tab, navigation, index) {171 var total, current, percent;172 173 $('#newFormFinishBtn').addClass('disabled');174 175 if(validateNewForm()) {176 /*total = navigation.find('li').length;177 current = index + 1;178 percent = (current / total) * 100;179 180 $('#newCarrierWizard').find('.progress-bar').css('width', percent + '%');181 */182 if (index == 1) {183 $('#newFormFinishBtn').removeClass('disabled');184 }185 186 return true;187 }188 189 return false;190 },191 onPrevious : function(tab, navigation, index) {192 var total, current, percent;193 194 $('#newFormFinishBtn').addClass('disabled');195 196 if(validateNewForm()) {197 /*198 total = navigation.find('li').length;199 current = index + 1;200 percent = (current / total) * 100;201 202 $('#newCarrierWizard').find('.progress-bar').css('width', percent + '%');203 */204 return true;205 }206 207 return false;208 },209 onTabShow: function(tab, navigation, index) {210 return;211 /*212 var total, current, percent;213 214 total = navigation.find('li').length;215 current = index + 1;216 percent = (current / total) * 100;217 218 $('#newCarrierWizard').find('.progress-bar').css('width', percent + '%');219 */220 },221 onTabClick: function(tab, navigation, index) {222 return false;223 }224 });225 };226 var validateNewForm = function() { 227 var $valid = $('#newUserForm').valid();228 229 if (!$valid) {230 console.log('Invalid...');231 $newFormValidator.focusInvalid();232 return false;233 }234 235 return true;236 };237 var validateEditForm = function() {238 var $valid = $('#editUserForm').valid();239 240 if (!$valid) {241 $editFormValidator.focusInvalid();242 return false;243 }244 245 return true;246 };247 var setUrls = function(arr) {248 urls = arr;249 };250 return {251 init: init,252 setUrls: setUrls253 };254 })(jQuery);255 256 257 App.UserListHandler = (function($) {258 var urls, destroy_user, disable_user, enable_user,259 bulk_operation = false; 260 var init = function(toggleStatuses) {261 $(document).on('click', 'a.close_modal', function() {262 $(this).parents('.modal').modal('hide'); 263 bulk_operation = false;264 });265 $("div.checkbox_toggler_container").on('click', '.result_select_all', function() {266 $("div.users-container input.user-cb:checkbox:not(:checked)").attr('checked', true); 267 toggleGroupButtons();268 });269 270 $("div.checkbox_toggler_container").on('click', '.result_deselect_all', function() {271 $("div.users-container input.user-cb:checkbox:checked").attr('checked', false);272 toggleGroupButtons();273 });274 275 $("div.checkbox_toggler_container").on('click', '.result_invert_sel', function() {276 $("div.users-container input.user-cb:checkbox").click();277 toggleGroupButtons();278 });279 $("div.users-container").on('click', 'input.user-cb:checkbox', function() {280 toggleGroupButtons();281 });282 $('table#users_table').on('click', '.user_destroy', function() {283 destroy_user = $(this).data('user-id');284 $('.delete-user-confirm-dlg').modal('show');285 return false;286 });287 $('#del_user_confirm_ok').click(function () {288 var link = "a#user_" + destroy_user + "_destroy_link";289 $(link).click();290 291 $('.delete-user-confirm-dlg').modal('hide');292 });293 $('table#users_table').on('click', '.user_disable', function() {294 disable_user = $(this).data('user-id');295 $('.disable-user-confirm-dlg').modal('show');296 return false;297 });298 $('#disable_user_confirm_ok').click(function () {299 if(bulk_operation) {300 $('form#selected_users_form').submit();301 }302 else {303 var link = "a#user_" + disable_carrier + "_disable_link";304 $(link).click(); 305 }306 307 $('.disable-user-confirm-dlg').modal('hide');308 bulk_operation = false;309 });310 $('table#users_table').on('click', '.user_enable', function() {311 enable_carrier = $(this).data('user-id');312 $('.enable-user-confirm-dlg').modal('show');313 return false;314 });315 $('#enable_user_confirm_ok').click(function () {316 if(bulk_operation) {317 $('form#selected_users_form').submit();318 }319 else {320 var link = "a#user_" + enable_carrier + "_enable_link";321 $(link).click();322 }323 $('.enable-user-confirm-dlg').modal('hide');324 bulk_operation = false;325 });326 $('button.btn_change_all_status').click(function() {327 bulk_operation = true;328 $('form#selected_users_form').attr('action', $(this).data('url'));329 });330 $('#users_table').DataTable({331 resposive: true,332 /*"sDom": '<"top"l>rt<"bottom"ip><"clear">',*/333 "lengthMenu": [ [5, 10, 25, 50, 100, -1], [5, 10, 25, 50, 100, "All"] ],334 "displayLength": 25,335 "columnDefs":[336 {337 "targets" : 'no-sort',338 "orderable" : false,339 },340 {341 "targets": 0,342 "createdCell": function (td, cellData, rowData, row, col) {343 $(td).addClass('text-center').html('<input type="checkbox" name="user_ids[]" class="user-cb" value="'+ cellData +'">');344 }345 },346 347 {348 "targets": 6,349 "createdCell": function (td, cellData, rowData, row, col) {350 if(cellData) {351 $(td).html('<span class="label label-success">Activated</span>');352 }353 else {354 $(td).html('<span class="label label-warning">Deactivated</span>');355 }356 }357 },358 {359 "targets": 7,360 "createdCell": function (td, cellData, rowData, row, col) {361 innerHtml = '';362 innerHtml += ' <a class="btn btn-default btn-xs" title="Modify" href="/users/'+ rowData[0] +'/edit_internal"><span class="glyphicon glyphicon-edit"></span></a>';363 364 if(rowData[0] != 1) {365 innerHtml += ' <a href="#" rel="nofollow" data-user-id="'+ rowData[0] +'" title="Delete" class="btn btn-danger btn-xs user_destroy"><span class="glyphicon glyphicon-trash"></span></a> ';366 innerHtml += ' <a href="/users/'+ rowData[0] +'" rel="nofollow" data-remote="true" data-method="delete" id="user_'+ rowData[0] +'_destroy_link"></a>';367 }368 369 $(td).html(innerHtml);370 }371 }372 ],373 "order": [[ 1, "desc" ]],374 "processing": true,375 "serverSide": true,376 "ajax": {377 url: urls[0],378 method: 'post',379 data: {380 page: function() {381 return $('#users_table').DataTable().page.info().page + 1;382 }383 } 384 },385 "language": {386 "paginate": {387 "previous": "<<",388 "next": ">>"389 },390 "processing": "Processing... " + window.ajax_loader391 },392 "fnDrawCallback": function() { 393 var paginateRow = $(this).parent().children('div.dataTables_paginate');394 var pageCount = Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength);395 396 if (pageCount > 1) {397 paginateRow.css("display", "block");398 } else {399 paginateRow.css("display", "none");400 }401 $(this).find('input.user-cb:checkbox').attr('checked', false);402 toggleGroupButtons();403 }404 });405 };406 var toggleGroupButtons = function() {407 if ($("div.users-container input.user-cb:checkbox:checked").length > 0) {408 $('button.btn_change_all_status, #btn_remove_all').removeClass('disabled'); 409 } 410 else {411 $('button.btn_change_all_status, #btn_remove_all').addClass('disabled');412 }413 };414 var setUrls = function(arr) {415 urls = arr;416 }417 return {418 init: init,419 setUrls: setUrls420 };421 422 })(jQuery);423 424 425 ...
inbound_dids_groups.js
Source:inbound_dids_groups.js
1//= require bootstrap.min2//= require modernizr.min3//= require toggles.min4//= require retina.min5//= require jquery.cookies6//= require jquery.validate.min7//= require select2.min8//= require jquery.datatables.min9//= require bootstrap-editable.min10//= require jquery.gritter.min11//= require custom12//= require did_settings13//= require_self14var App = App || {};15var destroy_grp = null;16jQuery(document).ready(function() {17 App.CarrierManageDids = (function($) {18 var urls;19 var init = function() {20 initMoveToSelect2();21 initGroupDatatable('.did_group');22 initEditDidDescription();23 //initEditDidGrpDescription('.did-group-desc');24 initDTSearch();25 $('#did_groups_container').on('click', '.group_destroy', function() {26 var group_id = $(this).data('group-id');27 if($('table#group_'+ group_id +'_table tbody tr[role="row"]').length > 0) {28 $('.delete-group-unempty-dlg').modal('show');29 }30 else {31 destroy_grp = group_id;32 $('.delete-group-confirm-dlg').modal('show');33 }34 return false;35 });36 $('#del_grp_confirm_ok').click(function () {37 var link = "a#group_" + destroy_grp + "_destroy_link";38 $(link).click();39 $('.delete-group-confirm-dlg').modal('hide');40 });41 $.validator.addMethod("alphaOnly", function(value, element) {42 return this.optional(element) || App.alphaOnlyRegex.test(value);43 }, "Group name must contain only letters, numbers, or dashes.");44 validationOptions = {45 debug : false,46 highlight : function(element) {47 $(element).closest('.form-group').removeClass('has-success').addClass('has-error');48 },49 success : function(element) {50 $(element).closest('.form-group').removeClass('has-error');51 },52 submitHandler : function(form) {53 // do other things for a valid form54 $.rails.handleRemote($(form));55 },56 rules : {57 "did_group[name]" : {58 required : true,59 minlength: 3,60 maxlength: 254,61 alphaOnly: true,62 remote : {63 url : "/inbound_dids_groups/check_group_name",64 type : "get"65 }66 },67 "did_group[description]": {68 required: false,69 minlength: 370 }71 },72 messages : {73 "did_group[description]": "Enter few more words ...",74 "did_group[name]": {75 remote: "This group name already exists. "76 }77 }78 }; 79 $create_group_form = $('#create_group_form').validate(validationOptions);80 81 $(document).on('click', 'a.close_modal', function() {82 $(this).parents('.modal').modal('hide'); 83 });84 $('div.edit-group-dlg').on('click', 'a.close_modal', function() {85 $(this).parents('.modal').modal('hide');86 })87 .on('show.bs.modal', function(e) {88 var url = $(e.relatedTarget).data('url');89 $.get(url, function(data) {90 $(".edit-group-dlg .modal-content").html(data);91 });92 });93 $('.create-group-dlg').on('show.bs.modal', function() {94 $('form#create_group_form')[0].reset(); 95 });96 $("div.checkbox_toggler_container").on('click', '.result_select_all', function() {97 $("div#did_groups_container input.did-cb:checkbox:not(:checked)").attr('checked', true); 98 $("div#did_groups_container input.table-cb-toggler:not(:checked)").attr('checked', true);99 toggleGroupButtons();100 });101 102 $("div.checkbox_toggler_container").on('click', '.result_deselect_all', function() {103 $("div#did_groups_container input.did-cb:checkbox:checked").attr('checked', false);104 $("div#did_groups_container input.table-cb-toggler").attr('checked', false);105 toggleGroupButtons();106 });107 108 $("div.checkbox_toggler_container").on('click', '.result_invert_sel', function() {109 $("div#did_groups_container input.did-cb:checkbox").click();110 $("div#did_groups_container input.table-cb-toggler").attr('checked', false);111 toggleGroupButtons();112 });113 $("div#did_groups_container").on('click', 'input.did-cb:checkbox', function() {114 toggleGroupButtons();115 });116 $("div#did_groups_container").on('click', 'input.table-cb-toggler', function() {117 var el = $(this);118 var table_id = el.data('table');119 if(el.is(":checked")) {120 $("div#did_groups_container " + table_id + " input.did-cb:checkbox").attr('checked', true);121 }122 else {123 $("div#did_groups_container " + table_id + " input.did-cb:checkbox").attr('checked', false);124 } 125 toggleGroupButtons();126 });127 128 $("input.rel-reason").click(function() {129 var value = $(this).val();130 $('#release_other_reason').hide();131 132 if('other' == value) {133 $('input#release_reason, #release_other_reason').val('');134 $('#release_other_reason').show();135 $('#rel_did_confirm_ok').addClass('disabled');136 }137 else {138 $('input#release_reason').val(value);139 $('#rel_did_confirm_ok').removeClass('disabled');140 }141 });142 $("#release_other_reason").keyup(function() {143 var value = $(this).val();144 if($.trim(value) == '') {145 $('#rel_did_confirm_ok').addClass('disabled');146 }147 else {148 $('#rel_did_confirm_ok').removeClass('disabled'); 149 }150 $('input#release_reason').val(value);151 });152 $('.release-did-confirm-dlg').on('show.bs.modal', function() {153 var form = $('form#selected_dids_form'); 154 $(this).find('form')[0].reset();155 $('#rel_did_confirm_ok').addClass('disabled');156 $('input#release_reason').val('');157 $('#release_other_reason').hide();158 form.attr('action', urls[1]);159 });160 $('#rel_did_confirm_ok').click(function() {161 if('' == $.trim($('input#release_reason').val())) {162 return;163 }164 165 if($('#single_did').val() != '' || $("div#did_groups_container input.did-cb:checkbox:checked").length > 0) {166 $('form#selected_dids_form').submit(); 167 }168 });169 $('#did_groups_container').on('click', '.release-link', function() {170 var id = $(this).data('pk');171 $('#single_did').val(id);172 });173 $('input#global_search_q').on('keyup click', function() {174 $('.did_group').DataTable().search($(this).val(), true, true).draw();175 });176 //Show-Hide all groups177 $('a.show-hide-all').click(function() {178 var icon = $(this).find('span');179 if(icon.hasClass('glyphicon-minus')){180 icon.removeClass('glyphicon-minus').addClass('glyphicon-plus');181 $('div.group-container a.minimize').removeClass('maximize').click();182 }183 else {184 icon.removeClass('glyphicon-plus').addClass('glyphicon-minus'); 185 $('div.group-container a.minimize').addClass('maximize').click();186 }187 });188 };189 var initDTSearch = function() {190 $('.group-container input[type="search"]').attr('placeholder', 'Search group...')191 };192 var toggleGroupButtons = function() {193 if ($("div#did_groups_container input.did-cb:checkbox:checked").length > 0) {194 $('#btn_release_all, #btn_bulk_sms_settings, #btn_bulk_voice_settings').removeClass('disabled'); 195 } 196 else {197 $('#btn_release_all, #btn_bulk_sms_settings, #btn_bulk_voice_settings').addClass('disabled');198 }199 };200 var initMoveToSelect2 = function() {201 $(".moveto-select2").select2({width: '75%'})202 .on('change', function(e) {203 if($("div#did_groups_container input.did-cb:checkbox:checked").length < 1) {204 return;205 };206 $("input#move_to").val(e.val);207 $("form#selected_dids_form").attr("action", urls[0]).submit();208 });209 };210 var addNewGroupOption = function(id, name) {211 $('<option value="'+ id +'">'+ name +'</option>').appendTo('#did_groups_select');212 };213 var updateGroupOption = function(id, name) {214 $("#did_groups_select option[value='"+ id +"']").html(name);215 };216 var initGroupDatatable = function(selector) {217 $(selector).dataTable({218 resposive: true,219 "lengthMenu": [ [5, 10, 25, 50, 100, -1], [5, 10, 25, 50, 100, "All"] ],220 "columnDefs":[{221 "targets" : 'no-sort',222 "orderable" : false,223 }],224 "language": {225 "paginate": {226 "previous": "<<",227 "next": ">>"228 },229 "search": ""230 },231 "fnDrawCallback": function() { 232 var paginateRow = $(this).parent().children('div.dataTables_paginate');233 var pageCount = Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength);234 235 if (pageCount > 1) {236 paginateRow.css("display", "block");237 } else {238 paginateRow.css("display", "none");239 }240 $(this).find('.table-cb-toggler, input.did-cb:checkbox').attr('checked', false);241 toggleGroupButtons();242 }243 });244 };245 var initEditDidDescription = function() {246 $('#did_groups_container').editable({247 toggle: 'click',248 selector: '.did-desc',249 validate: function(value) {250 if($.trim(value) === '')251 return 'Enter few words for description or cancel';252 },253 url: urls[2],254 title: 'Update description',255 rows: 5,256 display: function(value) {257 $(this).text(value.truncate(30));258 },259 ajaxOptions: {260 type: 'put',261 }262 });263 };264 var initEditDidGrpDescription = function(selector) {265 $(selector).editable({266 toggle: 'click',267 validate: function(value) {268 if($.trim(value) === '')269 return 'Enter few words for description or cancel';270 },271 url: '/inbound_dids_groups/update_didgrp_desc',272 title: 'Update description',273 rows: 5,274 ajaxOptions: {275 type: 'put'276 }277 });278 };279 var removeGroup = function(group_id) {280 var $targetCont = $('div#group_'+ group_id +'_container');281 $targetCont.hide('slow', function(){ $targetCont.remove(); });282 $('select#did_groups_select option[value="'+ group_id +'"]').remove();283 };284 var updateGroup = function(id, name, description) {285 $("#group_"+ id +"_name").html(name + " DIDs");286 $("#group_" + id + "_desc").html(description);287 };288 var initEditGroupForm = function(name) {289 new_rules = {rules : {290 "did_group[name]" : {291 required : true,292 minlength: 3,293 maxlength: 254,294 remote : {295 url : "/inbound_dids_groups/check_group_name",296 data: {ignore: name},297 type : "get"298 }299 },300 "did_group[description]": {301 required: false,302 minlength: 3303 }304 }};305 $('#edit_group_form').validate($.extend(true, new_rules, validationOptions)); 306 };307 var setUrls = function(arr) {308 urls = arr;309 };310 311 return {312 init: init,313 initGroupDatatable: initGroupDatatable,314 initEditDidDescription: initEditDidDescription,315 initEditDidGrpDescription: initEditDidGrpDescription,316 initDTSearch: initDTSearch,317 addNewGroupOption: addNewGroupOption,318 updateGroupOption: updateGroupOption,319 removeGroup: removeGroup,320 updateGroup: updateGroup,321 initEditGroupForm: initEditGroupForm,322 setUrls: setUrls323 };324 })(jQuery); ...
Using AI Code Generation
1require([2], function(ToggleGroup) {3 var toggleGroup = new ToggleGroup();4 toggleGroup.toggleGroupButtons([5 {6 },7 {8 },9 {10 },11 {12 },13 {14 },15 {16 }17 ]);18});19toggleGroup.toggleGroupButtons([20 {21 },22 {23 },24 {25 },26 {27 },28 {29 },30 {31 }32]);
Using AI Code Generation
1require('argos-sdk/src/ToggleGroupButtons');2require('argos-sdk/src/Action');3require('argos-sdk/src/ActionSheet');4require('argos-sdk/src/ActivityIndicator');5require('argos-sdk/src/Alert');6require('argos-sdk/src/AttachmentList');7require('argos-sdk/src/AttachmentItem');8require('argos-sdk/src/AttachmentView');9require('argos-sdk/src/BackButton');10require('argos-sdk/src/Button');11require('argos-sdk/src/Calendar');12require('argos-sdk/src/Carousel');13require('argos-sdk/src/CheckBox');14require('argos-sdk/src/ColorPicker');15require('argos-sdk/src/CurrencyField');16require('argos-sdk/src/DateField');17require('argos-sdk/src/DateTimeField');18require('argos-sdk/src/Detail');19require('argos-sdk/src/Editor');20require('argos-sdk/src/ErrorManager');21require('argos-sdk/src/Field');22require('argos-sdk/src/FieldSet');
Using AI Code Generation
1require([2], function(ToggleGroupButton) {3 var toggleGroupButton = new ToggleGroupButton({4 { id: 1, title: 'Item 1', selected: true },5 { id: 2, title: 'Item 2' },6 { id: 3, title: 'Item 3' },7 { id: 4, title: 'Item 4' },8 { id: 5, title: 'Item 5' },9 { id: 6, title: 'Item 6' },10 { id: 7, title: 'Item 7' },11 { id: 8, title: 'Item 8' },12 { id: 9, title: 'Item 9' },13 { id: 10, title: 'Item 10' }14 });15 toggleGroupButton.placeAt(document.body);16 toggleGroupButton.startup();17 toggleGroupButton.on('change', function() {18 console.log(toggleGroupButton.getSelectedItems());19 });20});21require([22], function(ToggleGroupButton) {23 var toggleGroupButton = new ToggleGroupButton({24 { id: 1, title: 'Item 1', selected: true },25 { id: 2, title: 'Item 2' },26 { id: 3, title: 'Item 3' },27 { id: 4, title: 'Item 4' },28 { id: 5, title: 'Item 5' },29 { id: 6, title: 'Item 6' },30 { id: 7, title: 'Item 7' },31 { id: 8, title: 'Item 8' },32 { id: 9, title: 'Item 9' },33 { id: 10, title: 'Item 10' }34 });35 toggleGroupButton.placeAt(document.body);36 toggleGroupButton.startup();37 toggleGroupButton.on('change', function() {38 console.log(toggleGroupButton.getSelectedItems());39 });40});
Using AI Code Generation
1require([2], function(ToggleGroup) {3 var toggleGroup = new ToggleGroup({4 {5 },6 {7 },8 {9 }10 });11 toggleGroup.toggleButtons[0].set('checked', true);12 toggleGroup.toggleButtons[1].set('checked', true);13 toggleGroup.toggleButtons[2].set('checked', true);14 toggleGroup.toggleButtons[0].set('checked', false);15});16new ToggleGroup([options])17Method Parameters Description getCheckedToggleButtons() Returns an array of checked toggle buttons. getCheckedValues() Returns an array of checked toggle button property values. getToggleButtons() Returns an array of toggle buttons. getValues() Returns an array of toggle button property values. toggleButtonPressed(button) button Object18new ToggleGroupButton([options])19new ToggleGroupButton([options])20new ToggleGroupButton([options])
Using AI Code Generation
1require([2], function(ToggleButton) {3 var toggleButton = new ToggleButton({4 });5 var toggleButton2 = new ToggleButton({6 });7 var toggleButton3 = new ToggleButton({8 });9 toggleButton.placeAt('content');10 toggleButton2.placeAt('content');11 toggleButton3.placeAt('content');12});
Using AI Code Generation
1require(['argos/ToggleGroup'], function(ToggleGroup) {2 var toggleGroup = new ToggleGroup();3 toggleGroup.toggleGroupButtons('button', 'active');4});5 .active { background-color: red; }6 require(['test']);
Using AI Code Generation
1require([2], function(ToggleGroup) {3 var toggleGroup = new ToggleGroup();4 toggleGroup.ToggleGroupButtons('test');5});6 var toggleGroup = new argos.ToggleGroup();7 toggleGroup.ToggleGroupButtons('test');8 var toggleGroup = new argos.ToggleGroup();9 toggleGroup.ToggleGroupButtons('test');10 var toggleGroup = new argos.ToggleGroup();11 toggleGroup.ToggleGroupButtons('test');12 var toggleGroup = new argos.ToggleGroup();13 toggleGroup.ToggleGroupButtons('test');14 var toggleGroup = new argos.ToggleGroup();15 toggleGroup.ToggleGroupButtons('test');16 var toggleGroup = new argos.ToggleGroup();17 toggleGroup.ToggleGroupButtons('test');18 var toggleGroup = new argos.ToggleGroup();19 toggleGroup.ToggleGroupButtons('test');
Using AI Code Generation
1require(['argos/ToggleButton'], function(ToggleButton) {2 var toggleGroup = new ToggleButton({3 options: {4 { id: '1', name: 'Item 1', value: '1' },5 { id: '2', name: 'Item 2', value: '2' },6 { id: '3', name: 'Item 3', value: '3' }7 }8 });9 toggleGroup.toggleGroupButtons();10});11require(['argos/ToggleButton'], function(ToggleButton) {12 var toggleGroup = new ToggleButton({13 options: {14 { id: '1', name: 'Item 1', value: '1' },15 { id: '2', name: 'Item 2', value: '2' },16 { id: '3', name: 'Item 3', value: '3' }17 }18 });19 toggleGroup.toggleGroupButtons();20});21require(['argos/ToggleButton'], function(ToggleButton) {22 var toggleGroup = new ToggleButton({23 options: {24 { id: '1', name: 'Item 1', value: '1' },25 { id: '2', name: 'Item 2', value: '2' },26 { id: '3', name: 'Item 3', value: '3' }27 }28 });29 toggleGroup.toggleGroupButtons();30});31require(['argos/ToggleButton'], function(ToggleButton) {32 var toggleGroup = new ToggleButton({33 options: {34 { id: '1', name: 'Item 1', value: '1' },35 { id: '2', name: 'Item 2', value: '2' },36 { id: '3', name: 'Item 3', value: '3' }37 }38 });39 toggleGroup.toggleGroupButtons();40});
Using AI Code Generation
1require('argos-SDK/src/ToggleButton');2require('argos-SDK/src/ToggleGroupButtons');3var btn = new argos.ToggleButton({4});5var group = new argos.ToggleGroupButtons({6});7group.placeAt(document.body);8group.show();9btn.toggleState = false;10btn.toggleState = true;11group.destroy();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!