Blame view
sources/apps/files_trashbin/js/filelist.js
6.95 KB
|
6d9380f96
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
/*
* Copyright (c) 2014
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/
(function() {
var DELETED_REGEXP = new RegExp(/^(.+)\.d[0-9]+$/);
/**
* Convert a file name in the format filename.d12345 to the real file name.
* This will use basename.
* The name will not be changed if it has no ".d12345" suffix.
* @param name file name
* @return converted file name
*/
function getDeletedFileName(name) {
name = OC.basename(name);
var match = DELETED_REGEXP.exec(name);
if (match && match.length > 1) {
name = match[1];
}
return name;
|
|
31b7f2792
|
27 |
} |
|
6d9380f96
|
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
var FileList = function($el, options) {
this.initialize($el, options);
};
FileList.prototype = _.extend({}, OCA.Files.FileList.prototype, {
id: 'trashbin',
appName: t('files_trashbin', 'Deleted files'),
initialize: function() {
var result = OCA.Files.FileList.prototype.initialize.apply(this, arguments);
this.$el.find('.undelete').click('click', _.bind(this._onClickRestoreSelected, this));
this.setSort('mtime', 'desc');
/**
* Override crumb making to add "Deleted Files" entry
* and convert files with ".d" extensions to a more
* user friendly name.
*/
this.breadcrumb._makeCrumbs = function() {
var parts = OCA.Files.BreadCrumb.prototype._makeCrumbs.apply(this, arguments);
for (var i = 1; i < parts.length; i++) {
parts[i].name = getDeletedFileName(parts[i].name);
}
return parts;
};
return result;
},
/**
* Override to only return read permissions
*/
getDirectoryPermissions: function() {
return OC.PERMISSION_READ | OC.PERMISSION_DELETE;
},
_setCurrentDir: function(targetDir) {
OCA.Files.FileList.prototype._setCurrentDir.apply(this, arguments);
var baseDir = OC.basename(targetDir);
if (baseDir !== '') {
this.setPageTitle(getDeletedFileName(baseDir));
}
},
_createRow: function() {
// FIXME: MEGAHACK until we find a better solution
var tr = OCA.Files.FileList.prototype._createRow.apply(this, arguments);
tr.find('td.filesize').remove();
return tr;
},
_renderRow: function(fileData, options) {
options = options || {};
var dir = this.getCurrentDirectory();
var dirListing = dir !== '' && dir !== '/';
// show deleted time as mtime
if (fileData.mtime) {
fileData.mtime = parseInt(fileData.mtime, 10);
}
if (!dirListing) {
fileData.displayName = fileData.name;
fileData.name = fileData.name + '.d' + Math.floor(fileData.mtime / 1000);
}
return OCA.Files.FileList.prototype._renderRow.call(this, fileData, options);
},
getAjaxUrl: function(action, params) {
var q = '';
if (params) {
q = '?' + OC.buildQueryString(params);
}
return OC.filePath('files_trashbin', 'ajax', action + '.php') + q;
},
setupUploadEvents: function() {
// override and do nothing
},
linkTo: function(dir){
return OC.linkTo('files', 'index.php')+"?view=trashbin&dir="+ encodeURIComponent(dir).replace(/%2F/g, '/');
},
updateEmptyContent: function(){
var exists = this.$fileList.find('tr:first').exists();
this.$el.find('#emptycontent').toggleClass('hidden', exists);
this.$el.find('#filestable th').toggleClass('hidden', !exists);
|
|
31b7f2792
|
115 |
}, |
|
6d9380f96
|
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
_removeCallback: function(result) {
if (result.status !== 'success') {
OC.dialogs.alert(result.data.message, t('files_trashbin', 'Error'));
}
var files = result.data.success;
var $el;
for (var i = 0; i < files.length; i++) {
$el = this.remove(OC.basename(files[i].filename), {updateSummary: false});
this.fileSummary.remove({type: $el.attr('data-type'), size: $el.attr('data-size')});
}
this.fileSummary.update();
this.updateEmptyContent();
this.enableActions();
},
_onClickRestoreSelected: function(event) {
event.preventDefault();
var self = this;
var allFiles = this.$el.find('.select-all').is(':checked');
var files = [];
var params = {};
this.disableActions();
if (allFiles) {
this.showMask();
params = {
allfiles: true,
dir: this.getCurrentDirectory()
};
}
else {
files = _.pluck(this.getSelectedFiles(), 'name');
for (var i = 0; i < files.length; i++) {
var deleteAction = this.findFileEl(files[i]).children("td.date").children(".action.delete");
deleteAction.removeClass('delete-icon').addClass('progress-icon');
}
params = {
files: JSON.stringify(files),
dir: this.getCurrentDirectory()
};
}
$.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'),
params,
function(result) {
if (allFiles) {
if (result.status !== 'success') {
OC.dialogs.alert(result.data.message, t('files_trashbin', 'Error'));
}
self.hideMask();
// simply remove all files
self.setFiles([]);
self.enableActions();
}
else {
self._removeCallback(result);
}
}
);
},
_onClickDeleteSelected: function(event) {
event.preventDefault();
var self = this;
var allFiles = this.$el.find('.select-all').is(':checked');
var files = [];
var params = {};
if (allFiles) {
params = {
allfiles: true,
dir: this.getCurrentDirectory()
};
}
else {
files = _.pluck(this.getSelectedFiles(), 'name');
params = {
files: JSON.stringify(files),
dir: this.getCurrentDirectory()
};
}
this.disableActions();
if (allFiles) {
this.showMask();
}
else {
for (var i = 0; i < files.length; i++) {
var deleteAction = this.findFileEl(files[i]).children("td.date").children(".action.delete");
deleteAction.removeClass('delete-icon').addClass('progress-icon');
}
}
$.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'),
params,
function(result) {
if (allFiles) {
if (result.status !== 'success') {
OC.dialogs.alert(result.data.message, t('files_trashbin', 'Error'));
}
self.hideMask();
// simply remove all files
self.setFiles([]);
self.enableActions();
}
else {
self._removeCallback(result);
}
}
);
|
|
31b7f2792
|
226 |
}, |
|
6d9380f96
|
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
_onClickFile: function(event) {
var mime = $(this).parent().parent().data('mime');
if (mime !== 'httpd/unix-directory') {
event.preventDefault();
}
return OCA.Files.FileList.prototype._onClickFile.apply(this, arguments);
},
generatePreviewUrl: function(urlSpec) {
return OC.generateUrl('/apps/files_trashbin/ajax/preview.php?') + $.param(urlSpec);
},
getDownloadUrl: function() {
// no downloads
return '#';
},
enableActions: function() {
this.$el.find('.action').css('display', 'inline');
this.$el.find(':input:checkbox').css('display', 'inline');
},
disableActions: function() {
this.$el.find('.action').css('display', 'none');
this.$el.find(':input:checkbox').css('display', 'none');
},
updateStorageStatistics: function() {
// no op because the trashbin doesn't have
// storage info like free space / used space
|
|
31b7f2792
|
258 |
} |
|
6d9380f96
|
259 |
|
|
31b7f2792
|
260 |
}); |
|
6d9380f96
|
261 262 263 |
OCA.Trashbin.FileList = FileList; })(); |