nextcloud/apps/files_versions/js/files_versions.js

2 lines
18 KiB
JavaScript

!function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/js/",n(n.s=0)}([function(e,t,n){"use strict";n.r(t);n(1),n(2),n(3),n(4),n(5),n(6);window.OCA.Versions=OCA.Versions},function(e,t){var n;n=OC.Backbone.Model.extend({sync:OC.Backbone.davSync,davProperties:{size:"{DAV:}getcontentlength",mimetype:"{DAV:}getcontenttype",timestamp:"{DAV:}getlastmodified"},revert:function(e){e=e?_.clone(e):{};var t=this;return this.get("client").move("/versions/"+this.get("fileId")+"/"+this.get("id"),"/restore/target",!0).done(function(){e.success&&e.success.call(e.context,t,{},e),t.trigger("revert",t,e)}).fail(function(){e.error&&e.error.call(e.context,t,{},e),t.trigger("error",t,{},e)})},getFullPath:function(){return this.get("fullPath")},getPreviewUrl:function(){var e=OC.generateUrl("/apps/files_versions/preview"),t={file:this.get("fullPath"),version:this.get("timestamp")};return e+"?"+OC.buildQueryString(t)},getDownloadUrl:function(){return OC.linkToRemoteBase("dav")+"/versions/"+this.get("user")+"/versions/"+this.get("fileId")+"/"+this.get("id")}}),OCA.Versions=OCA.Versions||{},OCA.Versions.VersionModel=n},function(e,t){function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var i,r;i=Handlebars.template,(r=OCA.Versions.Templates=OCA.Versions.Templates||{}).item=i({1:function(e,t,i,r,o){var s,l=null!=t?t:e.nullContext||{},a=i.helperMissing,c=e.escapeExpression;return'\t\t\t\t<div class="version-details">\n\t\t\t\t\t<span class="size has-tooltip" title="'+c("function"===n(s=null!=(s=i.altSize||(null!=t?t.altSize:t))?s:a)?s.call(l,{name:"altSize",hash:{},data:o}):s)+'">'+c("function"===n(s=null!=(s=i.humanReadableSize||(null!=t?t.humanReadableSize:t))?s:a)?s.call(l,{name:"humanReadableSize",hash:{},data:o}):s)+"</span>\n\t\t\t\t</div>\n"},3:function(e,t,i,r,o){var s,l=null!=t?t:e.nullContext||{},a=i.helperMissing,c=e.escapeExpression;return'\t\t\t<a href="#" class="revertVersion" title="'+c("function"===n(s=null!=(s=i.revertLabel||(null!=t?t.revertLabel:t))?s:a)?s.call(l,{name:"revertLabel",hash:{},data:o}):s)+'"><img src="'+c("function"===n(s=null!=(s=i.revertIconUrl||(null!=t?t.revertIconUrl:t))?s:a)?s.call(l,{name:"revertIconUrl",hash:{},data:o}):s)+'" /></a>\n'},compiler:[7,">= 4.0.0"],main:function(e,t,i,r,o){var s,l,a,c=null!=t?t:e.nullContext||{},u=i.helperMissing,f="function",d=e.escapeExpression,p=i.blockHelperMissing,h='<li data-revision="'+d(n(l=null!=(l=i.timestamp||(null!=t?t.timestamp:t))?l:u)===f?l.call(c,{name:"timestamp",hash:{},data:o}):l)+'">\n\t<div>\n\t\t<div class="preview-container">\n\t\t\t<img class="preview" src="'+d(n(l=null!=(l=i.previewUrl||(null!=t?t.previewUrl:t))?l:u)===f?l.call(c,{name:"previewUrl",hash:{},data:o}):l)+'" width="44" height="44"/>\n\t\t</div>\n\t\t<div class="version-container">\n\t\t\t<div>\n\t\t\t\t<a href="'+d(n(l=null!=(l=i.downloadUrl||(null!=t?t.downloadUrl:t))?l:u)===f?l.call(c,{name:"downloadUrl",hash:{},data:o}):l)+'" class="downloadVersion" download="'+d(n(l=null!=(l=i.downloadName||(null!=t?t.downloadName:t))?l:u)===f?l.call(c,{name:"downloadName",hash:{},data:o}):l)+'"><img src="'+d(n(l=null!=(l=i.downloadIconUrl||(null!=t?t.downloadIconUrl:t))?l:u)===f?l.call(c,{name:"downloadIconUrl",hash:{},data:o}):l)+'" />\n\t\t\t\t\t<span class="versiondate has-tooltip live-relative-timestamp" data-timestamp="'+d(n(l=null!=(l=i.millisecondsTimestamp||(null!=t?t.millisecondsTimestamp:t))?l:u)===f?l.call(c,{name:"millisecondsTimestamp",hash:{},data:o}):l)+'" title="'+d(n(l=null!=(l=i.formattedTimestamp||(null!=t?t.formattedTimestamp:t))?l:u)===f?l.call(c,{name:"formattedTimestamp",hash:{},data:o}):l)+'">'+d(n(l=null!=(l=i.relativeTimestamp||(null!=t?t.relativeTimestamp:t))?l:u)===f?l.call(c,{name:"relativeTimestamp",hash:{},data:o}):l)+"</span>\n\t\t\t\t</a>\n\t\t\t</div>\n";return l=null!=(l=i.hasDetails||(null!=t?t.hasDetails:t))?l:u,a={name:"hasDetails",hash:{},fn:e.program(1,o,0),inverse:e.noop,data:o},s=n(l)===f?l.call(c,a):l,i.hasDetails||(s=p.call(t,s,a)),null!=s&&(h+=s),h+="\t\t</div>\n",l=null!=(l=i.canRevert||(null!=t?t.canRevert:t))?l:u,a={name:"canRevert",hash:{},fn:e.program(3,o,0),inverse:e.noop,data:o},s=n(l)===f?l.call(c,a):l,i.canRevert||(s=p.call(t,s,a)),null!=s&&(h+=s),h+"\t</div>\n</li>\n"},useData:!0}),r.template=i({compiler:[7,">= 4.0.0"],main:function(e,t,i,r,o){var s,l=null!=t?t:e.nullContext||{},a=i.helperMissing,c=e.escapeExpression;return'<ul class="versions"></ul>\n<div class="clear-float"></div>\n<div class="empty hidden">\n\t<div class="emptycontent">\n\t\t<div class="icon-history"></div>\n\t\t<p>'+c("function"===n(s=null!=(s=i.emptyResultLabel||(null!=t?t.emptyResultLabel:t))?s:a)?s.call(l,{name:"emptyResultLabel",hash:{},data:o}):s)+'</p>\n\t</div>\n</div>\n<input type="button" class="showMoreVersions hidden" value="'+c("function"===n(s=null!=(s=i.moreVersionsLabel||(null!=t?t.moreVersionsLabel:t))?s:a)?s.call(l,{name:"moreVersionsLabel",hash:{},data:o}):s)+'" name="show-more-versions" id="show-more-versions" />\n<div class="loading hidden" style="height: 50px"></div>\n'},useData:!0})},function(e,t){var n;n=OC.Backbone.Collection.extend({model:OCA.Versions.VersionModel,sync:OC.Backbone.davSync,_fileInfo:null,_currentUser:null,_client:null,setFileInfo:function(e){this._fileInfo=e},getFileInfo:function(){return this._fileInfo},setCurrentUser:function(e){this._currentUser=e},getCurrentUser:function(){return this._currentUser||OC.getCurrentUser().uid},setClient:function(e){this._client=e},getClient:function(){return this._client||new OC.Files.Client({host:OC.getHost(),root:OC.linkToRemoteBase("dav")+"/versions/"+this.getCurrentUser(),useHTTPS:"https"===OC.getProtocol()})},url:function(){return OC.linkToRemoteBase("dav")+"/versions/"+this.getCurrentUser()+"/versions/"+this._fileInfo.get("id")},parse:function(e){var t=this._fileInfo.getFullPath(),n=this._fileInfo.get("id"),i=this._fileInfo.get("name"),r=this.getCurrentUser(),o=this.getClient();return _.map(e,function(e){return e.fullPath=t,e.fileId=n,e.name=i,e.timestamp=parseInt(moment(new Date(e.timestamp)).format("X"),10),e.id=parseInt(OC.basename(e.href),10),e.size=parseInt(e.size,10),e.user=r,e.client=o,e})}}),OCA.Versions=OCA.Versions||{},OCA.Versions.VersionCollection=n},function(e,i){var r;r=OCA.Files.DetailTabView.extend({id:"versionsTabView",className:"tab versionsTabView",_template:null,$versionsContainer:null,events:{"click .revertVersion":"_onClickRevertVersion"},initialize:function(){OCA.Files.DetailTabView.prototype.initialize.apply(this,arguments),this.collection=new OCA.Versions.VersionCollection,this.collection.on("request",this._onRequest,this),this.collection.on("sync",this._onEndRequest,this),this.collection.on("update",this._onUpdate,this),this.collection.on("error",this._onError,this),this.collection.on("add",this._onAddModel,this)},getLabel:function(){return t("files_versions","Versions")},getIcon:function(){return"icon-history"},nextPage:function(){this._loading||this.collection.getFileInfo()&&this.collection.getFileInfo().isDirectory()||this.collection.fetch()},_onClickRevertVersion:function(e){var n,i=this,r=$(e.target),o=this.collection.getFileInfo();r.is("li")||(r=r.closest("li")),e.preventDefault(),n=r.attr("data-revision");var s=this.collection.get(n);s.revert({success:function(){i.$versionsContainer.empty(),i.collection.setFileInfo(o),i.collection.reset([],{silent:!0}),i.collection.fetch(),i.$el.find(".versions").removeClass("hidden"),o.trigger("busy",o,!1),o.set({size:s.get("size"),mtime:1e3*s.get("timestamp"),etag:s.get("id")+s.get("timestamp")})},error:function(){o.trigger("busy",o,!1),i.$el.find(".versions").removeClass("hidden"),i._toggleLoading(!1),OC.Notification.show(t("files_version","Failed to revert {file} to revision {timestamp}.",{file:s.getFullPath(),timestamp:OC.Util.formatDate(1e3*s.get("timestamp"))}),{type:"error"})}}),this._toggleLoading(!0),o.trigger("busy",o,!0)},_toggleLoading:function(e){this._loading=e,this.$el.find(".loading").toggleClass("hidden",!e)},_onRequest:function(){this._toggleLoading(!0)},_onEndRequest:function(){this._toggleLoading(!1),this.$el.find(".empty").toggleClass("hidden",!!this.collection.length)},_onAddModel:function(e){var t=$(this.itemTemplate(this._formatItem(e)));this.$versionsContainer.append(t),t.find(".has-tooltip").tooltip()},template:function(e){return OCA.Versions.Templates.template(e)},itemTemplate:function(e){return OCA.Versions.Templates.item(e)},setFileInfo:function(e){e?(this.render(),this.collection.setFileInfo(e),this.collection.reset([],{silent:!0}),this.nextPage()):(this.render(),this.collection.reset())},_formatItem:function(e){var i=1e3*e.get("timestamp"),r=e.has("size")?e.get("size"):0,o=OC.MimeType.getIconUrl(e.get("mimetype")),s=new Image;return s.onload=function(){$("li[data-revision="+e.get("timestamp")+"] .preview").attr("src",e.getPreviewUrl())},s.src=e.getPreviewUrl(),_.extend({versionId:e.get("id"),formattedTimestamp:OC.Util.formatDate(i),relativeTimestamp:OC.Util.relativeModifiedDate(i),millisecondsTimestamp:i,humanReadableSize:OC.Util.humanFileSize(r,!0),altSize:n("files","%n byte","%n bytes",r),hasDetails:e.has("size"),downloadUrl:e.getDownloadUrl(),downloadIconUrl:OC.imagePath("core","actions/download"),downloadName:e.get("name"),revertIconUrl:OC.imagePath("core","actions/history"),previewUrl:o,revertLabel:t("files_versions","Restore"),canRevert:0!=(this.collection.getFileInfo().get("permissions")&OC.PERMISSION_UPDATE)},e.attributes)},render:function(){this.$el.html(this.template({emptyResultLabel:t("files_versions","No other versions available")})),this.$el.find(".has-tooltip").tooltip(),this.$versionsContainer=this.$el.find("ul.versions"),this.delegateEvents()},canDisplay:function(e){return!!e&&!e.isDirectory()}}),OCA.Versions=OCA.Versions||{},OCA.Versions.VersionsTabView=r},function(e,t){OCA.Versions=OCA.Versions||{},OCA.Versions.Util={attach:function(e){"trashbin"!==e.id&&"files.public"!==e.id&&e.registerTabView(new OCA.Versions.VersionsTabView("versionsTabView",{order:-10}))}},OC.Plugins.register("OCA.Files.FileList",OCA.Versions.Util)},function(e,t,n){var i=n(7);"string"==typeof i&&(i=[[e.i,i,""]]);var r={hmr:!0,transform:void 0,insertInto:void 0};n(9)(i,r);i.locals&&(e.exports=i.locals)},function(e,t,n){(e.exports=n(8)(!1)).push([e.i,".versionsTabView .clear-float {\n\tclear: both;\n}\n\n.versionsTabView li {\n\twidth: 100%;\n\tcursor: default;\n\theight: 56px;\n\tfloat: left;\n\tborder-bottom: 1px solid rgba(100,100,100,.1);\n}\n.versionsTabView li:last-child {\n\tborder-bottom: none;\n}\n\n.versionsTabView a,\n.versionsTabView div > span {\n\tvertical-align: middle;\n\topacity: .5;\n}\n\n.versionsTabView li a{\n\tpadding: 15px 10px 11px;\n}\n\n.versionsTabView a:hover,\n.versionsTabView a:focus {\n\topacity: 1;\n}\n\n.versionsTabView .preview-container {\n\tdisplay: inline-block;\n vertical-align: top;\n}\n\n.versionsTabView img {\n\tcursor: pointer;\n\tpadding-right: 4px;\n}\n\n.versionsTabView img.preview {\n\tcursor: default;\n}\n\n.versionsTabView .version-container {\n\tdisplay: inline-block;\n}\n\n.versionsTabView .versiondate {\n\tmin-width: 100px;\n\tvertical-align: super;\n}\n\n.versionsTabView .version-details {\n\ttext-align: left;\n}\n\n.versionsTabView .version-details > span {\n\tpadding: 0 10px;\n}\n\n.versionsTabView .revertVersion {\n\tcursor: pointer;\n\tfloat: right;\n\tmargin-right: -10px;\n}\n",""])},function(e,t,n){"use strict";e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var n=function(e,t){var n=e[1]||"",i=e[3];if(!i)return n;if(t&&"function"==typeof btoa){var r=(s=i,"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(s))))+" */"),o=i.sources.map(function(e){return"/*# sourceURL="+i.sourceRoot+e+" */"});return[n].concat(o).concat([r]).join("\n")}var s;return[n].join("\n")}(t,e);return t[2]?"@media "+t[2]+"{"+n+"}":n}).join("")},t.i=function(e,n){"string"==typeof e&&(e=[[null,e,""]]);for(var i={},r=0;r<this.length;r++){var o=this[r][0];null!=o&&(i[o]=!0)}for(r=0;r<e.length;r++){var s=e[r];null!=s[0]&&i[s[0]]||(n&&!s[2]?s[2]=n:n&&(s[2]="("+s[2]+") and ("+n+")"),t.push(s))}},t}},function(e,t,n){var i,r,o={},s=(i=function(){return window&&document&&document.all&&!window.atob},function(){return void 0===r&&(r=i.apply(this,arguments)),r}),l=function(e){var t={};return function(e,n){if("function"==typeof e)return e();if(void 0===t[e]){var i=function(e,t){return t?t.querySelector(e):document.querySelector(e)}.call(this,e,n);if(window.HTMLIFrameElement&&i instanceof window.HTMLIFrameElement)try{i=i.contentDocument.head}catch(e){i=null}t[e]=i}return t[e]}}(),a=null,c=0,u=[],f=n(10);function d(e,t){for(var n=0;n<e.length;n++){var i=e[n],r=o[i.id];if(r){r.refs++;for(var s=0;s<r.parts.length;s++)r.parts[s](i.parts[s]);for(;s<i.parts.length;s++)r.parts.push(b(i.parts[s],t))}else{var l=[];for(s=0;s<i.parts.length;s++)l.push(b(i.parts[s],t));o[i.id]={id:i.id,refs:1,parts:l}}}}function p(e,t){for(var n=[],i={},r=0;r<e.length;r++){var o=e[r],s=t.base?o[0]+t.base:o[0],l={css:o[1],media:o[2],sourceMap:o[3]};i[s]?i[s].parts.push(l):n.push(i[s]={id:s,parts:[l]})}return n}function h(e,t){var n=l(e.insertInto);if(!n)throw new Error("Couldn't find a style target. This probably means that the value for the 'insertInto' parameter is invalid.");var i=u[u.length-1];if("top"===e.insertAt)i?i.nextSibling?n.insertBefore(t,i.nextSibling):n.appendChild(t):n.insertBefore(t,n.firstChild),u.push(t);else if("bottom"===e.insertAt)n.appendChild(t);else{if("object"!=typeof e.insertAt||!e.insertAt.before)throw new Error("[Style Loader]\n\n Invalid value for parameter 'insertAt' ('options.insertAt') found.\n Must be 'top', 'bottom', or Object.\n (https://github.com/webpack-contrib/style-loader#insertat)\n");var r=l(e.insertAt.before,n);n.insertBefore(t,r)}}function m(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e);var t=u.indexOf(e);t>=0&&u.splice(t,1)}function v(e){var t=document.createElement("style");if(void 0===e.attrs.type&&(e.attrs.type="text/css"),void 0===e.attrs.nonce){var i=function(){0;return n.nc}();i&&(e.attrs.nonce=i)}return g(t,e.attrs),h(e,t),t}function g(e,t){Object.keys(t).forEach(function(n){e.setAttribute(n,t[n])})}function b(e,t){var n,i,r,o;if(t.transform&&e.css){if(!(o="function"==typeof t.transform?t.transform(e.css):t.transform.default(e.css)))return function(){};e.css=o}if(t.singleton){var s=c++;n=a||(a=v(t)),i=C.bind(null,n,s,!1),r=C.bind(null,n,s,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=function(e){var t=document.createElement("link");return void 0===e.attrs.type&&(e.attrs.type="text/css"),e.attrs.rel="stylesheet",g(t,e.attrs),h(e,t),t}(t),i=function(e,t,n){var i=n.css,r=n.sourceMap,o=void 0===t.convertToAbsoluteUrls&&r;(t.convertToAbsoluteUrls||o)&&(i=f(i));r&&(i+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(r))))+" */");var s=new Blob([i],{type:"text/css"}),l=e.href;e.href=URL.createObjectURL(s),l&&URL.revokeObjectURL(l)}.bind(null,n,t),r=function(){m(n),n.href&&URL.revokeObjectURL(n.href)}):(n=v(t),i=function(e,t){var n=t.css,i=t.media;i&&e.setAttribute("media",i);if(e.styleSheet)e.styleSheet.cssText=n;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(n))}}.bind(null,n),r=function(){m(n)});return i(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;i(e=t)}else r()}}e.exports=function(e,t){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(t=t||{}).attrs="object"==typeof t.attrs?t.attrs:{},t.singleton||"boolean"==typeof t.singleton||(t.singleton=s()),t.insertInto||(t.insertInto="head"),t.insertAt||(t.insertAt="bottom");var n=p(e,t);return d(n,t),function(e){for(var i=[],r=0;r<n.length;r++){var s=n[r];(l=o[s.id]).refs--,i.push(l)}e&&d(p(e,t),t);for(r=0;r<i.length;r++){var l;if(0===(l=i[r]).refs){for(var a=0;a<l.parts.length;a++)l.parts[a]();delete o[l.id]}}}};var y,w=(y=[],function(e,t){return y[e]=t,y.filter(Boolean).join("\n")});function C(e,t,n,i){var r=n?"":i.css;if(e.styleSheet)e.styleSheet.cssText=w(t,r);else{var o=document.createTextNode(r),s=e.childNodes;s[t]&&e.removeChild(s[t]),s.length?e.insertBefore(o,s[t]):e.appendChild(o)}}},function(e,t){e.exports=function(e){var t="undefined"!=typeof window&&window.location;if(!t)throw new Error("fixUrls requires window.location");if(!e||"string"!=typeof e)return e;var n=t.protocol+"//"+t.host,i=n+t.pathname.replace(/\/[^\/]*$/,"/");return e.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi,function(e,t){var r,o=t.trim().replace(/^"(.*)"$/,function(e,t){return t}).replace(/^'(.*)'$/,function(e,t){return t});return/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(o)?e:(r=0===o.indexOf("//")?o:0===o.indexOf("/")?n+o:i+o.replace(/^\.\//,""),"url("+JSON.stringify(r)+")")})}}]);
//# sourceMappingURL=files_versions.js.map