', {'class': 'cp-app-profile-description-rendered'}).appendTo($block);
+ APP.$descriptionEdit = $();
+ if (APP.readOnly) { return; }
+
+ var button = h('button.btn.btn-primary', [
+ h('i.fa.fa-pencil'),
+ h('span', Messages.profile_addDescription)
+ ]);
+ APP.$descriptionEdit = $(button);
+ var save = h('button.btn.btn-primary', Messages.settings_save);
+ var text = h('textarea');
+ var code = h('div.cp-app-profile-description-code', [
+ text,
+ h('br'),
+ save
+ ]);
+ var div = h('div.cp-app-profile-description-edit', [
+ h('p.cp-app-profile-info', Messages.profile_info),
+ button,
+ code
+ ]);
+ $block.append(div);
+
+ var editor = APP.editor = CodeMirror.fromTextArea(text, {
lineNumbers: true,
lineWrapping: true,
styleActiveLine : true,
@@ -409,25 +388,34 @@ define([
});
var markdownTb = common.createMarkdownToolbar(editor);
- $block.prepend(markdownTb.toolbar);
-
- var onLocal = function () {
- $ok.hide();
- $spinner.show();
- var val = editor.getValue();
- APP.lm.proxy.description = val;
- Realtime.whenRealtimeSyncs(APP.lm.realtime, function () {
- $ok.show();
- $spinner.hide();
- });
- };
+ $(code).prepend(markdownTb.toolbar);
+ $(markdownTb.toolbar).show();
- editor.on('change', onLocal);
+ $(button).click(function () {
+ $(code).show();
+ APP.editor.refresh();
+ $(button).hide();
+ });
+ $(save).click(function () {
+ $(save).hide();
+ APP.module.execCommand('SET', {
+ key: 'description',
+ value: editor.getValue()
+ }, function (data) {
+ APP.updateValues(data);
+ $(code).hide();
+ $(button).show();
+ $(save).show();
+ });
+ });
};
-
- var addPublicKey = function ($container) {
- var $block = $('
', {id: PUBKEY_ID});
- $container.append($block);
+ var refreshDescription = function (data) {
+ var val = Marked(data.description || "");
+ APP.$description.html(val);
+ APP.$descriptionEdit.find('span').text(val === "" ? Messages.profile_addDescription : Messages.profile_editDescription);
+ if (!APP.editor) { return; }
+ APP.editor.setValue(data.description || "");
+ APP.editor.save();
};
var createLeftside = function () {
@@ -438,7 +426,7 @@ define([
$category.append(Messages.profileButton);
};
- var onReady = function () {
+ var init = function () {
APP.$container.find('#'+CREATE_ID).remove();
if (!APP.initialized) {
@@ -447,14 +435,20 @@ define([
var $rightside = $('
', {id: HEADER_RIGHT_ID}).appendTo($header);
addDisplayName($rightside);
addLink($rightside);
+ addFriendRequest($rightside);
addDescription(APP.$rightside);
addViewButton(APP.$rightside);
- addPublicKey(APP.$rightside);
APP.initialized = true;
createLeftside();
}
+ };
- UI.removeLoadingScreen();
+ var updateValues = APP.updateValues = function (data) {
+ refreshAvatar(data);
+ refreshName(data);
+ refreshLink(data);
+ refreshDescription(data);
+ refreshFriendRequest(data);
};
var createToolbar = function () {
@@ -470,6 +464,16 @@ define([
APP.toolbar.$rightside.hide();
};
+ var onEvent = function (obj) {
+ var ev = obj.ev;
+ var data = obj.data;
+ if (ev === 'UPDATE') {
+ console.log('Update');
+ updateValues(data);
+ return;
+ }
+ };
+
nThen(function (waitFor) {
$(waitFor(UI.addLoadingScreen));
SFCommon.create(waitFor(function (c) { APP.common = common = c; }));
@@ -508,6 +512,23 @@ define([
return;
}
+ if (privateData.isOwnProfile) {
+
+ APP.module = common.makeUniversal('profile', {
+ onEvent: onEvent
+ });
+ var execCommand = APP.module.execCommand;
+
+ init();
+
+ console.log('POST SUBSCRIBE');
+ execCommand('SUBSCRIBE', null, function (obj) {
+ updateValues(obj);
+ UI.removeLoadingScreen();
+ });
+ return;
+ }
+
var listmapConfig = {
data: {},
common: common,
@@ -517,6 +538,12 @@ define([
var lm = APP.lm = Listmap.create(listmapConfig);
- lm.proxy.on('ready', onReady);
+ init();
+ lm.proxy.on('ready', function () {
+ updateValues(lm.proxy);
+ UI.removeLoadingScreen();
+ }).on('change', [], function () {
+ updateValues(lm.proxy);
+ });
});
});
diff --git a/www/profile/main.js b/www/profile/main.js
index 3afab9077..92b24b3fc 100644
--- a/www/profile/main.js
+++ b/www/profile/main.js
@@ -43,18 +43,13 @@ define([
// No password for profiles
return void cb(null, Hash.getSecrets('profile', window.location.hash.slice(1)));
}
- var editHash;
nThen(function (waitFor) {
// 2nd case: visiting our own existing profile
Cryptpad.getProfileEditUrl(waitFor(function (hash) {
- editHash = hash;
+ waitFor.abort();
+ return void cb(null, Hash.getSecrets('profile', hash));
}));
}).nThen(function () {
- if (editHash) {
- // No password for profile
- return void cb(null, Hash.getSecrets('profile', editHash));
- }
- // 3rd case: profile creation (create a new random hash, store it later if needed)
if (!Utils.LocalStore.isLoggedIn()) {
// Unregistered users can't create a profile
window.location.href = '/drive/';
@@ -79,6 +74,10 @@ define([
cb(null, secret);
});
};
+ var addData = function (meta, Cryptad, user) {
+ meta.isOwnProfile = !window.location.hash ||
+ window.location.hash.slice(1) === user.profile;
+ };
var addRpc = function (sframeChan, Cryptpad, Utils) {
// Adding a new avatar from the profile: pin it and store it in the object
sframeChan.on('Q_PROFILE_AVATAR_ADD', function (data, cb) {
@@ -100,6 +99,7 @@ define([
getSecrets: getSecrets,
noHash: true, // Don't add the hash in the URL if it doesn't already exist
addRpc: addRpc,
+ addData: addData,
owned: true
});
});