1
|
<?php
|
2
|
/*
|
3
|
headjs.php
|
4
|
|
5
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
6
|
|
7
|
Redistribution and use in source and binary forms, with or without
|
8
|
modification, are permitted provided that the following conditions are met:
|
9
|
|
10
|
1. Redistributions of source code must retain the above copyright notice,
|
11
|
this list of conditions and the following disclaimer.
|
12
|
|
13
|
2. Redistributions in binary form must reproduce the above copyright
|
14
|
notice, this list of conditions and the following disclaimer in the
|
15
|
documentation and/or other materials provided with the distribution.
|
16
|
|
17
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
18
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
19
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
20
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
21
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
22
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
23
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
24
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
25
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
26
|
POSSIBILITY OF SUCH DAMAGE.
|
27
|
*/
|
28
|
/*
|
29
|
pfSense_MODULE: header
|
30
|
*/
|
31
|
|
32
|
##|+PRIV
|
33
|
##|*IDENT=page-requiredforjavascript
|
34
|
##|*NAME=Required for javascript page
|
35
|
##|*DESCR=Allow access to the 'Required for javascript' page.
|
36
|
##|*MATCH=headjs.php*
|
37
|
##|-PRIV
|
38
|
|
39
|
require_once("guiconfig.inc");
|
40
|
|
41
|
function getHeadJS() {
|
42
|
global $g, $use_loader_tab_gif;
|
43
|
|
44
|
if(!$use_loader_tab_gif)
|
45
|
$loader_gif = "/themes/{$g['theme']}/images/misc/loader.gif";
|
46
|
else
|
47
|
$loader_gif = "/themes/{$g['theme']}/images/misc/loader_tab.gif";
|
48
|
|
49
|
$headjs = "
|
50
|
var input_errors = '';
|
51
|
jQuery(document).ready(init);
|
52
|
";
|
53
|
if (!session_id())
|
54
|
session_start();
|
55
|
$_SESSION['NO_AJAX'] == "True" ? $noajax = "var noAjaxOnSubmit = true;" : $noajax = "var noAjaxOnSubmit = false;";
|
56
|
session_commit();
|
57
|
|
58
|
$headjs .= "
|
59
|
{$noajax}
|
60
|
|
61
|
function init() {
|
62
|
if(jQuery('#submit') && ! noAjaxOnSubmit) {
|
63
|
// debugging helper
|
64
|
//alert('adding observe event for submit button');
|
65
|
|
66
|
jQuery(\"#submit\").click(submit_form);
|
67
|
jQuery('#submit').click(function() {return false;});
|
68
|
var to_insert = \"<div style='visibility:hidden' id='loading' name='loading'><img src='{$loader_gif}' alt='loader' \/><\/div>\";
|
69
|
jQuery('#submit').before(to_insert);
|
70
|
}
|
71
|
}
|
72
|
|
73
|
function submit_form(e){
|
74
|
// debugging helper
|
75
|
//alert(Form.serialize($('iform')));
|
76
|
|
77
|
if(jQuery('#inputerrors'))
|
78
|
jQuery('#inputerrors').html('<center><b><i>Loading...<\/i><\/b><\/center>');
|
79
|
|
80
|
/* dsh: Introduced because pkg_edit tries to set some hidden fields
|
81
|
* if executing submit's onclick event. The click gets deleted
|
82
|
* by Ajax. Hence using onkeydown instead.
|
83
|
*/
|
84
|
if(jQuery('#submit').prop('keydown')) {
|
85
|
jQuery('#submit').keydown();
|
86
|
jQuery('#submit').css('visibility','hidden');
|
87
|
}
|
88
|
if(jQuery('#cancelbutton'))
|
89
|
jQuery('#cancelbutton').css('visibility','hidden');
|
90
|
jQuery('#loading').css('visibility','visible');
|
91
|
// submit the form using Ajax
|
92
|
}
|
93
|
|
94
|
function formSubmitted(resp) {
|
95
|
var responseText = resp.responseText;
|
96
|
|
97
|
// debugging helper
|
98
|
// alert(responseText);
|
99
|
|
100
|
if(responseText.indexOf('html') > 0) {
|
101
|
/* somehow we have been fed an html page! */
|
102
|
//alert('Somehow we have been fed an html page! Forwarding to /.');
|
103
|
document.location.href = '/';
|
104
|
}
|
105
|
|
106
|
eval(responseText);
|
107
|
}
|
108
|
|
109
|
/* this function will be called if an HTTP error will be triggered */
|
110
|
function formFailure(resp) {
|
111
|
showajaxmessage(resp.responseText);
|
112
|
if(jQuery('#submit'))
|
113
|
jQuery('#submit').css('visibility','visible');
|
114
|
if(jQuery('#cancelbutton'))
|
115
|
jQuery('#cancelbutton').css('visibility','visible');
|
116
|
if(jQuery('#loading'))
|
117
|
jQuery('#loading').css('visibility','hidden');
|
118
|
|
119
|
}
|
120
|
|
121
|
function showajaxmessage(message) {
|
122
|
var message_html;
|
123
|
|
124
|
if (message == '') {
|
125
|
NiftyCheck();
|
126
|
Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");
|
127
|
Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");
|
128
|
|
129
|
if(jQuery('#submit'))
|
130
|
jQuery('#submit').css('visibility','visible');
|
131
|
if(jQuery('#cancelbutton'))
|
132
|
jQuery('#cancelbutton').css('visibility','visible');
|
133
|
if(jQuery('#loading'))
|
134
|
jQuery('#loading').css('visibility','hidden');
|
135
|
|
136
|
return;
|
137
|
}
|
138
|
|
139
|
message_html = '<table height=\"32\" width=\"100%\" summary=\"redbox\"><tr><td>';
|
140
|
message_html += '<div style=\"background-color:#990000\" id=\"redbox\">';
|
141
|
message_html += '<table width=\"100%\" summary=\"message\"><tr><td width=\"8%\">';
|
142
|
message_html += '<img style=\"vertical-align:center\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\" width=\"28\" height=\"32\" alt=\"exclamation\" \/>';
|
143
|
message_html += '<\/td><td width=\"70%\"><font color=\"white\">';
|
144
|
message_html += '<b>' + message + '<\/b><\/font><\/td>';
|
145
|
|
146
|
if(message.indexOf('apply') > 0) {
|
147
|
message_html += '<td>';
|
148
|
message_html += '<input name=\"apply\" type=\"submit\" class=\"formbtn\" id=\"apply\" value=\"" . gettext("Apply changes") . "\" \/>';
|
149
|
message_html += '<\/td>';
|
150
|
}
|
151
|
|
152
|
message_html += '<\/tr><\/table><\/div><\/td><\/table><br \/>';
|
153
|
jQuery('#inputerrors').html(message_html);
|
154
|
|
155
|
NiftyCheck();
|
156
|
Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");
|
157
|
Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");
|
158
|
|
159
|
if(jQuery('#submit'))
|
160
|
jQuery('#submit').css('visibility','visible');
|
161
|
if(jQuery('#cancelbutton'))
|
162
|
jQuery('#cancelbutton').css('visibility','visible');
|
163
|
if(jQuery('#loading'))
|
164
|
jQuery('#loading').css('visibility','hidden');
|
165
|
if(jQuery('#inputerrors'))
|
166
|
window.scrollTo(0, 0);
|
167
|
}
|
168
|
";
|
169
|
|
170
|
return $headjs;
|
171
|
}
|
172
|
|
173
|
?>
|