n?1:0})),b=null,P=w.length,_=(t=[],0);_0?(a.autocomplete("option","autoFocus",!0),e(t)):(console.info("no sharing recommendations found"),e())}).fail(function(e){console.error("could not load recommendations",e)})},autocompleteHandler:function(e,a){if(0===e.term.length)return console.info(e.term,"empty search term -> using recommendations"),void this.recommendationHandler(a);var s=$(".shareWithField"),i=this,l=this.$el.find(".shareWithLoading"),r=this.$el.find(".shareWithConfirm"),o=oc_config["sharing.minSearchStringLength"];if(e.term.trim().length0){if(s.autocomplete("option","autoFocus",!0),a(e),o){var d=t("core","This list is maybe truncated - please refine your search term to see more results.");$(".ui-autocomplete").append(''+d+"")}}else{var h=t("core","No users or groups found for {search}",{search:s.val()});i.configModel.get("allowGroupSharing")||(h=t("core","No users found for {search}",{search:$(".shareWithField").val()})),s.addClass("error").attr("data-original-title",h).tooltip("hide").tooltip({placement:"top",trigger:"manual"}).tooltip("fixTitle").tooltip("show"),a()}}).fail(function(e){i._pendingOperationsCount--,0===i._pendingOperationsCount&&(l.addClass("hidden"),l.removeClass("inlineblock"),r.removeClass("hidden")),e?OC.Notification.showTemporary(t("core",'An error occurred ("{message}"). Please try again',{message:e})):OC.Notification.showTemporary(t("core","An error occurred. Please try again"))})},autocompleteRenderItem:function(e,a){var n="icon-user",s=escapeHTML(a.label),i="",l="";void 0!==a.type&&null!==a.type&&(l=function(e){switch(e){case"HOME":return t("core","Home");case"WORK":return t("core","Work");case"OTHER":return t("core","Other");default:return""+e}}(a.type)+" "),void 0!==a.name&&(s=escapeHTML(a.name)),a.value.shareType===OC.Share.SHARE_TYPE_GROUP?n="icon-contacts-dark":a.value.shareType===OC.Share.SHARE_TYPE_REMOTE?(n="icon-shared",i+=a.value.shareWith):a.value.shareType===OC.Share.SHARE_TYPE_REMOTE_GROUP?(s=t("core","{sharee} (remote group)",{sharee:s},void 0,{escape:!1}),n="icon-shared",i+=a.value.shareWith):a.value.shareType===OC.Share.SHARE_TYPE_EMAIL?(n="icon-mail",i+=a.value.shareWith):a.value.shareType===OC.Share.SHARE_TYPE_CIRCLE?(s=t("core","{sharee} ({type}, {owner})",{sharee:s,type:a.value.circleInfo,owner:a.value.circleOwner},void 0,{escape:!1}),n="icon-circle"):a.value.shareType===OC.Share.SHARE_TYPE_ROOM&&(n="icon-talk");var r=$("");if(a.merged)r.addClass("merged"),s=a.value.shareWith,i=l;else if(a.lookup)s=a.label,n=!1,r.append('');else{var o=$("").appendTo(r);a.value.shareType===OC.Share.SHARE_TYPE_USER||a.value.shareType===OC.Share.SHARE_TYPE_CIRCLE?o.avatar(a.value.shareWith,32,void 0,void 0,void 0,a.label):(void 0===a.uuid&&(a.uuid=s),o.imageplaceholder(a.uuid,s,32)),i=l+i}return""!==i&&r.addClass("with-description"),$("").html(s.replace(new RegExp(this.term,"gi"),"$&")+''+i+"").appendTo(r),r.attr("title",a.value.shareWith),n&&r.append(''),r=$("").append(r),$("").addClass(a.value.shareType===OC.Share.SHARE_TYPE_GROUP?"group":"user").append(r).appendTo(e)},_onSelectRecipient:function(e,a){var t=this;if(9==e.keyCode)return e.preventDefault(),void 0!==a.item.name?e.target.value=a.item.name:e.target.value=a.item.label,setTimeout(function(){$(e.target).attr("disabled",!1).autocomplete("search",$(e.target).val())},0),!1;if(a.item.lookup){this._lookup=!0;var n=this.$el.find(".shareWithField"),s=n.val();return setTimeout(function(){console.debug("searching again, but globally. search term: "+s),n.autocomplete("search",s)},0),!1}e.preventDefault(),e.stopImmediatePropagation(),$(e.target).attr("disabled",!0).val(a.item.label);var i=this.$el.find(".shareWithLoading"),l=this.$el.find(".shareWithConfirm");i.removeClass("hidden"),i.addClass("inlineblock"),l.addClass("hidden"),this._pendingOperationsCount++,this.model.addShare(a.item.value,{success:function(){t._lastSuggestions=void 0,$(e.target).val("").attr("disabled",!1),t._pendingOperationsCount--,0===t._pendingOperationsCount&&(i.addClass("hidden"),i.removeClass("inlineblock"),l.removeClass("hidden"))},error:function(a,n){OC.Notification.showTemporary(n),$(e.target).attr("disabled",!1).autocomplete("search",$(e.target).val()),t._pendingOperationsCount--,0===t._pendingOperationsCount&&(i.addClass("hidden"),i.removeClass("inlineblock"),l.removeClass("hidden"))}})},_confirmShare:function(){var e=this,a=$(".shareWithField"),t=this.$el.find(".shareWithLoading"),n=this.$el.find(".shareWithConfirm");t.removeClass("hidden"),t.addClass("inlineblock"),n.addClass("hidden"),this._pendingOperationsCount++,a.prop("disabled",!0),a.autocomplete("close"),a.autocomplete("disable");var s=function(){e._pendingOperationsCount--,0===e._pendingOperationsCount&&(t.addClass("hidden"),t.removeClass("inlineblock"),n.removeClass("hidden")),a.prop("disabled",!1),a.focus()},i=parseInt(oc_config["sharing.maxAutocompleteResults"],10)||200;this._getSuggestions(a.val(),i,this.model,this._lookup).done(function(t,n){if(0===t.length)return s(),void a.autocomplete("enable");if(1!==n.length)return s(),void a.autocomplete("enable");e.model.addShare(n[0].value,{success:function(){e._lastSuggestions=void 0,a.val(""),s(),a.autocomplete("enable")},error:function(e,t){s(),a.autocomplete("enable"),OC.Notification.showTemporary(t)}})}).fail(function(e){s(),a.autocomplete("enable")})},_toggleLoading:function(e){this._loading=e,this.$el.find(".subView").toggleClass("hidden",e),this.$el.find(".loading").toggleClass("hidden",!e)},_onRequest:function(){this._loadingOnce||this._toggleLoading(!0)},_onEndRequest:function(){this._toggleLoading(!1),this._loadingOnce||(this._loadingOnce=!0)},render:function(){var e=this,a=OC.Share.Templates.sharedialogview;this.$el.html(a({cid:this.cid,shareLabel:t("core","Share"),sharePlaceholder:this._renderSharePlaceholderPart(),isSharingAllowed:this.model.sharePermissionPossible()}));var n=this.$el.find(".shareWithField");if(n.length){n.autocomplete({minLength:0,delay:750,focus:function(e){e.preventDefault()},source:this.autocompleteHandler,select:this._onSelectRecipient,open:function(){var e=$(this).autocomplete("widget"),a=e.find("li").size();e.removeClass("item-count-1"),e.removeClass("item-count-2"),a<=2&&e.addClass("item-count-"+a)}}).data("ui-autocomplete")._renderItem=this.autocompleteRenderItem,n.on("keydown",null,function(a){return 13!==a.keyCode||(e._confirmShare(),!1)})}return this.resharerInfoView.$el=this.$el.find(".resharerInfoView"),this.resharerInfoView.render(),this.linkShareView.$el=this.$el.find(".linkShareView"),this.linkShareView.render(),this.shareeListView.$el=this.$el.find(".shareeListView"),this.shareeListView.render(),this.$el.find(".hasTooltip").tooltip(),this},setShowLink:function(e){this._showLink="boolean"!=typeof e||e,this.linkShareView.showLink=this._showLink},_renderSharePlaceholderPart:function(){var e=this.configModel.get("isRemoteShareAllowed"),a=this.configModel.get("isMailShareAllowed");return!e&&a?t("core","Name or email address..."):e&&!a?t("core","Name or federated cloud ID..."):e&&a?t("core","Name, federated cloud ID or email address..."):t("core","Name...")}});OC.Share.ShareDialogView=e}()},function(e,a){OC.Share=_.extend(OC.Share||{},{SHARE_TYPE_USER:0,SHARE_TYPE_GROUP:1,SHARE_TYPE_LINK:3,SHARE_TYPE_EMAIL:4,SHARE_TYPE_REMOTE:6,SHARE_TYPE_CIRCLE:7,SHARE_TYPE_GUEST:8,SHARE_TYPE_REMOTE_GROUP:9,SHARE_TYPE_ROOM:10,_REMOTE_OWNER_REGEXP:new RegExp("^([^@]*)@(([^@]*)@)?([^/]*)([/](.*)?)?$"),itemShares:[],statuses:{},currentShares:{},droppedDown:!1,loadIcons:function(e,a,t){var n=a.dirInfo.path;"/"===n&&(n=""),n+="/"+a.dirInfo.name,$.get(OC.linkToOCS("apps/files_sharing/api/v1",2)+"shares",{subfiles:"true",path:n,format:"json"},function(n){n&&200===n.ocs.meta.statuscode&&(OC.Share.statuses={},$.each(n.ocs.data,function(e,a){a.item_source in OC.Share.statuses||(OC.Share.statuses[a.item_source]={link:!1}),a.share_type===OC.Share.SHARE_TYPE_LINK&&(OC.Share.statuses[a.item_source]={link:!0})}),_.isFunction(t)?t(OC.Share.statuses):OC.Share.updateIcons(e,a))})},updateIcons:function(e,a){var n,s,i;for(n in!a&&OCA.Files&&(a=OCA.Files.App.fileList),a&&(s=a.$fileList,i=a.getCurrentDirectory()),OC.Share.statuses){var l="icon-shared",r=OC.Share.statuses[n],o=r.link;if(o&&(l="icon-public"),"file"!==e&&"folder"!==e)$('a.share[data-item="'+n+'"] .icon').removeClass("icon-shared icon-public").addClass(l);else{var d,h=s.find('tr[data-id="'+n+'"]'),c=OC.imagePath("core","filetypes/folder-shared");if(h.length>0)this.markFileAsShared(h,!0,o);else{var u=i;if(u.length>1)for(var p="",m=u;m!=p;){if(m===r.path&&!r.link){var f,g=s.find('.fileactions .action[data-action="Share"]'),v=s.find(".filename");for(f=0;f "+t("core","Shared")+"").prepend(d));for(f=0;f0&&(t=!0,s="icon-shared")}),"file"!=e&&"folder"!=e)$('a.share[data-item="'+a+'"] .icon').removeClass("icon-shared icon-public").addClass(s);else{var i=$("tr").filterAttr("data-id",String(a));i.length>0&&i.each(function(){OC.Share.markFileAsShared($(this),t,n)})}t?(OC.Share.statuses[a]=OC.Share.statuses[a]||{},OC.Share.statuses[a].link=n):delete OC.Share.statuses[a]},_formatRemoteShare:function(e,a,t){var n=this._REMOTE_OWNER_REGEXP.exec(e);if(!n)return''+(''+t+" "+escapeHTML(a)+" ");var s=n[1],i=n[3],l=n[4],r=t+" "+s;i&&(r+="@"+i),l&&(i||(i="…"),r+="@"+l);var o='';return o+=''+escapeHTML(s)+"",i&&(o+='@'+escapeHTML(i)+""),o+=" "},_formatShareList:function(e){var a=this;return(e=_.toArray(e)).sort(function(e,a){return e.shareWithDisplayName.localeCompare(a.shareWithDisplayName)}),$.map(e,function(e){return a._formatRemoteShare(e.shareWith,e.shareWithDisplayName,t("core","Shared with"))})},markFileAsShared:function(e,a,n){var s,i,l,r,o=e.find('.fileactions .action[data-action="Share"]'),d=e.data("type"),h=o.find(".icon"),c=e.attr("data-share-owner-id"),u=e.attr("data-share-owner"),p=e.attr("data-mounttype"),m="icon-shared";if(o.removeClass("shared-style"),"dir"===d&&(a||n||c))r=void 0!==p&&"shared-root"!==p&&"shared"!==p?OC.MimeType.getIconUrl("dir-"+p):n?OC.MimeType.getIconUrl("dir-public"):OC.MimeType.getIconUrl("dir-shared"),e.find(".filename .thumbnail").css("background-image","url("+r+")"),e.attr("data-icon",r);else if("dir"===d){"true"===e.attr("data-e2eencrypted")?(r=OC.MimeType.getIconUrl("dir-encrypted"),e.attr("data-icon",r)):p&&0===p.indexOf("external")?(r=OC.MimeType.getIconUrl("dir-external"),e.attr("data-icon",r)):(r=OC.MimeType.getIconUrl("dir"),e.removeAttr("data-icon")),e.find(".filename .thumbnail").css("background-image","url("+r+")")}a||c?(i=e.data("share-recipient-data"),o.addClass("shared-style"),l=""+t("core","Shared")+"",c?(s=t("core","Shared by"),l=this._formatRemoteShare(c,u,s)):i&&(l=this._formatShareList(i)),o.html(l).prepend(h),(c||i)&&(o.find(".avatar").each(function(){$(this).avatar($(this).data("username"),32)}),o.find("span[title]").tooltip({placement:"top"}))):o.html(''+t("core","Shared")+"").prepend(h);n&&(m="icon-public"),h.removeClass("icon-shared icon-public").addClass(m)},showDropDown:function(e,a,t,n,s,i){var l=new OC.Share.ShareConfigModel,r={itemType:e,itemSource:a,possiblePermissions:s},o=new OC.Share.ShareItemModel(r,{configModel:l}),d=new OC.Share.ShareDialogView({id:"dropdown",model:o,configModel:l,className:"drop shareDropDown",attributes:{"data-item-source-name":i,"data-item-type":e,"data-item-source":a}});d.setShowLink(n);var h=d.render().$el;h.appendTo(t),h.slideDown(OC.menuSpeed,function(){OC.Share.droppedDown=!0}),o.fetch()},hideDropDown:function(e){OC.Share.currentShares=null,$("#dropdown").slideUp(OC.menuSpeed,function(){OC.Share.droppedDown=!1,$("#dropdown").remove(),"undefined"!=typeof FileActions&&$("tr").removeClass("mouseOver"),e&&e.call()})},dirname:function(e){return e.replace(/\\/g,"/").replace(/\/[^\/]*$/,"")}}),$(document).ready(function(){if("undefined"!=typeof monthNames){var e=new Date;e.setDate(e.getDate()+1),$.datepicker.setDefaults({monthNames:monthNames,monthNamesShort:monthNamesShort,dayNames:dayNames,dayNamesMin:dayNamesMin,dayNamesShort:dayNamesShort,firstDay:firstDay,minDate:e})}$(this).click(function(e){var a=$(e.target),t=!a.is(".drop, .ui-datepicker-next, .ui-datepicker-prev, .ui-icon")&&!a.closest("#ui-datepicker-div").length&&!a.closest(".ui-autocomplete").length;OC.Share&&OC.Share.droppedDown&&t&&0===$("#dropdown").has(e.target).length&&OC.Share.hideDropDown()})})}]);
//# sourceMappingURL=share_backend.js.map