').appendTo($block);
@@ -318,14 +352,30 @@ define([
}
};
APP.FM = common.createFileManager(fmConfig);
+ var accepted = ".gif,.jpg,.jpeg,.png";
var data = {
FM: APP.FM,
filter: function (file) {
var sizeMB = Util.bytesToMegabytes(file.size);
var type = file.type;
- return sizeMB <= 0.5 && allowedMediaTypes.indexOf(type) !== -1;
+ // We can't resize .gif so we have to display an error if it is too big
+ if (sizeMB > AVATAR_SIZE_LIMIT && type === 'image/gif') {
+ UI.log(Messages._getKey('profile_uploadSizeError', [
+ Messages._getKey('formattedMB', [AVATAR_SIZE_LIMIT])
+ ]));
+ return false;
+ }
+ // Display an error if the image type is not allowed
+ if (allowedMediaTypes.indexOf(type) === -1) {
+ UI.log(Messages._getKey('profile_uploadTypeError', [
+ accepted.split(',').join(', ')
+ ]));
+ return false;
+ }
+ return true;
},
- accept: ".gif,.jpg,.jpeg,.png"
+ transformer: transformAvatar,
+ accept: accepted
};
var $upButton = common.createButton('upload', false, data);
$upButton.text(Messages.profile_upload);
@@ -395,15 +445,6 @@ define([
var onReady = function () {
APP.$container.find('#'+CREATE_ID).remove();
- /*var obj = APP.lm && APP.lm.proxy;
- if (!APP.readOnly) {
- var pubKeys = Cryptpad.getPublicKeys();
- if (pubKeys && pubKeys.curve) {
- obj.curveKey = pubKeys.curve;
- obj.edKey = pubKeys.ed;
- }
- }*/
-
if (!APP.initialized) {
var $header = $('', {id: HEADER_ID}).appendTo(APP.$rightside);
addAvatar($header);
diff --git a/www/profile/main.js b/www/profile/main.js
index 195dbdc6b..22823d0d9 100644
--- a/www/profile/main.js
+++ b/www/profile/main.js
@@ -2,15 +2,15 @@
define([
'/bower_components/nthen/index.js',
'/api/config',
- 'jquery',
+ '/common/dom-ready.js',
'/common/requireconfig.js',
'/common/sframe-common-outer.js',
-], function (nThen, ApiConfig, $, RequireConfig, SFCommonO) {
+], function (nThen, ApiConfig, DomReady, RequireConfig, SFCommonO) {
var requireConfig = RequireConfig();
// Loaded in load #2
nThen(function (waitFor) {
- $(waitFor());
+ DomReady.onReady(waitFor());
}).nThen(function (waitFor) {
var req = {
cfg: requireConfig,
@@ -19,7 +19,7 @@ define([
};
window.rc = requireConfig;
window.apiconf = ApiConfig;
- $('#sbox-iframe').attr('src',
+ document.getElementById('sbox-iframe').setAttribute('src',
ApiConfig.httpSafeOrigin + '/profile/inner.html?' + requireConfig.urlArgs +
'#' + encodeURIComponent(JSON.stringify(req)));
@@ -36,34 +36,41 @@ define([
};
window.addEventListener('message', onMsg);
}).nThen(function (/*waitFor*/) {
- var getSecrets = function (Cryptpad, Utils) {
+ var getSecrets = function (Cryptpad, Utils, cb) {
var Hash = Utils.Hash;
// 1st case: visiting someone else's profile with hash in the URL
if (window.location.hash) {
- return Hash.getSecrets('profile', window.location.hash.slice(1));
+ return void cb(null, Hash.getSecrets('profile', window.location.hash.slice(1)));
}
- // 2nd case: visiting our own existing profile
- var obj = Cryptpad.getProxy();
- if (obj.profile && obj.profile.view && obj.profile.edit) {
- return Hash.getSecrets('profile', obj.profile.edit);
- }
- // 3rd case: profile creation (create a new random hash, store it later if needed)
- if (!Utils.LocalStore.isLoggedIn()) { return; }
- var hash = Hash.createRandomHash();
- var secret = Hash.getSecrets('profile', hash);
- Cryptpad.pinPads([secret.channel], function (e) {
- if (e) {
- if (e === 'E_OVER_LIMIT') {
- // TODO
- }
- return;
- //return void UI.log(Messages._getKey('profile_error', [e])) // TODO
+ var editHash;
+ nThen(function (waitFor) {
+ // 2nd case: visiting our own existing profile
+ Cryptpad.getProfileEditUrl(waitFor(function (hash) {
+ editHash = hash;
+ }));
+ }).nThen(function () {
+ if (editHash) {
+ return void cb(null, Hash.getSecrets('profile', editHash));
}
- obj.profile = {};
- obj.profile.edit = Utils.Hash.getEditHashFromKeys(secret.channel, secret.keys);
- obj.profile.view = Utils.Hash.getViewHashFromKeys(secret.channel, secret.keys);
+ // 3rd case: profile creation (create a new random hash, store it later if needed)
+ if (!Utils.LocalStore.isLoggedIn()) { return void cb(); }
+ var hash = Hash.createRandomHash();
+ var secret = Hash.getSecrets('profile', hash);
+ Cryptpad.pinPads([secret.channel], function (e) {
+ if (e) {
+ if (e === 'E_OVER_LIMIT') {
+ // TODO
+ }
+ return;
+ //return void UI.log(Messages._getKey('profile_error', [e])) // TODO
+ }
+ var profile = {};
+ profile.edit = Utils.Hash.getEditHashFromKeys(secret.channel, secret.keys);
+ profile.view = Utils.Hash.getViewHashFromKeys(secret.channel, secret.keys);
+ Cryptpad.setNewProfile(profile);
+ });
+ cb(null, secret);
});
- return secret;
};
var addRpc = function (sframeChan, Cryptpad, Utils) {
// Adding a new avatar from the profile: pin it and store it in the object
@@ -71,18 +78,14 @@ define([
var chanId = Utils.Hash.hrefToHexChannelId(data);
Cryptpad.pinPads([chanId], function (e) {
if (e) { return void cb(e); }
- Cryptpad.getProxy().profile.avatar = data;
- Utils.Realtime.whenRealtimeSyncs(Cryptpad.getRealtime(), function () {
- cb();
- });
+ Cryptpad.setAvatar(data, cb);
});
});
// Removing the avatar from the profile: unpin it
sframeChan.on('Q_PROFILE_AVATAR_REMOVE', function (data, cb) {
var chanId = Utils.Hash.hrefToHexChannelId(data);
- Cryptpad.unpinPads([chanId], function (e) {
- delete Cryptpad.getProxy().profile.avatar;
- cb(e);
+ Cryptpad.unpinPads([chanId], function () {
+ Cryptpad.setAvatar(undefined, cb);
});
});
};
diff --git a/www/settings/main.js b/www/settings/main.js
index 958dcda45..42f501075 100644
--- a/www/settings/main.js
+++ b/www/settings/main.js
@@ -2,15 +2,15 @@
define([
'/bower_components/nthen/index.js',
'/api/config',
- 'jquery',
+ '/common/dom-ready.js',
'/common/requireconfig.js',
'/common/sframe-common-outer.js'
-], function (nThen, ApiConfig, $, RequireConfig, SFCommonO) {
+], function (nThen, ApiConfig, DomReady, RequireConfig, SFCommonO) {
var requireConfig = RequireConfig();
// Loaded in load #2
nThen(function (waitFor) {
- $(waitFor());
+ DomReady.onReady(waitFor());
}).nThen(function (waitFor) {
var req = {
cfg: requireConfig,
@@ -19,7 +19,7 @@ define([
};
window.rc = requireConfig;
window.apiconf = ApiConfig;
- $('#sbox-iframe').attr('src',
+ document.getElementById('sbox-iframe').setAttribute('src',
ApiConfig.httpSafeOrigin + '/settings/inner.html?' + requireConfig.urlArgs +
'#' + encodeURIComponent(JSON.stringify(req)));
@@ -43,7 +43,7 @@ define([
});
});
sframeChan.on('Q_SETTINGS_DRIVE_GET', function (d, cb) {
- cb(Cryptpad.getProxy());
+ Cryptpad.getUserObject(cb);
});
sframeChan.on('Q_SETTINGS_DRIVE_SET', function (data, cb) {
var sjson = JSON.stringify(data);
@@ -57,26 +57,13 @@ define([
});
});
sframeChan.on('Q_SETTINGS_DRIVE_RESET', function (data, cb) {
- var proxy = Cryptpad.getProxy();
- var realtime = Cryptpad.getRealtime();
- proxy.drive = Cryptpad.getStore().getEmptyObject();
- Utils.Realtime.whenRealtimeSyncs(realtime, cb);
+ Cryptpad.resetDrive(cb);
});
sframeChan.on('Q_SETTINGS_LOGOUT', function (data, cb) {
- var proxy = Cryptpad.getProxy();
- var realtime = Cryptpad.getRealtime();
- var token = Math.floor(Math.random()*Number.MAX_SAFE_INTEGER);
- localStorage.setItem('loginToken', token);
- proxy.loginToken = token;
- Utils.Realtime.whenRealtimeSyncs(realtime, cb);
+ Cryptpad.logoutFromAll(cb);
});
sframeChan.on('Q_SETTINGS_IMPORT_LOCAL', function (data, cb) {
- var proxyData = Cryptpad.getStore().getProxy();
- require([
- '/common/mergeDrive.js',
- ], function (Merge) {
- Merge.anonDriveIntoUser(proxyData, Utils.LocalStore.getFSHash(), cb);
- });
+ Cryptpad.mergeAnonDrive(cb);
});
};
SFCommonO.start({
diff --git a/www/todo/main.js b/www/todo/main.js
index 3f6d1cd5f..2898434fd 100644
--- a/www/todo/main.js
+++ b/www/todo/main.js
@@ -2,15 +2,15 @@
define([
'/bower_components/nthen/index.js',
'/api/config',
- 'jquery',
+ '/common/dom-ready.js',
'/common/requireconfig.js',
'/common/sframe-common-outer.js'
-], function (nThen, ApiConfig, $, RequireConfig, SFCommonO) {
+], function (nThen, ApiConfig, DomReady, RequireConfig, SFCommonO) {
var requireConfig = RequireConfig();
// Loaded in load #2
nThen(function (waitFor) {
- $(waitFor());
+ DomReady.onReady(waitFor());
}).nThen(function (waitFor) {
var req = {
cfg: requireConfig,
@@ -19,7 +19,7 @@ define([
};
window.rc = requireConfig;
window.apiconf = ApiConfig;
- $('#sbox-iframe').attr('src',
+ document.getElementById('sbox-iframe').setAttribute('src',
ApiConfig.httpSafeOrigin + '/todo/inner.html?' + requireConfig.urlArgs +
'#' + encodeURIComponent(JSON.stringify(req)));
@@ -36,12 +36,12 @@ define([
};
window.addEventListener('message', onMsg);
}).nThen(function (/*waitFor*/) {
- var getSecrets = function (Cryptpad, Utils) {
- var proxy = Cryptpad.getProxy();
- var hash = proxy.todo || Utils.Hash.createRandomHash();
- if (!proxy.todo) { proxy.todo = hash; }
-
- return Utils.Hash.getSecrets('todo', hash);
+ var getSecrets = function (Cryptpad, Utils, cb) {
+ Cryptpad.getTodoHash(function (hash) {
+ var nHash = hash || Utils.Hash.createRandomHash();
+ if (!hash) { Cryptpad.setTodoHash(nHash); }
+ cb(null, Utils.Hash.getSecrets('todo', hash));
+ });
};
SFCommonO.start({
getSecrets: getSecrets,
diff --git a/www/whiteboard/main.js b/www/whiteboard/main.js
index 4c8a3887c..ce1f14d9c 100644
--- a/www/whiteboard/main.js
+++ b/www/whiteboard/main.js
@@ -2,15 +2,15 @@
define([
'/bower_components/nthen/index.js',
'/api/config',
- 'jquery',
+ '/common/dom-ready.js',
'/common/requireconfig.js',
'/common/sframe-common-outer.js'
-], function (nThen, ApiConfig, $, RequireConfig, SFCommonO) {
+], function (nThen, ApiConfig, DomReady, RequireConfig, SFCommonO) {
var requireConfig = RequireConfig();
// Loaded in load #2
nThen(function (waitFor) {
- $(waitFor());
+ DomReady.onReady(waitFor());
}).nThen(function (waitFor) {
var req = {
cfg: requireConfig,
@@ -19,7 +19,7 @@ define([
};
window.rc = requireConfig;
window.apiconf = ApiConfig;
- $('#sbox-iframe').attr('src',
+ document.getElementById('sbox-iframe').setAttribute('src',
ApiConfig.httpSafeOrigin + '/whiteboard/inner.html?' + requireConfig.urlArgs +
'#' + encodeURIComponent(JSON.stringify(req)));