Project

General

Profile

Download (5.68 KB) Statistics
| Branch: | Tag: | Revision:
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

    
50
	$headjs = "
51
		var input_errors = '';
52
		jQuery(document).ready(init);
53
		";
54
	if (!session_id()) {
55
		session_start();
56
	}
57
	$_SESSION['NO_AJAX'] == "True" ? $noajax = "var noAjaxOnSubmit = true;" : $noajax = "var noAjaxOnSubmit = false;";
58
	session_commit();
59

    
60
	$headjs .= "
61
	{$noajax}
62

    
63
	function init() {
64
		if (jQuery('#submit') && ! noAjaxOnSubmit) {
65
			// debugging helper
66
			//alert('adding observe event for submit button');
67

    
68
			jQuery(\"#submit\").click(submit_form);
69
			jQuery('#submit').click(function() {return false;});
70
			var to_insert = \"<div style='visibility:hidden' id='loading' name='loading'><img src='{$loader_gif}' alt='loader' \/><\/div>\";
71
			jQuery('#submit').before(to_insert);
72
		}
73
	}
74

    
75
	function submit_form(e){
76
		// debugging helper
77
		//alert(Form.serialize($('iform')));
78

    
79
		if (jQuery('#inputerrors')) {
80
			jQuery('#inputerrors').html('<center><b><i>Loading...<\/i><\/b><\/center>');
81
		}
82

    
83
		/* dsh: Introduced because pkg_edit tries to set some hidden fields
84
		 *      if executing submit's onclick event. The click gets deleted
85
		 *      by Ajax. Hence using onkeydown instead.
86
		 */
87
		if (jQuery('#submit').prop('keydown')) {
88
			jQuery('#submit').keydown();
89
			jQuery('#submit').css('visibility','hidden');
90
		}
91
		if(jQuery('#cancelbutton')) {
92
			jQuery('#cancelbutton').css('visibility','hidden');
93
		}
94
		jQuery('#loading').css('visibility','visible');
95
		// submit the form using Ajax
96
	}
97

    
98
	function formSubmitted(resp) {
99
		var responseText = resp.responseText;
100

    
101
		// debugging helper
102
		// alert(responseText);
103

    
104
		if (responseText.indexOf('html') > 0) {
105
			/* somehow we have been fed an html page! */
106
			//alert('Somehow we have been fed an html page! Forwarding to /.');
107
			document.location.href = '/';
108
		}
109

    
110
		eval(responseText);
111
	}
112

    
113
	/* this function will be called if an HTTP error will be triggered */
114
	function formFailure(resp) {
115
		showajaxmessage(resp.responseText);
116
		if (jQuery('#submit')) {
117
			jQuery('#submit').css('visibility','visible');
118
		}
119
		if (jQuery('#cancelbutton')) {
120
			jQuery('#cancelbutton').css('visibility','visible');
121
		}
122
		if (jQuery('#loading')) {
123
			jQuery('#loading').css('visibility','hidden');
124
		}
125
	}
126

    
127
	function showajaxmessage(message) {
128
		var message_html;
129

    
130
		if (message == '') {
131
			NiftyCheck();
132
			Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");
133
			Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");
134

    
135
			if (jQuery('#submit')) {
136
				jQuery('#submit').css('visibility','visible');
137
			}
138
			if (jQuery('#cancelbutton')) {
139
				jQuery('#cancelbutton').css('visibility','visible');
140
			}
141
			if (jQuery('#loading')) {
142
				jQuery('#loading').css('visibility','hidden');
143
			}
144

    
145
			return;
146
		}
147

    
148
		message_html = '<table height=\"32\" width=\"100%\" summary=\"redbox\"><tr><td>';
149
		message_html += '<div style=\"background-color:#990000\" id=\"redbox\">';
150
		message_html += '<table width=\"100%\" summary=\"message\"><tr><td width=\"8%\">';
151
		message_html += '<img style=\"vertical-align:center\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\" width=\"28\" height=\"32\" alt=\"exclamation\" \/>';
152
		message_html += '<\/td><td width=\"70%\"><font color=\"white\">';
153
		message_html += '<b>' + message + '<\/b><\/font><\/td>';
154

    
155
		if (message.indexOf('apply') > 0) {
156
			message_html += '<td>';
157
			message_html += '<input name=\"apply\" type=\"submit\" class=\"formbtn\" id=\"apply\" value=\"" . gettext("Apply changes") . "\" \/>';
158
			message_html += '<\/td>';
159
		}
160

    
161
		message_html += '<\/tr><\/table><\/div><\/td><\/table><br \/>';
162
		jQuery('#inputerrors').html(message_html);
163

    
164
		NiftyCheck();
165
		Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");
166
		Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");
167

    
168
		if (jQuery('#submit')) {
169
			jQuery('#submit').css('visibility','visible');
170
		}
171
		if (jQuery('#cancelbutton')) {
172
			jQuery('#cancelbutton').css('visibility','visible');
173
		}
174
		if (jQuery('#loading')) {
175
			jQuery('#loading').css('visibility','hidden');
176
		}
177
		if (jQuery('#inputerrors')) {
178
			window.scrollTo(0, 0);
179
		}
180
	}
181
	";
182

    
183
	return $headjs;
184
}
185

    
186
?>
(91-91/256)