openMoveDialog.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (C) 2015 - present Instructure, Inc.
  3. *
  4. * This file is part of Canvas.
  5. *
  6. * Canvas is free software: you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License as published by the Free
  8. * Software Foundation, version 3 of the License.
  9. *
  10. * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. * details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. import _ from 'underscore'
  19. import React from 'react'
  20. import ReactDOM from 'react-dom'
  21. import MoveDialog from 'jsx/files/MoveDialog'
  22. import filesEnv from 'compiled/react_files/modules/filesEnv'
  23. import $ from 'jquery'
  24. function openMoveDialog (thingsToMove, {contextType, contextId, returnFocusTo, clearSelectedItems, onMove}) {
  25. const rootFolderToShow = _.find(filesEnv.rootFolders, (folder) => {
  26. return (`${folder.get('context_type').toLowerCase()}s` === contextType) && (String(folder.get('context_id')) === String(contextId));
  27. });
  28. const $moveDialog = $('<div>').appendTo(document.body);
  29. const handleClose = () => {
  30. ReactDOM.unmountComponentAtNode($moveDialog[0]);
  31. $moveDialog.remove();
  32. $(returnFocusTo).focus();
  33. };
  34. const handleMove = (models) => {
  35. onMove(models) && clearSelectedItems();
  36. };
  37. ReactDOM.render(
  38. <MoveDialog
  39. thingsToMove={thingsToMove}
  40. rootFoldersToShow={(filesEnv.showingAllContexts) ? filesEnv.rootFolders : [rootFolderToShow] }
  41. onClose={handleClose}
  42. onMove={handleMove}
  43. />
  44. , $moveDialog[0]
  45. );
  46. }
  47. export default openMoveDialog