Project

General

Profile

Download (6.04 KB) Statistics
| Branch: | Tag: | Revision:
1 fab7ff44 Bill Marquette
<?php
2 6b07c15a Matthew Grooms
/*
3
    headjs.php
4
5 d961e7e3 Renato Botelho
    Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6 29aef6c4 Jim Thompson
7 6b07c15a Matthew Grooms
    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 7ac5a4cb Scott Ullrich
/*
29
	pfSense_MODULE:	header
30
*/
31 6b07c15a Matthew Grooms
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 fd4151a9 Ermal
require_once("guiconfig.inc");
40
41 fab7ff44 Bill Marquette
function getHeadJS() {
42 aa205c3b Ermal
  global $g, $use_loader_tab_gif;
43 fab7ff44 Bill Marquette
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 ea0d4171 Vinicius Coque
    jQuery(document).ready(init);
52 fab7ff44 Bill Marquette
  ";
53 4111fcf5 Ermal
  if (!session_id())
54
	session_start();
55 fab7ff44 Bill Marquette
  $_SESSION['NO_AJAX'] == "True" ? $noajax = "var noAjaxOnSubmit = true;" : $noajax = "var noAjaxOnSubmit = false;";
56 4111fcf5 Ermal
  session_commit();
57 fab7ff44 Bill Marquette
58
  $headjs .= "
59
    {$noajax}
60
61
    function init() {
62 ea0d4171 Vinicius Coque
      if(jQuery('#submit') && ! noAjaxOnSubmit) {
63 fab7ff44 Bill Marquette
        // debugging helper
64
        //alert('adding observe event for submit button');
65
        
66 ea0d4171 Vinicius Coque
        jQuery(\"#submit\").click(submit_form);
67
        jQuery('#submit').click(function() {return false;});
68 52593da5 Colin Fleming
        var to_insert = \"<div style='visibility:hidden' id='loading' name='loading'><img src='{$loader_gif}' alt='loader' \/><\/div>\";
69 ea0d4171 Vinicius Coque
        jQuery('#submit').before(to_insert);
70 fab7ff44 Bill Marquette
      }
71
    }
72
    
73
    function submit_form(e){
74
      // debugging helper
75
      //alert(Form.serialize($('iform')));
76 ea0d4171 Vinicius Coque
77
      if(jQuery('#inputerrors'))
78 52593da5 Colin Fleming
        jQuery('#inputerrors').html('<center><b><i>Loading...<\/i><\/b><\/center>');
79 fab7ff44 Bill Marquette
        
80
      /* dsh: Introduced because pkg_edit tries to set some hidden fields
81 52860a44 Bill Marquette
       *      if executing submit's onclick event. The click gets deleted
82 fab7ff44 Bill Marquette
       *      by Ajax. Hence using onkeydown instead.
83
       */
84 ea0d4171 Vinicius Coque
      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 fab7ff44 Bill Marquette
      // submit the form using Ajax
92
    }
93
   
94
    function formSubmitted(resp) {
95
      var responseText = resp.responseText;
96
      
97
      // debugging helper
98 be23be5a Scott Ullrich
      // alert(responseText);
99 fab7ff44 Bill Marquette
      
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 950f0f9e Scott Ullrich
	    showajaxmessage(resp.responseText);
112 ea0d4171 Vinicius Coque
		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 950f0f9e Scott Ullrich
119 fab7ff44 Bill Marquette
    }
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 ea0d4171 Vinicius Coque
        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 fab7ff44 Bill Marquette
136
        return;
137
      }
138
139 52593da5 Colin Fleming
      message_html = '<table height=\"32\" width=\"100%\" summary=\"redbox\"><tr><td>';
140 fab7ff44 Bill Marquette
      message_html += '<div style=\"background-color:#990000\" id=\"redbox\">';
141 52593da5 Colin Fleming
      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 fab7ff44 Bill Marquette
      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 ea0d4171 Vinicius Coque
      jQuery('#inputerrors').html(message_html);
154 fab7ff44 Bill Marquette
155
      NiftyCheck();
156
      Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");
157
      Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");
158
159 ea0d4171 Vinicius Coque
      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 fab7ff44 Bill Marquette
        window.scrollTo(0, 0);
167
    }
168
  ";
169
170
  return $headjs;
171
}
172
173 fd4151a9 Ermal
?>