1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 15:09:14 +00:00
This commit is contained in:
lian
2016-05-27 16:42:40 +08:00
parent 72f4297934
commit a767aeb3d8
22 changed files with 240 additions and 212 deletions

View File

@@ -6,12 +6,10 @@ from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework import status
from django.template.defaultfilters import filesizeformat
from django.utils.translation import ugettext as _
from seaserv import ccnet_api, seafile_api, seafserv_threaded_rpc
from seahub.views.ajax import get_related_users_by_org_repo, \
get_related_users_by_repo
from seahub.signals import repo_deleted
from seahub.views import get_system_default_repo_id
from seahub.utils import is_org_context
from seahub.base.accounts import User
@@ -35,6 +33,8 @@ def get_repo_info(repo):
class AdminLibraries(APIView):
""" return all libraries
"""
authentication_classes = (TokenAuthentication, SessionAuthentication)
throttle_classes = (UserRateThrottle,)
@@ -87,18 +87,9 @@ class AdminLibrary(APIView):
return Response({'success': True})
if get_system_default_repo_id() == repo_id:
error_msg = ('System library can not be deleted.')
error_msg = _('System library can not be deleted.')
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
if is_org_context(request):
org_id = seafserv_threaded_rpc.get_org_id_by_repo_id(repo_id)
usernames = get_related_users_by_org_repo(org_id, repo_id)
repo_owner = seafile_api.get_org_repo_owner(repo_id)
else:
org_id = -1
usernames = get_related_users_by_repo(repo_id)
repo_owner = seafile_api.get_repo_owner(repo_id)
try:
seafile_api.remove_repo(repo_id)
except Exception as e:
@@ -106,13 +97,11 @@ class AdminLibrary(APIView):
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
repo_deleted.send(sender=None, org_id=org_id, usernames=usernames,
repo_owner=repo_owner, repo_id=repo_id,
repo_name=repo.repo_name)
return Response({'success': True})
def put(self, request, repo_id, format=None):
""" transfer a library
"""
repo = seafile_api.get_repo(repo_id)
if not repo:
error_msg = 'Library %s not found.' % repo_id

View File

@@ -1,7 +1,7 @@
import os
import stat
import logging
import time
import posixpath
from rest_framework.authentication import SessionAuthentication
from rest_framework.permissions import IsAdminUser
@@ -26,6 +26,22 @@ from seahub.api2.utils import api_error
logger = logging.getLogger(__name__)
def get_dirent_info(dirent):
if stat.S_ISDIR(dirent.mode):
is_file = False
else:
is_file = True
result = {}
result['is_file'] = is_file
result['obj_name'] = dirent.obj_name
result['file_size'] = filesizeformat(dirent.size) if is_file else ''
result['last_update'] = timestamp_to_isoformat_timestr(dirent.mtime)
return result
class AdminLibraryDirents(APIView):
authentication_classes = (TokenAuthentication, SessionAuthentication)
@@ -33,6 +49,9 @@ class AdminLibraryDirents(APIView):
permission_classes = (IsAdminUser,)
def get(self, request, repo_id, format=None):
""" get all file/folder in a library
"""
repo = seafile_api.get_repo(repo_id)
if not repo:
error_msg = 'Library %s not found.' % repo_id
@@ -55,7 +74,6 @@ class AdminLibraryDirents(APIView):
error_msg = 'Folder %s not found.' % parent_dir
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
# TODO org?
if is_org_context(request):
repo_owner = seafile_api.get_org_repo_owner(repo_id)
else:
@@ -77,29 +95,15 @@ class AdminLibraryDirents(APIView):
return_results['dirent_list'] = []
for dirent in dirs:
result = {}
if stat.S_ISDIR(dirent.mode):
result['is_file'] = False
result['obj_name'] = dirent.obj_name
result['file_size'] = ''
result['last_update'] = timestamp_to_isoformat_timestr(dirent.mtime)
else:
if repo.version == 0:
size = seafile_api.get_file_size(repo.store_id,
repo.version, dirent.obj_id)
else:
size = dirent.size
result['is_file'] = True
result['obj_name'] = dirent.obj_name
result['file_size'] = filesizeformat(size)
result['last_update'] = timestamp_to_isoformat_timestr(dirent.mtime)
return_results['dirent_list'].append(result)
dirent_info = get_dirent_info(dirent)
return_results['dirent_list'].append(dirent_info)
return Response(return_results)
def post(self, request, repo_id, format=None):
""" create file/folder in a library
"""
repo = seafile_api.get_repo(repo_id)
if not repo:
error_msg = 'Library %s not found.' % repo_id
@@ -137,13 +141,11 @@ class AdminLibraryDirents(APIView):
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
result = {}
result['is_file'] = False
result['obj_name'] = obj_name
result['file_size'] = filesizeformat(0)
result['last_update'] = timestamp_to_isoformat_timestr(time.time())
dirent_path = posixpath.join(parent_dir, obj_name)
dirent = seafile_api.get_dirent_by_path(repo_id, dirent_path)
dirent_info = get_dirent_info(dirent)
return Response(result)
return Response(dirent_info)
class AdminLibraryDirent(APIView):
@@ -152,6 +154,9 @@ class AdminLibraryDirent(APIView):
permission_classes = (IsAdminUser,)
def get(self, request, repo_id):
""" get info of a single file/folder in a library
"""
repo = seafile_api.get_repo(repo_id)
if not repo:
error_msg = 'Library %s not found.' % repo_id
@@ -169,47 +174,39 @@ class AdminLibraryDirent(APIView):
if path[0] != '/':
path = '/' + path
file_id = None
dir_id = None
try:
file_id = seafile_api.get_file_id_by_path(repo_id, path)
dir_id = seafile_api.get_dir_id_by_path(repo_id, path)
dirent = seafile_api.get_dirent_by_path(repo_id, path)
except SearpcError as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
if file_id:
is_file = True
elif dir_id:
is_file = False
else:
error_msg = 'path %s not found.' % path
if not dirent:
error_msg = 'file/folder %s not found.' % path
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
username = request.user.username
obj_name = os.path.basename(path.rstrip('/'))
if stat.S_ISDIR(dirent.mode):
is_file = False
else:
is_file = True
username = request.user.username
if is_file and request.GET.get('dl', '0') == '1':
token = seafile_api.get_fileserver_access_token(repo_id,
file_id, 'download', username, use_onetime=True)
dl_url = gen_file_get_url(token, obj_name)
dirent.obj_id, 'download', username, use_onetime=True)
dl_url = gen_file_get_url(token, dirent.obj_name)
send_file_access_msg(request, repo, path, 'web')
return Response({'download_url': dl_url})
size = seafile_api.get_file_size(repo.store_id,
repo.version, file_id or dir_id)
dirent_info = get_dirent_info(dirent)
result = {}
result['is_file'] = is_file
result['obj_name'] = obj_name
result['file_size'] = filesizeformat(size)
# TODO
# result['last_update'] = timestamp_to_isoformat_timestr(dirent.mtime)
return Response(result)
return Response(dirent_info)
def delete(self, request, repo_id):
""" delete a single file/folder in a library
"""
repo = seafile_api.get_repo(repo_id)
if not repo:
error_msg = 'Library %s not found.' % repo_id

View File

@@ -25,6 +25,8 @@ class AdminTrashLibraries(APIView):
permission_classes = (IsAdminUser,)
def get(self, request, format=None):
""" get all deleted libraries
"""
repos_all = seafile_api.get_trash_repo_list(-1, -1)
return_results = []
@@ -40,6 +42,9 @@ class AdminTrashLibraries(APIView):
return Response(return_results)
def delete(self, request, format=None):
""" clean all deleted libraries
"""
try:
seafile_api.empty_repo_trash()
except SearpcError as e:
@@ -56,6 +61,9 @@ class AdminTrashLibrary(APIView):
permission_classes = (IsAdminUser,)
def put(self, request, repo_id, format=None):
""" restore a deleted library
"""
try:
seafile_api.restore_repo_from_trash(repo_id)
except SearpcError as e:
@@ -66,6 +74,9 @@ class AdminTrashLibrary(APIView):
return Response({'success': True})
def delete(self, request, repo_id, format=None):
""" permanently delete a deleted library
"""
try:
seafile_api.del_repo_from_trash(repo_id)
except SearpcError as e:

View File

@@ -268,11 +268,11 @@
<thead>
<tr>
<th width="4%"><!--icon--></th>
<th width="27%">{% trans "Name" %}</th>
<th width="10%"></th>
<th width="17%">{% trans "Files / Size" %}</th>
<th width="21%">ID</th>
<th width="21%">{% trans "Owner" %}</th>
<th width="34%">{% trans "Name" %}</th>
<th width="13%">{% trans "Files / Size" %}</th>
<th width="19%">ID</th>
<th width="20%">{% trans "Owner" %}</th>
<th width="10%">{% trans "Operations" %}</th>
</tr>
</thead>
<tbody>
@@ -289,12 +289,9 @@
</script>
<script type="text/template" id="library-item-tmpl">
<% if (encrypted) { %>
<td><img src="{{MEDIA_URL}}img/sync-folder-encrypt-20.png" title="{% trans "Encrypted"%}" alt="{% trans "directory icon" %}" /></td>
<% } else { %>
<td><img src="{{MEDIA_URL}}img/sync-folder-20.png?" title="{% trans "Read-Write"%}" alt="{% trans "directory icon" %}" /></td>
<% } %>
<td>
<img src="<%= icon_url %>" title="<%= icon_title %>" alt="<%= icon_title %>" width="24" />
</td>
<% if (name) { %>
<% if (enable_sys_admin_view_repo && is_pro && !encrypted) { %>
<td><a href="#libraries/<%- id %>/dirents/"><%- name %></a></td>
@@ -304,19 +301,19 @@
<% } else { %>
<td>--</td>
<% } %>
<td>
<a href="#" class="sf2-icon-delete sf2-x repo-delete-btn op-icon vh" title="{% trans "Delete" %}" aria-label="{% trans "Delete" %}"></a>
<a href="#" class="sf2-icon-move sf2-x repo-transfer-btn op-icon vh" title="{% trans "Transfer" %}" aria-label="{% trans "Transfer" %}"></a>
</td>
<td><%- file_count %> / <%- size_formatted %></td>
<td style="font-size:11px;"><%- id %></td>
<td>
<% if (owner) { %>
<a href="{{ SITE_ROOT }}useradmin/info/<%- owner %>/"><%- owner %></a>
<a href="{{ SITE_ROOT }}useradmin/info/<% print(encodeURIComponent(owner)); %>/"><%- owner %></a>
<% } else { %>
--
<% } %>
</td>
<td>
<a href="#" class="sf2-icon-delete sf2-x repo-delete-btn op-icon vh" title="{% trans "Delete" %}" aria-label="{% trans "Delete" %}"></a>
<a href="#" class="sf2-icon-move sf2-x repo-transfer-btn op-icon vh" title="{% trans "Transfer" %}" aria-label="{% trans "Transfer" %}"></a>
</td>
</script>
<script type="text/template" id="system-library-tmpl">
@@ -389,9 +386,11 @@
</script>
<script type="text/template" id="trash-library-item-tmpl">
<td><img src="{{MEDIA_URL}}img/sync-folder-20.png?t=1387267140" title="{% trans "Read-Write"%}" alt="{% trans "directory icon" %}" /></td>
<td>
<img src="<%= icon_url %>" title="<%= icon_title %>" alt="<%= icon_title %>" width="24" />
</td>
<td><%- name %></td>
<td><a href="{{ SITE_ROOT }}useradmin/info/<%- owner %>/"><%- owner %></a></td>
<td><a href="{{ SITE_ROOT }}useradmin/info/<% print(encodeURIComponent(owner)); %>/"><%- owner %></a></td>
<td><time title='<%- time %>'><%- time_from_now %></time></td>
<td>
<a href="#" class="sf2-icon-delete sf2-x repo-delete-btn op-icon vh" title="{% trans "Delete" %}" aria-label="{% trans "Delete" %}"></a>

View File

@@ -2,12 +2,12 @@ define([
'underscore',
'backbone',
'common',
'sysadmin-app/models/library-dirent'
], function(_, Backbone, Common, LibraryDirentModel) {
'sysadmin-app/models/dirent'
], function(_, Backbone, Common, DirentModel) {
'use strict';
var LibraryDirentCollection = Backbone.Collection.extend({
model: LibraryDirentModel,
var DirentCollection = Backbone.Collection.extend({
model: DirentModel,
parse: function (data) {
this.repo_name = data.repo_name;
this.repo_id = data.repo_id;
@@ -20,5 +20,5 @@ define([
}
});
return LibraryDirentCollection;
return DirentCollection;
});

View File

@@ -2,12 +2,12 @@ define([
'underscore',
'backbone.paginator',
'common',
'sysadmin-app/models/library'
], function(_, BackbonePaginator, Common, LibraryModel) {
'sysadmin-app/models/repo'
], function(_, BackbonePaginator, Common, RepoModel) {
'use strict';
var LibraryCollection = Backbone.PageableCollection.extend({
model: LibraryModel,
var RepoCollection = Backbone.PageableCollection.extend({
model: RepoModel,
state: {pageSize: 100},
parseState: function(data) {
return {hasNextPage: data[0].has_next_page, current_page: data[0].current_page};
@@ -20,5 +20,5 @@ define([
}
});
return LibraryCollection;
return RepoCollection;
});

View File

@@ -1,17 +0,0 @@
define([
'underscore',
'backbone',
'common',
'sysadmin-app/models/trash-library'
], function(_, Backbone, Common, TrashLibraryModel) {
'use strict';
var TrashLibraryCollection = Backbone.Collection.extend({
model: TrashLibraryModel,
url: function () {
return Common.getUrl({name: 'admin-trash-libraries'});
}
});
return TrashLibraryCollection;
});

View File

@@ -0,0 +1,17 @@
define([
'underscore',
'backbone',
'common',
'sysadmin-app/models/trash-repo'
], function(_, Backbone, Common, TrashRepoModel) {
'use strict';
var TrashRepoCollection = Backbone.Collection.extend({
model: TrashRepoModel,
url: function () {
return Common.getUrl({name: 'admin-trash-libraries'});
}
});
return TrashRepoCollection;
});

View File

@@ -5,7 +5,7 @@ define([
], function(_, Backbone, Common) {
'use strict';
var LibraryDirentModel = Backbone.Model.extend({
var DirentModel = Backbone.Model.extend({
// get the absolute path within the library
getPath: function() {
@@ -50,5 +50,5 @@ define([
}
});
return LibraryDirentModel;
return DirentModel;
});

View File

@@ -1,11 +0,0 @@
define([
'underscore',
'backbone',
'common',
], function(_, Backbone, Common) {
'use strict';
var LibraryModel = Backbone.Model.extend({});
return LibraryModel;
});

View File

@@ -0,0 +1,27 @@
define([
'underscore',
'backbone',
'common',
], function(_, Backbone, Common) {
'use strict';
var RepoModel = Backbone.Model.extend({
getIconUrl: function(size) {
var is_encrypted = this.get('encrypted');
return Common.getLibIconUrl(is_encrypted, false, size);
},
getIconTitle: function() {
var icon_title = '';
if (this.get('encrypted')) {
icon_title = gettext("Encrypted library");
} else {
icon_title = gettext("Read-Write library");
}
return icon_title;
}
});
return RepoModel;
});

View File

@@ -1,11 +0,0 @@
define([
'underscore',
'backbone',
'common'
], function(_, Backbone, Common) {
'use strict';
var SystemLibrary = Backbone.Model.extend({});
return SystemLibrary;
});

View File

@@ -5,7 +5,7 @@ define([
], function(_, Backbone, Common) {
'use strict';
var TrashLibrary = Backbone.Model.extend({});
var SystemRepo = Backbone.Model.extend({});
return TrashLibrary;
return SystemRepo;
});

View File

@@ -0,0 +1,19 @@
define([
'underscore',
'backbone',
'common'
], function(_, Backbone, Common) {
'use strict';
var TrashRepo = Backbone.Model.extend({
getIconUrl: function(size) {
return Common.getLibIconUrl(false, false, size);
},
getIconTitle: function() {
return gettext("Read-Write library");
}
});
return TrashRepo;
});

View File

@@ -8,15 +8,15 @@ define([
'sysadmin-app/views/desktop-devices',
'sysadmin-app/views/mobile-devices',
'sysadmin-app/views/device-errors',
'sysadmin-app/views/libraries',
'sysadmin-app/views/library-dir',
'sysadmin-app/views/system-library',
'sysadmin-app/views/trash-libraries',
'sysadmin-app/views/repos',
'sysadmin-app/views/dir',
'sysadmin-app/views/system-repo',
'sysadmin-app/views/trash-repos',
'app/views/account'
], function($, Backbone, Common, SideNavView, DashboardView,
DesktopDevicesView, MobileDevicesView, DeviceErrorsView,
LibrariesView, LibraryDirView, SystemLibrariesView,
TrashLibrariesView, AccountView) {
ReposView, DirView, SystemReposView,
TrashReposView, AccountView) {
"use strict";
@@ -50,10 +50,10 @@ define([
this.desktopDevicesView = new DesktopDevicesView();
this.mobileDevicesView = new MobileDevicesView();
this.deviceErrorsView = new DeviceErrorsView();
this.librariesView = new LibrariesView();
this.systemLibrariesView = new SystemLibrariesView();
this.trashLibrariesView = new TrashLibrariesView();
this.libraryDirView = new LibraryDirView();
this.reposView = new ReposView();
this.systemReposView = new SystemReposView();
this.trashReposView = new TrashReposView();
this.dirView = new DirView();
app.ui.accountView = this.accountView = new AccountView();
@@ -115,9 +115,9 @@ define([
} else {
var current_page = null;
}
this.switchCurrentView(this.librariesView);
this.switchCurrentView(this.reposView);
this.sideNavView.setCurTab('libraries');
this.librariesView.show({'current_page': current_page});
this.reposView.show({'current_page': current_page});
},
showLibraryDir: function(repo_id, path) {
@@ -126,21 +126,21 @@ define([
} else {
path = '/';
}
this.switchCurrentView(this.libraryDirView);
this.libraryDirView.show(repo_id, path);
this.switchCurrentView(this.dirView);
this.dirView.show(repo_id, path);
this.sideNavView.setCurTab('libraries');
},
showSystemLibrary: function() {
this.switchCurrentView(this.systemLibrariesView);
this.switchCurrentView(this.systemReposView);
this.sideNavView.setCurTab('libraries');
this.systemLibrariesView.show();
this.systemReposView.show();
},
showTrashLibraries: function() {
this.switchCurrentView(this.trashLibrariesView);
this.switchCurrentView(this.trashReposView);
this.sideNavView.setCurTab('libraries');
this.trashLibrariesView.show();
this.trashReposView.show();
}
});

View File

@@ -5,8 +5,8 @@ define([
'common',
'moment',
'app/views/fileupload',
'sysadmin-app/views/library-dirent',
'sysadmin-app/collection/library-dirents'
'sysadmin-app/views/dirent',
'sysadmin-app/collection/dirents'
], function($, _, Backbone, Common, Moment, FileUploadView,
DirentView, DirentCollection) {
'use strict';

View File

@@ -8,7 +8,7 @@ define([
], function($, _, Backbone, Common, Moment, HLItemView) {
'use strict';
var LibraryDirentView = HLItemView.extend({
var DirentView = HLItemView.extend({
tagName: 'tr',
template: _.template($('#dirent-item-tmpl').html()),
@@ -76,5 +76,5 @@ define([
});
return LibraryDirentView;
return DirentView;
});

View File

@@ -11,7 +11,7 @@ define([
Select2, HLItemView) {
'use strict';
var LibraryView = HLItemView.extend({
var RepoView = HLItemView.extend({
tagName: 'tr',
template: _.template($('#library-item-tmpl').html()),
@@ -107,8 +107,12 @@ define([
render: function() {
var data = this.model.toJSON(),
icon_size = Common.isHiDPI() ? 96 : 24,
icon_url = this.model.getIconUrl(icon_size),
last_accessed = Moment(data['last_accessed']);
data['icon_url'] = icon_url;
data['icon_title'] = this.model.getIconTitle();
data['enable_sys_admin_view_repo'] = app.pageOptions.enable_sys_admin_view_repo;
data['is_pro'] = app.pageOptions.is_pro;
data['time'] = last_accessed.format('LLLL');
@@ -121,5 +125,5 @@ define([
});
return LibraryView;
return RepoView;
});

View File

@@ -4,26 +4,26 @@ define([
'backbone',
'common',
'moment',
'sysadmin-app/views/library',
'sysadmin-app/collection/libraries'
], function($, _, Backbone, Common, Moment, LibraryView, LibraryCollection) {
'sysadmin-app/views/repo',
'sysadmin-app/collection/repos'
], function($, _, Backbone, Common, Moment, RepoView, RepoCollection) {
'use strict';
var LibrariesView = Backbone.View.extend({
var ReposView = Backbone.View.extend({
id: 'admin-libraries',
id: 'libraries',
template: _.template($("#libraries-tmpl").html()),
initialize: function() {
this.libraryCollection = new LibraryCollection();
this.listenTo(this.libraryCollection, 'add', this.addOne);
this.listenTo(this.libraryCollection, 'reset', this.reset);
this.repoCollection = new RepoCollection();
this.listenTo(this.repoCollection, 'add', this.addOne);
this.listenTo(this.repoCollection, 'reset', this.reset);
this.render();
},
render: function() {
var data = {'cur_tab': 'all',};
var data = {'cur_tab': 'all'};
this.$el.html(this.template(data));
this.$table = this.$('table');
this.$tableBody = $('tbody', this.$table);
@@ -49,9 +49,9 @@ define([
getNextPage: function() {
this.initPage();
var current_page = this.libraryCollection.state.current_page;
if (this.libraryCollection.state.hasNextPage) {
this.libraryCollection.getPage(current_page + 1, {
var current_page = this.repoCollection.state.current_page;
if (this.repoCollection.state.hasNextPage) {
this.repoCollection.getPage(current_page + 1, {
reset: true
});
}
@@ -61,9 +61,9 @@ define([
getPreviousPage: function() {
this.initPage();
var current_page = this.libraryCollection.state.current_page;
var current_page = this.repoCollection.state.current_page;
if ( current_page > 1) {
this.libraryCollection.getPage(current_page - 1, {
this.repoCollection.getPage(current_page - 1, {
reset: true
});
}
@@ -89,7 +89,7 @@ define([
var _this = this,
current_page = this.option.current_page || 1;
this.libraryCollection.fetch({
this.repoCollection.fetch({
data: {'page': current_page},
cache: false, // for IE
reset: true,
@@ -110,13 +110,13 @@ define([
},
reset: function() {
var length = this.libraryCollection.length,
current_page = this.libraryCollection.state.current_page;
var length = this.repoCollection.length,
current_page = this.repoCollection.state.current_page;
this.$loadingTip.hide();
if (length > 0) {
this.libraryCollection.each(this.addOne, this);
this.repoCollection.each(this.addOne, this);
this.$table.show();
this.renderPaginator();
} else {
@@ -127,13 +127,13 @@ define([
},
renderPaginator: function() {
if (this.libraryCollection.state.hasNextPage) {
if (this.repoCollection.state.hasNextPage) {
this.$jsNext.show();
} else {
this.$jsNext.hide();
}
var current_page = this.libraryCollection.state.current_page;
var current_page = this.repoCollection.state.current_page;
if (current_page > 1) {
this.$jsPrevious.show();
} else {
@@ -142,11 +142,11 @@ define([
},
addOne: function(library) {
var view = new LibraryView({model: library});
var view = new RepoView({model: library});
this.$tableBody.append(view.render().el);
}
});
return LibrariesView;
return ReposView;
});

View File

@@ -3,19 +3,19 @@ define([
'underscore',
'backbone',
'common',
'sysadmin-app/models/system-library'
], function($, _, Backbone, Common, SystemLibrary) {
'sysadmin-app/models/system-repo'
], function($, _, Backbone, Common, SystemRepo) {
'use strict';
var SystemLibraryView = Backbone.View.extend({
var SystemRepoView = Backbone.View.extend({
id: "admin-system-library",
id: "system-library",
template: _.template($("#system-library-tmpl").html()),
itemTemplate: _.template($("#system-library-item-tmpl").html()),
initialize: function() {
this.systemLibrary = new SystemLibrary();
this.systemRepo = new SystemRepo();
this.render();
},
@@ -37,7 +37,7 @@ define([
this.initPage();
var _this = this;
this.systemLibrary.fetch({
this.systemRepo.fetch({
url: Common.getUrl({name: 'admin-system-library'}),
cache: false, // for IE
reset: true,
@@ -71,11 +71,11 @@ define([
reset: function() {
this.$loadingTip.hide();
this.$tableBody.html(this.itemTemplate(this.systemLibrary.toJSON()));
this.$tableBody.html(this.itemTemplate(this.systemRepo.toJSON()));
this.$table.show();
}
});
return SystemLibraryView;
return SystemRepoView;
});

View File

@@ -8,7 +8,7 @@ define([
], function($, _, Backbone, Common, Moment, HLItemView) {
'use strict';
var LibraryView = HLItemView.extend({
var TrashRepoView = HLItemView.extend({
tagName: 'tr',
template: _.template($('#trash-library-item-tmpl').html()),
@@ -60,8 +60,12 @@ define([
render: function() {
var data = this.model.toJSON(),
icon_size = Common.isHiDPI() ? 96 : 24,
icon_url = this.model.getIconUrl(icon_size),
delete_time = Moment(data['delete_time']);
data['icon_url'] = icon_url;
data['icon_title'] = this.model.getIconTitle();
data['time'] = delete_time.format('LLLL');
data['time_from_now'] = Common.getRelativeTimeStr(delete_time);
@@ -72,5 +76,5 @@ define([
});
return LibraryView;
return TrashRepoView;
});

View File

@@ -4,22 +4,22 @@ define([
'backbone',
'common',
'moment',
'sysadmin-app/views/trash-library',
'sysadmin-app/collection/trash-libraries'
], function($, _, Backbone, Common, Moment, TrashLibraryView,
TrashLibraryCollection) {
'sysadmin-app/views/trash-repo',
'sysadmin-app/collection/trash-repos'
], function($, _, Backbone, Common, Moment, TrashRepoView,
TrashRepoCollection) {
'use strict';
var TrashLibrariesView = Backbone.View.extend({
var TrashReposView = Backbone.View.extend({
id: 'admin-trash-libraries',
id: 'trash-libraries',
template: _.template($("#trash-libraries-tmpl").html()),
initialize: function() {
this.trashLibraryCollection = new TrashLibraryCollection();
this.listenTo(this.trashLibraryCollection, 'add', this.addOne);
this.listenTo(this.trashLibraryCollection, 'reset', this.reset);
this.trashRepoCollection = new TrashRepoCollection();
this.listenTo(this.trashRepoCollection, 'add', this.addOne);
this.listenTo(this.trashRepoCollection, 'reset', this.reset);
},
render: function() {
@@ -75,7 +75,7 @@ define([
this.initPage();
var _this = this;
this.trashLibraryCollection.fetch({
this.trashRepoCollection.fetch({
data: {},
cache: false, // for IE
reset: true,
@@ -96,12 +96,12 @@ define([
},
reset: function() {
var length = this.trashLibraryCollection.length;
var length = this.trashRepoCollection.length;
this.$loadingTip.hide();
if (length > 0) {
this.trashLibraryCollection.each(this.addOne, this);
this.trashRepoCollection.each(this.addOne, this);
this.$table.show();
} else {
this.$emptyTip.show();
@@ -109,11 +109,11 @@ define([
},
addOne: function(library) {
var view = new TrashLibraryView({model: library});
var view = new TrashRepoView({model: library});
this.$tableBody.append(view.render().el);
}
});
return TrashLibrariesView;
return TrashReposView;
});