2017-05-01 05:54:48 +02:00
|
|
|
(function ($) {
|
2012-08-09 08:10:50 +02:00
|
|
|
"use strict";
|
|
|
|
|
2017-05-01 05:54:48 +02:00
|
|
|
$.entwine('ss', function ($) {
|
2012-08-14 04:12:56 +02:00
|
|
|
$('.document-add-existing').entwine({
|
2017-05-01 05:54:48 +02:00
|
|
|
adddocument: function (document_id) {
|
2017-05-05 05:35:39 +02:00
|
|
|
var documentSetId = $(this).closest('form').find('input[name="DSID"]').val();
|
2012-08-14 04:12:56 +02:00
|
|
|
|
|
|
|
jQuery.ajax(
|
2017-05-05 05:35:39 +02:00
|
|
|
'admin/pages/adddocument/linkdocument?dsid=' + documentSetId + '&documentID=' + document_id,
|
2012-08-14 04:12:56 +02:00
|
|
|
{
|
|
|
|
dataType: 'json',
|
2017-05-01 05:54:48 +02:00
|
|
|
success: function (data, textstatus) {
|
2012-08-14 04:12:56 +02:00
|
|
|
var fn = window.tmpl.cache['ss-uploadfield-addtemplate'];
|
|
|
|
var fnout = fn({
|
|
|
|
files: [data],
|
2017-05-01 05:54:48 +02:00
|
|
|
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';
|
|
|
|
}
|
2012-08-14 04:12:56 +02:00
|
|
|
return (bytes / 1000).toFixed(2) + ' KB';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.ss-add-files').append(fnout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2012-08-21 04:21:23 +02:00
|
|
|
},
|
2017-05-01 05:54:48 +02:00
|
|
|
selectdocument: function (documentID, documentName) {
|
2012-08-21 04:21:23 +02:00
|
|
|
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({
|
2017-05-01 05:54:48 +02:00
|
|
|
onmatch: function () {
|
2012-08-10 04:58:26 +02:00
|
|
|
var self = this;
|
|
|
|
this.autocomplete({
|
|
|
|
source: 'admin/pages/adddocument/documentautocomplete',
|
2017-05-01 05:54:48 +02:00
|
|
|
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({
|
2017-05-01 05:54:48 +02:00
|
|
|
onmatch: function () {
|
2012-08-17 06:48:09 +02:00
|
|
|
this.prepend('<span>Browse by page</span>');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-08-20 01:40:53 +02:00
|
|
|
$('.document-add-existing .TreeDropdownField').entwine({
|
2017-05-01 05:54:48 +02:00
|
|
|
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
|
|
|
},
|
2017-05-01 05:54:48 +02:00
|
|
|
onpanelhide: function () {
|
2012-08-20 01:40:53 +02:00
|
|
|
$(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({
|
2017-05-01 05:54:48 +02:00
|
|
|
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
|
|
|
);
|
2017-05-05 05:35:39 +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({
|
2017-05-01 05:54:48 +02:00
|
|
|
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({
|
2017-05-01 05:54:48 +02:00
|
|
|
onclick: function (event) {
|
2012-08-20 01:40:53 +02:00
|
|
|
$('.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({
|
2017-05-01 05:54:48 +02:00
|
|
|
onclick: function (event) {
|
2012-08-20 03:25:38 +02:00
|
|
|
$('.document-list:visible').hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-08-09 08:10:50 +02:00
|
|
|
});
|
2017-05-05 05:35:39 +02:00
|
|
|
}(jQuery));
|