4747 ' <input id="linkPassText-{{cid}}" class="linkPassText" type="password" placeholder="{{passwordPlaceholder}}" />' +
4848 ' <span class="icon-loading-small hidden"></span>' +
4949 '</div>' +
50+ ' {{#if mailPublicNotificationEnabled}}' +
51+ '<form id="emailPrivateLink" class="emailPrivateLinkForm">' +
52+ ' <input id="email" class="emailField" value="{{email}}" placeholder="{{mailPrivatePlaceholder}}" type="text" />' +
53+ ' <input id="emailButton" class="emailButton" type="submit" value="{{mailButtonText}}" />' +
54+ '</form>' +
55+ ' {{/if}}' +
5056 '{{else}}' +
51- // FIXME: this doesn't belong in this view
57+ // FIXME: this doesn't belong in this view
5258 '{{#if noSharingPlaceholder}}<input id="shareWith-{{cid}}" class="shareWithField" type="text" placeholder="{{noSharingPlaceholder}}" disabled="disabled"/>{{/if}}' +
5359 '{{/if}}'
5460 ;
7783 showLink : true ,
7884
7985 events : {
86+ 'submit .emailPrivateLinkForm' : '_onEmailPrivateLink' ,
8087 'focusout input.linkPassText' : 'onPasswordEntered' ,
8188 'keyup input.linkPassText' : 'onPasswordKeyUp' ,
8289 'click .linkCheckbox' : 'onLinkCheckBoxChange' ,
117124
118125 _ . bindAll (
119126 this ,
127+ '_onEmailPrivateLink' ,
120128 'onLinkCheckBoxChange' ,
121129 'onPasswordEntered' ,
122130 'onPasswordKeyUp' ,
237245 } ) ;
238246 } ,
239247
248+ _onEmailPrivateLink : function ( event ) {
249+ event . preventDefault ( ) ;
250+
251+ var $emailField = this . $el . find ( '.emailField' ) ;
252+ var $emailButton = this . $el . find ( '.emailButton' ) ;
253+ var email = $emailField . val ( ) ;
254+ if ( email !== '' ) {
255+ $emailField . prop ( 'disabled' , true ) ;
256+ $emailButton . prop ( 'disabled' , true ) ;
257+ $emailField . val ( t ( 'core' , 'Sending ...' ) ) ;
258+ this . model . sendEmailPrivateLink ( email ) . done ( function ( ) {
259+ $emailField . css ( 'font-weight' , 'bold' ) . val ( t ( 'core' , 'Email sent' ) ) ;
260+ setTimeout ( function ( ) {
261+ $emailField . val ( '' ) ;
262+ $emailField . css ( 'font-weight' , 'normal' ) ;
263+ $emailField . prop ( 'disabled' , false ) ;
264+ $emailButton . prop ( 'disabled' , false ) ;
265+ } , 2000 ) ;
266+ } ) . fail ( function ( ) {
267+ $emailField . val ( email ) ;
268+ $emailField . css ( 'font-weight' , 'normal' ) ;
269+ $emailField . prop ( 'disabled' , false ) ;
270+ $emailButton . prop ( 'disabled' , false ) ;
271+ } ) ;
272+ }
273+ return false ;
274+ } ,
275+
240276 render : function ( ) {
241277 var linkShareTemplate = this . template ( ) ;
242278 var resharingAllowed = this . model . sharePermissionPossible ( ) ;
279+ var email = this . $el . find ( '.emailField' ) . val ( ) ;
243280
244281 if ( ! resharingAllowed
245282 || ! this . showLink
297334 hideFileListLabel : t ( 'core' , 'Hide file listing' ) ,
298335 mailPublicNotificationEnabled : isLinkShare && this . configModel . isMailPublicNotificationEnabled ( ) ,
299336 mailPrivatePlaceholder : t ( 'core' , 'Email link to person' ) ,
300- mailButtonText : t ( 'core' , 'Send' )
337+ mailButtonText : t ( 'core' , 'Send' ) ,
338+ email : email
301339 } ) ) ;
302340
341+ var $emailField = this . $el . find ( '.emailField' ) ;
342+ if ( isLinkShare && $emailField . length !== 0 ) {
343+ $emailField . autocomplete ( {
344+ minLength : 1 ,
345+ source : function ( search , response ) {
346+ $ . get (
347+ OC . generateUrl ( 'core/ajax/share.php' ) , {
348+ fetch : 'getShareWithEmail' ,
349+ search : search . term
350+ } , function ( result ) {
351+ if ( result . status == 'success' && result . data . length > 0 ) {
352+ response ( result . data ) ;
353+ }
354+ } ) ;
355+ } ,
356+ select : function ( event , item ) {
357+ $emailField . val ( item . item . email ) ;
358+ return false ;
359+ }
360+ } )
361+ . data ( "ui-autocomplete" ) . _renderItem = function ( ul , item ) {
362+ return $ ( '<li>' )
363+ . append ( '<a>' + escapeHTML ( item . displayname ) + "<br>" + escapeHTML ( item . email ) + '</a>' )
364+ . appendTo ( ul ) ;
365+ } ;
366+ }
367+
368+ // TODO drop with IE8 drop
369+ if ( $ ( 'html' ) . hasClass ( 'ie8' ) ) {
370+ this . $el . find ( '#linkPassText' ) . removeAttr ( 'placeholder' ) ;
371+ this . $el . find ( '#linkPassText' ) . val ( '' ) ;
372+ }
373+
303374 this . delegateEvents ( ) ;
304375
305376 return this ;
320391
321392 OC . Share . ShareDialogLinkShareView = ShareDialogLinkShareView ;
322393
323- } ) ( ) ;
394+ } ) ( ) ;
0 commit comments