Commit 969703e209689233a9e65fb18da4b7787acda770

Authored by Megan Watson
1 parent ba4562d5

KTS-3215

"It should be possible to edit and rename lookup values form the administration section"
Fixed. Added an edit icon. Removed the sanitizetosql on saving to the DB.

Committed by: Megan Watson
Reviewed by: Jonathan Byrne



git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@8349 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/documentmanagement/MetaData.inc
... ... @@ -7,36 +7,35 @@
7 7 * KnowledgeTree Open Source Edition
8 8 * Document Management Made Simple
9 9 * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited
10   - *
  10 + *
11 11 * This program is free software; you can redistribute it and/or modify it under
12 12 * the terms of the GNU General Public License version 3 as published by the
13 13 * Free Software Foundation.
14   - *
  14 + *
15 15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 17 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 18 * details.
19   - *
  19 + *
20 20 * You should have received a copy of the GNU General Public License
21 21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22   - *
  22 + *
23 23 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
24 24 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
25   - *
  25 + *
26 26 * The interactive user interfaces in modified source and object code versions
27 27 * of this program must display Appropriate Legal Notices, as required under
28 28 * Section 5 of the GNU General Public License version 3.
29   - *
  29 + *
30 30 * In accordance with Section 7(b) of the GNU General Public License version 3,
31 31 * these Appropriate Legal Notices must retain the display of the "Powered by
32   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  32 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
33 33 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
34   - * must display the words "Powered by KnowledgeTree" and retain the original
35   - * copyright notice.
  34 + * must display the words "Powered by KnowledgeTree" and retain the original
  35 + * copyright notice.
36 36 * Contributor( s): ______________________________________
37 37 */
38 38  
39   -require_once(KT_LIB_DIR . "/util/sanitize.inc");
40 39  
41 40 class MetaData extends KTEntity {
42 41  
... ... @@ -80,8 +79,8 @@ class MetaData extends KTEntity {
80 79 }
81 80  
82 81 function getID() { return $this->iId; }
83   - function getName() { return sanitizeForSQLtoHTML($this->sName); }
84   - function setName($sNewValue) { $this->sName = sanitizeForSQL($sNewValue); }
  82 + function getName() { return $this->sName; }
  83 + function setName($sNewValue) { $this->sName = $sNewValue; }
85 84 function getDocFieldId() { return $this->iDocFieldId; }
86 85 function setDocFieldId($iNewValue) { $this->iDocFieldId = $iNewValue; }
87 86 function getTreeParent() { return $this->iTreeParent; }
... ...
plugins/ktcore/admin/fieldsets/basic.inc.php
... ... @@ -416,12 +416,41 @@ class BasicFieldsetManagementDispatcher extends KTAdminDispatcher {
416 416 function do_managelookups() {
417 417 $this->oPage->setBreadcrumbDetails(_kt('manage lookup values'));
418 418  
419   - $oTemplate =& $this->oValidator->validateTemplate("ktcore/metadata/admin/manage_lookups");
  419 + // Add javascript to create the edit form
  420 + $sJavaScript = "\nfunction editLookup(id)\n
  421 + {\n
  422 + var div = document.getElementById(id);\n
  423 + var value = div.innerHTML;
  424 +
  425 + <!-- Replace all double quotes with &#34; -->\n
  426 + matches = value.match(/\"/g);\n
  427 + var newValue = value;\n
  428 + if(matches){\n
  429 + for(var i = 0; i < matches.length; i++){\n
  430 + newValue = newValue.replace('\"', '&#34;');\n
  431 + }\n
  432 + }\n\n
  433 +
  434 + var inner = '<input type=\"text\" name=\"lookup['+id+']\" id=\"lookup_'+id+'\" value=\"'+newValue+'\" />';\n
  435 + inner += '<input type=\"hidden\" id=\"original_'+id+'\" value=\"'+newValue+'\" />';\n
  436 + inner += '<input type=\"submit\" name=\"submit[edit]\" value=\""._kt('Save')."\" />';\n
  437 + inner += '<input type=\"button\" onclick=\"javascript: closeLookupEdit('+id+');\" name=\"cancel\" value=\""._kt('Cancel')."\" />';\n
  438 + div.innerHTML = inner;\n
  439 + document.getElementById('lookup_'+id).focus();\n
  440 + }\n\n
  441 +
  442 + function closeLookupEdit(id)
  443 + {\n
  444 + value = document.getElementById('original_'+id).value;\n
  445 + document.getElementById(id).innerHTML = value;\n
  446 + }\n\n";
  447 +
  448 + $this->oPage->requireJSStandalone($sJavaScript);
420 449  
421 450 $lookups =& MetaData::getByDocumentField($this->oField);
422   -
423 451 $args = $this->meldPersistQuery("","metadataMultiAction", true);
424 452  
  453 + $oTemplate =& $this->oValidator->validateTemplate("ktcore/metadata/admin/manage_lookups");
425 454 $oTemplate->setData(array(
426 455 'context' => $this,
427 456 'field_name' => $this->oField->getName(),
... ... @@ -486,6 +515,40 @@ class BasicFieldsetManagementDispatcher extends KTAdminDispatcher {
486 515 }
487 516 // }}}
488 517  
  518 + /**
  519 + * Save the edited lookup values
  520 + *
  521 + */
  522 + function lookup_edit(){
  523 + $aLookupValues = $_REQUEST['lookup'];
  524 +
  525 + if(empty($aLookupValues)){
  526 + $this->errorRedirectTo('managelookups', _kt('No lookups were selected for editing'));
  527 + exit;
  528 + }
  529 +
  530 + foreach ($aLookupValues as $iMetaDataId => $sValue){
  531 + $oMetaData = MetaData::get($iMetaDataId);
  532 + if (PEAR::isError($oMetaData)) {
  533 + $this->addErrorMessage(_kt('Invalid lookup selected').': '.$sValue);
  534 + continue;
  535 + //$this->errorRedirectTo('managelookups', _kt('Invalid lookup selected'));
  536 + }
  537 + if(empty($sValue)){
  538 + $this->addErrorMessage(_kt('Lookup cannot be empty').': '.$oMetaData->getName());
  539 + if(count($aLookupValues) == 1){
  540 + $this->redirectTo('managelookups');
  541 + }
  542 + continue;
  543 + }
  544 + $oMetaData->setName($sValue);
  545 + $oMetaData->update();
  546 + }
  547 +
  548 + $this->successRedirectTo('managelookups', _kt('Lookup values saved'));
  549 + exit(0);
  550 + }
  551 +
489 552 // {{{ lookup_enable
490 553 function lookup_toggleenabled() {
491 554 $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']);
... ...
templates/ktcore/metadata/admin/manage_lookups.smarty
... ... @@ -3,9 +3,9 @@
3 3 <fieldset>
4 4 <legend>{i18n}Manage Lookups{/i18n}</legend>
5 5  
6   -<p class="descriptiveText">{i18n}Over time, the lookup values which make sense will
  6 +<p class="descriptiveText">{i18n}Over time, the lookup values which make sense will
7 7 change and evolve as your organisation does. You may thus need to change the lookup
8   -values associated with a given field. There are a number of different states
  8 +values associated with a given field. There are a number of different states
9 9 that are possible for a given lookup{/i18n}:</p>
10 10  
11 11 <ul class="descriptiveText">
... ... @@ -13,10 +13,10 @@ that are possible for a given lookup{/i18n}:&lt;/p&gt;
13 13 as an option when editing or creating documents.{/i18n}</li>
14 14 <li>{i18n}<strong>Sticky</strong>, which is used if you have some external
15 15 plugin controlling this lookup set. This will then tell that plugin not to
16   - remove the "sticky" value, even if it no longer available in the remote source.{/i18n}</li>
17   - <li>{i18n}<strong>Deleted</strong>, which completely removes the selected items
  16 + remove the "sticky" value, even if it no longer available in the remote source.{/i18n}</li>
  17 + <li>{i18n}<strong>Deleted</strong>, which completely removes the selected items
18 18 from the lookup. Note that this may not be possible if some other aspect of the system
19   - depends on a particular lookup.{/i18n}</li>
  19 + depends on a particular lookup.{/i18n}</li>
20 20 </ul>
21 21 <form method="POST" action="{$smarty.server.PHP_SELF}">
22 22  
... ... @@ -29,17 +29,20 @@ that are possible for a given lookup{/i18n}:&lt;/p&gt;
29 29 <tr>
30 30 <th>&nbsp;</th>
31 31 <th>{i18n}Lookup Value{/i18n}</th>
32   - <th class="centered">{i18n}Enabled{/i18n}</th>
33   - <th class="centered">{i18n}Sticky{/i18n}</th>
  32 + <th class="centered">{i18n}Enabled{/i18n}</th>
  33 + <th class="centered">{i18n}Sticky{/i18n}</th>
  34 + <th class="centered">{i18n}Edit{/i18n}</th>
34 35 </tr>
35 36 </thead>
36 37 <tbody>
37 38 {foreach from=$lookups item=oLookup}
  39 + {assign var='id' value=$oLookup->getId()}
38 40 <tr>
39 41 <td><input type="checkbox" name="metadata[]" value="{$oLookup->getId()}" /></td>
40   - <td>{$oLookup->getName()}</td>
  42 + <td><div id="{$id}">{$oLookup->getName()}</div></td>
41 43 <td class="centered">{if (!$oLookup->getDisabled())}<span class="ktAction ktAllowed">{i18n}Yes{/i18n}</span>{else}<span class="ktAction ktDenied">{i18n}No{/i18n}</span>{/if}</td>
42 44 <td class="centered">{if ($oLookup->getIsStuck())}<span>{i18n}Yes{/i18n}</span>{else}&nbsp;{/if}</td>
  45 + <td class="centered"><a href="#" onclick="javascript: editLookup({$id});" class="ktAction ktEdit">{i18n}Edit value{/i18n}</a></td>
43 46 </tr>
44 47 {/foreach}
45 48 </tbody>
... ...