20
<script type="text/javascript"><!--
22
newwindow=window.open(url,'name','height=400,width=600');
23
if (window.focus) newwindow.focus();
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) {
30
if (typeof s == "string") {
31
d = jQuery(s).serialize();
35
for(i=0; i<s.length; i++) {
36
q = jQuery("[name="+s[i]+"]").serialize();
39
if (pcs.length>0){query = pcs.join("&");}
41
jQuery.ajax({type: "POST", url: u, data: query, success: function(msg) { if(t) { if(t==':eval') eval(msg); else jQuery("#" + t).html(msg); } } });
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) {};
60
jQuery("input.time").live('focus', function() { var el = jQuery(this);
61
if (!el.hasClass('hasTimeEntry')) try { el.timeEntry(); } catch(e) {};
66
var flash = jQuery('.flash');
68
if(flash.html()) flash.slideDown();
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);
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);
98
if(command) eval(command);
99
if(flash) jQuery('.flash').html(flash).slideDown();
103
function web2py_component(action,target) {
104
jQuery(function(){ web2py_ajax_page('get',action,null,target); });
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
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')}}";
27
<script src="{{=URL('static','js/web2py_ajax.js')}}" type="text/javascript"></script>