1 |
8acd654a
|
Renato Botelho
|
/*
|
2 |
|
|
* pfSense.js
|
3 |
|
|
*
|
4 |
|
|
* part of pfSense (https://www.pfsense.org)
|
5 |
2a2396a6
|
Renato Botelho
|
* Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
|
6 |
8acd654a
|
Renato Botelho
|
* All rights reserved.
|
7 |
|
|
*
|
8 |
|
|
* Redistribution and use in source and binary forms, with or without
|
9 |
|
|
* modification, are permitted provided that the following conditions are met:
|
10 |
|
|
*
|
11 |
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
12 |
|
|
* this list of conditions and the following disclaimer.
|
13 |
|
|
*
|
14 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
15 |
|
|
* notice, this list of conditions and the following disclaimer in
|
16 |
|
|
* the documentation and/or other materials provided with the
|
17 |
|
|
* distribution.
|
18 |
|
|
*
|
19 |
|
|
* 3. All advertising materials mentioning features or use of this software
|
20 |
|
|
* must display the following acknowledgment:
|
21 |
|
|
* "This product includes software developed by the pfSense Project
|
22 |
|
|
* for use in the pfSense® software distribution. (http://www.pfsense.org/).
|
23 |
|
|
*
|
24 |
|
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
25 |
|
|
* endorse or promote products derived from this software without
|
26 |
|
|
* prior written permission. For written permission, please contact
|
27 |
|
|
* coreteam@pfsense.org.
|
28 |
|
|
*
|
29 |
|
|
* 5. Products derived from this software may not be called "pfSense"
|
30 |
|
|
* nor may "pfSense" appear in their names without prior written
|
31 |
|
|
* permission of the Electric Sheep Fencing, LLC.
|
32 |
|
|
*
|
33 |
|
|
* 6. Redistributions of any form whatsoever must retain the following
|
34 |
|
|
* acknowledgment:
|
35 |
|
|
*
|
36 |
|
|
* "This product includes software developed by the pfSense Project
|
37 |
|
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
38 |
|
|
*
|
39 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
40 |
|
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
41 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
42 |
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
43 |
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
44 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
45 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
46 |
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
47 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
48 |
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
49 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
50 |
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
51 |
|
|
*/
|
52 |
|
|
|
53 |
dc58b7b3
|
Sjon Hortensius
|
/*
|
54 |
a41b03d0
|
Sjon Hortensius
|
* This file should only contain functions that will be used on more than 2 pages
|
55 |
dc58b7b3
|
Sjon Hortensius
|
*/
|
56 |
|
|
|
57 |
41ea4cf3
|
Sjon Hortensius
|
$(function() {
|
58 |
b2e6dd64
|
Sjon Hortensius
|
// Attach collapsable behaviour to select options
|
59 |
85033097
|
Sjon Hortensius
|
(function()
|
60 |
c39f7276
|
Sander van Leeuwen
|
{
|
61 |
|
|
var selects = $('select[data-toggle="collapse"]');
|
62 |
|
|
|
63 |
b2e6dd64
|
Sjon Hortensius
|
selects.on('change', function(){
|
64 |
c39f7276
|
Sander van Leeuwen
|
var options = $(this).find('option');
|
65 |
|
|
var selectedValue = $(this).find(':selected').val();
|
66 |
|
|
|
67 |
b2e6dd64
|
Sjon Hortensius
|
options.each(function(){
|
68 |
c39f7276
|
Sander van Leeuwen
|
if ($(this).val() == selectedValue)
|
69 |
|
|
return;
|
70 |
|
|
|
71 |
50ea0588
|
Sjon Hortensius
|
targets = $('.toggle-'+ $(this).val() +'.in:not(.toggle-'+ selectedValue +')');
|
72 |
|
|
|
73 |
|
|
// Hide related collapsables which are visible (.in)
|
74 |
|
|
targets.collapse('hide');
|
75 |
b2e6dd64
|
Sjon Hortensius
|
|
76 |
|
|
// Disable all invisible inputs
|
77 |
50ea0588
|
Sjon Hortensius
|
targets.find(':input').prop('disabled', true);
|
78 |
c39f7276
|
Sander van Leeuwen
|
});
|
79 |
|
|
|
80 |
50ea0588
|
Sjon Hortensius
|
$('.toggle-' + selectedValue).collapse('show').find(':input').prop('disabled', false);
|
81 |
c39f7276
|
Sander van Leeuwen
|
});
|
82 |
|
|
|
83 |
|
|
// Trigger change to open currently selected item
|
84 |
|
|
selects.trigger('change');
|
85 |
85033097
|
Sjon Hortensius
|
})();
|
86 |
a8a4a7e3
|
Sjon Hortensius
|
|
87 |
3bbf56d7
|
Stephen Beaver
|
|
88 |
|
|
// Add +/- buttons to certain Groups; to allow adding multiple entries
|
89 |
|
|
// This time making the buttons col-2 wide so they can fit on the same line as the
|
90 |
|
|
// rest of the group (providing the total width of the group is col-8 or less)
|
91 |
|
|
(function()
|
92 |
|
|
{
|
93 |
|
|
var groups = $('div.form-group.user-duplication-horiz');
|
94 |
|
|
var controlsContainer = $('<div class="col-sm-2"></div>');
|
95 |
c0367cb8
|
jim-p
|
var plus = $('<a class="btn btn-sm btn-success"><i class="fa fa-plus icon-embed-btn"></i>Add</a>');
|
96 |
|
|
var minus = $('<a class="btn btn-sm btn-warning"><i class="fa fa-trash icon-embed-btn"></i>Delete</a>');
|
97 |
3bbf56d7
|
Stephen Beaver
|
|
98 |
|
|
minus.on('click', function(){
|
99 |
|
|
$(this).parents('div.form-group').remove();
|
100 |
|
|
});
|
101 |
|
|
|
102 |
|
|
plus.on('click', function(){
|
103 |
|
|
var group = $(this).parents('div.form-group');
|
104 |
|
|
|
105 |
|
|
var clone = group.clone(true);
|
106 |
7c540a5c
|
Stephen Beaver
|
clone.find('*').val('');
|
107 |
3bbf56d7
|
Stephen Beaver
|
clone.appendTo(group.parent());
|
108 |
|
|
});
|
109 |
|
|
|
110 |
|
|
groups.each(function(idx, group){
|
111 |
|
|
var controlsClone = controlsContainer.clone(true).appendTo(group);
|
112 |
|
|
minus.clone(true).appendTo(controlsClone);
|
113 |
|
|
|
114 |
|
|
if (group == group.parentNode.lastElementChild)
|
115 |
|
|
plus.clone(true).appendTo(controlsClone);
|
116 |
|
|
});
|
117 |
|
|
})();
|
118 |
|
|
|
119 |
b2e6dd64
|
Sjon Hortensius
|
// Add +/- buttons to certain Groups; to allow adding multiple entries
|
120 |
85033097
|
Sjon Hortensius
|
(function()
|
121 |
b2e6dd64
|
Sjon Hortensius
|
{
|
122 |
|
|
var groups = $('div.form-group.user-duplication');
|
123 |
8c10899b
|
Sander van Leeuwen
|
var controlsContainer = $('<div class="col-sm-10 col-sm-offset-2 controls"></div>');
|
124 |
c0367cb8
|
jim-p
|
var plus = $('<a class="btn btn-xs btn-success"><i class="fa fa-plus icon-embed-btn"></i>Add</a>');
|
125 |
|
|
var minus = $('<a class="btn btn-xs btn-warning"><i class="fa fa-trash icon-embed-btn"></i>Delete</a>');
|
126 |
b2e6dd64
|
Sjon Hortensius
|
|
127 |
|
|
minus.on('click', function(){
|
128 |
8c10899b
|
Sander van Leeuwen
|
$(this).parents('div.form-group').remove();
|
129 |
b2e6dd64
|
Sjon Hortensius
|
});
|
130 |
|
|
|
131 |
|
|
plus.on('click', function(){
|
132 |
8c10899b
|
Sander van Leeuwen
|
var group = $(this).parents('div.form-group');
|
133 |
b2e6dd64
|
Sjon Hortensius
|
|
134 |
|
|
var clone = group.clone(true);
|
135 |
5a957b9a
|
Phil Davis
|
clone.find('*').removeAttr('value');
|
136 |
b2e6dd64
|
Sjon Hortensius
|
clone.appendTo(group.parent());
|
137 |
|
|
});
|
138 |
|
|
|
139 |
|
|
groups.each(function(idx, group){
|
140 |
8c10899b
|
Sander van Leeuwen
|
var controlsClone = controlsContainer.clone(true).appendTo(group);
|
141 |
|
|
minus.clone(true).appendTo(controlsClone);
|
142 |
b2e6dd64
|
Sjon Hortensius
|
|
143 |
|
|
if (group == group.parentNode.lastElementChild)
|
144 |
8c10899b
|
Sander van Leeuwen
|
plus.clone(true).appendTo(controlsClone);
|
145 |
0ba2494e
|
Sjon Hortensius
|
});
|
146 |
85033097
|
Sjon Hortensius
|
})();
|
147 |
0ba2494e
|
Sjon Hortensius
|
|
148 |
2d911f2c
|
Phil Davis
|
// Automatically change IpAddress mask selectors to 128/32 options for IPv6/IPv4 addresses
|
149 |
85033097
|
Sjon Hortensius
|
$('span.pfIpMask + select').each(function (idx, select){
|
150 |
|
|
var input = $(select).prevAll('input[type=text]');
|
151 |
5a957b9a
|
Phil Davis
|
|
152 |
85033097
|
Sjon Hortensius
|
input.on('change', function(e){
|
153 |
|
|
var isV6 = (input.val().indexOf(':') != -1), min = 0, max = 128;
|
154 |
|
|
if (!isV6)
|
155 |
|
|
max = 32;
|
156 |
0ba2494e
|
Sjon Hortensius
|
|
157 |
85033097
|
Sjon Hortensius
|
if (input.val() == "")
|
158 |
|
|
return;
|
159 |
0ba2494e
|
Sjon Hortensius
|
|
160 |
5a957b9a
|
Phil Davis
|
// Eat all of the options with a value greater than max. We don't want them to be available
|
161 |
cddc70a2
|
Stephen Beaver
|
while (select.options[0].value > max)
|
162 |
85033097
|
Sjon Hortensius
|
select.remove(0);
|
163 |
5a957b9a
|
Phil Davis
|
|
164 |
cddc70a2
|
Stephen Beaver
|
if (select.options.length < max) {
|
165 |
85033097
|
Sjon Hortensius
|
for (var i=select.options.length; i<=max; i++)
|
166 |
|
|
select.options.add(new Option(i, i), 0);
|
167 |
036b32b5
|
Renato Botelho
|
// Make sure index 0 is selected otherwise it will stay in "32" for V6
|
168 |
|
|
select.options.selectedIndex = "0";
|
169 |
85033097
|
Sjon Hortensius
|
}
|
170 |
0ba2494e
|
Sjon Hortensius
|
});
|
171 |
85033097
|
Sjon Hortensius
|
|
172 |
|
|
// Fire immediately
|
173 |
|
|
input.change();
|
174 |
|
|
});
|
175 |
5a957b9a
|
Phil Davis
|
|
176 |
0619c9db
|
Stephen Beaver
|
// Add confirm to all btn-danger buttons and fa-trash icons
|
177 |
7c540a5c
|
Stephen Beaver
|
// Use element title in the confirmation message, or if not available
|
178 |
|
|
// the element value
|
179 |
0619c9db
|
Stephen Beaver
|
$('.btn-danger, .fa-trash').on('click', function(e){
|
180 |
d9f1170e
|
Steve Beaver
|
if (!($(this).hasClass('no-confirm')) && !($(this).hasClass('icon-embed-btn'))) {
|
181 |
3eaf25aa
|
plumbeo
|
var msg = $.trim(this.textContent).toLowerCase();
|
182 |
5a957b9a
|
Phil Davis
|
|
183 |
9488f42b
|
Phil Davis
|
if (!msg)
|
184 |
33f0b0d5
|
Stephen Beaver
|
var msg = $.trim(this.value).toLowerCase();
|
185 |
1c306cd0
|
Sjon Hortensius
|
|
186 |
586a79d5
|
heper
|
var q = 'Are you sure you wish to '+ msg +'?';
|
187 |
1c306cd0
|
Sjon Hortensius
|
|
188 |
33f0b0d5
|
Stephen Beaver
|
if ($(this).attr('title') != undefined)
|
189 |
586a79d5
|
heper
|
q = 'Are you sure you wish to '+ $(this).attr('title').toLowerCase() + '?';
|
190 |
33f0b0d5
|
Stephen Beaver
|
|
191 |
82d4c81b
|
NOYB
|
if (!confirm(q)) {
|
192 |
33f0b0d5
|
Stephen Beaver
|
e.preventDefault();
|
193 |
82d4c81b
|
NOYB
|
e.stopPropagation(); // Don't leave ancestor(s) selected.
|
194 |
|
|
}
|
195 |
33f0b0d5
|
Stephen Beaver
|
}
|
196 |
45d6ada5
|
Sjon Hortensius
|
});
|
197 |
|
|
|
198 |
5e7a1d46
|
Stephen Beaver
|
// Add toggle-all when there are multiple checkboxes
|
199 |
f0a108f2
|
Sander van Leeuwen
|
$('.control-label + .checkbox.multi').each(function() {
|
200 |
759cbbd1
|
jim-p
|
var a = $('<a name="btntoggleall" class="btn btn-xs btn-info"><i class="fa fa-check-square-o icon-embed-btn"></i>Toggle All</a>');
|
201 |
5a957b9a
|
Phil Davis
|
|
202 |
5e7a1d46
|
Stephen Beaver
|
a.on('click', function() {
|
203 |
|
|
var wrap = $(this).parents('.form-group').find('.checkbox.multi'),
|
204 |
|
|
all = wrap.find('input[type=checkbox]'),
|
205 |
|
|
checked = wrap.find('input[type=checkbox]:checked');
|
206 |
5a957b9a
|
Phil Davis
|
|
207 |
5e7a1d46
|
Stephen Beaver
|
all.prop('checked', (all.length != checked.length));
|
208 |
|
|
});
|
209 |
5a957b9a
|
Phil Davis
|
|
210 |
5e7a1d46
|
Stephen Beaver
|
a.appendTo($(this));
|
211 |
f0a108f2
|
Sander van Leeuwen
|
});
|
212 |
85033097
|
Sjon Hortensius
|
|
213 |
03b53522
|
Stephen Beaver
|
// The need to NOT hide the advanced options if the elements therein are not set to the system
|
214 |
|
|
// default values makes it better to handle advanced option hiding in each PHP file so this is being
|
215 |
2d911f2c
|
Phil Davis
|
// disabled for now by changing the class name it acts on to "auto-advanced"
|
216 |
03b53522
|
Stephen Beaver
|
|
217 |
08d1762e
|
Sjon Hortensius
|
// Hide advanced inputs by default
|
218 |
03b53522
|
Stephen Beaver
|
if ($('.auto-advanced').length > 0)
|
219 |
08d1762e
|
Sjon Hortensius
|
{
|
220 |
321a7e89
|
Stephen Beaver
|
var advButt = $('<a id="toggle-advanced" class="btn btn-default">toggle advanced options</a>');
|
221 |
08d1762e
|
Sjon Hortensius
|
advButt.on('click', function() {
|
222 |
|
|
$('.advanced').parents('.form-group').collapse('toggle');
|
223 |
|
|
});
|
224 |
|
|
|
225 |
|
|
advButt.insertAfter($('#save'));
|
226 |
|
|
|
227 |
03b53522
|
Stephen Beaver
|
$('.auto-advanced').parents('.form-group').collapse({toggle: true});
|
228 |
08d1762e
|
Sjon Hortensius
|
}
|
229 |
|
|
|
230 |
76bd03bb
|
Jared Dillard
|
var originalLeave = $.fn.popover.Constructor.prototype.leave;
|
231 |
|
|
$.fn.popover.Constructor.prototype.leave = function(obj){
|
232 |
|
|
var self = obj instanceof this.constructor ?
|
233 |
|
|
obj : $(obj.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type)
|
234 |
|
|
var container, timeout;
|
235 |
|
|
|
236 |
|
|
originalLeave.call(this, obj);
|
237 |
|
|
|
238 |
9488f42b
|
Phil Davis
|
if (self.$tip && self.$tip.length) {
|
239 |
76bd03bb
|
Jared Dillard
|
container = self.$tip;
|
240 |
|
|
timeout = self.timeout;
|
241 |
|
|
container.one('mouseenter', function(){
|
242 |
c0367cb8
|
jim-p
|
//We entered the actual popover - call off the dogs
|
243 |
76bd03bb
|
Jared Dillard
|
clearTimeout(timeout);
|
244 |
|
|
//Let's monitor popover content instead
|
245 |
|
|
container.one('mouseleave', function(){
|
246 |
|
|
$.fn.popover.Constructor.prototype.leave.call(self, self);
|
247 |
|
|
});
|
248 |
|
|
})
|
249 |
|
|
}
|
250 |
|
|
};
|
251 |
|
|
|
252 |
a8a4a7e3
|
Sjon Hortensius
|
// Enable popovers globally
|
253 |
76bd03bb
|
Jared Dillard
|
$('[data-toggle="popover"]').popover({ delay: {show: 50, hide: 400} });
|
254 |
a8a4a7e3
|
Sjon Hortensius
|
|
255 |
3e607d0e
|
Sjon Hortensius
|
// Force correct initial state for toggleable checkboxes
|
256 |
36a0cfe8
|
Sander van Leeuwen
|
$('input[type=checkbox][data-toggle="collapse"]:not(:checked)').each(function() {
|
257 |
|
|
$( $(this).data('target') ).addClass('collapse');
|
258 |
3e607d0e
|
Sjon Hortensius
|
});
|
259 |
0619c9db
|
Stephen Beaver
|
|
260 |
08d1762e
|
Sjon Hortensius
|
$('input[type=checkbox][data-toggle="disable"]:not(:checked)').each(function() {
|
261 |
|
|
$( $(this).data('target') ).prop('disabled', true);
|
262 |
|
|
});
|
263 |
3e607d0e
|
Sjon Hortensius
|
|
264 |
f8cb8d65
|
PiBa-NL
|
$('.table-rowdblclickedit>tbody>tr').dblclick(function () {
|
265 |
|
|
$(this).find(".fa-pencil")[0].click();
|
266 |
|
|
});
|
267 |
d9f1170e
|
Steve Beaver
|
|
268 |
45d6ada5
|
Sjon Hortensius
|
// Focus first input
|
269 |
|
|
$(':input:enabled:visible:first').focus();
|
270 |
|
|
|
271 |
ec51be45
|
PiBa-NL
|
$(".resizable").each(function() {
|
272 |
|
|
$(this).css('height', 80).resizable({minHeight: 80, minWidth: 200}).parent().css('padding-bottom', 0);
|
273 |
|
|
$(this).css('height', 78);
|
274 |
|
|
});
|
275 |
d9f1170e
|
Steve Beaver
|
|
276 |
85033097
|
Sjon Hortensius
|
// Run in-page defined events
|
277 |
|
|
while (func = window.events.shift())
|
278 |
|
|
func();
|
279 |
08d1762e
|
Sjon Hortensius
|
});
|
280 |
|
|
|
281 |
|
|
// Implement data-toggle=disable
|
282 |
|
|
// Source: https://github.com/synergic-cz/synergic-ui/blob/master/src/js/disable.js
|
283 |
|
|
;(function($, window, document) {
|
284 |
|
|
'use strict';
|
285 |
|
|
|
286 |
|
|
var Disable = function($element) {
|
287 |
|
|
this.$element = $element;
|
288 |
|
|
};
|
289 |
|
|
|
290 |
|
|
Disable.prototype.toggle = function() {
|
291 |
|
|
this.$element.prop('disabled', !this.$element.prop('disabled'));
|
292 |
|
|
};
|
293 |
|
|
|
294 |
|
|
function Plugin(options) {
|
295 |
|
|
$(document).trigger('toggle.sui.disable');
|
296 |
|
|
|
297 |
|
|
this.each(function() {
|
298 |
|
|
var $this = $(this);
|
299 |
|
|
var data = $this.data('sui.disable');
|
300 |
|
|
|
301 |
|
|
if (!data) {
|
302 |
|
|
$this.data('sui.disable', (data = new Disable($this)));
|
303 |
|
|
}
|
304 |
|
|
|
305 |
|
|
if (options === 'toggle') {
|
306 |
|
|
data.toggle();
|
307 |
|
|
}
|
308 |
|
|
});
|
309 |
|
|
|
310 |
|
|
$(document).trigger('toggled.sui.disable');
|
311 |
|
|
|
312 |
|
|
return this;
|
313 |
|
|
}
|
314 |
|
|
|
315 |
|
|
var old = $.fn.disable;
|
316 |
|
|
|
317 |
|
|
$.fn.disable = Plugin;
|
318 |
|
|
$.fn.disable.Constructor = Disable;
|
319 |
|
|
|
320 |
|
|
$.fn.disable.noConflict = function() {
|
321 |
|
|
$.fn.disable = old;
|
322 |
|
|
return this;
|
323 |
|
|
};
|
324 |
|
|
|
325 |
|
|
(function(Plugin, $, window) {
|
326 |
|
|
$(window).load(function() {
|
327 |
|
|
var $controls = $('[data-toggle=disable]');
|
328 |
|
|
|
329 |
|
|
$controls.each(function() {
|
330 |
|
|
var $this = $(this);
|
331 |
|
|
var eventType = $this.data('disable-event');
|
332 |
|
|
if (!eventType) {
|
333 |
|
|
eventType = 'change';
|
334 |
|
|
}
|
335 |
|
|
$this.on(eventType + '.sui.disable.data-api', function() {
|
336 |
|
|
Plugin.call($($this.data('target')), 'toggle');
|
337 |
|
|
});
|
338 |
|
|
});
|
339 |
|
|
});
|
340 |
|
|
}(Plugin, $, window, document));
|
341 |
586a79d5
|
heper
|
}(jQuery, window, document));
|