lib/caterpillar/helpers/liferay.rb in caterpillar-0.9.8 vs lib/caterpillar/helpers/liferay.rb in caterpillar-0.9.15
- old
+ new
@@ -1,86 +1,67 @@
+require 'rubygems'
+require 'action_controller'
+
module Caterpillar
module Helpers
+ # This module contains Rails helpers that provide methods to deal with various aspects
+ # of portlet functionality in Liferay.
+ #
+ # Currently this consists of things that were constructed whenever needed during development,
+ # and concidered general enough to be included here.
+ #
+ # link_to_liferay is deprecated, and is clearly a wrong way to solve the problem in question.
+ # A better way has been constructed, but it is not perfect due to its dependency on a specific portlet.
module Liferay
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::TagHelper
- # Formulates a link to Liferay.
+ # Link that the rails-portlet will leave unparsed.
+ def link_to_exit_portlet(name, options = {}, html_options = {})
+ link_to(name, url_to_exit_portlet(options), html_options)
+ end
+
+ # Formulates a link to Liferay. DEPRECATED.
+ #
# Parameters:
# - obj is an instance of a model from the lportal library.
# - options
def link_to_liferay(obj,options={})
- options.update(:use_large_igpreview => false) unless options[:use_large_igpreview]
# Rails-portlet cannot pass the actual redirect parameter.
# Workaround with JavaScript.
redirect = 'javascript: history.go(-1)'
title = 'n/a' # link title
begin
- STDERR.puts 'This method is DEPRECATED - use obj.path instead'
logger.debug "Formulating Liferay link for #{obj}"
case obj.liferay_class
### group
when 'com.liferay.portal.model.Group'
-# title = (obj.name.empty? ? obj.owner.fullname : obj.name)
-# urls = LiferayUrl.new(obj,nil,nil).static_url
-# logger.debug urls
-# if options[:private]
-# label = _('yksityiset sivut')
-# urls[:private] ?
-# link_to_exit_portlet( label, urls[:private] ) :
-# link_to_function(
-# label, "alert('%s')" % _('Yhteisöllä ei ole yksityisiä sivuja'))
-# else
-# label = _('julkiset sivut')
-# urls[:public] ?
-# link_to_exit_portlet( label, urls[:public] ) :
-# link_to_function(
-# label, "alert('%s')" % _('Yhteisöllä ei ole julkisia sivuja'))
-# end
+ STDERR.puts 'Called DEPRECATED method - use %s.path instead' % obj
-# siirretty malliin
-# when 'com.liferay.portal.model.Layout'
-# url = LiferayUrl.new(obj).static_url
-# return url_to_exit_portlet(url)
+ when 'com.liferay.portal.model.Layout'
+ STDERR.puts 'Called DEPRECATED method - use %s.path instead' % obj
### user
when 'com.liferay.portal.model.User'
-# urls = LiferayUrl.new(obj,nil,nil).static_url
-# #logger.debug urls
-# if options[:private]
-# label = options[:label]
-# label ||= _('yksityiset sivut')
-# urls[:private] ?
-# link_to_exit_portlet( label, urls[:private] ) :
-# link_to_function(
-# label, "alert('%s')" % _('Tunnuksella ei ole yksityisiä sivuja'))
-# else
-# label = options[:label] || _('julkiset sivut')
-# urls[:public] ?
-# link_to_exit_portlet( label, urls[:public] ) :
-# link_to_function(
-# label, "alert('%s')" % _('Tunnuksella ei ole julkisia sivuja'))
-# end
+ STDERR.puts 'Called DEPRECATED method - use %s.path instead' % obj
### blog
when 'com.liferay.portlet.blogs.model.BlogsEntry'
-# title = _('Linkki blogimerkintään "%s"') % obj.title
-# url = LiferayUrl.new(obj,@user,redirect).instance_url
-# link_to_exit_portlet( title, url )
+ STDERR.puts 'FIXME: %s.path' % obj
-
### document library file
#
# tämä toimii hiukan eri logiikalla kuin toiset, koska
# sama malli joutuu mallintamaan myös tyyppinsä tiedostopäätteestä
when 'com.liferay.portlet.documentlibrary.model.DLFileEntry'
+ STDERR.puts 'Called DEPRECATED method - use %s.path instead' % obj
redirect_link=request.env["PATH_INFO"] # ei toimi portletissa
label = 'Tiedostotyyppiä %s ei vielä tueta' % obj.type[:name]
#_('Lataa tiedosto "%s"') % obj.asset.title
case obj.type[:uuid]
@@ -103,11 +84,13 @@
end
### galleriakuva
when 'com.liferay.portlet.imagegallery.model.IGImage'
+ STDERR.puts 'FIXME: %s.path' % obj
base_url = "#{$LIFERAY_SERVER}/image/image_gallery"
+ options.update(:use_large_igpreview => false) unless options[:use_large_igpreview]
img_id = (options[:use_large_igpreview] == true ? obj.large.id : obj.small.id)
img = link_to_exit_portlet(
image_tag( "#{base_url}?img_id=#{img_id}", :alt => obj.description, :class => 'asset_image' ),
"#{base_url}?img_id=#{obj.large.id}"
@@ -115,68 +98,61 @@
logger.debug img
return img
when 'com.liferay.portlet.journal.model.JournalArticle'
+ STDERR.puts 'FIXME: %s.path' % obj
url = LiferayUrl.new(obj,@user,redirect).instance_url
link_to_exit_portlet( _('Lue koko artikkeli "%s"') % obj.asset.title, url )
when 'com.liferay.portlet.messageboards.model.MBCategory'
-# url = LiferayUrl.new(obj,@user,redirect).static_url
-# link_to_exit_portlet( obj.name, url )
+ STDERR.puts 'Called DEPRECATED method - use %s.path instead' % obj
when 'com.liferay.portlet.messageboards.model.MBMessage'
+ STDERR.puts 'FIXME: %s.path' % obj
url = LiferayUrl.new(obj,@user,redirect).instance_url
link_to_exit_portlet( _('Lue viesti "%s"') % obj.asset.title, url )
# when 'com.liferay.portlet.messageboards.model.MBThread'
- when 'com.liferay.portlet.wiki.model.WikiNode'
- logger.debug "WikiNode"
- # url = LiferayUrl.new(obj,@user,redirect).instance_url
- # link_to_exit_portlet( _('Lue sivu "%s"') % obj.asset.title, url )
-
when 'com.liferay.portlet.wiki.model.WikiPage'
- logger.debug "WikiPage"
+ STDERR.puts 'FIXME: %s.path' % obj
url = LiferayUrl.new(obj,@user,redirect).instance_url
link_to_exit_portlet( _('Lue sivu "%s"') % obj.asset.title, url )
else
- logger.debug obj.liferay_class
- raise _('Tämän tyyppistä linkkiä ei vielä hallita')
+ STDERR.puts 'Called DEPRECATED method, but no method can handle %s' % obj
+ raise _('This type of link cannot be handled.')
end
rescue Exception => err
logger.error '*** ERROR ***: %s' % err.message
- link_to_function( _('Kohteeseen ei voi linkittää.'), "alert('#{err.message}')" )
+ link_to_function( _('Cannot link to resource.'), "alert('#{err.message}')" )
end
end
+ # Appends parameters "exit_portlet=true" into the url.
+ # Url might be either Hash or String.
def url_to_exit_portlet(url)
- directive = { :exit_portlet => 'true' }
+ parameters = { :exit_portlet => 'true' }
+ # append parameters to the url
if url.is_a? Hash
- url.update directive
+ url.update parameters
elsif url.is_a? String
if url[/\?[\w]*\=/] # url has parameters
delimiter = '&'
else # no parameters
delimiter = '?'
end
- url += "#{delimiter}#{directive.keys.first}=#{directive.values.first}"
+ url += "#{delimiter}#{parameters.keys.first}=#{parameters.values.first}"
end
return url
- end
-
-
- # formulates a link that the rails286-portlet will leave unparsed.
- def link_to_exit_portlet(name, options = {}, html_options = {})
- link_to(name, url_to_exit_portlet(options), html_options)
end
end
end
end
\ No newline at end of file