You need to sign in before continuing.

Commit 5988e2a706ffd8c54f5e95e94e0381274e92ff30

Authored by Brad Shuttleworth
1 parent 4a48788e

pending merges:

Brad Shuttleworth 2006-04-07 fix for fieldset overviews.
    Brad Shuttleworth 2006-04-07 KTS-644: Add overview & test to conditional...
    Brad Shuttleworth 2006-04-07 KTS-453:  show types and fieldsets on respe...
    Brad Shuttleworth 2006-04-07 merge in.
    Brad Shuttleworth 2006-04-07 KTS-747: invalid role-allocation lookup


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5218 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/metadata/fieldset.inc.php
... ... @@ -161,6 +161,27 @@ class KTFieldset extends KTEntity {
161 161 }
162 162 return $aRet;
163 163 }
  164 +
  165 + function &getAssociatedTypes() {
  166 + // NOTE: this returns null if we are generic (all is the wrong answer)
  167 + if ($this->getIsGeneric()) { return null; }
  168 +
  169 + $sTable = KTUtil::getTableName('document_type_fieldsets');
  170 + $aQuery = array(
  171 + "SELECT document_type_id FROM $sTable WHERE fieldset_id = ?",
  172 + array($this->getId()),
  173 + );
  174 + $aIds = DBUtil::getResultArrayKey($aQuery, 'document_type_id');
  175 +
  176 + $aRet = array();
  177 + foreach ($aIds as $iID) {
  178 + $oType = DocumentType::get($iID);
  179 + if (!PEAR::isError($oType)) {
  180 + $aRet[] = $oType;
  181 + }
  182 + }
  183 + return $aRet;
  184 + }
164 185  
165 186 function &getFields() {
166 187 return DocumentField::getByFieldset($this);
... ...
lib/roles/roleallocation.inc.php
... ... @@ -110,7 +110,7 @@ class RoleAllocation extends KTEntity {
110 110 ' LEFT JOIN ' . $fTable . ' AS f ON (f.id = ra.folder_id) ' .
111 111 ' WHERE f.id IN ' . $folders .
112 112 ' AND ra.role_id = ?' .
113   - ' ORDER BY CHAR_LENGTH(f.parent_folder_ids) desc, f.parent_folder_ids DESC; ';
  113 + ' ORDER BY CHAR_LENGTH(f.parent_folder_ids) desc, f.parent_folder_ids DESC';
114 114 $aParams = array($iRoleId);
115 115  
116 116 $aRoleAllocIds = DBUtil::getResultArrayKey(array($sQuery, $aParams), 'id');
... ...
plugins/ktcore/admin/documentFields.php
... ... @@ -61,6 +61,7 @@ class KTDocumentFieldDispatcher extends KTAdminDispatcher {
61 61 $oTemplating =& KTTemplating::getSingleton();
62 62 $oTemplate =& $oTemplating->loadTemplate('ktcore/metadata/listFieldsets');
63 63 $oTemplate->setData(array(
  64 + 'context' => $this,
64 65 'fieldsets' => KTFieldset::getList(),
65 66 'creation_fields' => $createFields,
66 67 ));
... ... @@ -68,6 +69,25 @@ class KTDocumentFieldDispatcher extends KTAdminDispatcher {
68 69 }
69 70 // }}}
70 71  
  72 + function getTypesForFieldset($oFieldset) {
  73 + if ($oFieldset->getIsGeneric()) {
  74 + return _kt('All types use this generic fieldset.');
  75 + }
  76 +
  77 + $types = $oFieldset->getAssociatedTypes();
  78 + if (PEAR::isError($types)) {
  79 + return _kt('Error retrieving list of types.');
  80 + }
  81 + if (empty($types)) {
  82 + return _kt('None');
  83 + }
  84 + $aNames = array();
  85 + foreach ($types as $oType) {
  86 + $aNames[] = $oType->getName();
  87 + }
  88 + return implode(', ', $aNames);
  89 + }
  90 +
71 91 // {{{ do_edit
72 92 function do_edit() {
73 93 $this->oPage->setBreadcrumbDetails("edit");
... ... @@ -872,6 +892,122 @@ class KTDocumentFieldDispatcher extends KTAdminDispatcher {
872 892 $actionStr .= ")";
873 893 return $actionStr;
874 894 }
  895 +
  896 +
  897 + function do_viewOverview() {
  898 + $fieldset_id = KTUtil::arrayGet($_REQUEST, "fieldset_id");
  899 + $oTemplating =& KTTemplating::getSingleton();
  900 + $oTemplate = $oTemplating->loadTemplate("ktcore/metadata/conditional/conditional_overview");
  901 +
  902 +
  903 + $oFieldset =& KTFieldset::get($fieldset_id);
  904 + $aFields =& $oFieldset->getFields();
  905 +
  906 + $aBehaviours = array();
  907 + foreach ($aFields as $oField) {
  908 + $aOpts = KTFieldBehaviour::getByField($oField);
  909 + $aBehaviours = kt_array_merge($aBehaviours, $aOpts);
  910 + }
  911 +
  912 + $aTemplateData = array(
  913 + "context" => &$this,
  914 + "fieldset_id" => $fieldset_id,
  915 + "aFields" => $aFields,
  916 + "behaviours" => $aBehaviours,
  917 + "iMasterFieldId" => $oFieldset->getMasterFieldId(),
  918 + );
  919 + return $oTemplate->render($aTemplateData);
  920 + }
  921 +
  922 + function getSetsForBehaviour($oBehaviour, $fieldset_id) {
  923 + $oFieldset = KTFieldset::get($fieldset_id);
  924 + if (is_null($oBehaviour)) {
  925 + $fid = $oFieldset->getMasterFieldId();
  926 + $aQuery = array(
  927 + sprintf('SELECT df.name as field_name, ml.name as lookup_name, fb.id as behaviour_id, fb.name as behaviour_name FROM
  928 + %s as fvi
  929 + LEFT JOIN %s as fb ON (fvi.behaviour_id = fb.id)
  930 + LEFT JOIN %s AS df ON (fvi.field_id = df.id)
  931 + LEFT JOIN metadata_lookup AS ml ON (fvi.field_value_id = ml.id)
  932 + WHERE fvi.field_id = ?
  933 + ORDER BY df.name ASC, ml.name ASC',
  934 + KTUtil::getTableName('field_value_instances'),
  935 + KTUtil::getTableName('field_behaviours'),
  936 + KTUtil::getTableName('document_fields'),
  937 + KTUtil::getTableName('metadata')),
  938 + array($fid),
  939 + );
  940 + $res = DBUtil::getResultArray($aQuery);
  941 + return $res;
  942 + } else {
  943 + $bid = $oBehaviour->getId();
  944 + $aQuery = array(
  945 + sprintf('SELECT df.name as field_name, ml.name as lookup_name, fb.id as behaviour_id, fb.name as behaviour_name FROM
  946 + %s AS fbo
  947 + LEFT JOIN %s as fvi ON (fbo.instance_id = fvi.id)
  948 + LEFT JOIN %s as fb ON (fvi.behaviour_id = fb.id)
  949 + LEFT JOIN %s AS df ON (fvi.field_id = df.id)
  950 + LEFT JOIN metadata_lookup AS ml ON (fvi.field_value_id = ml.id)
  951 + WHERE fbo.behaviour_id = ?
  952 + ORDER BY df.name ASC, ml.name ASC',
  953 + KTUtil::getTableName('field_behaviour_options'),
  954 + KTUtil::getTableName('field_value_instances'),
  955 + KTUtil::getTableName('field_behaviours'),
  956 + KTUtil::getTableName('document_fields'),
  957 + KTUtil::getTableName('metadata')),
  958 + array($bid),
  959 + );
  960 +
  961 + $res = DBUtil::getResultArray($aQuery);
  962 + return $res;
  963 + }
  964 +
  965 + return $aNextFieldValues;
  966 + }
  967 +
  968 + function do_renameBehaviours() {
  969 + $fieldset_id = KTUtil::arrayGet($_REQUEST, "fieldset_id");
  970 + $oTemplating =& KTTemplating::getSingleton();
  971 + $oTemplate = $oTemplating->loadTemplate("ktcore/metadata/conditional/conditional_rename_behaviours");
  972 +
  973 +
  974 + $oFieldset =& KTFieldset::get($fieldset_id);
  975 + $aFields =& $oFieldset->getFields();
  976 +
  977 + $aBehaviours = array();
  978 + foreach ($aFields as $oField) {
  979 + $aOpts = KTFieldBehaviour::getByField($oField);
  980 + $aBehaviours = kt_array_merge($aBehaviours, $aOpts);
  981 + }
  982 +
  983 + $aTemplateData = array(
  984 + "context" => &$this,
  985 + "fieldset_id" => $fieldset_id,
  986 + "behaviours" => $aBehaviours,
  987 + );
  988 + return $oTemplate->render($aTemplateData);
  989 + }
  990 +
  991 + function do_finalRename() {
  992 + $fieldset_id = KTUtil::arrayGet($_REQUEST, "fieldset_id");
  993 + $aRenamed = (array) KTUtil::arrayGet($_REQUEST, "renamed");
  994 +
  995 + $this->startTransaction();
  996 +
  997 + foreach ($aRenamed as $bid => $new_name) {
  998 + $oBehaviour = KTFieldBehaviour::get($bid);
  999 + if (PEAR::isError($oBehaviour)) { continue; } // skip it...
  1000 + $oBehaviour->setName(trim($new_name));
  1001 + $res = $oBehaviour->update();
  1002 + if (PEAR::isError($res)) {
  1003 + $this->errorRedirectToMain(_kt('Failed to change name of behaviour.'), sprintf('action=edit&fFieldsetId=%s',$fieldset_id));
  1004 + }
  1005 + }
  1006 +
  1007 + $this->successRedirectToMain(_kt('Names changed.'), sprintf('action=edit&fFieldsetId=%s', $fieldset_id));
  1008 + }
  1009 +
  1010 +
875 1011 // }}}
876 1012 }
877 1013  
... ...
plugins/ktcore/admin/documentTypes.php
... ... @@ -51,6 +51,7 @@ class KTDocumentTypeDispatcher extends KTAdminDispatcher {
51 51 $oTemplating =& KTTemplating::getSingleton();
52 52 $oTemplate = $oTemplating->loadTemplate('ktcore/documenttypes/list');
53 53 $oTemplate->setData(array(
  54 + 'context' => $this,
54 55 'document_types' => DocumentType::getList(),
55 56 'add_fields' => $addFields,
56 57 ));
... ... @@ -151,6 +152,7 @@ class KTDocumentTypeDispatcher extends KTAdminDispatcher {
151 152 $this->oPage->setBreadcrumbDetails(_kt('edit'));
152 153  
153 154 $oTemplate->setData(array(
  155 + 'context' => $this,
154 156 'oDocumentType' => $oDocumentType,
155 157 'aCurrentFieldsets' => $aCurrentFieldsets,
156 158 'aAvailableFieldsets' => $aAvailableFieldsets,
... ... @@ -210,6 +212,22 @@ class KTDocumentTypeDispatcher extends KTAdminDispatcher {
210 212 $this->successRedirectTo('edit', _kt('Fieldsets associated.'), 'fDocumentTypeId=' . $oDocumentType->getId());
211 213 exit(0);
212 214 }
  215 +
  216 + function getFieldsetsForType($oType) {
  217 + $aCurrentFieldsets = KTFieldset::getForDocumentType($oType);
  218 + if (empty($aCurrentFieldsets)) {
  219 + return _kt('No fieldsets');
  220 + }
  221 +
  222 + $aNames = array();
  223 + foreach ($aCurrentFieldsets as $oFieldset) {
  224 + if (!PEAR::isError($oFieldset)) {
  225 + $aNames[] = $oFieldset->getName();
  226 + }
  227 + }
  228 +
  229 + return implode(', ', $aNames);
  230 + }
213 231 }
214 232  
215 233 ?>
... ...
resources/js/conditional_usage.js
... ... @@ -138,6 +138,7 @@ function createFixedWidget(fieldset, widget, i_name, i_value, i_label) {
138 138 return false;
139 139 }
140 140 var header = widget.getElementsByTagName('LABEL')[0]; // FIXME _could_ fail if pathalogical.
  141 + header.removeChild(header.getElementsByTagName('SPAN')[0]);
141 142 var i_friendly_name = scrapeText(header);
142 143  
143 144 var newWidget = DIV({'class':'field fixed'},
... ... @@ -345,7 +346,7 @@ function reviseConditional(buttonsource) {
345 346 */
346 347  
347 348 function initialiseConditionalFieldsets() {
348   - simpleLog('ERROR','incomplete function called: initialiseFieldsets.');
  349 +
349 350 var fieldsets = getElementsByTagAndClassName('FIELDSET','conditional_metadata');
350 351 simpleLog('DEBUG','found fieldsets: '+fieldsets.length);
351 352 // triggers initial update - since this contains no "fixed" vars, it'll remove "unfixed" widgets
... ...
templates/ktcore/documenttypes/list.smarty
... ... @@ -27,11 +27,12 @@ please enter a name for the type below.{/i18n}</p>
27 27 its details, or click on the delete button to remove it from the
28 28 system.{/i18n}</p>
29 29  
30   -<table class="listing" cellspacing="0" cellpadding="0">
  30 +<table class="kt_collection narrow" cellspacing="0" cellpadding="5">
31 31  
32 32 <thead>
33 33 <tr>
34 34 <th colspan="3">{i18n}Document Type{/i18n}</th>
  35 + <th>{i18n}Fieldsets{/i18n}</th>
35 36 </tr>
36 37 </thead>
37 38  
... ... @@ -46,17 +47,20 @@ system.{/i18n}&lt;/p&gt;
46 47 </td>
47 48  
48 49 <td>
49   - <a href="{addQS}action=edit&fDocumentTypeId={$oDocumentType->getId()}{/addQS}">{i18n}Edit{/i18n}</a>
  50 + <a class="ktAction ktEdit" href="{addQS}action=edit&fDocumentTypeId={$oDocumentType->getId()}{/addQS}">{i18n}Edit{/i18n}</a>
50 51 </td>
51 52  
52 53 <td>
53 54 {if $oDocumentType->getDisabled()}
54   - <a href="{addQS}action=enable&fDocumentTypeId={$oDocumentType->getId()}{/addQS}">{i18n}Enable{/i18n}</a>
  55 + <a class="ktAction ktEnable" href="{addQS}action=enable&fDocumentTypeId={$oDocumentType->getId()}{/addQS}">{i18n}Enable{/i18n}</a>
55 56 {else}
56   - <a href="{addQS}action=disable&fDocumentTypeId={$oDocumentType->getId()}{/addQS}">{i18n}Disable{/i18n}</a>
  57 + <a class="ktAction ktDelete" href="{addQS}action=disable&fDocumentTypeId={$oDocumentType->getId()}{/addQS}">{i18n}Disable{/i18n}</a>
57 58 {/if}
58 59 </td>
59 60  
  61 +<td>
  62 + <span class="descriptiveText">{$context->getFieldsetsForType($oDocumentType)}</span>
  63 +</td>
60 64  
61 65 </tr>
62 66 </tbody>
... ...
templates/ktcore/metadata/conditional/conditional_overview.smarty 0 → 100644
  1 +{$context->oPage->requireJSResource('thirdpartyjs/MochiKit/Base.js')}
  2 +{$context->oPage->requireJSResource('thirdpartyjs/MochiKit/Async.js')}
  3 +{$context->oPage->requireJSResource('thirdpartyjs/MochiKit/Iter.js')}
  4 +{$context->oPage->requireJSResource('thirdpartyjs/MochiKit/DateTime.js')}
  5 +{$context->oPage->requireJSResource('thirdpartyjs/MochiKit/DOM.js')}
  6 +{$context->oPage->requireJSResource('resources/js/taillog.js')}
  7 +{$context->oPage->requireJSResource('resources/js/conditional_usage.js')}
  8 +
  9 +<h2>{i18n}Conditional Metadata Overview{/i18n}</h2>
  10 +
  11 +<p class="descriptiveText">{i18n}Conditional Metadata is made up of fields, values
  12 +and behaviours. For a given behaviour, various values in other fields can be
  13 +selected. Depending on both the behaviour and the newly selected value, additional
  14 +fields and values may be selected, which cause a new behaviour to be "active".{/i18n}</p>
  15 +
  16 +<fieldset class="conditional_metadata"><legend>{i18n}Test Instance{/i18n}</legend>
  17 +<p class="descriptiveText">{i18n}For the majority of conditional cases, simply walking
  18 +through a test is sufficient. You can do that below for the fieldset you have selected.{/i18n}</p>
  19 +
  20 + <input type="hidden" class="fixed" name="fieldset" value="{$fieldset_id}" />
  21 + <p class="descriptiveText">
  22 + {$description}
  23 + </p>
  24 +
  25 + <div class="conditional_target">
  26 + {i18n}conditional data.{/i18n}
  27 + </div>
  28 +
  29 +
  30 +</fieldset>
  31 +
  32 +<p class="descriptiveText">{i18n}These behaviours and the fields and values they allow
  33 +are shown below for the active field.{/i18n}</p>
  34 +
  35 +<h3>Behaviours</h3>
  36 +<p class="descriptiveText">{i18n}Clicking on a given behaviour below will show you
  37 +which fields and values can be selected when the clicked behaviour is active.{/i18n}</p>
  38 +<ul>
  39 +<li><a href="#behaviour-null">No Active Behaviour (initial values)</a></li>
  40 +{foreach from=$behaviours item=oBehaviour}
  41 +<li><a href="#behaviour-{$oBehaviour->getId()}">{$oBehaviour->getName()}</a></li>
  42 +{/foreach}
  43 +</ul>
  44 +
  45 +<h4><a name="behaviour-null"></a>No Active Behaviour (initial values)</h4>
  46 +
  47 +{* this is a list of field rows ... see db. *}
  48 +
  49 +{foreach from=$context->getSetsForBehaviour(null, $fieldset_id) item=row}
  50 +<span class="descriptiveText">Field:</span> {$row.field_name} &raquo; <span class="descriptiveText">Option:</span> {$row.lookup_name} &raquo;
  51 +{if empty($row.behaviour_id)}
  52 + <span class="descriptiveText">no additional behaviours</span>
  53 +{else}
  54 + <a href="#behaviour-{$row.behaviour_id}">{$row.behaviour_name}</a>
  55 +{/if}
  56 +<br />
  57 +{/foreach}
  58 +
  59 +{foreach from=$behaviours item=oBehaviour}
  60 +
  61 +<h4><a name="behaviour-{$oBehaviour->getId()}"></a>{$oBehaviour->getName()}</h4>
  62 +
  63 +{* this is a list of field rows ... see db. *}
  64 +
  65 +{foreach from=$context->getSetsForBehaviour($oBehaviour, $fieldset_id) item=row}
  66 +<span class="descriptiveText">Field:</span> {$row.field_name} &raquo; <span class="descriptiveText">Option:</span> {$row.lookup_name} &raquo;
  67 +{if empty($row.behaviour_id)}
  68 + <span class="descriptiveText">no additional behaviours</span>
  69 +{else}
  70 + <a href="#behaviour-{$row.behaviour_id}">{$row.behaviour_name}</a>
  71 +{/if}
  72 +<br />
  73 +{/foreach}
  74 +
  75 +{/foreach}
0 76 \ No newline at end of file
... ...
templates/ktcore/metadata/conditional/conditional_rename_behaviours.smarty 0 → 100644
  1 +<h2>{i18n}Rename Behaviours{/i18n}</h2>
  2 +
  3 +<p class="descriptiveText">{i18n}If you have converted a simple conditional fieldset to a complex one,
  4 +it may be useful to rename some of the system-generated names. You can do that here.{/i18n}</p>
  5 +
  6 +<form method="POST" action="{$smarty.server.PHP_SELF}">
  7 +<table class="kt_collection narrow" cellspacing="0" cellpadding="5">
  8 +<thead>
  9 + <tr>
  10 + <th>{i18n}Current Name{/i18n}</th>
  11 + <th>{i18n}New Name{/i18n}</th>
  12 + </tr>
  13 +</thead>
  14 +<tbody>
  15 + {foreach from=$behaviours item=oBehaviour}
  16 + <tr>
  17 + <td><strong>{$oBehaviour->getName()}</strong></td>
  18 + <td><input type="text" name="renamed[{$oBehaviour->getId()}]" value="{$oBehaviour->getName()}" size="40" /></td>
  19 + </tr>
  20 + {/foreach}
  21 +</tbody>
  22 +</table>
  23 +
  24 +<div class="form_actions">
  25 + <input type="hidden" name="action" value="finalRename" />
  26 + <input type="hidden" name="fieldset_id" value="{$fieldset_id}" />
  27 + <input type="submit" value="{i18n}Rename Behaviours{/i18n}" />
  28 +</div>
  29 +</form>
0 30 \ No newline at end of file
... ...
templates/ktcore/metadata/listFieldsets.smarty
... ... @@ -14,6 +14,7 @@
14 14 <th>{i18n}Fields{/i18n}</th>
15 15 <th>{i18n}Edit{/i18n}</th>
16 16 <th>{i18n}Delete{/i18n}</th>
  17 + <th>{i18n}Document Types using this Fieldset{/i18n}</th>
17 18 </tr>
18 19 </thead>
19 20 <tbody>
... ... @@ -56,6 +57,10 @@
56 57 <a href="{addQS}action=delete&fFieldsetId={$oFieldset->getId()}{/addQS}" class="ktAction ktDelete">{i18n}Delete{/i18n}</a>
57 58 </td>
58 59  
  60 + <td>
  61 + <span class="descriptiveText">{$context->getTypesForFieldset($oFieldset)}</span>
  62 + </td>
  63 +
59 64 </tr>
60 65 </tbody>
61 66 {/foreach}
... ...