work in progress: state change dialog

This commit is contained in:
Helmut Merz 2013-06-19 20:46:25 +02:00
parent bc24407d34
commit 9d3f6a2fb3
3 changed files with 109 additions and 7 deletions

View file

@ -1,5 +1,5 @@
#
# Copyright (c) 2012 Helmut Merz helmutm@cy55.de
# Copyright (c) 2013 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -26,9 +26,13 @@ from zope.cachedescriptors.property import Lazy
from zope.i18n import translate
from cybertools.browser.action import Action, actions
from cybertools.composer.schema.field import Field
from cybertools.composer.schema.interfaces import ISchemaFactory
from cybertools.composer.schema.schema import Schema
from cybertools.stateful.interfaces import IStateful, IStatesDefinition
from loops.browser.common import BaseView
from loops.browser.concept import ConceptView
from loops.browser.form import ObjectForm, EditObject
from loops.expert.query import And, Or, State, Type, getObjects
from loops.expert.browser.search import search_template
from loops.security.common import checkPermission
@ -83,16 +87,65 @@ class StateAction(Action):
for std in statefulActions:
actions.register('state.' + std, 'object', StateAction,
definition = std,
definition=std,
cssClass='icon-action',
)
class ChangeStateBase(object):
@Lazy
def stateful(self):
return component.getAdapter(self.view.context, IStateful,
name=self.definition)
@Lazy
def definition(self):
return self.request.form.get('stdef') or u''
@Lazy
def action(self):
return self.request.form.get('action') or u''
@Lazy
def stateObject(self):
return self.stateful.getStateObject()
class ChangeStateForm(ObjectForm, ChangeStateBase):
form_action = 'change_state_action'
data = {}
@Lazy
def macro(self):
return template.macros['change_state']
@Lazy
def schema(self):
# TODO: create schema directly, use field information specified
# in transition
commentsField = Field('comments', u'Comments', 'textarea',
description=u'Enter comments.')
fields = [commentsField]
return Schema(name='change_state', request=self.request,
manager=self, *fields)
#schemaFactory = ISchemaFactory(self.adapted)
#return schemaFactory(self.typeInterface, manager=self,
# request=self.request)
class ChangeState(EditObject, ChangeStateBase):
def update(self):
print '***', self.request.form
return True
#class StateQuery(ConceptView):
class StateQuery(BaseView):
template = template
form_action = 'execute_search_action'
@Lazy

View file

@ -77,7 +77,7 @@
set_schema="cybertools.stateful.interfaces.IStateful" />
</zope:class>
<!-- views -->
<!-- views and form controllers -->
<browser:page
for="loops.interfaces.IConcept"
@ -91,6 +91,19 @@
class="loops.organize.stateful.browser.FilterAllStates"
permission="zope.View" />
<browser:page
name="change_state.html"
for="loops.interfaces.INode"
class="loops.organize.stateful.browser.ChangeStateForm"
permission="zope.ManageContent" />
<zope:adapter
name="change_state"
for="loops.browser.node.NodeView
zope.publisher.interfaces.browser.IBrowserRequest"
factory="loops.organize.stateful.browser.ChangeState"
permission="zope.ManageContent" />
<!-- event handlers -->
<zope:subscriber handler="loops.organize.stateful.base.handleTransition" />

View file

@ -68,8 +68,6 @@
</metal:query>
<!-- portlets -->
<metal:actions define-macro="portlet_states">
<div tal:repeat="stf macro/stfs">
<div tal:condition="python:len(macro.stfs) > 1">
@ -87,7 +85,11 @@
<ul>
<li tal:repeat="action stf/getAvailableTransitionsForUser">
<a i18n:translate=""
tal:attributes="href string:change_state.html"
tal:define="baseUrl view/virtualTargetUrl;
url string:$baseUrl/change_state.html?action=${action/name}&stdef=${stf/statesDefinition}"
tal:attributes="href url;
onClick string:objectDialog('change_state', '$url');;
return false;"
tal:content="action/title" />
</li>
</ul>
@ -96,4 +98,38 @@
</metal:actions>
<metal:dialog define-macro="change_state">
<form name="stateful_changeState" method="post">
<div dojoType="dijit.layout.BorderContainer"
style="width: 70em; height: 600px">
<div dojoType="dijit.layout.ContentPane" region="center">
<h1 i18n:translate=""
tal:content="view/title" />
<input type="hidden" name="form.action" value="change_state">
<input type="hidden" name="stdef"
tal:attributes="value request/form/stdef|nothing">
<input type="hidden" name="action"
tal:attributes="value request/form/action|nothing">
<table cellpadding="3" class="form">
<tbody><tr><td colspan="5" style="padding-right: 15px">
<div id="form.fields">
<metal:fields use-macro="view/fieldRenderers/fields" />
</div>
</td></tr></tbody>
</table>
</div>
<div dojoType="dijit.layout.ContentPane" region="bottom">
<metal:buttons define-slot="buttons">
<input value="Save" type="submit"
onClick="submit();; return false"
i18n:attributes="value">
<input type="button" value="Cancel" onClick="dialog.hide();"
i18n:attributes="value">
</metal:buttons>
</div>
</div>
</form>
</metal:dialog>
</html>