Search in sources :

Example 21 with JSCommand

use of org.olat.core.gui.control.winmgr.JSCommand in project openolat by klemens.

the class ShareLinkController method event.

@Override
protected void event(UserRequest ureq, Component source, Event event) {
    UserSession usess = ureq.getUserSession();
    if (source == shareLinkVC && "setLandingPage".equals(event.getCommand()) && usess != null && usess.isAuthenticated()) {
        HistoryPoint p = usess.getLastHistoryPoint();
        if (p != null && StringHelper.containsNonWhitespace(p.getBusinessPath())) {
            List<ContextEntry> ces = p.getEntries();
            String landingPage = BusinessControlFactory.getInstance().getAsURIString(ces, true);
            int start = landingPage.indexOf("/url/");
            if (start != -1) {
                // start with / after /url
                landingPage = landingPage.substring(start + 4);
            }
            // update user prefs
            Preferences prefs = usess.getGuiPreferences();
            prefs.put(WindowManager.class, "landing-page", landingPage);
            prefs.save();
            getWindowControl().getWindowBackOffice().sendCommandTo(new JSCommand("showInfoBox(\"" + translate("info.header") + "\",\"" + translate("landingpage.set.message") + "\");"));
        }
    }
}
Also used : UserSession(org.olat.core.util.UserSession) JSCommand(org.olat.core.gui.control.winmgr.JSCommand) Preferences(org.olat.core.util.prefs.Preferences) HistoryPoint(org.olat.core.id.context.HistoryPoint) ContextEntry(org.olat.core.id.context.ContextEntry) HistoryPoint(org.olat.core.id.context.HistoryPoint)

Example 22 with JSCommand

use of org.olat.core.gui.control.winmgr.JSCommand in project openolat by klemens.

the class BaseFullWebappController method removeBodyCssClass.

/**
 * removes the given css-Classname from the OLAT body-tag
 *
 * @param cssClass
 *            the name of a css-Class
 */
@Override
public void removeBodyCssClass(String cssClass) {
    // sets class for full page refreshes
    bodyCssClasses.remove(cssClass);
    // only relevant in AJAX mode
    JSCommand jsc = new JSCommand("try { jQuery('#o_body').removeClass('" + cssClass + "'); } catch(e){if(window.console) console.log(e) }");
    getWindowControl().getWindowBackOffice().sendCommandTo(jsc);
}
Also used : JSCommand(org.olat.core.gui.control.winmgr.JSCommand)

Example 23 with JSCommand

use of org.olat.core.gui.control.winmgr.JSCommand in project openolat by klemens.

the class BaseFullWebappController method setBodyDataResource.

/**
 * Helper method to set data-" attributes to the body element in the DOM.
 * Using the data attributes it is possible to implement css styles specific
 * to certain areas (sites, groups, courses) of for specific course id's.
 * The data attributes are removed if null
 *
 * @param restype The resource type or NULL if n.a.
 * @param resid The resource ID that matchtes the restype or NULL if n.a.
 * @param repoentryid the repository entry ID if available or NULL if n.a.
 */
private void setBodyDataResource(String restype, String resid, String repoentryid) {
    StringBuilder sb = new StringBuilder();
    sb.append("try {var oobody = jQuery('body');");
    // 'CourseModule' and groups 'BusinessGroup'
    if (restype == null) {
        sb.append("oobody.removeAttr('data-restype');");
    } else {
        sb.append("oobody.attr('data-restype','");
        sb.append(Formatter.escapeDoubleQuotes(restype));
        sb.append("');");
    }
    // course/repo entry id)
    if (resid == null) {
        sb.append("oobody.removeAttr('data-resid');");
    } else {
        sb.append("oobody.attr('data-resid','");
        sb.append(Formatter.escapeDoubleQuotes(resid));
        sb.append("');");
    }
    // (not for sites or groups)
    if (repoentryid == null) {
        sb.append("oobody.removeAttr('data-repoid');");
    } else {
        sb.append("oobody.attr('data-repoid','");
        sb.append(Formatter.escapeDoubleQuotes(repoentryid));
        sb.append("');");
    }
    sb.append("oobody=null;}catch(e){}");
    JSCommand jsc = new JSCommand(sb.toString());
    WindowControl wControl = getWindowControl();
    if (wControl != null && wControl.getWindowBackOffice() != null) {
        wControl.getWindowBackOffice().sendCommandTo(jsc);
    }
}
Also used : JSCommand(org.olat.core.gui.control.winmgr.JSCommand) WindowControl(org.olat.core.gui.control.WindowControl)

Example 24 with JSCommand

use of org.olat.core.gui.control.winmgr.JSCommand in project openolat by klemens.

the class EditorMainController method doInsert.

private void doInsert(UserRequest ureq, CourseNode newNode) {
    menuTree.setSelectedNodeId(newNode.getIdent());
    // update the current node in the editor course environment
    euce.getCourseEditorEnv().setCurrentCourseNodeId(newNode.getIdent());
    euce.getCourseEditorEnv().validateCourse();
    StatusDescription[] courseStatus = euce.getCourseEditorEnv().getCourseStatus();
    updateCourseStatusMessages(getLocale(), courseStatus);
    initNodeEditor(ureq, newNode);
    // do logging
    ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_EDITOR_NODE_CREATED, getClass(), LoggingResourceable.wrap(newNode));
    // Resize layout columns to make all nodes viewable in the menu column
    JSCommand resizeCommand = new JSCommand("try { OPOL.adjustHeight(); } catch(e) {if(window.console) console.log(e); }");
    getWindowControl().getWindowBackOffice().sendCommandTo(resizeCommand);
}
Also used : JSCommand(org.olat.core.gui.control.winmgr.JSCommand)

Example 25 with JSCommand

use of org.olat.core.gui.control.winmgr.JSCommand in project openolat by klemens.

the class ValidatingVisitor method setTitle.

/**
 * @param title The new title of this window (for browser history)
 */
public void setTitle(Translator translator, String newTitle) {
    this.title = translator.translate("page.appname") + " - " + newTitle;
    StringBuilder sb = new StringBuilder();
    sb.append("document.title = \"");
    sb.append(Formatter.escapeDoubleQuotes(this.title));
    sb.append("\";");
    JSCommand jsc = new JSCommand(sb.toString());
    if (getWindowBackOffice() != null) {
        getWindowBackOffice().sendCommandTo(jsc);
    }
}
Also used : JSCommand(org.olat.core.gui.control.winmgr.JSCommand)

Aggregations

JSCommand (org.olat.core.gui.control.winmgr.JSCommand)26 WindowControl (org.olat.core.gui.control.WindowControl)4 ContextEntry (org.olat.core.id.context.ContextEntry)4 HistoryPoint (org.olat.core.id.context.HistoryPoint)4 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 Command (org.olat.core.gui.control.winmgr.Command)2 ScrollTopCommand (org.olat.core.gui.control.winmgr.ScrollTopCommand)2 UserSession (org.olat.core.util.UserSession)2 Preferences (org.olat.core.util.prefs.Preferences)2 AssessmentItemSession (org.olat.ims.qti21.AssessmentItemSession)2