Skip to content

Commit

Permalink
FEATURE: Editing a comment.
Browse files Browse the repository at this point in the history
Registered users can modify (only) their comments.

Note: Comments' specific structure prevents the use of the validation function. Using a (weak) authentication strategy was thus preferred to the modification of this structure, which would lead to a major refactoring.

This commit includes minor fixes :
* The button allowing to add groundings is restored (#48).
  This completes commit 80f5f59
* No new memo can be created on the ground of an untitled memo (fixes #61).
* The log-in button is always located on the right of the heading menu.
  • Loading branch information
christophe-lejeune committed Mar 2, 2017
1 parent 074375f commit a3c495d
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 18 deletions.
8 changes: 7 additions & 1 deletion _attachments/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ form {
position: fixed;
}

.menu button,
.menu select,
.menu input {
color: black;
}


#header {
margin-bottom: 0;
padding: 4px;
Expand Down Expand Up @@ -325,7 +332,6 @@ input.actor {
margin: 0px 10px;
}


.occurrence{
display: table-row;
}
Expand Down
8 changes: 5 additions & 3 deletions lists/memo.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ function(head, req) {
data.comments.push({
user: user,
date: row.value.date,
text: row.value.text
text: row.value.text,
id: row.value.id,
rev: row.value.rev
});
break;
case ('H'):
Expand All @@ -48,7 +50,7 @@ function(head, req) {
case ('G'):
if (row.doc) {
if (row.doc.body) {
var preview = row.doc.body.substr(0, 200).replace("\s", ' ');
var preview = row.doc.body.substr(0, 200).replace(/\s/g, ' ');
} else {
if (row.doc.speeches) {
var preview = row.doc.speeches[0].text.substr(0, 200) || ' ';
Expand Down Expand Up @@ -115,7 +117,7 @@ function(head, req) {
leaves: [],
logged: username,
logged_fullname: username,
name: row.doc.name,
name: row.doc.name.replace(/\s/g, ' '),
readers: [],
readers_fullnames: [],
roles: req.userCtx.roles,
Expand Down
4 changes: 3 additions & 1 deletion templates/editable_memo.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
<header>
<div id="header" class="menu">
<button type="button" id="diary">&nbsp;</button>
<div id='logged'>
{{#logged}}
{{logged_fullname}}
<button id="signout">{{i18n.i_sign-out}}</button>
<button id="signout">{{i18n.i_sign-out}}</button>
{{/logged}}
</div>
</div>
</header>
<div id="memo">
Expand Down
78 changes: 66 additions & 12 deletions templates/memo.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
disabled='disabled' hidden="hidden">{{i18n.i_rare}}</button>
<button type='button' id='repeated' disabled='disabled' hidden="hidden">
{{i18n.i_phrases}}</button>
<input id='kwic' type='search' placeholder='{{i18n.i_search}}' hidden="hidden"/>
{{/authorized}}
<div id='logged'>
{{^logged}}
Expand All @@ -31,6 +30,9 @@
<button id="signout">{{i18n.i_sign-out}}</button>
{{/logged}}
</div>
{{#authorized}}
<input id='kwic' type='search' placeholder='{{i18n.i_search}}' hidden="hidden"/>
{{/authorized}}
</div>
<div id="memo">
{{#authorized}}
Expand All @@ -50,12 +52,12 @@ <h4 class="toggle">{{name}}</h4>
<h1>{{i18n.i_sign-in_required}}</h1>
{{/authorized}}
{{#authorized}}
<div id="add-leaves"><button type="button" id="add">+</button>
<div id="add-leaves"><button type="button" id="add" hidden="hidden">+</button>
<button id="create" class="diagram" type="button" hidden="hidden">+</button>
</div>
<h1><img src="../../style/{{type}}.png"/><span id="name">{{name}}</span></h1>
<p id="authorization">
{{i18n.i_created}} {{date}}<br/>
{{i18n.i_created-by}} {{date}}<br/>
{{i18n.i_contributors}} <span id="contributors">{{contributors_fullnames}}</span>
<button type="button" id="contributors_add">+</button>
<input id="contributors_edit" type="search" hidden="hidden" /><br/>
Expand Down Expand Up @@ -85,9 +87,13 @@ <h1><img src="../../style/{{type}}.png"/><span id="name">{{name}}</span></h1>
</div>
<div id="comments">
{{#comments}}
<div class="comment"><span class="meta">{{user}} ({{date}})</span>: <br/>{{text}}</div>
<div class="comment" id="{{id}}" name="{{rev}}">
<span class="meta"><span class="user">{{user}}</span> ({{date}})</span>: <br/>
<span class="comment_text">{{text}}</span>
<input size="80" height="50" type="text" hidden="hidden" class="comment_edit" value="{{text}}"/>
</div>
{{/comments}}
<button type="button" id="comment">{{i18n.i_comment}}</button>
<button type="button" id="comment_create">{{i18n.i_comment}}</button>
<textarea cols="80" rows="5" type="text" hidden="hidden" placeHolder="{{i18n.i_enter_comment}}"></textarea>
<button type="button" id="commented" hidden="hidden">{{i18n.i_done}}</button>
</div>
Expand Down Expand Up @@ -125,6 +131,7 @@ <h1><img src="../../style/{{type}}.png"/><span id="name">{{name}}</span></h1>
if ("{{logged}}") user = "{{logged}}";

$(document).ready(function() {
if ($('h1').text().length > 0) $('#add').show();
switch ('{{type}}') {
case ('field'):
$('#add').addClass('coding');
Expand Down Expand Up @@ -320,16 +327,34 @@ <h1><img src="../../style/{{type}}.png"/><span id="name">{{name}}</span></h1>
});

$('#add-grounding').on('click', function() {
$("#dialog").dialog({
autoOpen: true,
modal: true,
autoResize: true,
width:'auto'
$.ajax({
url: "../../memo_attribute/{{diary}}",
type: "GET",
dataType: "json",
success: function(ground_candidates) {
for (var i in ground_candidates.rows) {
var r = ground_candidates.rows[i];
var id = r.value['id'];
var rid = '#' + id;
if(document.getElementById(rid) == null && id != "{{_id}}") {
$("#dialog").find('select').append($('<option>', {
value: id,
text: r.value['name']
}));
}
}
$("#dialog").dialog({
autoOpen: true,
modal: true,
autoResize: true,
width:'auto'
});
}
});
});

$("#comment").click(function () {
$("#comment").remove();
$("#comment_create").click(function () {
$("#comment_create").remove();
$("#comments").find('textarea').show();
$('#commented').show();
});
Expand All @@ -342,6 +367,34 @@ <h1><img src="../../style/{{type}}.png"/><span id="name">{{name}}</span></h1>
}
});

$(".comment").click(function () {
var user = $(this).find('.user').text();
if ("{{logged_fullname}}" == user) {
$(this).find('.comment_text').hide();
$(this).find('.comment_edit').show();
$("#comment_create").remove();
}
});

$(".comment_edit").on('keypress', function(key) {
if (key.which == 13) {
var data = {
commented: "{{_id}}",
diary: "{{diary}}",
user: user,
date: new Date().toJSON(),
text: $(this).val().trim()
};
$.ajax({
type: "PUT",
url: '../../'+ $(this).closest('.comment').attr('id') + "?rev=" + $(this).closest('.comment').attr('name'),
contentType: "application/json",
data: JSON.stringify(data),
success: reload
});
}
});

function create(type) {
var diary = "{{diary}}";
var contributors = "{{contributors}}";
Expand Down Expand Up @@ -401,6 +454,7 @@ <h1><img src="../../style/{{type}}.png"/><span id="name">{{name}}</span></h1>
function comment() {
var data = {
commented: "{{_id}}",
diary: "{{diary}}",
user: user,
date: new Date().toJSON(),
text: $('#comments').find('textarea').val().trim()
Expand Down
2 changes: 1 addition & 1 deletion views/memo/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function(o) {
emit([o.groundings[key], 'L']);
}
if (o.commented)
emit([o.commented, 'M', o.date], {'_id':o.user, 'date': o.date, 'text': o.text});
emit([o.commented, 'M', o.date], {'_id':o.user, 'date': o.date, 'text': o.text, 'id': o._id, 'rev': o._rev});
if (o.history)
emit([o._id, 'H'], {'_id':o.history[0].user, 'date': o.history[0].date});
for (var key in o.contributors)
Expand Down

0 comments on commit a3c495d

Please sign in to comment.