2012-08-07 03:44:42 +02:00
|
|
|
(function($) {
|
2012-08-09 08:10:50 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
$.entwine('ss', function($) {
|
|
|
|
|
2012-08-07 03:44:42 +02:00
|
|
|
$('.document-add-existing .document-autocomplete').entwine({
|
|
|
|
onmatch: function() {
|
2012-08-09 08:10:50 +02:00
|
|
|
var self = this;
|
|
|
|
this.autocomplete({
|
2012-08-07 04:42:03 +02:00
|
|
|
source: 'admin/pages/adddocument/documentautocomplete',
|
|
|
|
select: function(event, ui) {
|
|
|
|
if(ui.item) {
|
|
|
|
var page_id = $(this).closest('form').find(':input[name=ID]').val();
|
|
|
|
var document_id = ui.item.value;
|
|
|
|
|
2012-08-08 07:58:08 +02:00
|
|
|
jQuery.ajax(
|
|
|
|
'admin/pages/adddocument/linkdocument?ID=' + page_id + '&documentID=' + document_id,
|
|
|
|
{
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data, textstatus) {
|
2012-08-09 08:10:50 +02:00
|
|
|
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);
|
2012-08-08 07:58:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2012-08-07 04:42:03 +02:00
|
|
|
}
|
|
|
|
}
|
2012-08-07 03:44:42 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2012-08-09 08:10:50 +02:00
|
|
|
|
|
|
|
});
|
2012-08-07 03:44:42 +02:00
|
|
|
}(jQuery));
|