Changeset 6955
- Timestamp:
- Sep 28, 2015, 1:38:54 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/clients/web/net/sf/basedb/clients/web/Base.java
r6947 r6955 1514 1514 } 1515 1515 } 1516 1517 /*1518 for (int i = 0; i < modifiedAnnotations.length; ++i)1519 {1520 int annotationTypeId = Values.getInt(modifiedAnnotations[i], -1);1521 if (annotationTypeId != -1)1522 {1523 AnnotationType at = AnnotationType.getById(dc, annotationTypeId);1524 String[] values = request.getParameterValues(String.valueOf(at.getId()));1525 int unitId = Values.getInt(request.getParameter("unit:" + at.getId()), 0);1526 Unit unit = unitId == 0 ? null : Unit.getById(dc, unitId);1527 Annotation oldAn = oldAs == null || !oldAs.hasAnnotation(at, Annotation.Source.PRIMARY) ?1528 null : oldAs.getAnnotation(at);1529 Annotation newAn = newAs.hasAnnotation(at, Annotation.Source.PRIMARY) || values != null ?1530 newAs.getAnnotation(at) : null;1531 if (newAn == null) continue;1532 1533 if (oldAn == null && newAn.isInDatabase() || oldAn != null && oldAn.getValuesVersion() != newAn.getValuesVersion())1534 {1535 throw new ItemModifiedException(at.toString());1536 }1537 Type valueType = at.getValueType();1538 if (values == null)1539 {1540 newAs.removeAnnotation(at);1541 }1542 else1543 {1544 Object[] oValues = new Object[values.length];1545 Formatter<?> formatter = FormatterFactory.getTypeFormatter(dc.getSessionControl(), valueType);1546 for (int j = 0; j < values.length; ++j)1547 {1548 oValues[j] = formatter.parseString(values[j]);1549 }1550 newAn.setValues(Arrays.asList(oValues), unit);1551 }1552 }1553 }1554 */1555 1516 } 1556 1517 1557 // Inherited annotations and annotation sets1558 1559 // Annotations that are no longer inherited1560 String removed = Values.getStringOrNull(request.getParameter("removedAnnotations"));1561 if (removed != null)1562 {1563 String[] removedAnnotations = removed.split(",");1564 AnnotationSet newAs = newItem.getAnnotationSet();1565 for (int i = 0; i < removedAnnotations.length; ++i)1566 {1567 int annotationId = Values.getInt(removedAnnotations[i], -1);1568 if (annotationId != -1)1569 {1570 newAs.removeInheritedAnnotation(Annotation.getById(dc, annotationId));1571 }1572 }1573 }1574 1575 // Annotations that we now are inheriting1576 String added = Values.getStringOrNull(request.getParameter("addedAnnotations"));1577 if (added != null)1578 {1579 String[] addedAnnotations = added.split(",");1580 AnnotationSet newAs = newItem.getAnnotationSet();1581 for (int i = 0; i < addedAnnotations.length; ++i)1582 {1583 int annotationId = Values.getInt(addedAnnotations[i], -1);1584 if (annotationId != -1)1585 {1586 newAs.inheritAnnotation(Annotation.getById(dc, annotationId), false);1587 }1588 }1589 }1590 1518 } 1591 1519 -
trunk/www/common/annotations/annotate.js
r6947 r6955 36 36 var parents; 37 37 var selectedAnnotation; 38 var selected Index;38 var selectedMultiIndex; 39 39 40 40 … … 61 61 // Event handlers for input fields 62 62 Events.addEventHandler('STRING-input', 'change', annotate.valueOnChange); 63 Events.addEventHandler('STRING-input', 'blur', annotate.valueOnBlur); 63 64 Events.addEventHandler('TEXT-input', 'change', annotate.valueOnChange); 65 Events.addEventHandler('TEXT-input', 'blur', annotate.valueOnBlur); 64 66 Buttons.addClickHandler('TEXT-zoom', annotate.openTextZoom); 65 67 Events.addEventHandler('INT-input', 'keypress', Events.integerOnly); 66 68 Events.addEventHandler('INT-input', 'change', annotate.valueOnChange); 69 Events.addEventHandler('INT-input', 'blur', annotate.valueOnBlur); 67 70 Events.addEventHandler('LONG-input', 'keypress', Events.integerOnly); 68 71 Events.addEventHandler('LONG-input', 'change', annotate.valueOnChange); 72 Events.addEventHandler('LONG-input', 'blur', annotate.valueOnBlur); 69 73 Events.addEventHandler('FLOAT-input', 'keypress', Events.numberOnly); 70 74 Events.addEventHandler('FLOAT-input', 'change', annotate.valueOnChange); 75 Events.addEventHandler('FLOAT-input', 'blur', annotate.valueOnBlur); 71 76 Events.addEventHandler('DOUBLE-input', 'keypress', Events.numberOnly); 72 77 Events.addEventHandler('DOUBLE-input', 'change', annotate.valueOnChange); 78 Events.addEventHandler('DOUBLE-input', 'blur', annotate.valueOnBlur); 73 79 Events.addEventHandler('DATE-input', 'change', annotate.valueOnChange); 80 Events.addEventHandler('DATE-input', 'blur', annotate.valueOnBlur); 74 81 Buttons.addClickHandler('DATE-calendar', annotate.openCalendar); 75 82 Events.addEventHandler('TIMESTAMP-input', 'change', annotate.valueOnChange); 83 Events.addEventHandler('TIMESTAMP-input', 'blur', annotate.valueOnBlur); 76 84 Buttons.addClickHandler('TIMESTAMP-calendar', annotate.openCalendar); 77 85 Events.addEventHandler('BOOLEAN-input-NULL', 'click', annotate.valueOnChange); … … 81 89 Events.addEventHandler('ENUM-MULTIPLE-input', 'change', annotate.valueOnChange); 82 90 83 /*84 91 // Buttons for multi-valued annotations 85 92 Buttons.addClickHandler('btnMultiAdd', annotate.addMultiValue); … … 89 96 90 97 // The category list box is used to filter visible annotations 91 */92 98 Events.addEventHandler('categories', 'change', annotate.categoryOnChange); 93 99 annotate.categoryOnChange(); … … 270 276 // category list doesn't hide it 271 277 selectedAnnotation = annotate.getEntryById(entryId); 272 278 selectedMultiIndex = -1; 279 273 280 var classes = []; 274 281 var valueElement; … … 358 365 } 359 366 367 360 368 // Fill form with current values 361 var values = ann.values.length > 0 ? ann.values : [''];369 var values = ann.values.length > 0 || at.multiplicity != 1 ? ann.values : ['']; 362 370 if (valueElement.type && valueElement.type.indexOf('select') == 0) 363 371 { … … 386 394 else 387 395 { 388 // TODO - multivalues annotation 396 classes.push('multiple'); 397 // Fill the 'multi-values' list with the current values 398 var multiValues = frm['multi-values']; 399 multiValues.length = 0; 400 for (var i = 0; i < values.length; i++) 401 { 402 multiValues[multiValues.length] = new Option(values[i]); 403 } 404 valueElement.value = ''; 389 405 } 390 406 } … … 392 408 Doc.element('selected-container').className = classes.join(' '); 393 409 if (valueElement && valueElement.focus) valueElement.focus(); 394 395 /*396 else if (at.multiplicity == 1)397 {398 if (ann && ann.values && ann.values.length > 0)399 {400 if (valueElement.length) // ie. radio buttons for boolean parameter401 {402 Forms.checkRadio(valueElement, ann.values[0]);403 }404 else405 {406 407 valueElement.value = ann.values[0];408 }409 }410 }411 */412 /*413 else414 {415 var multiValues = frm['multi-values'];416 multiValues.length = 0;417 for (var i = 0; i < selectedAnnotation.values.length; i++)418 {419 multiValues[multiValues.length] = new Option(selectedAnnotation.values[i]);420 }421 var mult = Doc.element('multiplicity');422 mult.innerHTML = selectedAnnotation.multiplicity == 0 ? '' : '(Max '+selectedAnnotation.multiplicity+' values)';423 Doc.show('valuecontainer');424 }425 */426 427 428 410 } 429 411 … … 465 447 { 466 448 typeSummary += ' <= '+at.maxValue; 449 } 450 if (at.multiplicity > 1) 451 { 452 typeSummary += '; max '+at.multiplicity+' values'; 467 453 } 468 454 } … … 516 502 var tmp = document.createDocumentFragment(); 517 503 var ctlType = radio ? 'radio' : 'checkbox'; 518 if (includeNotSpecified )504 if (includeNotSpecified && radio) 519 505 { 520 506 var noop = annotate.createRadioOrCheckBox(ctlType, '', '- not specified -'); … … 560 546 exception is thrown. 561 547 */ 562 annotate.setSingleValue = function( annotation, value)548 annotate.setSingleValue = function(entry, value) 563 549 { 564 550 var values = []; … … 567 553 values[0] = value; 568 554 } 569 annotate.setMultipleValues( annotation, values);555 annotate.setMultipleValues(entry, values); 570 556 } 571 557 … … 575 561 exception is thrown. 576 562 */ 577 annotate.setMultipleValues = function( annotation, values)578 { 579 var at = annotation.annotationType;580 var ann = annotation.annotation;563 annotate.setMultipleValues = function(entry, values) 564 { 565 var at = entry.annotationType; 566 var ann = entry.annotation; 581 567 582 568 if (at.multiplicity > 0 && values.length > at.multiplicity) … … 585 571 } 586 572 ann.values = values; 587 annotation.modified = MODIFIED;588 annotate.updateIcon( annotation);573 entry.modified = MODIFIED; 574 annotate.updateIcon(entry); 589 575 } 590 576 … … 593 579 is not accepted an exception is thrown. 594 580 */ 595 /* 596 annotate.setIndexedValue = function(annotation, index, value) 597 { 581 annotate.setIndexedValue = function(entry, index, value) 582 { 583 var ann = entry.annotation; 584 var at = entry.annotationType; 585 598 586 if (!value) 599 587 { 600 if (index < ann otation.values.length)601 { 602 ann otation.values.splice(index, 1);588 if (index < ann.values.length) 589 { 590 ann.values.splice(index, 1); 603 591 } 604 592 } 605 593 else 606 594 { 607 if (index >= ann otation.values.length)595 if (index >= ann.values.length) 608 596 { 609 597 // Add a new value 610 if (annotation.multiplicity > 0 && annotation.values.length >= annotation.multiplicity) 611 { 612 throw 'Max '+annotation.multiplicity+' values allowed'; 613 } 614 index = annotation.values.length; 615 } 616 annotation.values[index] = value; 617 } 618 annotation.modified = true; 619 annotate.updateIcon(annotation); 620 } 621 */ 598 if (at.multiplicity > 0 && ann.values.length >= at.multiplicity) 599 { 600 throw 'Max '+at.multiplicity+' values allowed'; 601 } 602 index = ann.values.length; 603 } 604 ann.values[index] = value; 605 } 606 entry.modified = MODIFIED; 607 annotate.updateIcon(entry); 608 } 622 609 623 610 /** … … 649 636 annotate.setSingleValue(selectedAnnotation, target.value); 650 637 } 651 /*652 638 else if (at.enumeration) 653 639 { … … 668 654 { 669 655 // Otherwise we use the 'multi-values' control and update the currently 670 // selected option 671 if (selectedIndex >= 0) 672 { 673 annotate.setIndexedValue(selectedAnnotation, selectedIndex, target.value); 656 // selected option (but note that we can't use 'selectedIndex' property of the 657 // list control, since it may already point to the future selection 658 var selectedIndex = frm['multi-values'].selectedIndex; 659 if (selectedMultiIndex >= 0) 660 { 661 annotate.setIndexedValue(selectedAnnotation, selectedMultiIndex, target.value); 674 662 var multiValues = frm['multi-values']; 675 663 if (!target.value) 676 664 { 677 multiValues[selected Index] = null;678 selected Index = -1;665 multiValues[selectedMultiIndex] = null; 666 selectedMultiIndex = -1; 679 667 } 680 668 else 681 669 { 682 multiValues[selected Index].text = target.value;670 multiValues[selectedMultiIndex].text = target.value; 683 671 } 684 672 } 685 673 } 686 */687 674 } 688 675 catch (errorMessage) … … 690 677 event.preventDefault(); 691 678 Forms.showNotification(event.currentTarget, errorMessage); 679 } 680 } 681 682 // To catch the case if 'new' was clicked but no value was entered 683 annotate.valueOnBlur = function(event) 684 { 685 if (!selectedAnnotation && selectedMultiIndex < 0) return; 686 687 var frm = document.forms['annotations']; 688 689 if (event.currentTarget.value == '' && frm['multi-values'][selectedMultiIndex].isNewValue) 690 { 691 // This will remove the new but empty value 692 Events.sendChangeEvent(event.currentTarget); 693 } 694 else 695 { 696 frm['multi-values'][selectedMultiIndex].isNewValue = false; 692 697 } 693 698 } … … 1020 1025 } 1021 1026 1022 /*1023 1027 annotate.addMultiValue = function(event) 1024 1028 { 1025 1029 if (!selectedAnnotation) return; 1026 1030 1031 var at = selectedAnnotation.annotationType; 1032 1027 1033 var frm = document.forms['annotations']; 1028 var valueElement = frm['value.'+selectedAnnotation.id]; 1034 var valueElement = frm[at.valueType+'-input']; 1035 1029 1036 var multiValues = frm['multi-values']; 1030 1037 var errorMessage = null; 1031 1038 try 1032 1039 { 1033 if (selectedIndex >= 0) 1040 // If one item is already selected, we create a new entry 1041 if (selectedMultiIndex >= 0) 1034 1042 { 1035 1043 // Add a new option … … 1037 1045 if (!errorMessage) 1038 1046 { 1039 multiValues[multiValues.length] = new Option('<new>', '', false, true); 1040 selectedIndex = multiValues.length-1; 1047 var opt = new Option('<new>', '', false, true); 1048 opt.isNewValue = true; 1049 multiValues[multiValues.length] = opt; 1050 selectedMultiIndex = multiValues.length-1; 1041 1051 valueElement.value = ''; 1042 1052 } … … 1053 1063 } 1054 1064 valueElement.focus(); 1055 annotate.updateIcon(selectedAnnotation);1056 1065 } 1057 1066 catch (errorMessage) … … 1063 1072 annotate.removeMultiValue = function() 1064 1073 { 1065 if (!selectedAnnotation || selectedIndex < 0) return;1066 1074 if (!selectedAnnotation) return; 1075 1067 1076 var frm = document.forms['annotations']; 1068 var multiValues = frm['multi-values']; 1069 1070 annotate.setIndexedValue(selectedAnnotation, multiValues.selectedIndex, null); 1071 multiValues[multiValues.selectedIndex] = null; 1072 frm['value.'+selectedAnnotation.id].value = ''; 1073 frm['value.'+selectedAnnotation.id].focus(); 1074 } 1075 */ 1076 1077 var selectedIndex = frm['multi-values'].selectedIndex; 1078 1079 if (selectedIndex >= 0) 1080 { 1081 // Clear the current value, and send a 'change' event to let the 1082 // regular event handlers take care of the removal 1083 var at = selectedAnnotation.annotationType; 1084 var valueElement = frm[at.valueType+'-input']; 1085 valueElement.value = ''; 1086 Events.sendChangeEvent(valueElement); 1087 } 1088 } 1089 1077 1090 /** 1078 1091 Event handler for the 'multi-values' selection list. This should change 1079 1092 the value that is currently being edited to the selected option. 1080 1093 */ 1081 /* 1082 annotate.multiValueOnClick = function() 1094 annotate.multiValueOnClick = function(event) 1083 1095 { 1084 1096 if (!selectedAnnotation) return; 1097 1098 var at = selectedAnnotation.annotationType; 1099 var ann = selectedAnnotation.annotation; 1100 1085 1101 var frm = document.forms['annotations']; 1086 selected Index = frm['multi-values'].selectedIndex;1087 if (selected Index >= 0)1088 { 1089 frm['value.'+selectedAnnotation.id].value = selectedAnnotation.values[selectedIndex];1090 frm['value.'+selectedAnnotation.id].focus();1091 }1092 }1093 */1102 selectedMultiIndex = event.currentTarget.selectedIndex; 1103 if (selectedMultiIndex >= 0) 1104 { 1105 var valueElement = frm[at.valueType+'-input']; 1106 valueElement.value = ann.values[selectedMultiIndex]; 1107 valueElement.focus(); 1108 } 1109 } 1094 1110 1095 1111 … … 1184 1200 tmp.annotationId = entry.annotation.id; 1185 1201 tmp.unitId = entry.annotation.unit; 1202 if (tmp.modified == MODIFIED && tmp.values.length == 0) 1203 { 1204 tmp.modified = DELETE; 1205 } 1186 1206 } 1187 1207 if (entry.inherited) … … 1192 1212 } 1193 1213 1194 alert(JSON.stringify(modified));1214 //alert(JSON.stringify(modified)); 1195 1215 1196 1216 if (frm.modifiedAnnotations) -
trunk/www/common/annotations/annotate.jsp
r6947 r6955 458 458 } 459 459 #selected-container.has-unit #unit-container 460 { 461 display: block; 462 } 463 #selected-container.multiple #multiple-container 460 464 { 461 465 display: block; … … 603 607 } 604 608 %> 605 <div id="valuecontainer" style="display: none;">606 <b>Values</b> <span id="multiplicity"></span><br>607 <select name="multi-values" id="multi-values" size="5" style="width: 100%;">608 </select>609 <table>610 <tr>611 <td><base:button id="btnMultiAdd" title="Add" tooltip="Add a new value" /></td>612 <td><base:button id="btnMultiRemove" title="Remove" tooltip="Remove the selected values"/></td>613 </tr>614 </table>615 <br>616 </div>617 609 618 610 <div id="selected-container"> … … 638 630 639 631 <div id="input-container"> 632 <div id="multiple-container"> 633 634 <select name="multi-values" id="multi-values" size="5" style="width: calc(100% - 8px);"> 635 </select> 636 <table> 637 <tr> 638 <td><base:button id="btnMultiAdd" title="Add" tooltip="Add a new value" /></td> 639 <td><base:button id="btnMultiRemove" title="Remove" tooltip="Remove the selected values"/></td> 640 </tr> 641 </table> 642 </div> 640 643 641 644 <div id="ENUM-SINGLE"> 642 645 <select name="ENUM-SINGLE-input" id="ENUM-SINGLE-input" 643 style="min-width: 5em;">646 style="min-width: 15em;"> 644 647 </select> 645 648 </div> … … 647 650 <div id="ENUM-MULTIPLE"> 648 651 <select name="ENUM-MULTIPLE-input" id="ENUM-MULTIPLE-input" 649 multiple size="10" style="min-width: 5em;">652 multiple size="10" style="min-width: 15em;"> 650 653 </select> 651 654 </div> … … 763 766 value="false">false</label> 764 767 </div> 768 769 765 770 </div> 766 771
Note: See TracChangeset
for help on using the changeset viewer.