1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-13 05:39:59 +00:00

[lib] modified new dir/file

This commit is contained in:
llj
2015-02-07 16:50:33 +08:00
committed by Daniel Pan
parent 1e3a18f6c9
commit 13d5730684
6 changed files with 148 additions and 82 deletions

View File

@@ -123,7 +123,8 @@ define([
user_perm: user_perm, user_perm: user_perm,
encrypted: dir.encrypted, encrypted: dir.encrypted,
path: dir.path, path: dir.path,
repo_id: dir.repo_id repo_id: dir.repo_id,
enable_upload_folder: app.globalState.enable_upload_folder
}))); })));
}, },
@@ -152,16 +153,16 @@ define([
$('#simplemodal-container').css({'height':'auto'}); $('#simplemodal-container').css({'height':'auto'});
form.submit(function() { form.submit(function() {
var dirent_name = $.trim($('input[name="name"]', form).val()), var dirent_name = $.trim($('input[name="name"]', form).val());
post_data = {'dirent_name': dirent_name},
post_url = Common.getUrl({name: "new_dir", repo_id: dir.repo_id})
+ '?parent_dir=' + encodeURIComponent(dir.path);
if (!dirent_name) { if (!dirent_name) {
Common.showFormError(form_id, gettext("It is required.")); Common.showFormError(form_id, gettext("It is required."));
return false; return false;
}; };
var post_data = {'dirent_name': dirent_name},
post_url = Common.getUrl({name: "new_dir", repo_id: dir.repo_id})
+ '?parent_dir=' + encodeURIComponent(dir.path);
var after_op_success = function(data) { var after_op_success = function(data) {
$.modal.close(); $.modal.close();
@@ -174,7 +175,7 @@ define([
}, {silent:true}); }, {silent:true});
var view = new DirentView({model: new_dirent, dirView: dirView}); var view = new DirentView({model: new_dirent, dirView: dirView});
$('tr:first', dirView.$dirent_list).before(view.render().el); // put the new dir as the first one dirView.$dirent_list.prepend(view.render().el); // put the new dir as the first one
}; };
Common.ajaxPost({ Common.ajaxPost({
@@ -196,29 +197,64 @@ define([
dir = this.dir, dir = this.dir,
dirView = this; dirView = this;
form.modal({appendTo:'#main'}); form.modal({
appendTo: '#main',
focus: false,
containerCss: {'padding':'20px 25px'}
});
$('#simplemodal-container').css({'height':'auto'}); $('#simplemodal-container').css({'height':'auto'});
form.find('.set-file-type').on('click', function() { $('.set-file-type', form).click(function() {
file_name.val('.' + $(this).data('filetype')); file_name.val('.' + $(this).data('filetype'));
Common.setCaretPos(file_name[0], 0); Common.setCaretPos(file_name[0], 0);
file_name.focus(); file_name.focus();
}); });
form.submit(function() { form.submit(function() {
var dirent_name = $.trim(file_name.val()), var dirent_name = $.trim(file_name.val());
post_data = {'dirent_name': dirent_name},
post_url = Common.getUrl({name: "new_file", repo_id: dir.repo_id})
+ '?parent_dir=' + encodeURIComponent(dir.path);
if (!dirent_name) { if (!dirent_name) {
Common.showFormError(form_id, gettext("It is required.")); Common.showFormError(form_id, gettext("It is required."));
return false; return false;
}; };
// if it has an extension, make sure it has a name
if (dirent_name.lastIndexOf('.') != -1 && dirent_name.substr(0, dirent_name.lastIndexOf('.')).length == 0) {
Common.showFormError(form_id, gettext("Only an extension there, please input a name."));
return false;
}
var post_data = {'dirent_name': dirent_name},
post_url = Common.getUrl({name: "new_file", repo_id: dir.repo_id})
+ '?parent_dir=' + encodeURIComponent(dir.path);
var after_op_success = function(data) { var after_op_success = function(data) {
location.href = Common.getUrl({name: "repo_new_file", repo_id: dir.repo_id}) $.modal.close();
+ '?p=' + encodeURIComponent(dir.path) + encodeURIComponent(data['name']); var new_dirent = dir.add({
'is_file': true,
'obj_name': data['name'],
'file_size': Common.fileSizeFormat(0),
'obj_id': '0000000000000000000000000000000000000000',
'file_icon': 'file.png',
'starred': false,
'last_modified': new Date().getTime() / 1000,
'last_update': gettext("Just now"),
'sharelink': '',
'sharetoken': ''
}, {silent: true});
var view = new DirentView({model: new_dirent, dirView: dirView});
var new_file = view.render().el;
// put the new file as the first file
if ($('tr', dirView.$dirent_list).length == 0) {
dirView.$dirent_list.append(new_file);
} else {
var dirs = dir.where({'is_dir':true});
if (dirs.length == 0) {
dirView.$dirent_list.prepend(new_file);
} else {
// put the new file after the last dir
$($('tr', dirView.$dirent_list)[dirs.length - 1]).after(new_file);
}
}
}; };
Common.ajaxPost({ Common.ajaxPost({

View File

@@ -53,7 +53,6 @@ define([
case 'cp_file': return siteRoot + 'ajax/repo/' + options.repo_id + '/file/cp/'; case 'cp_file': return siteRoot + 'ajax/repo/' + options.repo_id + '/file/cp/';
case 'new_dir': return siteRoot + 'ajax/repo/' + options.repo_id + '/dir/new/'; case 'new_dir': return siteRoot + 'ajax/repo/' + options.repo_id + '/dir/new/';
case 'new_file': return siteRoot + 'ajax/repo/' + options.repo_id + '/file/new/'; case 'new_file': return siteRoot + 'ajax/repo/' + options.repo_id + '/file/new/';
case 'repo_new_file': return siteRoot + 'repo/' + options.repo_id + '/files/';
case 'del_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/delete/'; case 'del_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/delete/';
case 'mv_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/move/'; case 'mv_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/move/';
case 'cp_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/copy/'; case 'cp_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/copy/';
@@ -207,7 +206,7 @@ define([
}); });
}, },
HTMLescape: function(html){ HTMLescape: function(html) {
return document.createElement('div') return document.createElement('div')
.appendChild(document.createTextNode(html)) .appendChild(document.createTextNode(html))
.parentNode .parentNode
@@ -223,7 +222,35 @@ define([
result += '/' + array[i]; result += '/' + array[i];
} }
return result; return result;
} },
fileSizeFormat: function (bytes, precision) {
var kilobyte = 1024;
var megabyte = kilobyte * 1024;
var gigabyte = megabyte * 1024;
var terabyte = gigabyte * 1024;
var precision = precision || 0;
if ((bytes >= 0) && (bytes < kilobyte)) {
return bytes + ' B';
} else if ((bytes >= kilobyte) && (bytes < megabyte)) {
return (bytes / kilobyte).toFixed(precision) + ' KB';
} else if ((bytes >= megabyte) && (bytes < gigabyte)) {
return (bytes / megabyte).toFixed(precision) + ' MB';
} else if ((bytes >= gigabyte) && (bytes < terabyte)) {
return (bytes / gigabyte).toFixed(precision) + ' GB';
} else if (bytes >= terabyte) {
return (bytes / terabyte).toFixed(precision) + ' TB';
} else {
return bytes + ' B';
}
}
} }
}); });

View File

@@ -4,7 +4,7 @@
<span>{% trans "Upload" %}</span> <span>{% trans "Upload" %}</span>
<input type="file" name="file" multiple /> <input type="file" name="file" multiple />
</div> </div>
{% if enable_upload_folder %} <% if (enable_upload_folder) { %>
<ul id="upload-menu" class="hide"> <ul id="upload-menu" class="hide">
<li class="item"> <li class="item">
<span>{% trans "Upload Files" %}</span> <span>{% trans "Upload Files" %}</span>
@@ -15,7 +15,7 @@
<input type="file" name="file" multiple directory webkitdirectory /> <input type="file" name="file" multiple directory webkitdirectory />
</li> </li>
</ul> </ul>
{% endif %} <% } %>
<button id="add-new-dir" class="op-btn">{% trans "New Directory" %}</button> <button id="add-new-dir" class="op-btn">{% trans "New Directory" %}</button>
<button id="add-new-file" class="op-btn">{% trans "New File" %}</button> <button id="add-new-file" class="op-btn">{% trans "New File" %}</button>
<% } %> <% } %>

View File

@@ -1,92 +1,92 @@
{% load i18n %} {% load i18n %}
<% if (dirent.is_dir) { %> <% if (dirent.is_dir) { %>
<td class="select"> <td class="select">
<span class="checkbox"><input type="checkbox" class="checkbox-orig" /></span> <span class="checkbox"><input type="checkbox" class="checkbox-orig" /></span>
</td> </td>
<td class="star"></td> <td class="star"></td>
<td class="dirent-icon"><img src="{{ MEDIA_URL }}img/folder-icon-24.png" alt="{% trans "Directory icon" %}" /></td> <td class="dirent-icon"><img src="{{ MEDIA_URL }}img/folder-icon-24.png" alt="{% trans "Directory icon" %}" /></td>
<td> <td>
<span class="dirent-name"><a href="#<%= category %>/lib/<%= repo_id %><% print(dirent_path); %>" class="dir-link normal"><%= dirent.obj_name %></a></span> <span class="dirent-name"><a href="#<%= category %>/lib/<%= repo_id %><% print(dirent_path); %>" class="dir-link normal"><%= dirent.obj_name %></a></span>
</td> </td>
<td class="dirent-size"></td> <td class="dirent-size"></td>
<td class="dirent-update"> <td class="dirent-update">
<% if (dirent.last_modified) { %> <% if (dirent.last_modified) { %>
<% print(dirent.last_update); %> <% print(dirent.last_update); %>
<% } else { %> <% } else { %>
<% print(""); %> <% print(""); %>
<% } %> <% } %>
</td> </td>
<td class="dirent-op"> <td class="dirent-op">
<div class="repo-file-op vh"> <div class="repo-file-op vh">
<div class="displayed-op"> <div class="displayed-op">
<a class="op download" href="{{ SITE_ROOT }}repo/download_dir/<%= repo_id %>/?p=<% print(dirent_path); %>" title="{% trans "Download" %}"><img src="{{ MEDIA_URL }}img/download.png" alt="" /></a> <a class="op download" href="{{ SITE_ROOT }}repo/download_dir/<%= repo_id %>/?p=<% print(dirent_path); %>" title="{% trans "Download" %}"><img src="{{ MEDIA_URL }}img/download.png" alt="" /></a>
<% if (!repo_encrypted) { %> <% if (!repo_encrypted) { %>
<a class="op share" href="#" title="{% trans "Share" %}"><img src="{{ MEDIA_URL }}img/share_20.png" alt="" /></a> <a class="op share" href="#" title="{% trans "Share" %}"><img src="{{ MEDIA_URL }}img/share_20.png" alt="" /></a>
<% } %> <% } %>
</div>
<% if (user_perm == 'rw') { %>
<img src="{{ MEDIA_URL }}img/dropdown-arrow.png" title="{% trans "More operations" %}" alt="{% trans "More operations" %}" class="more-op-icon cspt" />
<ul class="hidden-op hide">
<li><a class="op del" href="#">{% trans "Delete" %}</a></li>
<li><a class="op rename" href="#">{% trans "Rename" %}</a></li>
<li><a class="op mv" href="#">{% trans "Move" %}</a></li>
<li><a class="op cp" href="#">{% trans "Copy" %}</a></li>
</ul>
<% } %>
</div> </div>
<% if (user_perm == 'rw') { %>
<img src="{{ MEDIA_URL }}img/dropdown-arrow.png" title="{% trans "More operations" %}" alt="{% trans "More operations" %}" class="more-op-icon cspt" />
<ul class="hidden-op hide">
<li><a class="op del" href="#">{% trans "Delete" %}</a></li>
<li><a class="op rename" href="#">{% trans "Rename" %}</a></li>
<li><a class="op mv" href="#">{% trans "Move" %}</a></li>
<li><a class="op cp" href="#">{% trans "Copy" %}</a></li>
</ul>
<% } %>
</div>
</td> </td>
<% } else { %> <% } else { %>
<td class="select"> <td class="select">
<span class="checkbox"><input type="checkbox" class="checkbox-orig" /></span> <span class="checkbox"><input type="checkbox" class="checkbox-orig" /></span>
</td> </td>
<td class="star alc"> <td class="star alc">
<% if (dirent.starred) { %> <% if (dirent.starred) { %>
<span title="{% trans "starred" %}" class="icon-star file-star"></span> <span title="{% trans "starred" %}" class="icon-star file-star"></span>
<% } else { %> <% } else { %>
<span title="{% trans "unstarred" %}" class="icon-star-empty file-star"></span> <span title="{% trans "unstarred" %}" class="icon-star-empty file-star"></span>
<% } %> <% } %>
</td> </td>
<td class="dirent-icon"> <td class="dirent-icon">
<% if (dirent.is_img) { %> <% if (dirent.is_img) { %>
<% if (dirent.thumbnail_src) { %> <% if (dirent.thumbnail_src) { %>
<img class="thumbnail" src="<%= dirent.thumbnail_src %>" alt="" /> <img class="thumbnail" src="<%= dirent.thumbnail_src %>" alt="" />
<% } else { %> <% } else { %>
<img class="not-thumbnail" src="{{ MEDIA_URL }}img/file/<%= dirent.file_icon %>" alt="" /> <img class="not-thumbnail" src="{{ MEDIA_URL }}img/file/<%= dirent.file_icon %>" alt="" />
<% } %> <% } %>
<% } else { %> <% } else { %>
<img src="{{ MEDIA_URL }}img/file/<%= dirent.file_icon %>" alt="" /> <img src="{{ MEDIA_URL }}img/file/<%= dirent.file_icon %>" alt="" />
<% } %> <% } %>
</td> </td>
<td> <td>
<span class="dirent-name"><a class="normal" href="{{ SITE_ROOT }}lib/<%= repo_id %>/file<% print(dirent_path); %>" target="_blank"><%= dirent.obj_name %></a></span> <span class="dirent-name"><a class="normal" href="{{ SITE_ROOT }}lib/<%= repo_id %>/file<% print(dirent_path); %>" target="_blank"><%= dirent.obj_name %></a></span>
</td> </td>
<td class="dirent-size"><%= dirent.file_size %></td> <td class="dirent-size"><%= dirent.file_size %></td>
<td class="dirent-update"> <td class="dirent-update">
<% if (dirent.last_modified) { %> <% if (dirent.last_modified) { %>
<% print(dirent.last_update); %> <% print(dirent.last_update); %>
<% } else { %> <% } else { %>
<% print("{% trans "Fetch failed" %}"); %> <% print("{% trans "Fetch failed" %}"); %>
<% } %> <% } %>
</td> </td>
<td class="dirent-op"> <td class="dirent-op">
<div class="repo-file-op vh"> <div class="repo-file-op vh">
<div class="displayed-op"> <div class="displayed-op">
<a class="op download" href="{{ SITE_ROOT }}repo/<%= repo_id %>/<%= dirent.obj_id %>/download/?p=<% print(dirent_path); %>" title="{% trans "Download" %}"><img src="{{ MEDIA_URL }}img/download.png" alt="" /></a> <a class="op download" href="{{ SITE_ROOT }}repo/<%= repo_id %>/<%= dirent.obj_id %>/download/?p=<% print(dirent_path); %>" title="{% trans "Download" %}"><img src="{{ MEDIA_URL }}img/download.png" alt="" /></a>
<% if (!repo_encrypted) { %> <% if (!repo_encrypted) { %>
<a class="op share" href="#" data-link="<%= dirent.sharelink %>" data-token="<%= dirent.sharetoken %>" title="{% trans "Share" %}"><img src="{{ MEDIA_URL }}img/share_20.png" alt="" /></a> <a class="op share" href="#" data-link="<%= dirent.sharelink %>" data-token="<%= dirent.sharetoken %>" title="{% trans "Share" %}"><img src="{{ MEDIA_URL }}img/share_20.png" alt="" /></a>
<% } %> <% } %>
</div>
<% if (user_perm == 'rw') { %>
<img src="{{ MEDIA_URL }}img/dropdown-arrow.png" title="{% trans "More Operations"%}" alt="{% trans "More Operations"%}" class="more-op-icon cspt" />
<ul class="hidden-op hide">
<li><a class="op del" href="#">{% trans "Delete" %}</a></li>
<li><a class="op rename" href="#">{% trans "Rename" %}</a></li>
<li><a class="op mv" href="#">{% trans "Move" %}</a></li>
<li><a class="op cp" href="#">{% trans "Copy" %}</a></li>
<li><a class="op file-update" href="#">{% trans "Update"%}</a></li>
<li><a class="op file-history" href="{{ SITE_ROOT }}repo/file_revisions/<%= repo_id %>/?p=<% print(dirent_path); %>" target="_blank">{% trans "History" %}</a></li>
</ul>
<% } %>
</div> </div>
<% if (user_perm == 'rw') { %>
<img src="{{ MEDIA_URL }}img/dropdown-arrow.png" title="{% trans "More Operations"%}" alt="{% trans "More Operations"%}" class="more-op-icon cspt" />
<ul class="hidden-op hide">
<li><a class="op del" href="#">{% trans "Delete" %}</a></li>
<li><a class="op rename" href="#">{% trans "Rename" %}</a></li>
<li><a class="op mv" href="#">{% trans "Move" %}</a></li>
<li><a class="op cp" href="#">{% trans "Copy" %}</a></li>
<li><a class="op file-update" href="#">{% trans "Update"%}</a></li>
<li><a class="op file-history" href="{{ SITE_ROOT }}repo/file_revisions/<%= repo_id %>/?p=<% print(dirent_path); %>" target="_blank">{% trans "History" %}</a></li>
</ul>
<% } %>
</div>
</td> </td>
<% } %> <% } %>

View File

@@ -226,7 +226,9 @@ app["pageOptions"] = {
csrfToken: "{{ csrf_token }}", csrfToken: "{{ csrf_token }}",
reposUrl: "{% url 'api2-repos' %}" reposUrl: "{% url 'api2-repos' %}"
}; };
app.globalState = {}; app.globalState = {
enable_upload_folder: {% if enable_upload_folder %} true {% else %} false {% endif %}
};
</script> </script>
<script type="text/javascript" data-main="{{ MEDIA_URL }}scripts/myhome" src="{{ MEDIA_URL }}scripts/lib/require.js"></script> <script type="text/javascript" data-main="{{ MEDIA_URL }}scripts/myhome" src="{{ MEDIA_URL }}scripts/lib/require.js"></script>
{% endblock %} {% endblock %}

View File

@@ -1175,6 +1175,7 @@ def myhome(request):
"sub_lib_enabled": sub_lib_enabled, "sub_lib_enabled": sub_lib_enabled,
"sub_repos": sub_repos, "sub_repos": sub_repos,
"repo_create_url": repo_create_url, "repo_create_url": repo_create_url,
'enable_upload_folder': settings.ENABLE_UPLOAD_FOLDER,
}, context_instance=RequestContext(request)) }, context_instance=RequestContext(request))
@login_required @login_required