module Admin::CustomGalleriesHelper
  def back_end_breadcrumb
    if params[:controller] == "admin/custom_galleries"
      res = ''
      divider = "<span class='divider'>/</span>"
      res << "<li><a href='#{admin_dashboards_path}'>#{t(:dashboard_)}</a>#{divider}</li>"
      if params[:custom_module]
        trans_name = I18n.t("module_name.#{params[:custom_module]}")
        if trans_name.include?("translation missing")
          trans_name = params[:custom_module]
        end
        res << "<li><a href='/admin/#{params[:custom_module].pluralize}'>#{trans_name}</a>#{divider}</li>"
      end
      if params[:action] != "index"
        if params[:custom_module]
          extra_url = "/#{params[:custom_module]}#{params[:bind_uid].present? ? ('-'+params[:bind_uid]) : ''}"
        end
        res << "<li><a href='/#{params[:controller]}#{extra_url}'>#{t('module_name.'+@module_app.key)}</a>#{divider}</li>"
        res << "<li class='active'>#{t(params[:action], scope: 'restful_actions')}</li>"
      else
        res << "<li>#{t('module_name.'+@module_app.key)}</li>"
      end
      res.html_safe
    else
      super
    end
  end
  def import_this_image(row,custom_album)
    value = {}
    image = CustomAlbumImage.new
    image.custom_album = custom_album
    row.cells.each_with_index do |cell,index|
      val = cell.value rescue nil
      next if val.blank?
      case index
      when 0
        image.remote_file_url = val
      when 1
        value["zh_tw"] = val
        value["en"] = (row.cells[index + 1].value rescue "")
        image.description_translations = value
      end
    end
    image.save
  end
end
