2014-12-23 08:12:26 +08:00
|
|
|
class Admin::EmojisController < Admin::AdminController
|
|
|
|
|
|
|
|
def index
|
|
|
|
render_serialized(Emoji.custom, EmojiSerializer, root: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
file = params[:file] || params[:files].first
|
|
|
|
name = params[:name] || File.basename(file.original_filename, ".*")
|
|
|
|
|
|
|
|
# fix the name
|
|
|
|
name = name.gsub(/[^a-z0-9]+/i, '_')
|
|
|
|
.gsub(/_{2,}/, '_')
|
|
|
|
.downcase
|
|
|
|
|
2015-02-10 01:54:57 +08:00
|
|
|
if Emoji.exists?(name)
|
2014-12-23 08:12:26 +08:00
|
|
|
render json: failed_json.merge(message: I18n.t("emoji.errors.name_already_exists", name: name)), status: 422
|
|
|
|
else
|
|
|
|
if emoji = Emoji.create_for(file, name)
|
|
|
|
render_serialized(emoji, EmojiSerializer, root: false)
|
|
|
|
else
|
|
|
|
render json: failed_json.merge(message: I18n.t("emoji.errors.error_while_storing_emoji")), status: 422
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
name = params.require(:id)
|
2015-02-10 01:54:57 +08:00
|
|
|
Emoji[name].try(:remove)
|
2014-12-23 08:12:26 +08:00
|
|
|
render nothing: true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|