Permalink
Browse files

Backport to current devel branch

  • Loading branch information...
Egil Moeller
Egil Moeller committed Apr 26, 2012
1 parent 63f4ce4 commit 0bbd865a0d9b6787d055021d13cc871f3dc12c1f
Showing with 32 additions and 1 deletion.
  1. +32 −1 hooks.js
View
@@ -72,7 +72,7 @@ exports.createCopy = function (oldPadId, newPadId, cloneRevNum, cb) {
cb();
},
function (cb) {
- readOnlyManager.getIds(oldPadId, function(err, value) {
+ exports.getIds(oldPadId, function(err, value) {
if(ERR(err, cb)) return;
oldPadId = value.padId;
cb();
@@ -190,3 +190,34 @@ exports.getRevisionText = function(pad, r, optInfoObj, cb) {
cb(null, internalText.slice(0, -1));
});
}
+
+
+/**
+ * returns a the padId and readonlyPadId in an object for any id
+ * @param {String} padIdOrReadonlyPadId read only id or real pad id
+ */
+exports.getIds = function(padIdOrReadonlyPadId, callback) {
+ var handleRealPadId = function () {
+ readOnlyManager.getReadOnlyId(padIdOrReadonlyPadId, function (err, value) {
+ callback(null, {
+ readOnlyPadId: value,
+ padId: padIdOrReadonlyPadId,
+ readonly: false
+ });
+ });
+ }
+
+ if (padIdOrReadonlyPadId.indexOf("r.") != 0)
+ return handleRealPadId();
+
+ readOnlyManager.getPadId(padIdOrReadonlyPadId, function (err, value) {
+ if(ERR(err, callback)) return;
+ if (value == null)
+ return handleRealPadId();
+ callback(null, {
+ readOnlyPadId: padIdOrReadonlyPadId,
+ padId: value,
+ readonly: true
+ });
+ });
+}

0 comments on commit 0bbd865

Please sign in to comment.