Project

General

Profile

Download (5.74 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
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

    
27
##|+PRIV
28
##|*IDENT=page-requiredforjavascript
29
##|*NAME=Required for javascript page
30
##|*DESCR=Allow access to the 'Required for javascript' page.
31
##|*MATCH=headjs.php*
32
##|-PRIV
33

    
34

    
35
function getHeadJS() {
36
  global $_SERVER, $HTTP_SERVER_VARS, $g, $use_loader_tab_gif;
37

    
38
  if(!$use_loader_tab_gif)
39
    $loader_gif = "/themes/{$g['theme']}/images/misc/loader.gif";
40
  else
41
    $loader_gif = "/themes/{$g['theme']}/images/misc/loader_tab.gif";
42

    
43
  $headjs = "
44
    var input_errors = '';
45
    Event.observe(window, 'load', init, false);
46
  ";
47
  $_SESSION['NO_AJAX'] == "True" ? $noajax = "var noAjaxOnSubmit = true;" : $noajax = "var noAjaxOnSubmit = false;";
48

    
49
  $headjs .= "
50
    {$noajax}
51

    
52
    function init() {
53
      if($('submit') && ! noAjaxOnSubmit) {
54
        // debugging helper
55
        //alert('adding observe event for submit button');
56
        
57
        Event.observe(\"submit\", \"click\", submit_form, false);
58
        $('submit').onclick = function() {return false;};
59
        var to_insert = \"<div style='visibility:hidden' id='loading' name='loading'><img src='{$loader_gif}' \/><\/div>\";
60
        new Insertion.Before('submit', to_insert);
61
      }
62
    }
63
    
64
    function submit_form(e){
65
      // debugging helper
66
      //alert(Form.serialize($('iform')));
67
      
68
      if($('inputerrors'))
69
        $('inputerrors').innerHTML = '<center><b><i>Loading...</i></b></center>';
70
        
71
      /* dsh: Introduced because pkg_edit tries to set some hidden fields
72
       *      if executing submit's onclick event. The click gets deleted
73
       *      by Ajax. Hence using onkeydown instead.
74
       */
75
      if($('submit') && $('submit').onkeydown)
76
        $('submit').onkeydown();
77
      if($('submit'))
78
        $('submit').style.visibility = 'hidden';
79
      if($('cancelbutton'))
80
        $('cancelbutton').style.visibility = 'hidden';
81
      $('loading').style.visibility = 'visible';
82
      // submit the form using Ajax
83
    }
84
   
85
    function formSubmitted(resp) {
86
      var responseText = resp.responseText;
87
      
88
      // debugging helper
89
      // alert(responseText);
90
      
91
      if(responseText.indexOf('html') > 0) {
92
        /* somehow we have been fed an html page! */
93
        //alert('Somehow we have been fed an html page! Forwarding to /.');
94
        document.location.href = '/';
95
      }
96
      
97
      eval(responseText);
98
    }
99
    
100
    /* this function will be called if an HTTP error will be triggered */
101
    function formFailure(resp) {
102
	    showajaxmessage(resp.responseText);
103
		if($('submit'))
104
		  $('submit').style.visibility = 'visible';
105
		if($('cancelbutton'))
106
		  $('cancelbutton').style.visibility = 'visible';
107
		if($('loading'))
108
		  $('loading').style.visibility = 'hidden';
109

    
110
    }
111
    
112
    function showajaxmessage(message) {
113
      var message_html;
114

    
115
      if (message == '') {
116
        NiftyCheck();
117
        Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");
118
        Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");
119

    
120
        if($('submit'))
121
          $('submit').style.visibility = 'visible';
122
        if($('cancelbutton'))
123
          $('cancelbutton').style.visibility = 'visible';
124
        if($('loading'))
125
          $('loading').style.visibility = 'hidden';
126

    
127
        return;
128
      }
129

    
130
      message_html = '<table height=\"32\" width=\"100%\"><tr><td>';
131
      message_html += '<div style=\"background-color:#990000\" id=\"redbox\">';
132
      message_html += '<table width=\"100%\"><tr><td width=\"8%\">';
133
      message_html += '<img style=\"vertical-align:center\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\" width=\"28\" height=\"32\" \/>';
134
      message_html += '<\/td><td width=\"70%\"><font color=\"white\">';
135
      message_html += '<b>' + message + '<\/b><\/font><\/td>';
136

    
137
      if(message.indexOf('apply') > 0) {
138
        message_html += '<td>';
139
        message_html += '<input name=\"apply\" type=\"submit\" class=\"formbtn\" id=\"apply\" value=\"" . gettext("Apply changes") . "\" \/>';
140
        message_html += '<\/td>';
141
      }
142

    
143
      message_html += '<\/tr><\/table><\/div><\/td><\/table><br \/>';
144
      $('inputerrors').innerHTML = message_html;
145

    
146
      NiftyCheck();
147
      Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");
148
      Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");
149

    
150
      if($('submit'))
151
        $('submit').style.visibility = 'visible';
152
      if($('cancelbutton'))
153
        $('cancelbutton').style.visibility = 'visible';
154
      if($('loading'))
155
        $('loading').style.visibility = 'hidden';
156
      if($('inputerrors'))
157
        window.scrollTo(0, 0);
158
    }
159
  ";
160

    
161
  return $headjs;
162
}
163

    
164
?>
(76-76/217)