~pexego/openobject-addons/6.1-pexego-sale_commission

« back to all changes in this revision

Viewing changes to django_pos/apps/dajax/core/Dajax.py

  • Committer: Santi Argueso (Pexego)
  • Date: 2013-02-06 17:03:36 UTC
  • mfrom: (10.1.6 pexego-addons_6.1)
  • Revision ID: santiago@pexego.es-20130206170336-ml430s6p9jknun0j
[MERGE]

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#----------------------------------------------------------------------
 
2
# Copyright (c) 2009-2010 Benito Jorge Bastida
 
3
# All rights reserved.
 
4
#  Redistribution and use in source and binary forms, with or without
 
5
#  modification, are permitted provided that the following conditions are
 
6
#  met:
 
7
#
 
8
#    o Redistributions of source code must retain the above copyright
 
9
#      notice, this list of conditions, and the disclaimer that follows.
 
10
#
 
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
 
14
#      distribution.
 
15
#
 
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.
 
19
#
 
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
 
31
#  DAMAGE.
 
32
#----------------------------------------------------------------------
 
33
 
 
34
from django.utils import simplejson as json
 
35
 
 
36
class Dajax(object):
 
37
 
 
38
    def __init__(self):
 
39
        self.calls = []
 
40
        
 
41
    def json(self):
 
42
        return json.dumps(self.calls)
 
43
        
 
44
    def alert(self,message):
 
45
        self.calls.append({'cmd':'alert','val':self._clean(message)})
 
46
            
 
47
    def assign(self,id,attribute,value):
 
48
        self.calls.append({'cmd':'as','id':id,'prop':attribute,'val':self._clean(value)})
 
49
        
 
50
    def add_css_class(self,id,value):
 
51
        if not hasattr(value,'__iter__'):
 
52
            value = [value]
 
53
        self.calls.append({'cmd':'addcc','id':id,'val':self._clean(value)})
 
54
        
 
55
    def remove_css_class(self,id,value):
 
56
        if not hasattr(value,'__iter__'):
 
57
            value = [value]
 
58
        self.calls.append({'cmd':'remcc','id':id,'val':self._clean(value)})
 
59
    
 
60
    def append(self,id,attribute,value):
 
61
        self.calls.append({'cmd':'ap','id':id,'prop':attribute,'val':self._clean(value)})
 
62
        
 
63
    def prepend(self,id,attribute,value):
 
64
        self.calls.append({'cmd':'pp','id':id,'prop':attribute,'val':self._clean(value)})
 
65
        
 
66
    def clear(self,id,attribute):
 
67
        self.calls.append({'cmd':'clr','id':id,'prop':attribute})
 
68
        
 
69
    def redirect(self,url,delay=0):
 
70
        self.calls.append({'cmd':'red','url':url,'delay':delay})
 
71
        
 
72
    def script(self,code):#OK
 
73
        self.calls.append({'cmd':'js','val':code})
 
74
        
 
75
    def remove(self,id):
 
76
        self.calls.append({'cmd':'rm','id':id})
 
77
        
 
78
    def add_data(self,data,function):
 
79
        self.calls.append({'cmd':'data','val':data,'fun':function})
 
80
    
 
81
    def _clean(self, data):
 
82
        if hasattr(data,'__iter__'):
 
83
            return map(self._clean,data)
 
84
        else:
 
85
            return unicode(data).replace('\n','').replace('\r','')
 
 
b'\\ No newline at end of file'