2014-04-12 01:35:42 +00:00
|
|
|
module Extra
|
2014-04-13 11:16:51 +00:00
|
|
|
extend ActiveSupport::Concern
|
2014-04-12 01:35:42 +00:00
|
|
|
|
2014-04-13 11:16:51 +00:00
|
|
|
CODING_HTML = 0
|
|
|
|
CODING_BBCODE = 1
|
|
|
|
CODING_MARKDOWN = 2
|
2014-04-12 01:35:42 +00:00
|
|
|
|
|
|
|
included do
|
2014-04-13 11:16:51 +00:00
|
|
|
def codings
|
|
|
|
{
|
|
|
|
CODING_HTML => "Plain HTML",
|
|
|
|
CODING_BBCODE => "BBCode",
|
|
|
|
CODING_MARKDOWN => "Markdown"
|
|
|
|
}
|
|
|
|
end
|
2014-04-12 01:35:42 +00:00
|
|
|
|
2014-04-13 11:16:51 +00:00
|
|
|
def check_params(params, filter)
|
|
|
|
(params.instance_of?(Array) ? params : params.keys).each do |key|
|
|
|
|
return false unless filter.include? key.to_sym
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
2014-04-12 01:35:42 +00:00
|
|
|
|
2014-04-13 11:16:51 +00:00
|
|
|
def error_messages
|
|
|
|
self.errors.full_messages.uniq
|
|
|
|
end
|
2014-04-12 01:35:42 +00:00
|
|
|
|
2014-04-13 11:16:51 +00:00
|
|
|
def bbcode_to_html(text)
|
2017-06-12 18:30:10 +00:00
|
|
|
Sanitize.clean(text.to_s).bbcode_to_html.gsub(/\n|\r\n/, "<br>").html_safe
|
2014-04-13 11:16:51 +00:00
|
|
|
end
|
2014-04-12 01:35:42 +00:00
|
|
|
|
2020-03-29 23:16:34 +00:00
|
|
|
def move_up(objects, column = "position")
|
2014-04-13 11:16:51 +00:00
|
|
|
n = 0
|
2020-03-29 23:16:34 +00:00
|
|
|
# the objects need to be assigned before loop or the order is not right
|
|
|
|
(objects = objects.order(column)).each_with_index do |item, i|
|
2014-04-13 11:16:51 +00:00
|
|
|
if item.id == id and n > 0
|
2015-04-09 13:49:35 +00:00
|
|
|
old_position = item[column]
|
2020-03-29 23:16:34 +00:00
|
|
|
item.update_attribute(column, objects[i-1][column])
|
|
|
|
objects[i-1].update_attribute(column, old_position)
|
2014-04-13 11:16:51 +00:00
|
|
|
end
|
|
|
|
n = n + 1
|
|
|
|
end
|
|
|
|
end
|
2014-04-12 01:35:42 +00:00
|
|
|
|
2020-03-29 23:16:34 +00:00
|
|
|
def move_down(objects, column = "position")
|
2014-04-13 11:16:51 +00:00
|
|
|
n = 0
|
2020-03-29 23:16:34 +00:00
|
|
|
(objects = objects.order(column)).each_with_index do |item, i|
|
2014-04-13 11:16:51 +00:00
|
|
|
if item.id == id and n < (objects.length-1)
|
2015-04-09 13:49:35 +00:00
|
|
|
old_position = item[column]
|
2020-03-29 23:16:34 +00:00
|
|
|
item.update_attribute(column, objects[n+1][column])
|
|
|
|
objects[n+1].update_attribute(column, old_position)
|
2014-04-13 11:16:51 +00:00
|
|
|
end
|
|
|
|
n = n + 1
|
|
|
|
end
|
|
|
|
end
|
2014-04-12 01:35:42 +00:00
|
|
|
|
2014-04-13 11:16:51 +00:00
|
|
|
def can_show? cuser
|
|
|
|
true
|
|
|
|
end
|
2014-04-12 01:35:42 +00:00
|
|
|
|
2014-04-13 11:16:51 +00:00
|
|
|
def can_create? cuser
|
|
|
|
true
|
|
|
|
end
|
2014-04-12 01:35:42 +00:00
|
|
|
|
2014-04-13 11:16:51 +00:00
|
|
|
def can_update? cuser
|
|
|
|
true
|
|
|
|
end
|
2014-04-12 01:35:42 +00:00
|
|
|
|
2014-04-13 11:16:51 +00:00
|
|
|
def can_destroy? cuser
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
2014-04-12 01:35:42 +00:00
|
|
|
end
|