7604 |
25 Feb 19 |
nicklas |
/* $Id $ |
7604 |
25 Feb 19 |
nicklas |
2 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
Copyright (C) 2014 Nicklas Nordborg |
7604 |
25 Feb 19 |
nicklas |
4 |
|
7604 |
25 Feb 19 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
7604 |
25 Feb 19 |
nicklas |
Available at http://base.thep.lu.se/ |
7604 |
25 Feb 19 |
nicklas |
7 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is free software; you can redistribute it and/or |
7604 |
25 Feb 19 |
nicklas |
modify it under the terms of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
as published by the Free Software Foundation; either version 3 |
7604 |
25 Feb 19 |
nicklas |
of the License, or (at your option) any later version. |
7604 |
25 Feb 19 |
nicklas |
12 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is distributed in the hope that it will be useful, |
7604 |
25 Feb 19 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
7604 |
25 Feb 19 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7604 |
25 Feb 19 |
nicklas |
GNU General Public License for more details. |
7604 |
25 Feb 19 |
nicklas |
17 |
|
7604 |
25 Feb 19 |
nicklas |
You should have received a copy of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
7604 |
25 Feb 19 |
nicklas |
20 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
21 |
|
7604 |
25 Feb 19 |
nicklas |
@author Nicklas |
7604 |
25 Feb 19 |
nicklas |
23 |
*/ |
7604 |
25 Feb 19 |
nicklas |
'use strict'; |
7604 |
25 Feb 19 |
nicklas |
25 |
|
7604 |
25 Feb 19 |
nicklas |
var PlaceOnPlate = function() |
7604 |
25 Feb 19 |
nicklas |
27 |
{ |
7604 |
25 Feb 19 |
nicklas |
var pop = {}; |
7604 |
25 Feb 19 |
nicklas |
29 |
|
7604 |
25 Feb 19 |
nicklas |
var graphics; |
7604 |
25 Feb 19 |
nicklas |
var pen; |
7604 |
25 Feb 19 |
nicklas |
var selectedPen; |
7604 |
25 Feb 19 |
nicklas |
33 |
|
7604 |
25 Feb 19 |
nicklas |
var plate; |
7604 |
25 Feb 19 |
nicklas |
var selectedWell; |
7604 |
25 Feb 19 |
nicklas |
var itemList; |
7604 |
25 Feb 19 |
nicklas |
var selectedItem; |
7604 |
25 Feb 19 |
nicklas |
38 |
|
7604 |
25 Feb 19 |
nicklas |
39 |
/** |
7604 |
25 Feb 19 |
nicklas |
Initialize the page. |
7604 |
25 Feb 19 |
nicklas |
41 |
*/ |
7604 |
25 Feb 19 |
nicklas |
pop.initPage = function() |
7604 |
25 Feb 19 |
nicklas |
43 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Save and close buttons |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnSave', pop.placeOnPlate); |
7604 |
25 Feb 19 |
nicklas |
47 |
|
7604 |
25 Feb 19 |
nicklas |
// Protocol |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('protocol_id.select', Wizards.selectProtocol); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('protocol_id', 'base-selected', Wizards.setProtocolCallback); |
7604 |
25 Feb 19 |
nicklas |
51 |
|
7604 |
25 Feb 19 |
nicklas |
// Kit |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('kit_id.select', Wizards.selectKit); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('kit_id', 'base-selected', Wizards.setKitCallback); |
7604 |
25 Feb 19 |
nicklas |
55 |
|
7604 |
25 Feb 19 |
nicklas |
// Hardware |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('hardware_id.select', Wizards.selectHardware); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('hardware_id', 'base-selected', Wizards.setHardwareCallback); |
7604 |
25 Feb 19 |
nicklas |
59 |
|
7604 |
25 Feb 19 |
nicklas |
// Toolbar |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnSelectPlate', pop.selectBioPlate); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('btnSelectPlate', 'base-selected', pop.setBioPlateCallback); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnPlaceByRow', pop.placeByRow); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnPlaceByColumn', pop.placeByColumn); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnClearMapping', pop.clearMapping); |
7604 |
25 Feb 19 |
nicklas |
66 |
|
7604 |
25 Feb 19 |
nicklas |
// Initialize graphics |
7604 |
25 Feb 19 |
nicklas |
graphics = new jsGraphics(Doc.element('canvas')); |
7604 |
25 Feb 19 |
nicklas |
pen = new jsPen(new jsColor('#2288AA'), 1); |
7604 |
25 Feb 19 |
nicklas |
selectedPen = new jsPen(new jsColor('#2288AA'), 2); |
7604 |
25 Feb 19 |
nicklas |
71 |
|
7604 |
25 Feb 19 |
nicklas |
// Create the list of items |
7604 |
25 Feb 19 |
nicklas |
itemList = new ItemList('itemlist'); |
7604 |
25 Feb 19 |
nicklas |
var items = Doc.element('itemlist').getElementsByClassName('item'); |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < items.length; i++) |
7604 |
25 Feb 19 |
nicklas |
76 |
{ |
7604 |
25 Feb 19 |
nicklas |
var item = items[i]; |
7604 |
25 Feb 19 |
nicklas |
var itemId = Data.int(item, 'item-id'); |
7604 |
25 Feb 19 |
nicklas |
var name = Data.get(item, 'name'); |
7604 |
25 Feb 19 |
nicklas |
if (itemId) |
7604 |
25 Feb 19 |
nicklas |
81 |
{ |
7604 |
25 Feb 19 |
nicklas |
itemList.addItem(itemId, name); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler(item, 'click', pop.itemOnClick); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler(item, 'mouseover', pop.itemOnMouseOver); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler(item, 'mouseout', pop.itemOnMouseOut); |
7604 |
25 Feb 19 |
nicklas |
86 |
} |
7604 |
25 Feb 19 |
nicklas |
87 |
} |
7604 |
25 Feb 19 |
nicklas |
// Handle layout changes |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('itemlist', 'scroll', pop.onLayoutChange); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler(window, 'resize', pop.onLayoutChange); |
7604 |
25 Feb 19 |
nicklas |
91 |
} |
7604 |
25 Feb 19 |
nicklas |
92 |
|
7604 |
25 Feb 19 |
nicklas |
pop.selectBioPlate = function() |
7604 |
25 Feb 19 |
nicklas |
94 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (plate && !confirm('This will remove all placed biomaterial. Continue?')) return; |
7604 |
25 Feb 19 |
nicklas |
96 |
|
7604 |
25 Feb 19 |
nicklas |
var url = '&resetTemporary=1'; |
7604 |
25 Feb 19 |
nicklas |
var bioMaterialType = Data.int('page-data', 'biomaterial-type'); |
7604 |
25 Feb 19 |
nicklas |
url += '&tmpfilter:INT:bioPlateType.bioMaterialType='+encodeURIComponent('|'+bioMaterialType); |
7604 |
25 Feb 19 |
nicklas |
var commonSubtype = Data.int('page-data', 'common-subtype'); |
7604 |
25 Feb 19 |
nicklas |
if (commonSubtype) |
7604 |
25 Feb 19 |
nicklas |
102 |
{ |
7604 |
25 Feb 19 |
nicklas |
url += '&tmpfilter:INT:bioPlateType.itemSubtype='+encodeURIComponent('|'+commonSubtype); |
7604 |
25 Feb 19 |
nicklas |
104 |
} |
7604 |
25 Feb 19 |
nicklas |
Dialogs.selectItem('BIOPLATE', 'btnSelectPlate', 0, url); |
7604 |
25 Feb 19 |
nicklas |
106 |
} |
7604 |
25 Feb 19 |
nicklas |
107 |
|
7604 |
25 Feb 19 |
nicklas |
pop.setBioPlateCallback = function(event) |
7604 |
25 Feb 19 |
nicklas |
109 |
{ |
7604 |
25 Feb 19 |
nicklas |
var request = Ajax.getXmlHttpRequest(); |
7604 |
25 Feb 19 |
nicklas |
var url = '../bioplates/ajax.jsp?ID='+App.getSessionId()+'&cmd=GetFullPlateInfo&item_id=' + event.detail.id; |
7604 |
25 Feb 19 |
nicklas |
request.open("GET", url, false); |
7604 |
25 Feb 19 |
nicklas |
// NOTE! 'false' causes code to wait for the response. aka. 'Synchronous AJAX' or SJAX. |
7604 |
25 Feb 19 |
nicklas |
request.send(null); |
7604 |
25 Feb 19 |
nicklas |
115 |
|
7604 |
25 Feb 19 |
nicklas |
var plateInfo = JSON.parse(request.responseText); |
7604 |
25 Feb 19 |
nicklas |
if (plateInfo.status != 'ok') |
7604 |
25 Feb 19 |
nicklas |
118 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification('plate.name', plateInfo.message); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
121 |
} |
7604 |
25 Feb 19 |
nicklas |
122 |
|
7604 |
25 Feb 19 |
nicklas |
// Get plate and well information from the AJAX response |
7604 |
25 Feb 19 |
nicklas |
var rows = plateInfo.rows; |
7604 |
25 Feb 19 |
nicklas |
var columns = plateInfo.columns; |
7604 |
25 Feb 19 |
nicklas |
126 |
|
7604 |
25 Feb 19 |
nicklas |
var bigPlate = rows > 12 || columns > 18; |
7604 |
25 Feb 19 |
nicklas |
var plateClass = bigPlate ? 'plate bigplate' : 'plate'; |
7604 |
25 Feb 19 |
nicklas |
129 |
|
7604 |
25 Feb 19 |
nicklas |
// Remove existing mapping |
7604 |
25 Feb 19 |
nicklas |
itemList.unmapAll(graphics); |
7604 |
25 Feb 19 |
nicklas |
132 |
|
7604 |
25 Feb 19 |
nicklas |
// Create plate and wells |
7604 |
25 Feb 19 |
nicklas |
plate = new Plate('dest', plateInfo.id, plateInfo.name, rows, columns); |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < plateInfo.wells.length; i++) |
7604 |
25 Feb 19 |
nicklas |
136 |
{ |
7604 |
25 Feb 19 |
nicklas |
var wellInfo = plateInfo.wells[i]; |
7604 |
25 Feb 19 |
nicklas |
var bmInfo = wellInfo.bioMaterial; |
7604 |
25 Feb 19 |
nicklas |
var row = parseInt(wellInfo.row); |
7604 |
25 Feb 19 |
nicklas |
var col = parseInt(wellInfo.column); |
7604 |
25 Feb 19 |
nicklas |
var well = plate.getWell(row, col); |
7604 |
25 Feb 19 |
nicklas |
well.locked = !wellInfo.canAdd || bmInfo; |
7604 |
25 Feb 19 |
nicklas |
well.name = bmInfo ? bmInfo.name : ''; |
7604 |
25 Feb 19 |
nicklas |
144 |
} |
7604 |
25 Feb 19 |
nicklas |
145 |
|
7604 |
25 Feb 19 |
nicklas |
Doc.element('plate.name').innerHTML = Strings.encodeTags(plateInfo.name); |
7604 |
25 Feb 19 |
nicklas |
147 |
|
7604 |
25 Feb 19 |
nicklas |
// Create html table representing the bioplate |
7604 |
25 Feb 19 |
nicklas |
var html = '<table class="'+plateClass+'">'; |
7604 |
25 Feb 19 |
nicklas |
html += '<tr><td class="bg-filled-100"></td>'; |
7604 |
25 Feb 19 |
nicklas |
for (var c = 0; c < plate.columns; c++) |
7604 |
25 Feb 19 |
nicklas |
152 |
{ |
7604 |
25 Feb 19 |
nicklas |
html += '<td class="columnheader bg-filled-100">' + (c+1) + '</td>'; |
7604 |
25 Feb 19 |
nicklas |
154 |
} |
7604 |
25 Feb 19 |
nicklas |
html += '</tr>'; |
7604 |
25 Feb 19 |
nicklas |
for (var r = 0; r < plate.rows; r++) |
7604 |
25 Feb 19 |
nicklas |
157 |
{ |
7604 |
25 Feb 19 |
nicklas |
html += '<tr><td class="rowheader bg-filled-100">' + Plates.toAlphaCoordinate[r] + '</td>'; |
7604 |
25 Feb 19 |
nicklas |
for (var c = 0; c < plate.columns; c++) |
7604 |
25 Feb 19 |
nicklas |
160 |
{ |
7604 |
25 Feb 19 |
nicklas |
var well = plate.getWell(r, c); |
7604 |
25 Feb 19 |
nicklas |
var cls = 'well'; |
7604 |
25 Feb 19 |
nicklas |
var title = ''; |
7604 |
25 Feb 19 |
nicklas |
if (well.locked) |
7604 |
25 Feb 19 |
nicklas |
165 |
{ |
7604 |
25 Feb 19 |
nicklas |
cls+= ' unmappable'; |
7604 |
25 Feb 19 |
nicklas |
if (well.name) |
7604 |
25 Feb 19 |
nicklas |
168 |
{ |
7604 |
25 Feb 19 |
nicklas |
title = 'This well is used by: ' + Strings.encodeTags(well.name); |
7604 |
25 Feb 19 |
nicklas |
170 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
172 |
{ |
7604 |
25 Feb 19 |
nicklas |
title = 'This well has already been used'; |
7604 |
25 Feb 19 |
nicklas |
174 |
} |
7604 |
25 Feb 19 |
nicklas |
175 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
177 |
{ |
7604 |
25 Feb 19 |
nicklas |
cls += ' empty editable'; |
7604 |
25 Feb 19 |
nicklas |
179 |
} |
7604 |
25 Feb 19 |
nicklas |
html += '<td id="dest.'+r+'.'+c+'" class="' + cls + '" data-row="'+r+'" data-column="'+c+'" title="'+title+'"></td>'; |
7604 |
25 Feb 19 |
nicklas |
181 |
} |
7604 |
25 Feb 19 |
nicklas |
html += '</tr>'; |
7604 |
25 Feb 19 |
nicklas |
183 |
} |
7604 |
25 Feb 19 |
nicklas |
html += '</table>'; |
7604 |
25 Feb 19 |
nicklas |
Doc.element('plate').innerHTML = html; |
7604 |
25 Feb 19 |
nicklas |
186 |
|
7604 |
25 Feb 19 |
nicklas |
var wells = Doc.element('plate').getElementsByClassName('editable'); |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < wells.length; i++) |
7604 |
25 Feb 19 |
nicklas |
189 |
{ |
7604 |
25 Feb 19 |
nicklas |
var well = wells[i]; |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler(well, 'click', pop.wellOnClick); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler(well, 'mouseout', pop.wellOnMouseOut); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler(well, 'mouseover', pop.wellOnMouseOver); |
7604 |
25 Feb 19 |
nicklas |
194 |
} |
7604 |
25 Feb 19 |
nicklas |
195 |
|
7604 |
25 Feb 19 |
nicklas |
Doc.show('toolbar.mappings'); |
7604 |
25 Feb 19 |
nicklas |
197 |
} |
7604 |
25 Feb 19 |
nicklas |
198 |
|
7604 |
25 Feb 19 |
nicklas |
199 |
|
7604 |
25 Feb 19 |
nicklas |
pop.placeOnPlate = function() |
7604 |
25 Feb 19 |
nicklas |
201 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (!plate) |
7604 |
25 Feb 19 |
nicklas |
203 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification('btnSelectPlate', 'No plate has been selected'); |
7604 |
25 Feb 19 |
nicklas |
return; |
7604 |
25 Feb 19 |
nicklas |
206 |
} |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['main']; |
7604 |
25 Feb 19 |
nicklas |
if (Strings.trim(frm.name.value) == '') |
7604 |
25 Feb 19 |
nicklas |
209 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(frm.name, 'You must enter a name for the event'); |
7604 |
25 Feb 19 |
nicklas |
return; |
7604 |
25 Feb 19 |
nicklas |
212 |
} |
7604 |
25 Feb 19 |
nicklas |
213 |
|
7604 |
25 Feb 19 |
nicklas |
frm.plate_id.value = plate.id; |
7604 |
25 Feb 19 |
nicklas |
frm.rows.value = plate.rows; |
7604 |
25 Feb 19 |
nicklas |
frm.columns.value = plate.columns; |
7604 |
25 Feb 19 |
nicklas |
217 |
|
7604 |
25 Feb 19 |
nicklas |
var numMapped = 0; |
7604 |
25 Feb 19 |
nicklas |
for (var row = 0; row < plate.rows; row++) |
7604 |
25 Feb 19 |
nicklas |
220 |
{ |
7604 |
25 Feb 19 |
nicklas |
for (var column = 0; column < plate.columns; column++) |
7604 |
25 Feb 19 |
nicklas |
222 |
{ |
7604 |
25 Feb 19 |
nicklas |
var well = plate.getWell(row, column); |
7604 |
25 Feb 19 |
nicklas |
224 |
|
7604 |
25 Feb 19 |
nicklas |
if (well.mappedItem) |
7604 |
25 Feb 19 |
nicklas |
226 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.addHidden(frm, 'well.' + row + '.' + column, well.mappedItem.id); |
7604 |
25 Feb 19 |
nicklas |
numMapped++; |
7604 |
25 Feb 19 |
nicklas |
229 |
} |
7604 |
25 Feb 19 |
nicklas |
230 |
} |
7604 |
25 Feb 19 |
nicklas |
231 |
} |
7604 |
25 Feb 19 |
nicklas |
232 |
|
7604 |
25 Feb 19 |
nicklas |
if (numMapped == 0) |
7604 |
25 Feb 19 |
nicklas |
234 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification('btnSave', 'No biomaterial has been mapped to wells'); |
7604 |
25 Feb 19 |
nicklas |
return; |
7604 |
25 Feb 19 |
nicklas |
237 |
} |
7604 |
25 Feb 19 |
nicklas |
238 |
|
7604 |
25 Feb 19 |
nicklas |
frm.submit(); |
7604 |
25 Feb 19 |
nicklas |
240 |
} |
7604 |
25 Feb 19 |
nicklas |
241 |
|
7604 |
25 Feb 19 |
nicklas |
242 |
/** |
7604 |
25 Feb 19 |
nicklas |
Draw a link between the item and it's mapped well. |
7604 |
25 Feb 19 |
nicklas |
244 |
*/ |
7604 |
25 Feb 19 |
nicklas |
pop.itemOnMouseOver = function(event) |
7604 |
25 Feb 19 |
nicklas |
246 |
{ |
7604 |
25 Feb 19 |
nicklas |
var itemId = Data.get(event.currentTarget, 'item-id'); |
7604 |
25 Feb 19 |
nicklas |
var item = itemList.getItem(itemId); |
7604 |
25 Feb 19 |
nicklas |
item.drawLink(graphics, pen, false); |
7604 |
25 Feb 19 |
nicklas |
250 |
} |
7604 |
25 Feb 19 |
nicklas |
251 |
|
7604 |
25 Feb 19 |
nicklas |
252 |
/** |
7604 |
25 Feb 19 |
nicklas |
Hide the link between the item and it's mapped well, |
7604 |
25 Feb 19 |
nicklas |
unless the item (or it's mapped well) is selected. |
7604 |
25 Feb 19 |
nicklas |
255 |
*/ |
7604 |
25 Feb 19 |
nicklas |
pop.itemOnMouseOut = function(event) |
7604 |
25 Feb 19 |
nicklas |
257 |
{ |
7604 |
25 Feb 19 |
nicklas |
var itemId = Data.get(event.currentTarget, 'item-id'); |
7604 |
25 Feb 19 |
nicklas |
var item = itemList.getItem(itemId); |
7604 |
25 Feb 19 |
nicklas |
260 |
|
7604 |
25 Feb 19 |
nicklas |
if (!item.selected && !(item.mappedWell && item.mappedWell.selected)) |
7604 |
25 Feb 19 |
nicklas |
262 |
{ |
7604 |
25 Feb 19 |
nicklas |
item.hideLink(graphics); |
7604 |
25 Feb 19 |
nicklas |
264 |
} |
7604 |
25 Feb 19 |
nicklas |
265 |
} |
7604 |
25 Feb 19 |
nicklas |
266 |
|
7604 |
25 Feb 19 |
nicklas |
267 |
/** |
7604 |
25 Feb 19 |
nicklas |
Select the item that is clicked on. The currently selected item |
7604 |
25 Feb 19 |
nicklas |
is de-selected. If the clicked item is the same as the currently |
7604 |
25 Feb 19 |
nicklas |
selected item no new item is selected. If a well is already selected |
7604 |
25 Feb 19 |
nicklas |
a link is made between the well and the newly selected item. |
7604 |
25 Feb 19 |
nicklas |
272 |
*/ |
7604 |
25 Feb 19 |
nicklas |
pop.itemOnClick = function(event) |
7604 |
25 Feb 19 |
nicklas |
274 |
{ |
7604 |
25 Feb 19 |
nicklas |
var itemId = Data.get(event.currentTarget, 'item-id'); |
7604 |
25 Feb 19 |
nicklas |
var item = itemList.getItem(itemId); |
7604 |
25 Feb 19 |
nicklas |
277 |
|
7604 |
25 Feb 19 |
nicklas |
// De-select the currently selected item |
7604 |
25 Feb 19 |
nicklas |
if (selectedItem) |
7604 |
25 Feb 19 |
nicklas |
280 |
{ |
7604 |
25 Feb 19 |
nicklas |
selectedItem.setSelected(false); |
7604 |
25 Feb 19 |
nicklas |
if (item == selectedItem) |
7604 |
25 Feb 19 |
nicklas |
283 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Re-draw link with regular pen (eg. same as onmouseover) |
7604 |
25 Feb 19 |
nicklas |
selectedItem.drawLink(graphics, pen, true); |
7604 |
25 Feb 19 |
nicklas |
selectedItem = null; |
7604 |
25 Feb 19 |
nicklas |
return; |
7604 |
25 Feb 19 |
nicklas |
288 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
290 |
{ |
7604 |
25 Feb 19 |
nicklas |
selectedItem.hideLink(graphics); |
7604 |
25 Feb 19 |
nicklas |
292 |
} |
7604 |
25 Feb 19 |
nicklas |
293 |
} |
7604 |
25 Feb 19 |
nicklas |
294 |
|
7604 |
25 Feb 19 |
nicklas |
// Select the new item and draw link to mapped well |
7604 |
25 Feb 19 |
nicklas |
selectedItem = item; |
7604 |
25 Feb 19 |
nicklas |
selectedItem.setSelected(true); |
7604 |
25 Feb 19 |
nicklas |
selectedItem.drawLink(graphics, selectedPen, true); |
7604 |
25 Feb 19 |
nicklas |
299 |
|
7604 |
25 Feb 19 |
nicklas |
// Map the item to the selected well |
7604 |
25 Feb 19 |
nicklas |
if (selectedWell && selectedItem) |
7604 |
25 Feb 19 |
nicklas |
302 |
{ |
7604 |
25 Feb 19 |
nicklas |
pop.placeSelectedOnPlate(); |
7604 |
25 Feb 19 |
nicklas |
304 |
} |
7604 |
25 Feb 19 |
nicklas |
305 |
} |
7604 |
25 Feb 19 |
nicklas |
306 |
|
7604 |
25 Feb 19 |
nicklas |
307 |
|
7604 |
25 Feb 19 |
nicklas |
308 |
/** |
7604 |
25 Feb 19 |
nicklas |
Draw a link between the well and it's mapped item. |
7604 |
25 Feb 19 |
nicklas |
310 |
*/ |
7604 |
25 Feb 19 |
nicklas |
pop.wellOnMouseOver = function(event) |
7604 |
25 Feb 19 |
nicklas |
312 |
{ |
7604 |
25 Feb 19 |
nicklas |
var row = Data.int(event.currentTarget, 'row'); |
7604 |
25 Feb 19 |
nicklas |
var column = Data.int(event.currentTarget, 'column'); |
7604 |
25 Feb 19 |
nicklas |
315 |
|
7604 |
25 Feb 19 |
nicklas |
var well = plate.getWell(row, column); |
7604 |
25 Feb 19 |
nicklas |
if (!well || !well.mappedItem) return; |
7604 |
25 Feb 19 |
nicklas |
well.mappedItem.scrollIntoView(); |
7604 |
25 Feb 19 |
nicklas |
well.mappedItem.drawLink(graphics, pen, false); |
7604 |
25 Feb 19 |
nicklas |
320 |
} |
7604 |
25 Feb 19 |
nicklas |
321 |
|
7604 |
25 Feb 19 |
nicklas |
322 |
/** |
7604 |
25 Feb 19 |
nicklas |
Hide the link between the well and it's mapped item, |
7604 |
25 Feb 19 |
nicklas |
unless the well (or it's mapped item) is selected. |
7604 |
25 Feb 19 |
nicklas |
325 |
*/ |
7604 |
25 Feb 19 |
nicklas |
pop.wellOnMouseOut = function(event) |
7604 |
25 Feb 19 |
nicklas |
327 |
{ |
7604 |
25 Feb 19 |
nicklas |
var row = Data.int(event.currentTarget, 'row'); |
7604 |
25 Feb 19 |
nicklas |
var column = Data.int(event.currentTarget, 'column'); |
7604 |
25 Feb 19 |
nicklas |
330 |
|
7604 |
25 Feb 19 |
nicklas |
var well = plate.getWell(row, column); |
7604 |
25 Feb 19 |
nicklas |
if (!well || !well.mappedItem) return; |
7604 |
25 Feb 19 |
nicklas |
if (!well.selected && !(well.mappedItem && well.mappedItem.selected)) |
7604 |
25 Feb 19 |
nicklas |
334 |
{ |
7604 |
25 Feb 19 |
nicklas |
well.hideLink(graphics); |
7604 |
25 Feb 19 |
nicklas |
336 |
} |
7604 |
25 Feb 19 |
nicklas |
337 |
} |
7604 |
25 Feb 19 |
nicklas |
338 |
|
7604 |
25 Feb 19 |
nicklas |
339 |
/** |
7604 |
25 Feb 19 |
nicklas |
Select the well that is clicked on. The currently selected well is |
7604 |
25 Feb 19 |
nicklas |
de-selected. If the clicked well is the same as the currently |
7604 |
25 Feb 19 |
nicklas |
selected well no new well is selected. If an item is already selected |
7604 |
25 Feb 19 |
nicklas |
a link is made between the item and the newly selected well. |
7604 |
25 Feb 19 |
nicklas |
344 |
*/ |
7604 |
25 Feb 19 |
nicklas |
pop.wellOnClick = function(event) |
7604 |
25 Feb 19 |
nicklas |
346 |
{ |
7604 |
25 Feb 19 |
nicklas |
var row = Data.int(event.currentTarget, 'row'); |
7604 |
25 Feb 19 |
nicklas |
var column = Data.int(event.currentTarget, 'column'); |
7604 |
25 Feb 19 |
nicklas |
var well = plate.getWell(row, column); |
7604 |
25 Feb 19 |
nicklas |
350 |
|
7604 |
25 Feb 19 |
nicklas |
// De-select the currently selected well |
7604 |
25 Feb 19 |
nicklas |
if (selectedWell) |
7604 |
25 Feb 19 |
nicklas |
353 |
{ |
7604 |
25 Feb 19 |
nicklas |
selectedWell.setSelected(false); |
7604 |
25 Feb 19 |
nicklas |
if (well == selectedWell) |
7604 |
25 Feb 19 |
nicklas |
356 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Re-draw link with regular pen (eg. same as onmouseover) |
7604 |
25 Feb 19 |
nicklas |
selectedWell.drawLink(graphics, pen, true); |
7604 |
25 Feb 19 |
nicklas |
selectedWell = null; |
7604 |
25 Feb 19 |
nicklas |
return; |
7604 |
25 Feb 19 |
nicklas |
361 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
363 |
{ |
7604 |
25 Feb 19 |
nicklas |
selectedWell.hideLink(graphics); |
7604 |
25 Feb 19 |
nicklas |
365 |
} |
7604 |
25 Feb 19 |
nicklas |
366 |
} |
7604 |
25 Feb 19 |
nicklas |
367 |
|
7604 |
25 Feb 19 |
nicklas |
selectedWell = well; |
7604 |
25 Feb 19 |
nicklas |
selectedWell.setSelected(true); |
7604 |
25 Feb 19 |
nicklas |
selectedWell.drawLink(graphics, selectedPen, true); |
7604 |
25 Feb 19 |
nicklas |
371 |
|
7604 |
25 Feb 19 |
nicklas |
if (selectedWell && selectedItem) |
7604 |
25 Feb 19 |
nicklas |
373 |
{ |
7604 |
25 Feb 19 |
nicklas |
var nextItem = Doc.element('autoSelectUnmappedItem').checked ? |
7604 |
25 Feb 19 |
nicklas |
itemList.nextUnmappedItem(selectedItem) : null; |
7604 |
25 Feb 19 |
nicklas |
pop.placeSelectedOnPlate(); |
7604 |
25 Feb 19 |
nicklas |
if (nextItem) |
7604 |
25 Feb 19 |
nicklas |
378 |
{ |
7604 |
25 Feb 19 |
nicklas |
nextItem.setSelected(true); |
7604 |
25 Feb 19 |
nicklas |
nextItem.scrollIntoView(); |
7604 |
25 Feb 19 |
nicklas |
selectedItem = nextItem; |
7604 |
25 Feb 19 |
nicklas |
382 |
} |
7604 |
25 Feb 19 |
nicklas |
383 |
} |
7604 |
25 Feb 19 |
nicklas |
384 |
} |
7604 |
25 Feb 19 |
nicklas |
385 |
|
7604 |
25 Feb 19 |
nicklas |
386 |
/** |
7604 |
25 Feb 19 |
nicklas |
Redraw the link to the selected item/well when the item list scrolls. |
7604 |
25 Feb 19 |
nicklas |
388 |
*/ |
7604 |
25 Feb 19 |
nicklas |
pop.onLayoutChange = function(event) |
7604 |
25 Feb 19 |
nicklas |
390 |
{ |
7604 |
25 Feb 19 |
nicklas |
var item = selectedItem; |
7604 |
25 Feb 19 |
nicklas |
if (!item && selectedWell) item = selectedWell.mappedItem; |
7604 |
25 Feb 19 |
nicklas |
if (item) item.drawLink(graphics, selectedPen, true); |
7604 |
25 Feb 19 |
nicklas |
394 |
} |
7604 |
25 Feb 19 |
nicklas |
395 |
|
7604 |
25 Feb 19 |
nicklas |
396 |
|
7604 |
25 Feb 19 |
nicklas |
397 |
/** |
7604 |
25 Feb 19 |
nicklas |
Map the selected item with the selected well. Hide and |
7604 |
25 Feb 19 |
nicklas |
redraw links as needed. |
7604 |
25 Feb 19 |
nicklas |
400 |
*/ |
7604 |
25 Feb 19 |
nicklas |
pop.placeSelectedOnPlate = function() |
7604 |
25 Feb 19 |
nicklas |
402 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Hide any links that are currently displayed |
7604 |
25 Feb 19 |
nicklas |
selectedItem.hideLink(graphics); |
7604 |
25 Feb 19 |
nicklas |
selectedWell.hideLink(graphics); |
7604 |
25 Feb 19 |
nicklas |
406 |
|
7604 |
25 Feb 19 |
nicklas |
// Map to the new well and draw link |
7604 |
25 Feb 19 |
nicklas |
if (selectedItem.mappedWell != selectedWell) |
7604 |
25 Feb 19 |
nicklas |
409 |
{ |
7604 |
25 Feb 19 |
nicklas |
selectedItem.mapToWell(selectedWell); |
7604 |
25 Feb 19 |
nicklas |
selectedItem.scrollIntoView(); |
7604 |
25 Feb 19 |
nicklas |
selectedItem.drawLink(graphics, pen, true); |
7604 |
25 Feb 19 |
nicklas |
413 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
415 |
{ |
7604 |
25 Feb 19 |
nicklas |
selectedItem.unmapWell(); |
7604 |
25 Feb 19 |
nicklas |
417 |
} |
7604 |
25 Feb 19 |
nicklas |
418 |
|
7604 |
25 Feb 19 |
nicklas |
// De-select everything |
7604 |
25 Feb 19 |
nicklas |
selectedItem.setSelected(false); |
7604 |
25 Feb 19 |
nicklas |
selectedWell.setSelected(false); |
7604 |
25 Feb 19 |
nicklas |
selectedItem = null; |
7604 |
25 Feb 19 |
nicklas |
selectedWell = null; |
7604 |
25 Feb 19 |
nicklas |
424 |
} |
7604 |
25 Feb 19 |
nicklas |
425 |
|
7604 |
25 Feb 19 |
nicklas |
426 |
/** |
7604 |
25 Feb 19 |
nicklas |
Remove all mappings that have been made so far. |
7604 |
25 Feb 19 |
nicklas |
428 |
*/ |
7604 |
25 Feb 19 |
nicklas |
pop.clearMapping = function() |
7604 |
25 Feb 19 |
nicklas |
430 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (!plate) |
7604 |
25 Feb 19 |
nicklas |
432 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification('btnSelectPlate', 'No destination plate has been selected'); |
7604 |
25 Feb 19 |
nicklas |
return; |
7604 |
25 Feb 19 |
nicklas |
435 |
} |
7604 |
25 Feb 19 |
nicklas |
if (!confirm('This will remove all placed biomaterial. Continue?')) return; |
7604 |
25 Feb 19 |
nicklas |
itemList.unmapAll(graphics); |
7604 |
25 Feb 19 |
nicklas |
if (selectedItem) |
7604 |
25 Feb 19 |
nicklas |
439 |
{ |
7604 |
25 Feb 19 |
nicklas |
selectedItem.setSelected(false); |
7604 |
25 Feb 19 |
nicklas |
selectedItem = null; |
7604 |
25 Feb 19 |
nicklas |
442 |
} |
7604 |
25 Feb 19 |
nicklas |
if (selectedWell) |
7604 |
25 Feb 19 |
nicklas |
444 |
{ |
7604 |
25 Feb 19 |
nicklas |
selectedWell.setSelected(false); |
7604 |
25 Feb 19 |
nicklas |
selectedWell = null; |
7604 |
25 Feb 19 |
nicklas |
447 |
} |
7604 |
25 Feb 19 |
nicklas |
448 |
} |
7604 |
25 Feb 19 |
nicklas |
449 |
|
7604 |
25 Feb 19 |
nicklas |
450 |
/** |
7604 |
25 Feb 19 |
nicklas |
Automatically place unplaced biomaterial on the plate filling rows first. |
7604 |
25 Feb 19 |
nicklas |
Biomaterial and wells that have already been mapped are skipped. |
7604 |
25 Feb 19 |
nicklas |
453 |
*/ |
7604 |
25 Feb 19 |
nicklas |
pop.placeByRow = function() |
7604 |
25 Feb 19 |
nicklas |
455 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (!plate) |
7604 |
25 Feb 19 |
nicklas |
457 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification('btnSelectPlate', 'No destination plate has been selected'); |
7604 |
25 Feb 19 |
nicklas |
return; |
7604 |
25 Feb 19 |
nicklas |
460 |
} |
7604 |
25 Feb 19 |
nicklas |
var index = 0; |
7604 |
25 Feb 19 |
nicklas |
var numItems = itemList.items.length; |
7604 |
25 Feb 19 |
nicklas |
for (var row = 0; row < plate.rows; row++) |
7604 |
25 Feb 19 |
nicklas |
464 |
{ |
7604 |
25 Feb 19 |
nicklas |
for (var column = 0; column < plate.columns; column++) |
7604 |
25 Feb 19 |
nicklas |
466 |
{ |
7604 |
25 Feb 19 |
nicklas |
var well = plate.getWell(row, column); |
7604 |
25 Feb 19 |
nicklas |
if (!well.mappedItem && !well.locked) |
7604 |
25 Feb 19 |
nicklas |
469 |
{ |
7604 |
25 Feb 19 |
nicklas |
var mapped = false; |
7604 |
25 Feb 19 |
nicklas |
while (index < itemList.items.length && !mapped) |
7604 |
25 Feb 19 |
nicklas |
472 |
{ |
7604 |
25 Feb 19 |
nicklas |
var item = itemList.items[index]; |
7604 |
25 Feb 19 |
nicklas |
index++; |
7604 |
25 Feb 19 |
nicklas |
if (!item.mappedWell) |
7604 |
25 Feb 19 |
nicklas |
476 |
{ |
7604 |
25 Feb 19 |
nicklas |
item.mapToWell(well); |
7604 |
25 Feb 19 |
nicklas |
mapped = true; |
7604 |
25 Feb 19 |
nicklas |
479 |
} |
7604 |
25 Feb 19 |
nicklas |
480 |
} |
7604 |
25 Feb 19 |
nicklas |
481 |
} |
7604 |
25 Feb 19 |
nicklas |
482 |
} |
7604 |
25 Feb 19 |
nicklas |
483 |
} |
7604 |
25 Feb 19 |
nicklas |
484 |
} |
7604 |
25 Feb 19 |
nicklas |
485 |
|
7604 |
25 Feb 19 |
nicklas |
486 |
/** |
7604 |
25 Feb 19 |
nicklas |
Automatically place unplaced biomaterial on the plate filling columns first. |
7604 |
25 Feb 19 |
nicklas |
Biomaterial and wells that have already been mapped are skipped. |
7604 |
25 Feb 19 |
nicklas |
489 |
*/ |
7604 |
25 Feb 19 |
nicklas |
pop.placeByColumn = function() |
7604 |
25 Feb 19 |
nicklas |
491 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (!plate) |
7604 |
25 Feb 19 |
nicklas |
493 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification('btnSelectPlate', 'No destination plate has been selected'); |
7604 |
25 Feb 19 |
nicklas |
return; |
7604 |
25 Feb 19 |
nicklas |
496 |
} |
7604 |
25 Feb 19 |
nicklas |
var index = 0; |
7604 |
25 Feb 19 |
nicklas |
var numItems = itemList.items.length; |
7604 |
25 Feb 19 |
nicklas |
for (var column = 0; column < plate.columns; column++) |
7604 |
25 Feb 19 |
nicklas |
500 |
{ |
7604 |
25 Feb 19 |
nicklas |
for (var row = 0; row < plate.rows; row++) |
7604 |
25 Feb 19 |
nicklas |
502 |
{ |
7604 |
25 Feb 19 |
nicklas |
var well = plate.getWell(row, column); |
7604 |
25 Feb 19 |
nicklas |
if (!well.mappedItem && !well.locked) |
7604 |
25 Feb 19 |
nicklas |
505 |
{ |
7604 |
25 Feb 19 |
nicklas |
var mapped = false; |
7604 |
25 Feb 19 |
nicklas |
while (index < itemList.items.length && !mapped) |
7604 |
25 Feb 19 |
nicklas |
508 |
{ |
7604 |
25 Feb 19 |
nicklas |
var item = itemList.items[index]; |
7604 |
25 Feb 19 |
nicklas |
index++; |
7604 |
25 Feb 19 |
nicklas |
if (!item.mappedWell) |
7604 |
25 Feb 19 |
nicklas |
512 |
{ |
7604 |
25 Feb 19 |
nicklas |
item.mapToWell(well); |
7604 |
25 Feb 19 |
nicklas |
mapped = true; |
7604 |
25 Feb 19 |
nicklas |
515 |
} |
7604 |
25 Feb 19 |
nicklas |
516 |
} |
7604 |
25 Feb 19 |
nicklas |
517 |
} |
7604 |
25 Feb 19 |
nicklas |
518 |
} |
7604 |
25 Feb 19 |
nicklas |
519 |
} |
7604 |
25 Feb 19 |
nicklas |
520 |
} |
7604 |
25 Feb 19 |
nicklas |
521 |
|
7604 |
25 Feb 19 |
nicklas |
return pop; |
7604 |
25 Feb 19 |
nicklas |
523 |
}(); |
7604 |
25 Feb 19 |
nicklas |
524 |
|
7604 |
25 Feb 19 |
nicklas |
Doc.onLoad(PlaceOnPlate.initPage); |