Open calendar URL
parent
9ae482b744
commit
7f01ab3e1a
|
@ -49,6 +49,7 @@ define([
|
|||
};
|
||||
|
||||
var common;
|
||||
var metadataMgr;
|
||||
var sframeChan;
|
||||
|
||||
Messages.calendar = "Calendar"; // XXX
|
||||
|
@ -63,6 +64,7 @@ Messages.calendar_deleteTeamConfirm = "Are you sure you want to delete this cale
|
|||
Messages.calendar_deleteOwned = " It will still be visible for the users it has been shared with.";
|
||||
Messages.calendar_errorNoCalendar = "No editable calendar selected!";
|
||||
Messages.calendar_myCalendars = "My calendars";
|
||||
Messages.calendar_tempCalendar = "Temp calendar";
|
||||
|
||||
var onCalendarsUpdate = Util.mkEvent();
|
||||
|
||||
|
@ -223,7 +225,6 @@ Messages.calendar_myCalendars = "My calendars";
|
|||
};
|
||||
|
||||
var makeTeamSelector = function () {
|
||||
var metadataMgr = common.getMetadataMgr();
|
||||
var privateData = metadataMgr.getPrivateData();
|
||||
var keys = Object.keys(privateData.teams);
|
||||
if (!keys.length) { return; }
|
||||
|
@ -347,36 +348,41 @@ Messages.calendar_myCalendars = "My calendars";
|
|||
});
|
||||
return true;
|
||||
}
|
||||
}, {
|
||||
tag: 'a',
|
||||
attributes: {
|
||||
'class': 'fa fa-trash-o',
|
||||
},
|
||||
content: h('span', Messages.kanban_delete),
|
||||
action: function (e) {
|
||||
e.stopPropagation();
|
||||
var cal = APP.calendars[id];
|
||||
var key = Messages.calendar_deleteConfirm;
|
||||
var teams = (cal && cal.teams) || [];
|
||||
if (teams.length === 1 && teams[0] !== 1) {
|
||||
key = Messages.calendar_deleteTeamConfirm;
|
||||
}
|
||||
if (cal.owned) {
|
||||
key += Messages.calendar_deleteOwned;
|
||||
}
|
||||
UI.confirm(Messages.calendar_deleteConfirm, function (yes) {
|
||||
deleteCalendar({
|
||||
id: id,
|
||||
teamId: teamId,
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
UI.warn(Messages.error);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}];
|
||||
var privateData = metadataMgr.getPrivateData();
|
||||
var cantRemove = teamId === 0 || (teamId !== 1 && privateData.teams[teamId].viewer);
|
||||
if (!cantRemove) {
|
||||
options.push({
|
||||
tag: 'a',
|
||||
attributes: {
|
||||
'class': 'fa fa-trash-o',
|
||||
},
|
||||
content: h('span', Messages.kanban_delete),
|
||||
action: function (e) {
|
||||
e.stopPropagation();
|
||||
var cal = APP.calendars[id];
|
||||
var key = Messages.calendar_deleteConfirm;
|
||||
var teams = (cal && cal.teams) || [];
|
||||
if (teams.length === 1 && teams[0] !== 1) {
|
||||
key = Messages.calendar_deleteTeamConfirm;
|
||||
}
|
||||
if (cal.owned) {
|
||||
key += Messages.calendar_deleteOwned;
|
||||
}
|
||||
UI.confirm(Messages.calendar_deleteConfirm, function (yes) {
|
||||
deleteCalendar({
|
||||
id: id,
|
||||
teamId: teamId,
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
UI.warn(Messages.error);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
var dropdownConfig = {
|
||||
text: '',
|
||||
options: options, // Entries displayed in the menu
|
||||
|
@ -479,15 +485,21 @@ Messages.calendar_myCalendars = "My calendars";
|
|||
var $calendars = APP.$calendars = $(calendars).appendTo($container);
|
||||
onCalendarsUpdate.reg(function () {
|
||||
$calendars.empty();
|
||||
var metadataMgr = common.getMetadataMgr();
|
||||
var privateData = metadataMgr.getPrivateData();
|
||||
var filter = function (teamId) {
|
||||
return Object.keys(APP.calendars || {}).filter(function (id) {
|
||||
var cal = APP.calendars[id] || {};
|
||||
var teams = cal.teams || [];
|
||||
return teams.indexOf(teamId || 1) !== -1;
|
||||
return teams.indexOf(typeof(teamId) !== "undefined" ? teamId : 1) !== -1;
|
||||
});
|
||||
};
|
||||
var tempCalendars = filter(0);
|
||||
if (tempCalendars.length) {
|
||||
APP.$calendars.append(h('div.cp-calendar-team', [
|
||||
h('span', Messages.calendar_tempCalendar)
|
||||
]));
|
||||
makeCalendarEntry(tempCalendars[0], 0);
|
||||
}
|
||||
var myCalendars = filter(1);
|
||||
if (myCalendars.length) {
|
||||
APP.$calendars.append(h('div.cp-calendar-team', [
|
||||
|
@ -640,11 +652,10 @@ Messages.calendar_myCalendars = "My calendars";
|
|||
sframeChan.onReady(waitFor());
|
||||
}).nThen(function (/*waitFor*/) {
|
||||
createToolbar();
|
||||
var metadataMgr = common.getMetadataMgr();
|
||||
metadataMgr = common.getMetadataMgr();
|
||||
var privateData = metadataMgr.getPrivateData();
|
||||
var user = metadataMgr.getUserData();
|
||||
|
||||
|
||||
// Fix flatpickr selection
|
||||
var MutationObserver = window.MutationObserver;
|
||||
var onFlatPickr = function (el) {
|
||||
|
@ -730,7 +741,7 @@ Messages.calendar_myCalendars = "My calendars";
|
|||
onEvent: onEvent
|
||||
});
|
||||
APP.module.execCommand('SUBSCRIBE', null, function (obj) {
|
||||
if (obj.empty) {
|
||||
if (obj.empty && !privateData.calendarHash) {
|
||||
// No calendar yet, create one
|
||||
newCalendar({
|
||||
teamId: 1,
|
||||
|
@ -743,7 +754,14 @@ Messages.calendar_myCalendars = "My calendars";
|
|||
});
|
||||
return;
|
||||
}
|
||||
// XXX build UI
|
||||
if (privateData.calendarHash) {
|
||||
APP.module.execCommand('OPEN', {
|
||||
hash: privateData.hashes.editHash || privateData.hashes.viewHash,
|
||||
password: privateData.password
|
||||
}, function (obj) {
|
||||
console.error(obj); // XXX
|
||||
});
|
||||
}
|
||||
makeCalendar();
|
||||
UI.removeLoadingScreen();
|
||||
});
|
||||
|
|
|
@ -12,19 +12,14 @@ define([
|
|||
}).nThen(function (waitFor) {
|
||||
SFCommonO.initIframe(waitFor);
|
||||
}).nThen(function (/*waitFor*/) {
|
||||
var getSecrets = function (Cryptpad, Utils, cb) {
|
||||
// XXX open calendar from URL
|
||||
};
|
||||
var addData = function (meta, Cryptpad, user) {
|
||||
// XXX flag when opening URL
|
||||
meta.isOwnProfile = !window.location.hash ||
|
||||
window.location.hash.slice(1) === user.profile;
|
||||
meta.calendarHash = Boolean(window.location.hash);
|
||||
};
|
||||
SFCommonO.start({
|
||||
//getSecrets: getSecrets,
|
||||
//noHash: true, // Don't add the hash in the URL if it doesn't already exist
|
||||
//addRpc: addRpc,
|
||||
//addData: addData,
|
||||
addData: addData,
|
||||
//owned: true,
|
||||
noRealtime: true,
|
||||
cache: true,
|
||||
|
|
|
@ -595,7 +595,7 @@
|
|||
return '#' + getColor().toString(16) +
|
||||
getColor().toString(16) +
|
||||
getColor().toString(16);
|
||||
};
|
||||
};
|
||||
|
||||
if (typeof(module) !== 'undefined' && module.exports) {
|
||||
module.exports = Util;
|
||||
|
|
|
@ -157,7 +157,7 @@ ctx.calendars[channel] = {
|
|||
|
||||
|
||||
var parsed = Hash.parsePadUrl(data.href || data.roHref);
|
||||
var secret = Hash.getSecrets('calendar', parsed.hash);
|
||||
var secret = Hash.getSecrets('calendar', parsed.hash, data.password);
|
||||
var crypto = Crypto.createEncryptor(secret.keys);
|
||||
|
||||
c.hashes.viewHash = Hash.getViewHashFromKeys(secret);
|
||||
|
@ -207,6 +207,7 @@ ctx.calendars[channel] = {
|
|||
if (obj && typeof(obj.isNew) === "boolean") {
|
||||
if (obj.isNew) {
|
||||
onDeleted();
|
||||
cb({error: 'EDELETED'});
|
||||
waitFor.abort();
|
||||
return;
|
||||
}
|
||||
|
@ -216,7 +217,7 @@ ctx.calendars[channel] = {
|
|||
// Set the owners as the first store opening it. We don't know yet if it's a new or
|
||||
// existing calendar. "owners' will be ignored if the calendar already exists.
|
||||
var edPublic;
|
||||
if (teamId === 1) {
|
||||
if (teamId === 1 || !teamId) {
|
||||
edPublic = ctx.store.proxy.edPublic;
|
||||
} else {
|
||||
var teams = ctx.store.modules.team && ctx.store.modules.team.getTeamsData();
|
||||
|
@ -238,7 +239,6 @@ ctx.calendars[channel] = {
|
|||
onRejected: ctx.Store && ctx.Store.onRejected
|
||||
};
|
||||
|
||||
console.error(channel, config);
|
||||
var lm = Listmap.create(config);
|
||||
c.lm = lm;
|
||||
var proxy = c.proxy = lm.proxy;
|
||||
|
@ -304,7 +304,6 @@ ctx.calendars[channel] = {
|
|||
if (!teams) { return; }
|
||||
Object.keys(teams).forEach(function (id) {
|
||||
var store = getStore(ctx, id);
|
||||
console.log(store);
|
||||
findFromStore(store);
|
||||
});
|
||||
};
|
||||
|
@ -325,6 +324,23 @@ ctx.calendars[channel] = {
|
|||
});
|
||||
};
|
||||
|
||||
var openCalendar = function (ctx, data, cId, cb) {
|
||||
var secret = Hash.getSecrets('calendar', data.hash, data.password);
|
||||
|
||||
var cal = {
|
||||
href: Hash.hashToHref(Hash.getEditHashFromKeys(secret), 'calendar'),
|
||||
roHref: Hash.hashToHref(Hash.getViewHashFromKeys(secret), 'calendar'),
|
||||
channel: secret.channel,
|
||||
color: Util.getRandomColor(),
|
||||
title: '...'
|
||||
};
|
||||
openChannel(ctx, {
|
||||
storeId: 0,
|
||||
data: cal,
|
||||
noStore: true,
|
||||
isNew: true
|
||||
}, cb);
|
||||
};
|
||||
var addCalendar = function (ctx, data, cId, cb) {
|
||||
var store = getStore(ctx, data.teamId);
|
||||
if (!store) { return void cb({error: "NO_STORE"}); }
|
||||
|
@ -515,6 +531,12 @@ ctx.calendars[channel] = {
|
|||
if (cmd === 'SUBSCRIBE') {
|
||||
return void subscribe(ctx, data, clientId, cb);
|
||||
}
|
||||
if (cmd === 'OPEN') {
|
||||
ctx.Store.onReadyEvt.reg(function () {
|
||||
openCalendar(ctx, data, clientId, cb);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (cmd === 'ADD') {
|
||||
if (ctx.store.offline) { return void cb({error: 'OFFLINE'}); }
|
||||
return void addCalendar(ctx, data, clientId, cb);
|
||||
|
|
|
@ -571,7 +571,7 @@ define([
|
|||
var defaultTitle = Utils.UserObject.getDefaultName(parsed);
|
||||
var edPublic, curvePublic, notifications, isTemplate;
|
||||
var settings = {};
|
||||
var isSafe = ['debug', 'profile', 'drive', 'teams'].indexOf(currentPad.app) !== -1;
|
||||
var isSafe = ['debug', 'profile', 'drive', 'teams', 'calendar'].indexOf(currentPad.app) !== -1;
|
||||
|
||||
var isDeleted = isNewFile && currentPad.hash.length > 0;
|
||||
if (isDeleted) {
|
||||
|
|
Loading…
Reference in New Issue