www/admin/annotationtypes/annotationtypes.js

Code
Comments
Other
Rev Date Author Line
7604 25 Feb 19 nicklas 1 /* $Id $
7604 25 Feb 19 nicklas 2   ------------------------------------------------------------------
7604 25 Feb 19 nicklas 3   Copyright (C) 2012 Nicklas Nordborg
7604 25 Feb 19 nicklas 4
7604 25 Feb 19 nicklas 5   This file is part of BASE - BioArray Software Environment.
7604 25 Feb 19 nicklas 6   Available at http://base.thep.lu.se/
7604 25 Feb 19 nicklas 7
7604 25 Feb 19 nicklas 8   BASE is free software; you can redistribute it and/or
7604 25 Feb 19 nicklas 9   modify it under the terms of the GNU General Public License
7604 25 Feb 19 nicklas 10   as published by the Free Software Foundation; either version 3
7604 25 Feb 19 nicklas 11   of the License, or (at your option) any later version.
7604 25 Feb 19 nicklas 12
7604 25 Feb 19 nicklas 13   BASE is distributed in the hope that it will be useful,
7604 25 Feb 19 nicklas 14   but WITHOUT ANY WARRANTY; without even the implied warranty of
7604 25 Feb 19 nicklas 15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7604 25 Feb 19 nicklas 16   GNU General Public License for more details.
7604 25 Feb 19 nicklas 17
7604 25 Feb 19 nicklas 18   You should have received a copy of the GNU General Public License
7604 25 Feb 19 nicklas 19   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 22   @author Nicklas
7604 25 Feb 19 nicklas 23 */
7604 25 Feb 19 nicklas 24 'use strict';
7604 25 Feb 19 nicklas 25
7604 25 Feb 19 nicklas 26 var AnnotationTypes = function()
7604 25 Feb 19 nicklas 27 {
7604 25 Feb 19 nicklas 28   var annotationTypes = {};
7604 25 Feb 19 nicklas 29   
7604 25 Feb 19 nicklas 30   /**
7604 25 Feb 19 nicklas 31     Initialize the page.
7604 25 Feb 19 nicklas 32   */
7604 25 Feb 19 nicklas 33   annotationTypes.initPage = function()
7604 25 Feb 19 nicklas 34   {
7604 25 Feb 19 nicklas 35     var pageId = Doc.getPageId();    
7604 25 Feb 19 nicklas 36     if (pageId == 'edit-page')
7604 25 Feb 19 nicklas 37     {
7604 25 Feb 19 nicklas 38       // Save + Close buttons
7604 25 Feb 19 nicklas 39       Buttons.addClickHandler('btnSave', annotationTypes.save);
7604 25 Feb 19 nicklas 40       Buttons.addClickHandler('close', App.closeWindow);
7604 25 Feb 19 nicklas 41
7604 25 Feb 19 nicklas 42       // Tab validation
7604 25 Feb 19 nicklas 43       TabControl.addTabValidator('settings.info', annotationTypes.validateAnnotationType);
7604 25 Feb 19 nicklas 44       
7604 25 Feb 19 nicklas 45       // Options
7604 25 Feb 19 nicklas 46       Buttons.addClickHandler('interfaceBox', annotationTypes.interfaceOnClick);
7604 25 Feb 19 nicklas 47       Buttons.addClickHandler('interfaceList', annotationTypes.interfaceOnClick);
7604 25 Feb 19 nicklas 48       Buttons.addClickHandler('interfaceButtons', annotationTypes.interfaceOnClick);
7604 25 Feb 19 nicklas 49       annotationTypes.interfaceOnClick();
7604 25 Feb 19 nicklas 50       
7604 25 Feb 19 nicklas 51       // Item type lists
7604 25 Feb 19 nicklas 52       Buttons.addClickHandler('btnMoveLeft', Forms.moveSelectedOnClick);
7604 25 Feb 19 nicklas 53       Buttons.addClickHandler('btnMoveRight', Forms.moveSelectedOnClick);
7604 25 Feb 19 nicklas 54       Events.addEventHandler('enabled', 'dblclick', Forms.moveSelectedOnClick);
7604 25 Feb 19 nicklas 55       Events.addEventHandler('disabled', 'dblclick', Forms.moveSelectedOnClick);
7604 25 Feb 19 nicklas 56       
7604 25 Feb 19 nicklas 57       // Units
7604 25 Feb 19 nicklas 58       annotationTypes.initQuantities();
7604 25 Feb 19 nicklas 59       Events.addEventHandler('quantity_id', 'change', annotationTypes.quantityOnChange);
7604 25 Feb 19 nicklas 60       Buttons.addClickHandler('btnAddUsableUnits', annotationTypes.addToUsableUnits);
7604 25 Feb 19 nicklas 61       Events.addEventHandler('allUnits', 'dblclick', annotationTypes.addToUsableUnits);
7604 25 Feb 19 nicklas 62     }
7604 25 Feb 19 nicklas 63     else if (pageId == 'view-page')
7604 25 Feb 19 nicklas 64     {
7604 25 Feb 19 nicklas 65       var itemId = Data.get('page-data', 'item-id');
7604 25 Feb 19 nicklas 66       var attributes = {'item-type': 'ANNOTATIONTYPE', 'item-id': itemId};
7604 25 Feb 19 nicklas 67       
7604 25 Feb 19 nicklas 68       Buttons.addClickHandler('btnEdit', Buttons.editItem, attributes);
7604 25 Feb 19 nicklas 69       Buttons.addClickHandler('btnDelete', Buttons.deleteItem, attributes);
7604 25 Feb 19 nicklas 70       Buttons.addClickHandler('btnRestore', Buttons.restoreItem, attributes);
7604 25 Feb 19 nicklas 71       Buttons.addClickHandler('btnUsingItems', Buttons.showUsingItems, attributes);
7604 25 Feb 19 nicklas 72       Buttons.addClickHandler('btnDeletePermanently', Buttons.deleteItemPermanently, attributes);
7604 25 Feb 19 nicklas 73       Buttons.addClickHandler('btnShare', Buttons.shareItem, attributes);
7604 25 Feb 19 nicklas 74       Buttons.addClickHandler('btnSetOwner', Buttons.setOwner, attributes);
7604 25 Feb 19 nicklas 75       Buttons.addClickHandler('btnExport', Buttons.runPlugin, attributes);
7604 25 Feb 19 nicklas 76       Buttons.addClickHandler('btnImport', Buttons.runPlugin, attributes);
7604 25 Feb 19 nicklas 77       Buttons.addClickHandler('btnRunPlugin', Buttons.runPlugin, attributes);
7604 25 Feb 19 nicklas 78       
7604 25 Feb 19 nicklas 79       TabControl.addTabActivateListener('main.history', History.loadOnce);
7604 25 Feb 19 nicklas 80     }
7604 25 Feb 19 nicklas 81     else if (pageId == 'list-page')
7604 25 Feb 19 nicklas 82     {
7604 25 Feb 19 nicklas 83       var attributes = {'item-type': 'ANNOTATIONTYPE'};
7604 25 Feb 19 nicklas 84       var tableAttributes = {'table-id': 'annotationTypes'};
7604 25 Feb 19 nicklas 85       Buttons.addClickHandler('mnuNewAnnotationType', annotationTypes.newItem);
7604 25 Feb 19 nicklas 86       Buttons.addClickHandler('btnDeleteItems', Buttons.deleteItems, tableAttributes);
7604 25 Feb 19 nicklas 87       Buttons.addClickHandler('btnRestoreItems', Buttons.restoreItems, tableAttributes);
7604 25 Feb 19 nicklas 88       Buttons.addClickHandler('btnShareItems', Buttons.shareItems, tableAttributes);
7604 25 Feb 19 nicklas 89       Buttons.addClickHandler('btnSetOwner', Buttons.setOwnerOfItems, tableAttributes);
7604 25 Feb 19 nicklas 90       Buttons.addClickHandler('btnColumns', Buttons.configureColumns, tableAttributes);
7604 25 Feb 19 nicklas 91       Buttons.addClickHandler('btnExport', Buttons.runListPlugin, tableAttributes);
7604 25 Feb 19 nicklas 92       Buttons.addClickHandler('btnImport', Buttons.runListPlugin, tableAttributes);
7604 25 Feb 19 nicklas 93       Buttons.addClickHandler('btnRunPlugin', Buttons.runListPlugin, tableAttributes);
7604 25 Feb 19 nicklas 94       
7604 25 Feb 19 nicklas 95       Buttons.addClickHandler('close', App.closeWindow);
7604 25 Feb 19 nicklas 96       Buttons.addClickHandler('btnOk', Buttons.returnSelected, tableAttributes);
7604 25 Feb 19 nicklas 97     }
7604 25 Feb 19 nicklas 98   }
7604 25 Feb 19 nicklas 99
7604 25 Feb 19 nicklas 100   annotationTypes.newItem = function(event)
7604 25 Feb 19 nicklas 101   {
7604 25 Feb 19 nicklas 102     var valueType = Data.get(event.target, 'value-type');
7604 25 Feb 19 nicklas 103     Items.newItem('ANNOTATIONTYPE', '&value_type='+valueType);
7604 25 Feb 19 nicklas 104   }
7604 25 Feb 19 nicklas 105
7604 25 Feb 19 nicklas 106   annotationTypes.validateAnnotationType = function()
7604 25 Feb 19 nicklas 107   {
7604 25 Feb 19 nicklas 108     var frm = document.forms['annotationType'];
7604 25 Feb 19 nicklas 109     if (Strings.trim(frm.name.value) == '')
7604 25 Feb 19 nicklas 110     {
7604 25 Feb 19 nicklas 111       Forms.showNotification(frm.name, 'You must enter a name');
7604 25 Feb 19 nicklas 112       return false;
7604 25 Feb 19 nicklas 113     }
7604 25 Feb 19 nicklas 114     return true;
7604 25 Feb 19 nicklas 115   }
7604 25 Feb 19 nicklas 116   
7604 25 Feb 19 nicklas 117   annotationTypes.save = function()
7604 25 Feb 19 nicklas 118   {
7604 25 Feb 19 nicklas 119     var frm = document.forms['annotationType'];
7604 25 Feb 19 nicklas 120     if (TabControl.validateActiveTab('settings'))
7604 25 Feb 19 nicklas 121     {
7604 25 Feb 19 nicklas 122       var enabled = frm.enabled;
7604 25 Feb 19 nicklas 123       for (var i = 0; i < enabled.length; i++)
7604 25 Feb 19 nicklas 124       {
7604 25 Feb 19 nicklas 125         enabled.options[i].selected = true;
7604 25 Feb 19 nicklas 126       }
7604 25 Feb 19 nicklas 127       Link.exportActions('categories');
7604 25 Feb 19 nicklas 128       if (Doc.element('usableUnits'))
7604 25 Feb 19 nicklas 129       {
7604 25 Feb 19 nicklas 130         Link.exportActions('usableUnits');
7604 25 Feb 19 nicklas 131       }
7604 25 Feb 19 nicklas 132       frm.project_annotations.disabled = false;
7604 25 Feb 19 nicklas 133       frm.submit();
7604 25 Feb 19 nicklas 134     }
7604 25 Feb 19 nicklas 135   }
7604 25 Feb 19 nicklas 136   
7604 25 Feb 19 nicklas 137   annotationTypes.interfaceOnClick = function()
7604 25 Feb 19 nicklas 138   {
7604 25 Feb 19 nicklas 139     var frm = document.forms['annotationType'];
7604 25 Feb 19 nicklas 140     if (frm['interface'])
7604 25 Feb 19 nicklas 141     {
7604 25 Feb 19 nicklas 142       var isEnum = Forms.getCheckedRadio(frm['interface']).value != 'box';
7604 25 Feb 19 nicklas 143       if (frm.minValue) frm.minValue.disabled = isEnum;
7604 25 Feb 19 nicklas 144       if (frm.maxValue) frm.maxValue.disabled = isEnum;
7604 25 Feb 19 nicklas 145       if (frm.width) frm.width.disabled = isEnum;
7604 25 Feb 19 nicklas 146       if (frm.maxLength) frm.maxLength.disabled = isEnum;
7604 25 Feb 19 nicklas 147       if (frm.values) frm.values.disabled = !isEnum;
7604 25 Feb 19 nicklas 148     }
7604 25 Feb 19 nicklas 149   }
7604 25 Feb 19 nicklas 150
7604 25 Feb 19 nicklas 151   /**
7604 25 Feb 19 nicklas 152     Initialize the 'Quantities'. If a current
7604 25 Feb 19 nicklas 153     quantity is specified the 'Default unit' list is initialized
7604 25 Feb 19 nicklas 154     as well.
7604 25 Feb 19 nicklas 155    */
7604 25 Feb 19 nicklas 156   annotationTypes.initQuantities = function()
7604 25 Feb 19 nicklas 157   {
7604 25 Feb 19 nicklas 158     var frm = document.forms['annotationType'];
7604 25 Feb 19 nicklas 159     var quantities = Data.json('page-data', 'units');
7604 25 Feb 19 nicklas 160     var currentQuantityId = Data.int('page-data', 'current-quantity');
7604 25 Feb 19 nicklas 161     
7604 25 Feb 19 nicklas 162     for (var i = 0; i < quantities.length; i++)
7604 25 Feb 19 nicklas 163     {
7604 25 Feb 19 nicklas 164       var quantity = quantities[i];
7604 25 Feb 19 nicklas 165       var option = new Option(quantity.name, quantity.id, false, quantity.id == currentQuantityId);
7604 25 Feb 19 nicklas 166       option.quantity = quantity;
7604 25 Feb 19 nicklas 167       frm.quantity_id[frm.quantity_id.length] = option;
7604 25 Feb 19 nicklas 168     }
7604 25 Feb 19 nicklas 169     
7604 25 Feb 19 nicklas 170     // Initialize units for the current quantity
7604 25 Feb 19 nicklas 171     if (currentQuantityId > 0) 
7604 25 Feb 19 nicklas 172     {
7604 25 Feb 19 nicklas 173       annotationTypes.quantityOnChange();
7604 25 Feb 19 nicklas 174     }
7604 25 Feb 19 nicklas 175   }
7604 25 Feb 19 nicklas 176   
7604 25 Feb 19 nicklas 177   /**
7604 25 Feb 19 nicklas 178     If the selected quantity is changed, we need to update the list of
7604 25 Feb 19 nicklas 179     default units and also the two 'usable units' lists.
7604 25 Feb 19 nicklas 180   */
7604 25 Feb 19 nicklas 181   annotationTypes.quantityOnChange = function(event)
7604 25 Feb 19 nicklas 182   {
7604 25 Feb 19 nicklas 183     var frm = document.forms['annotationType'];
7604 25 Feb 19 nicklas 184     var quantity = frm.quantity_id[frm.quantity_id.selectedIndex].quantity;
7604 25 Feb 19 nicklas 185     var currentUnitId = Data.int('page-data', 'current-unit');
7604 25 Feb 19 nicklas 186     
7604 25 Feb 19 nicklas 187     // Update the default unit list with units from the selected quantity
7604 25 Feb 19 nicklas 188     frm.unit_id.length = 0;
7604 25 Feb 19 nicklas 189     frm.allUnits.length = 0;
7604 25 Feb 19 nicklas 190     
7604 25 Feb 19 nicklas 191     if (event)
7604 25 Feb 19 nicklas 192     {
7604 25 Feb 19 nicklas 193       // Clear the 'usable units' list
7604 25 Feb 19 nicklas 194       Link.removeAll(frm.usableUnits);
7604 25 Feb 19 nicklas 195     }
7604 25 Feb 19 nicklas 196     
7604 25 Feb 19 nicklas 197     if (quantity)
7604 25 Feb 19 nicklas 198     {
7604 25 Feb 19 nicklas 199       for (var i = 0; i < quantity.units.length; i++)
7604 25 Feb 19 nicklas 200       {
7604 25 Feb 19 nicklas 201         var unit = quantity.units[i];
7604 25 Feb 19 nicklas 202         var option = new Option(unit.name + ' [ '+unit.symbol+' ]', unit.id, false, currentUnitId == unit.id);
7604 25 Feb 19 nicklas 203         option.unit = unit;
7604 25 Feb 19 nicklas 204         frm.unit_id[frm.unit_id.length] = option;
7604 25 Feb 19 nicklas 205         
7604 25 Feb 19 nicklas 206         var addToAllUnits = true;
7604 25 Feb 19 nicklas 207         for (var j = 0; j < frm.usableUnits.length; j++)
7604 25 Feb 19 nicklas 208         {
7604 25 Feb 19 nicklas 209           if (frm.usableUnits[j].value == 'UNIT.'+unit.id)
7604 25 Feb 19 nicklas 210           {
7604 25 Feb 19 nicklas 211             addToAllUnits = false;
7604 25 Feb 19 nicklas 212             j = frm.usableUnits.length;
7604 25 Feb 19 nicklas 213           }
7604 25 Feb 19 nicklas 214         }
7604 25 Feb 19 nicklas 215         if (addToAllUnits)
7604 25 Feb 19 nicklas 216         {
7604 25 Feb 19 nicklas 217           frm.allUnits[frm.allUnits.length] = new Option(unit.name + ' [ '+unit.symbol+' ]', unit.id);
7604 25 Feb 19 nicklas 218         }
7604 25 Feb 19 nicklas 219       }
7604 25 Feb 19 nicklas 220     }
7604 25 Feb 19 nicklas 221   }
7604 25 Feb 19 nicklas 222   
7604 25 Feb 19 nicklas 223   /**
7604 25 Feb 19 nicklas 224     Event handler for adding selected units from the 'All units' list to
7604 25 Feb 19 nicklas 225     the 'Usable units' list.
7604 25 Feb 19 nicklas 226   */
7604 25 Feb 19 nicklas 227   annotationTypes.addToUsableUnits = function(event)
7604 25 Feb 19 nicklas 228   {
7604 25 Feb 19 nicklas 229     var frm = document.forms['annotationType'];
7604 25 Feb 19 nicklas 230     for (var i = 0; i < frm.allUnits.length; i++)
7604 25 Feb 19 nicklas 231     {
7604 25 Feb 19 nicklas 232       var option = frm.allUnits[i];
7604 25 Feb 19 nicklas 233       if (option.selected)
7604 25 Feb 19 nicklas 234       {
7604 25 Feb 19 nicklas 235         Link.addItem(frm.usableUnits, 'UNIT', {'id': option.value, 'name': option.text });
7604 25 Feb 19 nicklas 236         frm.allUnits[i--] = null;
7604 25 Feb 19 nicklas 237       }
7604 25 Feb 19 nicklas 238     }
7604 25 Feb 19 nicklas 239   }  
7604 25 Feb 19 nicklas 240   
7604 25 Feb 19 nicklas 241   return annotationTypes;
7604 25 Feb 19 nicklas 242 }();
7604 25 Feb 19 nicklas 243
7604 25 Feb 19 nicklas 244 if (Doc.getPageId() == 'edit-page') 
7604 25 Feb 19 nicklas 245 {
7604 25 Feb 19 nicklas 246   Doc.addElementInitializer(Forms.numberOnlyInitializer);
7604 25 Feb 19 nicklas 247 }
7604 25 Feb 19 nicklas 248 Doc.onLoad(AnnotationTypes.initPage);