Project

General

Profile

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