This repository has been archived by the owner on Jun 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
modal_share.coffee
146 lines (123 loc) · 5.11 KB
/
modal_share.coffee
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
BaseView = require '../lib/base_view'
Modal = require "./modal"
client = require "../lib/client"
CozyClearanceModal = require "cozy-clearance/modal_share_view"
# extends the cozy-clearance modal to files specifics
module.exports = class ModalShareView extends CozyClearanceModal
# display inherited details on summary's click
events: -> _.extend super,
'click #inherited-share-summary a': =>
@$('#inherited-share-list').show()
@$('#inherited-share-summary').hide()
# retrieve inherited rules
initialize: (options) ->
@type = @model.get('type')
super
@summaryemails = []
client.get "clearance/#{@model.id}", (err, data) =>
if err
Modal.error 'server error occured', => @$el.modal 'hide'
else
@inherited = data.inherited
@forcedShared = @inherited.length > 0
@makePublic() if @isPrivateClearance()
# actually render content
@refresh()
# allow rw permissions for folder, customize message depending on type
permissions: ->
if @type is 'folder'
'r': 'perm r folder'
'rw': 'perm rw folder'
else
'r': t 'perm r file'
# do not allow adding permissions for user who already have them by inheritance
typeaheadFilter: (item) =>
email = item.toString().split(';')[0]
super and email not in @summaryemails
# force 'shared' display if forced shared by inheritance
getRenderData: ->
out = super
if @forcedShared
if @inherited?
if @inherited[0].clearance is 'public'
out.clearance = 'public'
else
guests = []
for folder in @inherited
guests.push guest for guest in folder.clearance
out.clearance = @getClearanceWithContacts guests
return out
# ignore click on 'private' button when forced public by inheritance
makePrivate: ->
return if @forcedShared
super
# support forced public by inheritance and add inherited summary
afterRender: ->
super
if @forcedShared
@$('#share-public').addClass 'toggled'
@$('#select-mode-section').hide()
if @inherited[0].clearance is 'public'
text = t('forced public')
@$('#select-mode-section').after $('<p>').text text
$('#share-input').hide()
$('#add-contact').hide()
$('.input-group').prev('p').hide()
$('#public-url').removeClass 'disabled'
setTimeout ->
$('#public-url').focus().select()
, 200
else
text = t('forced shared')
@$('#select-mode-section').after $('<p>').text text
$('#share-input').hide()
$('#add-contact').hide()
$('.input-group').prev('p').hide()
$('.input-group').prev('p').prev('p').hide()
$('#public-url').prev('p').hide()
$('#public-url').prev('p').prev('p').hide()
$('#public-url').hide()
$('.revoke').hide()
$('.changeperm').prop 'disabled', true
$('#modal-dialog-no').hide()
$('#modal-dialog-yes').html t('ok')
else
listitems = []
summary = []
for folder in @inherited when folder.clearance.length isnt 0
text = t('inherited from') + folder.name
listitems.push $('<li>').addClass('header').text text
for rule in folder.clearance when folder.clearance
summary.push rule.email
listitems.push $('<li>').text rule.email
if summary.length isnt 0
@summaryemails = summary
text = t('also have access') + ': ' + summary.join(', ') + '. '
summary = $('<div id="inherited-share-summary">').text text
summary.append $('<a>').text t('details')
list = $('<ul id="inherited-share-list">').hide()
list.append item for item in listitems
@$('#share-list').after summary, list
# if there is a writing guest
guestCanWrite = _.findWhere @model.get('clearance'), perm: 'rw'
if guestCanWrite
checkbox = $('<input id="notifs" type="checkbox">')
checkbox.prop 'checked', @model.get 'changeNotification'
text = t('change notif')
html = '<label class="notifs-label" for="notifs">'
label = $(html).append checkbox, text
@$('#share-list').after label
# include the changes notification in PUT request
saveData: ->
changeNotification = @$('#notifs').prop('checked') or false
_.extend super, changeNotification: changeNotification
onYes: ->
if @forcedShared
@close()
else
super()
onNo: ->
if @forcedShared
@close()
else
super()