ENHANCMENT: Add document to page when it is clicked

This commit is contained in:
Andrew O'Neil 2012-08-14 14:12:56 +12:00
parent be809ac2c9
commit 6280bed9ab
2 changed files with 40 additions and 23 deletions

View File

@ -203,7 +203,9 @@ class DMSDocumentAddController extends LeftAndMain {
$list = '<ul>';
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>';

View File

@ -2,16 +2,9 @@
"use strict";
$.entwine('ss', function($) {
$('.document-add-existing .document-autocomplete').entwine({
onmatch: function() {
var self = this;
this.autocomplete({
source: 'admin/pages/adddocument/documentautocomplete',
select: function(event, ui) {
if(ui.item) {
$('.document-add-existing').entwine({
adddocument: function(document_id) {
var page_id = $(this).closest('form').find(':input[name=ID]').val();
var document_id = ui.item.value;
jQuery.ajax(
'admin/pages/adddocument/linkdocument?ID=' + page_id + '&documentID=' + document_id,
@ -26,8 +19,7 @@
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);
@ -35,6 +27,19 @@
}
);
}
});
$('.document-add-existing .document-autocomplete').entwine({
onmatch: function() {
var self = this;
this.autocomplete({
source: 'admin/pages/adddocument/documentautocomplete',
select: function(event, ui) {
if(ui.item) {
var document_id = ui.item.value;
$(this).closest('.document-add-existing').adddocument(document_id);
}
}
});
}
@ -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));