Index: trunk/extensions/Wikidata/OmegaWiki/suggest.js |
— | — | @@ -133,6 +133,7 @@ |
134 | 134 | |
135 | 135 | function suggestLinkClicked(event, suggestLink) { |
136 | 136 | var suggestLinkId = suggestLink.id; |
| 137 | + // removing the "link" at the end of the Id |
137 | 138 | var suggestPrefix = suggestLinkId.substr(0, suggestLinkId.length - 4); |
138 | 139 | |
139 | 140 | var suggestDiv = document.getElementById(suggestPrefix + "div"); |
— | — | @@ -922,3 +923,59 @@ |
923 | 924 | } |
924 | 925 | return ""; |
925 | 926 | } |
| 927 | + |
| 928 | + |
| 929 | +// add a new row for translation or definition |
| 930 | +function addEmptyRow(elementId) { |
| 931 | + var element = document.getElementById( elementId ); |
| 932 | + |
| 933 | + var container = element.parentNode ; |
| 934 | + |
| 935 | + // create a clone to work on |
| 936 | + var new_element = element.cloneNode(true); |
| 937 | + |
| 938 | + // removes the green button for the old row |
| 939 | + element.firstChild.removeChild ( element.firstChild.firstChild ) ; |
| 940 | + |
| 941 | + // all new textareas field should be set empty |
| 942 | + var textAreaList = new_element.getElementsByTagName('textarea'); |
| 943 | + for (i=0; i<textAreaList.length ; i++) |
| 944 | + { |
| 945 | + if ( textAreaList[i].type == 'text' ) { |
| 946 | + textAreaList[i].value = '' ; |
| 947 | + } |
| 948 | + } |
| 949 | + |
| 950 | +// for the spelling, it is not a textarea but an input type=text. |
| 951 | +// (some other input fields, hidden, are needed, so we should not clear all <input> ) |
| 952 | + var inputList = new_element.getElementsByTagName('input'); |
| 953 | + for (i=0; i<inputList.length ; i++) |
| 954 | + { |
| 955 | + if ( inputList[i].type == 'text' ) { |
| 956 | + inputList[i].value = '' ; |
| 957 | + } |
| 958 | + if ( inputList[i].name == 'onUpdate' ) { |
| 959 | + inputList[i].value = inputList[i].value.replace("add-", "add-X-") ; |
| 960 | + } |
| 961 | + } |
| 962 | + |
| 963 | + recursiveChangeId( new_element ) ; |
| 964 | + |
| 965 | + // add the element as the last one (null) |
| 966 | + container.appendChild(new_element ); |
| 967 | +} |
| 968 | + |
| 969 | +function recursiveChangeId(element) { |
| 970 | + if (element == null) return; |
| 971 | + if ( element.hasChildNodes() ) { |
| 972 | + var children = element.childNodes ; |
| 973 | + for (var i=0; i<children.length ; i++) |
| 974 | + { |
| 975 | + recursiveChangeId ( children[i] ) ; |
| 976 | + } |
| 977 | + } |
| 978 | + |
| 979 | + if ( element.id ) element.id = element.id.replace("add-", "add-X-") ; |
| 980 | + if ( element.name ) element.name = element.name.replace("add-", "add-X-") ; |
| 981 | + return ; |
| 982 | +} |
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php |
— | — | @@ -209,7 +209,7 @@ |
210 | 210 | public function save( IdStack $idPath, $value ); |
211 | 211 | |
212 | 212 | public function getUpdateValue( IdStack $idPath ); |
213 | | - public function getAddValue( IdStack $idPath ); |
| 213 | + public function getAddValues( IdStack $idPath ); |
214 | 214 | |
215 | 215 | public function getEditors(); |
216 | 216 | public function getAttributeEditorMap(); |
— | — | @@ -316,7 +316,7 @@ |
317 | 317 | return null; |
318 | 318 | } |
319 | 319 | |
320 | | - public function getAddValue( IdStack $idPath ) { |
| 320 | + public function getAddValues( IdStack $idPath ) { |
321 | 321 | return null; |
322 | 322 | } |
323 | 323 | |
— | — | @@ -344,28 +344,42 @@ |
345 | 345 | $this->controller = $controller; |
346 | 346 | } |
347 | 347 | |
348 | | - public function getAddValue( IdStack $idPath ) { |
| 348 | + public function getAddValues( IdStack $idPath ) { |
349 | 349 | $addStructure = $this->getAddStructure(); |
350 | 350 | |
351 | 351 | if ( count( $addStructure->getAttributes() ) > 0 ) { |
352 | | - $relation = new ArrayRecordSet( $addStructure, $addStructure ); // TODO Determine real key |
353 | | - $values = array(); |
| 352 | + $relations = array(); |
354 | 353 | |
355 | | - foreach ( $this->getEditors() as $editor ) |
| 354 | + $value_array_array = array(array()); |
| 355 | + |
| 356 | + foreach ( $this->getEditors() as $editor ) { |
356 | 357 | if ( $attribute = $editor->getAddAttribute() ) { |
357 | 358 | $idPath->pushAttribute( $attribute ); |
358 | | - $values[] = $editor->getAddValue( $idPath ); |
| 359 | + |
| 360 | + $addValues = $editor->getAddValues( $idPath ); |
| 361 | + $i = 0; |
| 362 | + foreach ( $addValues as $value ) { |
| 363 | + $value_array_array[$i][] = $value ; |
| 364 | + $i++; |
| 365 | + } |
| 366 | + |
359 | 367 | $idPath->popAttribute(); |
360 | 368 | } |
| 369 | + } |
361 | 370 | |
362 | | - $relation->addRecord( $values ); |
| 371 | + foreach ( $value_array_array as $value_array ) { |
| 372 | + $relation = new ArrayRecordSet( $addStructure, $addStructure ) ; // TODO Determine real key |
| 373 | + $relation->addRecord( $value_array ); |
| 374 | + $relations[] = $relation ; |
| 375 | + } |
363 | 376 | |
364 | | - return $relation; |
| 377 | + return $relations ; |
365 | 378 | } |
366 | 379 | else |
367 | 380 | return null; |
368 | 381 | } |
369 | 382 | |
| 383 | + |
370 | 384 | protected function saveRecord( IdStack $idPath, Record $record ) { |
371 | 385 | foreach ( $this->getEditors() as $editor ) { |
372 | 386 | $attribute = $editor->getAttribute(); |
— | — | @@ -452,16 +466,25 @@ |
453 | 467 | } |
454 | 468 | |
455 | 469 | public function getAddRecord( IdStack $idPath, Structure $structure, $editors ) { |
456 | | - $result = new ArrayRecord( $structure ); |
| 470 | + $results = array(); |
457 | 471 | |
458 | 472 | foreach ( $editors as $editor ) |
459 | 473 | if ( $attribute = $editor->getAddAttribute() ) { |
460 | 474 | $idPath->pushAttribute( $attribute ); |
461 | | - $result->setAttributeValue( $attribute, $editor->getAddValue( $idPath ) ); |
| 475 | + $addValues = $editor->getAddValues( $idPath ); |
| 476 | + $i = 0 ; |
| 477 | + foreach ( $addValues as $value ) { |
| 478 | + if ( ! $results[$i] ) { |
| 479 | + $results[$i] = new ArrayRecord( $structure ); |
| 480 | + } |
| 481 | + $results[$i]->setAttributeValue( $attribute, $value ); |
| 482 | + $i++ ; |
| 483 | + } |
| 484 | + |
462 | 485 | $idPath->popAttribute(); |
463 | 486 | } |
464 | 487 | |
465 | | - return $result; |
| 488 | + return $results; |
466 | 489 | } |
467 | 490 | |
468 | 491 | public function getUpdateRecord( IdStack $idPath, Structure $structure, $editors ) { |
— | — | @@ -484,8 +507,12 @@ |
485 | 508 | |
486 | 509 | if ( count( $addStructure->getAttributes() ) > 0 ) { |
487 | 510 | $addEditors = $this->getAddEditors(); // array of editors |
488 | | - $record = $this->getAddRecord( $idPath, $addStructure, $addEditors ); // array of records |
489 | | - $this->controller->add( $idPath, $record ); |
| 511 | + |
| 512 | + $records = array(); |
| 513 | + $records = $this->getAddRecord( $idPath, $addStructure, $addEditors ); |
| 514 | + foreach ( $records as $record ) { |
| 515 | + $this->controller->add( $idPath, $record ); |
| 516 | + } |
490 | 517 | } |
491 | 518 | } |
492 | 519 | |
— | — | @@ -779,7 +806,7 @@ |
780 | 807 | |
781 | 808 | # + is add new Fo o(but grep this file for Add.png for more) |
782 | 809 | if ( $allowRemove ) { |
783 | | - $result .= '<td class="add"><img src="' . $wgScriptPath . '/extensions/Wikidata/Images/Add.png" title="' . wfMsgSc( "AddHint" ) . '" alt="Add"/></td>' . EOL; |
| 810 | + $result .= '<td class="add"><img src="' . $wgScriptPath . '/extensions/Wikidata/Images/Add.png" title="' . wfMsgSc( "AddHint" ) . '" alt="Add" onclick="addEmptyRow(this.parentNode.parentNode.id);"/></td>' . EOL; |
784 | 811 | } |
785 | 812 | |
786 | 813 | $result .= $this->getStructureAsAddCells( $idPath, $this ); |
— | — | @@ -829,17 +856,25 @@ |
830 | 857 | return $result; |
831 | 858 | } |
832 | 859 | |
833 | | - public function getAddValue( IdStack $idPath ) { |
834 | | - $result = new ArrayRecord( $this->getAddStructure() ); |
| 860 | + public function getAddValues( IdStack $idPath ) { |
| 861 | + $results = array(); |
835 | 862 | |
836 | 863 | foreach ( $this->getEditors() as $editor ) |
837 | 864 | if ( $attribute = $editor->getAddAttribute() ) { |
838 | 865 | $idPath->pushAttribute( $attribute ); |
839 | | - $result->setAttributeValue( $attribute, $editor->getAddValue( $idPath ) ); |
| 866 | + $addValues = array(); |
| 867 | + $addValues = $editor->getAddValues( $idPath ); |
| 868 | + $i = 0 ; |
| 869 | + foreach ( $addValues as $value ) { |
| 870 | + if ( ! $results[$i] ) { |
| 871 | + $results[$i] = new ArrayRecord( $this->getAddStructure() ); |
| 872 | + } |
| 873 | + $results[$i]->setAttributeValue( $attribute, $value ); |
| 874 | + $i++ ; |
| 875 | + } |
840 | 876 | $idPath->popAttribute(); |
841 | 877 | } |
842 | | - |
843 | | - return $result; |
| 878 | + return $results ; |
844 | 879 | } |
845 | 880 | |
846 | 881 | public function getUpdateAttribute() { |
— | — | @@ -947,8 +982,18 @@ |
948 | 983 | return $this->getInputValue( "update-" . $idPath->getId() ); |
949 | 984 | } |
950 | 985 | |
951 | | - public function getAddValue( IdStack $idPath ) { |
952 | | - return $this->getInputValue( "add-" . $idPath->getId() ); |
| 986 | + // tries to get multiple "add" values e.g. adding multiple translations at once |
| 987 | + // the "X-" corresponds to what is in suggest.js, function recursiveChangeId |
| 988 | + public function getAddValues( IdStack $idPath ) { |
| 989 | + $addValues = array(); |
| 990 | + $prefix = "add-" ; |
| 991 | + |
| 992 | + while ( ( $value = $this->getInputValue( $prefix . $idPath->getId() ) ) != '' ) { |
| 993 | + $addValues[] = $value ; |
| 994 | + $prefix = $prefix . "X-" ; |
| 995 | + } |
| 996 | + |
| 997 | + return $addValues ; |
953 | 998 | } |
954 | 999 | |
955 | 1000 | public function view( IdStack $idPath, $value ) { |
— | — | @@ -1751,8 +1796,8 @@ |
1752 | 1797 | return $this->wrappedEditor->getUpdateValue( $idPath ); |
1753 | 1798 | } |
1754 | 1799 | |
1755 | | - public function getAddValue( IdStack $idPath ) { |
1756 | | - return $this->wrappedEditor->getAddValue( $idPath ); |
| 1800 | + public function getAddValues( IdStack $idPath ) { |
| 1801 | + return $this->wrappedEditor->getAddValues( $idPath ); |
1757 | 1802 | } |
1758 | 1803 | |
1759 | 1804 | public function getEditors() { |
— | — | @@ -1906,7 +1951,7 @@ |
1907 | 1952 | |
1908 | 1953 | # For which class is this add? |
1909 | 1954 | $result .= '<li>' . |
1910 | | - '<h' . $this->headerLevel . '><span id="collapse-' . $recordId . '" class="toggle ' . addCollapsablePrefixToClass( $class ) . '" onclick="toggle(this, event);">' . $this->getExpansionPrefix( $idPath->getClass(), $idPath->getId() ) . ' <img src="' . $wgScriptPath . '/extensions/Wikidata/Images/Add.png" title="Enter new list item to add" alt="Add"/>' . $this->captionEditor->add( $idPath ) . '</span></h' . $this->headerLevel . '>' . EOL; |
| 1955 | + '<h' . $this->headerLevel . '><span id="collapse-' . $recordId . '" class="toggle ' . addCollapsablePrefixToClass( $class ) . '" onclick="toggle(this, event);">' . $this->getExpansionPrefix( $idPath->getClass(), $idPath->getId() ) . ' <img src="' . $wgScriptPath . '/extensions/Wikidata/Images/Add.png" title="Enter new list item to add" alt="Add" onclick="addEmptyRow(this.parentNode.parentNode.id);"/>' . $this->captionEditor->add( $idPath ) . '</span></h' . $this->headerLevel . '>' . EOL; |
1911 | 1956 | $idPath->popAttribute(); |
1912 | 1957 | |
1913 | 1958 | $idPath->pushAttribute( $valueAttribute ); |
— | — | @@ -2255,8 +2300,13 @@ |
2256 | 2301 | $this->recordEditor->save( $idPath, $record ); |
2257 | 2302 | $idPath->popKey(); |
2258 | 2303 | } |
2259 | | - else |
2260 | | - $this->controller->add( $idPath, $this->recordEditor->getAddValue( $idPath ) ); |
| 2304 | + else { |
| 2305 | + $addValues = array() ; |
| 2306 | + $addValues = $this->recordEditor->getAddValues( $idPath ) ; |
| 2307 | + foreach ( $addValues as $addValue ) { |
| 2308 | + $this->controller->add( $idPath, $addValue ); |
| 2309 | + } |
| 2310 | + } |
2261 | 2311 | } |
2262 | 2312 | |
2263 | 2313 | public function setRecordEditor( Editor $recordEditor ) { |