app.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. var urlParams = OC.Util.History.parseUrlQuery();
  25. this.fileList = new OCA.Trashbin.FileList(
  26. $('#app-content-trashbin'), {
  27. scrollContainer: $('#app-content'),
  28. fileActions: this._createFileActions(),
  29. detailsViewEnabled: false,
  30. scrollTo: urlParams.scrollto,
  31. config: OCA.Files.App.getFilesConfig()
  32. }
  33. );
  34. },
  35. _createFileActions: function() {
  36. var fileActions = new OCA.Files.FileActions();
  37. fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) {
  38. var dir = context.fileList.getCurrentDirectory();
  39. context.fileList.changeDirectory(OC.joinPaths(dir, filename));
  40. });
  41. fileActions.setDefault('dir', 'Open');
  42. fileActions.registerAction({
  43. name: 'Restore',
  44. displayName: t('files_trashbin', 'Restore'),
  45. type: OCA.Files.FileActions.TYPE_INLINE,
  46. mime: 'all',
  47. permissions: OC.PERMISSION_READ,
  48. iconClass: 'icon-history',
  49. actionHandler: function(filename, context) {
  50. var fileList = context.fileList;
  51. var tr = fileList.findFileEl(filename);
  52. var deleteAction = tr.children("td.date").children(".action.delete");
  53. deleteAction.removeClass('icon-delete').addClass('icon-loading-small');
  54. fileList.disableActions();
  55. $.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'), {
  56. files: JSON.stringify([filename]),
  57. dir: fileList.getCurrentDirectory()
  58. },
  59. _.bind(fileList._removeCallback, fileList)
  60. );
  61. }
  62. });
  63. fileActions.registerAction({
  64. name: 'Delete',
  65. displayName: t('files', 'Delete'),
  66. mime: 'all',
  67. permissions: OC.PERMISSION_READ,
  68. iconClass: 'icon-delete',
  69. render: function(actionSpec, isDefault, context) {
  70. var $actionLink = fileActions._makeActionLink(actionSpec, context);
  71. $actionLink.attr('original-title', t('files_trashbin', 'Delete permanently'));
  72. $actionLink.children('img').attr('alt', t('files_trashbin', 'Delete permanently'));
  73. context.$file.find('td:last').append($actionLink);
  74. return $actionLink;
  75. },
  76. actionHandler: function(filename, context) {
  77. var fileList = context.fileList;
  78. $('.tipsy').remove();
  79. var tr = fileList.findFileEl(filename);
  80. var deleteAction = tr.children("td.date").children(".action.delete");
  81. deleteAction.removeClass('icon-delete').addClass('icon-loading-small');
  82. fileList.disableActions();
  83. $.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'), {
  84. files: JSON.stringify([filename]),
  85. dir: fileList.getCurrentDirectory()
  86. },
  87. _.bind(fileList._removeCallback, fileList)
  88. );
  89. }
  90. });
  91. return fileActions;
  92. }
  93. };
  94. $(document).ready(function() {
  95. $('#app-content-trashbin').one('show', function() {
  96. var App = OCA.Trashbin.App;
  97. App.initialize($('#app-content-trashbin'));
  98. // force breadcrumb init
  99. // App.fileList.changeDirectory(App.fileList.getCurrentDirectory(), false, true);
  100. });
  101. });