app.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 2014
  3. *
  4. * This file is licensed under the Affero General Public License version 3
  5. * or later.
  6. *
  7. * See the COPYING-README file.
  8. *
  9. */
  10. /**
  11. * @namespace OCA.Trashbin
  12. */
  13. OCA.Trashbin = {};
  14. /**
  15. * @namespace OCA.Trashbin.App
  16. */
  17. OCA.Trashbin.App = {
  18. _initialized: false,
  19. initialize: function($el) {
  20. if (this._initialized) {
  21. return;
  22. }
  23. this._initialized = true;
  24. this.fileList = new OCA.Trashbin.FileList(
  25. $('#app-content-trashbin'), {
  26. scrollContainer: $('#app-content'),
  27. fileActions: this._createFileActions()
  28. }
  29. );
  30. },
  31. _createFileActions: function() {
  32. var fileActions = new OCA.Files.FileActions();
  33. fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) {
  34. var dir = context.fileList.getCurrentDirectory();
  35. if (dir !== '/') {
  36. dir = dir + '/';
  37. }
  38. context.fileList.changeDirectory(dir + filename);
  39. });
  40. fileActions.setDefault('dir', 'Open');
  41. fileActions.register('all', 'Restore', OC.PERMISSION_READ, OC.imagePath('core', 'actions/history'), function(filename, context) {
  42. var fileList = context.fileList;
  43. var tr = fileList.findFileEl(filename);
  44. var deleteAction = tr.children("td.date").children(".action.delete");
  45. deleteAction.removeClass('icon-delete').addClass('icon-loading-small');
  46. fileList.disableActions();
  47. $.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'), {
  48. files: JSON.stringify([filename]),
  49. dir: fileList.getCurrentDirectory()
  50. },
  51. _.bind(fileList._removeCallback, fileList)
  52. );
  53. }, t('files_trashbin', 'Restore'));
  54. fileActions.registerAction({
  55. name: 'Delete',
  56. displayName: '',
  57. mime: 'all',
  58. permissions: OC.PERMISSION_READ,
  59. icon: function() {
  60. return OC.imagePath('core', 'actions/delete');
  61. },
  62. render: function(actionSpec, isDefault, context) {
  63. var $actionLink = fileActions._makeActionLink(actionSpec, context);
  64. $actionLink.attr('original-title', t('files_trashbin', 'Delete permanently'));
  65. $actionLink.children('img').attr('alt', t('files_trashbin', 'Delete permanently'));
  66. context.$file.find('td:last').append($actionLink);
  67. return $actionLink;
  68. },
  69. actionHandler: function(filename, context) {
  70. var fileList = context.fileList;
  71. $('.tipsy').remove();
  72. var tr = fileList.findFileEl(filename);
  73. var deleteAction = tr.children("td.date").children(".action.delete");
  74. deleteAction.removeClass('icon-delete').addClass('icon-loading-small');
  75. fileList.disableActions();
  76. $.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'), {
  77. files: JSON.stringify([filename]),
  78. dir: fileList.getCurrentDirectory()
  79. },
  80. _.bind(fileList._removeCallback, fileList)
  81. );
  82. }
  83. });
  84. return fileActions;
  85. }
  86. };
  87. $(document).ready(function() {
  88. $('#app-content-trashbin').one('show', function() {
  89. var App = OCA.Trashbin.App;
  90. App.initialize($('#app-content-trashbin'));
  91. // force breadcrumb init
  92. // App.fileList.changeDirectory(App.fileList.getCurrentDirectory(), false, true);
  93. });
  94. });