| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535 |
- Ext.namespace('MODx.browser');
- MODx.Browser = function(config) {
- if (MODx.browserOpen && !config.multiple) return false;
- if (!config.multiple) MODx.browserOpen = true;
- config = config || {};
- Ext.applyIf(config,{
- onSelect: function(data) {}
- ,scope: this
- ,source: config.source || 1
- ,cls: 'modx-browser'
- ,closeAction: 'hide'
- });
- MODx.Browser.superclass.constructor.call(this,config);
- this.config = config;
- this.win = new MODx.browser.Window(config);
- this.win.reset();
- };
- Ext.extend(MODx.Browser,Ext.Component,{
- show: function(el) { if (this.win) { this.win.show(el); } }
- ,hide: function() { if (this.win) { this.win.hide(); } }
- ,setSource: function(source) {
- this.config.source = source;
- this.win.tree.config.baseParams.source = source;
- this.win.view.config.baseParams.source = source;
- }
- });
- Ext.reg('modx-browser',MODx.Browser);
- MODx.browser.View = function(config) {
- config = config || {};
- this.ident = config.ident+'-view' || 'modx-browser-'+Ext.id()+'-view';
- this._initTemplates();
- Ext.applyIf(config,{
- url: MODx.config.connector_url
- ,id: this.ident
- ,fields: [
- {name: 'name', sortType: Ext.data.SortTypes.asUCString}
- ,'cls','url','relativeUrl','fullRelativeUrl','image','image_width','image_height','thumb','thumb_width','thumb_height','pathname','pathRelative','ext','disabled','preview'
- ,{name: 'size', type: 'float'}
- ,{name: 'lastmod', type: 'date', dateFormat: 'timestamp'}
- ,'menu'
- ]
- ,baseParams: {
- action: 'browser/directory/getfiles'
- ,prependPath: config.prependPath || null
- ,prependUrl: config.prependUrl || null
- ,source: config.source || 1
- // @todo: this overrides the media source configuration
- ,allowedFileTypes: config.allowedFileTypes || ''
- ,wctx: config.wctx || 'web'
- ,dir: config.openTo || ''
- }
- ,tpl: MODx.config.modx_browser_default_viewmode === 'list' ? this.templates.list : this.templates.thumb
- ,itemSelector: MODx.config.modx_browser_default_viewmode === 'list' ? 'div.modx-browser-list-item' : 'div.modx-browser-thumb-wrap'
- ,thumbnails: []
- ,lazyLoad: function() {
- var height = this.getEl().parent().getHeight() + 100;
- for (var i = 0; i < this.thumbnails.length; i++) {
- var image = this.thumbnails[i];
- if (image !== undefined) {
- var rect = image.getBoundingClientRect();
- if (rect.top >= 0 && rect.left >= 0 && rect.top <= height) {
- image.src = image.getAttribute('data-src');
- delete(this.thumbnails[i]);
- }
- }
- }
- }
- ,refresh: function() {
- MODx.DataView.prototype.refresh.call(this);
- this.thumbnails = Array.prototype.slice.call(document.querySelectorAll('img[data-src]'));
- this.lazyLoad();
- }
- ,listeners: {
- 'selectionchange': {fn:this.showDetails, scope:this, buffer:100}
- ,'dblclick': config.onSelect || {fn:Ext.emptyFn,scope:this}
- ,'render': {fn:this.sortStore, scope:this}
- ,'afterrender': {
- fn: function() {
- this.getEl().parent().on('scroll', function() {
- this.lazyLoad();
- }, this);
- }, scope:this
- }
- }
- ,prepareData: this.formatData.createDelegate(this)
- });
- MODx.browser.View.superclass.constructor.call(this,config);
- };
- Ext.extend(MODx.browser.View,MODx.DataView,{
- templates: {}
- ,run: function(p) {
- p = p || {};
- if (p.dir) { this.dir = p.dir; }
- Ext.applyIf(p,{
- action: 'browser/directory/getFiles'
- ,dir: this.dir
- ,source: this.config.source || MODx.config.default_media_source
- });
- this.store.load({
- params: p
- ,callback: function() {
- this.refresh();
- // reset the bottom filepath bar
- Ext.getCmp(this.ident+'-filepath').setValue('');
- this.select(0);
- }
- ,scope: this
- });
- }
- ,editFile: function(item,e) {
- var node = this.cm.activeNode;
- var data = this.lookup[node.id];
- MODx.loadPage('system/file/edit', 'file='+data.pathRelative+'&source='+this.config.source);
- }
- ,quickUpdateFile: function(item,e) {
- var node = this.cm.activeNode;
- var data = this.lookup[node.id];
- MODx.Ajax.request({
- url: MODx.config.connector_url
- ,params: {
- action: 'browser/file/get'
- ,file: data.pathRelative
- ,wctx: MODx.ctx || ''
- ,source: this.config.source
- }
- ,listeners: {
- 'success': {fn:function(response) {
- var r = {
- file: data.pathRelative
- ,name: data.name
- ,path: data.pathRelative
- ,source: this.config.source
- ,content: response.object.content
- };
- var w = MODx.load({
- xtype: 'modx-window-file-quick-update'
- ,record: r
- ,listeners: {
- 'hide':{fn:function() {this.destroy();}}
- }
- });
- w.show(e.target);
- },scope:this}
- }
- });
- }
- ,renameFile: function(item,e) {
- var node = this.cm.activeNode;
- var data = this.lookup[node.id];
- var r = {
- old_name: data.name
- ,name: data.name
- ,path: data.pathRelative
- ,source: this.config.source
- };
- var w = MODx.load({
- xtype: 'modx-window-file-rename'
- ,record: r
- ,listeners: {
- 'success':{fn:function(r) {
- this.config.tree.refreshParentNode();
- this.run();
- },scope:this}
- ,'hide':{fn:function() {
- this.destroy();}
- }
- }
- });
- w.show(e.target);
- }
- ,downloadFile: function(item,e) {
- var node = this.cm.activeNode;
- var data = this.lookup[node.id];
- MODx.Ajax.request({
- url: MODx.config.connector_url
- ,params: {
- action: 'browser/file/download'
- ,file: data.pathRelative
- ,wctx: MODx.ctx || ''
- ,source: this.config.source
- }
- ,listeners: {
- 'success':{fn:function(r) {
- if (!Ext.isEmpty(r.object.url)) {
- location.href = MODx.config.connector_url+'?action=browser/file/download&download=1&file='+data.pathRelative+'&HTTP_MODAUTH='+MODx.siteId+'&source='+this.config.source+'&wctx='+MODx.ctx;
- }
- },scope:this}
- }
- });
- }
- ,copyRelativePath: function(item,e) {
- var node = this.cm.activeNode;
- var data = this.lookup[node.id];
- var dummyRelativePathInput = document.createElement("input");
- document.body.appendChild(dummyRelativePathInput);
- dummyRelativePathInput.setAttribute('value', data.pathRelative);
- dummyRelativePathInput.select();
- document.execCommand("copy");
- document.body.removeChild(dummyRelativePathInput);
- }
- ,removeFile: function(item,e) {
- var node = this.cm.activeNode;
- var data = this.lookup[node.id];
- // var d = '';
- // if (typeof(this.dir) != 'object' && typeof(this.dir) != 'undefined') { d = this.dir; }
- MODx.msg.confirm({
- text: _('file_remove_confirm')
- ,url: MODx.config.connector_url
- ,params: {
- action: 'browser/file/remove'
- ,file: data.pathRelative
- ,source: this.config.source
- ,wctx: this.config.wctx || 'web'
- }
- ,listeners: {
- 'success': {fn:function(r) {
- this.config.tree.refreshParentNode();
- this.run();
- },scope:this}
- }
- });
- }
- ,setTemplate: function(tpl) {
- if (tpl === 'list') {
- this.tpl = this.templates.list;
- this.itemSelector = 'div.modx-browser-list-item';
- } else {
- this.tpl = this.templates.thumb;
- this.itemSelector = 'div.modx-browser-thumb-wrap';
- }
- this.refresh();
- this.select(0);
- }
- ,sortStore: function() {
- var v = MODx.config.modx_browser_default_sort || 'name'
- this.store.sort(v, v == 'name' ? 'ASC' : 'DESC');
- this.select(0);
- }
- ,showDetails: function() {
- var node = this.getSelectedNodes();
- var detailPanel = Ext.getCmp(this.config.ident+'-img-detail-panel').body;
- var okBtn = Ext.getCmp(this.ident+'-ok-btn');
- if (node && node.length > 0) {
- node = node[0];
- if (okBtn) {
- okBtn.enable();
- }
- var data = this.lookup[node.id];
- // sync the selected file in browser view and tree
- // we have to take care of the tree loosing sync after a file is deleted
- // and this.config.tree.getNodeById(data.pathRelative) being undefined
- if (this.config.tree.getNodeById(data.pathRelative)) {
- // this is necessary to prevent the whole tree from refreshing
- // e.g. like this we set the correct activeNode which is then used to determine the parent node
- this.config.tree.cm.activeNode = this.config.tree.getNodeById(data.pathRelative);
- // and this to have the visual syncing of selected items in browser view and tree
- this.config.tree.getSelectionModel().select(this.config.tree.getNodeById(data.pathRelative));
- }
- // keeps the bottom filepath bar in sync with the selected file
- Ext.getCmp(this.ident+'-filepath').setValue((data.fullRelativeUrl.indexOf('http') === -1 ? '/' : '')+data.fullRelativeUrl);
- detailPanel.hide();
- this.templates.details.overwrite(detailPanel, data);
- detailPanel.slideIn('l', {stopFx:true,duration:'.2'});
- } else {
- if (okBtn) {
- okBtn.disable();
- }
- detailPanel.update('');
- }
- }
- ,showFullView: function(name,ident) {
- var data = this.lookup[name];
- if (!data) return;
- if (!this.fvWin) {
- this.fvWin = new Ext.Window({
- layout:'fit'
- ,width: 600
- ,height: 450
- ,bodyStyle: 'padding: 0;'
- ,closeAction: 'hide'
- ,plain: true
- ,items: [{
- id: this.ident+'modx-view-item-full'
- ,cls: 'modx-browser-fullview'
- ,html: ''
- }]
- ,buttons: [{
- text: _('close')
- ,cls: 'primary-button'
- ,handler: function() { this.fvWin.hide(); }
- ,scope: this
- }]
- });
- }
- this.fvWin.show();
- var ratio = data.image_width > 800 ? 800/data.image_width : 1;
- var w = data.image_width < 250 ? 250 : (data.image_width > 800 ? 800 : data.image_width);
- var hfit = (data.image_height*ratio)+this.fvWin.footer.dom.clientHeight+1+this.fvWin.header.dom.clientHeight+1; // +1 for the borders
- var h = data.image_height < 200 ? 200 : (data.image_height > 600 ? (hfit > 600 ? 600 : hfit) : data.image_height);
- this.fvWin.setSize(w,h);
- this.fvWin.center();
- this.fvWin.setTitle(data.name);
- Ext.get(this.ident+'modx-view-item-full').update('<img src="'+data.image+'" width="'+data.image_width+'" height="'+data.image_height+'" alt="'+data.name+'" title="'+data.name+'" class="modx-browser-fullview-img" onclick="Ext.getCmp(\''+ident+'\').fvWin.hide();" />');
- }
- ,formatData: function(data) {
- var formatSize = function(size){
- if(size < 1024) {
- return size + " bytes";
- } else {
- return (Math.round(((size*10) / 1024))/10) + " KB";
- }
- };
- data.shortName = Ext.util.Format.ellipsis(data.name,18);
- data.sizeString = data.size != 0 ? formatSize(data.size) : 0;
- data.imageSizeString = data.preview != 0 ? data.image_width + "x" + data.image_height + "px": 0;
- data.imageSizeString = data.imageSizeString === "xpx" ? 0 : data.imageSizeString;
- data.dateString = !Ext.isEmpty(data.lastmod) ? new Date(data.lastmod).format(MODx.config.manager_date_format + " " + MODx.config.manager_time_format) : 0;
- this.lookup[data.name] = data;
- return data;
- }
- ,_initTemplates: function() {
- this.templates.thumb = new Ext.XTemplate(
- '<tpl for=".">'
- ,'<div class="modx-browser-thumb-wrap" id="{name}" title="{name}">'
- ,' <div class="modx-browser-thumb">'
- ,' <img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" ' +
- 'data-src="{thumb}" width="{thumb_width}" height="{thumb_height}" alt="{name}" title="{name}" />'
- ,' </div>'
- ,' <span>{shortName}</span>'
- ,'</div>'
- ,'</tpl>'
- );
- this.templates.thumb.compile();
- this.templates.list = new Ext.XTemplate(
- '<tpl for=".">'
- ,'<div class="modx-browser-list-item" id="{name}">'
- ,' <span class="icon icon-file {cls}">'
- ,' <span class="file-name">{name}</span>'
- ,' <tpl if="sizeString !== 0">'
- ,' <span class="file-size">{sizeString}</span>'
- ,' </tpl>'
- ,' <tpl if="imageSizeString !== 0">'
- ,' <span class="image-size">{imageSizeString}</span>'
- ,' </tpl>'
- ,' </span>'
- ,'</div>'
- ,'</tpl>'
- );
- this.templates.list.compile();
- this.templates.details = new Ext.XTemplate(
- '<div class="details">'
- ,' <tpl for=".">'
- ,' <tpl if="preview === 1">'
- ,' <div class="modx-browser-detail-thumb preview" onclick="Ext.getCmp(\''+this.ident+'\').showFullView(\'{name}\',\''+this.ident+'\'); return false;">'
- ,' <img src="{image}" width="{image_width}" height="{image_height}" alt="{name}" title="{name}" />'
- ,' </div>'
- ,' </tpl>'
- ,' <tpl if="preview === 0">'
- ,' <div class="modx-browser-detail-thumb">'
- ,' <img src="{image}" alt="" />'
- ,' </div>'
- ,' </tpl>'
- ,' <div class="modx-browser-details-info">'
- ,' <b>'+_('file_name')+':</b>'
- ,' <span>{name}</span>'
- ,' <tpl if="sizeString !== 0">'
- ,' <b>'+_('file_size')+':</b>'
- ,' <span>{sizeString}</span>'
- ,' </tpl>'
- ,' <tpl if="imageSizeString !== 0">'
- ,' <b>'+_('image_size')+':</b>'
- ,' <span>{imageSizeString}</span>'
- ,' </tpl>'
- ,' <tpl if="dateString !== 0">'
- ,' <b>'+_('last_modified')+':</b>'
- ,' <span>{dateString}</span>'
- ,' </tpl>'
- ,' </div>'
- ,' </tpl>'
- ,'</div>'
- );
- this.templates.details.compile();
- }
- });
- Ext.reg('modx-browser-view',MODx.browser.View);
- /**
- * This is the regular media browser window that opens when clicking on an image or file TV for example
- */
- MODx.browser.Window = function(config) {
- config = config || {};
- this.ident = Ext.id();
- // Hide the "MODX Browser" toolbar button
- MODx.browserOpen = true;
- // Tree navigation
- this.tree = MODx.load({
- xtype: 'modx-tree-directory'
- ,onUpload: function() {
- this.view.run();
- }
- ,scope: this
- ,source: config.source || MODx.config.default_media_source
- ,hideFiles: config.hideFiles || MODx.config.modx_browser_tree_hide_files
- ,hideTooltips: config.hideTooltips || MODx.config.modx_browser_tree_hide_tooltips || true // by default do not request image preview tooltips in the media browser
- ,openTo: config.openTo || ''
- ,ident: this.ident
- ,rootId: config.rootId || '/'
- ,rootName: _('files')
- ,rootVisible: config.rootVisible == undefined || !Ext.isEmpty(config.rootId)
- ,id: this.ident+'-tree'
- ,hideSourceCombo: config.hideSourceCombo || false
- ,useDefaultToolbar: false
- ,listeners: {
- 'afterUpload': {
- fn: function() {
- this.view.run();
- }
- ,scope: this
- }
- ,'afterQuickCreate': {
- fn: function() {
- this.view.run();
- }
- ,scope: this
- }
- ,'afterRename': {
- fn: function() {
- this.view.run();
- }
- ,scope: this
- }
- ,'afterRemove': {
- fn: function() {
- this.view.run();
- }
- ,scope: this
- }
- ,'changeSource': {
- fn: function(s) {
- this.config.source = s;
- this.view.config.source = s;
- this.view.baseParams.source = s;
- this.view.dir = '/';
- this.view.run();
- }
- ,scope: this
- }
- ,'afterrender': {
- fn: function(tree) {
- tree.root.expand();
- }
- ,scope: this
- }
- ,'beforeclick': {
- fn: function(node, e) {
- // load the node/folder that is clicked on but prevent unnecessary requests when a file is clicked
- if (!node.leaf) {
- this.load(node.id);
- } else {
- // sync the selected item in the tree with the one in browser view
- // the id of a browser view node in the store is the full absolute URL
- // but there is a bug with urlAbsolute, see #11821 that's why we prepend a slash
- this.view.select(this.view.store.indexOfId('/' + node.attributes.url));
- // but instead load the container the file resides in if not already displayed
- if (this.view.dir !== node.parentNode.id) {
- this.load(node.parentNode.id);
- }
- return false;
- }
- }
- ,scope: this
- }
- }
- });
- // DataView
- this.view = MODx.load({
- xtype: 'modx-browser-view'
- ,onSelect: {
- fn: this.onSelect
- ,scope: this
- }
- ,source: config.source || MODx.config.default_media_source
- ,allowedFileTypes: config.allowedFileTypes || ''
- ,wctx: config.wctx || 'web'
- ,openTo: config.openTo || ''
- ,ident: this.ident
- ,id: this.ident+'-view'
- ,tree: this.tree
- });
- Ext.applyIf(config,{
- title: _('modx_browser')+' ('+(MODx.ctx ? MODx.ctx : 'web')+')'
- ,cls: 'modx-browser modx-browser-window'
- ,layout: 'border'
- ,minWidth: 500
- ,minHeight: 300
- ,width: '90%'
- ,height: Ext.getBody().getViewSize().height * 0.9
- ,modal: false
- ,closeAction: 'hide'
- ,border: false
- ,items: [{
- id: this.ident+'-browser-tree'
- ,cls: 'modx-browser-tree'
- ,region: 'west'
- ,width: 250
- ,height: '100%'
- ,items: this.tree
- ,autoScroll: true
- ,split: true
- ,border: false
- },{
- id: this.ident+'-browser-view'
- ,cls: 'modx-browser-view-ct'
- ,region: 'center'
- ,autoScroll: true
- //,width: 635
- ,border: false
- ,items: this.view
- ,tbar: this.getToolbar()
- ,bbar: this.getPathbar()
- },{
- id: this.ident+'-img-detail-panel'
- ,cls: 'modx-browser-details-ct'
- ,region: 'east'
- ,split: true
- ,border: false
- ,width: 250
- }]
- ,buttons: [{
- id: this.ident+'-cancel-btn'
- ,text: _('cancel')
- ,handler: this.close
- ,scope: this
- },{
- id: this.ident+'-ok-btn'
- ,text: _('ok')
- ,cls: 'primary-button'
- ,handler: this.onSelect
- ,scope: this
- }]
- ,keys: {
- key: 27
- ,handler: this.hide
- ,scope: this
- }
- });
- MODx.browser.Window.superclass.constructor.call(this,config);
- this.config = config;
- this.addEvents({
- 'select': true
- });
- };
- Ext.extend(MODx.browser.Window,Ext.Window,{
- returnEl: null
- /**
- * Filter the DataView results
- */
- ,filter : function() {
- var filter = Ext.getCmp(this.ident+'filter');
- this.view.store.filter('name', filter.getValue(), true);
- this.view.select(0);
- }
- /**
- * Load the given directory in the DataView
- *
- * @param {String} dir
- */
- ,load: function(dir) {
- dir = dir || (Ext.isEmpty(this.config.openTo) ? '' : this.config.openTo);
- this.view.run({
- dir: dir
- ,source: this.config.source
- ,allowedFileTypes: this.config.allowedFileTypes || ''
- ,wctx: this.config.wctx || 'web'
- });
- this.sortStore();
- }
- /**
- * Sort the DataView results
- */
- ,sortStore: function(){
- var v = Ext.getCmp(this.ident+'sortSelect').getValue();
- this.view.store.sort(v, v == 'name' ? 'ASC' : 'DESC');
- this.view.select(0);
- }
- /**
- * Switch viewmode from grid to list and vice versa
- */
- ,changeViewmode: function() {
- var v = Ext.getCmp(this.ident+'viewSelect').getValue();
- this.view.setTemplate(v);
- this.view.select(0);
- }
- /**
- * Remove any filter applied to the DataView
- */
- ,reset: function() {
- if (this.rendered) {
- Ext.getCmp(this.ident+'filter').reset();
- this.view.getEl().dom.scrollTop = 0;
- }
- this.view.store.clearFilter();
- this.view.select(0);
- }
- /**
- * Get the browser view toolbar configuration
- *
- * @returns {Array}
- */
- ,getToolbar: function() {
- return [{
- text: _('filter')+':'
- ,xtype: 'label'
- },{
- xtype: 'textfield'
- ,id: this.ident+'filter'
- ,selectOnFocus: true
- ,width: 200
- ,listeners: {
- 'render': {
- fn: function() {
- Ext.getCmp(this.ident+'filter').getEl().on('keyup', function() {
- this.filter();
- }, this, {buffer: 500});
- }
- ,scope: this
- }
- }
- },{
- text: _('sort_by')+':'
- ,xtype: 'label'
- },{
- id: this.ident+'sortSelect'
- ,xtype: 'combo'
- ,typeAhead: true
- ,triggerAction: 'all'
- ,width: 130
- ,editable: false
- ,mode: 'local'
- ,displayField: 'desc'
- ,valueField: 'name'
- ,lazyInit: false
- ,value: MODx.config.modx_browser_default_sort || 'name'
- ,store: new Ext.data.SimpleStore({
- fields: ['name', 'desc'],
- data : [
- ['name', _('name')]
- ,['size', _('file_size')]
- ,['lastmod', _('last_modified')]
- ]
- })
- ,listeners: {
- 'select': {
- fn: this.sortStore
- ,scope: this
- }
- }
- }, '-', {
- text: _('files_viewmode')+':'
- ,xtype: 'label'
- }, '-', {
- id: this.ident+'viewSelect'
- ,xtype: 'combo'
- ,typeAhead: false
- ,triggerAction: 'all'
- ,width: 100
- ,editable: false
- ,mode: 'local'
- ,displayField: 'desc'
- ,valueField: 'type'
- ,lazyInit: false
- ,value: MODx.config.modx_browser_default_viewmode || 'grid'
- ,store: new Ext.data.SimpleStore({
- fields: ['type', 'desc'],
- data : [
- ['grid', _('files_viewmode_grid')]
- ,['list', _('files_viewmode_list')]
- ]
- })
- ,listeners: {
- 'select': {
- fn: this.changeViewmode
- ,scope: this
- }
- }
- }];
- }
- /**
- * Get the bottom filepath textfield in the browser view
- *
- * @returns {Array}
- */
- ,getPathbar: function() {
- return {
- cls: 'modx-browser-pathbbar'
- ,items: [{
- xtype: 'textfield'
- ,id: this.ident+'-filepath'
- ,cls: 'modx-browser-filepath'
- ,listeners: {
- 'focus': {
- // select the filepath on focus
- fn: function(el) {
- // let the focus event stick first, needed for webkit primarily
- setTimeout(function () {
- var field = el.getEl().dom;
- if (field.createTextRange) {
- var selRange = field.createTextRange();
- selRange.collapse(true);
- selRange.moveStart('character', 0);
- selRange.moveEnd('character', field.value.length);
- selRange.select();
- } else if (field.setSelectionRange) {
- field.setSelectionRange(0, field.value.length);
- } else if (field.selectionStart) {
- field.selectionStart = 0;
- field.selectionEnd = field.value.length;
- }
- }, 50);
- }
- ,scope: this
- }
- }
- }]
- };
- }
- ,setReturn: function(el) {
- this.returnEl = el;
- }
- ,onSelect: function(data) {
- var selNode = this.view.getSelectedNodes()[0];
- var callback = this.config.onSelect || this.onSelectHandler;
- var lookup = this.view.lookup;
- var scope = this.config.scope;
- this.hide(this.config.animEl || null,function(){
- if(selNode && callback){
- var data = lookup[selNode.id];
- Ext.callback(callback,scope || this,[data]);
- this.fireEvent('select',data);
- }
- },scope);
- }
- ,onSelectHandler: function(data) {
- Ext.get(this.returnEl).dom.value = unescape(data.url);
- }
- });
- Ext.reg('modx-browser-window',MODx.browser.Window);
- /**
- * This is an attempt to extract the MODx.Browser.Window as a whole "component/page" found under Media > Media Browser
- *
- * @param {Object} config
- *
- * @extends Ext.Container
- * @xtype modx-media-view
- */
- MODx.Media = function(config) {
- config = config || {};
- this.ident = config.ident || Ext.id();
- // Hide the "MODX Browser" toolbar button
- MODx.browserOpen = true;
- // Tree navigation
- this.tree = MODx.load({
- xtype: 'modx-tree-directory'
- ,onUpload: function() {
- this.view.run();
- }
- ,scope: this
- ,source: config.source || MODx.config.default_media_source
- ,hideFiles: config.hideFiles || MODx.config.modx_browser_tree_hide_files
- ,hideTooltips: config.hideTooltips || MODx.config.modx_browser_tree_hide_tooltips || true // by default do not request image preview tooltips in the media browser
- ,openTo: config.openTo || ''
- ,ident: this.ident
- ,rootId: config.rootId || '/'
- ,rootName: _('files')
- ,rootVisible: config.rootVisible == undefined || !Ext.isEmpty(config.rootId)
- ,id: this.ident+'-tree'
- ,hideSourceCombo: config.hideSourceCombo || false
- ,useDefaultToolbar: false
- ,listeners: {
- 'afterUpload': {
- fn: function() {
- this.view.run();
- }
- ,scope: this
- }
- ,'afterQuickCreate': {
- fn: function() {
- this.view.run();
- }
- ,scope: this
- }
- ,'afterRename': {
- fn: function() {
- this.view.run();
- }
- ,scope: this
- }
- ,'afterRemove': {
- fn: function() {
- this.view.run();
- }
- ,scope: this
- }
- ,'changeSource': {
- fn: function(s) {
- this.config.source = s;
- this.view.config.source = s;
- this.view.baseParams.source = s;
- this.view.dir = '/';
- this.view.run();
- }
- ,scope: this
- }
- ,'afterrender': {
- fn: function(tree) {
- tree.root.expand();
- }
- ,scope: this
- }
- ,'beforeclick': {
- fn: function(node, e) {
- // load the node/folder that is clicked on but prevent unnecessary requests when a file is clicked
- if (!node.leaf) {
- this.load(node.id);
- } else {
- // sync the selected item in the tree with the one in browser view
- // the id of a browser view node in the store is the full absolute URL
- // but there is a bug with urlAbsolute, see #11821 that's why we prepend a slash
- this.view.select(this.view.store.indexOfId('/' + node.attributes.url));
- // but instead load the container the file resides in if not already displayed
- if (this.view.dir !== node.parentNode.id) {
- this.load(node.parentNode.id);
- }
- return false;
- }
- }
- ,scope: this
- }
- }
- });
- // DataView
- this.view = MODx.load({
- xtype: 'modx-browser-view'
- ,onSelect: {
- fn: this.onSelect
- ,scope: this
- }
- ,source: config.source || MODx.config.default_media_source
- ,allowedFileTypes: config.allowedFileTypes || ''
- ,wctx: config.wctx || 'web'
- ,openTo: config.openTo || ''
- ,ident: this.ident
- ,id: this.ident+'-view'
- ,tree: this.tree
- });
- Ext.applyIf(config, {
- cls: 'modx-browser modx-browser-panel container'
- ,layout: 'border'
- ,width: '98%'
- ,height: '95%'
- ,items: [{
- region: 'west'
- ,width: 250
- ,items: this.tree
- ,id: this.ident+'-browser-tree'
- ,cls: 'modx-browser-tree'
- ,autoScroll: true
- ,split: true
- },{
- region: 'center'
- ,layout: 'fit'
- ,items: this.view
- ,id: this.ident+'-browser-view'
- ,cls: 'modx-browser-view-ct'
- ,autoScroll: true
- ,border: false
- ,tbar: this.getToolbar()
- ,bbar: this.getPathbar()
- },{
- region: 'east'
- ,width: 250
- ,id: this.ident+'-img-detail-panel'
- ,cls: 'modx-browser-details-ct'
- ,split: true
- //,collapsed: true
- }]
- });
- MODx.Media.superclass.constructor.call(this, config);
- this.config = config;
- };
- Ext.extend(MODx.Media, Ext.Container, {
- returnEl: null
- /**
- * Filter the DataView results
- */
- ,filter : function() {
- var filter = Ext.getCmp(this.ident+'filter');
- this.view.store.filter('name', filter.getValue(), true);
- this.view.select(0);
- }
- /**
- * Load the given directory in the DataView
- *
- * @param {String} dir
- */
- ,load: function(dir) {
- dir = dir || (Ext.isEmpty(this.config.openTo) ? '' : this.config.openTo);
- this.view.run({
- dir: dir
- ,source: this.config.source
- ,allowedFileTypes: this.config.allowedFileTypes || ''
- ,wctx: this.config.wctx || 'web'
- });
- this.sortStore();
- }
- /**
- * Sort the DataView results
- */
- ,sortStore: function(){
- var v = Ext.getCmp(this.ident+'sortSelect').getValue();
- this.view.store.sort(v, v == 'name' ? 'ASC' : 'DESC');
- this.view.select(0);
- }
- /**
- * Switch viewmode from grid to list and vice versa
- */
- ,changeViewmode: function() {
- var v = Ext.getCmp(this.ident+'viewSelect').getValue();
- this.view.setTemplate(v);
- this.view.select(0);
- }
- /**
- * Remove any filter applied to the DataView
- */
- ,reset: function() {
- if (this.rendered) {
- Ext.getCmp(this.ident+'filter').reset();
- this.view.getEl().dom.scrollTop = 0;
- }
- this.view.store.clearFilter();
- this.view.select(0);
- }
- /**
- * Get the browser view toolbar configuration
- *
- * @returns {Array}
- */
- ,getToolbar: function() {
- return [{
- text: _('filter')+':'
- ,xtype: 'label'
- },{
- xtype: 'textfield'
- ,id: this.ident+'filter'
- ,selectOnFocus: true
- ,width: 200
- ,listeners: {
- 'render': {
- fn: function() {
- Ext.getCmp(this.ident+'filter').getEl().on('keyup', function() {
- this.filter();
- }, this, {buffer: 500});
- }
- ,scope: this
- }
- }
- },{
- text: _('sort_by')+':'
- ,xtype: 'label'
- },{
- id: this.ident+'sortSelect'
- ,xtype: 'combo'
- ,typeAhead: true
- ,triggerAction: 'all'
- ,width: 130
- ,editable: false
- ,mode: 'local'
- ,displayField: 'desc'
- ,valueField: 'name'
- ,lazyInit: false
- ,value: MODx.config.modx_browser_default_sort || 'name'
- ,store: new Ext.data.SimpleStore({
- fields: ['name', 'desc'],
- data : [
- ['name', _('name')]
- ,['size', _('file_size')]
- ,['lastmod', _('last_modified')]
- ]
- })
- ,listeners: {
- 'select': {
- fn: this.sortStore
- ,scope: this
- }
- }
- }, '-', {
- text: _('files_viewmode')+':'
- ,xtype: 'label'
- }, '-', {
- id: this.ident+'viewSelect'
- ,xtype: 'combo'
- ,typeAhead: false
- ,triggerAction: 'all'
- ,width: 100
- ,editable: false
- ,mode: 'local'
- ,displayField: 'desc'
- ,valueField: 'type'
- ,lazyInit: false
- ,value: MODx.config.modx_browser_default_viewmode || 'grid'
- ,store: new Ext.data.SimpleStore({
- fields: ['type', 'desc'],
- data : [
- ['grid', _('files_viewmode_grid')]
- ,['list', _('files_viewmode_list')]
- ]
- })
- ,listeners: {
- 'select': {
- fn: this.changeViewmode
- ,scope: this
- }
- }
- }];
- }
- /**
- * Get the bottom filepath textfield in the browser view
- *
- * @returns {Array}
- */
- ,getPathbar: function() {
- return {
- cls: 'modx-browser-pathbbar'
- ,items: [{
- xtype: 'textfield'
- ,id: this.ident+'-filepath'
- ,cls: 'modx-browser-filepath'
- ,listeners: {
- 'focus': {
- // select the filepath on focus
- fn: function(el) {
- // let the focus event stick first, needed for webkit primarily
- setTimeout(function () {
- var field = el.getEl().dom;
- if (field.createTextRange) {
- var selRange = field.createTextRange();
- selRange.collapse(true);
- selRange.moveStart('character', 0);
- selRange.moveEnd('character', field.value.length);
- selRange.select();
- } else if (field.setSelectionRange) {
- field.setSelectionRange(0, field.value.length);
- } else if (field.selectionStart) {
- field.selectionStart = 0;
- field.selectionEnd = field.value.length;
- }
- }, 50);
- }
- ,scope: this
- }
- }
- }]
- };
- }
- ,setReturn: function(el) {
- this.returnEl = el;
- }
- ,onSelect: function(data) {
- return;
- }
- ,onSelectHandler: function(data) {
- Ext.get(this.returnEl).dom.value = unescape(data.url);
- }
- });
- Ext.reg('modx-media-view', MODx.Media);
- /**
- * This is the popup window (not Ext.Window!) that opens when triggered from an RTE
- */
- MODx.browser.RTE = function(config) {
- config = config || {};
- this.ident = config.ident || Ext.id();
- // Hide the "MODX Browser" toolbar button
- MODx.browserOpen = true;
- Ext.Ajax.defaultHeaders = {
- 'modAuth': config.auth
- };
- Ext.Ajax.extraParams = {
- 'HTTP_MODAUTH': config.auth
- };
- // Tree navigation
- this.tree = MODx.load({
- xtype: 'modx-tree-directory'
- ,onUpload: function() {
- this.view.run();
- }
- ,scope: this
- ,source: config.source || MODx.config.default_media_source
- ,hideFiles: config.hideFiles || MODx.config.modx_browser_tree_hide_files
- ,hideTooltips: config.hideTooltips || MODx.config.modx_browser_tree_hide_tooltips || true // by default do not request image preview tooltips in the media browser
- ,openTo: config.openTo || ''
- ,ident: this.ident
- ,rootId: config.rootId || '/'
- ,rootName: _('files')
- ,rootVisible: config.rootVisible == undefined || !Ext.isEmpty(config.rootId)
- ,id: this.ident+'-tree'
- ,hideSourceCombo: config.hideSourceCombo || false
- ,useDefaultToolbar: false
- ,listeners: {
- 'afterUpload': {
- fn: function() {
- this.view.run();
- }
- ,scope: this
- }
- ,'afterQuickCreate': {
- fn: function() {
- this.view.run();
- }
- ,scope: this
- }
- ,'afterRename': {
- fn: function() {
- this.view.run();
- }
- ,scope: this
- }
- ,'afterRemove': {
- fn: function() {
- this.view.run();
- }
- ,scope: this
- }
- ,'changeSource': {
- fn: function(s) {
- this.config.source = s;
- this.view.config.source = s;
- this.view.baseParams.source = s;
- this.view.dir = '/';
- this.view.run();
- }
- ,scope: this
- }
- ,'afterrender': {
- fn: function(tree) {
- tree.root.expand();
- }
- ,scope: this
- }
- ,'beforeclick': {
- fn: function(node, e) {
- // load the node/folder that is clicked on but prevent unnecessary requests when a file is clicked
- if (!node.leaf) {
- this.load(node.id);
- } else {
- // sync the selected item in the tree with the one in browser view
- // the id of a browser view node in the store is the full absolute URL
- // but there is a bug with urlAbsolute, see #11821 that's why we prepend a slash
- this.view.select(this.view.store.indexOfId('/' + node.attributes.url));
- // but instead load the container the file resides in if not already displayed
- if (this.view.dir !== node.parentNode.id) {
- this.load(node.parentNode.id);
- }
- return false;
- }
- }
- ,scope: this
- }
- }
- });
- // DataView
- this.view = MODx.load({
- xtype: 'modx-browser-view'
- ,onSelect: {
- fn: this.onSelect
- ,scope: this
- }
- ,source: config.source || MODx.config.default_media_source
- ,allowedFileTypes: config.allowedFileTypes || ''
- ,wctx: config.wctx || 'web'
- ,openTo: config.openTo || ''
- ,ident: this.ident
- ,id: this.ident+'-view'
- ,tree: this.tree
- });
- Ext.applyIf(config,{
- title: _('modx_browser')
- ,cls: 'modx-browser modx-browser-rte'
- ,layout: 'border'
- ,renderTo: document.body
- ,id: this.ident+'-viewport'
- ,onSelect: MODx.onBrowserReturn || function(data) {}
- ,items: [{
- id: this.ident+'-browser-tree'
- ,cls: 'modx-browser-tree'
- ,region: 'west'
- ,width: 250
- ,height: '100%'
- ,split: true
- ,items: this.tree
- ,autoScroll: true
- },{
- id: this.ident+'-browser-view'
- ,cls: 'modx-browser-view-ct'
- ,region: 'center'
- ,autoScroll: true
- ,width: 450
- ,items: this.view
- ,tbar: this.getToolbar()
- ,bbar: this.getPathbar()
- },{
- id: this.ident+'-img-detail-panel'
- ,cls: 'modx-browser-details-ct'
- ,region: 'east'
- ,split: true
- ,width: 200
- ,minWidth: 200
- ,maxWidth: 300
- },{
- id: this.ident+'-south'
- ,cls: 'modx-browser-rte-buttons'
- ,region: 'south'
- ,split: false
- ,bbar: ['->',{
- xtype: 'button'
- ,id: this.ident+'-cancel-btn'
- ,text: _('cancel')
- ,minWidth: 75
- ,handler: this.onCancel
- ,scope: this
- // ,width: 200
- },{
- xtype: 'button'
- ,id: this.ident+'-ok-btn'
- ,text: _('ok')
- ,cls: 'primary-button'
- ,minWidth: 75
- ,handler: this.onSelect
- ,scope: this
- // ,width: 200
- }]
- }]
- });
- MODx.browser.RTE.superclass.constructor.call(this,config);
- this.config = config;
- };
- Ext.extend(MODx.browser.RTE,Ext.Viewport,{
- returnEl: null
- /**
- * Filter the DataView results
- */
- ,filter : function() {
- var filter = Ext.getCmp(this.ident+'filter');
- this.view.store.filter('name', filter.getValue(), true);
- this.view.select(0);
- }
- /**
- * Load the given directory in the DataView
- *
- * @param {String} dir
- */
- ,load: function(dir) {
- dir = dir || (Ext.isEmpty(this.config.openTo) ? '' : this.config.openTo);
- this.view.run({
- dir: dir
- ,source: this.config.source
- ,allowedFileTypes: this.config.allowedFileTypes || ''
- ,wctx: this.config.wctx || 'web'
- });
- this.sortStore();
- }
- /**
- * Sort the DataView results
- */
- ,sortStore: function(){
- var v = Ext.getCmp(this.ident+'sortSelect').getValue();
- this.view.store.sort(v, v == 'name' ? 'ASC' : 'DESC');
- this.view.select(0);
- }
- /**
- * Switch viewmode from grid to list and vice versa
- */
- ,changeViewmode: function() {
- var v = Ext.getCmp(this.ident+'viewSelect').getValue();
- this.view.setTemplate(v);
- this.view.select(0);
- }
- /**
- * Remove any filter applied to the DataView
- */
- ,reset: function() {
- if (this.rendered) {
- Ext.getCmp(this.ident+'filter').reset();
- this.view.getEl().dom.scrollTop = 0;
- }
- this.view.store.clearFilter();
- this.view.select(0);
- }
- /**
- * Get the browser view toolbar configuration
- *
- * @returns {Array}
- */
- ,getToolbar: function() {
- return [{
- text: _('filter')+':'
- ,xtype: 'label'
- },{
- xtype: 'textfield'
- ,id: this.ident+'filter'
- ,selectOnFocus: true
- ,width: 200
- ,listeners: {
- 'render': {
- fn: function() {
- Ext.getCmp(this.ident+'filter').getEl().on('keyup', function() {
- this.filter();
- }, this, {buffer: 500});
- }
- ,scope: this
- }
- }
- },{
- text: _('sort_by')+':'
- ,xtype: 'label'
- },{
- id: this.ident+'sortSelect'
- ,xtype: 'combo'
- ,typeAhead: true
- ,triggerAction: 'all'
- ,width: 130
- ,editable: false
- ,mode: 'local'
- ,displayField: 'desc'
- ,valueField: 'name'
- ,lazyInit: false
- ,value: MODx.config.modx_browser_default_sort || 'name'
- ,store: new Ext.data.SimpleStore({
- fields: ['name', 'desc'],
- data : [
- ['name', _('name')]
- ,['size', _('file_size')]
- ,['lastmod', _('last_modified')]
- ]
- })
- ,listeners: {
- 'select': {
- fn: this.sortStore
- ,scope: this
- }
- }
- }, '-', {
- text: _('files_viewmode')+':'
- ,xtype: 'label'
- }, '-', {
- id: this.ident+'viewSelect'
- ,xtype: 'combo'
- ,typeAhead: false
- ,triggerAction: 'all'
- ,width: 100
- ,editable: false
- ,mode: 'local'
- ,displayField: 'desc'
- ,valueField: 'type'
- ,lazyInit: false
- ,value: MODx.config.modx_browser_default_viewmode || 'grid'
- ,store: new Ext.data.SimpleStore({
- fields: ['type', 'desc'],
- data : [
- ['grid', _('files_viewmode_grid')]
- ,['list', _('files_viewmode_list')]
- ]
- })
- ,listeners: {
- 'select': {
- fn: this.changeViewmode
- ,scope: this
- }
- }
- }];
- }
- /**
- * Get the bottom filepath textfield in the browser view
- *
- * @returns {Array}
- */
- ,getPathbar: function() {
- return {
- cls: 'modx-browser-pathbbar'
- ,items: [{
- xtype: 'textfield'
- ,id: this.ident+'-filepath'
- ,cls: 'modx-browser-filepath'
- ,listeners: {
- 'focus': {
- // select the filepath on focus
- fn: function(el) {
- // let the focus event stick first, needed for webkit primarily
- setTimeout(function () {
- var field = el.getEl().dom;
- if (field.createTextRange) {
- var selRange = field.createTextRange();
- selRange.collapse(true);
- selRange.moveStart('character', 0);
- selRange.moveEnd('character', field.value.length);
- selRange.select();
- } else if (field.setSelectionRange) {
- field.setSelectionRange(0, field.value.length);
- } else if (field.selectionStart) {
- field.selectionStart = 0;
- field.selectionEnd = field.value.length;
- }
- }, 50);
- }
- ,scope: this
- }
- }
- }]
- };
- }
- ,setReturn: function(el) {
- this.returnEl = el;
- }
- ,onSelect: function(data) {
- var selNode = this.view.getSelectedNodes()[0];
- var callback = this.config.onSelect || this.onSelectHandler;
- var lookup = this.view.lookup;
- var scope = this.config.scope;
- if (callback) {
- data = (selNode) ? lookup[selNode.id] : null;
- Ext.callback(callback, scope || this, [data]);
- this.fireEvent('select', data);
- if (window.top.opener) {
- window.top.close();
- window.top.opener.focus();
- }
- }
- }
- ,onCancel: function() {
- var callback = this.config.onSelect || this.onSelectHandler;
- var scope = this.config.scope;
- Ext.callback(callback, scope || this, [null]);
- this.fireEvent('select', null);
- if (window.top.opener) {
- window.top.close();
- window.top.opener.focus();
- }
- }
- ,onSelectHandler: function(data) {
- Ext.get(this.returnEl).dom.value = unescape(data.url);
- }
- });
- Ext.reg('modx-browser-rte',MODx.browser.RTE);
|