| 1 | ################################################################################
|
|---|
| 2 | # ZMSWorkflowActivitiesManager.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 ZPublisher.HTTPRequest
|
|---|
| 21 | import copy
|
|---|
| 22 | import sys
|
|---|
| 23 | import time
|
|---|
| 24 | import urllib
|
|---|
| 25 | # Product Imports.
|
|---|
| 26 | import _blobfields
|
|---|
| 27 | import _globals
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 | ################################################################################
|
|---|
| 31 | ################################################################################
|
|---|
| 32 | ###
|
|---|
| 33 | ### Class
|
|---|
| 34 | ###
|
|---|
| 35 | ################################################################################
|
|---|
| 36 | ################################################################################
|
|---|
| 37 | class ZMSWorkflowActivitiesManager:
|
|---|
| 38 |
|
|---|
| 39 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 40 | ZMSWorkflowActivitiesManager.setActivity
|
|---|
| 41 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 42 | def setActivity(self, id, newId, newName, newIcon=None):
|
|---|
| 43 | obs = self.activities
|
|---|
| 44 | # Remove exisiting entry.
|
|---|
| 45 | if id in obs:
|
|---|
| 46 | i = obs.index(id)
|
|---|
| 47 | del obs[i]
|
|---|
| 48 | del obs[i]
|
|---|
| 49 | else:
|
|---|
| 50 | i = len(obs)
|
|---|
| 51 | # Values.
|
|---|
| 52 | newValues = {}
|
|---|
| 53 | newValues['name'] = newName
|
|---|
| 54 | newValues['icon'] = newIcon
|
|---|
| 55 | for obj_id in ['%s.icon'%str(id),'%s.icon'%str(newId)]:
|
|---|
| 56 | if obj_id in self.objectIds():
|
|---|
| 57 | self.manage_delObjects([obj_id])
|
|---|
| 58 | if isinstance(newIcon,_blobfields.MyBlob):
|
|---|
| 59 | self.manage_addFile(id='%s.icon'%newId,title=newIcon.getFilename(),file=newIcon.getData())
|
|---|
| 60 | # Update attribute.
|
|---|
| 61 | obs.insert(i,newValues)
|
|---|
| 62 | obs.insert(i,newId)
|
|---|
| 63 | self.activities = copy.copy(obs)
|
|---|
| 64 | # Return with new id.
|
|---|
| 65 | return newId
|
|---|
| 66 |
|
|---|
| 67 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 68 | ZMSWorkflowActivitiesManager.getActivities
|
|---|
| 69 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 70 | def getActivities(self):
|
|---|
| 71 | obs = self.activities
|
|---|
| 72 | activities = []
|
|---|
| 73 | for i in range(len(obs)/2):
|
|---|
| 74 | id = obs[i*2]
|
|---|
| 75 | activity = obs[i*2+1].copy()
|
|---|
| 76 | activity['id'] = id
|
|---|
| 77 | activities.append(activity)
|
|---|
| 78 | return activities
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 82 | ZMSWorkflowActivitiesManager.getActivityIds
|
|---|
| 83 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 84 | def getActivityIds(self):
|
|---|
| 85 | obs = self.getActivities()
|
|---|
| 86 | return map(lambda x: x['id'], obs)
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 90 | ZMSWorkflowActivitiesManager.getActivity
|
|---|
| 91 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 92 | def getActivity(self, id, for_export=False):
|
|---|
| 93 | activity = filter(lambda x: x['id']==id, self.getActivities())[0]
|
|---|
| 94 | activity = copy.deepcopy(activity)
|
|---|
| 95 | if not for_export:
|
|---|
| 96 | if activity['icon']:
|
|---|
| 97 | activity['icon'] = self.absolute_url()+'/'+id+'.icon'
|
|---|
| 98 | return activity
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 102 | ZMSWorkflowActivitiesManager.getActivityDetails
|
|---|
| 103 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 104 | def getActivityDetails(self, id):
|
|---|
| 105 | ids = self.getActivityIds()
|
|---|
| 106 | froms = []
|
|---|
| 107 | tos = []
|
|---|
| 108 | for transition in self.getTransitions():
|
|---|
| 109 | if transition['to'] is not None and len(transition['to']) > 0 and id in transition['to']:
|
|---|
| 110 | for ac_id in transition['from']:
|
|---|
| 111 | if ac_id in ids:
|
|---|
| 112 | idx = ids.index(ac_id)
|
|---|
| 113 | if idx not in froms:
|
|---|
| 114 | froms.append(idx)
|
|---|
| 115 | if transition['from'] is not None and len(transition['from']) > 0 and id in transition['from']:
|
|---|
| 116 | for ac_id in transition['to']:
|
|---|
| 117 | if ac_id in ids:
|
|---|
| 118 | idx = ids.index(ac_id)
|
|---|
| 119 | if idx not in tos:
|
|---|
| 120 | tos.append(idx)
|
|---|
| 121 | froms.sort()
|
|---|
| 122 | tos.sort()
|
|---|
| 123 | idxs = self.concat_list(froms,tos)
|
|---|
| 124 | idx = ids.index(id)
|
|---|
| 125 | return {'froms':froms, 'tos': tos, 'idxs': idxs, 'idx': idx}
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 129 | ZMSWorkflowActivitiesManager.manage_changeActivities
|
|---|
| 130 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|---|
| 131 | def manage_changeActivities(self, lang, btn='', REQUEST=None, RESPONSE=None):
|
|---|
| 132 | """ ZMSWorkflowActivitiesManager.manage_changeActivities """
|
|---|
| 133 | message = ''
|
|---|
| 134 | id = REQUEST.get('id','')
|
|---|
| 135 |
|
|---|
| 136 | # Cancel.
|
|---|
| 137 | # -------
|
|---|
| 138 | if btn in [ self.getZMILangStr('BTN_CANCEL'), self.getZMILangStr('BTN_BACK')]:
|
|---|
| 139 | id = ''
|
|---|
| 140 |
|
|---|
| 141 | # Change.
|
|---|
| 142 | # -------
|
|---|
| 143 | if btn == self.getZMILangStr('BTN_SAVE'):
|
|---|
| 144 | item = self.getActivity(id)
|
|---|
| 145 | newId = REQUEST.get('inpId').strip()
|
|---|
| 146 | newName = REQUEST.get('inpName').strip()
|
|---|
| 147 | newIcon = REQUEST.get('inpIcon','')
|
|---|
| 148 | if isinstance(newIcon,ZPublisher.HTTPRequest.FileUpload):
|
|---|
| 149 | if len(getattr(newIcon,'filename',''))==0:
|
|---|
| 150 | newIcon = item.get('icon',None)
|
|---|
| 151 | else:
|
|---|
| 152 | newIcon = _blobfields.createBlobField(self,_globals.DT_IMAGE,newIcon)
|
|---|
| 153 | id = self.setActivity( item.get('id',None), newId, newName, newIcon)
|
|---|
| 154 | message = self.getZMILangStr('MSG_CHANGED')
|
|---|
| 155 |
|
|---|
| 156 | # Delete.
|
|---|
| 157 | # -------
|
|---|
| 158 | elif btn in ['delete',self.getZMILangStr('BTN_DELETE')]:
|
|---|
| 159 | id = self.delItem(id, 'activities')
|
|---|
| 160 | message = self.getZMILangStr('MSG_CHANGED')
|
|---|
| 161 |
|
|---|
| 162 | # Insert.
|
|---|
| 163 | # -------
|
|---|
| 164 | elif btn == self.getZMILangStr('BTN_INSERT'):
|
|---|
| 165 | item = {}
|
|---|
| 166 | newId = REQUEST.get('newId').strip()
|
|---|
| 167 | newName = REQUEST.get('newName').strip()
|
|---|
| 168 | newIcon = REQUEST.get('newIcon','')
|
|---|
| 169 | if isinstance(newIcon,ZPublisher.HTTPRequest.FileUpload):
|
|---|
| 170 | if len(getattr(newIcon,'filename',''))==0:
|
|---|
| 171 | newIcon = item.get('icon',None)
|
|---|
| 172 | else:
|
|---|
| 173 | newIcon = _blobfields.createBlobField(self,_globals.DT_IMAGE,newIcon)
|
|---|
| 174 | id = self.setActivity( item.get('id',None), newId, newName, newIcon)
|
|---|
| 175 | message = self.getZMILangStr('MSG_INSERTED')%id
|
|---|
| 176 |
|
|---|
| 177 | # Move to.
|
|---|
| 178 | # --------
|
|---|
| 179 | elif btn == 'move_to':
|
|---|
| 180 | pos = REQUEST['pos']
|
|---|
| 181 | self.moveItem(id, pos, 'activities')
|
|---|
| 182 | message = self.getZMILangStr('MSG_MOVEDOBJTOPOS')%(("<i>%s</i>"%id),(pos+1))
|
|---|
| 183 | id = ''
|
|---|
| 184 |
|
|---|
| 185 | # Return with message.
|
|---|
| 186 | message = urllib.quote(message)
|
|---|
| 187 | return RESPONSE.redirect('manage_main?lang=%s&manage_tabs_message=%s#_Activities'%(lang,message))
|
|---|
| 188 |
|
|---|
| 189 | ################################################################################
|
|---|