Back to index

plone3  3.1.7
Public Member Functions
kss.core.plugins.core.demo.addressbook.KSSDynamicTableDemo Class Reference
Inheritance diagram for kss.core.plugins.core.demo.addressbook.KSSDynamicTableDemo:
Inheritance graph
[legend]
Collaboration diagram for kss.core.plugins.core.demo.addressbook.KSSDynamicTableDemo:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def getPersons
def cleanPersons
def addPerson
def removePerson
def moveUp
def moveDown
def toTop
def toBottom
def switchPersons
def renderPersonAsTr

Detailed Description

Definition at line 22 of file addressbook.py.


Member Function Documentation

def kss.core.plugins.core.demo.addressbook.KSSDynamicTableDemo.addPerson (   self,
  name,
  address,
  city,
  country,
  telephone 
)
adds a person

Definition at line 35 of file addressbook.py.

00035 
00036     def addPerson(self, name, address, city, country, telephone):
00037         """ adds a person"""
00038         persons = self.getPersons()
00039         person = {
00040             'pid' : str(time()).replace('.',''),
00041             'name' : name,
00042             'address' : address,
00043             'city' : city,
00044             'country' : country,
00045             'telephone' : telephone
00046         }
00047         persons.append(person)
00048         html = self.renderPersonAsTr(person)
00049         self.getCommandSet('core').insertHTMLAsLastChild('table#personTable tbody', html)
00050         return self.render()
00051     

Definition at line 30 of file addressbook.py.

00030 
00031     def cleanPersons(self):
00032         self.request.SESSION['persons'] = PersistentList()
00033         self.getCommandSet('core').replaceHTML('table#personTable tbody', '<tbody></tbody>')
00034         return self.render()

Definition at line 24 of file addressbook.py.

00024 
00025     def getPersons(self):
00026         persons = self.request.SESSION.get('persons', PersistentList())
00027         if not persons or not isinstance(persons, PersistentList):
00028             persons = self.request.SESSION['persons'] = PersistentList()
00029         return persons

Here is the caller graph for this function:

Definition at line 71 of file addressbook.py.

00071 
00072     def moveDown(self, pid):
00073         persons = self.getPersons()
00074         for i in range(0, len(persons)-1):
00075             pid1 = persons[i]['pid']
00076             pid2 = persons[i+1]['pid']
00077             if pid==pid1:
00078                 self.switchPersons(pid1, pid2)
00079                 break
00080         return self.render()

Here is the caller graph for this function:

Definition at line 61 of file addressbook.py.

00061 
00062     def moveUp(self, pid):
00063         persons = self.getPersons()
00064         for i in range(1, len(persons)):
00065             pid1 = persons[i]['pid']
00066             pid2 = persons[i-1]['pid']
00067             if pid==pid1:
00068                 self.switchPersons(pid1, pid2)
00069                 break
00070         return self.render()

Here is the caller graph for this function:

Definition at line 52 of file addressbook.py.

00052 
00053     def removePerson(self, pid):
00054         persons = self.getPersons()
00055         for p in persons:
00056             if p['pid'] == pid:
00057                 persons.remove(p)
00058         self.getCommandSet('core').deleteNode('tr#pid%s' % pid)
00059         return self.render()
00060 

Definition at line 130 of file addressbook.py.

00130 
00131     def renderPersonAsTr(self, person):
00132         pid = person['pid']
00133         buttons = '''
00134                     <input type="button" class="button remove kssattr-pid-%(pid)s" value="Remove">
00135                     <input type="button" class="button moveUp kssattr-pid-%(pid)s" value="Up">
00136                     <input type="button" class="button moveDown kssattr-pid-%(pid)s" value="Down">
00137                     <input type="button" class="button toTop kssattr-pid-%(pid)s" value="Top">
00138                     <input type="button" class="button toBottom kssattr-pid-%(pid)s" value="Bottom">
00139                 ''' % {'pid' : pid}
00140         html = """<tr id="pid%(pid)s"><td>%(name)s</td><td>%(address)s</td><td>%(city)s</td><td>%(country)s</td><td>%(telephone)s</td><td>%(buttons)s</td></tr>""" % {
00141                 'pid' : person['pid'],
00142                 'name' : person['name'],
00143                 'address' : person['address'],
00144                 'city' : person['city'],
00145                 'country' : person['country'],
00146                 'telephone' : person['telephone'],
00147                 'buttons' : buttons
00148         }
00149         return html
00150 
00151 

Here is the caller graph for this function:

Definition at line 108 of file addressbook.py.

00108 
00109     def switchPersons(self, pid1, pid2):
00110         persons = self.getPersons()
00111         p1 = None
00112         i1 = None
00113         p2 = None
00114         i2 = None
00115         for i in range(0, len(persons)):
00116             if persons[i]['pid'] == pid1:
00117                 p1 = persons[i]
00118                 i1 = i
00119             if persons[i]['pid'] == pid2:
00120                 p2 = persons[i]
00121                 i2 = i
00122         if p1 and p2:
00123             self.getCommandSet('core').replaceHTML('tr#pid%s' % p2['pid'], '<tr class="placeholder"></tr>')
00124             self.getCommandSet('core').replaceHTML('tr#pid%s' % p1['pid'], self.renderPersonAsTr(p2))
00125             self.getCommandSet('core').replaceHTML('tr.placeholder', self.renderPersonAsTr(p1))
00126             persons[i1] = p2
00127             persons[i2] = p1
00128 
00129 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 94 of file addressbook.py.

00094 
00095     def toBottom(self, pid):
00096         persons = self.getPersons()
00097         lastPid = persons[-1]['pid']
00098         if lastPid == pid:
00099             return self.render()
00100         self.getCommandSet('core').moveNodeAfter('tr#pid%s' % pid, 'pid%s' % lastPid)
00101         for p in persons:
00102             if p['pid'] == pid:
00103                 persons.remove(p)
00104                 persons.append(p)
00105                 break
00106         return self.render()
00107 

Definition at line 81 of file addressbook.py.

00081 
00082     def toTop(self, pid):
00083         persons = self.getPersons()
00084         firstPid = persons[0]['pid']
00085         if firstPid == pid:
00086             return self.render()
00087         self.getCommandSet('core').moveNodeBefore('tr#pid%s' % pid, 'pid%s' % firstPid)
00088         for p in persons:
00089             if p['pid'] == pid:
00090                 persons.remove(p)
00091                 persons.insert(0, p)
00092                 break
00093         return self.render()


The documentation for this class was generated from the following file: