files.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. var uploadingFiles = {};
  2. Files={
  3. cancelUpload:function(filename) {
  4. if(uploadingFiles[filename]) {
  5. uploadingFiles[filename].abort();
  6. delete uploadingFiles[filename];
  7. return true;
  8. }
  9. return false;
  10. },
  11. cancelUploads:function() {
  12. $.each(uploadingFiles,function(index,file) {
  13. if(typeof file['abort'] === 'function') {
  14. file.abort();
  15. var filename = $('tr').filterAttr('data-file',index);
  16. filename.hide();
  17. filename.find('input[type="checkbox"]').removeAttr('checked');
  18. filename.removeClass('selected');
  19. } else {
  20. $.each(file,function(i,f) {
  21. f.abort();
  22. delete file[i];
  23. });
  24. }
  25. delete uploadingFiles[index];
  26. });
  27. procesSelection();
  28. },
  29. updateMaxUploadFilesize:function(response) {
  30. if(response == undefined) {
  31. return;
  32. }
  33. if(response.data !== undefined && response.data.uploadMaxFilesize !== undefined) {
  34. $('#max_upload').val(response.data.uploadMaxFilesize);
  35. $('#upload.button').attr('original-title', response.data.maxHumanFilesize);
  36. $('#usedSpacePercent').val(response.data.usedSpacePercent);
  37. Files.displayStorageWarnings();
  38. }
  39. if(response[0] == undefined) {
  40. return;
  41. }
  42. if(response[0].uploadMaxFilesize !== undefined) {
  43. $('#max_upload').val(response[0].uploadMaxFilesize);
  44. $('#upload.button').attr('original-title', response[0].maxHumanFilesize);
  45. $('#usedSpacePercent').val(response[0].usedSpacePercent);
  46. Files.displayStorageWarnings();
  47. }
  48. },
  49. isFileNameValid:function (name) {
  50. if (name === '.') {
  51. OC.Notification.show(t('files', '\'.\' is an invalid file name.'));
  52. return false;
  53. }
  54. if (name.length == 0) {
  55. OC.Notification.show(t('files', 'File name cannot be empty.'));
  56. return false;
  57. }
  58. // check for invalid characters
  59. var invalid_characters = ['\\', '/', '<', '>', ':', '"', '|', '?', '*'];
  60. for (var i = 0; i < invalid_characters.length; i++) {
  61. if (name.indexOf(invalid_characters[i]) != -1) {
  62. OC.Notification.show(t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed."));
  63. return false;
  64. }
  65. }
  66. OC.Notification.hide();
  67. return true;
  68. },
  69. displayStorageWarnings: function() {
  70. if (!OC.Notification.isHidden()) {
  71. return;
  72. }
  73. var usedSpacePercent = $('#usedSpacePercent').val();
  74. if (usedSpacePercent > 98) {
  75. OC.Notification.show(t('files', 'Your storage is full, files can not be updated or synced anymore!'));
  76. return;
  77. }
  78. if (usedSpacePercent > 90) {
  79. OC.Notification.show(t('files', 'Your storage is almost full ({usedSpacePercent}%)', {usedSpacePercent: usedSpacePercent}));
  80. }
  81. },
  82. displayEncryptionWarning: function() {
  83. if (!OC.Notification.isHidden()) {
  84. return;
  85. }
  86. var encryptedFiles = $('#encryptedFiles').val();
  87. if (encryptedFiles === '1') {
  88. OC.Notification.show(t('files_encryption', 'Encryption was disabled but your files are still encrypted. Please go to your personal settings to decrypt your files.'));
  89. return;
  90. }
  91. }
  92. };
  93. $(document).ready(function() {
  94. Files.displayEncryptionWarning();
  95. Files.bindKeyboardShortcuts(document, jQuery);
  96. $('#fileList tr').each(function(){
  97. //little hack to set unescape filenames in attribute
  98. $(this).attr('data-file',decodeURIComponent($(this).attr('data-file')));
  99. });
  100. $('#file_action_panel').attr('activeAction', false);
  101. //drag/drop of files
  102. $('#fileList tr td.filename').each(function(i,e){
  103. if ($(e).parent().data('permissions') & OC.PERMISSION_DELETE) {
  104. $(e).draggable(dragOptions);
  105. }
  106. });
  107. $('#fileList tr[data-type="dir"] td.filename').each(function(i,e){
  108. if ($(e).parent().data('permissions') & OC.PERMISSION_CREATE){
  109. $(e).droppable(folderDropOptions);
  110. }
  111. });
  112. $('div.crumb:not(.last)').droppable(crumbDropOptions);
  113. $('ul#apps>li:first-child').data('dir','');
  114. if($('div.crumb').length){
  115. $('ul#apps>li:first-child').droppable(crumbDropOptions);
  116. }
  117. // Triggers invisible file input
  118. $('#upload a').on('click', function() {
  119. $(this).parent().children('#file_upload_start').trigger('click');
  120. return false;
  121. });
  122. // Trigger cancelling of file upload
  123. $('#uploadprogresswrapper .stop').on('click', function() {
  124. Files.cancelUploads();
  125. });
  126. // Show trash bin
  127. $('#trash').on('click', function() {
  128. window.location=OC.filePath('files_trashbin', '', 'index.php');
  129. });
  130. var lastChecked;
  131. // Sets the file link behaviour :
  132. $('#fileList').on('click','td.filename a',function(event) {
  133. if (event.ctrlKey || event.shiftKey) {
  134. event.preventDefault();
  135. if (event.shiftKey) {
  136. var last = $(lastChecked).parent().parent().prevAll().length;
  137. var first = $(this).parent().parent().prevAll().length;
  138. var start = Math.min(first, last);
  139. var end = Math.max(first, last);
  140. var rows = $(this).parent().parent().parent().children('tr');
  141. for (var i = start; i < end; i++) {
  142. $(rows).each(function(index) {
  143. if (index == i) {
  144. var checkbox = $(this).children().children('input:checkbox');
  145. $(checkbox).attr('checked', 'checked');
  146. $(checkbox).parent().parent().addClass('selected');
  147. }
  148. });
  149. }
  150. }
  151. var checkbox = $(this).parent().children('input:checkbox');
  152. lastChecked = checkbox;
  153. if ($(checkbox).attr('checked')) {
  154. $(checkbox).removeAttr('checked');
  155. $(checkbox).parent().parent().removeClass('selected');
  156. $('#select_all').removeAttr('checked');
  157. } else {
  158. $(checkbox).attr('checked', 'checked');
  159. $(checkbox).parent().parent().toggleClass('selected');
  160. var selectedCount=$('td.filename input:checkbox:checked').length;
  161. if (selectedCount == $('td.filename input:checkbox').length) {
  162. $('#select_all').attr('checked', 'checked');
  163. }
  164. }
  165. procesSelection();
  166. } else {
  167. var filename=$(this).parent().parent().attr('data-file');
  168. var tr=$('tr').filterAttr('data-file',filename);
  169. var renaming=tr.data('renaming');
  170. if(!renaming && !FileList.isLoading(filename)){
  171. FileActions.currentFile = $(this).parent();
  172. var mime=FileActions.getCurrentMimeType();
  173. var type=FileActions.getCurrentType();
  174. var permissions = FileActions.getCurrentPermissions();
  175. var action=FileActions.getDefault(mime,type, permissions);
  176. if(action){
  177. event.preventDefault();
  178. action(filename);
  179. }
  180. }
  181. }
  182. });
  183. // Sets the select_all checkbox behaviour :
  184. $('#select_all').click(function() {
  185. if($(this).attr('checked')){
  186. // Check all
  187. $('td.filename input:checkbox').attr('checked', true);
  188. $('td.filename input:checkbox').parent().parent().addClass('selected');
  189. }else{
  190. // Uncheck all
  191. $('td.filename input:checkbox').attr('checked', false);
  192. $('td.filename input:checkbox').parent().parent().removeClass('selected');
  193. }
  194. procesSelection();
  195. });
  196. $('#fileList').on('change', 'td.filename input:checkbox',function(event) {
  197. if (event.shiftKey) {
  198. var last = $(lastChecked).parent().parent().prevAll().length;
  199. var first = $(this).parent().parent().prevAll().length;
  200. var start = Math.min(first, last);
  201. var end = Math.max(first, last);
  202. var rows = $(this).parent().parent().parent().children('tr');
  203. for (var i = start; i < end; i++) {
  204. $(rows).each(function(index) {
  205. if (index == i) {
  206. var checkbox = $(this).children().children('input:checkbox');
  207. $(checkbox).attr('checked', 'checked');
  208. $(checkbox).parent().parent().addClass('selected');
  209. }
  210. });
  211. }
  212. }
  213. var selectedCount=$('td.filename input:checkbox:checked').length;
  214. $(this).parent().parent().toggleClass('selected');
  215. if(!$(this).attr('checked')){
  216. $('#select_all').attr('checked',false);
  217. }else{
  218. if(selectedCount==$('td.filename input:checkbox').length){
  219. $('#select_all').attr('checked',true);
  220. }
  221. }
  222. procesSelection();
  223. });
  224. $('.download').click('click',function(event) {
  225. var files=getSelectedFiles('name');
  226. var fileslist = JSON.stringify(files);
  227. var dir=$('#dir').val()||'/';
  228. OC.Notification.show(t('files','Your download is being prepared. This might take some time if the files are big.'));
  229. // use special download URL if provided, e.g. for public shared files
  230. if ( (downloadURL = document.getElementById("downloadURL")) ) {
  231. window.location=downloadURL.value+"&download&files="+encodeURIComponent(fileslist);
  232. } else {
  233. window.location=OC.filePath('files', 'ajax', 'download.php') + '?'+ $.param({ dir: dir, files: fileslist });
  234. }
  235. return false;
  236. });
  237. $('.delete-selected').click(function(event) {
  238. var files=getSelectedFiles('name');
  239. event.preventDefault();
  240. FileList.do_delete(files);
  241. return false;
  242. });
  243. // drag&drop support using jquery.fileupload
  244. // TODO use OC.dialogs
  245. $(document).bind('drop dragover', function (e) {
  246. e.preventDefault(); // prevent browser from doing anything, if file isn't dropped in dropZone
  247. });
  248. //do a background scan if needed
  249. scanFiles();
  250. var lastWidth = 0;
  251. var breadcrumbs = [];
  252. var breadcrumbsWidth = 0;
  253. if ( document.getElementById("navigation") ) {
  254. breadcrumbsWidth = $('#navigation').get(0).offsetWidth;
  255. }
  256. var hiddenBreadcrumbs = 0;
  257. $.each($('.crumb'), function(index, breadcrumb) {
  258. breadcrumbs[index] = breadcrumb;
  259. breadcrumbsWidth += $(breadcrumb).get(0).offsetWidth;
  260. });
  261. $.each($('#controls .actions>div'), function(index, action) {
  262. breadcrumbsWidth += $(action).get(0).offsetWidth;
  263. });
  264. function resizeBreadcrumbs(firstRun) {
  265. var width = $(this).width();
  266. if (width != lastWidth) {
  267. if ((width < lastWidth || firstRun) && width < breadcrumbsWidth) {
  268. if (hiddenBreadcrumbs == 0) {
  269. breadcrumbsWidth -= $(breadcrumbs[1]).get(0).offsetWidth;
  270. $(breadcrumbs[1]).find('a').hide();
  271. $(breadcrumbs[1]).append('<span>...</span>');
  272. breadcrumbsWidth += $(breadcrumbs[1]).get(0).offsetWidth;
  273. hiddenBreadcrumbs = 2;
  274. }
  275. var i = hiddenBreadcrumbs;
  276. while (width < breadcrumbsWidth && i > 1 && i < breadcrumbs.length - 1) {
  277. breadcrumbsWidth -= $(breadcrumbs[i]).get(0).offsetWidth;
  278. $(breadcrumbs[i]).hide();
  279. hiddenBreadcrumbs = i;
  280. i++
  281. }
  282. } else if (width > lastWidth && hiddenBreadcrumbs > 0) {
  283. var i = hiddenBreadcrumbs;
  284. while (width > breadcrumbsWidth && i > 0) {
  285. if (hiddenBreadcrumbs == 1) {
  286. breadcrumbsWidth -= $(breadcrumbs[1]).get(0).offsetWidth;
  287. $(breadcrumbs[1]).find('span').remove();
  288. $(breadcrumbs[1]).find('a').show();
  289. breadcrumbsWidth += $(breadcrumbs[1]).get(0).offsetWidth;
  290. } else {
  291. $(breadcrumbs[i]).show();
  292. breadcrumbsWidth += $(breadcrumbs[i]).get(0).offsetWidth;
  293. if (breadcrumbsWidth > width) {
  294. breadcrumbsWidth -= $(breadcrumbs[i]).get(0).offsetWidth;
  295. $(breadcrumbs[i]).hide();
  296. break;
  297. }
  298. }
  299. i--;
  300. hiddenBreadcrumbs = i;
  301. }
  302. }
  303. lastWidth = width;
  304. }
  305. }
  306. $(window).resize(function() {
  307. resizeBreadcrumbs(false);
  308. });
  309. resizeBreadcrumbs(true);
  310. // display storage warnings
  311. setTimeout ( "Files.displayStorageWarnings()", 100 );
  312. OC.Notification.setDefault(Files.displayStorageWarnings);
  313. // file space size sync
  314. function update_storage_statistics() {
  315. $.getJSON(OC.filePath('files','ajax','getstoragestats.php'),function(response) {
  316. Files.updateMaxUploadFilesize(response);
  317. });
  318. }
  319. // start on load - we ask the server every 5 minutes
  320. var update_storage_statistics_interval = 5*60*1000;
  321. var update_storage_statistics_interval_id = setInterval(update_storage_statistics, update_storage_statistics_interval);
  322. // Use jquery-visibility to de-/re-activate file stats sync
  323. if ($.support.pageVisibility) {
  324. $(document).on({
  325. 'show.visibility': function() {
  326. if (!update_storage_statistics_interval_id) {
  327. update_storage_statistics_interval_id = setInterval(update_storage_statistics, update_storage_statistics_interval);
  328. }
  329. },
  330. 'hide.visibility': function() {
  331. clearInterval(update_storage_statistics_interval_id);
  332. update_storage_statistics_interval_id = 0;
  333. }
  334. });
  335. }
  336. });
  337. function scanFiles(force, dir, users){
  338. if (!OC.currentUser) {
  339. return;
  340. }
  341. if(!dir){
  342. dir = '';
  343. }
  344. force = !!force; //cast to bool
  345. scanFiles.scanning = true;
  346. var scannerEventSource;
  347. if (users) {
  348. var usersString;
  349. if (users === 'all') {
  350. usersString = users;
  351. } else {
  352. usersString = JSON.stringify(users);
  353. }
  354. scannerEventSource = new OC.EventSource(OC.filePath('files','ajax','scan.php'),{force: force,dir: dir, users: usersString});
  355. } else {
  356. scannerEventSource = new OC.EventSource(OC.filePath('files','ajax','scan.php'),{force: force,dir: dir});
  357. }
  358. scanFiles.cancel = scannerEventSource.close.bind(scannerEventSource);
  359. scannerEventSource.listen('count',function(count){
  360. console.log(count + ' files scanned')
  361. });
  362. scannerEventSource.listen('folder',function(path){
  363. console.log('now scanning ' + path)
  364. });
  365. scannerEventSource.listen('done',function(count){
  366. scanFiles.scanning=false;
  367. console.log('done after ' + count + ' files');
  368. });
  369. scannerEventSource.listen('user',function(user){
  370. console.log('scanning files for ' + user);
  371. });
  372. }
  373. scanFiles.scanning=false;
  374. function boolOperationFinished(data, callback) {
  375. result = jQuery.parseJSON(data.responseText);
  376. Files.updateMaxUploadFilesize(result);
  377. if(result.status == 'success'){
  378. callback.call();
  379. } else {
  380. alert(result.data.message);
  381. }
  382. }
  383. function updateBreadcrumb(breadcrumbHtml) {
  384. $('p.nav').empty().html(breadcrumbHtml);
  385. }
  386. var createDragShadow = function(event){
  387. //select dragged file
  388. var isDragSelected = $(event.target).parents('tr').find('td input:first').prop('checked');
  389. if (!isDragSelected) {
  390. //select dragged file
  391. $(event.target).parents('tr').find('td input:first').prop('checked',true);
  392. }
  393. var selectedFiles = getSelectedFiles();
  394. if (!isDragSelected && selectedFiles.length == 1) {
  395. //revert the selection
  396. $(event.target).parents('tr').find('td input:first').prop('checked',false);
  397. }
  398. //also update class when we dragged more than one file
  399. if (selectedFiles.length > 1) {
  400. $(event.target).parents('tr').addClass('selected');
  401. }
  402. // build dragshadow
  403. var dragshadow = $('<table class="dragshadow"></table>');
  404. var tbody = $('<tbody></tbody>');
  405. dragshadow.append(tbody);
  406. var dir=$('#dir').val();
  407. $(selectedFiles).each(function(i,elem){
  408. var newtr = $('<tr/>').attr('data-dir', dir).attr('data-filename', elem.name);
  409. newtr.append($('<td/>').addClass('filename').text(elem.name));
  410. newtr.append($('<td/>').addClass('size').text(humanFileSize(elem.size)));
  411. tbody.append(newtr);
  412. if (elem.type === 'dir') {
  413. newtr.find('td.filename').attr('style','background-image:url('+OC.imagePath('core', 'filetypes/folder.png')+')');
  414. } else {
  415. getMimeIcon(elem.mime,function(path){
  416. newtr.find('td.filename').attr('style','background-image:url('+path+')');
  417. });
  418. }
  419. });
  420. return dragshadow;
  421. }
  422. //options for file drag/drop
  423. var dragOptions={
  424. revert: 'invalid', revertDuration: 300,
  425. opacity: 0.7, zIndex: 100, appendTo: 'body', cursorAt: { left: -5, top: -5 },
  426. helper: createDragShadow, cursor: 'move',
  427. stop: function(event, ui) {
  428. $('#fileList tr td.filename').addClass('ui-draggable');
  429. }
  430. }
  431. // sane browsers support using the distance option
  432. if ( $('html.ie').length === 0) {
  433. dragOptions['distance'] = 20;
  434. }
  435. var folderDropOptions={
  436. drop: function( event, ui ) {
  437. //don't allow moving a file into a selected folder
  438. if ($(event.target).parents('tr').find('td input:first').prop('checked') === true) {
  439. return false;
  440. }
  441. var target=$.trim($(this).find('.nametext').text());
  442. var files = ui.helper.find('tr');
  443. $(files).each(function(i,row){
  444. var dir = $(row).data('dir');
  445. var file = $(row).data('filename');
  446. $.post(OC.filePath('files', 'ajax', 'move.php'), { dir: dir, file: file, target: dir+'/'+target }, function(result) {
  447. if (result) {
  448. if (result.status === 'success') {
  449. //recalculate folder size
  450. var oldSize = $('#fileList tr').filterAttr('data-file',target).data('size');
  451. var newSize = oldSize + $('#fileList tr').filterAttr('data-file',file).data('size');
  452. $('#fileList tr').filterAttr('data-file',target).data('size', newSize);
  453. $('#fileList tr').filterAttr('data-file',target).find('td.filesize').text(humanFileSize(newSize));
  454. FileList.remove(file);
  455. procesSelection();
  456. $('#notification').hide();
  457. } else {
  458. $('#notification').hide();
  459. $('#notification').text(result.data.message);
  460. $('#notification').fadeIn();
  461. }
  462. } else {
  463. OC.dialogs.alert(t('Error moving file'), t('core', 'Error'));
  464. }
  465. });
  466. });
  467. },
  468. tolerance: 'pointer'
  469. }
  470. var crumbDropOptions={
  471. drop: function( event, ui ) {
  472. var target=$(this).data('dir');
  473. var dir=$('#dir').val();
  474. while(dir.substr(0,1)=='/'){//remove extra leading /'s
  475. dir=dir.substr(1);
  476. }
  477. dir='/'+dir;
  478. if(dir.substr(-1,1)!='/'){
  479. dir=dir+'/';
  480. }
  481. if(target==dir || target+'/'==dir){
  482. return;
  483. }
  484. var files = ui.helper.find('tr');
  485. $(files).each(function(i,row){
  486. var dir = $(row).data('dir');
  487. var file = $(row).data('filename');
  488. $.post(OC.filePath('files', 'ajax', 'move.php'), { dir: dir, file: file, target: target }, function(result) {
  489. if (result) {
  490. if (result.status === 'success') {
  491. FileList.remove(file);
  492. procesSelection();
  493. $('#notification').hide();
  494. } else {
  495. $('#notification').hide();
  496. $('#notification').text(result.data.message);
  497. $('#notification').fadeIn();
  498. }
  499. } else {
  500. OC.dialogs.alert(t('Error moving file'), t('core', 'Error'));
  501. }
  502. });
  503. });
  504. },
  505. tolerance: 'pointer'
  506. }
  507. function procesSelection(){
  508. var selected=getSelectedFiles();
  509. var selectedFiles=selected.filter(function(el){return el.type=='file'});
  510. var selectedFolders=selected.filter(function(el){return el.type=='dir'});
  511. if(selectedFiles.length==0 && selectedFolders.length==0) {
  512. $('#headerName>span.name').text(t('files','Name'));
  513. $('#headerSize').text(t('files','Size'));
  514. $('#modified').text(t('files','Modified'));
  515. $('table').removeClass('multiselect');
  516. $('.selectedActions').hide();
  517. }
  518. else {
  519. $('.selectedActions').show();
  520. var totalSize=0;
  521. for(var i=0;i<selectedFiles.length;i++){
  522. totalSize+=selectedFiles[i].size;
  523. };
  524. for(var i=0;i<selectedFolders.length;i++){
  525. totalSize+=selectedFolders[i].size;
  526. };
  527. $('#headerSize').text(humanFileSize(totalSize));
  528. var selection='';
  529. if(selectedFolders.length>0){
  530. selection += n('files', '%n folder', '%n folders', selectedFolders.length);
  531. if(selectedFiles.length>0){
  532. selection+=' & ';
  533. }
  534. }
  535. if(selectedFiles.length>0){
  536. selection += n('files', '%n file', '%n files', selectedFiles.length);
  537. }
  538. $('#headerName>span.name').text(selection);
  539. $('#modified').text('');
  540. $('table').addClass('multiselect');
  541. }
  542. }
  543. /**
  544. * @brief get a list of selected files
  545. * @param string property (option) the property of the file requested
  546. * @return array
  547. *
  548. * possible values for property: name, mime, size and type
  549. * if property is set, an array with that property for each file is returnd
  550. * if it's ommited an array of objects with all properties is returned
  551. */
  552. function getSelectedFiles(property){
  553. var elements=$('td.filename input:checkbox:checked').parent().parent();
  554. var files=[];
  555. elements.each(function(i,element){
  556. var file={
  557. name:$(element).attr('data-file'),
  558. mime:$(element).data('mime'),
  559. type:$(element).data('type'),
  560. size:$(element).data('size')
  561. };
  562. if(property){
  563. files.push(file[property]);
  564. }else{
  565. files.push(file);
  566. }
  567. });
  568. return files;
  569. }
  570. function getMimeIcon(mime, ready){
  571. if(getMimeIcon.cache[mime]){
  572. ready(getMimeIcon.cache[mime]);
  573. }else{
  574. $.get( OC.filePath('files','ajax','mimeicon.php'), {mime: mime}, function(path){
  575. getMimeIcon.cache[mime]=path;
  576. ready(getMimeIcon.cache[mime]);
  577. });
  578. }
  579. }
  580. getMimeIcon.cache={};
  581. function getUniqueName(name){
  582. if($('tr').filterAttr('data-file',name).length>0){
  583. var parts=name.split('.');
  584. var extension = "";
  585. if (parts.length > 1) {
  586. extension=parts.pop();
  587. }
  588. var base=parts.join('.');
  589. numMatch=base.match(/\((\d+)\)/);
  590. var num=2;
  591. if(numMatch && numMatch.length>0){
  592. num=parseInt(numMatch[numMatch.length-1])+1;
  593. base=base.split('(')
  594. base.pop();
  595. base=$.trim(base.join('('));
  596. }
  597. name=base+' ('+num+')';
  598. if (extension) {
  599. name = name+'.'+extension;
  600. }
  601. return getUniqueName(name);
  602. }
  603. return name;
  604. }
  605. function checkTrashStatus() {
  606. $.post(OC.filePath('files_trashbin', 'ajax', 'isEmpty.php'), function(result){
  607. if (result.data.isEmpty === false) {
  608. $("input[type=button][id=trash]").removeAttr("disabled");
  609. }
  610. });
  611. }