mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-11 03:42:16 +00:00
Merge pull request #1423 from haiwen/new
[dir view] redesigned 'new folder/file'
This commit is contained in:
commit
1273ffa83d
@ -1644,9 +1644,6 @@ button.sf-dropdown-toggle:focus {
|
|||||||
margin-bottom:.5em;
|
margin-bottom:.5em;
|
||||||
border-radius:2px;
|
border-radius:2px;
|
||||||
}
|
}
|
||||||
#dir-view .repo-op {
|
|
||||||
position: relative; /* for '#upload-menu' */
|
|
||||||
}
|
|
||||||
#right-panel .hd,
|
#right-panel .hd,
|
||||||
.tabnav,
|
.tabnav,
|
||||||
.wiki-top {
|
.wiki-top {
|
||||||
@ -2121,6 +2118,11 @@ button.sf-dropdown-toggle:focus {
|
|||||||
#dir-view .repo-op .op-btn {
|
#dir-view .repo-op .op-btn {
|
||||||
padding:5px 14px;
|
padding:5px 14px;
|
||||||
}
|
}
|
||||||
|
#new-file-menu {
|
||||||
|
margin-top:4px;
|
||||||
|
border-top:1px solid #ddd;
|
||||||
|
padding-top:4px;
|
||||||
|
}
|
||||||
.repo-file-list {
|
.repo-file-list {
|
||||||
margin:0;
|
margin:0;
|
||||||
}
|
}
|
||||||
|
BIN
media/office-template/empty.docx
Normal file
BIN
media/office-template/empty.docx
Normal file
Binary file not shown.
BIN
media/office-template/empty.pptx
Normal file
BIN
media/office-template/empty.pptx
Normal file
Binary file not shown.
BIN
media/office-template/empty.xlsx
Normal file
BIN
media/office-template/empty.xlsx
Normal file
Binary file not shown.
@ -2,6 +2,7 @@
|
|||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import posixpath
|
import posixpath
|
||||||
|
import requests
|
||||||
|
|
||||||
from rest_framework.authentication import SessionAuthentication
|
from rest_framework.authentication import SessionAuthentication
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
@ -15,11 +16,13 @@ from seahub.api2.throttling import UserRateThrottle
|
|||||||
from seahub.api2.authentication import TokenAuthentication
|
from seahub.api2.authentication import TokenAuthentication
|
||||||
from seahub.api2.utils import api_error
|
from seahub.api2.utils import api_error
|
||||||
|
|
||||||
from seahub.utils import check_filename_with_rename, is_pro_version
|
from seahub.utils import check_filename_with_rename, is_pro_version, \
|
||||||
|
gen_file_upload_url
|
||||||
from seahub.utils.timeutils import timestamp_to_isoformat_timestr
|
from seahub.utils.timeutils import timestamp_to_isoformat_timestr
|
||||||
from seahub.views import check_folder_permission, check_file_lock
|
from seahub.views import check_folder_permission, check_file_lock
|
||||||
|
|
||||||
from seahub.settings import MAX_UPLOAD_FILE_NAME_LEN, FILE_LOCK_EXPIRATION_DAYS
|
from seahub.settings import MAX_UPLOAD_FILE_NAME_LEN, \
|
||||||
|
FILE_LOCK_EXPIRATION_DAYS, OFFICE_TEMPLATE_ROOT
|
||||||
|
|
||||||
from seaserv import seafile_api
|
from seaserv import seafile_api
|
||||||
from pysearpc import SearpcError
|
from pysearpc import SearpcError
|
||||||
@ -147,7 +150,7 @@ class FileView(APIView):
|
|||||||
error_msg = 'Permission denied.'
|
error_msg = 'Permission denied.'
|
||||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||||
|
|
||||||
# create file
|
# create new empty file
|
||||||
new_file_name = os.path.basename(path)
|
new_file_name = os.path.basename(path)
|
||||||
new_file_name = check_filename_with_rename(repo_id, parent_dir, new_file_name)
|
new_file_name = check_filename_with_rename(repo_id, parent_dir, new_file_name)
|
||||||
|
|
||||||
@ -158,6 +161,32 @@ class FileView(APIView):
|
|||||||
error_msg = 'Internal Server Error'
|
error_msg = 'Internal Server Error'
|
||||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
|
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
|
||||||
|
|
||||||
|
# update office file by template
|
||||||
|
if new_file_name.endswith('.xlsx'):
|
||||||
|
empty_file_path = os.path.join(OFFICE_TEMPLATE_ROOT, 'empty.xlsx')
|
||||||
|
elif new_file_name.endswith('.pptx'):
|
||||||
|
empty_file_path = os.path.join(OFFICE_TEMPLATE_ROOT, 'empty.pptx')
|
||||||
|
elif new_file_name.endswith('.docx'):
|
||||||
|
empty_file_path = os.path.join(OFFICE_TEMPLATE_ROOT, 'empty.docx')
|
||||||
|
else:
|
||||||
|
empty_file_path = ''
|
||||||
|
|
||||||
|
if empty_file_path:
|
||||||
|
# get file server update url
|
||||||
|
update_token = seafile_api.get_fileserver_access_token(
|
||||||
|
repo_id, 'dummy', 'update', username)
|
||||||
|
update_url = gen_file_upload_url(update_token, 'update-api')
|
||||||
|
|
||||||
|
# update file
|
||||||
|
try:
|
||||||
|
requests.post(
|
||||||
|
update_url,
|
||||||
|
data={'filename': new_file_name, 'target_file': path},
|
||||||
|
files={'file': open(empty_file_path, 'rb')}
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(e)
|
||||||
|
|
||||||
new_file_path = posixpath.join(parent_dir, new_file_name)
|
new_file_path = posixpath.join(parent_dir, new_file_name)
|
||||||
file_info = self.get_file_info(username, repo_id, new_file_path)
|
file_info = self.get_file_info(username, repo_id, new_file_path)
|
||||||
return Response(file_info)
|
return Response(file_info)
|
||||||
|
@ -508,6 +508,9 @@ THUMBNAIL_SIZE_FOR_GRID = 192
|
|||||||
THUMBNAIL_IMAGE_SIZE_LIMIT = 20
|
THUMBNAIL_IMAGE_SIZE_LIMIT = 20
|
||||||
THUMBNAIL_IMAGE_ORIGINAL_SIZE_LIMIT = 256
|
THUMBNAIL_IMAGE_ORIGINAL_SIZE_LIMIT = 256
|
||||||
|
|
||||||
|
# template for create new office file
|
||||||
|
OFFICE_TEMPLATE_ROOT = os.path.join(MEDIA_ROOT, 'office-template')
|
||||||
|
|
||||||
#####################
|
#####################
|
||||||
# Global AddressBook #
|
# Global AddressBook #
|
||||||
#####################
|
#####################
|
||||||
|
@ -13,18 +13,9 @@
|
|||||||
|
|
||||||
<script type="text/template" id="add-new-file-form-template">
|
<script type="text/template" id="add-new-file-form-template">
|
||||||
<form id="add-new-file-form" action="" method="post" class="hide">{% csrf_token %}
|
<form id="add-new-file-form" action="" method="post" class="hide">{% csrf_token %}
|
||||||
<h3 id="dialogTitle">{% trans "New File" %}</h3>
|
<h3 id="dialogTitle"><%= title %></h3>
|
||||||
<div id="featured-filetype">
|
<label for="file-name">{% trans "Name" %}</label><br/>
|
||||||
<label>{% trans "Featured File Type" %}</label><br />
|
<input type="text" name="name" value="<%= initial_file_name %>" class="input" maxlength="{{max_file_name}}" id="file-name" /><br />
|
||||||
<button type="button" class="set-file-type" data-filetype="md" title="{% trans "Click to choose" %}">markdown</button> <span>{% trans "simple markup format." %}</span>
|
|
||||||
{% if LANGUAGE_CODE == 'zh-cn' %}
|
|
||||||
<a href="http://www.seafile.com/help/markdown/" target="_blank">{% trans 'Details' %}</a>
|
|
||||||
{% else %}
|
|
||||||
<a href="http://www.seafile.com/en/help/markdown/" target="_blank">{% trans 'Details' %}</a>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
<label for="file-name">{% trans "File Name" %}</label><br/>
|
|
||||||
<input type="text" name="name" value="" class="input" maxlength="{{max_file_name}}" id="file-name" /><br />
|
|
||||||
<p class="error hide"></p>
|
<p class="error hide"></p>
|
||||||
<button type="submit" class="submit">{% trans "Submit" %}</button>
|
<button type="submit" class="submit">{% trans "Submit" %}</button>
|
||||||
<button class="simplemodal-close">{% trans "Cancel" %}</button>
|
<button class="simplemodal-close">{% trans "Cancel" %}</button>
|
||||||
|
@ -145,8 +145,21 @@
|
|||||||
<% } else { %>
|
<% } else { %>
|
||||||
<button class="op-btn btn-disabled" disabled="disabled" title="{% trans "Out of quota" %}">{% trans "Upload" %}</button>
|
<button class="op-btn btn-disabled" disabled="disabled" title="{% trans "Out of quota" %}">{% trans "Upload" %}</button>
|
||||||
<% } %>
|
<% } %>
|
||||||
<button id="add-new-dir" class="op-btn">{% trans "New Folder" %}</button>
|
<div id="add-new" class="sf-dropdown sf-dropdown-inline">
|
||||||
<button id="add-new-file" class="op-btn">{% trans "New File" %}</button>
|
<button class="sf-dropdown-toggle op-btn">{% trans "New" %}</button>
|
||||||
|
<div class="sf-dropdown-menu hide">
|
||||||
|
<ul>
|
||||||
|
<li><a id="add-new-dir" class="op" href="#">{% trans "New Folder" %}</a></li>
|
||||||
|
<li><a id="add-new-file" class="op" href="#">{% trans "New File" %}</a></li>
|
||||||
|
</ul>
|
||||||
|
<ul id="new-file-menu">
|
||||||
|
<li><a id="add-new-md-file" class="op" href="#">{% trans "New Markdown File" %}</a></li>
|
||||||
|
<li><a id="add-new-excel-file" class="op" href="#">{% trans "New Excel File" %}</a></li>
|
||||||
|
<li><a id="add-new-ppt-file" class="op" href="#">{% trans "New PowerPoint File" %}</a></li>
|
||||||
|
<li><a id="add-new-word-file" class="op" href="#">{% trans "New Word File" %}</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
<% if (!encrypted && (can_generate_share_link || can_generate_upload_link || is_repo_owner)) { %>
|
<% if (!encrypted && (can_generate_share_link || can_generate_upload_link || is_repo_owner)) { %>
|
||||||
|
@ -441,6 +441,13 @@ define([
|
|||||||
can_generate_upload_link: app.pageOptions.can_generate_upload_link,
|
can_generate_upload_link: app.pageOptions.can_generate_upload_link,
|
||||||
enable_upload_folder: app.pageOptions.enable_upload_folder
|
enable_upload_folder: app.pageOptions.enable_upload_folder
|
||||||
})));
|
})));
|
||||||
|
|
||||||
|
if (dir.user_perm == 'rw') {
|
||||||
|
// add new folder/file
|
||||||
|
this.new_dropdown = new DropdownView({
|
||||||
|
el: this.$("#add-new")
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
renderDirentsHd: function() {
|
renderDirentsHd: function() {
|
||||||
@ -461,7 +468,11 @@ define([
|
|||||||
// Directory Operations
|
// Directory Operations
|
||||||
events: {
|
events: {
|
||||||
'click #add-new-dir': 'newDir',
|
'click #add-new-dir': 'newDir',
|
||||||
'click #add-new-file': 'newFile',
|
'click #add-new-file': 'newCommonFile',
|
||||||
|
'click #add-new-md-file': 'newMdFile',
|
||||||
|
'click #add-new-excel-file': 'newExcelFile',
|
||||||
|
'click #add-new-ppt-file': 'newPPTFile',
|
||||||
|
'click #add-new-word-file': 'newWordFile',
|
||||||
'click #share-cur-dir': 'share',
|
'click #share-cur-dir': 'share',
|
||||||
'click #js-switch-grid-view': 'switchToGridView',
|
'click #js-switch-grid-view': 'switchToGridView',
|
||||||
'click #js-switch-list-view': 'switchToListView',
|
'click #js-switch-list-view': 'switchToListView',
|
||||||
@ -535,31 +546,29 @@ define([
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
newFile: function() {
|
newFile: function(options) {
|
||||||
var form = $(this.newFileTemplate()),
|
var $form = $(this.newFileTemplate(options)),
|
||||||
form_id = form.attr('id'),
|
form_id = $form.attr('id'),
|
||||||
file_name = form.find('input[name="name"]'),
|
$input = $('input[name="name"]', $form),
|
||||||
dir = this.dir,
|
dir = this.dir,
|
||||||
dirView = this;
|
dirView = this;
|
||||||
|
|
||||||
form.modal({
|
$form.modal({
|
||||||
appendTo: '#main',
|
appendTo: '#main',
|
||||||
focus: false,
|
focus: false,
|
||||||
containerCss: {'padding':'20px 25px'}
|
containerCss: {'padding':'20px 25px'}
|
||||||
});
|
});
|
||||||
file_name.focus();
|
|
||||||
$('#simplemodal-container').css({'height':'auto'});
|
$('#simplemodal-container').css({'height':'auto'});
|
||||||
|
|
||||||
$('.set-file-type', form).click(function() {
|
Common.setCaretPos($input[0], 0);
|
||||||
file_name.val('.' + $(this).data('filetype'));
|
$input.focus();
|
||||||
Common.setCaretPos(file_name[0], 0);
|
|
||||||
file_name.focus();
|
|
||||||
});
|
|
||||||
|
|
||||||
form.submit(function() {
|
$form.submit(function() {
|
||||||
var dirent_name = $.trim(file_name.val());
|
var dirent_name = $.trim($input.val());
|
||||||
|
|
||||||
if (!dirent_name) {
|
if (!dirent_name) {
|
||||||
Common.showFormError(form_id, gettext("It is required."));
|
Common.showFormError(form_id, gettext("It is required."));
|
||||||
@ -579,10 +588,10 @@ define([
|
|||||||
$.modal.close();
|
$.modal.close();
|
||||||
var new_dirent = dir.add({
|
var new_dirent = dir.add({
|
||||||
'is_file': true,
|
'is_file': true,
|
||||||
'is_img': Common.imageCheck(data['obj_name']),
|
'is_img': Common.imageCheck(data.obj_name),
|
||||||
'obj_name': data['obj_name'],
|
'obj_name': data.obj_name,
|
||||||
'file_size': Common.fileSizeFormat(0),
|
'file_size': Common.fileSizeFormat(data.size),
|
||||||
'obj_id': '0000000000000000000000000000000000000000',
|
'obj_id': data.obj_id,
|
||||||
'file_icon': 'file.png',
|
'file_icon': 'file.png',
|
||||||
'starred': false,
|
'starred': false,
|
||||||
'perm': 'rw',
|
'perm': 'rw',
|
||||||
@ -593,7 +602,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
Common.ajaxPost({
|
Common.ajaxPost({
|
||||||
'form': form,
|
'form': $form,
|
||||||
'post_url': post_url,
|
'post_url': post_url,
|
||||||
'post_data': post_data,
|
'post_data': post_data,
|
||||||
'after_op_success': after_op_success,
|
'after_op_success': after_op_success,
|
||||||
@ -604,6 +613,46 @@ define([
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
newCommonFile: function() {
|
||||||
|
this.newFile({
|
||||||
|
title: gettext('New File'),
|
||||||
|
initial_file_name: ''
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
newMdFile: function() {
|
||||||
|
this.newFile({
|
||||||
|
title: gettext('New Markdown File'),
|
||||||
|
initial_file_name: '.md'
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
newExcelFile: function() {
|
||||||
|
this.newFile({
|
||||||
|
title: gettext('New Excel File'),
|
||||||
|
initial_file_name: '.xlsx'
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
newPPTFile: function() {
|
||||||
|
this.newFile({
|
||||||
|
title: gettext('New PowerPoint File'),
|
||||||
|
initial_file_name: '.pptx'
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
newWordFile: function() {
|
||||||
|
this.newFile({
|
||||||
|
title: gettext('New Word File'),
|
||||||
|
initial_file_name: '.docx'
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
addNewFile: function(new_dirent) {
|
addNewFile: function(new_dirent) {
|
||||||
var dirView = this,
|
var dirView = this,
|
||||||
dir = this.dir;
|
dir = this.dir;
|
||||||
|
Loading…
Reference in New Issue
Block a user