~ubuntu-branches/debian/sid/web2py/sid

« back to all changes in this revision

Viewing changes to applications/admin/views/web2py_ajax.html

  • Committer: Bazaar Package Importer
  • Author(s): José L. Redrejo Rodríguez
  • Date: 2011-06-02 16:55:29 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110602165529-wq73zmx3zy9pc3ul
Tags: 1.96.1-1
* New upstream version
* Move wsgihandler.py from python-web2py to examples of python-gluon
* Added subwsgihandler.py to python-gluon examples (as a patch)
* Added web2py.apache-subdir and updated web2py.apache and README.Debian
* Refreshed debian/patches/avoid_upgrading 

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
  pass
17
17
pass
18
18
}}
19
 
  
20
 
<script type="text/javascript"><!--
21
 
function popup(url) {
22
 
  newwindow=window.open(url,'name','height=400,width=600');
23
 
  if (window.focus) newwindow.focus();
24
 
  return false;
25
 
}
26
 
function collapse(id) { jQuery('#'+id).slideToggle(); }
27
 
function fade(id,value) { if(value>0) jQuery('#'+id).hide().fadeIn('slow'); else jQuery('#'+id).show().fadeOut('slow'); }
28
 
function ajax(u,s,t) {
29
 
    query = '';
30
 
    if (typeof s == "string") {
31
 
        d = jQuery(s).serialize();
32
 
        if(d){ query = d; }
33
 
    } else {
34
 
        pcs = [];
35
 
        for(i=0; i<s.length; i++) {
36
 
            q = jQuery("[name="+s[i]+"]").serialize();
37
 
            if(q){pcs.push(q);}
38
 
        }
39
 
        if (pcs.length>0){query = pcs.join("&");}
40
 
    }
41
 
    jQuery.ajax({type: "POST", url: u, data: query, success: function(msg) { if(t) { if(t==':eval') eval(msg); else jQuery("#" + t).html(msg); } } }); 
42
 
}
43
 
 
44
 
String.prototype.reverse = function () { return this.split('').reverse().join('');};
45
 
function web2py_ajax_init() {
46
 
  jQuery('.hidden').hide();
47
 
  jQuery('.error').hide().slideDown('slow');
48
 
  jQuery('.flash').click(function() { jQuery(this).fadeOut('slow'); return false; });
49
 
  // jQuery('input[type=submit]').click(function(){var t=jQuery(this);t.hide();t.after('<input class="submit_disabled" disabled="disabled" type="submit" name="'+t.attr("name")+'_dummy" value="'+t.val()+'">')});
50
 
  jQuery('input.integer').live('keyup', function(){this.value=this.value.reverse().replace(/[^0-9\-]|\-(?=.)/g,'').reverse();});
51
 
  jQuery('input.double,input.decimal').live('keyup', function(){this.value=this.value.reverse().replace(/[^0-9\-\.,]|[\-](?=.)|[\.,](?=[0-9]*[\.,])/g,'').reverse();});
52
 
  jQuery("input[type='checkbox'].delete").live('click', function(){ if(this.checked) if(!confirm("{{=T('Sure you want to delete this object?')}}")) this.checked=false; });
53
 
  try {jQuery("input.date").live('focus',function() {Calendar.setup({
54
 
     inputField:this, ifFormat:"{{=T('%Y-%m-%d')}}", showsTime:false
55
 
  }); }); } catch(e) {};
56
 
  try { jQuery("input.datetime").live('focus', function() {Calendar.setup({
57
 
     inputField:this, ifFormat:"{{=T('%Y-%m-%d %H:%M:%S')}}", showsTime: true,timeFormat: "24"
58
 
  }); }); } catch(e) {};
59
 
 
60
 
  jQuery("input.time").live('focus', function() { var el = jQuery(this); 
61
 
          if (!el.hasClass('hasTimeEntry')) try { el.timeEntry(); } catch(e) {}; 
62
 
  });
63
 
};
64
 
 
65
 
jQuery(function() {   
66
 
   var flash = jQuery('.flash');
67
 
   flash.hide();
68
 
   if(flash.html()) flash.slideDown();
69
 
   web2py_ajax_init();
70
 
});
71
 
function web2py_trap_form(action,target) {
72
 
   jQuery('#'+target+' form').each(function(i){
73
 
      var form=jQuery(this);
74
 
      if(!form.hasClass('no_trap'))
75
 
        form.submit(function(obj){
76
 
         jQuery('.flash').hide().html('');
77
 
         web2py_ajax_page('post',action,form.serialize(),target);
78
 
         return false;
79
 
      });
80
 
   });
81
 
}
82
 
function web2py_ajax_page(method,action,data,target) {
83
 
  jQuery.ajax({'type':method,'url':action,'data':data,
84
 
    'beforeSend':function(xhr) {
85
 
      xhr.setRequestHeader('web2py-component-location',document.location);
86
 
      xhr.setRequestHeader('web2py-component-element',target);},
87
 
    'complete':function(xhr,text){
88
 
      var html=xhr.responseText;
89
 
      var content=xhr.getResponseHeader('web2py-component-content'); 
90
 
      var command=xhr.getResponseHeader('web2py-component-command');
91
 
      var flash=xhr.getResponseHeader('web2py-component-flash');
92
 
      var t = jQuery('#'+target);
93
 
      if(content=='prepend') t.prepend(html); 
94
 
      else if(content=='append') t.append(html);
95
 
      else if(content!='hide') t.html(html);  
96
 
      web2py_trap_form(action,target);
97
 
      web2py_ajax_init();      
98
 
      if(command) eval(command);
99
 
      if(flash) jQuery('.flash').html(flash).slideDown();
100
 
      }
101
 
    });
102
 
}
103
 
function web2py_component(action,target) {
104
 
  jQuery(function(){ web2py_ajax_page('get',action,null,target); });
105
 
}
106
 
function web2py_comet(url,onmessage,onopen,onclose) {
107
 
  if ("WebSocket" in window) {
108
 
    var ws = new WebSocket(url);
109
 
    ws.onopen = onopen?onopen:(function(){});
110
 
    ws.onmessage = onmessage;
111
 
    ws.onclose = onclose?onclose:(function(){});
112
 
    return true; // supported
113
 
  } else return false; // not supported
114
 
}
115
 
//--></script>
 
19
 
 
20
    <script type="text/javascript"><!--
 
21
        // These variables are used by the web2py_ajax_init function in web2py_ajax.js (which is loaded below).
 
22
    var w2p_ajax_confirm_message = "{{=T('Are you sure you want to delete this object?')}}";
 
23
    var w2p_ajax_date_format = "{{=T('%Y-%m-%d')}}";
 
24
    var w2p_ajax_datetime_format = "{{=T('%Y-%m-%d %H:%M:%S')}}";
 
25
    //--></script>
 
26
 
 
27
    <script src="{{=URL('static','js/web2py_ajax.js')}}" type="text/javascript"></script>