FIX Allow linking existing documents to document sets via add existing upload field

This commit is contained in:
Robbie Averill 2017-05-05 15:35:39 +12:00
parent b80aa645f8
commit 66abd22ee5
6 changed files with 29 additions and 29 deletions

View File

@ -218,16 +218,17 @@ class DMSDocumentAddController extends LeftAndMain
return Convert::raw2json($return); return Convert::raw2json($return);
} }
/**
* Link an existing document to the given document set ID
* @return string JSON
*/
public function linkdocument() public function linkdocument()
{ {
$return = array('error' => _t('UploadField.FIELDNOTSET', 'Could not add document to page')); $return = array('error' => _t('UploadField.FIELDNOTSET', 'Could not add document to page'));
$return = array('error' => 'testing'); $documentSet = $this->getCurrentDocumentSet();
return Convert::raw2json($return); if (!empty($documentSet)) {
$page = $this->currentPage();
if (!empty($page)) {
$document = DMSDocument::get()->byId($this->getRequest()->getVar('documentID')); $document = DMSDocument::get()->byId($this->getRequest()->getVar('documentID'));
// @todo add sets $documentSet->Documents()->add($document);
$document->addPage($page);
$buttonText = '<button class="ss-uploadfield-item-edit ss-ui-button ui-corner-all"' $buttonText = '<button class="ss-uploadfield-item-edit ss-ui-button ui-corner-all"'
. ' title="' . _t('DMSDocument.EDITDOCUMENT', 'Edit this document') . '" data-icon="pencil">' . ' title="' . _t('DMSDocument.EDITDOCUMENT', 'Edit this document') . '" data-icon="pencil">'

View File

@ -4,10 +4,10 @@
$.entwine('ss', function ($) { $.entwine('ss', function ($) {
$('.document-add-existing').entwine({ $('.document-add-existing').entwine({
adddocument: function (document_id) { adddocument: function (document_id) {
var page_id = $(this).closest('form').find(':input[name=ID]').val(); var documentSetId = $(this).closest('form').find('input[name="DSID"]').val();
jQuery.ajax( jQuery.ajax(
'admin/pages/adddocument/linkdocument?ID=' + page_id + '&documentID=' + document_id, 'admin/pages/adddocument/linkdocument?dsid=' + documentSetId + '&documentID=' + document_id,
{ {
dataType: 'json', dataType: 'json',
success: function (data, textstatus) { success: function (data, textstatus) {
@ -92,7 +92,7 @@
doclist.load( doclist.load(
'admin/pages/adddocument/documentlist?pageID=' + $(this).val() 'admin/pages/adddocument/documentlist?pageID=' + $(this).val()
); );
} }
}); });
@ -128,4 +128,4 @@
}); });
}); });
}(jQuery)); }(jQuery));

View File

@ -8,7 +8,7 @@ window.tmpl.cache['ss-uploadfield-addtemplate'] = tmpl(
'<label class="ss-uploadfield-item-name">' + '<label class="ss-uploadfield-item-name">' +
'<span class="name" title="{%=file.name%}">{%=file.name%}</span> ' + '<span class="name" title="{%=file.name%}">{%=file.name%}</span> ' +
'{% if (!file.error) { %}' + '{% if (!file.error) { %}' +
'<div class="ss-uploadfield-item-status ui-state-success-text" title="'+ss.i18n._t('UploadField.AddedToPage', 'Added to Page')+'">'+ss.i18n._t('UploadField.AddedToPage', 'Added to Page')+'</div>' + '<div class="ss-uploadfield-item-status ui-state-success-text" title="'+ss.i18n._t('UploadField.AddedToDocumentSet', 'Added to Document Set')+'">'+ss.i18n._t('UploadField.AddedToDocumentSet', 'Added to Document Set')+'</div>' +
'{% } else { %}' + '{% } else { %}' +
'<div class="ss-uploadfield-item-status ui-state-error-text" title="{%=o.options.errorMessages[file.error] || file.error%}">{%=o.options.errorMessages[file.error] || file.error%}</div>' + '<div class="ss-uploadfield-item-status ui-state-error-text" title="{%=o.options.errorMessages[file.error] || file.error%}">{%=o.options.errorMessages[file.error] || file.error%}</div>' +
'{% } %}' + '{% } %}' +
@ -27,4 +27,4 @@ window.tmpl.cache['ss-uploadfield-addtemplate'] = tmpl(
'{% } %}' + '{% } %}' +
'</li>' + '</li>' +
'{% } %}' '{% } %}'
); );

View File

@ -167,8 +167,8 @@ class DMSTest extends FunctionalTest
{ {
$pageWithEmbargoes = $this->objFromFixture('SiteTree', 's3'); $pageWithEmbargoes = $this->objFromFixture('SiteTree', 's3');
$documents = $this->dms->getByPage($pageWithEmbargoes); $documents = $this->dms->getByPage($pageWithEmbargoes);
// Fixture: 3 documents in set, 1 is embargoed // Fixture: 6 documents in set, 1 is embargoed
$this->assertCount(2, $documents, 'Embargoed documents are excluded by default'); $this->assertCount(5, $documents, 'Embargoed documents are excluded by default');
$this->assertContainsOnlyInstancesOf('DMSDocument', $documents); $this->assertContainsOnlyInstancesOf('DMSDocument', $documents);
} }
@ -179,8 +179,8 @@ class DMSTest extends FunctionalTest
{ {
$pageWithEmbargoes = $this->objFromFixture('SiteTree', 's3'); $pageWithEmbargoes = $this->objFromFixture('SiteTree', 's3');
$documents = $this->dms->getByPage($pageWithEmbargoes, true); $documents = $this->dms->getByPage($pageWithEmbargoes, true);
// Fixture: 3 documents in set, 1 is embargoed // Fixture: 6 documents in set, 1 is embargoed
$this->assertCount(3, $documents, 'Embargoed documents can be included'); $this->assertCount(6, $documents, 'Embargoed documents can be included');
$this->assertContainsOnlyInstancesOf('DMSDocument', $documents); $this->assertContainsOnlyInstancesOf('DMSDocument', $documents);
} }

View File

@ -46,6 +46,13 @@ Group:
cable-guy: cable-guy:
Code: cable-guy Code: cable-guy
Title: "Cable Guy" Title: "Cable Guy"
Member:
editor:
Name: editor
Groups: =>Group.content-author
non-editor:
Name: cable-guy
Groups: =>Group.cable-guy
DMSDocumentSet: DMSDocumentSet:
ds1: ds1:
Title: Document Set 1 Title: Document Set 1
@ -83,20 +90,20 @@ DMSDocument:
CanEditType: LoggedInUsers CanEditType: LoggedInUsers
Folder: 5 Folder: 5
Tags: =>DMSTag.t1, =>DMSTag.t2, =>DMSTag.t3, =>DMSTag.t4 Tags: =>DMSTag.t1, =>DMSTag.t2, =>DMSTag.t3, =>DMSTag.t4
Pages: =>SiteTree.s1, =>SiteTree.s2, =>SiteTree.s3, =>SiteTree.s4, =>SiteTree.s5, =>SiteTree.s6 Sets: =>DMSDocumentSet.ds1, =>DMSDocumentSet.ds2, =>DMSDocumentSet.ds3, =>DMSDocumentSet.ds4
doc-anyone: doc-anyone:
FileName: doc-anyone FileName: doc-anyone
CanViewType: Anyone CanViewType: Anyone
Folder: 5 Folder: 5
Tags: =>DMSTag.t1, =>DMSTag.t2, =>DMSTag.t3, =>DMSTag.t4 Tags: =>DMSTag.t1, =>DMSTag.t2, =>DMSTag.t3, =>DMSTag.t4
Pages: =>SiteTree.s1, =>SiteTree.s2, =>SiteTree.s3, =>SiteTree.s4, =>SiteTree.s5, =>SiteTree.s6 Sets: =>DMSDocumentSet.ds1, =>DMSDocumentSet.ds2, =>DMSDocumentSet.ds3, =>DMSDocumentSet.ds4
doc-only-these-users: doc-only-these-users:
FileName: doc-only-these-users FileName: doc-only-these-users
CanViewType: OnlyTheseUsers CanViewType: OnlyTheseUsers
CanEditType: OnlyTheseUsers CanEditType: OnlyTheseUsers
Folder: 5 Folder: 5
Tags: =>DMSTag.t1, =>DMSTag.t2, =>DMSTag.t3, =>DMSTag.t4 Tags: =>DMSTag.t1, =>DMSTag.t2, =>DMSTag.t3, =>DMSTag.t4
Pages: =>SiteTree.s1, =>SiteTree.s2, =>SiteTree.s3, =>SiteTree.s4, =>SiteTree.s5, =>SiteTree.s6 Sets: =>DMSDocumentSet.ds1, =>DMSDocumentSet.ds2, =>DMSDocumentSet.ds3, =>DMSDocumentSet.ds4
ViewerGroups: =>Group.content-author ViewerGroups: =>Group.content-author
EditorGroups: =>Group.content-author EditorGroups: =>Group.content-author
embargoed_document1: embargoed_document1:
@ -114,10 +121,3 @@ DMSDocument:
EmbargoUntilPublish: true EmbargoUntilPublish: true
Folder: 5 Folder: 5
Sets: =>DMSDocumentSet.ds5 Sets: =>DMSDocumentSet.ds5
Member:
editor:
Name: editor
Groups: =>Group.content-author
non-editor:
Name: cable-guy
Groups: =>Group.cable-guy

View File

@ -54,13 +54,12 @@ class DMSSiteTreeExtensionTest extends SapphireTest
/** /**
* Ensure that a page title can be retrieved with the number of related documents it has (across all document sets). * Ensure that a page title can be retrieved with the number of related documents it has (across all document sets).
* *
* Note that the fixture has the same two documents attached to two different document sets, attached to this * See fixtures for relationships that define this result.
* page, but we're expecting only two since they should be returned as unique only (rather than four).
*/ */
public function testGetTitleWithNumberOfDocuments() public function testGetTitleWithNumberOfDocuments()
{ {
$siteTree = $this->objFromFixture('SiteTree', 's1'); $siteTree = $this->objFromFixture('SiteTree', 's1');
$this->assertSame('testPage1 has document sets (2)', $siteTree->getTitleWithNumberOfDocuments()); $this->assertSame('testPage1 has document sets (5)', $siteTree->getTitleWithNumberOfDocuments());
} }
/** /**