ENHANCEMENT: Editing document defaults after adding

This commit is contained in:
Julian Seidenberg 2012-08-09 18:10:50 +12:00
parent 7de79e20be
commit 607d3e8266
3 changed files with 64 additions and 26 deletions

View File

@ -172,13 +172,30 @@ class DMSDocumentAddController extends LeftAndMain {
} }
public function linkdocument() { public function linkdocument() {
$page = $this->currentPage(); $return = array('error' => _t('UploadField.FIELDNOTSET', 'Could not add document to page'));
$document = DataObject::get_by_id('DMSDocument', (int) $_GET['documentID']);
$document->addPage($page);
return json_encode(array( $page = $this->currentPage();
'iframe_url' => $this->getEditForm()->Fields()->fieldByName('Main.From your computer.AssetUploadField')->getItemHandler($document->ID)->EditLink() if (!empty($page)) {
)); $document = DataObject::get_by_id('DMSDocument', (int) $_GET['documentID']);
$document->addPage($page);
// Collect all output data.
$return = array(
'id' => $document->ID,
'name' => $document->getTitle(),
'thumbnail_url' => $document->UploadFieldThumbnailURL,
'edit_url' => $this->getEditForm()->Fields()->fieldByName('Main.From your computer.AssetUploadField')->getItemHandler($document->ID)->EditLink(),
'size' => $document->getFileSizeFormatted(),
'buttons' => $document->renderWith('UploadField_FileButtons'),
'showeditform' => true
);
}
return json_encode($return);
// array(
// 'iframe_url' => $this->getEditForm()->Fields()->fieldByName('Main.From your computer.AssetUploadField')->getItemHandler($document->ID)->EditLink()
// ));
} }
} }

View File

@ -1,7 +1,12 @@
(function($) { (function($) {
"use strict";
$.entwine('ss', function($) {
$('.document-add-existing .document-autocomplete').entwine({ $('.document-add-existing .document-autocomplete').entwine({
onmatch: function() { onmatch: function() {
$(this).autocomplete({ var self = this;
this.autocomplete({
source: 'admin/pages/adddocument/documentautocomplete', source: 'admin/pages/adddocument/documentautocomplete',
select: function(event, ui) { select: function(event, ui) {
if(ui.item) { if(ui.item) {
@ -13,7 +18,19 @@
{ {
dataType: 'json', dataType: 'json',
success: function(data, textstatus) { success: function(data, textstatus) {
alert(data.iframe_url); var fn = window.tmpl.cache['ss-uploadfield-downloadtemplate'];
var fnout = fn({
files: [data],
formatFileSize: function (bytes) {
if (typeof bytes !== 'number') return '';
if (bytes >= 1000000000) return (bytes / 1000000000).toFixed(2) + ' GB';
if (bytes >= 1000000) return (bytes / 1000000).toFixed(2) + ' MB';
return (bytes / 1000).toFixed(2) + ' KB';
},
options: self.fileupload('option')
});
$('.ss-add-files').append(fnout);
} }
} }
); );
@ -22,4 +39,6 @@
}); });
} }
}); });
});
}(jQuery)); }(jQuery));

View File

@ -1,22 +1,24 @@
<div class="document-add-existing field"> <div class="ss-add">
<div class="document-add-existing field">
<h3> <h3>
<span class="step-label"> <span class="step-label">
<span class="flyout">1</span><span class="arrow"></span> <span class="flyout">1</span><span class="arrow"></span>
<span class="title">Link a Document</span> <span class="title">Link a Document</span>
</span> </span>
</h3> </h3>
<input class="document-autocomplete" placeholder="Search by ID or filename" /> <input class="document-autocomplete" placeholder="Search by ID or filename" />
</div> </div>
<div> <div class="ss-assetuploadfield">
<h3> <h3>
<span class="step-label"> <span class="step-label">
<span class="flyout">2</span><span class="arrow"></span> <span class="flyout">2</span><span class="arrow"></span>
<span class="title">Edit details</span> <span class="title">Edit details</span>
</span> </span>
</h3> </h3>
<div class="fileOverview"> <div class="fileOverview">
<ul class="files"></ul> <ul class="files ss-uploadfield-files ss-add-files"></ul>
</div>
</div> </div>