1 /** 2 * @class Monk.component.CollectionsTreeBrowserComponent 3 * @description A {@link Worbench.component.Component} for browsing text chunks. 4 * @extends Workbench.component.Component 5 * @author Stéfan Sinclair 6 * @version 0.1 7 * @since Monk 0.1 8 */ 9 Monk.component.DocumentSelectorComponent = function(args) { 10 11 this.allWorks = []; 12 this.allNodes = null; 13 Monk.component.DocumentSelectorComponent.superclass.constructor.call(this, args); 14 }; 15 16 Workbench.extend(Monk.component.DocumentSelectorComponent, Workbench.component.Component, { 17 18 label : "Document Selector", 19 description : "For quickly selecting documents.", 20 "window" : this.window, 21 cachedData : null, 22 23 handle : function(monkEvent, data){ 24 if (monkEvent.instanceOf(Monk.event.chunk.ChunksChecked) && !monkEvent.component.instanceOf(Monk.component.DocumentSelectorComponent)) { 25 this.cacheData(data); 26 } else if (monkEvent.instanceOf(Monk.event.workset.WorksetLoaded)) { 27 var worklist = Monk.component.dataManager.getWorklist(); 28 var chunks = []; 29 for (var chunkId in worklist) { 30 var chunk = worklist[chunkId]; 31 chunk.id = chunkId; 32 chunks.push(chunk); 33 } 34 this.cacheData(chunks); 35 } else if (monkEvent.instanceOf(Monk.event.workbench.LocalWindowFocus)) { 36 if (this.cachedData) { 37 this.syncData(); 38 } 39 } else if (monkEvent.instanceOf(Monk.event.workbench.SimpleSearchQuery)) { 40 Monk.data.chunk.getChunksContainingFeature({ 41 lemmaPatternCriterion: data.featureValue 42 }); 43 } else if (monkEvent.instanceOf(Monk.event.workbench.AdvancedSearchQuery)) { 44 Monk.data.chunk.getChunksContainingFeature(data[0]); 45 } else if (monkEvent.instanceOf(Monk.event.chunk.ChunksContainingFeatureRetrieved)) { 46 //if (this.hasFocus) { 47 var works = data.responseXML.getElementsByTagName('work'); 48 var workIds = []; 49 var collectionId = null; 50 for (var i = 0; i < works.length; i++) { 51 var workId = works[i].getAttribute('id'); 52 // TODO workId now contains collection ID, so remove this legacy adaption 53 if (collectionId === null) { 54 collectionId = workId.match(/^(\w+)\-(.+)$/)[1]; 55 } 56 //workIds.push(collectionId + '.' + workId); 57 workIds.push(workId); 58 } 59 this.filter(workIds); 60 // } 61 } 62 }, 63 64 cacheData : function(data) { 65 this.cachedData = data; 66 }, 67 68 syncData : function() { 69 if (this.cachedData) { 70 this.updateList(this.cachedData); 71 } 72 this.cachedData = null; 73 }, 74 75 76 addNodes : function(fromNode, collection) { 77 for (var i=0;i<fromNode.length;i++) { 78 var node = fromNode[i]; 79 if (node.chunkType=="work") { 80 var newNode = {"collection" : collection}; 81 for(var p in node){ 82 if (p!="children") {newNode[p] = node[p];} 83 } 84 this.allWorks.push(newNode); 85 } 86 else if (node.children) { 87 if (node.chunkType=="collection") { 88 collection=node.text; 89 } 90 this.addNodes(node.children, collection); 91 } 92 } 93 }, 94 95 updateList : function(data) { 96 alert("This function should be overriden."); 97 } 98 99 }); 100