From b76af3e0c2c461a959c96449d94d16e48913df7f Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Fri, 11 Jan 2013 10:52:54 +0100 Subject: [PATCH] [gen] Allow Managers to delete data change events if things go wrong. --- gen/mixins/__init__.py | 22 +++++++++++++++++++++- gen/ui/appy.js | 7 +++++++ gen/ui/page.pt | 13 ++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/gen/mixins/__init__.py b/gen/mixins/__init__.py index f70b7c0..1f20560 100644 --- a/gen/mixins/__init__.py +++ b/gen/mixins/__init__.py @@ -102,7 +102,7 @@ class BaseMixin: return obj, msg def delete(self): - '''This methods is self's suicide.''' + '''This method is self's suicide.''' # Call a custom "onDelete" if it exists appyObj = self.appy() if hasattr(appyObj, 'onDelete'): appyObj.onDelete() @@ -129,6 +129,26 @@ class BaseMixin: self.say(self.translate('delete_done')) self.goto(urlBack) + def onDeleteEvent(self): + '''Called when an event (from object history) deletion is triggered + from the ui.''' + rq = self.REQUEST + # Re-create object history, but without the event corresponding to + # rq['eventTime'] + history = [] + from DateTime import DateTime + eventToDelete = DateTime(rq['eventTime']) + key = self.workflow_history.keys()[0] + for event in self.workflow_history[key]: + if (event['action'] != '_datachange_') or \ + (event['time'] != eventToDelete): + history.append(event) + self.workflow_history[key] = tuple(history) + appy = self.appy() + self.log('Data change event deleted by %s for %s (UID=%s).' % \ + (appy.user.getId(), appy.klass.__name__, appy.uid)) + self.goto(self.getUrl(rq['HTTP_REFERER'])) + def onUnlink(self): '''Called when an object unlinking is triggered from the ui.''' rq = self.REQUEST diff --git a/gen/ui/appy.js b/gen/ui/appy.js index aa9d8a6..cbb4283 100644 --- a/gen/ui/appy.js +++ b/gen/ui/appy.js @@ -351,6 +351,13 @@ function onDeleteObject(objectUid) { askConfirm('form', 'deleteForm', delete_confirm); } +function onDeleteEvent(objectUid, eventTime) { + f = document.getElementById('deleteEventForm'); + f.objectUid.value = objectUid; + f.eventTime.value = eventTime; + askConfirm('form', 'deleteEventForm', delete_confirm); +} + function onUnlinkObject(sourceUid, fieldName, targetUid) { f = document.getElementById('unlinkForm'); f.sourceUid.value = sourceUid; diff --git a/gen/ui/page.pt b/gen/ui/page.pt index 4ef55ae..fde3492 100644 --- a/gen/ui/page.pt +++ b/gen/ui/page.pt @@ -18,6 +18,12 @@ + Global form for deleting an event from an object's history +
+ + + +
Global form for unlinking an object
@@ -98,7 +104,12 @@ state event/review_state|nothing; isDataChange python: event['action'] == '_datachange_'" tal:attributes="class python:test(odd, 'even', 'odd')" valign="top"> - + + + +