Show a read only link on the pad
This commit is contained in:
parent
7915390b83
commit
1c1e035bf1
|
@ -23,6 +23,7 @@ var padManager = require("./PadManager");
|
|||
var Changeset = require("./Changeset");
|
||||
var AttributePoolFactory = require("./AttributePoolFactory");
|
||||
var authorManager = require("./AuthorManager");
|
||||
var readOnlyManager = require("./ReadOnlyManager");
|
||||
|
||||
/**
|
||||
* A associative array that translates a session to a pad
|
||||
|
@ -507,6 +508,7 @@ function handleClientReady(client, message)
|
|||
var authorColorId;
|
||||
var pad;
|
||||
var historicalAuthorData = {};
|
||||
var readOnlyId;
|
||||
|
||||
async.series([
|
||||
//get all authordata of this new user
|
||||
|
@ -543,6 +545,14 @@ function handleClientReady(client, message)
|
|||
pad = value;
|
||||
callback(err);
|
||||
});
|
||||
},
|
||||
function(callback)
|
||||
{
|
||||
readOnlyManager.getReadOnlyId(message.padId, function(err, value)
|
||||
{
|
||||
readOnlyId = value;
|
||||
callback(err);
|
||||
});
|
||||
}
|
||||
], callback);
|
||||
});
|
||||
|
@ -627,6 +637,7 @@ function handleClientReady(client, message)
|
|||
},
|
||||
"numConnectedUsers": pad2sessions[message.padId].length,
|
||||
"isProPad": false,
|
||||
"readOnlyId": readOnlyId,
|
||||
"serverTimestamp": new Date().getTime(),
|
||||
"globalPadId": message.padId,
|
||||
"userId": author,
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/**
|
||||
* The ReadOnlyManager manages the database and rendering releated to read only pads
|
||||
*/
|
||||
|
||||
/*
|
||||
* 2011 Peter 'Pita' Martischka
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS-IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var db = require("./db").db;
|
||||
var async = require("async");
|
||||
|
||||
/**
|
||||
* returns a read only id for a pad
|
||||
* @param {String} padId the id of the pad
|
||||
*/
|
||||
exports.getReadOnlyId = function (padId, callback)
|
||||
{
|
||||
var readOnlyId;
|
||||
|
||||
async.waterfall([
|
||||
//check if there is a pad2readonly entry
|
||||
function(callback)
|
||||
{
|
||||
db.get("pad2readonly:" + padId, callback);
|
||||
},
|
||||
function(dbReadOnlyId, callback)
|
||||
{
|
||||
//there is no readOnly Entry in the database, let's create one
|
||||
if(dbReadOnlyId == null)
|
||||
{
|
||||
readOnlyId = randomString(10);
|
||||
|
||||
db.set("pad2readonly:" + padId, readOnlyId);
|
||||
db.set("readonly2pad:" + readOnlyId, padId);
|
||||
}
|
||||
//there is a readOnly Entry in the database, let's take this one
|
||||
else
|
||||
{
|
||||
readOnlyId = dbReadOnlyId;
|
||||
}
|
||||
|
||||
callback();
|
||||
}
|
||||
], function(err)
|
||||
{
|
||||
//return the results
|
||||
callback(err, readOnlyId);
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random String with the given length. Is needed to generate the read only ids
|
||||
*/
|
||||
function randomString(len)
|
||||
{
|
||||
// use only numbers and lowercase letters
|
||||
var pieces = [];
|
||||
for(var i=0;i<len;i++) {
|
||||
pieces.push(Math.floor(Math.random()*36).toString(36).slice(-1));
|
||||
}
|
||||
return pieces.join('');
|
||||
}
|
|
@ -1088,7 +1088,7 @@ a#topbarmaximize {
|
|||
width: 100%;
|
||||
}
|
||||
|
||||
#embed{
|
||||
#embed, #readonly {
|
||||
display:none;
|
||||
position:absolute;
|
||||
top:40px;
|
||||
|
@ -1105,11 +1105,11 @@ padding: 10px;
|
|||
border-radius: 6px;
|
||||
}
|
||||
|
||||
#embedcode{
|
||||
#embedcode, #readonlyUrl {
|
||||
margin-left:10px;
|
||||
}
|
||||
|
||||
#embedinput{
|
||||
#embedinput, #readonlyInput{
|
||||
width:375px;
|
||||
height:24px;
|
||||
display:inline;
|
||||
|
|
|
@ -101,10 +101,18 @@ var padeditbar = (function()
|
|||
else if (cmd == 'embed')
|
||||
{
|
||||
var padurl = document.location;
|
||||
$('#embed').html('<div id="embedcode">Embed code:<input id="embedinput" type="text" value="<iframe src="' + padurl + '" width=500 height=400>"</iframe></div>');
|
||||
$('#embedinput').val("<iframe src='" + padurl + "' width=500 height=400>");
|
||||
self.toogleDropDown("embed");
|
||||
$('#embedinput').focus().select();
|
||||
}
|
||||
else if (cmd == 'readonly')
|
||||
{
|
||||
var basePath = document.location.href.substring(0, document.location.href.indexOf("/p/"));
|
||||
var readonlyLink = basePath + "/ro/" + clientVars.readOnlyId;
|
||||
$('#readonlyInput').val(readonlyLink);
|
||||
self.toogleDropDown("readonly");
|
||||
$('#readonlyInput').focus().select();
|
||||
}
|
||||
else if (cmd == 'save')
|
||||
{
|
||||
padsavedrevs.saveNow();
|
||||
|
@ -150,7 +158,7 @@ var padeditbar = (function()
|
|||
},
|
||||
toogleDropDown: function(moduleName)
|
||||
{
|
||||
var modules = ["embed", "users"];
|
||||
var modules = ["embed", "users", "readonly"];
|
||||
|
||||
//hide all modules
|
||||
if(moduleName == "none")
|
||||
|
|
|
@ -200,8 +200,19 @@ We removed this feature cause its not worth the space it needs in the editbar
|
|||
|
||||
</div>
|
||||
|
||||
<!-- needed? -->
|
||||
<div id="embed"></div>
|
||||
<!-- the embed code -->
|
||||
<div id="embed">
|
||||
<div id="embedcode">
|
||||
Embed code:<input id="embedinput" type="text" value="">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- the embed code -->
|
||||
<div id="readonly">
|
||||
<div id="readonlyUrl">
|
||||
Use this link to share a read-only version of your pad:<input id="readonlyInput" type="text" value="">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- /padeditor -->
|
||||
<div id="modaloverlay">
|
||||
|
|
Loading…
Reference in New Issue