Index: trunk/extensions/Wikidata/OmegaWiki/forms.php |
— | — | @@ -2,8 +2,13 @@ |
3 | 3 | |
4 | 4 | require_once('languages.php'); |
5 | 5 | |
6 | | -function getTextBox($name, $value = "", $maximumLength = 255) { |
7 | | - return '<input type="text" id="'. $name .'" name="'. $name .'" value="'. $value .'" maxlength="'. $maximumLength .'" style="width: 100%; padding: 0px; margin: 0px;"/>'; |
| 6 | +function getTextBox($name, $value = "", $onChangeHandler = "", $maximumLength = 255) { |
| 7 | + if ($onChangeHandler != "") |
| 8 | + $onChangeAttribute = ' onchange="'. $onChangeHandler . '"'; |
| 9 | + else |
| 10 | + $onChangeAttribute = ''; |
| 11 | + |
| 12 | + return '<input type="text" id="'. $name .'" name="'. $name .'" value="'. $value .'" maxlength="'. $maximumLength .'"' . $onChangeAttribute . ' style="width: 100%; padding: 0px; margin: 0px;"/>'; |
8 | 13 | } |
9 | 14 | |
10 | 15 | function getTextArea($name, $text = "", $rows = 5, $columns = 80) { |
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php |
— | — | @@ -373,7 +373,7 @@ |
374 | 374 | $linkEditor = new LinkEditor($linkAttribute, new SimplePermissionController(true), true); |
375 | 375 | else { |
376 | 376 | $linkEditor = new RecordTableCellEditor($linkAttribute); |
377 | | - $linkEditor->addEditor(new ShortTextEditor($linkURLAttribute, new SimplePermissionController(true), true)); |
| 377 | + $linkEditor->addEditor(new ShortTextEditor($linkURLAttribute, new SimplePermissionController(true), true, "urlFieldChanged(this);")); |
378 | 378 | $linkEditor->addEditor(new ShortTextEditor($linkLabelAttribute, new SimplePermissionController(true), true)); |
379 | 379 | } |
380 | 380 | |
Index: trunk/extensions/Wikidata/OmegaWiki/suggest.js |
— | — | @@ -667,3 +667,147 @@ |
668 | 668 | |
669 | 669 | elementsToSort.push(params); |
670 | 670 | } |
| 671 | + |
| 672 | +function startsWith(value, prefix) { |
| 673 | + return value.toLowerCase().substr(0, prefix.length) == prefix.toLowerCase(); |
| 674 | +} |
| 675 | + |
| 676 | +function urlFieldChanged(urlField) { |
| 677 | + var labelField = document.getElementById(stripSuffix(urlField.id, "url") + "label"); |
| 678 | + var url = urlField.value; |
| 679 | + |
| 680 | +// if (startsWith(url, "http://www.ncbi.nlm.nih.gov")) { |
| 681 | +// var pubMedId = 1000; |
| 682 | +// labelField.value = getPubMedTitle(pubMedId); |
| 683 | +// } |
| 684 | +} |
| 685 | + |
| 686 | +// Knewco specific Javascript |
| 687 | + |
| 688 | +function GetOffset( text, Pattern, inclusive ){ |
| 689 | + var extra = 0; |
| 690 | + |
| 691 | + try{ |
| 692 | + offset = text.indexOf( Pattern ); |
| 693 | + |
| 694 | + if ( offset != -1 ){ |
| 695 | + if ( inclusive ){ |
| 696 | + offset = offset + Pattern.length; |
| 697 | + } |
| 698 | + |
| 699 | + return offset; |
| 700 | + } |
| 701 | + return -1; |
| 702 | + } |
| 703 | + catch(e){ |
| 704 | + return -1; |
| 705 | + } |
| 706 | + |
| 707 | +} |
| 708 | + |
| 709 | +function ExtractText( text, startTag, startOffset, endTag, endOffset ){ |
| 710 | + var extra = 0; |
| 711 | + var offset = 0; |
| 712 | + var endPos = 0; |
| 713 | + |
| 714 | + try{ |
| 715 | + /* search for a starting pattern in the text and return the remainder */ |
| 716 | + offset = GetOffset( text, startTag, true ); |
| 717 | + if ( offset == -1 ){ |
| 718 | + return null; |
| 719 | + } |
| 720 | + |
| 721 | + offset += startOffset; |
| 722 | + text2 = text.slice( offset ); |
| 723 | + |
| 724 | + if ( endTag != '' ){ |
| 725 | + /* search for an ending pattern in the text and return the part before */ |
| 726 | + endPos = GetOffset( text2, endTag, false ); |
| 727 | + |
| 728 | + if ( endPos == -1 ){ |
| 729 | + return [offset,text2]; |
| 730 | + } |
| 731 | + endPos += endOffset + offset; |
| 732 | + text3 = text.slice( offset, endPos ); |
| 733 | + } |
| 734 | + else{ |
| 735 | + return [offset,text2]; |
| 736 | + } |
| 737 | + return [offset,text3]; |
| 738 | + } |
| 739 | + catch(e){ |
| 740 | + return null; |
| 741 | + } |
| 742 | +} |
| 743 | + |
| 744 | +function getPubMedTitle( pmid ){ |
| 745 | + try { |
| 746 | + xmlhttp = GetXMLHttpRequest(); |
| 747 | + try{ |
| 748 | + xmlhttp.async = false; |
| 749 | + } catch(e){ |
| 750 | + } |
| 751 | + |
| 752 | + xmlhttp.open( "GET", "http://"+ HOST + "/knewco/get.py?http://www.ncbi.nlm.nih.gov/entrez/utils/pmfetch.fcgi?db=PubMed&id="+pmid+"&report=xml&mode=text", false ); |
| 753 | + xmlhttp.send(null); |
| 754 | + |
| 755 | + if ( xmlhttp.status == 200){ |
| 756 | + AuthorsRec = ExtractText( xmlhttp.responseText, "<AuthorList>", 0, "</AuthorList>", 0 ); |
| 757 | + if ( AuthorsRec != null ) { |
| 758 | + Authors = AuthorsRec[1]; |
| 759 | + } |
| 760 | + else{ |
| 761 | + Authors = ""; |
| 762 | + } |
| 763 | + |
| 764 | + var Offset = 0; |
| 765 | + var AuthorText = ""; |
| 766 | + while (true) { |
| 767 | + AuthorRec = ExtractText( Authors.slice( Offset ), "<Author>", 0, "</Author>", 0 ); |
| 768 | + if ( AuthorRec == null ){ |
| 769 | + break; |
| 770 | + } |
| 771 | + Offset += AuthorRec[0] |
| 772 | + AuthorXml = AuthorRec[1] |
| 773 | + LastNameRec = ExtractText( AuthorXml, "<LastName>", 0, "</LastName>", 0 ); |
| 774 | + if ( LastNameRec != null ){ |
| 775 | + LastName = LastNameRec[1]; |
| 776 | + } else{ |
| 777 | + LastName = ""; |
| 778 | + } |
| 779 | + FirstNameRec = ExtractText( AuthorXml, "<FirstName>", 0, "</FirstName>", 0 ); |
| 780 | + if ( FirstNameRec == null ){ |
| 781 | + FirstNameRec = ExtractText( AuthorXml, "<ForeName>", 0, "</ForeName>", 0 ); |
| 782 | + } |
| 783 | + |
| 784 | + if ( FirstNameRec != null ){ |
| 785 | + FirstName = FirstNameRec[1]; |
| 786 | + } else { |
| 787 | + FirstName = ""; |
| 788 | + } |
| 789 | + |
| 790 | + if ( LastName != "" ){ |
| 791 | + if ( AuthorText != "" ){ |
| 792 | + AuthorText += "; " |
| 793 | + } |
| 794 | + |
| 795 | + if ( FirstName != "" ){ |
| 796 | + AuthorText += LastName + ", " + FirstName; |
| 797 | + } |
| 798 | + else { |
| 799 | + AuthorText += LastName; |
| 800 | + } |
| 801 | + } |
| 802 | + } |
| 803 | + TitleRec = ExtractText( xmlhttp.responseText, "<ArticleTitle>", 0, "</ArticleTitle>", 0 ); |
| 804 | + if ( TitleRec != null ){ |
| 805 | + return [AuthorText, TitleRec[1]]; |
| 806 | + } |
| 807 | + else { |
| 808 | + return [AuthorText, "unknown title"]; |
| 809 | + } |
| 810 | + } |
| 811 | + } catch(e){ |
| 812 | + } |
| 813 | + return ""; |
| 814 | +} |
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php |
— | — | @@ -993,17 +993,25 @@ |
994 | 994 | } |
995 | 995 | |
996 | 996 | class ShortTextEditor extends ScalarEditor { |
| 997 | + protected $onChangeHandler; |
| 998 | + |
| 999 | + public function __construct(Attribute $attribute = null, PermissionController $permissionController, $isAddField, $onChangeHandler = "") { |
| 1000 | + parent::__construct($attribute, $permissionController, $isAddField); |
| 1001 | + |
| 1002 | + $this->onChangeHandler = $onChangeHandler; |
| 1003 | + } |
| 1004 | + |
997 | 1005 | public function getViewHTML(IdStack $idPath, $value) { |
998 | 1006 | return htmlspecialchars($value); |
999 | 1007 | } |
1000 | 1008 | |
1001 | 1009 | public function getEditHTML(IdStack $idPath, $value) { |
1002 | | - return getTextBox($this->updateId($idPath->getId()), $value); |
| 1010 | + return getTextBox($this->updateId($idPath->getId()), $value, $this->onChangeHandler); |
1003 | 1011 | } |
1004 | 1012 | |
1005 | 1013 | public function add(IdStack $idPath) { |
1006 | 1014 | if ($this->isAddField) |
1007 | | - return getTextBox($this->addId($idPath->getId()), ""); |
| 1015 | + return getTextBox($this->addId($idPath->getId()), "", $this->onChangeHandler); |
1008 | 1016 | else |
1009 | 1017 | return ""; |
1010 | 1018 | } |