summaryrefslogtreecommitdiffstats
path: root/src/usr/local/www/jquery/pfSense.js
diff options
context:
space:
mode:
authorRenato Botelho <renato@netgate.com>2015-08-26 15:12:02 -0300
committerRenato Botelho <renato@netgate.com>2015-08-26 15:12:02 -0300
commit03b19a93f4d8d870507ee96121cee4acd748dd2a (patch)
tree71a34e9e7e73d13de21cb4ad831799fb10c30df4 /src/usr/local/www/jquery/pfSense.js
parent7f410a121522c5d0e2660256ae50c1fde1df3645 (diff)
parent30ce58ac1ea27b758d5112cb5a3b190c9760f010 (diff)
downloadpfsense-03b19a93f4d8d870507ee96121cee4acd748dd2a.zip
pfsense-03b19a93f4d8d870507ee96121cee4acd748dd2a.tar.gz
Merge branch 'master' into bootstrap
Diffstat (limited to 'src/usr/local/www/jquery/pfSense.js')
-rw-r--r--src/usr/local/www/jquery/pfSense.js242
1 files changed, 242 insertions, 0 deletions
diff --git a/src/usr/local/www/jquery/pfSense.js b/src/usr/local/www/jquery/pfSense.js
new file mode 100644
index 0000000..15a518e
--- /dev/null
+++ b/src/usr/local/www/jquery/pfSense.js
@@ -0,0 +1,242 @@
+/*
+ * This file should only contain functions that will be used on more than 2 pages
+ */
+
+$(function() {
+ // Attach collapsable behaviour to select options
+ (function()
+ {
+ var selects = $('select[data-toggle="collapse"]');
+
+ selects.on('change', function(){
+ var options = $(this).find('option');
+ var selectedValue = $(this).find(':selected').val();
+
+ options.each(function(){
+ if ($(this).val() == selectedValue)
+ return;
+
+ targets = $('.toggle-'+ $(this).val() +'.in:not(.toggle-'+ selectedValue +')');
+
+ // Hide related collapsables which are visible (.in)
+ targets.collapse('hide');
+
+ // Disable all invisible inputs
+ targets.find(':input').prop('disabled', true);
+ });
+
+ $('.toggle-' + selectedValue).collapse('show').find(':input').prop('disabled', false);
+ });
+
+ // Trigger change to open currently selected item
+ selects.trigger('change');
+ })();
+
+
+ // Add +/- buttons to certain Groups; to allow adding multiple entries
+ // This time making the buttons col-2 wide so they can fit on the same line as the
+ // rest of the group (providing the total width of the group is col-8 or less)
+ (function()
+ {
+ var groups = $('div.form-group.user-duplication-horiz');
+ var controlsContainer = $('<div class="col-sm-2"></div>');
+ var plus = $('<a class="btn btn-sm btn-success">Add</a>');
+ var minus = $('<a class="btn btn-sm btn-warning">Delete</a>');
+
+ minus.on('click', function(){
+ $(this).parents('div.form-group').remove();
+ });
+
+ plus.on('click', function(){
+ var group = $(this).parents('div.form-group');
+
+ var clone = group.clone(true);
+ clone.find('*').val(''); //removeAttr('value');
+ clone.appendTo(group.parent());
+ });
+
+ groups.each(function(idx, group){
+ var controlsClone = controlsContainer.clone(true).appendTo(group);
+ minus.clone(true).appendTo(controlsClone);
+
+ if (group == group.parentNode.lastElementChild)
+ plus.clone(true).appendTo(controlsClone);
+ });
+ })();
+
+ // Add +/- buttons to certain Groups; to allow adding multiple entries
+ (function()
+ {
+ var groups = $('div.form-group.user-duplication');
+ var controlsContainer = $('<div class="col-sm-10 col-sm-offset-2 controls"></div>');
+ var plus = $('<a class="btn btn-xs btn-success">Add</a>');
+ var minus = $('<a class="btn btn-xs btn-warning">Delete</a>');
+
+ minus.on('click', function(){
+ $(this).parents('div.form-group').remove();
+ });
+
+ plus.on('click', function(){
+ var group = $(this).parents('div.form-group');
+
+ var clone = group.clone(true);
+ clone.find('*').val(''); //removeAttr('value');
+ clone.appendTo(group.parent());
+ });
+
+ groups.each(function(idx, group){
+ var controlsClone = controlsContainer.clone(true).appendTo(group);
+ minus.clone(true).appendTo(controlsClone);
+
+ if (group == group.parentNode.lastElementChild)
+ plus.clone(true).appendTo(controlsClone);
+ });
+ })();
+
+ // Find all ipaddress masks and make dynamic based on address family of input
+ $('span.pfIpMask + select').each(function (idx, select){
+ var input = $(select).prevAll('input[type=text]');
+
+ input.on('change', function(e){
+ var isV6 = (input.val().indexOf(':') != -1), min = 0, max = 128;
+ if (!isV6)
+ max = 32;
+
+ if (input.val() == "")
+ return;
+
+ while (select.options.length > max)
+ select.remove(0);
+
+ if (select.options.length < max)
+ {
+ for (var i=select.options.length; i<=max; i++)
+ select.options.add(new Option(i, i), 0);
+ }
+ });
+
+ // Fire immediately
+ input.change();
+ });
+
+ // Add confirm to all btn-danger buttons
+ $('.btn-danger').on('click', function(e){
+ var q = 'Are you sure you wish to '+ $.trim(this.textContent) +'?';
+
+ if ($(this).attr('title') != undefined)
+ q = $(this).attr('title')+'?';
+
+ if (!confirm(q))
+ e.preventDefault();
+ });
+
+ // Add toggle-all when there are multiple checkboxes and none of them are radio buttons
+ $('.control-label + .checkbox.multi').each(function() {
+ var a = $('<a class="btn btn-xs btn-default">toggle all</a>');
+
+ if(($(this).html().indexOf("type=\"radio\"") == -1)) {
+ a.on('click', function() {
+ var wrap = $(this).parents('.form-group').find('.checkbox.multi'),
+ all = wrap.find('input[type=checkbox]'),
+ checked = wrap.find('input[type=checkbox]:checked');
+
+ all.prop('checked', (all.length != checked.length));
+ });
+
+ a.appendTo($(this));
+ }
+ });
+
+ // Hide advanced inputs by default
+ if ($('.advanced').length > 0)
+ {
+ var advButt = $('<a id="toggle-advanced" class="btn btn-default">toggle advanced options</a>');
+ advButt.on('click', function() {
+ $('.advanced').parents('.form-group').collapse('toggle');
+ });
+
+ advButt.insertAfter($('#save'));
+
+ $('.advanced').parents('.form-group').collapse({toggle: true});
+ }
+
+ // Enable popovers globally
+ $('[data-toggle="popover"]').popover();
+
+ // Force correct initial state for toggleable checkboxes
+ $('input[type=checkbox][data-toggle="collapse"]:not(:checked)').each(function() {
+ $( $(this).data('target') ).addClass('collapse');
+ });
+ $('input[type=checkbox][data-toggle="disable"]:not(:checked)').each(function() {
+ $( $(this).data('target') ).prop('disabled', true);
+ });
+
+ // Focus first input
+ $(':input:enabled:visible:first').focus();
+
+ // Run in-page defined events
+ while (func = window.events.shift())
+ func();
+});
+
+// Implement data-toggle=disable
+// Source: https://github.com/synergic-cz/synergic-ui/blob/master/src/js/disable.js
+;(function($, window, document) {
+ 'use strict';
+
+ var Disable = function($element) {
+ this.$element = $element;
+ };
+
+ Disable.prototype.toggle = function() {
+ this.$element.prop('disabled', !this.$element.prop('disabled'));
+ };
+
+ function Plugin(options) {
+ $(document).trigger('toggle.sui.disable');
+
+ this.each(function() {
+ var $this = $(this);
+ var data = $this.data('sui.disable');
+
+ if (!data) {
+ $this.data('sui.disable', (data = new Disable($this)));
+ }
+
+ if (options === 'toggle') {
+ data.toggle();
+ }
+ });
+
+ $(document).trigger('toggled.sui.disable');
+
+ return this;
+ }
+
+ var old = $.fn.disable;
+
+ $.fn.disable = Plugin;
+ $.fn.disable.Constructor = Disable;
+
+ $.fn.disable.noConflict = function() {
+ $.fn.disable = old;
+ return this;
+ };
+
+ (function(Plugin, $, window) {
+ $(window).load(function() {
+ var $controls = $('[data-toggle=disable]');
+
+ $controls.each(function() {
+ var $this = $(this);
+ var eventType = $this.data('disable-event');
+ if (!eventType) {
+ eventType = 'change';
+ }
+ $this.on(eventType + '.sui.disable.data-api', function() {
+ Plugin.call($($this.data('target')), 'toggle');
+ });
+ });
+ });
+ }(Plugin, $, window, document));
+}(jQuery, window, document)); \ No newline at end of file
OpenPOWER on IntegriCloud