Skip to content

Instantly share code, notes, and snippets.

@ryanschuhler
Last active February 24, 2016 21:25
Show Gist options
  • Save ryanschuhler/f8c1ccf83821855d6d6a to your computer and use it in GitHub Desktop.
Save ryanschuhler/f8c1ccf83821855d6d6a to your computer and use it in GitHub Desktop.
<#if request.lifecycle == "RENDER_PHASE">
<#assign journal_article_local_service = serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService") />
<#assign journal_content_util = staticUtil["com.liferay.portlet.journalcontent.util.JournalContentUtil"] />
<#assign layout_service = serviceLocator.findService("com.liferay.portal.service.LayoutLocalService") />
<#assign theme_display = request["theme-display"] />
<#assign plid = theme_display["plid"] />
<#assign layout = layout_service.getLayout(plid?number) />
<div class="lego-article ${article_class.data}" id="article-${.vars['reserved-article-id'].data}">
<#list section.siblings as cur_section>
<section class="row-fluid lego-section section-${cur_section_index + 1} ${cur_section.section_class.data}" ${cur_section.data}>
<#list cur_section.block.siblings as cur_block>
<div class="block-${cur_block_index + 1} content-column lego-block span${cur_block.width.data} ${cur_block.block_class.data}" ${cur_block.data}>
<#list cur_block.element.siblings as cur_element>
<#assign cur_element_tag = cur_element.tag.data>
<#if !cur_element_tag?has_content>
<#assign cur_element_tag = "div">
</#if>
<${cur_element_tag}
class="live-edit lego-element ${cur_element.element_class.data}"
data-article-id='${.vars["reserved-article-id"].data}'
data-field-name="${cur_element.content.name}"
data-level-path="${cur_section_index},${cur_block_index},${cur_element_index},0"
data-namespace='${request["portlet-namespace"]}'
data-resource-url='${request["resource-url"]}'
${cur_element.data}
>
${cur_element.content.data}
</${cur_element_tag}>
</#list>
<#if cur_block.article_id?? && cur_block.article_id.data?has_content>
<#list cur_block.article_id.siblings as article_id>
<#if article_id.data?has_content && journal_article_local_service.hasArticle(groupId, article_id.data)>
${journal_content_util.getContent(groupId, article_id.data, "", locale, xmlRequest)!}
<#if layoutPermission.contains(permissionChecker, layout, "UPDATE")>
<#assign service_context = staticUtil["com.liferay.portal.service.ServiceContextThreadLocal"].getServiceContext() />
<#assign http_servlet_request = service_context.getRequest() />
<#assign current_url = request.attributes.CURRENT_COMPLETE_URL! />
<#assign edit_url = portletURLFactory.create(http_servlet_request, "15", theme_display["plid"]?number, "0") />
<#assign VOID = edit_url.setParameter("p_p_state", "maximized") />
<#assign VOID = edit_url.setParameter("p_p_lifecycle", "0") />
<#assign VOID = edit_url.setParameter("groupId", "${groupId}") />
<#assign VOID = edit_url.setParameter("struts_action", "/journal/edit_article") />
<#assign VOID = edit_url.setParameter("redirect", "${current_url}") />
<#assign VOID = edit_url.setParameter("articleId", "${article_id.data}") />
<span class="lfr-icon-action lfr-icon-action-edit lfr-meta-actions pull-right">
<a href="${edit_url}" class="taglib-icon">
<img src="/osb-community-theme/images/spacer.png" alt="Edit" style="background-image: url('/osb-community-theme/sprite/images/common/_sprite.png'); background-position: 50% -608px; background-repeat: no-repeat; height: 16px; width: 16px;">
<span class="taglib-text ">Edit</span>
</a>
</span>
</#if>
</#if>
</#list>
</#if>
</div>
</#list>
</section>
</#list>
</div>
<#if css.data?has_content>
<style type="text/css">
${css.data}
</style>
</#if>
<#if javascript?? && javascript.data?has_content>
<script type="text/javascript">
${javascript.data}
</script>
</#if>
<#assign layout_service = serviceLocator.findService("com.liferay.portal.service.LayoutLocalService") />
<#assign theme_display = request["theme-display"] />
<#assign plid = theme_display["plid"] />
<#assign layout = layout_service.getLayout(plid?number) />
<#if layoutPermission.contains(permissionChecker, layout, "UPDATE")>
<style>
.controls-visible .live-edit {
-moz-user-modify: read-write;
-webkit-user-modify: read-write;
}
</style>
<script text="text/javascript">
AUI().ready(
'aui-io-request',
function(A) {
var body = A.getBody();
var saveInfo = function(articleId, fieldName, levelPath, namespace, resourceURL, value) {
var data = {};
data[namespace + 'articleId'] = articleId;
data[namespace + 'fieldName'] = fieldName;
data[namespace + 'languageId'] = themeDisplay.getLanguageId();
data[namespace + 'levelPath'] = levelPath;
data[namespace + 'value'] = value;
A.io.request(
resourceURL,
{
data: data
}
);
};
A.one('#article-${.vars['reserved-article-id'].data}').delegate(
'click',
function(event) {
if (!body.hasClass('controls-visible')) {
return;
}
event.preventDefault();
var node = event.currentTarget;
var initialContent = node.getContent();
node.on(
'blur',
function(event) {
node.detach('blur');
var content = node.getContent();
if ((content == '') || (initialContent == content)) {
return;
}
var articleId = node.attr('data-article-id');
var fieldName = node.attr('data-field-name');
var levelPath = node.attr('data-level-path');
var namespace = node.attr('data-namespace');
var resourceURL = node.attr('data-resource-url');
saveInfo(articleId, fieldName, levelPath, namespace, resourceURL, content);
}
);
},
'.live-edit'
);
}
);
</script>
</#if>
<#elseif request.lifecycle == "RESOURCE_PHASE">
<#assign layout_service = serviceLocator.findService("com.liferay.portal.service.LayoutLocalService") />
<#assign theme_display = request["theme-display"] />
<#assign plid = theme_display["plid"] />
<#assign layout = layout_service.getLayout(plid?number) />
<#if layoutPermission.contains(permissionChecker, layout, "UPDATE")>
<#assign journal_article_service = serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleService") />
<#assign service_context = objectUtil("com.liferay.portal.service.ServiceContextThreadLocal").getServiceContext() />
<#assign http_servlet_request = service_context.getRequest() />
<#assign article_id = paramUtil.getString(http_servlet_request, "articleId") />
<#assign field_name = paramUtil.getString(http_servlet_request, "fieldName") />
<#assign language_id = paramUtil.getString(http_servlet_request, "languageId") />
<#assign level_path = paramUtil.getString(http_servlet_request, "levelPath") />
<#assign value = paramUtil.getString(http_servlet_request, "value") />
<#assign level_path = stringUtil.split(level_path) />
<#assign article = journal_article_service.getArticle(groupId, article_id) />
<#assign document = saxReaderUtil.read(article.getContent()) />
<#assign root_element = document.getRootElement() />
<#assign dynamic_elements = root_element.elements("dynamic-element") />
<#list level_path as level>
<#if level_has_next>
<#assign current_element = dynamic_elements[getterUtil.getInteger(level)] />
<#assign dynamic_elements = current_element.elements("dynamic-element") />
</#if>
</#list>
<#assign content = "" />
<#assign element_count = 0 />
<#list dynamic_elements as dynamic_element>
<#if validator.equals(dynamic_element.attributeValue("name"), field_name)>
<#if element_count == level_path[level_path?size - 1]?number>
<#assign content = dynamic_element />
</#if>
<#assign element_count = element_count + 1 />
</#if>
</#list>
<#assign dynamic_content = content.elements("dynamic-content") />
<#assign found_language_id = false />
<#list dynamic_content as dynamic_content_element>
<#assign content_language_id = dynamic_content_element.attributeValue("language-id") />
<#if validator.equals(language_id, content_language_id)>
<#assign void = dynamic_content_element.clearContent() />
<#assign void = dynamic_content_element.addCDATA(value) />
<#assign found_language_id = true />
</#if>
</#list>
<#if !found_language_id>
<#assign dynamic_content_element = content.addElement("dynamic-content") />
<#assign void = dynamic_content_element.addAttribute("language-id", language_id) />
<#assign void = dynamic_content_element.addCDATA(value) />
<#assign available_locales = root_element.attributeValue("available-locales") />
<#assign available_locales = stringUtil.add(available_locales, language_id) />
<#assign void = root_element.addAttribute("available-locales", available_locales) />
</#if>
<#assign void = journal_article_service.updateContent(article.getGroupId(), article.getArticleId(), article.getVersion(), document.formattedString(" ")) />
</#if>
</#if>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment