| 1 | ################################################################################
|
|---|
| 2 | # ZMSWorkflowTransitionsManager.py
|
|---|
| 3 | #
|
|---|
| 4 | # This program is free software; you can redistribute it and/or
|
|---|
| 5 | # modify it under the terms of the GNU General Public License
|
|---|
| 6 | # as published by the Free Software Foundation; either version 2
|
|---|
| 7 | # of the License, or (at your option) any later version.
|
|---|
| 8 | #
|
|---|
| 9 | # This program is distributed in the hope that it will be useful,
|
|---|
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | # GNU General Public License for more details.
|
|---|
| 13 | #
|
|---|
| 14 | # You should have received a copy of the GNU General Public License
|
|---|
| 15 | # along with this program; if not, write to the Free Software
|
|---|
| 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|---|
| 17 | ################################################################################
|
|---|
| 18 |
|
|---|
| 19 | # Imports.
|
|---|
| 20 | import copy
|
|---|
| 21 | import sys
|
|---|
| 22 | import time
|
|---|
| 23 | import urllib
|
|---|
| 24 | # Product Imports.
|
|---|
| 25 | import _globals
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | ################################################################################
|
|---|
| 29 | ################################################################################
|
|---|
| 30 | ###
|
|---|
| 31 | ### Class
|
|---|
| 32 | ###
|
|---|
| 33 | ################################################################################
|
|---|
| 34 | ################################################################################
|
|---|
| 35 | class ZMSWorkflowTransitionsManager:
|
|---|
| 36 |
|
|---|
| 37 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 38 | ZMSWorkflowTransitionsManager.setTransition
|
|---|
| 39 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 40 | def setTransition(self, id, newId, newName, newFrom, newTo, newPerformer=[], newDtml=''):
|
|---|
| 41 | message = ''
|
|---|
| 42 | obs = self.transitions
|
|---|
| 43 | # Remove exisiting entry.
|
|---|
| 44 | if id in obs:
|
|---|
| 45 | i = obs.index(id)
|
|---|
| 46 | del obs[i]
|
|---|
| 47 | del obs[i]
|
|---|
| 48 | else:
|
|---|
| 49 | i = len(obs)
|
|---|
| 50 | if len(newTo) == 0:
|
|---|
| 51 | newTo = []
|
|---|
| 52 | elif type(newTo) is str:
|
|---|
| 53 | newTo = [newTo]
|
|---|
| 54 | # Parse Dtml.
|
|---|
| 55 | message = _globals.dt_parse(self,newDtml)
|
|---|
| 56 | if len( message) > 0:
|
|---|
| 57 | message = '<div style="color:red; background-color:yellow; ">%s</div>'%message
|
|---|
| 58 | # Values.
|
|---|
| 59 | newValues = {}
|
|---|
| 60 | newValues['name'] = newName
|
|---|
| 61 | newValues['from'] = newFrom
|
|---|
| 62 | newValues['to'] = newTo
|
|---|
| 63 | newValues['performer'] = newPerformer
|
|---|
| 64 | newValues['dtml'] = newDtml
|
|---|
| 65 | for obj_id in [str(id),str(newId)]:
|
|---|
| 66 | if obj_id in self.objectIds():
|
|---|
| 67 | self.manage_delObjects([obj_id])
|
|---|
| 68 | self.manage_addDTMLMethod(newId,newName,newDtml)
|
|---|
| 69 | # Update attribute.
|
|---|
| 70 | obs.insert(i,newValues)
|
|---|
| 71 | obs.insert(i,newId)
|
|---|
| 72 | self.transitions = copy.copy(obs)
|
|---|
| 73 | # Return with message.
|
|---|
| 74 | return message
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 78 | ZMSWorkflowTransitionsManager.getTransitions
|
|---|
| 79 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 80 | def getTransitions(self):
|
|---|
| 81 | obs = self.transitions
|
|---|
| 82 | transitions = []
|
|---|
| 83 | for i in range(len(obs)/2):
|
|---|
| 84 | id = obs[i*2]
|
|---|
| 85 | transition = obs[i*2+1].copy()
|
|---|
| 86 | transition['id'] = id
|
|---|
| 87 | transitions.append(transition)
|
|---|
| 88 | return transitions
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 92 | ZMSWorkflowTransitionsManager.getTransitionIds
|
|---|
| 93 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 94 | def getTransitionIds(self):
|
|---|
| 95 | obs = self.getTransitions()
|
|---|
| 96 | return map(lambda x: x['id'], obs)
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 100 | ZMSWorkflowTransitionsManager.getTransition
|
|---|
| 101 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 102 | def getTransition(self, id, for_export=False):
|
|---|
| 103 | transition = filter(lambda x: x['id']==id, self.getTransitions())[0]
|
|---|
| 104 | transition = copy.deepcopy(transition)
|
|---|
| 105 | transition['dtml'] = getattr(self,transition['id']).raw
|
|---|
| 106 | return transition
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 110 | ZMSWorkflowTransitionsManager.manage_changeTransitions:
|
|---|
| 111 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 112 | def manage_changeTransitions(self, lang, btn='', REQUEST=None, RESPONSE=None):
|
|---|
| 113 | """ ZMSWorkflowTransitionsManager.manage_changeTransitions """
|
|---|
| 114 | message = ''
|
|---|
| 115 | id = REQUEST.get('id','')
|
|---|
| 116 |
|
|---|
| 117 | # Cancel.
|
|---|
| 118 | # -------
|
|---|
| 119 | if btn in [ self.getZMILangStr('BTN_CANCEL'), self.getZMILangStr('BTN_BACK')]:
|
|---|
| 120 | id = ''
|
|---|
| 121 |
|
|---|
| 122 | # Change.
|
|---|
| 123 | # -------
|
|---|
| 124 | if btn == self.getZMILangStr('BTN_SAVE'):
|
|---|
| 125 | item = self.getTransition(id)
|
|---|
| 126 | newId = REQUEST.get('inpId').strip()
|
|---|
| 127 | newName = REQUEST.get('inpName').strip()
|
|---|
| 128 | newFrom = REQUEST.get('inpFrom')
|
|---|
| 129 | newTo = REQUEST.get('inpTo')
|
|---|
| 130 | newPerformer = REQUEST.get('inpPerformer',[])
|
|---|
| 131 | newDtml = REQUEST.get('inpDtml','').strip()
|
|---|
| 132 | message += self.setTransition( item.get('id',None), newId, newName, newFrom, newTo, newPerformer, newDtml)
|
|---|
| 133 | message += self.getZMILangStr('MSG_CHANGED')
|
|---|
| 134 | id = newId
|
|---|
| 135 |
|
|---|
| 136 | # Delete.
|
|---|
| 137 | # -------
|
|---|
| 138 | elif btn in ['delete',self.getZMILangStr('BTN_DELETE')]:
|
|---|
| 139 | id = self.delItem(id, 'transitions')
|
|---|
| 140 | message = self.getZMILangStr('MSG_CHANGED')
|
|---|
| 141 |
|
|---|
| 142 | # Insert.
|
|---|
| 143 | # -------
|
|---|
| 144 | elif btn == self.getZMILangStr('BTN_INSERT'):
|
|---|
| 145 | item = {}
|
|---|
| 146 | newId = REQUEST.get('newId').strip()
|
|---|
| 147 | newName = REQUEST.get('newName').strip()
|
|---|
| 148 | newFrom = REQUEST.get('newFrom',[])
|
|---|
| 149 | newTo = REQUEST.get('newTo',[])
|
|---|
| 150 | newPerformer = REQUEST.get('newPerformer',[])
|
|---|
| 151 | newDtml = REQUEST.get('newDtml','').strip()
|
|---|
| 152 | message += self.setTransition( item.get('id',None), newId, newName, newFrom, newTo, newPerformer, newDtml)
|
|---|
| 153 | message += self.getZMILangStr('MSG_INSERTED')%id
|
|---|
| 154 | id = newId
|
|---|
| 155 |
|
|---|
| 156 | # Move to.
|
|---|
| 157 | # --------
|
|---|
| 158 | elif btn == 'move_to':
|
|---|
| 159 | pos = REQUEST['pos']
|
|---|
| 160 | self.moveItem(id, pos, 'transitions')
|
|---|
| 161 | message = self.getZMILangStr('MSG_MOVEDOBJTOPOS')%(("<i>%s</i>"%id),(pos+1))
|
|---|
| 162 | id = ''
|
|---|
| 163 |
|
|---|
| 164 | # Return with message.
|
|---|
| 165 | message = urllib.quote(message)
|
|---|
| 166 | return RESPONSE.redirect('manage_main?id=%s&lang=%s&manage_tabs_message=%s#_Transitions'%(id,lang,message))
|
|---|
| 167 |
|
|---|
| 168 | ################################################################################
|
|---|