1 /**This component talks with the MONK Project Zotero plugin and 2 * allows access to the collection informatuion which 3 * can then be saved as a workset. 4 * @author Amit Kumar 5 * @since 1.3M2 6 */ 7 Monk.component.ZoteroImportComponent = function(args) { 8 9 10 this.zoteroCollectionStore= new Ext.data.SimpleStore({ 11 fields: ['id','name','numitems','workList'] 12 }) 13 14 this.ZoteroCollectionRecordDef = Ext.data.Record.create([ 15 {name : 'name', mapping : 'name'}, 16 {name:'id',mapping: 'id'}, 17 {name:'numitems',mapping: 'numitems'}, 18 {name:'workList',mapping:'workList'} 19 ]); 20 21 22 23 24 25 26 Monk.component.ZoteroImportComponent.superclass.constructor.call(this, args); 27 } 28 29 30 Workbench.extend(Monk.component.ZoteroImportComponent, Workbench.component.Component, { 31 label : "Zotero Import Component", 32 description : "This component is for importing Zotero Components", 33 "window" : this.window, 34 35 handle : function(monkEvent, data) { 36 37 }, 38 39 beforeExit: function() { 40 41 }, 42 43 44 init: function(){ 45 46 var zoteroCollectionList= new Ext.form.ComboBox({ 47 id: 'zoteroCollectionListId', 48 name: 'zoteroCollectionList', 49 triggerAction: 'all', 50 fieldLabel: 'Zotero Collections', 51 valueField : 'id', 52 displayField : 'name', 53 mode : 'local', 54 store: this.zoteroCollectionStore, 55 width: 150 56 }); 57 58 var panel = new Ext.Panel({ 59 frame:true, 60 width:'100%', 61 autoHeight:true, 62 layout:'fit', 63 items: {contentEl:'info',text:''} 64 }); 65 66 67 68 69 70 var viewport = new Ext.Viewport({ 71 layout: 'fit', 72 renderTo: 'container', 73 items: { 74 border: false, 75 items:[ 76 panel, 77 { 78 xtype: 'form', 79 id: 'featureFormPanel', 80 bodyStyle:'padding: 10px', 81 labelAlign: 'right', 82 labelWidth: 125, 83 autoScroll: true, 84 border: false, 85 defaultType: 'textfield', 86 items: [ 87 zoteroCollectionList 88 ], 89 buttons: [{ 90 id: 'gobutton', 91 xtype: 'button', 92 text: 'Import MONK works', 93 tooltip: 'Click to search for MONK Works.', 94 listeners :{ 95 click :{fn : function(){ 96 this.processCollectionSelection(zoteroCollectionList.value); 97 }, scope: this} 98 } 99 }] 100 }] 101 } 102 103 }); 104 105 106 this.raiseCollectionEvent(); 107 108 109 110 111 }, 112 113 selectAllAndSaveNotification: function(){ 114 var params ={'showSaveOption':true}; 115 Workbench.component.manager.notify(new Monk.event.chunk.AllChunksChecked({ 116 label: 'all chunks in the resultstore are selected ' 117 }), params); 118 }, 119 120 121 sendSearchNotification: function(workList){ 122 //Workbench.console.info("LEN IS: " + workList.length); 123 var documentArray = []; 124 for(var count=0; count<workList.length ;count++){ 125 var url = workList[count].toString(); 126 if(url.indexOf("monk.lis.uiuc.edu")!=-1 || 127 url.indexOf("devadatta.lis.illinois.edu")!=-1 || 128 url.indexOf("gautam.lis.illinois.edu")!=-1 ){ 129 var workId = this.getWorkId(url); 130 documentArray[count]=workId; 131 } 132 } 133 134 //Workbench.console.info("found: " + documentArray.length+ " doucmnets..."); 135 if(documentArray.length==0){ 136 Ext.Msg.alert('Status', 'No Valid MONK work or workparts found in the Zotero collection.<br/>Select another collection.'); 137 }else{ 138 var paramValues = {'workpartIdCriterion':documentArray.join(",")}; 139 //Workbench.console.info("param values are: "+ paramValues.workpartIdCriterion); 140 Monk.component.dataManager.getResultStore().removeAll(); 141 this.notify(new Monk.event.workbench.AdvancedSearchQuery({ 142 label: 'new search request: ' 143 }), [paramValues]); 144 } 145 146 147 }, 148 149 processCollectionSelection: function(collectionValue){ 150 //debugger; 151 this.zoteroCollectionStore.each(function(record,options){ 152 if(record.data.id==collectionValue){ 153 var workList = record.data.workList; 154 if(workList!=null){ 155 this.sendSearchNotification(workList.split(",")); 156 this.selectAllAndSaveNotification(); 157 } 158 } 159 },this); 160 161 }, 162 163 raiseCollectionEvent: function () { 164 window.addEventListener("collectionEvent",this.bindMethod(this.zoteroCollectionListener,this),false); 165 var evt = document.createEvent("Events"); 166 evt.initEvent("Monk.Zotero.GetCollectionsEvent", true, false); 167 var elm=Ext.get("zoteroCollectionListId").dom; 168 elm.dispatchEvent(evt); 169 }, 170 171 172 zoteroCollectionListener: function (event){ 173 //debugger; 174 var elm = event.target; 175 var myextra = elm.getAttribute("myextra"); 176 this.zoteroCollectionStore.removeAll(); 177 178 if (elm){ 179 var results = JSON.parse(myextra); 180 for(var i=0; i < results.length; i++){ 181 var result = results[i]; 182 var record=new this.ZoteroCollectionRecordDef({ 183 id: result[3], 184 name: result[1], 185 numitems: result[5], 186 workList: result[7] 187 }); 188 this.zoteroCollectionStore.add(record); 189 190 } 191 } 192 193 if (elm.hasAttribute("myextra")){ 194 elm.removeAttribute("myextra"); 195 } 196 }, 197 getWorkId: function(url){ 198 var name ="id"; 199 //name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 200 var regexS = "[\\?&]"+name+"=([^]*)"; 201 var regex = new RegExp( regexS ); 202 var results = regex.exec( url ); 203 if( results == null ){ 204 return ""; 205 }else{ 206 return results[1]; 207 } 208 }, 209 210 bindMethod: function(method, scope){ 211 return function(){ 212 method.apply(scope,arguments); 213 } 214 } 215 216 217 218 219 }); 220 221