Commit 49235ec5b34b71010db771b40d78823393e26397
1 parent
98bc743d
fix for KTS-1348: edit does not specify current type.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5929 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
3 changed files
with
93 additions
and
9 deletions
lib/metadata/metadatautil.inc.php
| ... | ... | @@ -671,11 +671,14 @@ class KTMetadataUtil { |
| 671 | 671 | // }}} |
| 672 | 672 | |
| 673 | 673 | // {{{ fieldsetsForDocument |
| 674 | - function fieldsetsForDocument($oDocument) { | |
| 674 | + function fieldsetsForDocument($oDocument, $iTypeOverride = null) { | |
| 675 | 675 | global $default; |
| 676 | 676 | $oDocument = KTUtil::getObject('Document', $oDocument); |
| 677 | 677 | $iMetadataVersionId = $oDocument->getMetadataVersionId(); |
| 678 | 678 | $iDocumentTypeId = $oDocument->getDocumentTypeId(); |
| 679 | + if (!is_null($iTypeOverride)) { | |
| 680 | + $iDocumentTypeId = $iTypeOverride; | |
| 681 | + } | |
| 679 | 682 | |
| 680 | 683 | $sQuery = "SELECT DISTINCT F.id AS fieldset_id " . |
| 681 | 684 | "FROM $default->document_metadata_version_table AS DM INNER JOIN document_fields_link AS DFL ON DM.id = DFL.metadata_version_id " . | ... | ... |
plugins/ktcore/document/edit.php
| ... | ... | @@ -58,6 +58,10 @@ class KTDocumentEditAction extends KTDocumentAction { |
| 58 | 58 | return _kt('Edit Metadata'); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | + function predispatch() { | |
| 62 | + $this->persistParams(array('new_type')); | |
| 63 | + } | |
| 64 | + | |
| 61 | 65 | function form_edit() { |
| 62 | 66 | $oForm = new KTForm; |
| 63 | 67 | $oForm->setOptions(array( |
| ... | ... | @@ -74,6 +78,12 @@ class KTDocumentEditAction extends KTDocumentAction { |
| 74 | 78 | $oFReg =& KTFieldsetRegistry::getSingleton(); |
| 75 | 79 | |
| 76 | 80 | $doctypeid = $this->oDocument->getDocumentTypeID(); |
| 81 | + if ($_REQUEST['new_type']) { | |
| 82 | + $oTestType = DocumentType::get($_REQUEST['new_type']); | |
| 83 | + if (!PEAR::isError($oTestType)) { | |
| 84 | + $doctypeid = $oTestType->getId(); | |
| 85 | + } | |
| 86 | + } | |
| 77 | 87 | |
| 78 | 88 | $widgets = array( |
| 79 | 89 | array('ktcore.widgets.string', array( |
| ... | ... | @@ -90,7 +100,7 @@ class KTDocumentEditAction extends KTDocumentAction { |
| 90 | 100 | 'output' => 'document_title', |
| 91 | 101 | )), |
| 92 | 102 | ); |
| 93 | - $fieldsets = (array) KTMetadataUtil::fieldsetsForDocument($this->oDocument); | |
| 103 | + $fieldsets = (array) KTMetadataUtil::fieldsetsForDocument($this->oDocument, $doctypeid); | |
| 94 | 104 | |
| 95 | 105 | foreach ($fieldsets as $oFieldset) { |
| 96 | 106 | $widgets = kt_array_merge($widgets, $oFReg->widgetsForFieldset($oFieldset, 'fieldset_' . $oFieldset->getId(), $this->oDocument)); |
| ... | ... | @@ -103,19 +113,22 @@ class KTDocumentEditAction extends KTDocumentAction { |
| 103 | 113 | return $oForm; |
| 104 | 114 | } |
| 105 | 115 | |
| 106 | - function do_main() { | |
| 107 | - $this->addErrorMessage("Doctype changing regressed."); | |
| 108 | - | |
| 116 | + function do_main() { | |
| 109 | 117 | $this->oPage->setBreadcrumbDetails("Edit Metadata"); |
| 110 | 118 | |
| 111 | 119 | $oTemplate = $this->oValidator->validateTemplate('ktcore/document/edit'); |
| 112 | - | |
| 120 | + | |
| 121 | + $doctypeid = $this->oDocument->getDocumentTypeID(); | |
| 122 | + $type = DocumentType::get($doctypeid); | |
| 123 | + | |
| 124 | + | |
| 113 | 125 | $oForm = $this->form_edit(); |
| 114 | 126 | |
| 115 | 127 | $oTemplate->setData(array( |
| 116 | 128 | 'context' => $this, |
| 117 | 129 | 'form' => $oForm, |
| 118 | 130 | 'document' => $this->oDocument, |
| 131 | + 'type_name' => $type->getName(), | |
| 119 | 132 | )); |
| 120 | 133 | return $oTemplate->render(); |
| 121 | 134 | } |
| ... | ... | @@ -140,8 +153,16 @@ class KTDocumentEditAction extends KTDocumentAction { |
| 140 | 153 | // ); |
| 141 | 154 | // |
| 142 | 155 | // we do this the "easy" way. |
| 156 | + $doctypeid = $this->oDocument->getDocumentTypeId(); | |
| 157 | + if ($_REQUEST['new_type']) { | |
| 158 | + $oTestType = DocumentType::get($_REQUEST['new_type']); | |
| 159 | + if (!PEAR::isError($oTestType)) { | |
| 160 | + $doctypeid = $oTestType->getId(); | |
| 161 | + } | |
| 162 | + } | |
| 163 | + | |
| 143 | 164 | |
| 144 | - $fieldsets = KTMetadataUtil::fieldsetsForDocument($this->oDocument); | |
| 165 | + $fieldsets = KTMetadataUtil::fieldsetsForDocument($this->oDocument, $doctypeid); | |
| 145 | 166 | |
| 146 | 167 | $MDPack = array(); |
| 147 | 168 | foreach ($fieldsets as $oFieldset) { |
| ... | ... | @@ -162,6 +183,9 @@ class KTDocumentEditAction extends KTDocumentAction { |
| 162 | 183 | } |
| 163 | 184 | |
| 164 | 185 | $this->startTransaction(); |
| 186 | + if ($this->oDocument->getDocumentTypeId() != $doctypeid) { | |
| 187 | + $this->oDocument->setDocumentTypeId($doctypeid); | |
| 188 | + } | |
| 165 | 189 | $this->oDocument->setName($data['document_title']); |
| 166 | 190 | $res = $this->oDocument->update(); |
| 167 | 191 | if (PEAR::isError($res)) { |
| ... | ... | @@ -190,9 +214,66 @@ class KTDocumentEditAction extends KTDocumentAction { |
| 190 | 214 | |
| 191 | 215 | redirect(KTBrowseUtil::getUrlForDocument($this->oDocument->getId())); |
| 192 | 216 | exit(0); |
| 193 | - | |
| 194 | 217 | } |
| 195 | 218 | |
| 219 | + function form_changetype() { | |
| 220 | + $oForm = new KTForm; | |
| 221 | + $oForm->setOptions(array( | |
| 222 | + 'label' => _kt("Change Document Type"), | |
| 223 | + 'description' => _kt("Changing the document type will allow different metadata to be associated with it."), | |
| 224 | + 'identifier' => 'ktcore.doc.edit.typechange', | |
| 225 | + 'submit_label' => _kt("Update Document"), | |
| 226 | + 'context' => $this, | |
| 227 | + 'cancel_action' => 'main', | |
| 228 | + 'action' => 'trytype', | |
| 229 | + )); | |
| 230 | + | |
| 231 | + $type = DocumentType::get($this->oDocument->getDocumentTypeId()); | |
| 232 | + $current_type_name = $type->getName(); | |
| 233 | + $oFolder = Folder::get($this->oDocument->getFolderID()); | |
| 234 | + | |
| 235 | + $oForm->setWidgets(array( | |
| 236 | + array('ktcore.widgets.entityselection',array( | |
| 237 | + 'label' => _kt("New Document Type"), | |
| 238 | + 'description' => _kt("Please select the new type for this document."), | |
| 239 | + 'important_description' => sprintf(_kt("The document is currently of type \"%s\"."), $current_type_name), | |
| 240 | + 'value' => $type->getId(), | |
| 241 | + 'label_method' => 'getName', | |
| 242 | + 'vocab' => DocumentType::getListForUserAndFolder($this->oUser, $oFolder), | |
| 243 | + 'simple_select' => false, | |
| 244 | + 'required' => true, | |
| 245 | + 'name' => 'type' | |
| 246 | + )), | |
| 247 | + )); | |
| 248 | + | |
| 249 | + $oForm->setValidators(array( | |
| 250 | + array('ktcore.validators.entity', array( | |
| 251 | + 'test' => 'type', | |
| 252 | + 'output' => 'type', | |
| 253 | + 'class' => 'DocumentType', | |
| 254 | + )), | |
| 255 | + )); | |
| 256 | + | |
| 257 | + return $oForm; | |
| 258 | + } | |
| 259 | + | |
| 260 | + function do_selecttype() { | |
| 261 | + $oForm = $this->form_changetype(); | |
| 262 | + return $oForm->renderPage(_kt("Change Document Type")); | |
| 263 | + } | |
| 264 | + | |
| 265 | + function do_trytype() { | |
| 266 | + $oForm = $this->form_changetype(); | |
| 267 | + $res = $oForm->validate(); | |
| 268 | + $data = $res['results']; | |
| 269 | + $errors = $res['errors']; | |
| 270 | + | |
| 271 | + if (!empty($errors)) { | |
| 272 | + $oForm->handleError(); | |
| 273 | + } | |
| 274 | + | |
| 275 | + $this->successRedirectToMain(sprintf(_kt("You have selected a new document type: %s. Please note that this change has <strong>not</strong> yet been saved - please update the metadata below as necessary, and then save the document to make it a permanent change."), $data['type']->getName()), array('new_type' => $data['type']->getId())); | |
| 276 | + } | |
| 196 | 277 | } |
| 197 | 278 | // }}} |
| 198 | 279 | ... | ... |
templates/ktcore/document/edit.smarty
| ... | ... | @@ -14,7 +14,7 @@ |
| 14 | 14 | <h2>{i18n}Editing{/i18n}: {$document->getName()}</h2> |
| 15 | 15 | |
| 16 | 16 | {capture assign=link}{addQS}action=selectType&fDocumentId={$document->getId()}{/addQS}{/capture} |
| 17 | -<p class="descriptiveText">{i18n arg_link=$link}Change the <strong><a href="#link#">document type</a></strong>{/i18n}</p> | |
| 17 | +<p class="descriptiveText">{i18n arg_link=$link arg_name=$type_name}Change the <strong><a href="#link#">document type</a></strong>. The current type is "#name#"{/i18n}</p> | |
| 18 | 18 | |
| 19 | 19 | <p class="descriptiveText">{i18n}The following document metadata is available for editing.{/i18n}</p> |
| 20 | 20 | ... | ... |