1
#----------------------------------------------------------------------
2
# Copyright (c) 2009-2010 Benito Jorge Bastida
4
# Redistribution and use in source and binary forms, with or without
5
# modification, are permitted provided that the following conditions are
8
# o Redistributions of source code must retain the above copyright
9
# notice, this list of conditions, and the disclaimer that follows.
11
# o Redistributions in binary form must reproduce the above copyright
12
# notice, this list of conditions, and the following disclaimer in
13
# the documentation and/or other materials provided with the
16
# o Neither the name of Digital Creations nor the names of its
17
# contributors may be used to endorse or promote products derived
18
# from this software without specific prior written permission.
20
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS AND CONTRIBUTORS *AS
21
# IS* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL
24
# CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
29
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
32
#----------------------------------------------------------------------
34
from django.utils import simplejson as json
42
return json.dumps(self.calls)
44
def alert(self,message):
45
self.calls.append({'cmd':'alert','val':self._clean(message)})
47
def assign(self,id,attribute,value):
48
self.calls.append({'cmd':'as','id':id,'prop':attribute,'val':self._clean(value)})
50
def add_css_class(self,id,value):
51
if not hasattr(value,'__iter__'):
53
self.calls.append({'cmd':'addcc','id':id,'val':self._clean(value)})
55
def remove_css_class(self,id,value):
56
if not hasattr(value,'__iter__'):
58
self.calls.append({'cmd':'remcc','id':id,'val':self._clean(value)})
60
def append(self,id,attribute,value):
61
self.calls.append({'cmd':'ap','id':id,'prop':attribute,'val':self._clean(value)})
63
def prepend(self,id,attribute,value):
64
self.calls.append({'cmd':'pp','id':id,'prop':attribute,'val':self._clean(value)})
66
def clear(self,id,attribute):
67
self.calls.append({'cmd':'clr','id':id,'prop':attribute})
69
def redirect(self,url,delay=0):
70
self.calls.append({'cmd':'red','url':url,'delay':delay})
72
def script(self,code):#OK
73
self.calls.append({'cmd':'js','val':code})
76
self.calls.append({'cmd':'rm','id':id})
78
def add_data(self,data,function):
79
self.calls.append({'cmd':'data','val':data,'fun':function})
81
def _clean(self, data):
82
if hasattr(data,'__iter__'):
83
return map(self._clean,data)
85
return unicode(data).replace('\n','').replace('\r','')
b'\\ No newline at end of file'