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

View File

@ -4,10 +4,10 @@
$.entwine('ss', function ($) {
$('.document-add-existing').entwine({
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(
'admin/pages/adddocument/linkdocument?ID=' + page_id + '&documentID=' + document_id,
'admin/pages/adddocument/linkdocument?dsid=' + documentSetId + '&documentID=' + document_id,
{
dataType: 'json',
success: function (data, textstatus) {
@ -92,7 +92,7 @@
doclist.load(
'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">' +
'<span class="name" title="{%=file.name%}">{%=file.name%}</span> ' +
'{% 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 { %}' +
'<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>' +
'{% } %}'
);
);

View File

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

View File

@ -46,6 +46,13 @@ Group:
cable-guy:
Code: cable-guy
Title: "Cable Guy"
Member:
editor:
Name: editor
Groups: =>Group.content-author
non-editor:
Name: cable-guy
Groups: =>Group.cable-guy
DMSDocumentSet:
ds1:
Title: Document Set 1
@ -83,20 +90,20 @@ DMSDocument:
CanEditType: LoggedInUsers
Folder: 5
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:
FileName: doc-anyone
CanViewType: Anyone
Folder: 5
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:
FileName: doc-only-these-users
CanViewType: OnlyTheseUsers
CanEditType: OnlyTheseUsers
Folder: 5
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
EditorGroups: =>Group.content-author
embargoed_document1:
@ -114,10 +121,3 @@ DMSDocument:
EmbargoUntilPublish: true
Folder: 5
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).
*
* Note that the fixture has the same two documents attached to two different document sets, attached to this
* page, but we're expecting only two since they should be returned as unique only (rather than four).
* See fixtures for relationships that define this result.
*/
public function testGetTitleWithNumberOfDocuments()
{
$siteTree = $this->objFromFixture('SiteTree', 's1');
$this->assertSame('testPage1 has document sets (2)', $siteTree->getTitleWithNumberOfDocuments());
$this->assertSame('testPage1 has document sets (5)', $siteTree->getTitleWithNumberOfDocuments());
}
/**