Search in sources :

Example 6 with ItemsPackage

use of org.olat.ims.qti.questionimport.ItemsPackage in project OpenOLAT by OpenOLAT.

the class QuestionListController method doOpenExcelImportQTI12.

private void doOpenExcelImportQTI12(UserRequest ureq) {
    removeAsListenerAndDispose(excelImportWizard);
    final ItemsPackage importPackage = new ItemsPackage();
    Step additionalStep = null;
    if (getSource().askEditable()) {
        additionalStep = new EditableStep(ureq);
    }
    final org.olat.ims.qti.questionimport.ImportOptions options = new org.olat.ims.qti.questionimport.ImportOptions();
    options.setShuffle(true);
    Step start = new org.olat.ims.qti.questionimport.QImport_1_InputStep(ureq, importPackage, options, additionalStep);
    StepRunnerCallback finish = new StepRunnerCallback() {

        @Override
        public Step execute(UserRequest uureq, WindowControl wControl, StepsRunContext runContext) {
            List<ItemAndMetadata> itemsToImport = importPackage.getItems();
            QTIQPoolServiceProvider spi = CoreSpringFactory.getImpl(QTIQPoolServiceProvider.class);
            List<QuestionItem> importItems = spi.importBeecomItem(getIdentity(), itemsToImport, getLocale());
            for (QuestionItem item : importItems) {
                QuestionItemAuditLogBuilder builder = qpoolService.createAuditLogBuilder(getIdentity(), Action.CREATE_QUESTION_ITEM_BY_IMPORT);
                builder.withAfter(item);
                qpoolService.persist(builder.create());
            }
            boolean editable = true;
            if (getSource().askEditable()) {
                Object editableCtx = runContext.get("editable");
                editable = (editableCtx instanceof Boolean) ? ((Boolean) editableCtx).booleanValue() : false;
            }
            qpoolService.index(importItems);
            int postImported = getSource().postImport(importItems, editable);
            if (postImported > 0) {
                getItemsTable().reset();
            }
            return StepsMainRunController.DONE_MODIFIED;
        }
    };
    excelImportWizard = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, translate("import.excellike.12"), "o_sel_qpool_excel_import_wizard");
    listenTo(excelImportWizard);
    getWindowControl().pushAsModalDialog(excelImportWizard.getInitialComponent());
}
Also used : QImport_1_InputStep(org.olat.ims.qti21.questionimport.QImport_1_InputStep) Step(org.olat.core.gui.control.generic.wizard.Step) Export_1_TypeStep(org.olat.modules.qpool.ui.wizard.Export_1_TypeStep) ImportAuthor_1_ChooseMemberStep(org.olat.modules.qpool.ui.wizard.ImportAuthor_1_ChooseMemberStep) WindowControl(org.olat.core.gui.control.WindowControl) StepsRunContext(org.olat.core.gui.control.generic.wizard.StepsRunContext) QImport_1_InputStep(org.olat.ims.qti21.questionimport.QImport_1_InputStep) QTIQPoolServiceProvider(org.olat.ims.qti.qpool.QTIQPoolServiceProvider) UserRequest(org.olat.core.gui.UserRequest) AssessmentItemsPackage(org.olat.ims.qti21.questionimport.AssessmentItemsPackage) ItemsPackage(org.olat.ims.qti.questionimport.ItemsPackage) QuestionItemAuditLogBuilder(org.olat.modules.qpool.QuestionItemAuditLogBuilder) StepsMainRunController(org.olat.core.gui.control.generic.wizard.StepsMainRunController) AssessmentItemAndMetadata(org.olat.ims.qti21.questionimport.AssessmentItemAndMetadata) ItemAndMetadata(org.olat.ims.qti.questionimport.ItemAndMetadata) QuestionItem(org.olat.modules.qpool.QuestionItem) ImportOptions(org.olat.ims.qti21.questionimport.ImportOptions) StepRunnerCallback(org.olat.core.gui.control.generic.wizard.StepRunnerCallback)

Example 7 with ItemsPackage

use of org.olat.ims.qti.questionimport.ItemsPackage in project openolat by klemens.

the class QTIEditorMainController method doImportTable.

private void doImportTable(UserRequest ureq) {
    removeAsListenerAndDispose(importTableWizard);
    final ItemsPackage importPackage = new ItemsPackage();
    final ImportOptions options = new ImportOptions();
    options.setShuffle(!qtiPackage.getQTIDocument().isSurvey());
    Step start = new QImport_1_InputStep(ureq, importPackage, options, null);
    StepRunnerCallback finish = new StepRunnerCallback() {

        @Override
        public Step execute(UserRequest uureq, WindowControl wControl, StepsRunContext runContext) {
            runContext.put("importPackage", importPackage);
            return StepsMainRunController.DONE_MODIFIED;
        }
    };
    importTableWizard = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, translate("tools.import.table"), "o_mi_table_import_wizard");
    listenTo(importTableWizard);
    getWindowControl().pushAsModalDialog(importTableWizard.getInitialComponent());
}
Also used : StepsMainRunController(org.olat.core.gui.control.generic.wizard.StepsMainRunController) QImport_1_InputStep(org.olat.ims.qti.questionimport.QImport_1_InputStep) Step(org.olat.core.gui.control.generic.wizard.Step) WindowControl(org.olat.core.gui.control.WindowControl) StepsRunContext(org.olat.core.gui.control.generic.wizard.StepsRunContext) ItemsPackage(org.olat.ims.qti.questionimport.ItemsPackage) ImportOptions(org.olat.ims.qti.questionimport.ImportOptions) StepRunnerCallback(org.olat.core.gui.control.generic.wizard.StepRunnerCallback) UserRequest(org.olat.core.gui.UserRequest) QImport_1_InputStep(org.olat.ims.qti.questionimport.QImport_1_InputStep)

Example 8 with ItemsPackage

use of org.olat.ims.qti.questionimport.ItemsPackage in project openolat by klemens.

the class QTIEditorMainController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == deleteDialog) {
        // event from delete dialog
        if (DialogBoxUIFactory.isYesEvent(event)) {
            // yes, delete
            GenericQtiNode clickedNode = (GenericQtiNode) deleteDialog.getUserObject();
            doDelete(clickedNode);
            event(ureq, menuTree, new Event(MenuTree.COMMAND_TREENODE_CLICKED));
            // ask user to confirm referenced media removal
            if (deletableMediaFiles != null && deletableMediaFiles.size() > 0) {
                String msg = translate("delete.item.media", deletableMediaFiles.toString());
                deleteMediaDialog = activateYesNoDialog(ureq, null, msg, deleteMediaDialog);
            }
            updateWarning();
        }
        // cleanup controller
        removeAsListenerAndDispose(deleteDialog);
        deleteDialog = null;
    } else if (source == deleteMediaDialog) {
        // event from deleteMediaDialog
        if (DialogBoxUIFactory.isYesEvent(event)) {
            // yes, delete
            qtiPackage.removeMediaFiles(deletableMediaFiles);
            deleteMediaDialog = null;
            deletableMediaFiles = null;
        }
    } else if (event instanceof NodeBeforeChangeEvent) {
        NodeBeforeChangeEvent nce = (NodeBeforeChangeEvent) event;
        // active node changed some data
        String activeQtiNodeId = menuTree.getSelectedNodeId();
        GenericQtiNode activeQtiNode = menuTreeModel.getQtiNode(activeQtiNodeId);
        // force rerendering for ajax mode
        menuTree.setDirty(true);
        /*
			 * mementos are only created in restricted mode
			 */
        if (isRestrictedEdit()) {
            String key = nce.getSectionIdent() + "/" + nce.getItemIdent() + "/" + nce.getQuestionIdent() + "/" + nce.getResponseIdent();
            if (!history.containsKey(key)) {
                Memento memento = activeQtiNode.createMemento();
                history.put(key, memento);
                qtiPackage.serializeChangelog(history);
            }
        }
        /*
			 * generate a Memento, store it for further use
			 */
        if (nce.hasNewTitle) {
            // update the treemodel to reflect the change of the underlying qti node
            activeQtiNode.setMenuTitleAndAlt(nce.getNewTitle());
            main.contextPut("qtititle", menuTreeModel.getQtiRootNode().getAltText());
        }
    } else if (source == proceedRestricedEditDialog) {
        // restricted edit warning
        if (DialogBoxUIFactory.isYesEvent(event)) {
            // remove dialog and continue with real content
            columnLayoutCtr.setCol3(mainPanel);
            columnLayoutCtr.hideCol1(false);
            columnLayoutCtr.hideCol2(false);
            removeAsListenerAndDispose(proceedRestricedEditDialog);
            proceedRestricedEditDialog = null;
        } else {
            // remove lock as user is not interested in restricted edit
            // and quick editor
            removeLocksAndExit(ureq);
        }
    } else if (source == cfc) {
        // dispose the content only controller we live in
        // remove modal dialog and cleanup exit process
        // modal dialog must be removed before fire DONE event
        // within the saveAndExit() call, otherwise the wrong
        // gui stack is popped see also OLAT-3056
        cmcExit.deactivate();
        removeAsListenerAndDispose(cmcExit);
        cmcExit = null;
        if (event == Event.CANCELLED_EVENT) {
        // nothing to do, back to editor
        } else {
            QTIChangeLogMessage clm = new QTIChangeLogMessage(changeLog, chngMsgFrom.hasInformLearners());
            qtiPackage.commitChangelog(clm);
            StringBuilder traceMsg = new StringBuilder(chngMsgFrom.hasInformLearners() ? "Visible for ALL \n" : "Visible for GROUP only \n");
            logAudit(traceMsg.append(changeLog).toString(), null);
            // save, remove locks and tmp files
            saveAndExit(ureq);
        }
        removeAsListenerAndDispose(cfc);
        cfc = null;
    } else if (source == chngMsgFrom) {
        if (event == Event.DONE_EVENT) {
            // the changemessage is created and user is willing to send it
            String userMsg = chngMsgFrom.getUserMsg();
            changeLog = changeEmail.getBodyText();
            if (StringHelper.containsNonWhitespace(userMsg)) {
                changeEmail.setBodyText("<p>" + userMsg + "</p>\n<pre>" + changeLog + "</pre>");
            }
            // else nothing was added!
            changeEmail.setSubject("Change log for " + startedWithTitle);
            cfc = new ContactFormController(ureq, getWindowControl(), true, false, false, changeEmail);
            listenTo(cfc);
            exitPanel.setContent(cfc.getInitialComponent());
            return;
        } else {
            // cancel button was pressed
            // just go back to the editor - remove modal dialog
            cmcExit.deactivate();
        }
    } else if (source == selectQItemCtrl) {
        cmc.deactivate();
        cleanUp();
        if (event instanceof QItemViewEvent) {
            QItemViewEvent e = (QItemViewEvent) event;
            List<QuestionItemView> items = e.getItemList();
            doSelectInsertionPoint(ureq, CMD_TOOLS_ADD_QPOOL, items);
        }
    } else if (source == importTableWizard) {
        ItemsPackage importPackage = (ItemsPackage) importTableWizard.getRunContext().get("importPackage");
        getWindowControl().pop();
        cleanUp();
        if (event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
            doSelectInsertionPoint(ureq, CMD_TOOLS_ADD_QPOOL, importPackage);
        }
    } else if (createConvertedTestController == source) {
        cmc.deactivate();
        if (event == Event.DONE_EVENT) {
            showInfo("test.converted");
            RepositoryEntry convertedEntry = createConvertedTestController.getAddedEntry();
            String businessPath = "[RepositoryEntry:" + convertedEntry.getKey() + "]";
            NewControllerFactory.getInstance().launch(businessPath, ureq, getWindowControl());
        }
        cleanUp();
    } else if (source == insertCtrl) {
        // catch insert operations
        cmc.deactivate();
        if (event == Event.DONE_EVENT) {
            TreePosition tp = insertCtrl.getInsertPosition();
            if (tp != null) {
                doInsert(ureq, tp, insertCtrl.getUserObject());
                updateWarning();
            }
        }
        cleanUp();
    } else if (source == moveCtrl) {
        cmc.deactivate();
        if (Event.DONE_EVENT == event) {
            TreePosition tp = moveCtrl.getInsertPosition();
            if (tp != null) {
                doMove(tp);
                // force rerendering for ajax mode
                menuTree.setDirty(true);
                updateWarning();
            }
        }
        cleanUp();
    } else if (source == copyCtrl) {
        cmc.deactivate();
        if (Event.DONE_EVENT == event) {
            TreePosition tp = copyCtrl.getInsertPosition();
            if (tp != null) {
                doCopy(ureq, tp);
                updateWarning();
            }
        }
        cleanUp();
    }
}
Also used : GenericQtiNode(org.olat.ims.qti.editor.tree.GenericQtiNode) RepositoryEntry(org.olat.repository.RepositoryEntry) ItemsPackage(org.olat.ims.qti.questionimport.ItemsPackage) TreePosition(org.olat.core.gui.components.tree.TreePosition) Memento(org.olat.core.util.memento.Memento) QTIChangeLogMessage(org.olat.ims.qti.QTIChangeLogMessage) ContactFormController(org.olat.modules.co.ContactFormController) QItemViewEvent(org.olat.modules.qpool.ui.events.QItemViewEvent) Event(org.olat.core.gui.control.Event) QItemViewEvent(org.olat.modules.qpool.ui.events.QItemViewEvent) QuestionItemView(org.olat.modules.qpool.QuestionItemView)

Aggregations

ItemsPackage (org.olat.ims.qti.questionimport.ItemsPackage)8 UserRequest (org.olat.core.gui.UserRequest)4 Event (org.olat.core.gui.control.Event)4 WindowControl (org.olat.core.gui.control.WindowControl)4 Step (org.olat.core.gui.control.generic.wizard.Step)4 StepRunnerCallback (org.olat.core.gui.control.generic.wizard.StepRunnerCallback)4 StepsMainRunController (org.olat.core.gui.control.generic.wizard.StepsMainRunController)4 StepsRunContext (org.olat.core.gui.control.generic.wizard.StepsRunContext)4 GenericQtiNode (org.olat.ims.qti.editor.tree.GenericQtiNode)4 ItemAndMetadata (org.olat.ims.qti.questionimport.ItemAndMetadata)4 QuestionItemView (org.olat.modules.qpool.QuestionItemView)4 QItemViewEvent (org.olat.modules.qpool.ui.events.QItemViewEvent)4 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 TreePosition (org.olat.core.gui.components.tree.TreePosition)2 ContactList (org.olat.core.util.mail.ContactList)2 Memento (org.olat.core.util.memento.Memento)2 QTIChangeLogMessage (org.olat.ims.qti.QTIChangeLogMessage)2 ItemNode (org.olat.ims.qti.editor.tree.ItemNode)2