ENHANCMENT: Add document to page when it is clicked
This commit is contained in:
parent
be809ac2c9
commit
6280bed9ab
|
@ -203,7 +203,9 @@ class DMSDocumentAddController extends LeftAndMain {
|
||||||
$list = '<ul>';
|
$list = '<ul>';
|
||||||
|
|
||||||
foreach($page->Documents() as $document) {
|
foreach($page->Documents() as $document) {
|
||||||
$list .= '<li>' . $document->ID . ' - ' . Convert::raw2xml($document->Title) . '</li>';
|
$list .= '<li><a class="add-document" data-document-id="' . $document->ID . '">';
|
||||||
|
$list .= $document->ID . ' - ' . Convert::raw2xml($document->Title);
|
||||||
|
$list .= '</a></li>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$list .= '</ul>';
|
$list .= '</ul>';
|
||||||
|
|
|
@ -2,6 +2,32 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
$.entwine('ss', function($) {
|
$.entwine('ss', function($) {
|
||||||
|
$('.document-add-existing').entwine({
|
||||||
|
adddocument: function(document_id) {
|
||||||
|
var page_id = $(this).closest('form').find(':input[name=ID]').val();
|
||||||
|
|
||||||
|
jQuery.ajax(
|
||||||
|
'admin/pages/adddocument/linkdocument?ID=' + page_id + '&documentID=' + document_id,
|
||||||
|
{
|
||||||
|
dataType: 'json',
|
||||||
|
success: function(data, textstatus) {
|
||||||
|
var fn = window.tmpl.cache['ss-uploadfield-addtemplate'];
|
||||||
|
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';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.ss-add-files').append(fnout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$('.document-add-existing .document-autocomplete').entwine({
|
$('.document-add-existing .document-autocomplete').entwine({
|
||||||
onmatch: function() {
|
onmatch: function() {
|
||||||
|
@ -10,30 +36,9 @@
|
||||||
source: 'admin/pages/adddocument/documentautocomplete',
|
source: 'admin/pages/adddocument/documentautocomplete',
|
||||||
select: function(event, ui) {
|
select: function(event, ui) {
|
||||||
if(ui.item) {
|
if(ui.item) {
|
||||||
var page_id = $(this).closest('form').find(':input[name=ID]').val();
|
|
||||||
var document_id = ui.item.value;
|
var document_id = ui.item.value;
|
||||||
|
|
||||||
jQuery.ajax(
|
$(this).closest('.document-add-existing').adddocument(document_id);
|
||||||
'admin/pages/adddocument/linkdocument?ID=' + page_id + '&documentID=' + document_id,
|
|
||||||
{
|
|
||||||
dataType: 'json',
|
|
||||||
success: function(data, textstatus) {
|
|
||||||
var fn = window.tmpl.cache['ss-uploadfield-addtemplate'];
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -46,5 +51,15 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('.document-add-existing a.add-document').entwine({
|
||||||
|
onclick: function(event) {
|
||||||
|
var document_id = $(this).data('document-id');
|
||||||
|
|
||||||
|
$(this).closest('.document-add-existing').adddocument(document_id);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
});
|
});
|
||||||
}(jQuery));
|
}(jQuery));
|
Loading…
Reference in New Issue