diff --git a/src/plugin/cursus/Controller/CourseController.php b/src/plugin/cursus/Controller/CourseController.php index 6188b1dfc4..61e7103101 100644 --- a/src/plugin/cursus/Controller/CourseController.php +++ b/src/plugin/cursus/Controller/CourseController.php @@ -18,6 +18,7 @@ use Claroline\CoreBundle\Component\Context\DesktopContext; use Claroline\CoreBundle\Entity\Organization\Organization; use Claroline\CoreBundle\Entity\User; +use Claroline\CoreBundle\Entity\Workspace\Workspace; use Claroline\CoreBundle\Library\Normalizer\TextNormalizer; use Claroline\CoreBundle\Library\RoutingHelper; use Claroline\CoreBundle\Manager\Tool\ToolManager; @@ -214,6 +215,13 @@ public function copyAction(Request $request): JsonResponse $data = $this->decodeRequest($request); + $workspaceData = $data['workspace'] ?? null; + $workspace = null; + + if ($workspaceData) { + $workspace = $this->om->getRepository(Workspace::class)->findOneBy(['uuid' => $data['workspace']['id']]); + } + /** @var Course[] $courses */ $courses = $this->om->getRepository(Course::class)->findBy([ 'uuid' => $data['ids'], @@ -221,7 +229,11 @@ public function copyAction(Request $request): JsonResponse foreach ($courses as $course) { if ($this->authorization->isGranted('ADMINISTRATE', $course)) { - $processed[] = $this->crud->copy($course); + $copy = $this->crud->copy($course); + if (1 === count($courses) && $workspace) { + $copy->setWorkspace($workspace); + } + $processed[] = $copy; } } diff --git a/src/plugin/cursus/Resources/modules/course/components/empty.jsx b/src/plugin/cursus/Resources/modules/course/components/empty.jsx index 1ca58315aa..59358bee7e 100644 --- a/src/plugin/cursus/Resources/modules/course/components/empty.jsx +++ b/src/plugin/cursus/Resources/modules/course/components/empty.jsx @@ -7,7 +7,6 @@ import {trans} from '#/main/app/intl/translation' import {ContentSizing} from '#/main/app/content/components/sizing' import {CreationType} from '#/plugin/cursus/course/components/type' -import {ContentPlaceholder} from '#/main/app/content/components/placeholder' import {MODAL_COURSE_TYPE_CREATION} from '#/plugin/cursus/course/modals/creation' const EmptyCourse = (props) => @@ -20,7 +19,8 @@ const EmptyCourse = (props) => icon: 'fa fa-fw fa-plus', label: trans('add_course', {}, 'cursus'), modal: [MODAL_COURSE_TYPE_CREATION, { - path: props.path + path: props.path, + contextId: props.contextId }], group: trans('management'), displayed: props.canEdit, @@ -28,15 +28,12 @@ const EmptyCourse = (props) => } ]} > - - - - - + +

+ + {trans('no_course', {}, 'cursus')} + {trans('no_course_help', {}, 'cursus')} +

diff --git a/src/plugin/cursus/Resources/modules/course/components/type.jsx b/src/plugin/cursus/Resources/modules/course/components/type.jsx index 6ebd523270..ecede052a2 100644 --- a/src/plugin/cursus/Resources/modules/course/components/type.jsx +++ b/src/plugin/cursus/Resources/modules/course/components/type.jsx @@ -1,15 +1,29 @@ import React from 'react' import {PropTypes as T} from 'prop-types' import {useHistory} from 'react-router-dom' + +import {url} from '#/main/app/api' import {trans} from '#/main/app/intl' +import {ContentMenu} from '#/main/app/content/components/menu' +import {ASYNC_BUTTON, CALLBACK_BUTTON, MODAL_BUTTON} from '#/main/app/buttons' import {MODAL_WORKSPACES} from '#/main/core/modals/workspaces' -import {ContentMenu} from '#/main/app/content/components/menu' -import {CALLBACK_BUTTON, MODAL_BUTTON} from '#/main/app/buttons' import {Course as CourseTypes} from '#/plugin/cursus/prop-types' +import {MODAL_TRAINING_COURSES} from '#/plugin/cursus/modals/courses' const CreationType = (props) => { const history = useHistory() + const handleNavigation = (props, history, workspace = null, course = null) => { + if (props.modal) { + props.fadeModal() + } + if (course) { + history.push(`${props.path}/${course.slug}`) + } else { + history.push(props.path + '/new') + props.openForm(null, CourseTypes.defaultProps, workspace) + } + } return ( { selectAction: (selected) => ( { type: CALLBACK_BUTTON, - callback: () => { - if (props.modal) { - props.fadeModal() - } - history.push(props.path + '/new') - props.openForm(null, CourseTypes.defaultProps, selected[0]) - } + callback: () => handleNavigation(props, history, selected[0]) } ) }] @@ -54,13 +62,7 @@ const CreationType = (props) => { selectAction: (selected) => ( { type: CALLBACK_BUTTON, - callback: () => { - if (props.modal) { - props.fadeModal() - } - history.push(props.path + '/new') - props.openForm(null, CourseTypes.defaultProps, selected[0]) - } + callback: () => handleNavigation(props, history, selected[0]) } ) }] @@ -72,13 +74,7 @@ const CreationType = (props) => { description: trans('create_mode_empty_desc', {}, 'cursus'), action: { type: CALLBACK_BUTTON, - callback: () => { - if (props.modal) { - props.fadeModal() - } - history.push(props.path + '/new') - props.openForm(null, CourseTypes.defaultProps) - } + callback: () => handleNavigation(props, history) } }, { id: 'create-from-copy', @@ -87,7 +83,23 @@ const CreationType = (props) => { description: trans('create_mode_copy_desc', {}, 'cursus'), action: { type: MODAL_BUTTON, - modal: [] + modal: [MODAL_TRAINING_COURSES, { + selectAction: (selected) => ({ + type: ASYNC_BUTTON, + label: trans('copy', {}, 'actions'), + request: { + url: url(['apiv2_cursus_course_copy']), + request: { + method: 'POST', + body: JSON.stringify({ + ids: selected.length ? [selected[selected.length - 1].id] : [], + workspace: props.contextId + }) + }, + success: (course) => handleNavigation(props, history, null, course[0]) + } + }) + }] }, group: trans('create_mode_group_existing', {}, 'cursus') }, { @@ -119,9 +131,10 @@ const CreationType = (props) => { CreationType.propTypes = { path: T.string.isRequired, - openForm: T.func.isRequired, + openForm: T.func, reset: T.func, contextType: T.string, + contextId: T.object, modal: T.bool, fadeModal: T.func } diff --git a/src/plugin/cursus/Resources/modules/course/modals/creation/components/modal.jsx b/src/plugin/cursus/Resources/modules/course/modals/creation/components/modal.jsx index 705e084d5b..759dabbcef 100644 --- a/src/plugin/cursus/Resources/modules/course/modals/creation/components/modal.jsx +++ b/src/plugin/cursus/Resources/modules/course/modals/creation/components/modal.jsx @@ -19,6 +19,7 @@ const CreationModal = (props) => CreationModal.propTypes = { path: T.string.isRequired, contextType: T.string.isRequired, + contextId: T.object.isRequired, openForm: T.func.isRequired, reset: T.func.isRequired, fadeModal: T.func.isRequired diff --git a/src/plugin/cursus/Resources/modules/tools/events/components/tool.jsx b/src/plugin/cursus/Resources/modules/tools/events/components/tool.jsx index 4c918682b9..8a3967e1fd 100644 --- a/src/plugin/cursus/Resources/modules/tools/events/components/tool.jsx +++ b/src/plugin/cursus/Resources/modules/tools/events/components/tool.jsx @@ -83,6 +83,8 @@ const EventsTool = (props) => path={props.path} canEdit={props.canEdit} contextType={props.contextType} + contextId={props.currentContext.data} + openForm={props.openForm} /> ) } diff --git a/src/plugin/cursus/Resources/modules/tools/trainings/catalog/components/list.jsx b/src/plugin/cursus/Resources/modules/tools/trainings/catalog/components/list.jsx index a10bd11f83..1ac3c28c2f 100644 --- a/src/plugin/cursus/Resources/modules/tools/trainings/catalog/components/list.jsx +++ b/src/plugin/cursus/Resources/modules/tools/trainings/catalog/components/list.jsx @@ -39,6 +39,11 @@ const CatalogList = (props) => name={selectors.LIST_NAME} url={['apiv2_cursus_course_list']} > +

+ + {trans('no_courses', {}, 'cursus')} + {trans('no_courses_help', {}, 'cursus')} +