forked from linuxfrorg/linuxfr.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredaction.coffee
More file actions
118 lines (95 loc) · 3.65 KB
/
redaction.coffee
File metadata and controls
118 lines (95 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#= require lang
#= require push
$ = window.jQuery
class Redaction
constructor: (chan) ->
push = $.push chan
for name, fn of @ when name.slice(0, 2) == "on"
kind = name.replace(/[A-Z]/g, "_$&").toLowerCase().slice(3)
push.on kind, fn
push.start()
onSubmit: (msg) ->
$.noticeAdd text: "#{msg.username} a soumis la dépêche", stay: true
onPublish: (msg) ->
$.noticeAdd text: "La dépêche a été acceptée par #{msg.username}", stay: true
onRefuse: (msg) ->
$.noticeAdd text: "La dépêche a été refusée par #{msg.username}", stay: true
onRewrite: (msg) ->
$.noticeAdd text: "La dépêche a été renvoyée dans l’espace de rédaction par #{msg.username}", stay: true
onVote: (msg) ->
$.noticeAdd text: "#{msg.username} a voté #{msg.word}"
$("#news_vote").load "/moderation/news/#{msg.news_id}/vote"
onUpdate: (msg) ->
$("#news_header .title").text msg.title
$("#news_header .topic").text msg.section.title
$("#edition figure.image img").attr src: "/images/sections/#{msg.section.id}.png"
liForRevision: (msg) ->
parts = window.location.pathname.split("/")
slug = parts[parts.length - 1]
"""
<li><a href="/redaction/news/#{slug}/revisions/#{msg.version}">
#{msg.username} : #{msg.message} - #{msg.creationdate}
</a></li>
"""
onRevision: (msg) =>
$("#news_revisions ul").prepend @liForRevision(msg)
$("#topbar .revision-cell").text msg.version
atPosition = msg.creationdate.indexOf(':') - 2
finalDate = [msg.creationdate.slice(0, atPosition), "à ", msg.creationdate.slice(atPosition)].join("")
$("#topbar .revision-date").text "le " + finalDate
innerHtmlForLink: (msg) ->
"""
<a href="/redirect/#{msg.id}" class="hit_counter">#{msg.title}</a> (#{if msg.lang == 'fr' then '' else 'en ' + window.langs[msg.lang].toLowerCase() + ', '}#{msg.nb_clicks} clic#{if msg.nb_clicks > 1 then 's' else ''})
"""
htmlForLink: (msg) ->
"""
<li class="link" id="link_#{msg.id}" lang="#{msg.lang}" data-url="/redaction/links/#{msg.id}/modifier">
#{@innerHtmlForLink msg}
<div class="actions">
<button class="edit">Modifier</button>
</div>
</li>
"""
onAddLink: (msg) =>
$("#links").append @htmlForLink(msg)
$("#link_#{msg.id}").lockableEditionInPlace()
onUpdateLink: (msg) =>
$("#link_#{msg.id}").html(@innerHtmlForLink msg)
.attr(lang: msg.lang)
onRemoveLink: (msg) ->
$("#link_#{msg.id}").remove()
htmlForPara: (msg) ->
"""
<div id="paragraph_#{msg.id}" class="paragraph #{msg.part}" data-url="/redaction/paragraphs/#{msg.id}/modifier">
#{msg.body}
<div class="actions">
<button class="edit">Modifier</button>
</div>
</div>
"""
onAddParagraph: (msg) =>
if msg.after
$("#paragraph_#{msg.after}").after @htmlForPara(msg)
else
$("##{msg.part}").append @htmlForPara(msg)
$("#paragraph_#{msg.id}").lockableEditionInPlace()
onUpdateParagraph: (msg) =>
$("#paragraph_#{msg.id}").html(msg.body)
onRemoveParagraph: (msg) ->
$("#paragraph_#{msg.id}").remove()
onSecondPartToc: (msg) ->
$(".second_part_toc").html(msg.toc)
onLockParagraph: (msg) ->
editing = $ """
<img class="editing"
id="editing_#{msg.id}"
alt="#{msg.user.name} est en train de modifier ce paragraphe"
title="#{msg.user.name} est en train de modifier ce paragraphe"
src="#{msg.user.avatar}" />
"""
$("#paragraph_#{msg.id} .actions").prepend editing
onUnlockParagraph: (msg) ->
$("#editing_#{msg.id}").remove()
$.fn.redaction = ->
@each ->
new Redaction($(@).data("chan"))