Untitled
unknown
plain_text
2 years ago
24 kB
9
Indexable
$(document).ready(function () {
displayAlertBoxes();
displayLogoutTime();
$('.filter').each(function() {
var that = this;
var filters = $('.filters', this);
if (!Foundation.utils.is_large_up() && !$(that).hasClass('expanded')) {
filters.hide();
}
$('.toggleFilter', that).on('click', function() {
filters.slideToggle('fast', function() {
$(that).toggleClass('expanded');
});
});
});
initFormInputs();
var $tabs = $('.slicker-tabs');
var toggleSlick = function() {
if (Foundation.utils.is_large_up()
&& $tabs.hasClass('slick-initialized')
) {
$tabs.slick('unslick');
} else if (!Foundation.utils.is_large_up()
&& !$tabs.hasClass('slick-initialized')
) {
$tabs.slick({
arrows: false,
infinite: false,
initialSlide: $('.tabControl .tab.current').index(),
adaptiveHeight: true,
touchThreshold: 1.65 // ~60% tab width to swipe
});
$tabs.off('afterChange');
$tabs.on('afterChange', function(event, slick, currentSlide){
var $curr = $(slick.$slides.get(currentSlide));
if ($curr.data('loaded') === 1) {
return;
}
var request = $.nette.ajax({
beforeSend: function() {
$('.slicker-tabs .slick-list').finish();
$curr.find('.content').html('<i class="fa fa-spinner fa-4x fa-spin"></i>');
$('.slicker-tabs .slick-list').height($('.slicker-tabs .slick-active').outerHeight(true));
},
method: "POST",
url: $curr.data('url'),
dataType: "html"
});
request.done(function(response) {
try {
data = JSON.parse(response);
} catch (err) {
data = { 'html' : response };
}
if (data.redirect) {
displayAlertBox('warning',
'Session timeout, you have been logged out. Please <a href="'+data.redirect+'">sign in</a>.');
return;
}
$curr.find('.content').html(data.html);
// reinit form controls
initFormInputs();
$('.spinner').spinner();
$('table.responsive').each(function() {
if (!$(this).parent().hasClass('scrollable')) {
$(this).trigger('redraw');
}
});
$('.slicker-tabs .slick-list').animate({
height: $('.slicker-tabs .slick-active').outerHeight(true) + 'px'
}, 400);
$curr.data('loaded', 1);
});
request.fail(function(jqXHR, textStatus) {
displayAlertBox('error', 'Ups, something went wrong.');
});
});
}
};
$(window).resize(toggleSlick);
toggleSlick();
$( '.tagsInput' ).each( function() {
var valueField = $(this).data( 'attr-value' ) ? $(this).data( 'attr-value' ) : 'id';
var textField = $(this).data( 'attr-text' ) ? $(this).data( 'attr-text' ) : 'name';
var newElements = $(this).data( 'disable-new' ) == 1 ? false : true;
$( this ).tokenize({
datas: '?do=tags',
valueField: valueField,
textField: textField,
displayDropdownOnFocus: true,
debounce: 300,
newElements: newElements
});
} );
$( '#globalSearchInput' ).easyAutocomplete({
url: function(phrase) {
return $( '#globalSearchInput' ).data( 'url' );
},
getValue: function(element) {
return element.name;
},
adjustWidth: false,
ajaxSettings: {
dataType: "json",
method: "POST",
data: {
dataType: "json"
}
},
preparePostData: function(data) {
data.phrase = $( '#globalSearchInput' ).val();
return data;
},
requestDelay: 400,
template: {
type: "custom",
method: function(value, element) {
var icon = '';
if( element.type == 'P' ) {
icon = '<i class="fa fa-file-powerpoint-o"></i> ';
} else if( element.type == 'D' ) {
icon = '<i class="fa fa-file-code-o"></i> ';
}
return "<a href='" + element.link + "' >" + icon + value + "</a>";
}
}
});
var userNotifications = $( "#userNotifications > a > i" );
if( userNotifications.length ) {
$( '<span id="userNotificationCount" />' ).appendTo( userNotifications );
updateUsernotificationCount();
setInterval( updateUsernotificationCount, 5000 );
}
});
function updateUsernotificationCount() {
var userNotificationCount = $( '#userNotificationCount' );
$.ajax( {
url: '?do=countNotifications',
success: function( data ) {
if( data.count > 0 ) {
userNotificationCount.html( data.count );
if( !userNotificationCount.hasClass( 'nonempty' ) ) {
userNotificationCount.addClass( 'nonempty' );
}
} else {
userNotificationCount.html( '' );
userNotificationCount.removeClass( 'nonempty' );
}
}
} );
}
function confirmDeleteFile(name) {
return confirm("Are you sure you want to delete file "+name+"?");
}
function confirmFinalizeProtocol() {
return confirm("Protocol will be locked and cannot be modified. Continue?");
}
/**
* Init all form inputs
* Function is called on document ready
*/
function initFormInputs() {
initFancyInputs();
initDropDowns($('select:not(.multiselect):not(.tagsInput):not(.treeMultiselect):not(.treeMultiselectTwo):visible'));
$( 'select.treeMultiselect' ).each( function() {
var that = $( this );
var option = {
enableSelectAll: false,
sortable: false,
startCollapsed: true,
allowBatchSelection: false,
onlyBatchSelection: false,
hideSidePanel: false,
};
if( that.hasClass( 'treeOnlyOneSelect' ) )
{
option.hideSidePanel = true;
option.onChange = function( allSelectedItems, addedItems, removedItems ) {
var $i = -1;
if ( allSelectedItems[ 1 ] )
{
$( allSelectedItems ).each( function() {
$i = $i + 1;
$( 'div[ data-key="'+allSelectedItems[ $i ].id+'" ] > input', that.parent() ).click ();
});
$( 'div[ data-key="'+allSelectedItems[$i].id+'" ] > input', that.parent() ).click ();
}
};
}
that.treeMultiselect( option );
if( that.hasClass( 'treeOnlyOneSelect' ) )
{
$( ".selections" ).css( "width", "100%" );
}
if( that.hasClass( 'treeGenesisSelect' ) )
{
$( ".tree-multiselect" ).height( 500 ).css({
});
}
});
$('select.multiselect').each(function() {
$(this).multiSelect();
});
$('input.datepicker').each(function(){
var pickTime = $(this).data('date-picktime');
$(this).fdatepicker({
weekStart: 1,
pickTime: pickTime
});
});
var prepareControlWebLink = function(control) {
var link = $('input', control).val();
link = link.replace( /^https?:\/\//gi, '' );
if( link == '' ) {
link = '#';
} else {
link = '//' + link;
}
$( 'a.postfix', control ).attr( 'href', link );
};
$('.controlWebLink').each( function() {
var that = this;
prepareControlWebLink(that);
$( 'input', that ).on( 'keyup', function() {
prepareControlWebLink(that);
});
});
$('.controlProtocolLink').each( function() {
var that = this;
var link = $( '.postfix', that );
$( 'select', that ).on( 'change', function() {
var protocolQRCode = $( '.protocolQRCode', that );
if( $(this).val() != 0 )
{
var text = encodeURI( $('option:selected', this).text() ) + '-';
protocolQRCode.attr( 'src', protocolQRCode.data('src') + text );
link.attr( 'href', link.data('href') + $(this).val() );
link.attr( 'target', '_blank' );
}
else
{
protocolQRCode.attr( 'src', '' );
link.attr( 'href', '#' );
link.attr( 'target', '' );
}
});
});
$('.accordion').each(function(){
var accordion = this;
$('.accordionTab', accordion).off('click');
$('.accordionTab', accordion).on('click', function(){
if (Foundation.utils.is_large_up()) {
if (!$(this).hasClass('current')) {
$('.accordionContent.opened', accordion).hide().removeClass('opened');
$('.accordionTab.current', accordion).removeClass('current');
$('.accordionContent-'+$(this).data('content'), accordion).show().addClass('opened');
$('.accordionTab[data-content='+$(this).data('content')+']').addClass('current');
initDropDowns($('select:not(.multiselect):visible', accordion));
}
} else {
if (!$(this).hasClass('current')) {
$('.accordionContent.opened', accordion).hide().removeClass('opened');
$('.accordionTab.current', accordion).removeClass('current');
$('.accordionContent-'+$(this).data('content'), accordion).show().addClass('opened');
$('.slicker-tabs .slick-list').animate({
height: $('.slicker-tabs .slick-active').outerHeight(true) + 'px'
}, 400);
$('.accordionTab[data-content='+$(this).data('content')+']').addClass('current');
initDropDowns($('select:not(.multiselect):visible', accordion));
} else {
$('.accordionContent.opened', accordion).hide().removeClass('opened');
$('.accordionTab.current', accordion).removeClass('current');
$('.slicker-tabs .slick-list').height($('.slicker-tabs .slick-active').outerHeight(true));
}
}
});
});
$('.richTextEditor').each(function() {
if ($(this).css('display') != 'none') {
CKEDITOR.replace(this);
}
});
// Init protocol files upload
$('#fileUploadCaptureImageButton').off('click touch touchstart start');
$('#fileUploadCaptureImageButton').on('click touch touchstart start', function(e){
if ($(e.target).is('input[type="file"]')) {
return;
}
$('#fileUploadCaptureImageInput').attr('data-button', 'fileUploadCaptureImageButton');
$('#fileUploadCaptureImageInput').click();
});
$('#fileUploadButton').off('click touch touchstart start');
$('#fileUploadButton').on('click touch touchstart start', function(e){
if ($(e.target).is('input[type="file"]')) {
return;
}
$('#fileUploadInput').attr('data-button', 'fileUploadButton');
$('#fileUploadInput').click();
});
$('#dirUploadButton').off('click touch touchstart start');
$('#dirUploadButton').on('click touch touchstart start', function(e){
if ($(e.target).is('input[type="file"]')) {
return;
}
$('#dirUploadInput').attr('data-button', 'dirUploadButton');
$('#dirUploadInput').click();
});
$(function () {
'use strict';
/**
* Abort uploading of protocol files
*/
function abortUpload(dataInAbort)
{
if( dataInAbort === null || typeof dataInAbort.abort !== "function" ) {
return;
}
dataInAbort.abort();
$('#progress .progress-meter').css( 'width', 0 ).html('');
$(this).addClass('invisible');
}
/**
* Set relativeFilePaths for directory upload
*/
function startUpload(fileUploadInput, data)
{
if( typeof data.submit !== "function" ) {
return;
}
// Get a relative file path of files in the uploaded directory
let relativeFilePaths = '';
if(data.files) {
for (let i = 0; i < data.files.length; i++) {
// Append the current file path to the relativeFilePaths variable
// (delimited by tripple hash signs - ###)
if(data.files[i].webkitRelativePath !== undefined) {
relativeFilePaths += data.files[i].webkitRelativePath + '###';
} else {
relativeFilePaths += '';
}
}
}
// Set the relativeFilePaths to the data which is sent to the backend
// HTTP requests do not natively carry the relative path data,
// so it must be added to the request manually.
data.formData = {relativeFilePaths: relativeFilePaths};
// Set data to .fileUploadInput which has been clicked and show abort button
fileUploadInput.data(data);
$('#fileUploadAbortButton')
.removeClass('invisible')
.on('click', function(){
abortUpload(data);
});
data.submit();
}
// jQuery File Upload init (submit and callbacks)
$('.fileUploadInput').each(function() {
var fileUploadInput = $(this);
var returnUrl = fileUploadInput[0].dataset.returnurl ? fileUploadInput[0].dataset.returnurl : window.location.pathname;
$(this).fileupload({
url: $(this).data('url'),
dataType: 'json',
autoUpload: false,
singleFileUploads: true,
maxFileSize: 2 * 1024 * 1024 * 1024,
maxChunkSize: 10 * 1024 * 1024,
maxNumberOfFiles: 1000,
messages: {
maxFileSize: 'File exceeds maximum allowed size of 2GB',
maxNumberOfFiles: 'Maximum number of uploaded files is 1000 files'
}
}).on('fileuploadadd', function (e, data) {
if(fileUploadInput[0].files.length > 1000)
{
displayAlertBox('error', 'Maximum number of uploaded files is 1000 files, you have chosen ' + fileUploadInput[0].files.length
+ ". Please split your files into more groups.'");
fileUploadInput[0].files = [];
}
else
{
startUpload(fileUploadInput, data);
}
}).on('fileuploadprocessalways', function (e, data) {
var index = data.index,
file = data.files[index],
fireButton = '#'+$(this).attr('data-button');
if (file.error) {
displayAlertBox( 'error', file.error );
}
if (index + 1 === data.files.length) {
$(fireButton).prop('disabled', !!data.files.error);
$('#progress .progress-meter').text('Uploading... 0%');
}
}).on('fileuploadprogressall', function (e, data) {
$('#progress.invisible').removeClass('invisible');
var progress = parseInt(data.loaded / data.total * 99.9, 10);
$('#progress .progress-meter')
.css( 'width', progress + '%' )
.text('Uploading... ' + progress + ' %');
}).on('fileuploaddone', function (e, data) {
$('#progress').addClass('invisible');
$('#fileUploadAbortButton').addClass('invisible');
$.each(data.result.files, function (index, file) {
if (file.url) {
displayAlertBox('success', 'File "' + file.name + '" has been successfully saved');
} else if (file.error) {
console.log(file.error);
displayAlertBox('error', 'File "' + file.name + '": ' + file.error);
}
});
}).on('fileuploadfail', function (e, data) {
var fireButton = '#' + $(this).attr('data-button');
$('#progress').addClass('invisible');
$('#fileUploadAbortButton').addClass('invisible');
$(fireButton).on('click touch touchstart start', function(e){
$(this).click();
});
displayAlertBox( 'error', 'File upload failed' );
}).on('fileuploadstop', function (e, data) {
// when all files are uploaded
window.location = returnUrl;
}).prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled');
});
});
// Init enable controls
var controls = {};
$( "input:checkbox[data-nette-rules], input:radio[data-nette-rules]" ).each( function() {
var rules = eval('[' + $(this).attr( 'data-nette-rules' ) + ']');
rules = rules.pop();
for( i = 0 ; i < rules.length ; i++ )
{
var rule = rules[i];
if( rule.toggle )
{
if( !controls[ rule.control ] )
{
controls[ rule.control ] = {};
}
if( !controls[ rule.control ][ rule.arg ] )
{
controls[ rule.control ][ rule.arg ] = [];
}
controls[ rule.control ][ rule.arg ].push( Object.keys( rule.toggle ).pop() );
}
}
});
$( "input:checkbox[readonly], input:radio[readonly]" ).each( function() {
// checkbox and radio input should have 'disabled' attribute, not 'readonly' attribute
// if 'disabled' attribute is set in ProtocolFormFactory (when form is rendered), the input is not submitted
$(this).attr( 'readonly', false );
$(this).attr( 'disabled', true );
});
for( var key in controls )
{
// on.change of parent input: set target input to disabled/readonly
$( '[name="' + key + '"]' ).on( 'change', function() {
var input = $(this),
value = input.val(),
name = input.attr( 'name' );
if( input.is( ':radio' ) )
{
for( var arg in controls[ name ] )
{
// iterate through target inputs
for( i = 0 ; i < controls[ name ][ arg ].length ; i++ )
{
// 'target' is input, which is controlled by parent input
var target = $( '[name="' + controls[ name ][ arg ][ i ] + '"]' );
// checkbox and radio input should have 'disabled' attribute, not 'readonly' attribute
if( target.is(':checkbox') || target.is( ':radio' )) {
target.attr( 'disabled', true );
target.parent().addClass('readonly');
} else {
target.attr( 'readonly', true );
}
if( target.is( 'select' ) )
{
target.heapbox( 'disable' );
}
else if( target.hasClass( "richTextEditor" ) )
{
CKEDITOR.instances[ target.attr( 'id' ) ].setReadOnly( true );
}
}
}
}
if( controls[ name ][ value ] )
{
// iterate through target inputs
for( i = 0 ; i < controls[ name ][ value ].length ; i++ )
{
var isChecked = input.is( ':checked' );
// 'target' is input, which is controlled by parent input
var target = $( '[name="' + controls[ name ][ value ][ i ] + '"]' );
// checkbox and radio input should have 'disabled' attribute, not 'readonly' attribute
if( target.is(':checkbox') || target.is( ':radio' )) {
target.attr( 'disabled', !isChecked );
if(isChecked) {
target.parent().removeClass('readonly');
} else {
target.parent().addClass('readonly');
}
} else {
target.attr( 'readonly', !isChecked );
}
if( target.is( 'select' ) )
{
heapboxAction = 'disable';
if( isChecked )
{
heapboxAction = 'enable';
}
target.heapbox( heapboxAction );
}
else if( target.hasClass( "richTextEditor" ) )
{
CKEDITOR.instances[ target.attr( 'id' ) ].setReadOnly( !isChecked );
}
}
}
if( input.is( ':checkbox' ) )
{
$( '[name="' + name + '"]:checked' ).each( function() {
value = $(this).val();
if( controls[ name ][ value ] )
{
// iterate through target inputs
for( i = 0 ; i < controls[ name ][ value ].length ; i++ )
{
// 'target' is input, which is controlled by parent input
var target = $( '[name="' + controls[ name ][ value ][ i ] + '"]' );
// checkbox and radio input should have 'disabled' attribute, not 'readonly' attribute
if( target.is(':checkbox') || target.is( ':radio' )) {
target.attr( 'disabled', false );
target.parent().removeClass('readonly');
} else {
target.attr( 'readonly', false );
}
if( target.is( 'select' ) )
{
target.heapbox( 'enable' );
}
else if( target.hasClass( "richTextEditor" ) )
{
CKEDITOR.instances[ target.attr( 'id' ) ].setReadOnly( false );
}
}
}
} );
}
} );
}
}
function initDropDowns($elements) {
$elements.each(function () {
var select = $(this);
$(this).heapbox({
'effect': {
'speed': 'fast'
},
'heapsize': 300,
'onChange':function(val, elm) {
elm.trigger('change');
select.siblings( 'input[ type=text ]' ).hide();
select.siblings( 'input[ type=text ]' ).val(val);
},
'openStart':function(){
if( select.data( 'editable' ) == "1" )
{
select.siblings( 'input[ type=text ]' ).show();
select.siblings( 'input[ type=text ]' ).focus();
}
},
'closeComplete':function(){
if( select.data( 'editable' ) == "1" )
{
select.siblings('input[ type=text ]').hide();
}
},
});
if ($(this).attr('readonly')) {
$(this).heapbox('disable');
}
});
}
// create alert box and display it
function displayAlertBox(type, message) {
var $alert = createAlertBox(type, message);
$('#alert-box-container').append($alert);
$alert.show();
$(document).foundation('alert', 'reflow');
setTimeout(function(){
$alert.fadeOut('slow', function() {
$alert.remove();
});
}, 8000);
}
// create alert box element
function createAlertBox(type, message) {
return $("<div data-alert class=\"alert-box " + type + "\">"
+ message
+ "<a href=\"#\" class=\"close\">×</a></div>");
}
// method for image deletion confirmation
function processControlImage(form, imgName) {
if (imgName == '' || confirm("Are you sure you want to replace image "+imgName+"?")) {
form.submit();
}
}
// method for image deletion confirmation
function processControlImage_SimulateSubmitClick(imgName, submitButtonName) {
if (imgName == '' || confirm("Are you sure you want to replace image "+imgName+"?")) {
$("input[type='submit'][name='_" + submitButtonName + "']").click();
}
}
// bind alert box displaying on snippet redraw
$.nette.ext('snippets').complete( displayAlertBoxes );
// display alert boxes stored in container
function displayAlertBoxes() {
$('#alert-box-container .alert-box').each(function () {
var that = this;
$(that).show();
$(document).foundation('alert', 'reflow');
setTimeout(function(){
$(that).fadeOut('slow', function() {
$(that).remove();
});
}, 8000);
});
}
function getPermissionInfoTable( accessLevel )
{
table = $( '<table/>' );
row = $( '<tr/>' );
$( '<td colspan="2"/>' ).html( 'Share to others' ).appendTo( row );
$( '<td/>' ).html( accessLevel > 6 ? 'Master' : accessLevel > 3 ? 'Guest' : '-' ).appendTo( row );
row.appendTo( table );
row = $( '<tr/>' );
$( '<td/>' ).appendTo( row );
$( '<td/>' ).html( 'Read' ).appendTo( row );
$( '<td/>' ).html( 'Write' ).appendTo( row );
row.appendTo( table );
row = $( '<tr/>' );
$( '<td/>' ).html( 'General info' ).appendTo( row );
$( '<td class="text-center"/>' ).html( accessLevel > 0 ? '+' : '-' ).appendTo( row );
$( '<td class="text-center"/>' ).html( accessLevel > 3 ? '+' : '-' ).appendTo( row );
row.appendTo( table );
row = $( '<tr/>' );
$( '<td/>' ).html( 'Metadata' ).appendTo( row );
$( '<td class="text-center"/>' ).html( accessLevel > 1 ? '+' : '-' ).appendTo( row );
$( '<td class="text-center"/>' ).html( accessLevel > 4 ? '+' : '-' ).appendTo( row );
row.appendTo( table );
row = $( '<tr/>' );
$( '<td/>' ).html( 'Data files' ).appendTo( row );
$( '<td class="text-center"/>' ).html( accessLevel > 2 ? '+' : '-' ).appendTo( row );
$( '<td class="text-center"/>' ).html( accessLevel > 5 ? '+' : '-' ).appendTo( row );
row.appendTo( table );
return table;
}
$(document).ready(function() {
$('.qtipTitle').qtip({
content: {
text: function(event, api) {
return $(this).attr("title");
}
},
position: {
viewport: $(window)
},
style: {
classes: 'qtip-bootstrap qtip-shadow'
}
});
$('.permissionSelect strong').qtip({
content: {
title: function(event, api) {
return $(this).html();
},
text: function(event, api) {
return getPermissionInfoTable( $(this).closest( '.permissionSelect' ).attr( 'rel' ) );
}
},
hide: {
event: 'click mouseleave'
},
position: {
viewport: $(window)
},
style: {
classes: 'qtip-bootstrap qtip-shadow'
}
});
});
var logoutInterval;
function displayLogoutTime()
{
var logoutTimeBase = $( "#logoutTime" );
if( logoutTimeBase.length )
{
var logoutTime = parseInt( logoutTimeBase.text() );
clearInterval( logoutInterval );
if( !$( "#logoutTimeBox" ).length ) {
$( "#logout > a" ).append( $( '<span id="logoutTimeBox"></span>' ) );
}
logoutInterval = setInterval(function() {
logoutTime = logoutTime - 1;
if( logoutTime < 0 ) {
clearInterval( logoutInterval );
window.location.href = $( "#logout > a" ).attr( "href" );
return;
}
logoutTimeMinutes = parseInt( logoutTime / 60 );
logoutTimeSeconds = logoutTime % 60;
$( "#logoutTimeBox" ).html( addZero( logoutTimeMinutes ) + ":" + addZero( logoutTimeSeconds ) );
}, 1000);
}
}
function addZero( num )
{
if( num < 10 )
{
num = "0" + num;
}
return num;
}
Editor is loading...
Leave a Comment