2016-07-04 21:21:23 +08:00
|
|
|
define([
|
2016-07-12 21:53:58 +08:00
|
|
|
'/customize/messages.js',
|
2016-09-13 17:01:10 +08:00
|
|
|
'/customize/application_config.js',
|
2016-07-04 21:21:23 +08:00
|
|
|
'/common/cryptpad-common.js',
|
|
|
|
'/bower_components/lil-uri/uri.min.js',
|
2016-12-30 22:33:28 +08:00
|
|
|
'/customize/languageSelector.js',
|
2016-07-06 21:14:41 +08:00
|
|
|
'/bower_components/jquery/dist/jquery.min.js',
|
2016-12-30 22:33:28 +08:00
|
|
|
], function (Messages, Config, Cryptpad, LilUri, LS) {
|
2016-07-04 21:21:23 +08:00
|
|
|
var $ = window.$;
|
2016-07-11 17:07:59 +08:00
|
|
|
|
2017-01-03 19:17:17 +08:00
|
|
|
var USE_TABLE = Config.USE_HOMEPAGE_TABLE;
|
|
|
|
var USE_FS_STORE = Config.USE_FS_STORE;
|
|
|
|
|
2016-08-31 00:15:43 +08:00
|
|
|
var APP = window.APP = {
|
|
|
|
Cryptpad: Cryptpad,
|
|
|
|
};
|
|
|
|
|
2016-07-04 21:21:23 +08:00
|
|
|
var padTypes = {
|
2016-09-16 00:35:09 +08:00
|
|
|
'/pad/': Messages.type.pad,
|
|
|
|
'/code/': Messages.type.code,
|
|
|
|
'/poll/': Messages.type.poll,
|
|
|
|
'/slide/': Messages.type.slide,
|
2016-07-04 21:21:23 +08:00
|
|
|
};
|
|
|
|
|
2016-10-05 17:19:18 +08:00
|
|
|
var $table;
|
|
|
|
var $tbody;
|
|
|
|
var $tryit;
|
2016-08-31 00:15:43 +08:00
|
|
|
var now = new Date();
|
|
|
|
var hasRecent = false;
|
2016-07-04 21:21:23 +08:00
|
|
|
|
2016-08-31 00:15:43 +08:00
|
|
|
var forgetPad = Cryptpad.forgetPad;
|
2016-07-07 20:52:00 +08:00
|
|
|
|
2016-09-13 17:01:10 +08:00
|
|
|
var displayCreateButtons = function () {
|
2016-11-07 18:43:49 +08:00
|
|
|
var $parent = $('#buttons');
|
2016-09-13 17:01:10 +08:00
|
|
|
Config.availablePadTypes.forEach(function (el) {
|
2017-01-04 23:41:47 +08:00
|
|
|
$('#create-' + el).detach().appendTo($parent).attr('target', '_blank').show();
|
2016-09-13 17:01:10 +08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-12-30 22:33:28 +08:00
|
|
|
var $sel = $('#language-selector');
|
|
|
|
|
|
|
|
Object.keys(Messages._languages).forEach(function (code) {
|
|
|
|
$sel.append($('<option>', {
|
|
|
|
value: code,
|
|
|
|
}).text(Messages._languages[code]));
|
|
|
|
});
|
|
|
|
|
|
|
|
LS.main();
|
|
|
|
Messages._applyTranslation();
|
|
|
|
$sel.show();
|
|
|
|
|
2016-07-28 23:44:40 +08:00
|
|
|
var makeRecentPadsTable = function (recentPads) {
|
2016-07-04 21:21:23 +08:00
|
|
|
if (!recentPads.length) { return; }
|
2016-08-03 17:36:22 +08:00
|
|
|
|
|
|
|
$('tbody tr').each(function (i, e) {
|
|
|
|
if (!i) { return; }
|
|
|
|
$(this).remove();
|
|
|
|
});
|
|
|
|
|
2016-07-04 21:21:23 +08:00
|
|
|
recentPads.some(function (pad, index) {
|
|
|
|
if (!pad) { return; }
|
|
|
|
|
|
|
|
hasRecent = true;
|
|
|
|
|
|
|
|
// split up the uri
|
|
|
|
var uri = LilUri(pad.href);
|
|
|
|
|
|
|
|
// derive the name
|
|
|
|
var name = padTypes[uri.path()];
|
|
|
|
|
|
|
|
var title = pad.title || uri.parts.hash.slice(0,8);
|
2016-08-31 00:15:43 +08:00
|
|
|
var shortTitle = Cryptpad.truncate(pad.title, 48);
|
2016-07-04 21:21:23 +08:00
|
|
|
|
|
|
|
var date = new Date(pad.atime).toLocaleDateString();
|
|
|
|
var created = new Date(pad.ctime).toLocaleDateString();
|
|
|
|
|
|
|
|
if (date === now.toLocaleDateString()) {
|
|
|
|
date = new Date(pad.atime).toLocaleTimeString().replace(/ /g, '');
|
|
|
|
}
|
|
|
|
|
|
|
|
var id = 'pad-'+index;
|
2016-07-04 23:31:52 +08:00
|
|
|
|
2016-07-07 20:17:48 +08:00
|
|
|
var $row = $('<tr>', {
|
|
|
|
id: id
|
|
|
|
});
|
|
|
|
|
|
|
|
var $remove = $('<td>', {
|
|
|
|
'class': 'remove',
|
2016-09-16 00:35:09 +08:00
|
|
|
title: Messages.forget + " '"+shortTitle + "'"
|
2016-07-07 20:17:48 +08:00
|
|
|
}).text('✖').click(function () {
|
2016-08-31 00:15:43 +08:00
|
|
|
Cryptpad.confirm(Messages.forgetPrompt + ' (' + Cryptpad.fixHTML(shortTitle) + ')', function (yes) {
|
2016-07-07 20:17:48 +08:00
|
|
|
if (!yes) { return; }
|
2016-07-28 23:44:40 +08:00
|
|
|
forgetPad(pad.href, function (err, data) {
|
|
|
|
if (err) {
|
|
|
|
console.log("Unable to forget pad");
|
|
|
|
console.log(err);
|
|
|
|
return;
|
2016-07-07 20:17:48 +08:00
|
|
|
}
|
2016-07-28 23:44:40 +08:00
|
|
|
$row.fadeOut(750, function () {
|
|
|
|
$row.remove();
|
|
|
|
if (!$table.find('tr').find('td').length) {
|
|
|
|
$table.remove();
|
|
|
|
$tryit.text(Messages.tryIt);
|
|
|
|
}
|
|
|
|
});
|
2016-07-07 20:17:48 +08:00
|
|
|
});
|
2016-07-04 21:21:23 +08:00
|
|
|
});
|
|
|
|
});
|
2016-07-07 20:17:48 +08:00
|
|
|
|
2016-09-20 17:59:13 +08:00
|
|
|
var readOnly = false;
|
|
|
|
if (pad.href.indexOf('#') !== -1) {
|
|
|
|
var modeArray = pad.href.split('#')[1].split('/');
|
|
|
|
if (modeArray.length >= 3 && modeArray[2] === 'view') {
|
|
|
|
readOnly = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var readOnlyText = readOnly ? '(' + Messages.readonly + ') ' : '';
|
2016-07-07 20:17:48 +08:00
|
|
|
$row
|
|
|
|
.append($('<td>').text(name))
|
2016-09-20 17:59:13 +08:00
|
|
|
.append($('<td>').append(readOnlyText).append($('<a>', {
|
2016-07-07 20:17:48 +08:00
|
|
|
href: pad.href,
|
|
|
|
title: pad.title,
|
|
|
|
}).text(shortTitle)))
|
|
|
|
.append($('<td>').text(created))
|
|
|
|
.append($('<td>').text(date))
|
|
|
|
.append($remove);
|
|
|
|
$tbody.append($row);
|
2016-07-04 21:21:23 +08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-08-03 17:36:22 +08:00
|
|
|
var refreshTable = function () {
|
2016-08-02 18:11:40 +08:00
|
|
|
Cryptpad.getRecentPads(function (err, recentPads) {
|
|
|
|
if (err) {
|
|
|
|
console.log("unable to get recent pads");
|
|
|
|
console.error(err);
|
|
|
|
return;
|
|
|
|
}
|
2016-07-28 23:44:40 +08:00
|
|
|
|
2016-08-02 18:11:40 +08:00
|
|
|
if (recentPads.length) {
|
|
|
|
recentPads.sort(Cryptpad.mostRecent);
|
2016-12-20 00:53:03 +08:00
|
|
|
$('iframe').attr('style', '');
|
|
|
|
$tryit.removeAttr('data-localization');
|
|
|
|
$tryit.text(Messages.recentPadsIframe);
|
2017-01-03 19:17:17 +08:00
|
|
|
|
|
|
|
if (USE_TABLE) {
|
|
|
|
makeRecentPadsTable(recentPads);
|
|
|
|
}
|
2016-08-02 18:11:40 +08:00
|
|
|
}
|
2017-01-03 18:49:44 +08:00
|
|
|
|
2017-01-03 19:17:17 +08:00
|
|
|
if (USE_TABLE && hasRecent) {
|
2017-01-03 18:49:44 +08:00
|
|
|
$('table').attr('style', '');
|
|
|
|
// Race condition here, this is triggered before the localization in HTML
|
|
|
|
// so we have to remove the data-localization attr
|
|
|
|
$tryit.removeAttr('data-localization');
|
|
|
|
$tryit.text(Messages.recentPads);
|
2017-01-03 19:17:17 +08:00
|
|
|
}
|
2016-08-02 18:11:40 +08:00
|
|
|
});
|
2016-08-03 17:36:22 +08:00
|
|
|
};
|
|
|
|
|
2016-12-22 18:02:12 +08:00
|
|
|
displayCreateButtons();
|
2016-08-03 17:36:22 +08:00
|
|
|
Cryptpad.ready(function () {
|
|
|
|
console.log("ready");
|
2016-08-31 00:15:43 +08:00
|
|
|
|
2016-10-05 17:19:18 +08:00
|
|
|
$table = $('table.scroll');
|
|
|
|
$tbody = $table.find('tbody');
|
|
|
|
$tryit = $('#tryit');
|
|
|
|
|
|
|
|
Cryptpad.styleAlerts();
|
|
|
|
|
|
|
|
refreshTable();
|
2016-08-31 00:15:43 +08:00
|
|
|
if (Cryptpad.store && Cryptpad.store.change) {
|
|
|
|
Cryptpad.store.change(function (data) {
|
|
|
|
if (data.key === 'CryptPad_RECENTPADS') {
|
|
|
|
refreshTable();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-07-28 23:44:40 +08:00
|
|
|
});
|
2016-07-04 21:21:23 +08:00
|
|
|
});
|
|
|
|
|