# Copyright (C) 2009 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class DoclistController < ApplicationController
layout 'standard'
before_filter :setup_client, :set_user_email
def all
url = params[:url] ? params[:url] + "/-/#{MINE_LABEL}" :
DOCLIST_FEED + "/-/#{MINE_LABEL}/#{DOCUMENT_DOC_TYPE}"
url += '?showfolders=true'
begin
feed = @client.get(url).to_xml
@documents = create_docs(feed)
@doc_type = DOCUMENT_DOC_TYPE
rescue GData::Client::AuthorizationError
logout
end
if !request.xhr?
render :action => 'documents'
else
render :partial => 'documents_list'
end
end
def documents
@doc_type = DOCUMENT_DOC_TYPE
get_documents_for(:category => [@doc_type, MINE_LABEL])
end
def spreadsheets
@doc_type = SPREADSHEET_DOC_TYPE
get_documents_for(:category => [@doc_type, MINE_LABEL])
end
def presentations
@doc_type = PRESO_DOC_TYPE
get_documents_for(:category => [@doc_type, MINE_LABEL])
end
def pdfs
@doc_type = PDF_DOC_TYPE
get_documents_for(:category => [@doc_type, MINE_LABEL])
end
def folders
@doc_type = FOLDER_DOC_TYPE
get_documents_for(:category => [@doc_type, MINE_LABEL],
:params=>'showfolders=true')
end
def starred
@doc_type = DOCUMENT_DOC_TYPE
get_documents_for(:category => [STARRED_LABEL, MINE_LABEL],
:params=>'showfolders=true')
end
def trashed
@doc_type = DOCUMENT_DOC_TYPE
get_documents_for(:category => [TRASHED_LABEL, MINE_LABEL],
:params=>'showfolders=true')
end
def show
# expandAcl projection will inline the ACLs in the resulting feed
url = params[:url].sub(/\/full/, '/expandAcl')
entry = @client.get(url).to_xml
@document = create_doc(entry)
if @document.type == DOCUMENT_DOC_TYPE or @document.type == PRESO_DOC_TYPE
export_url = @document.links['export'] + '&exportFormat=png'
# Src value for an image containing a data URI
@preview_img = Base64.encode64(download(export_url))
end
render :partial => 'show'
end
def download(export_url=nil)
export_url ||= params[:export_url]
resp = @client.get(export_url)
# Set our response headers based on those returned with the file.
headers['content-type'] = resp.headers['content-type']
headers['content-disposition'] = resp.headers['content-disposition']
if params[:export_url]
render :text => resp.body
else
return resp.body
end
end
def set_acls
return unless request.xhr?
@html, @errors = [], []
@role = params[:role] || 'writer'
if !params[:emails].nil?
for email in params[:emails]
entry = <<-EOF