Skip to content

Commit

Permalink
SAK-33240 - Create a user preference panel for CKEditor toolbar type (s…
Browse files Browse the repository at this point in the history
…akaiproject#4698)

* SAK-33240 - Add user preference panel for CKEditor

* SAK-33240 - Support for portal to expose the editor type for ckeditor

* SAK-33240 - Name of property changed during dev, updating docs

* SAK-33240 - Updating strings to better matching names, removing CKEditor
per John A, some other minor comment tweaks

* SAK-33240 - Protect portal variable better (errors in iframe'd tools)
  • Loading branch information
jonespm authored Aug 21, 2017
1 parent f4b98dc commit fed45a6
Show file tree
Hide file tree
Showing 10 changed files with 285 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2380,8 +2380,8 @@
# To show the privacy page, include pref_privacy_title in the preference_pages setting.

# To eliminate a page, explicity set preference.pages and leave the page value out.
# DEFAULT: prefs_noti_title, prefs_timezone_title, prefs_lang_title, prefs_hidden_title
# preference.pages=prefs_noti_title, prefs_timezone_title, prefs_lang_title, prefs_privacy_title, prefs_hidden_title
# DEFAULT: prefs_noti_title, prefs_timezone_title, prefs_lang_title, prefs_hidden_title, prefs_editor_title
# preference.pages=prefs_noti_title, prefs_timezone_title, prefs_lang_title, prefs_privacy_title, prefs_hidden_title, prefs_editor_title

# Should research/collab specific preferences (no syllabus) be displayed?
# DEFAULT: false.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ public interface PreferencesService extends EntityProducer

/** Prefs key under which stuff like the site tab order and hiding is stored. */
static final String SITENAV_PREFS_KEY = "sakai:portal:sitenav";

/** Prefs key under which stuff like the editor preferences stored. */
static final String EDITOR_PREFS_KEY = "sakai:portal:editor";

/** Prefs key under which stuff like the editor typepreferences stored. */
static final String EDITOR_PREFS_TYPE = "editor:type";


/**
* Access a set of preferences associated with this id.
Expand Down
105 changes: 60 additions & 45 deletions library/src/webapp-filtered/editor/ckeditor.launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,53 +206,68 @@ sakai.editor.editors.ckeditor.launch = function(targetId, config, w, h) {
//To add extra plugins outside the plugins directory, add them here! (And in the variable)
(function() {
// SAK-30370 present a nice and simple editor without plugins to the user on a tiny screen.
if (getWidth() < 800) {
ckconfig.toolbar = 'Basic';
//
//Check for the portal variable (Should be defined)
//These are defined in user/user-tool-prefs/tool/src/webapp/prefs/editor.jsp

var detectWidth = true;
if (typeof portal != 'undefined' && typeof portal.editor != 'undefined' && typeof portal.editor.type == 'string') {
if (portal.editor.type == "basic") {
ckconfig.toolbar = "Basic";
detectWidth = false;
}
else if (portal.editor.type == "full") {
ckconfig.toolbar = "Full";
detectWidth = false;
}
}
else {
CKEDITOR.plugins.addExternal('lineutils',basePath+'lineutils/', 'plugin.js');
CKEDITOR.plugins.addExternal('widget',basePath+'widget/', 'plugin.js');
CKEDITOR.plugins.addExternal('iframedialog',basePath+'iframedialog/', 'plugin.js');
CKEDITOR.plugins.addExternal('movieplayer',basePath+'movieplayer/', 'plugin.js');
CKEDITOR.plugins.addExternal('fmath_formula',basePath+'fmath_formula/', 'plugin.js');
CKEDITOR.plugins.addExternal('audiorecorder',basePath+'audiorecorder/', 'plugin.js');
CKEDITOR.plugins.addExternal('contentitem',basePath+'contentitem/', 'plugin.js');
CKEDITOR.plugins.addExternal('image2',basePath+'image2/', 'plugin.js');
CKEDITOR.plugins.addExternal('sakaipreview',basePath+'sakaipreview/', 'plugin.js');
//Autosave has a dependency on notification
CKEDITOR.plugins.addExternal('autosave',webJars+'autosave/8541f541d9985cfd0859c7d8eb6be404afe95a2d/', 'plugin.js');
CKEDITOR.plugins.addExternal('wordcount',webJars+'wordcount/4897cb23a9f2ca7fb6b792add4350fb9e2a1722c/', 'plugin.js');
CKEDITOR.plugins.addExternal('notification',basePath+'notification/', 'plugin.js');
// Accessibility checker has a dependency on balloonpanel
CKEDITOR.plugins.addExternal('balloonpanel',webJars+'balloonpanel/4.6.2/', 'plugin.js');
CKEDITOR.plugins.addExternal('a11ychecker',webJars+'a11ychecker/1.1.0/', 'plugin.js');
/*
To enable after the deadline uncomment these two lines and add atd-ckeditor to toolbar
and to extraPlugins. This also needs extra stylesheets.
See readme for more info http://www.polishmywriting.com/atd-ckeditor/readme.html
You have to actually setup a server or get an API key
Hopefully this will get easier to configure soon.
*/
CKEDITOR.plugins.addExternal('atd-ckeditor',basePath+'atd-ckeditor/', 'plugin.js');
/*
Replace this with your own server if you download it from http://openatd.wordpress.com/
Or you can proxy to the public one, see the page for more information.
*/
//ckconfig.atd_rpc='//localhost/proxy/spellcheck';
//ckconfig.extraPlugins+="atd-ckeditor,";
//ckconfig.contentsCss = [basePath+'atd-ckeditor/atd.css'];

ckconfig.extraPlugins+="sakaipreview,image2,audiorecorder,contentitem,movieplayer,wordcount,fmath_formula,autosave,notification${ckeditor-a11y-extra-plugins}";

// Load FontAwesome CSS in case a user wants to manually add FA markup
ckconfig.contentsCss = [webJars+'fontawesome/4.7.0/css/font-awesome.min.css'];
//If the siteskin is defined, add the print.css
if (sakai.editor.sitePrintSkin) {
ckconfig.contentsCss.push(sakai.editor.sitePrintSkin);
}
CKEDITOR.dtd.$removeEmpty.span = false;
CKEDITOR.dtd.$removeEmpty['i'] = false;

if (detectWidth == true && getWidth() < 800) {
ckconfig.toolbar = 'Basic';
}
//These could be applicable to the basic toolbar
CKEDITOR.plugins.addExternal('lineutils',basePath+'lineutils/', 'plugin.js');
CKEDITOR.plugins.addExternal('widget',basePath+'widget/', 'plugin.js');
CKEDITOR.plugins.addExternal('iframedialog',basePath+'iframedialog/', 'plugin.js');
CKEDITOR.plugins.addExternal('movieplayer',basePath+'movieplayer/', 'plugin.js');
CKEDITOR.plugins.addExternal('fmath_formula',basePath+'fmath_formula/', 'plugin.js');
CKEDITOR.plugins.addExternal('audiorecorder',basePath+'audiorecorder/', 'plugin.js');
CKEDITOR.plugins.addExternal('contentitem',basePath+'contentitem/', 'plugin.js');
CKEDITOR.plugins.addExternal('image2',basePath+'image2/', 'plugin.js');
CKEDITOR.plugins.addExternal('sakaipreview',basePath+'sakaipreview/', 'plugin.js');
//Autosave has a dependency on notification
CKEDITOR.plugins.addExternal('autosave',webJars+'autosave/8541f541d9985cfd0859c7d8eb6be404afe95a2d/', 'plugin.js');
CKEDITOR.plugins.addExternal('wordcount',webJars+'wordcount/4897cb23a9f2ca7fb6b792add4350fb9e2a1722c/', 'plugin.js');
CKEDITOR.plugins.addExternal('notification',basePath+'notification/', 'plugin.js');
// Accessibility checker has a dependency on balloonpanel
CKEDITOR.plugins.addExternal('balloonpanel',webJars+'balloonpanel/4.6.2/', 'plugin.js');
CKEDITOR.plugins.addExternal('a11ychecker',webJars+'a11ychecker/1.1.0/', 'plugin.js');
/*
To enable after the deadline uncomment these two lines and add atd-ckeditor to toolbar
and to extraPlugins. This also needs extra stylesheets.
See readme for more info http://www.polishmywriting.com/atd-ckeditor/readme.html
You have to actually setup a server or get an API key
Hopefully this will get easier to configure soon.
*/
CKEDITOR.plugins.addExternal('atd-ckeditor',basePath+'atd-ckeditor/', 'plugin.js');
/*
Replace this with your own server if you download it from http://openatd.wordpress.com/
Or you can proxy to the public one, see the page for more information.
*/
//ckconfig.atd_rpc='//localhost/proxy/spellcheck';
//ckconfig.extraPlugins+="atd-ckeditor,";
//ckconfig.contentsCss = [basePath+'atd-ckeditor/atd.css'];

ckconfig.extraPlugins+="sakaipreview,image2,audiorecorder,contentitem,movieplayer,wordcount,fmath_formula,autosave,notification${ckeditor-a11y-extra-plugins}";

// Load FontAwesome CSS in case a user wants to manually add FA markup
ckconfig.contentsCss = [webJars+'fontawesome/4.7.0/css/font-awesome.min.css'];
//If the siteskin is defined, add the print.css
if (sakai.editor.sitePrintSkin) {
ckconfig.contentsCss.push(sakai.editor.sitePrintSkin);
}
CKEDITOR.dtd.$removeEmpty.span = false;
CKEDITOR.dtd.$removeEmpty['i'] = false;
})();

CKEDITOR.replace(targetId, ckconfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ public class SkinnableCharonPortal extends HttpServlet implements Portal

private SecurityService securityService = null;

//Get user preferences
private PreferencesService preferencesService;

/**
* Keyword to look for in sakai.properties copyright message to replace
* for the server's time's year for auto-update of Copyright end date
Expand Down Expand Up @@ -1052,12 +1055,16 @@ public PortalRenderContext startPageContext(String siteType, String title,

User currentUser = UserDirectoryService.getCurrentUser();
Role role = site != null && currentUser != null ? site.getUserRole(currentUser.getId()) : null;

Preferences prefs = preferencesService.getPreferences(currentUser.getId());
String editorType = prefs.getProperties(PreferencesService.EDITOR_PREFS_KEY).getProperty(PreferencesService.EDITOR_PREFS_TYPE);

rcontext.put("loggedIn", Boolean.valueOf(currentUser.getId() != null));
rcontext.put("userId", currentUser.getId());
rcontext.put("userEid", currentUser.getEid());
rcontext.put("userType", currentUser.getType());
rcontext.put("userSiteRole", role != null ? role.getId() : "");
rcontext.put("editorType", editorType);

rcontext.put("loggedOutUrl",ServerConfigurationService.getLoggedOutUrl());
rcontext.put("portalPath",ServerConfigurationService.getPortalUrl());
Expand Down Expand Up @@ -1575,8 +1582,6 @@ public void includeBottom(PortalRenderContext rcontext)
String thisUser = SessionManager.getCurrentSessionUserId();

//Get user preferences
PreferencesService preferencesService = (PreferencesService) ComponentManager.get(PreferencesService.class);

Preferences prefs = preferencesService.getPreferences(thisUser);

boolean showServerTime = ServerConfigurationService.getBoolean("portal.show.time", true);
Expand Down Expand Up @@ -1977,6 +1982,8 @@ public void init(ServletConfig config) throws ServletException
portalService = org.sakaiproject.portal.api.cover.PortalService.getInstance();
securityService = (SecurityService) ComponentManager.get("org.sakaiproject.authz.api.SecurityService");
chatHelper = org.sakaiproject.portal.api.cover.PortalChatPermittedHelper.getInstance();
preferencesService = ComponentManager.get(PreferencesService.class);

log.info("init()");

forceContainer = ServerConfigurationService.getBoolean("login.use.xlogin.to.relogin", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
"sitenav": false // This is not allowed in morpheus
},
"pageScriptPath" : "$!{pageScriptPath}",
"editor" : {
"type": "$!{editorType}",
},
"portalCDNQuery" : "$!{portalCDNQuery}"
};
</script>
Expand Down
10 changes: 10 additions & 0 deletions user/user-tool-prefs/tool/src/bundle/user-tool-prefs.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ prefs_lang_title=Language
prefs_title=Preferences
prefs_privacy=Privacy Status
prefs_sites=Sites
prefs_editor=Editor

prefs_site_tab_display_format=Site Tab Display Format

prefs_editor_tab_options=Editor Options

prefs_element_locked=This element can not be placed here. The element underneath is locked.

Expand Down Expand Up @@ -117,6 +121,12 @@ privacy_choice_later=Ask me again later

privacy_change_later_instructions=To change your privacy settings in the future, visit<br />Home > Preferences > Privacy Status

editor_prompt=Default Rich Text Editor toolbar layout
editor_auto=Auto detected based on browser size
editor_basic=Force basic/mobile mode (Limited set of buttons and features)
editor_full=Force full/desktop mode (Full set of buttons, all features)


## SAK-23895:Display full name of course, not just code, in site tab
tabDisplay_prompt=Show tabs as:
tabDisplay_coursecode=Site Title
Expand Down
Loading

0 comments on commit fed45a6

Please sign in to comment.