-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
custom adapter for the status provider
- Loading branch information
Alessandro Pisa
committed
Feb 3, 2015
1 parent
5f97228
commit 63adc6b
Showing
4 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# -*- coding: utf-8 -*- | ||
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile | ||
from ploneintranet.workspace.workspacefolder import IWorkspaceFolder | ||
from plonesocial.microblog.browser.interfaces import IPlonesocialMicroblogLayer | ||
from plonesocial.microblog.browser.interfaces import IStatusProvider | ||
from plonesocial.microblog.browser.status import StatusProvider | ||
from zope.component import adapter | ||
from zope.interface import implementer | ||
from zope.interface import Interface | ||
|
||
|
||
@implementer(IStatusProvider) | ||
@adapter(IWorkspaceFolder, IPlonesocialMicroblogLayer, Interface) | ||
class WSStatusProvider(StatusProvider): | ||
''' | ||
status form provider to be used on a statusupdate for a workspace | ||
''' | ||
index = ViewPageTemplateFile('templates/status.pt') |
140 changes: 140 additions & 0 deletions
140
src/ploneintranet/workspace/browser/templates/status.pt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<tal:block tal:define="errors options/state/getErrors|nothing; | ||
portal_url view/portal_url" | ||
tal:condition="view/available" | ||
i18n:domain="plone"> | ||
|
||
<div id="microblog" class="plonesocial"> | ||
|
||
<fieldset tal:condition="not:view/compact"> | ||
|
||
<legend i18n:translate="label_add_status">Add status update</legend> | ||
<p tal:content="view/comment_transform_message"> | ||
You can add a comment by filling out the form below. Plain text | ||
formatting. | ||
</p> | ||
|
||
<div tal:replace="structure view/form/render" /> | ||
|
||
</fieldset> | ||
|
||
|
||
|
||
<form id="post-box" method="post" | ||
class="pat-inject update-social status-inactive" | ||
action="" | ||
data-pat-inject=" | ||
source: #activity-stream; | ||
target: #activity-stream::before | ||
&& #new-post-box | ||
" | ||
tal:condition="view/compact" | ||
tal:attributes="action request/ACTUAL_URL"> | ||
|
||
<script type="text/javascript"> | ||
<!-- Ideally this will be a separate pattern one day --> | ||
$(document).ready(function(){ | ||
var the_textarea = $('textarea.pat-comment-box'); | ||
function updateMirror(){ | ||
var the_mirror = the_textarea.siblings('p.content-mirror').find('.text'); | ||
var the_value = the_textarea.val(); | ||
the_mirror.text(the_value); | ||
}; | ||
|
||
$(document).on('input propertychange',the_textarea, function() { | ||
updateMirror(); | ||
}); | ||
|
||
$('form.update-social').submit(function(event){ | ||
var textarea = $(this).find('textarea'); | ||
var selected_tags = $(this).find('.selected-tags a'); | ||
var selected_users = $(this).find('.selected-users a'); | ||
var tags = ''; | ||
var users = ''; | ||
|
||
for (i = 0; i < selected_users.length; i++) { | ||
users = users + ' @' + selected_users[i].dataset.userId; | ||
} | ||
|
||
for (i = 0; i < selected_tags.length; i++) { | ||
tags = tags + ' ' + selected_tags[i].text; | ||
} | ||
|
||
users = users?' — ' + users:users | ||
tags = tags?' — ' + tags:tags | ||
|
||
textarea.val(textarea.val() + users + tags); | ||
}); | ||
}); | ||
</script> | ||
|
||
<fieldset> | ||
<!-- This content-mirror paragraph is oddly wrapped | ||
to avoid extra whitespace when it is rendered as a 'pre' --> | ||
<p class="content-mirror"><span class="text">What are you doing?</span><em class="selected-users" id="selected-users"><tal:users tal:condition="request/users|nothing"> — <tal:block tal:repeat="user request/users|nothing"><a tal:define="fullname python:context.portal_membership.getMemberById(user).getProperty('fullname')" tal:content="string:@${fullname|user}" tal:attributes="data-user-id user"/><tal:space condition="not:repeat/user/end"> </tal:space></tal:block></tal:users></em><em class="selected-tags" id="selected-tags"><tal:tags tal:condition="request/tags|nothing"> — <tal:block tal:repeat="tag request/tags|nothing" ><a tal:content="string:#${tag}" /><tal:space condition="not:repeat/tag/end"> </tal:space></tal:block></tal:tags></em></p> | ||
<textarea placeholder="Post a message…" | ||
class="pat-comment-box pat-switch focus" | ||
data-pat-switch="#post-box status-inactive status-active" | ||
name="form.widgets.text"></textarea> | ||
<fieldset | ||
tal:condition="view/is_attachment_supported" | ||
class="attachments pat-subform pat-autosubmit pat-inject" | ||
data-pat-inject="url: @@upload-attachments; source: #attachments; target: #post-box-attachment-previews"> | ||
<label class="iconified icon-attach pat-switch" | ||
data-pat-switch="#post-box status-* status-attach"><input multiple capture="camera" accept="image/*" type="file" title="Attach a file" name="form.widgets.attachments"> Attach a file (or create a picture)</label> | ||
<p class="attachment-previews" | ||
id="post-box-attachment-previews"> | ||
No attachments selected. | ||
</p> | ||
<input type="hidden" name="attachment-form-token" value="854e4838a29f4f378e0beaf3100f0b83-admin-20130807093933376415" tal:attributes="value view/form/attachment_form_token"> | ||
<span tal:replace="structure context/@@authenticator/authenticator"/> | ||
</fieldset> | ||
<div class="button-bar"> | ||
<a class="iconified icon-user-add pat-tooltip" | ||
data-pat-tooltip="position: tl; source: ajax; class: mentions;" | ||
tal:attributes="href string:${portal_url}/@@panel-users#status-user-selector::element" | ||
href="/feedback/panel-mentions.html#content">Mention people</a> | ||
<br/> | ||
<a class="iconified icon-tags pat-tooltip" | ||
data-pat-tooltip="position: tl; source: ajax; class: tags;" | ||
tal:attributes="href string:${context/portal_url}/@@panel-tags#status-tag-selector::element"> | ||
Add tags</a> | ||
<br/> | ||
<button | ||
class="pat-switch" | ||
data-pat-switch="#post-box status-* status-inactive" | ||
type="submit" | ||
name="form.buttons.statusupdate">Post</button> | ||
<button | ||
class="pat-switch" | ||
data-pat-switch="#post-box status-* status-inactive" | ||
type="reset">Cancel</button> | ||
</div> | ||
</fieldset> | ||
</form> | ||
</div> | ||
|
||
<style type="text/css"> | ||
/* XXX temporary hack | ||
These are overrides to some of Plone's overly-ambitious defaults, | ||
to allow ploneintranet.theme's styles to work for now. | ||
*/ | ||
.update-social fieldset { | ||
border-style: inherit !important; | ||
margin: inherit !important; | ||
} | ||
.update-social p.content-mirror { | ||
margin-bottom: -100% !important; | ||
} | ||
.update-social textarea { | ||
font: inherit !important; | ||
} | ||
.update-social .attachments { | ||
margin: 0 !important; | ||
} | ||
.update-social .attachment-previews { | ||
margin: inherit !important; | ||
} | ||
|
||
</style> | ||
|
||
</tal:block> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
from plone import api | ||
from ploneintranet.workspace.browser.status import WSStatusProvider | ||
from ploneintranet.workspace.tests.base import BaseTestCase | ||
from zope.component import getMultiAdapter | ||
from zope.interface import alsoProvides | ||
from plonesocial.microblog.browser.interfaces import IPlonesocialMicroblogLayer | ||
|
||
|
||
class TestAdapters(BaseTestCase): | ||
|
||
def test_status_update(self): | ||
""" | ||
We need a workspace folder | ||
We want to make sure the adapter registered for it | ||
is correctly picked up | ||
""" | ||
workspace_folder = api.content.create( | ||
self.portal, | ||
'ploneintranet.workspace.workspacefolder', | ||
'example-workspace' | ||
) | ||
|
||
request = self.request.clone() | ||
alsoProvides(request, IPlonesocialMicroblogLayer) | ||
provider = getMultiAdapter( | ||
(workspace_folder, request, self), | ||
name='plonesocial.microblog.status_provider' | ||
) | ||
self.assertIsInstance(provider, WSStatusProvider) |