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
|
/*
* Copyright (c) 2015
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/
/* globals Clipboard, Handlebars */
(function() {
if (!OC.Share) {
OC.Share = {};
}
var PASSWORD_PLACEHOLDER = '**********';
var PASSWORD_PLACEHOLDER_MESSAGE = t('core', 'Choose a password for the public link');
var PASSWORD_PLACEHOLDER_MESSAGE_OPTIONAL = t('core', 'Choose a password for the public link or press the "Enter" key');
var TEMPLATE =
'{{#if shareAllowed}}' +
'<ul id="shareLink" class="shareWithList">' +
' <li data-share-id="{{cid}}">' +
' <div class="avatar icon-public-white"></div><span class="username" title="{{linkShareLabel}}">{{linkShareLabel}}</span>' +
' <span class="sharingOptionsGroup">' +
' <span class="shareOption"> ' +
' <span class="icon-loading-small hidden"></span>' +
' <input id="linkCheckbox-{{cid}}" {{#if isLinkShare}}checked="checked"{{/if}} type="checkbox" name="linkCheckbox" class="linkCheckbox permissions checkbox">' +
' <label for="linkCheckbox-{{cid}}">{{linkShareEnableLabel}}</label>' +
' </span>' +
' {{#if isLinkShare}}' +
' <div class="share-menu" tabindex="0"><span class="icon icon-more"></span>' +
' {{{popoverMenu}}}' +
' </div>' +
' {{/if}}' +
' </span>' +
' </li>' +
'</ul>' +
'{{else}}' +
// FIXME: this doesn't belong in this view
'{{#if noSharingPlaceholder}}<input id="shareWith-{{cid}}" class="shareWithField" type="text" placeholder="{{noSharingPlaceholder}}" disabled="disabled"/>{{/if}}' +
'{{/if}}'
;
var TEMPLATE_POPOVER_MENU =
'<div class="popovermenu menu">' +
'<ul>' +
'<li>' +
'<a href="#" class="menuitem clipboardButton" data-clipboard-text="{{shareLinkURL}}">' +
'<span class="icon icon-clippy" ></span>' +
'<span>{{copyLabel}}</span>' +
'</a>' +
'</li>' +
'<li class="hidden linkTextMenu">' +
'<span class="menuitem icon-link-text">' +
'<input id="linkText-{{cid}}" class="linkText" type="text" readonly="readonly" value="{{shareLinkURL}}" />' +
'</span>' +
'</li>' +
'{{#if publicUpload}}' +
'<li><span class="shareOption menuitem">' +
'<span class="icon-loading-small hidden"></span>' +
'<input type="radio" name="publicUpload" value="{{publicUploadRValue}}" id="sharingDialogAllowPublicUpload-r-{{cid}}" class="radio publicUploadRadio" {{{publicUploadRChecked}}} />' +
'<label for="sharingDialogAllowPublicUpload-r-{{cid}}">{{publicUploadRLabel}}</label>' +
'</span></li>' +
'<li><span class="shareOption menuitem">' +
'<span class="icon-loading-small hidden"></span>' +
'<input type="radio" name="publicUpload" value="{{publicUploadRWValue}}" id="sharingDialogAllowPublicUpload-rw-{{cid}}" class="radio publicUploadRadio" {{{publicUploadRWChecked}}} />' +
'<label for="sharingDialogAllowPublicUpload-rw-{{cid}}">{{publicUploadRWLabel}}</label>' +
'</span></li>' +
'<li><span class="shareOption menuitem">' +
'<span class="icon-loading-small hidden"></span>' +
'<input type="radio" name="publicUpload" value="{{publicUploadWValue}}" id="sharingDialogAllowPublicUpload-w-{{cid}}" class="radio publicUploadRadio" {{{publicUploadWChecked}}} />' +
'<label for="sharingDialogAllowPublicUpload-w-{{cid}}">{{publicUploadWLabel}}</label>' +
'</span></li>' +
'{{/if}}' +
'{{#if publicEditing}}' +
' <li id="allowPublicEditingWrapper"><span class="shareOption menuitem">' +
' <span class="icon-loading-small hidden"></span>' +
' <input type="checkbox" name="allowPublicEditing" id="sharingDialogAllowPublicEditing-{{cid}}" class="checkbox publicEditingCheckbox" {{{publicEditingChecked}}} />' +
' <label for="sharingDialogAllowPublicEditing-{{cid}}">{{publicEditingLabel}}</label>' +
' </span></li>' +
'{{/if}}' +
'{{#if showPasswordCheckBox}}' +
' <li><span class="shareOption menuitem">' +
' <input type="checkbox" name="showPassword" id="showPassword-{{cid}}" class="checkbox showPasswordCheckbox" {{#if isPasswordSet}}checked="checked"{{/if}} value="1" />' +
' <label for="showPassword-{{cid}}">{{enablePasswordLabel}}</label>' +
' </span></li>' +
' <li class="{{#unless isPasswordSet}}hidden{{/unless}} linkPassMenu"><span class="shareOption menuitem icon-share-pass">' +
' <input id="linkPassText-{{cid}}" class="linkPassText" type="password" placeholder="{{passwordPlaceholder}}" autocomplete="new-password" />' +
' <span class="icon icon-loading-small hidden"></span>' +
' </span></li>' +
'{{/if}}' +
'<li>' +
'<span class="shareOption menuitem">' +
'<input id="expireDate-{{cid}}" type="checkbox" name="expirationDate" class="expireDate checkbox" {{#if hasExpireDate}}checked="checked"{{/if}}" />' +
'<label for="expireDate-{{cid}}">{{expireDateLabel}}</label>' +
'</li>' +
'<li class="{{#unless hasExpireDate}}hidden{{/unless}}">' +
'<span class="menuitem icon-expiredate expirationDateContainer-{{cid}}">' +
' <label for="expirationDatePicker-{{cid}}" class="hidden-visually" value="{{expirationDate}}">{{expirationLabel}}</label>' +
' <input id="expirationDatePicker-{{cid}}" class="datepicker" type="text" placeholder="{{expirationDatePlaceholder}}" value="{{#if hasExpireDate}}{{expireDate}}{{else}}{{defaultExpireDate}}{{/if}}" />' +
'</span>' +
'</span>' +
'</li>' +
'<li>' +
'<a href="#" class="share-add"><span class="icon-loading-small hidden"></span>' +
' <span class="icon icon-edit"></span>' +
' <span>{{addNoteLabel}}</span>' +
' <input type="button" class="share-note-delete icon-delete">' +
'</a>' +
'</li>' +
'<li class="share-note-form share-note-link hidden">' +
'<span class="menuitem icon-note">' +
' <textarea class="share-note">{{shareNote}}</textarea>' +
' <input type="submit" class="icon-confirm share-note-submit" value="" id="add-note-{{shareId}}" />' +
'</span>' +
'</li>' +
'{{#each social}}' +
'<li>' +
'<a href="#" class="shareOption menuitem pop-up" data-url="{{url}}" data-window="{{newWindow}}">' +
'<span class="icon {{iconClass}}"' +
'></span><span>{{label}}' +
'</span>' +
'</a>' +
'</li>' +
'{{/each}}' +
'</ul>' +
'</div>';
/**
* @class OCA.Share.ShareDialogLinkShareView
* @member {OC.Share.ShareItemModel} model
* @member {jQuery} $el
* @memberof OCA.Sharing
* @classdesc
*
* Represents the GUI of the share dialogue
*
*/
var ShareDialogLinkShareView = OC.Backbone.View.extend({
/** @type {string} **/
id: 'shareDialogLinkShare',
/** @type {OC.Share.ShareConfigModel} **/
configModel: undefined,
/** @type {Function} **/
_template: undefined,
/** @type {Function} **/
_popoverMenuTemplate: undefined,
/** @type {boolean} **/
showLink: true,
events: {
'focusout input.linkPassText': 'onPasswordEntered',
'keyup input.linkPassText': 'onPasswordKeyUp',
'click .linkCheckbox': 'onLinkCheckBoxChange',
'click .linkText': 'onLinkTextClick',
'change .publicEditingCheckbox': 'onAllowPublicEditingChange',
'click .showPasswordCheckbox': 'onShowPasswordClick',
'click .share-menu .icon-more': 'onToggleMenu',
'click .pop-up': 'onPopUpClick',
'change .publicUploadRadio': 'onPublicUploadChange',
'click .expireDate' : 'onExpireDateChange',
'change .datepicker': 'onChangeExpirationDate',
'click .datepicker' : 'showDatePicker',
'click .share-add': 'showNoteForm',
'click .share-note-delete': 'deleteNote',
'click .share-note-submit': 'updateNote'
},
initialize: function(options) {
var view = this;
this.model.on('change:permissions', function() {
view.render();
});
this.model.on('change:itemType', function() {
view.render();
});
this.model.on('change:allowPublicUploadStatus', function() {
view.render();
});
this.model.on('change:hideFileListStatus', function() {
view.render();
});
this.model.on('change:linkShare', function() {
view.render();
});
if(!_.isUndefined(options.configModel)) {
this.configModel = options.configModel;
} else {
throw 'missing OC.Share.ShareConfigModel';
}
var clipboard = new Clipboard('.clipboardButton');
clipboard.on('success', function(e) {
var $menu = $(e.trigger);
var $linkTextMenu = $menu.parent().next('li.linkTextMenu')
$menu.tooltip('hide')
.attr('data-original-title', t('core', 'Copied!'))
.tooltip('fixTitle')
.tooltip({placement: 'bottom', trigger: 'manual'})
.tooltip('show');
_.delay(function() {
$menu.tooltip('hide');
$menu.tooltip('destroy');
}, 3000);
});
clipboard.on('error', function (e) {
var $menu = $(e.trigger);
var $linkTextMenu = $menu.parent().next('li.linkTextMenu')
var $input = $linkTextMenu.find('.linkText');
var actionMsg = '';
if (/iPhone|iPad/i.test(navigator.userAgent)) {
actionMsg = t('core', 'Not supported!');
} else if (/Mac/i.test(navigator.userAgent)) {
actionMsg = t('core', 'Press ⌘-C to copy.');
} else {
actionMsg = t('core', 'Press Ctrl-C to copy.');
}
$linkTextMenu.removeClass('hidden');
$input.select();
$input.tooltip('hide')
.attr('data-original-title', actionMsg)
.tooltip('fixTitle')
.tooltip({placement: 'bottom', trigger: 'manual'})
.tooltip('show');
_.delay(function () {
$input.tooltip('hide');
$input.attr('data-original-title', t('core', 'Copy'))
.tooltip('fixTitle');
}, 3000);
});
},
onLinkCheckBoxChange: function() {
var $checkBox = this.$el.find('.linkCheckbox');
var $loading = $checkBox.siblings('.icon-loading-small');
if(!$loading.hasClass('hidden')) {
return false;
}
if($checkBox.is(':checked')) {
if(this.configModel.get('enforcePasswordForPublicLink') === false && this.configModel.get('enableLinkPasswordByDefault') === false) {
$loading.removeClass('hidden');
// this will create it
this.model.saveLinkShare();
} else {
this.$el.find('.linkPass').slideToggle(OC.menuSpeed);
this.$el.find('.linkPassText').focus();
}
} else {
if (this.model.get('linkShare').isLinkShare) {
$loading.removeClass('hidden');
this.model.removeLinkShare();
} else {
this.$el.find('.linkPass').slideToggle(OC.menuSpeed);
}
}
},
onLinkTextClick: function() {
var $el = this.$el.find('.linkText');
$el.focus();
$el.select();
},
onShowPasswordClick: function() {
this.$el.find('.linkPass').slideToggle(OC.menuSpeed);
this.$el.find('.linkPassMenu').toggleClass('hidden');
if(!this.$el.find('.showPasswordCheckbox').is(':checked')) {
this.model.saveLinkShare({
password: ''
});
} else {
if (!OC.Util.isIE()) {
this.$el.find('.linkPassText').focus();
}
}
},
onPasswordKeyUp: function(event) {
if(event.keyCode === 13) {
this.onPasswordEntered();
}
},
onPasswordEntered: function() {
var $loading = this.$el.find('.linkPassMenu .icon-loading-small');
if (!$loading.hasClass('hidden')) {
// still in process
return;
}
var $input = this.$el.find('.linkPassText');
$input.removeClass('error');
var password = $input.val();
if (this.$el.find('.linkPassText').attr('placeholder') === PASSWORD_PLACEHOLDER_MESSAGE_OPTIONAL) {
// in IE9 the password might be the placeholder due to bugs in the placeholders polyfill
if(password === PASSWORD_PLACEHOLDER_MESSAGE_OPTIONAL) {
password = '';
}
} else {
// in IE9 the password might be the placeholder due to bugs in the placeholders polyfill
if(password === '' || password === PASSWORD_PLACEHOLDER || password === PASSWORD_PLACEHOLDER_MESSAGE) {
return;
}
}
$loading
.removeClass('hidden')
.addClass('inlineblock');
this.model.saveLinkShare({
password: password
}, {
complete: function(model) {
$loading.removeClass('inlineblock').addClass('hidden');
},
error: function(model, msg) {
// destroy old tooltips
$input.tooltip('destroy');
$input.addClass('error');
$input.attr('title', msg);
$input.tooltip({placement: 'bottom', trigger: 'manual'});
$input.tooltip('show');
}
});
},
onAllowPublicEditingChange: function() {
var $checkbox = this.$('.publicEditingCheckbox');
$checkbox.siblings('.icon-loading-small').removeClass('hidden').addClass('inlineblock');
var permissions = OC.PERMISSION_READ;
if($checkbox.is(':checked')) {
permissions = OC.PERMISSION_UPDATE | OC.PERMISSION_READ;
}
this.model.saveLinkShare({
permissions: permissions
});
},
onPublicUploadChange: function(e) {
var permissions = e.currentTarget.value;
this.model.saveLinkShare({
permissions: permissions
});
},
showNoteForm: function(event) {
event.preventDefault();
event.stopPropagation();
var self = this;
var $element = $(event.target);
var $li = $element.closest('li[data-share-id]');
var $menu = $element.closest('li');
var $form = $menu.next('li.share-note-form');
// show elements
$menu.find('.share-note-delete').toggle();
$form.toggleClass('hidden');
$form.find('textarea').focus();
},
deleteNote: function(event) {
event.preventDefault();
event.stopPropagation();
var self = this;
var $element = $(event.target);
var $li = $element.closest('li[data-share-id]');
var shareId = $li.data('share-id');
var $menu = $element.closest('li');
var $form = $menu.next('li.share-note-form');
console.log($form.find('.share-note'));
$form.find('.share-note').val('');
$form.addClass('hidden');
$menu.find('.share-note-delete').hide();
self.sendNote('', shareId, $menu);
},
updateNote: function(event) {
event.preventDefault();
event.stopPropagation();
var self = this;
var $element = $(event.target);
var $li = $element.closest('li[data-share-id]');
var shareId = $li.data('share-id');
var $form = $element.closest('li.share-note-form');
var $menu = $form.prev('li');
var message = $form.find('.share-note').val().trim();
if (message.length < 1) {
return;
}
self.sendNote(message, shareId, $menu);
},
sendNote: function(note, shareId, $menu) {
var $form = $menu.next('li.share-note-form');
var $submit = $form.find('input.share-note-submit');
var $error = $form.find('input.share-note-error');
$submit.prop('disabled', true);
$menu.find('.icon-loading-small').removeClass('hidden');
$menu.find('.icon-edit').hide();
var complete = function() {
$submit.prop('disabled', false);
$menu.find('.icon-loading-small').addClass('hidden');
$menu.find('.icon-edit').show();
};
var error = function() {
$error.show();
setTimeout(function() {
$error.hide();
}, 3000);
};
// send data
$.ajax({
method: 'PUT',
url: OC.linkToOCS('apps/files_sharing/api/v1/shares',2) + shareId + '?' + OC.buildQueryString({format: 'json'}),
data: { note: note },
complete : complete,
error: error
});
},
render: function() {
var linkShareTemplate = this.template();
var resharingAllowed = this.model.sharePermissionPossible();
if(!resharingAllowed
|| !this.showLink
|| !this.configModel.isShareWithLinkAllowed())
{
var templateData = {shareAllowed: false};
if (!resharingAllowed) {
// add message
templateData.noSharingPlaceholder = t('core', 'Resharing is not allowed');
}
this.$el.html(linkShareTemplate(templateData));
return this;
}
var publicUpload =
this.model.isFolder()
&& this.model.createPermissionPossible()
&& this.configModel.isPublicUploadEnabled();
var publicUploadRWChecked = '';
var publicUploadRChecked = '';
var publicUploadWChecked = '';
switch (this.model.linkSharePermissions()) {
case OC.PERMISSION_READ:
publicUploadRChecked = 'checked';
break;
case OC.PERMISSION_CREATE:
publicUploadWChecked = 'checked';
break;
case OC.PERMISSION_UPDATE | OC.PERMISSION_CREATE | OC.PERMISSION_READ | OC.PERMISSION_DELETE:
publicUploadRWChecked = 'checked';
break;
}
var publicEditingChecked = '';
if(this.model.isPublicEditingAllowed()) {
publicEditingChecked = 'checked="checked"';
}
var isLinkShare = this.model.get('linkShare').isLinkShare;
var isPasswordSet = !!this.model.get('linkShare').password;
var showPasswordCheckBox = isLinkShare
&& ( !this.configModel.get('enforcePasswordForPublicLink')
|| !this.model.get('linkShare').password);
var passwordPlaceholderInitial = this.configModel.get('enforcePasswordForPublicLink')
? PASSWORD_PLACEHOLDER_MESSAGE : PASSWORD_PLACEHOLDER_MESSAGE_OPTIONAL;
var publicEditable =
!this.model.isFolder()
&& isLinkShare
&& this.model.updatePermissionPossible();
var link = this.model.get('linkShare').link;
var social = [];
OC.Share.Social.Collection.each(function(model) {
var url = model.get('url');
url = url.replace('{{reference}}', link);
social.push({
url: url,
label: t('core', 'Share to {name}', {name: model.get('name')}),
name: model.get('name'),
iconClass: model.get('iconClass'),
newWindow: model.get('newWindow')
});
});
var defaultExpireDays = this.configModel.get('defaultExpireDate');
var isExpirationEnforced = this.configModel.get('isDefaultExpireDateEnforced');
var hasExpireDate = !!this.model.get('linkShare').expiration || isExpirationEnforced;
var expireDate;
if (hasExpireDate) {
expireDate = moment(this.model.get('linkShare').expiration, 'YYYY-MM-DD').format('DD-MM-YYYY');
}
// what if there is another date picker on that page?
var minDate = new Date();
var maxDate = null;
// min date should always be the next day
minDate.setDate(minDate.getDate()+1);
if(hasExpireDate) {
if(isExpirationEnforced) {
// TODO: hack: backend returns string instead of integer
var shareTime = this.model.get('linkShare').stime;
if (_.isNumber(shareTime)) {
shareTime = new Date(shareTime * 1000);
}
if (!shareTime) {
shareTime = new Date(); // now
}
shareTime = OC.Util.stripTime(shareTime).getTime();
maxDate = new Date(shareTime + defaultExpireDays * 24 * 3600 * 1000);
}
}
$.datepicker.setDefaults({
minDate: minDate,
maxDate: maxDate
});
this.$el.find('.datepicker').datepicker({dateFormat : 'dd-mm-yy'});
var popover = this.popoverMenuTemplate({
cid: this.model.get('linkShare').id,
copyLabel: t('core', 'Copy URL'),
social: social,
shareLinkURL: this.model.get('linkShare').link,
urlLabel: t('core', 'Link'),
enablePasswordLabel: t('core', 'Password protect'),
passwordLabel: t('core', 'Password'),
passwordPlaceholder: isPasswordSet ? PASSWORD_PLACEHOLDER : PASSWORD_PLACEHOLDER_MESSAGE,
passwordPlaceholderInitial: passwordPlaceholderInitial,
isPasswordSet: isPasswordSet,
showPasswordCheckBox: showPasswordCheckBox,
publicUpload: publicUpload && isLinkShare,
publicEditing: publicEditable,
publicEditingChecked: publicEditingChecked,
publicEditingLabel: t('core', 'Allow editing'),
mailPrivatePlaceholder: t('core', 'Email link to person'),
mailButtonText: t('core', 'Send'),
publicUploadRWLabel: t('core', 'Allow upload and editing'),
publicUploadRLabel: t('core', 'Read only'),
publicUploadWLabel: t('core', 'File drop (upload only)'),
publicUploadRWValue: OC.PERMISSION_UPDATE | OC.PERMISSION_CREATE | OC.PERMISSION_READ | OC.PERMISSION_DELETE,
publicUploadRValue: OC.PERMISSION_READ,
publicUploadWValue: OC.PERMISSION_CREATE,
publicUploadRWChecked: publicUploadRWChecked,
publicUploadRChecked: publicUploadRChecked,
publicUploadWChecked: publicUploadWChecked,
expireDateLabel: t('core', 'Set expiration date'),
expirationLabel: t('core', 'Expiration'),
expirationDatePlaceholder: t('core', 'Expiration date'),
hasExpireDate: hasExpireDate,
isExpirationEnforced: isExpirationEnforced,
expireDate: expireDate,
defaultExpireDate: moment().add(1, 'day').format('DD-MM-YYYY'), // Can't expire today
shareNote: this.model.get('linkShare').note,
addNoteLabel: t('core', 'Note to recipient'),
});
this.$el.html(linkShareTemplate({
cid: this.model.get('linkShare').id,
shareAllowed: true,
isLinkShare: isLinkShare,
linkShareLabel: t('core', 'Share link'),
linkShareEnableLabel: t('core', 'Enable'),
popoverMenu: popover,
}));
this.delegateEvents();
// new note autosize
autosize(this.$el.find('.share-note-form .share-note'));
return this;
},
onToggleMenu: function(event) {
event.preventDefault();
event.stopPropagation();
var $element = $(event.target);
var $li = $element.closest('li[data-share-id]');
var $menu = $li.find('.sharingOptionsGroup .popovermenu');
OC.showMenu(null, $menu);
this._menuOpen = $li.data('share-id');
},
/**
* @returns {Function} from Handlebars
* @private
*/
template: function () {
if (!this._template) {
this._template = Handlebars.compile(TEMPLATE);
}
return this._template;
},
/**
* renders the popover template and returns the resulting HTML
*
* @param {Object} data
* @returns {string}
*/
popoverMenuTemplate: function(data) {
if(!this._popoverMenuTemplate) {
this._popoverMenuTemplate = Handlebars.compile(TEMPLATE_POPOVER_MENU);
}
return this._popoverMenuTemplate(data);
},
onPopUpClick: function(event) {
event.preventDefault();
event.stopPropagation();
var url = $(event.currentTarget).data('url');
var newWindow = $(event.currentTarget).data('window');
$(event.currentTarget).tooltip('hide');
if (url) {
if (newWindow === true) {
var width = 600;
var height = 400;
var left = (screen.width / 2) - (width / 2);
var top = (screen.height / 2) - (height / 2);
window.open(url, 'name', 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left);
} else {
window.location.href = url;
}
}
},
onExpireDateChange: function(event) {
var $element = $(event.target);
var li = $element.closest('li[data-share-id]');
var shareId = li.data('share-id');
var expirationDatePicker = '#expirationDateContainer-' + shareId;
var datePicker = $(expirationDatePicker);
var state = $element.prop('checked');
datePicker.toggleClass('hidden', !state);
if (!state) {
// disabled, let's hide the input and
// set the expireDate to nothing
$element.closest('li').next('li').addClass('hidden');
this.setExpirationDate('');
} else {
// enabled, show the input and the datepicker
$element.closest('li').next('li').removeClass('hidden');
this.showDatePicker(event);
}
},
showDatePicker: function(event) {
var $element = $(event.target);
var li = $element.closest('li[data-share-id]');
var shareId = li.data('share-id');
var expirationDatePicker = '#expirationDatePicker-' + shareId;
var self = this;
$(expirationDatePicker).datepicker({
dateFormat : 'dd-mm-yy',
onSelect: function (expireDate) {
self.setExpirationDate(expireDate);
}
});
console.log(event, $(expirationDatePicker));
$(expirationDatePicker).datepicker('show');
$(expirationDatePicker).focus();
},
setExpirationDate: function(expireDate) {
this.model.saveLinkShare({expireDate: expireDate});
},
});
OC.Share.ShareDialogLinkShareView = ShareDialogLinkShareView;
})();
|