This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
forked from cozy/cozy-clearance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient-build.js
772 lines (676 loc) · 25.1 KB
/
client-build.js
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
require.register("cozy-clearance/contact_autocomplete", function(exports, require, module){
module.exports = function(input, onGuestAdded, extrafilter) {
var contactCollection;
contactCollection = require('./contact_collection');
if (extrafilter == null) {
extrafilter = function() {
return true;
};
}
input.on('keyup', (function(_this) {
return function(event) {
if (event.which === 13 && !input.data('typeahead').shown) {
onGuestAdded(input.val());
input.val('');
return event.preventDefault();
}
};
})(this));
return input.typeahead({
source: function(query) {
var contacts, items, regexp;
regexp = new RegExp(query);
contacts = contactCollection.filter(function(contact) {
return contact.match(regexp);
});
items = [];
contacts.forEach(function(contact) {
return contact.get('emails').forEach(function(email) {
return items.push({
id: contact.id,
hasPicture: contact.get('hasPicture'),
display: "" + (contact.get('name')) + " <" + email + ">",
toString: function() {
return "" + email + ";" + contact.id;
}
});
});
});
items = items.filter(extrafilter);
return items;
},
matcher: function(contact) {
var old;
old = $.fn.typeahead.Constructor.prototype.matcher;
return old.call(this, contact.display);
},
sorter: function(contacts) {
var beginswith, caseInsensitive, caseSensitive, contact, item;
beginswith = [];
caseSensitive = [];
caseInsensitive = [];
while ((contact = contacts.shift())) {
item = contact.display;
if (!item.toLowerCase().indexOf(this.query.toLowerCase())) {
beginswith.push(contact);
} else if (~item.indexOf(this.query)) {
caseSensitive.push(contact);
} else {
caseInsensitive.push(contact);
}
}
return beginswith.concat(caseSensitive, caseInsensitive);
},
highlighter: function(contact) {
var img, old;
old = $.fn.typeahead.Constructor.prototype.highlighter;
img = contact.hasPicture ? '<img width="40" src="clearance/contacts/' + contact.id + '.jpg"> ' : '<img width="40" src="images/defaultpicture.png"> ';
return img + old.call(this, contact.display);
},
updater: (function(_this) {
return function(value) {
onGuestAdded(value);
return "";
};
})(this)
});
};
});
require.register("cozy-clearance/contact_collection", function(exports, require, module){
var Contact, collection,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
collection = new Backbone.Collection();
collection.url = 'clearance/contacts';
collection.model = Contact = (function(_super) {
__extends(Contact, _super);
function Contact() {
return Contact.__super__.constructor.apply(this, arguments);
}
Contact.prototype.match = function(filter) {
return filter.test(this.get('name')) || this.get('emails').some(function(email) {
return filter.test(email);
});
};
return Contact;
})(Backbone.Model);
collection.fetch();
module.exports = collection;
});
require.register("cozy-clearance/modal", function(exports, require, module){
var Modal,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Modal = (function(_super) {
__extends(Modal, _super);
function Modal() {
this.closeOnEscape = __bind(this.closeOnEscape, this);
return Modal.__super__.constructor.apply(this, arguments);
}
Modal.prototype.id = 'modal-dialog';
Modal.prototype.className = 'modal fade';
Modal.prototype.attributes = {
'data-backdrop': "static",
'data-keyboard': "false"
};
Modal.prototype.initialize = function(options) {
if (this.title == null) {
this.title = options.title;
}
if (this.content == null) {
this.content = options.content;
}
if (this.yes == null) {
this.yes = options.yes || 'ok';
}
if (this.no == null) {
this.no = options.no || 'cancel';
}
if (this.cb == null) {
this.cb = options.cb || function() {};
}
this.render();
this.saving = false;
this.$el.modal('show');
this.$('button.close').click((function(_this) {
return function(event) {
event.stopPropagation();
return _this.onNo();
};
})(this));
return $(document).on('keyup', this.closeOnEscape);
};
Modal.prototype.events = function() {
return {
"click #modal-dialog-no": 'onNo',
"click #modal-dialog-yes": 'onYes',
'click': 'onClickAnywhere'
};
};
Modal.prototype.onNo = function() {
if (this.closing) {
return;
}
this.closing = true;
this.$el.modal('hide');
setTimeout(((function(_this) {
return function() {
return _this.remove();
};
})(this)), 500);
return this.cb(false);
};
Modal.prototype.onYes = function() {
if (this.closing) {
return;
}
this.closing = true;
this.$el.modal('hide');
setTimeout(((function(_this) {
return function() {
return _this.remove();
};
})(this)), 500);
return this.cb(true);
};
Modal.prototype.closeOnEscape = function(e) {
if (e.which === 27) {
return this.onNo();
}
};
Modal.prototype.remove = function() {
$(document).off('keyup', this.closeOnEscape);
return Modal.__super__.remove.apply(this, arguments);
};
Modal.prototype.render = function() {
var body, close, container, foot, head, title, yesBtn;
close = $('<button class="close" type="button" data-dismiss="modal" aria-hidden="true">×</button>');
title = $('<h4 class="model-title">').text(this.title);
head = $('<div class="modal-header">').append(close, title);
body = $('<div class="modal-body">').append(this.renderContent());
yesBtn = $('<button id="modal-dialog-yes" class="btn btn-cozy">').text(this.yes);
foot = $('<div class="modal-footer">').append(yesBtn);
if (this.no) {
foot.prepend($('<button id="modal-dialog-no" class="btn btn-link">').text(this.no));
}
container = $('<div class="modal-content">').append(head, body, foot);
container = $('<div class="modal-dialog">').append(container);
return $("body").append(this.$el.append(container));
};
Modal.prototype.renderContent = function() {
return this.content;
};
Modal.prototype.onClickAnywhere = function(event) {
if (event.target.id === this.id) {
return this.onNo();
}
};
return Modal;
})(Backbone.View);
Modal.alert = function(title, content, cb) {
return new Modal({
title: title,
content: content,
yes: 'ok',
no: null,
cb: cb
});
};
Modal.confirm = function(title, content, yesMsg, noMsg, cb) {
return new Modal({
title: title,
content: content,
yes: yesMsg,
no: noMsg,
cb: cb
});
};
Modal.error = function(text, cb) {
return new ModalView(t("modal error"), text, t("modal ok"), false, cb);
};
module.exports = Modal;
});
require.register("cozy-clearance/modal_share_template", function(exports, require, module){
function template(locals) {
var buf = [];
var jade_mixins = {};
var jade_interp;
;var locals_for_with = (locals || {});(function (t, type, model, clearance, makeURL, Object, possible_permissions) {
buf.push("<p>" + (jade.escape(null == (jade_interp = t('modal question ' + type + ' shareable', {name: model.get('name')})) ? "" : jade_interp)) + "</p><p><button id=\"share-public\" class=\"button btn-cozy\">" + (jade.escape(null == (jade_interp = t('public')) ? "" : jade_interp)) + "</button> <button id=\"share-private\" class=\"button btn-cozy\">" + (jade.escape(null == (jade_interp = t('private')) ? "" : jade_interp)) + "</button></p>");
if ( clearance == 'public')
{
buf.push("<p>" + (jade.escape(null == (jade_interp = t('modal shared ' + type + ' link msg')) ? "" : jade_interp)) + "</p><input id=\"public-url\"" + (jade.attr("value", makeURL(), true, false)) + " class=\"form-control\"/>");
}
else
{
buf.push("<p>" + (jade.escape(null == (jade_interp = t('only you can see')) ? "" : jade_interp)) + "</p><form role=\"form\" class=\"input-group\"><input id=\"share-input\" type=\"text\"" + (jade.attr("placeholder", t('modal shared ' + type + ' custom msg'), true, false)) + " class=\"form-control\"/><a id=\"add-contact\" class=\"btn btn-cozy\">Add</a></form><ul id=\"share-list\">");
// iterate clearance
;(function(){
var $$obj = clearance;
if ('number' == typeof $$obj.length) {
for (var i = 0, $$l = $$obj.length; i < $$l; i++) {
var rule = $$obj[i];
var key = rule.key
buf.push("<li class=\"clearance-line\">");
if ( rule.contact)
{
if ( rule.contact.get('hasPicture'))
{
buf.push("<img width=\"40\"" + (jade.attr("src", "clearance/contacts/" + rule.contact.id + ".jpg", true, false)) + "/> ");
}
else
{
buf.push("<img width=\"40\" src=\"images/defaultpicture.png\"/> ");
}
buf.push("<span class=\"clearance-name\">" + (jade.escape(null == (jade_interp = rule.contact.get('name')) ? "" : jade_interp)) + "</span>");
}
else
{
buf.push("<span class=\"clearance-name\">" + (jade.escape(null == (jade_interp = rule.email) ? "" : jade_interp)) + "</span>");
}
var keys = Object.keys(possible_permissions)
if ( keys.length > 1)
{
buf.push("<select" + (jade.attr("data-key", key, true, false)) + " class=\"changeperm\">");
// iterate possible_permissions
;(function(){
var $$obj = possible_permissions;
if ('number' == typeof $$obj.length) {
for (var perm = 0, $$l = $$obj.length; perm < $$l; perm++) {
var display = $$obj[perm];
buf.push("<option" + (jade.attr("value", perm, true, false)) + (jade.attr("selected", rule.perm==perm, true, false)) + ">" + (jade.escape(null == (jade_interp = ' ' + t('perm') + t(display)) ? "" : jade_interp)) + "</option>");
}
} else {
var $$l = 0;
for (var perm in $$obj) {
$$l++; var display = $$obj[perm];
buf.push("<option" + (jade.attr("value", perm, true, false)) + (jade.attr("selected", rule.perm==perm, true, false)) + ">" + (jade.escape(null == (jade_interp = ' ' + t('perm') + t(display)) ? "" : jade_interp)) + "</option>");
}
}
}).call(this);
buf.push("</select>");
}
else
{
buf.push(jade.escape(null == (jade_interp = ' ' + t('perm') + possible_permissions[keys[0]]) ? "" : jade_interp));
}
buf.push("<a" + (jade.attr("data-key", key, true, false)) + (jade.attr("title", t("revoke"), true, false)) + " class=\"clearance-btn pull-right revoke\"><i class=\"icon-remove\"></i></a><a" + (jade.attr("data-key", key, true, false)) + (jade.attr("title", t("see link"), true, false)) + (jade.attr("href", makeURL(key), true, false)) + " class=\"clearance-btn pull-right show-link\"><i class=\"glyphicon glyphicon-link\"></i></a></li>");
}
} else {
var $$l = 0;
for (var i in $$obj) {
$$l++; var rule = $$obj[i];
var key = rule.key
buf.push("<li class=\"clearance-line\">");
if ( rule.contact)
{
if ( rule.contact.get('hasPicture'))
{
buf.push("<img width=\"40\"" + (jade.attr("src", "clearance/contacts/" + rule.contact.id + ".jpg", true, false)) + "/> ");
}
else
{
buf.push("<img width=\"40\" src=\"images/defaultpicture.png\"/> ");
}
buf.push("<span class=\"clearance-name\">" + (jade.escape(null == (jade_interp = rule.contact.get('name')) ? "" : jade_interp)) + "</span>");
}
else
{
buf.push("<span class=\"clearance-name\">" + (jade.escape(null == (jade_interp = rule.email) ? "" : jade_interp)) + "</span>");
}
var keys = Object.keys(possible_permissions)
if ( keys.length > 1)
{
buf.push("<select" + (jade.attr("data-key", key, true, false)) + " class=\"changeperm\">");
// iterate possible_permissions
;(function(){
var $$obj = possible_permissions;
if ('number' == typeof $$obj.length) {
for (var perm = 0, $$l = $$obj.length; perm < $$l; perm++) {
var display = $$obj[perm];
buf.push("<option" + (jade.attr("value", perm, true, false)) + (jade.attr("selected", rule.perm==perm, true, false)) + ">" + (jade.escape(null == (jade_interp = ' ' + t('perm') + t(display)) ? "" : jade_interp)) + "</option>");
}
} else {
var $$l = 0;
for (var perm in $$obj) {
$$l++; var display = $$obj[perm];
buf.push("<option" + (jade.attr("value", perm, true, false)) + (jade.attr("selected", rule.perm==perm, true, false)) + ">" + (jade.escape(null == (jade_interp = ' ' + t('perm') + t(display)) ? "" : jade_interp)) + "</option>");
}
}
}).call(this);
buf.push("</select>");
}
else
{
buf.push(jade.escape(null == (jade_interp = ' ' + t('perm') + possible_permissions[keys[0]]) ? "" : jade_interp));
}
buf.push("<a" + (jade.attr("data-key", key, true, false)) + (jade.attr("title", t("revoke"), true, false)) + " class=\"clearance-btn pull-right revoke\"><i class=\"icon-remove\"></i></a><a" + (jade.attr("data-key", key, true, false)) + (jade.attr("title", t("see link"), true, false)) + (jade.attr("href", makeURL(key), true, false)) + " class=\"clearance-btn pull-right show-link\"><i class=\"glyphicon glyphicon-link\"></i></a></li>");
}
}
}).call(this);
buf.push("</ul>");
}}("t" in locals_for_with?locals_for_with.t:typeof t!=="undefined"?t:undefined,"type" in locals_for_with?locals_for_with.type:typeof type!=="undefined"?type:undefined,"model" in locals_for_with?locals_for_with.model:typeof model!=="undefined"?model:undefined,"clearance" in locals_for_with?locals_for_with.clearance:typeof clearance!=="undefined"?clearance:undefined,"makeURL" in locals_for_with?locals_for_with.makeURL:typeof makeURL!=="undefined"?makeURL:undefined,"Object" in locals_for_with?locals_for_with.Object:typeof Object!=="undefined"?Object:undefined,"possible_permissions" in locals_for_with?locals_for_with.possible_permissions:typeof possible_permissions!=="undefined"?possible_permissions:undefined));;return buf.join("");
}
module.exports = template;
});
require.register("cozy-clearance/modal_share_view", function(exports, require, module){
var CozyClearanceModal, Modal, clearanceDiff, contactCollection, contactTypeahead, randomString, request,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Modal = require("./modal");
contactTypeahead = require("./contact_autocomplete");
contactCollection = require("./contact_collection");
randomString = function(length) {
var string;
if (length == null) {
length = 32;
}
string = "";
while (string.length < length) {
string += Math.random().toString(36).substr(2);
}
return string.substr(0, length);
};
clearanceDiff = function(now, old) {
if (now === 'public') {
return [];
}
if (old === 'public') {
return now;
}
return now.filter(function(rule) {
return !_.findWhere(old, {
key: rule.key
});
});
};
request = function(method, url, data, options) {
var params;
params = {
method: method,
url: url,
dataType: 'json',
data: JSON.stringify(data),
contentType: 'application/json; charset=utf-8'
};
return $.ajax(_.extend(params, options));
};
module.exports = CozyClearanceModal = (function(_super) {
__extends(CozyClearanceModal, _super);
function CozyClearanceModal() {
this.showLink = __bind(this.showLink, this);
this.onClose = __bind(this.onClose, this);
this.onYes = __bind(this.onYes, this);
this.onNo = __bind(this.onNo, this);
this.revoke = __bind(this.revoke, this);
this.onGuestAdded = __bind(this.onGuestAdded, this);
this.getClearanceWithContacts = __bind(this.getClearanceWithContacts, this);
this.getRenderData = __bind(this.getRenderData, this);
this.typeaheadFilter = __bind(this.typeaheadFilter, this);
this.makeURL = __bind(this.makeURL, this);
return CozyClearanceModal.__super__.constructor.apply(this, arguments);
}
CozyClearanceModal.prototype.id = 'cozy-clearance-modal';
CozyClearanceModal.prototype.template_content = require('./modal_share_template');
CozyClearanceModal.prototype.events = function() {
return _.extend(CozyClearanceModal.__super__.events.apply(this, arguments), {
"click #share-public": "makePublic",
"click #share-private": "makePrivate",
'click #modal-dialog-share-save': 'onSave',
'click .revoke': 'revoke',
'click .show-link': 'showLink',
'click #add-contact': 'onAddClicked',
'change select.changeperm': 'changePerm'
});
};
CozyClearanceModal.prototype.permissions = function() {
return {
'r': t('r')
};
};
CozyClearanceModal.prototype.initialize = function(options) {
this.cb = this.onClose;
this.model = options.model;
this.model.set('clearance', this.model.get('clearance') || []);
this.initState = JSON.parse(JSON.stringify(this.model.get('clearance')));
this.title = t('sharing');
this.yes = t('save');
this.no = t('cancel');
return CozyClearanceModal.__super__.initialize.apply(this, arguments);
};
CozyClearanceModal.prototype.makeURL = function(key) {
var url;
url = this.model.getPublicURL();
if (key) {
url += '?key=' + key;
}
return url;
};
CozyClearanceModal.prototype.makePublic = function() {
if (this.model.get('clearance') === 'public') {
return;
}
this.lastPrivate = this.model.get('clearance');
this.model.set({
clearance: 'public'
});
return this.refresh();
};
CozyClearanceModal.prototype.makePrivate = function() {
if (Array.isArray(this.model.get('clearance'))) {
return;
}
this.model.set({
clearance: this.lastPrivate || []
});
return this.refresh();
};
CozyClearanceModal.prototype.render = function() {
var foot;
CozyClearanceModal.__super__.render.call(this);
foot = $('.modal-footer');
return foot.prepend($("<span class='pull-left'>" + (t('send email hint')) + "</span>"));
};
CozyClearanceModal.prototype.afterRender = function() {
var clearance;
clearance = this.model.get('clearance') || [];
if (clearance === 'public') {
this.$('#share-public').addClass('toggled');
} else {
this.$('#share-private').addClass('toggled');
contactTypeahead(this.$('#share-input'), this.onGuestAdded, this.typeaheadFilter);
}
return setTimeout((function(_this) {
return function() {
if (clearance === 'public') {
return _this.$('#public-url').focus().select();
} else {
return _this.$('input#share-input').select();
}
};
})(this), 100);
};
CozyClearanceModal.prototype.renderContent = function() {
return $('<p>Please wait</p>');
};
CozyClearanceModal.prototype.typeaheadFilter = function(item) {
return !this.existsEmail(item.toString().split(';')[0]);
};
CozyClearanceModal.prototype.existsEmail = function(email) {
return this.model.get('clearance').some(function(rule) {
return rule.email === email;
});
};
CozyClearanceModal.prototype.getRenderData = function() {
return {
type: this.model.get('type'),
model: this.model,
clearance: this.getClearanceWithContacts(),
makeURL: this.makeURL,
possible_permissions: this.permissions(),
t: t
};
};
CozyClearanceModal.prototype.getClearanceWithContacts = function() {
var clearance;
clearance = this.model.get('clearance') || [];
if (clearance === 'public') {
return 'public';
}
return clearance.map(function(rule) {
var out;
out = _.clone(rule);
if (out.contactid) {
out.contact = contactCollection.get(rule.contactid);
}
return out;
});
};
CozyClearanceModal.prototype.refresh = function() {
this.$('.modal-body').html(this.template_content(this.getRenderData()));
return this.afterRender();
};
CozyClearanceModal.prototype.onAddClicked = function() {
return this.onGuestAdded(this.$('#share-input').val());
};
CozyClearanceModal.prototype.onGuestAdded = function(result) {
var contactid, email, key, perm, _ref;
_ref = result.split(';'), email = _ref[0], contactid = _ref[1];
if (this.existsEmail(email)) {
return null;
}
key = randomString();
perm = 'r';
this.model.get('clearance').push({
email: email,
contactid: contactid,
key: key,
perm: perm
});
return this.refresh();
};
CozyClearanceModal.prototype.revoke = function(event) {
var clearance;
clearance = this.model.get('clearance').filter(function(rule) {
return rule.key !== event.currentTarget.dataset.key;
});
this.model.set({
clearance: clearance
});
return this.refresh();
};
CozyClearanceModal.prototype.changePerm = function(event) {
var select;
select = event.currentTarget;
this.model.get('clearance').filter(function(rule) {
return rule.key === select.dataset.key;
})[0].perm = select.options[select.selectedIndex].value;
return this.refresh();
};
CozyClearanceModal.prototype.onNo = function() {
var clearance, diffLength, diffNews, hasChanged;
clearance = this.model.get('clearance');
diffNews = clearanceDiff(clearance, this.initState).length !== 0;
diffLength = clearance.length !== this.initState.length;
hasChanged = diffNews || diffLength;
if (hasChanged) {
return Modal.confirm(t("confirm"), t('share confirm save'), t("yes"), t("no"), (function(_this) {
return function(confirmed) {
if (confirmed) {
return CozyClearanceModal.__super__.onNo.apply(_this, arguments);
}
};
})(this));
} else {
return CozyClearanceModal.__super__.onNo.apply(this, arguments);
}
};
CozyClearanceModal.prototype.onYes = function() {
var clearance, diffNews;
clearance = this.model.get('clearance');
diffNews = clearanceDiff(clearance, this.initState).length !== 0;
if (this.$('#share-input').val() && !diffNews) {
return Modal.confirm(t("confirm"), t('share forgot add'), t("no forgot"), t("yes forgot"), (function(_this) {
return function(confirmed) {
if (confirmed) {
return CozyClearanceModal.__super__.onYes.apply(_this, arguments);
}
};
})(this));
} else {
return CozyClearanceModal.__super__.onYes.apply(this, arguments);
}
};
CozyClearanceModal.prototype.onClose = function(saving) {
var newClearances, text;
if (!saving) {
return this.model.set({
clearance: this.initState
});
} else {
newClearances = clearanceDiff(this.model.get('clearance'), this.initState);
if (newClearances.length) {
text = t("send mails question") + newClearances.map(function(rule) {
return rule.email;
}).join(', ');
return Modal.confirm(t("modal send mails"), text, t("yes"), t("no"), (function(_this) {
return function(sendmail) {
return _this.doSave(sendmail, newClearances);
};
})(this));
} else {
return this.doSave(false);
}
}
};
CozyClearanceModal.prototype.doSave = function(sendmail, clearances) {
return request('PUT', "clearance/" + this.model.id, this.saveData(), {
error: function() {
return Modal.error('server error occured');
},
success: (function(_this) {
return function(data) {
_this.model.trigger('change');
if (!sendmail) {
return _this.$el.modal('hide');
} else {
return request('POST', "clearance/" + _this.model.id + "/send", clearances, {
error: function() {
return Modal.error('mail not send');
},
success: function(data) {
return _this.$el.modal('hide');
}
});
}
};
})(this)
});
};
CozyClearanceModal.prototype.saveData = function() {
return {
clearance: this.model.get('clearance')
};
};
CozyClearanceModal.prototype.showLink = function(event) {
var label, line, link, url, urlField;
line = $(event.target).parents('li');
if (line.find('.linkshow').length === 0) {
link = $(event.currentTarget);
url = link.prop('href');
line = $('<div class="linkshow">');
label = $('<label>').text(t('copy paste link'));
urlField = $('<input type="text">').val(url);
link.parents('li').append(line.append(label, urlField));
urlField.focus().select();
event.preventDefault();
} else {
line.find('.linkshow').remove();
}
return false;
};
return CozyClearanceModal;
})(Modal);
});