1 /* mandala.js */
  2 
  3 Monk.component.MandalaComponent = function(args) {
  4     // call the constructor for the superclass, i.e. Workbench.component.Component
  5     Monk.component.MandalaComponent.superclass.constructor.call(this, args);
  6 }
  7 
  8 // overwrite Workbench.component.Component methods & properties and add custom methods
  9 Workbench.extend(Monk.component.MandalaComponent, Workbench.component.Component, {
 10 
 11     label : "Mandala Browser",
 12 
 13     description : "Prospective Browser.",
 14 
 15     // this is required in order to associate the correct window with the component
 16     // since all components reside in IFRAMEs
 17     "window" : this.window,
 18 
 19 	// current selection
 20 	"selection" : null,
 21 
 22     // the handle method of every component gets called when a Monk.event is sent to the Workbench.component.Manager.
 23     // here the component reacts only to those events it is interested in
 24     handle : function(monkEvent, data) {
 25     },
 26 
 27 	/**
 28 	 * Synchronizes item selection in the workbench with item selection
 29 	 * in the Mandala.
 30 	 *
 31 	 * @param applet    a reference to the Mandala applet
 32 	 * @param attribute the attribute used to identify selected items
 33 	 *
 34 	 */
 35 	synchronizeSelection : function (applet, attribute) {
 36 		// Query the Mandala for selected items
 37 				
 38 		//console.debug("Checking if workbench selection needs to be updated.");
 39 				
 40 		var currentSelection = eval('(' + applet.getSelectedAttributeValues(attribute) + ')');
 41 		
 42 		//console.debug(currentSelection);
 43 		
 44 		// Compare the workbench selection with the selection in Mandala and
 45 		// update our selection if they differ			
 46 				
 47 		if(this.selection != currentSelection) {
 48 			//console.info("Updating workbench selection.");
 49 				
 50 			this.selection = currentSelection;
 51 			//console.debug(this.selection);
 52 			
 53 			// Create an array of the selected items.
 54 			
 55 			var selectedItems = [];
 56 			
 57 			for(i = 0; i < this.selection.length; i++) {
 58 				var compositeId = this.selection[i].work_id;
 59 				//console.debug("composite id: " + compositeId);
 60 				
 61 				if(compositeId != null) {
 62 					 var splitId = compositeId.split("-");
 63 					var collectionId = splitId[0];
 64 					selectedItems.push({
 65 						id: compositeId,
 66 						collectionId: collectionId
 67 					});
 68 				}
 69 			}
 70 			
 71 			// Notify the workbench that the selection has been updated
 72 			
 73 			this.notify(
 74             	new Monk.event.chunk.ChunksChecked({
 75                 	label: "Chunks selected in Mandala browser",
 76 					component: this
 77             	}),
 78 				selectedItems
 79         	);
 80 		}
 81 	}
 82 });