Commit 003b0bc5 authored by Roque's avatar Roque

erp5_messenger: getting posts with jio allDocs

- get rid of scripts to add and get posts
parent fca49e31
......@@ -43,9 +43,7 @@
</item>
<item>
<key> <string>edit_order</string> </key>
<value>
<list/>
</value>
<value> <string>[]</string> </value>
</item>
<item>
<key> <string>encoding</string> </key>
......
......@@ -6,19 +6,6 @@
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>all_columns</string>
<string>columns</string>
<string>domain_root_list</string>
<string>domain_tree</string>
<string>selection_name</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>listbox</string> </value>
......@@ -31,6 +18,10 @@
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
<item>
<key> <unicode>required_not_found</unicode> </key>
<value> <string>Input is required but no input given.</string> </value>
</item>
</dictionary>
</value>
</item>
......@@ -46,10 +37,6 @@
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
......@@ -65,10 +52,6 @@
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
......@@ -142,15 +125,15 @@
<value>
<list>
<tuple>
<string>Discussion Thread</string>
<string>Discussion Thread</string>
<string>Messenger Thread</string>
<string>Messenger Thread</string>
</tuple>
</list>
</value>
</item>
<item>
<key> <string>selection_name</string> </key>
<value> <string>discussion_module_selection</string> </value>
<value> <string>messenger_thread_module_selection</string> </value>
</item>
<item>
<key> <string>target</string> </key>
......@@ -158,7 +141,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Discussion Threads</string> </value>
<value> <string>Messenger Threads</string> </value>
</item>
</dictionary>
</value>
......
"""
This script allows to create a new Messenger Post in context.
"""
from DateTime import DateTime
from Products.ERP5Type.Log import log
portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
messenger_thread = context
is_temp_object = messenger_thread.isTempObject()
if is_temp_object:
# this is a temporary object accessed by its reference
# we need to get real ZODB one
messenger_thread = messenger_thread.getOriginalDocument()
# inspired on PostModule_createHTMLPostForSupportRequest
# temporarily using post_module until data structure (and portal_type/module) for Post are defined
post = context.PostModule_createHTMLPostFromText(
follow_up=follow_up,
data=text_content,
source_reference=source_reference,
)
# XXX the UI of support request app should be responsible for generating a unique
# "message id" for each posted message.
if not post.getSourceReference():
post.setSourceReference(post.getId())
ingest_document_tag = 'ingest-%s' % post.getSourceReference()
after_ingest_document_tag = 'after-ingest-%s' % post.getSourceReference()
document = None
#TODO
#if file not in ("undefined", None): # XXX "undefined" ? should also be fixed in javascript side
#get attachment code from PostModule_createHTMLPostForSupportRequest
#else:
# when we don't upload a document, we can publish the post now.
post.publish()
follow_up_value = portal.restrictedTraverse(follow_up)
assert follow_up_value.getPortalType() == "Messenger Thread"
# TODO: CHECK IF THIS IS NEEDED
# to be able to display the just posted data in MessengerThread_getCommentPostListAsJson,
# we store it in a session variable.
successor_name = successor_link = None
if document is not None:
successor_link, successor_name = document.getRelativeUrl(), document.getFilename()
portal.portal_sessions[
'%s.latest_comment' % follow_up_value.getRelativeUrl()]['comment_post_list'] = dict(
user=post.Base_getOwnerTitle(),
date=post.getStartDate().ISO8601(),
text=post.asStrippedHTML(),
attachment_link=successor_link,
attachment_name=successor_name,
message_id=post.getSourceReference(),)
return
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>title, follow_up, text_content, form_id=\'view\', predecessor=None, source_reference=None, file=None, **kw</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>MessengerThread_createNewMessengerPost</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from Products.ERP5Type.Log import log
from DateTime import DateTime
portal = context.getPortalObject()
document_type_list = portal.getPortalDocumentTypeList()
comment_list = []
followup_thread = 'follow_up/' + context.getRelativeUrl()
catalog_kw = {'portal_type': '%Post',
'query': portal.portal_catalog.getCategoryParameterDict(
category_list=[followup_thread]),
'validation_state': "published"}
for post in portal.portal_catalog(**catalog_kw):
# hardcoded content until data structure (and portal_type/module) for Post are defined
comment_list.append((dict(
user="hardcoded user",#event.getSourceTitle(),
date=DateTime().ISO8601(),#"TODO: get date",#event.getStartDate().ISO8601(),
text=post.getData(),#event.asStrippedHTML(),
attachment_link=None,#attachment_link,
attachment_name=None,#attachment_name,
message_id="hardcoded message_id",#event.getSourceReference(),
)))
return comment_list
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>MessengerThread_getCommentPostList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from json import dumps
return dumps(context.MessengerThread_getCommentPostList ())
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>MessengerThread_getCommentPostListAsJson</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -78,6 +78,7 @@
<value>
<list>
<string>listbox</string>
<string>my_listbox</string>
</list>
</value>
</item>
......@@ -108,7 +109,6 @@
<string>my_title</string>
<string>my_short_title</string>
<string>my_reference</string>
<string>my_listbox</string>
</list>
</value>
</item>
......
......@@ -128,7 +128,7 @@
</item>
<item>
<key> <string>selection_name</string> </key>
<value> <string>discussion_post_selection</string> </value>
<value> <string>messenger_post_selection</string> </value>
</item>
<item>
<key> <string>sort</string> </key>
......
......@@ -159,7 +159,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: [(\'view\', "view"), (\'jio_key\', context.getRelativeUrl()), (\'portal_type\', context.getPortalType()), (\'maximize\', \'listbox\' not in field.id)]</string> </value>
<value> <string>python: [ ( \'query\', context.getPortalObject().portal_catalog.getSQLCatalog().buildQuery({"portal_type":[\'Messenger Post\'], "parent_uid":context.getUid()}).asSearchTextExpression(context.getPortalObject().portal_catalog.getSQLCatalog()) ), (\'view\', "view"), (\'jio_key\', context.getRelativeUrl()), (\'portal_type\', context.getPortalType()), (\'maximize\', \'listbox\' not in field.id)]</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -20,7 +20,7 @@
<li>By <strong>{{ user }}</strong> -
<time datetime="{{ date }}" title="{{ date_formatted }}">{{ date_relative }}</time>
<br/>
{{{ text }}}
{{{ value.text_content }}}
{{#if attachment_link }}
<br/>
<strong>Attachment: </strong>
......@@ -30,7 +30,7 @@
</li>
{{/each }}
{{else }}
<p><em>No comment yet.</em></p><hr id="post_item">
<p><em>No posts yet.</em></p><hr id="post_item">
{{/if }}
</script>
......
/*jslint nomen: true, indent: 2 */
/*global window, rJS, RSVP, document,moment, jIO, Handlebars*/
(function (window, rJS, RSVP, document, moment, jIO, Handlebars) {
/*global window, rJS, RSVP, document, moment, jIO, Handlebars, console*/
(function (window, rJS, RSVP, document, moment, jIO, Handlebars, console) {
"use strict";
var gadget_klass = rJS(window),
comment_list_template = Handlebars.compile(
......@@ -10,8 +10,7 @@
rJS(window)
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareMethod('render', function (options) {
var gadget = this;
......@@ -25,6 +24,7 @@
id: options.jio_key,
view: options.view,
editable: options.editable,
query: options.query,
erp5_form: options.erp5_form || {}
};
return gadget.changeState(state_dict);
......@@ -33,13 +33,17 @@
.onStateChange(function () {
var gadget = this;
return gadget.jio_getAttachment(
'post_module',
gadget.hateoas_url + gadget.options.jio_key + "/MessengerThread_getCommentPostListAsJson"
)
.push(function (post_list) {
console.log("gadget.state.query:");
console.log(gadget.state.query);
return gadget.jio_allDocs({
"query": gadget.state.query,
"select_list": ["text_content", "modification_date", "local_role"],
"sort_on": [["modification_date", "ascending"]]
})
.push(function (results) {
var post_list = results.data.rows;
function getPostWithLinkAndLocalDate(post) {
post.date = post.value.modification_date;
post.date_formatted = moment(post.date).format('LLLL');
post.date_relative = moment(post.date).fromNow();
if (post.attachment_link === null) {
......@@ -60,9 +64,12 @@
}
);
}
// build links with attachments and localized dates
var queue_list = [], i = 0;
for (i = 0; i < post_list.length; i += 1) {
post_list[i].user = "zope"; // problems getting Owner property
// TODO: attachments
post_list[i].attachment_link = null;
post_list[i].attachment_name = null;
queue_list.push(getPostWithLinkAndLocalDate(post_list[i]));
}
return RSVP.all(queue_list);
......@@ -70,10 +77,7 @@
.push(function (comment_list) {
var comments = gadget.element.querySelector("#post_list");
comments.innerHTML = comment_list_template({comments: comment_list});
})
;
});
})
.onLoop(function () {
......@@ -88,4 +92,4 @@
return this.submitPostComment();
})*/;
}(window, rJS, RSVP, document, moment, jIO, Handlebars));
\ No newline at end of file
}(window, rJS, RSVP, document, moment, jIO, Handlebars, console));
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment