2012-08-07 03:44:42 +02:00
|
|
|
(function($) {
|
2012-08-09 08:10:50 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
$.entwine('ss', function($) {
|
2012-08-14 04:12:56 +02:00
|
|
|
$('.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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2012-08-21 04:21:23 +02:00
|
|
|
},
|
|
|
|
selectdocument: function(documentID, documentName) {
|
|
|
|
if (typeof(documentID) !== "undefined") {
|
|
|
|
//substitute the ID for the full document name, if no name is present
|
|
|
|
if (typeof(documentName) === "undefined") {
|
|
|
|
documentName = documentID;
|
|
|
|
}
|
|
|
|
$('.ss-add-files').html('<div class="selected-document" data-document-id="'+documentID+'">'+documentName+'</div>');
|
|
|
|
} else {
|
|
|
|
$('.ss-add-files').html('');
|
|
|
|
}
|
2012-08-14 04:12:56 +02:00
|
|
|
}
|
|
|
|
});
|
2012-08-09 08:10:50 +02:00
|
|
|
|
2012-08-10 04:58:26 +02:00
|
|
|
$('.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) {
|
2012-08-21 04:21:23 +02:00
|
|
|
if (self.closest('.document-add-existing').hasClass('link-editor-context')) {
|
|
|
|
$(this).closest('.document-add-existing').selectdocument(ui.item.value, ui.item.label);
|
|
|
|
} else {
|
|
|
|
$(this).closest('.document-add-existing').adddocument(ui.item.value);
|
|
|
|
}
|
2012-08-20 01:40:53 +02:00
|
|
|
|
2012-08-21 07:56:40 +02:00
|
|
|
$(this).val('');
|
|
|
|
|
2012-08-20 01:40:53 +02:00
|
|
|
return false;
|
2012-08-10 04:58:26 +02:00
|
|
|
}
|
2012-08-07 04:42:03 +02:00
|
|
|
}
|
2012-08-10 04:58:26 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2012-08-09 08:10:50 +02:00
|
|
|
|
2012-08-17 06:48:09 +02:00
|
|
|
// Add label to tree drop down button
|
|
|
|
$('.document-add-existing .treedropdownfield-toggle-panel-link').entwine({
|
|
|
|
onmatch: function() {
|
|
|
|
this.prepend('<span>Browse by page</span>');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-08-20 01:40:53 +02:00
|
|
|
$('.document-add-existing .TreeDropdownField').entwine({
|
|
|
|
onpanelshow: function() {
|
2012-08-20 00:49:35 +02:00
|
|
|
$(this).closest('.document-add-existing').find('input.document-autocomplete').prop('disabled', true);
|
2012-08-20 01:40:53 +02:00
|
|
|
},
|
|
|
|
onpanelhide: function() {
|
|
|
|
$(this).closest('.document-add-existing').find('input.document-autocomplete').prop('disabled', $(this).closest('.document-add-existing').find('.document-list:visible').length > 0);
|
2012-08-17 06:48:09 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-08-14 03:59:08 +02:00
|
|
|
$('.document-add-existing input[name=PageSelector]').entwine({
|
|
|
|
onchange: function(event) {
|
2012-08-20 01:40:53 +02:00
|
|
|
var doclist = $(this).closest('.document-add-existing').find('.document-list');
|
2014-01-28 22:26:34 +01:00
|
|
|
doclist.html('<p>Loading...</p>');
|
2012-08-20 01:40:53 +02:00
|
|
|
doclist.show();
|
|
|
|
doclist.load(
|
|
|
|
'admin/pages/adddocument/documentlist?pageID=' + $(this).val()
|
2012-08-20 00:49:35 +02:00
|
|
|
);
|
|
|
|
|
2012-08-14 03:59:08 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-08-14 04:12:56 +02:00
|
|
|
$('.document-add-existing a.add-document').entwine({
|
|
|
|
onclick: function(event) {
|
2012-08-21 04:21:23 +02:00
|
|
|
var document_id = this.data('document-id');
|
|
|
|
var dae = this.closest('.document-add-existing');
|
2012-08-14 04:12:56 +02:00
|
|
|
|
2012-08-21 04:21:23 +02:00
|
|
|
if (dae.hasClass('link-editor-context')) {
|
|
|
|
dae.selectdocument(document_id, this.text());
|
|
|
|
} else {
|
|
|
|
dae.adddocument(document_id);
|
|
|
|
}
|
|
|
|
|
2012-08-21 07:56:40 +02:00
|
|
|
$(this).closest('.document-list').hide();
|
|
|
|
$(this).closest('.document-add-existing').find('input.document-autocomplete').prop('disabled', false);
|
|
|
|
|
2012-08-14 04:12:56 +02:00
|
|
|
return false;
|
|
|
|
}
|
2012-08-20 01:40:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$('body').entwine({
|
|
|
|
onclick: function(event) {
|
|
|
|
$('.document-list:visible').hide()
|
|
|
|
.closest('.document-add-existing').find('input.document-autocomplete').prop('disabled', false);
|
|
|
|
}
|
|
|
|
});
|
2012-08-14 04:12:56 +02:00
|
|
|
|
2012-08-20 03:25:38 +02:00
|
|
|
$('.document-add-existing .treedropdownfield-toggle-panel-link').entwine({
|
|
|
|
onclick: function(event) {
|
|
|
|
$('.document-list:visible').hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-08-09 08:10:50 +02:00
|
|
|
});
|
2012-08-07 03:44:42 +02:00
|
|
|
}(jQuery));
|