Project

General

Profile

Download (5.21 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2

    
3
function getHeadJS() {
4
  global $_SERVER, $HTTP_SERVER_VARS, $g, $use_loader_tab_gif;
5

    
6
  if(!$use_loader_tab_gif)
7
    $loader_gif = "/themes/{$g['theme']}/images/misc/loader.gif";
8
  else
9
    $loader_gif = "/themes/{$g['theme']}/images/misc/loader_tab.gif";
10

    
11
  $headjs = "
12
    var input_errors = '';
13
    Event.observe(window, 'load', init, false);
14
  ";
15
  $_SESSION['NO_AJAX'] == "True" ? $noajax = "var noAjaxOnSubmit = true;" : $noajax = "var noAjaxOnSubmit = false;";
16

    
17
  $headjs .= "
18
    {$noajax}
19

    
20
    function init() {
21
      if($('submit') && ! noAjaxOnSubmit) {
22
        // debugging helper
23
        //alert('adding observe event for submit button');
24
        
25
        Event.observe(\"submit\", \"click\", submit_form, false);
26
        $('submit').onclick = function() {return false;};
27
        var to_insert = \"<div style='visibility:hidden' id='loading' name='loading'><img src='{$loader_gif}' \/><\/div>\";
28
        new Insertion.Before('submit', to_insert);
29
      }
30
    }
31
    
32
    function submit_form(e){
33
      // debugging helper
34
      //alert(Form.serialize($('iform')));
35
      
36
      if($('inputerrors'))
37
        $('inputerrors').innerHTML = '';
38
        
39
      /* dsh: Introduced because pkg_edit tries to set some hidden fields
40
       *      if executing submit's onclick event. Tho click gets deleted
41
       *      by Ajax. Hence using onkeydown instead.
42
       */
43
      if($('submit') && $('submit').onkeydown)
44
        $('submit').onkeydown();
45
      if($('submit'))
46
        $('submit').style.visibility = 'hidden';
47
      if($('cancelbutton'))
48
        $('cancelbutton').style.visibility = 'hidden';
49
      $('loading').style.visibility = 'visible';
50
      // submit the form using Ajax
51
  ";
52
  
53
  
54
  isset($HTTP_SERVER_VARS['AUTH_USER']) ? $scriptName = split("/", $_SERVER["SCRIPT_FILENAME"]) : $scriptName = split("/", "/index.php");
55
  isset($HTTP_SERVER_VARS['AUTH_USER']) ? $loggedin = "var isLoggedIn = true;" : $loggedin = "var isLoggedIn = false;";
56
  $scriptElms = count($scriptName);
57
  $scriptName = $scriptName[$scriptElms-1];
58
  $realScriptName = $_SERVER["SCRIPT_NAME"];
59

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

    
63
      if (! isLoggedIn) {
64
        var newInput = document.createElement('input');
65
        newInput.setAttribute('id', 'scriptname');
66
        newInput.setAttribute('name', 'scriptname');
67
        newInput.setAttribute('value', '$realScriptName');
68
        newInput.setAttribute('type', 'hidden');
69

    
70
        $('iform').appendChild(newInput);
71
      }
72

    
73
      new Ajax.Request('{$scriptName}', {
74
                method     : 'post',
75
                parameters : Form.serialize($('iform')),
76
                onSuccess  : formSubmitted,
77
                onFailure  : formFailure
78
      });
79
    }
80
   
81
    function formSubmitted(resp) {
82
      var responseText = resp.responseText;
83
      
84
      // debugging helper
85
      //alert(responseText);
86
      
87
      if(responseText.indexOf('html') > 0) {
88
        /* somehow we have been fed an html page! */
89
        //alert('Somehow we have been fed an html page! Forwarding to /.');
90
        document.location.href = '/';
91
      }
92
      
93
      eval(responseText);
94
    }
95
    
96
    /* this function will be called if an HTTP error will be triggered */
97
    function formFailure(resp) {
98
      alert('An error occured while saving the data ' + resp.responseText);
99
    }
100
    
101
    function showajaxmessage(message) {
102
      var message_html;
103

    
104
      if (message == '') {
105
        NiftyCheck();
106
        Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");
107
        Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");
108

    
109
        if($('submit'))
110
          $('submit').style.visibility = 'visible';
111
        if($('cancelbutton'))
112
          $('cancelbutton').style.visibility = 'visible';
113
        if($('loading'))
114
          $('loading').style.visibility = 'hidden';
115

    
116
        return;
117
      }
118

    
119
      message_html = '<table height=\"32\" width=\"100%\"><tr><td>';
120
      message_html += '<div style=\"background-color:#990000\" id=\"redbox\">';
121
      message_html += '<table width=\"100%\"><tr><td width=\"8%\">';
122
      message_html += '&nbsp;&nbsp;&nbsp;';
123
      message_html += '<img style=\"vertical-align:middle\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\" width=\"28\" height=\"32\" \/>';
124
      message_html += '<\/td><td width=\"70%\"><font color=\"white\">';
125
      message_html += '<b>' + message + '<\/b><\/font><\/td>';
126

    
127
      if(message.indexOf('apply') > 0) {
128
        message_html += '<td>';
129
        message_html += '<input name=\"apply\" type=\"submit\" class=\"formbtn\" id=\"apply\" value=\"" . gettext("Apply changes") . "\" \/>';
130
        message_html += '<\/td>';
131
      }
132

    
133
      message_html += '<\/tr><\/table><\/div><\/td><\/table><br \/>';
134
      $('inputerrors').innerHTML = message_html;
135

    
136
      NiftyCheck();
137
      Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");
138
      Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");
139

    
140
      if($('submit'))
141
        $('submit').style.visibility = 'visible';
142
      if($('cancelbutton'))
143
        $('cancelbutton').style.visibility = 'visible';
144
      if($('loading'))
145
        $('loading').style.visibility = 'hidden';
146
      if($('inputerrors'))
147
        window.scrollTo(0, 0);
148
      if($('inputerrors'))
149
        new Effect.Shake($('inputerrors'));
150
    }
151
  ";
152

    
153
  return $headjs;
154
}
155

    
156
?>
(70-70/186)