Added global settings for authorship-colors, line-numbers and font-type

This commit is contained in:
mluto 2013-01-27 14:54:43 +01:00
parent e811037300
commit 12fee1a46b
8 changed files with 156 additions and 10 deletions

View file

@ -33,6 +33,7 @@
"pad.settings.fontType.normal": "Normal",
"pad.settings.fontType.monospaced": "Monospace",
"pad.settings.globalView": "Global View",
"pad.settings.globalView.warning": "Warning: This will effect everyones view of this pad.",
"pad.settings.language": "Language:",
"pad.importExport.import_export": "Import/Export",
"pad.importExport.import": "Upload any text file or document",

View file

@ -39,6 +39,7 @@ var Pad = function Pad(id) {
this.chatHead = -1;
this.publicStatus = false;
this.passwordHash = null;
this.viewSettings = {};
this.id = id;
this.savedRevisions = [];
};
@ -57,6 +58,14 @@ Pad.prototype.getPublicStatus = function getPublicStatus() {
return this.publicStatus;
};
Pad.prototype.getViewSettings = function getViewSettings() {
return this.viewSettings;
};
Pad.prototype.getViewSetting = function getViewSettings(setting) {
return this.viewSettings[setting];
};
Pad.prototype.appendRevision = function appendRevision(aChangeset, author) {
if(!author)
author = '';
@ -471,6 +480,16 @@ Pad.prototype.setPublicStatus = function setPublicStatus(publicStatus) {
this.saveToDatabase();
};
Pad.prototype.setViewSettings = function setPublicStatus(viewSettings) {
this.viewSettings = viewSettings;
this.saveToDatabase();
};
Pad.prototype.setViewSetting = function setPublicStatus(setting, value) {
this.viewSettings[setting] = value;
this.saveToDatabase();
};
Pad.prototype.setPassword = function setPassword(password) {
this.passwordHash = password == null ? null : hash(password, generateSalt());
this.saveToDatabase();

View file

@ -209,6 +209,8 @@ exports.handleMessage = function(client, message)
handleGetChatMessages(client, message);
} else if (message.data.type == "SAVE_REVISION") {
handleSaveRevisionMessage(client, message);
} else if (message.data.type == "GLOBAL_SETTING_CHANGED") {
handleGlobalSettingChangedMessage(client, message);
} else if (message.data.type == "CLIENT_MESSAGE" &&
message.data.payload.type == "suggestUserName") {
handleSuggestUserName(client, message);
@ -276,6 +278,55 @@ function handleSaveRevisionMessage(client, message){
});
}
/**
* Handles a global setting changed message
* @param client the client that send this message
* @param message the message from the client
*/
function handleGlobalSettingChangedMessage(client, message){
var padId = sessioninfos[client.id].padId;
var userId = sessioninfos[client.id].author;
if(message.data.setting == null)
{
messageLogger.warn("Dropped message, GlobalSettingChanged Message has no setting!");
return;
}
if(message.data.value == null)
{
messageLogger.warn("Dropped message, GlobalSettingChanged Message has no value!");
return;
}
var setting = message.data.setting;
var value = message.data.value;
// check for illegal values
if(setting != "showLineNumbers" && setting != "showAuthorColors" && setting != "useMonospaceFont")
{
messageLogger.warn("Dropped message, GlobalSettingChanged Message has an invalid setting!");
return;
}
if(value != true && value != false)
{
messageLogger.warn("Dropped message, GlobalSettingChanged Message has an invalid value!");
return;
}
padManager.getPad(padId, function(err, pad)
{
if(ERR(err)) return;
// save changed value to the db
pad.setViewSetting(setting, value);
// tell the users that a setting has been changed
for (var i in pad2sessions[padId]) {
socketio.sockets.sockets[pad2sessions[padId][i]].json.send(message);
}
});
}
/**
* Handles a custom message (sent via HTTP API request)
*
@ -1054,6 +1105,7 @@ function handleClientReady(client, message)
"plugins": plugins.plugins,
"parts": plugins.parts,
},
"viewSettings": pad.getViewSettings(),
"initialChangesets": [] // FIXME: REMOVE THIS SHIT
}

View file

@ -807,6 +807,10 @@ input[type=checkbox] {
display: none;
z-index: 500;
}
#globalViewWarning {
color: red;
font-size: 10px;
}
.stickyChat {
background-color: #f1f1f1 !important;
right: 0px !important;

View file

@ -424,6 +424,10 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
else // there are still more messages, re-show the load-button
$("#chatloadmessagesbutton").css("display", "block");
}
else if (msg.type == "GLOBAL_SETTING_CHANGED")
{
pad.changeViewOption(msg.setting, msg.value, true);
}
else if (msg.type == "SERVER_MESSAGE")
{
callbacks.onServerMessage(msg.payload);
@ -444,6 +448,14 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
});
}
function changeGlobalSetting(setting, value)
{
sendMessage({ "type" : "GLOBAL_SETTING_CHANGED",
"setting" : setting,
"value" : value
});
}
function tellAceActiveAuthorInfo(userInfo)
{
tellAceAuthorInfo(userInfo.userId, userInfo.colorId);
@ -675,7 +687,8 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
getMissedChanges: getMissedChanges,
callWhenNotCommitting: callWhenNotCommitting,
addHistoricalAuthors: tellAceAboutHistoricalAuthors,
setChannelState: setChannelState
setChannelState: setChannelState,
changeGlobalSetting: changeGlobalSetting
};
$(document).ready(setUpSocket);

View file

@ -355,7 +355,7 @@ function handshake()
// If the noColors value is set to true then we need to hide the background colors on the ace spans
if (settings.noColors == true)
{
pad.changeViewOption('noColors', true);
pad.changeViewOption('showAuthorColors', true);
}
if (settings.rtlIsTrue == true)
@ -368,6 +368,29 @@ function handshake()
{
pad.changeViewOption('useMonospaceFont', true);
}
// settings which are global for all users of this pad, these overwrite
// all settings set in cookies or by the user. They will also get updated
// via a collabClient-message when they're changed later.
var viewSettings = clientVars.viewSettings;
// check if they are set, if they are overwrite whatever is set by the user
if (typeof(viewSettings.showLineNumbers) != "undefined")
{
pad.changeViewOption('showLineNumbers', viewSettings.showLineNumbers, true);
$("#options-global-linenoscheck").prop('checked', viewSettings.showLineNumbers);
}
if (typeof(viewSettings.showAuthorColors) != "undefined")
{
pad.changeViewOption('showAuthorColors', viewSettings.showAuthorColors, true);
$("#options-global-colorscheck").prop('checked', viewSettings.showAuthorColors);
}
if (typeof(viewSettings.useMonospaceFont) != "undefined")
{
pad.changeViewOption('useMonospaceFont', viewSettings.useMonospaceFont, true);
$("#global-viewfontmenu").val(viewSettings.useMonospaceFont ? "monospace" : "normal");
}
// if the globalUserName value is set we need to tell the server and the client about the new authorname
if (settings.globalUserName !== false)
{
@ -630,15 +653,15 @@ var pad = {
changedBy: pad.myUserInfo.name || "unnamed"
});
},
changeViewOption: function(key, value)
changeViewOption: function(key, value, global)
{
var options = {
view: {}
};
options.view[key] = value;
pad.handleOptionsChange(options);
pad.handleOptionsChange(options, global);
},
handleOptionsChange: function(opts)
handleOptionsChange: function(opts, global)
{
// opts object is a full set of options or just
// some options to change
@ -652,7 +675,7 @@ var pad = {
{
pad.padOptions.view[k] = opts.view[k];
}
padeditor.setViewOptions(pad.padOptions.view);
padeditor.setViewOptions(pad.padOptions.view, global);
}
if (opts.guestPolicy)
{

View file

@ -62,6 +62,7 @@ var padeditor = (function()
},
initViewOptions: function()
{
// my view
padutils.bindCheckboxChange($("#options-linenoscheck"), function()
{
pad.changeViewOption('showLineNumbers', padutils.getCheckbox($("#options-linenoscheck")));
@ -76,6 +77,20 @@ var padeditor = (function()
pad.changeViewOption('useMonospaceFont', $("#viewfontmenu").val() == 'monospace');
});
// global view
padutils.bindCheckboxChange($("#options-global-linenoscheck"), function()
{
pad.collabClient.changeGlobalSetting("showLineNumbers", $("#options-global-linenoscheck").prop('checked'));
});
padutils.bindCheckboxChange($("#options-global-colorscheck"), function()
{
pad.collabClient.changeGlobalSetting("showAuthorColors", $("#options-global-colorscheck").prop('checked'));
});
$("#global-viewfontmenu").change(function()
{
pad.collabClient.changeGlobalSetting("useMonospaceFont", $("#global-viewfontmenu").val() == 'monospace');
});
html10n.bind('localized', function() {
$("#languagemenu").val(html10n.getLanguage());
// translate the value of 'unnamed' and 'Enter your name' textboxes in the userlist
@ -95,7 +110,7 @@ var padeditor = (function()
window.html10n.localize([$("#languagemenu").val(), 'en']);
});
},
setViewOptions: function(newOptions)
setViewOptions: function(newOptions, global)
{
function getOption(key, defaultValue)
{
@ -113,10 +128,12 @@ var padeditor = (function()
v = getOption('showLineNumbers', true);
self.ace.setProperty("showslinenumbers", v);
if(!global)
padutils.setCheckbox($("#options-linenoscheck"), v);
v = getOption('showAuthorColors', true);
self.ace.setProperty("showsauthorcolors", v);
if(!global)
padutils.setCheckbox($("#options-colorscheck"), v);
// Override from parameters if true
if (settings.noColors !== false)
@ -124,6 +141,7 @@ var padeditor = (function()
v = getOption('useMonospaceFont', false);
self.ace.setProperty("textface", (v ? "monospace" : "Arial, sans-serif"));
if(!global)
$("#viewfontmenu").val(v ? "monospace" : "normal");
},
dispose: function()

View file

@ -249,6 +249,22 @@
<div class="column">
<% e.begin_block("globalSettings"); %>
<h2 data-l10n-id="pad.settings.globalView"></h2>
<p>
<input type="checkbox" id="options-global-colorscheck">
<label for="options-global-colorscheck" data-l10n-id="pad.settings.colorcheck"></label>
</p>
<p>
<input type="checkbox" id="options-global-linenoscheck" checked>
<label for="options-global-linenoscheck" data-l10n-id="pad.settings.linenocheck"></label>
</p>
<% e.begin_block("globalSettings.dropdowns"); %>
<label for="global-viewfontmenu" data-l10n-id="pad.settings.fontType"></label>
<select id="global-viewfontmenu">
<option value="normal" data-l10n-id="pad.settings.fontType.normal"></option>
<option value="monospace" data-l10n-id="pad.settings.fontType.monospaced"></option>
</select>
<% e.end_block(); %>
<p data-l10n-id="pad.settings.globalView.warning" id="globalViewWarning"></p>
<% e.end_block(); %>
</div>
</div>