2016-02-12 23:52:43 +08:00
|
|
|
|
// jquery.turbolinks MUST IMMEDIATELY FOLLOW jquery inclusion
|
|
|
|
|
// turbolinks MUST BE THE LAST inclusion
|
|
|
|
|
//= require jquery
|
|
|
|
|
//= require jquery.turbolinks
|
|
|
|
|
//= require jquery_ujs
|
|
|
|
|
//= require jquery.remotipart
|
|
|
|
|
//= require jquery.mousewheel.min
|
|
|
|
|
//= require jquery.scrollTo
|
2016-11-08 20:27:19 +08:00
|
|
|
|
//= require jquery.autosize
|
2016-02-12 23:52:43 +08:00
|
|
|
|
//= require jquery-ui/widget
|
2017-09-12 15:26:22 +08:00
|
|
|
|
//= require jquery-ui/mouse
|
|
|
|
|
//= require jquery-ui/draggable
|
|
|
|
|
//= require jquery-ui/droppable
|
2016-02-12 23:52:43 +08:00
|
|
|
|
//= require jquery.ui.touch-punch.min
|
2017-01-05 19:06:59 +08:00
|
|
|
|
//= require jquery.caret.min
|
|
|
|
|
//= require jquery.atwho.min
|
2016-02-12 23:52:43 +08:00
|
|
|
|
//= require hammer
|
|
|
|
|
//= require introjs
|
|
|
|
|
//= require js.cookie
|
|
|
|
|
//= require spin
|
|
|
|
|
//= require jquery.spin
|
|
|
|
|
//= require bootstrap-sprockets
|
|
|
|
|
//= require moment
|
|
|
|
|
//= require bootstrap-datetimepicker
|
|
|
|
|
//= require bootstrap-colorselector
|
2016-07-21 19:11:15 +08:00
|
|
|
|
//= require bootstrap-tagsinput.min
|
2016-10-04 21:52:48 +08:00
|
|
|
|
//= require bootstrap-checkbox.min
|
2016-07-21 19:11:15 +08:00
|
|
|
|
//= require typeahead.bundle.min
|
2016-02-12 23:52:43 +08:00
|
|
|
|
//= require nested_form_fields
|
2017-01-19 05:40:08 +08:00
|
|
|
|
//= require highlight.pack
|
|
|
|
|
//= require tinymce-jquery
|
2016-02-12 23:52:43 +08:00
|
|
|
|
//= require_directory ./sitewide
|
2017-03-29 21:59:51 +08:00
|
|
|
|
//= require jquery.dataTables.yadcf
|
2017-01-16 22:52:02 +08:00
|
|
|
|
//= require datatables
|
2016-07-21 19:11:15 +08:00
|
|
|
|
//= require dataTables.noSearchHidden
|
2016-02-12 23:52:43 +08:00
|
|
|
|
//= require bootstrap-select
|
|
|
|
|
//= require underscore
|
|
|
|
|
//= require i18n.js
|
|
|
|
|
//= require i18n/translations
|
|
|
|
|
//= require turbolinks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize links for submitting forms. This is useful for submitting
|
|
|
|
|
// forms with clicking on links outside form in cases when other than
|
|
|
|
|
// GET method is used.
|
|
|
|
|
function initFormSubmitLinks(el) {
|
|
|
|
|
|
|
|
|
|
el = el || $(document.body);
|
|
|
|
|
$(".form-submit-link", el).click(function () {
|
|
|
|
|
var val = true;
|
|
|
|
|
if ($(this).is("[data-confirm-form]")) {
|
|
|
|
|
val = confirm($(this).data("confirm-form"));
|
|
|
|
|
}
|
|
|
|
|
// Only submit form if confirmed
|
|
|
|
|
if (val) {
|
|
|
|
|
animateLoading();
|
|
|
|
|
$("#" + $(this).data("submit-form")).submit();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Enable loading bars */
|
|
|
|
|
Turbolinks.enableProgressBar();
|
|
|
|
|
$(document)
|
|
|
|
|
.bind("ajaxSend", function(){
|
|
|
|
|
animateLoading();
|
|
|
|
|
})
|
|
|
|
|
.bind("ajaxComplete", function(){
|
|
|
|
|
animateLoading(false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Show/hide loading indicator on top of page.
|
|
|
|
|
*/
|
|
|
|
|
function animateLoading(start){
|
|
|
|
|
if (start === undefined)
|
|
|
|
|
start = true;
|
|
|
|
|
start = start !== false;
|
|
|
|
|
if (start) {
|
|
|
|
|
$("#loading-animation").addClass("animate");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$("#loading-animation").removeClass("animate");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Show/hide spinner for a given element.
|
|
|
|
|
* Shows spinner if start is true or not given, hides it if false.
|
|
|
|
|
* Optional parameter options for spin.js options.
|
|
|
|
|
*/
|
2016-08-11 22:05:23 +08:00
|
|
|
|
function animateSpinner(el, start, options) {
|
2017-06-05 20:09:04 +08:00
|
|
|
|
// If overlaying the whole page, put the spinner in the middle of the page
|
2016-07-21 19:11:15 +08:00
|
|
|
|
var overlayPage = false;
|
|
|
|
|
if (_.isUndefined(el) || el === null) {
|
|
|
|
|
overlayPage = true;
|
|
|
|
|
if ($(document.body).has('.loading-overlay-center').length === 0) {
|
|
|
|
|
$(document.body).append('<div class="loading-overlay-center" />');
|
|
|
|
|
}
|
|
|
|
|
el = $(document.body).find('.loading-overlay-center');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_.isUndefined(start)) {
|
2016-02-12 23:52:43 +08:00
|
|
|
|
start = true;
|
2016-07-21 19:11:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
|
if (start && options) {
|
|
|
|
|
$(el).spin(options);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$(el).spin(start);
|
|
|
|
|
}
|
2016-07-21 19:11:15 +08:00
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
|
if (start) {
|
2016-07-21 19:11:15 +08:00
|
|
|
|
if (overlayPage) {
|
|
|
|
|
$(document.body).append('<div class="loading-overlay" />');
|
|
|
|
|
} else {
|
|
|
|
|
$(el).append('<div class="loading-overlay" />');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2016-02-12 23:52:43 +08:00
|
|
|
|
$(".loading-overlay").remove();
|
|
|
|
|
}
|
2016-08-11 22:05:23 +08:00
|
|
|
|
}
|
2016-02-12 23:52:43 +08:00
|
|
|
|
|
2017-06-05 20:09:04 +08:00
|
|
|
|
/**
|
|
|
|
|
* Automatic handling of show/hide spinner.
|
|
|
|
|
* @param {boolean} redirection Whether page is refreshed/redirected on success
|
|
|
|
|
* @param {boolean} onElement Whether spinner is fixed on the center of fn
|
|
|
|
|
* element or it's positions on the center of whole page
|
|
|
|
|
*/
|
|
|
|
|
$.fn.animateSpinner = function(redirection, onElement) {
|
|
|
|
|
redirection = _.isUndefined(redirection) ? false : redirection;
|
|
|
|
|
onElement = _.isUndefined(onElement) ? false : onElement;
|
|
|
|
|
|
|
|
|
|
$(this)
|
|
|
|
|
.on('ajax:beforeSend', function() {
|
|
|
|
|
onElement ? animateSpinner($(this)) : animateSpinner();
|
|
|
|
|
})
|
|
|
|
|
.on('ajax:error', function(e, data) {
|
|
|
|
|
animateSpinner(null, false);
|
|
|
|
|
})
|
|
|
|
|
.on('ajax:success', function(e, data) {
|
|
|
|
|
if (!redirection) {
|
|
|
|
|
animateSpinner(null, false);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-11 22:05:23 +08:00
|
|
|
|
/*
|
2016-08-17 15:44:53 +08:00
|
|
|
|
* Prevents user from accidentally leaving page when server is busy
|
|
|
|
|
* and notifies him with a message.
|
|
|
|
|
*
|
|
|
|
|
* NOTE: Don't prevent event propagation (ev.stopPropagation()), or
|
|
|
|
|
* else all events occurring when alert is up will be ignored.
|
2016-08-11 22:05:23 +08:00
|
|
|
|
*/
|
|
|
|
|
function preventLeavingPage(prevent, msg) {
|
|
|
|
|
busy = prevent;
|
2016-08-09 20:39:24 +08:00
|
|
|
|
if (busy && !_.isUndefined(msg)) {
|
|
|
|
|
busyMsg = msg;
|
|
|
|
|
}
|
2016-02-12 23:52:43 +08:00
|
|
|
|
}
|
2016-08-11 22:05:23 +08:00
|
|
|
|
var busy = false;
|
|
|
|
|
var busyMsg = I18n.t("general.busy");
|
|
|
|
|
window.onbeforeunload = function () {
|
|
|
|
|
if (busy) {
|
|
|
|
|
var currentMsg = busyMsg;
|
|
|
|
|
// Reset to default message
|
|
|
|
|
busyMsg = I18n.t("general.busy");
|
|
|
|
|
return currentMsg;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-12 23:52:43 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Disable Firefox caching to get rid of issues with pressing
|
|
|
|
|
* browser back, like opening canvas in edit mode.
|
|
|
|
|
*/
|
2016-08-11 22:05:23 +08:00
|
|
|
|
$(window).unload(function () {
|
|
|
|
|
$(window).unbind('unload');
|
|
|
|
|
});
|
2016-02-12 23:52:43 +08:00
|
|
|
|
|
|
|
|
|
$(document.body).ready(function () {
|
|
|
|
|
// Activity feed modal in main navigation menu
|
|
|
|
|
var activityModal = $('#activity-modal');
|
|
|
|
|
var activityModalBody = activityModal.find('.modal-body');
|
|
|
|
|
|
|
|
|
|
var initMoreBtn = function () {
|
|
|
|
|
activityModalBody.find('.btn-more-activities')
|
|
|
|
|
.on('ajax:success', function (e, data) {
|
|
|
|
|
$(data.html).insertBefore($(this).parents('li'));
|
|
|
|
|
$(this).attr('href', data.next_url);
|
|
|
|
|
if (data.activities_number < data.per_page) {
|
|
|
|
|
$(this).remove();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2016-08-19 19:08:35 +08:00
|
|
|
|
notificationAlertClose();
|
2016-02-12 23:52:43 +08:00
|
|
|
|
|
|
|
|
|
$('#main-menu .btn-activity')
|
|
|
|
|
.on('ajax:before', function () {
|
|
|
|
|
activityModal.modal('show');
|
|
|
|
|
})
|
|
|
|
|
.on('ajax:success', function (e, data) {
|
|
|
|
|
activityModalBody.html(data.html);
|
|
|
|
|
initMoreBtn();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
activityModal.on('hidden.bs.modal', function () {
|
|
|
|
|
activityModalBody.html('');
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-07-21 19:11:15 +08:00
|
|
|
|
|
2016-08-19 16:48:43 +08:00
|
|
|
|
$(document).ajaxComplete(function(){
|
2016-08-19 19:08:35 +08:00
|
|
|
|
notificationAlertClose();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function notificationAlertClose(){
|
2016-08-19 16:48:43 +08:00
|
|
|
|
$("#notifications .alert").on("closed.bs.alert", function () {
|
|
|
|
|
$("#content-wrapper")
|
|
|
|
|
.addClass("alert-hidden")
|
|
|
|
|
.removeClass("alert-shown");
|
|
|
|
|
});
|
2016-08-19 19:08:35 +08:00
|
|
|
|
}
|
2016-12-28 21:52:03 +08:00
|
|
|
|
var HelperModule = (function(){
|
2016-08-19 16:48:43 +08:00
|
|
|
|
|
2016-12-28 21:52:03 +08:00
|
|
|
|
var helpers = {};
|
|
|
|
|
|
|
|
|
|
helpers.treeLinkTruncation = function() {
|
2016-11-11 19:30:48 +08:00
|
|
|
|
$('.tree-link a').each( function(){
|
|
|
|
|
truncateLongString( $(this), <%= Constants::NAME_TRUNCATION_LENGTH %>);
|
|
|
|
|
});
|
|
|
|
|
$(".tree-link span").each( function(){
|
|
|
|
|
truncateLongString( $(this), <%= Constants::NAME_TRUNCATION_LENGTH %>);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-28 21:52:03 +08:00
|
|
|
|
helpers.hideFlashMsg = function() {
|
2016-11-11 19:30:48 +08:00
|
|
|
|
var flash = $('.alert');
|
|
|
|
|
if (flash.length > 0) {
|
|
|
|
|
window.setTimeout(function () {
|
|
|
|
|
flash.fadeTo(500, 0).slideUp(500, function () {
|
|
|
|
|
$(this).remove();
|
2017-01-09 20:55:50 +08:00
|
|
|
|
if($('.alert').length <= 0) {
|
|
|
|
|
$('#content-wrapper').removeClass('alert-shown');
|
|
|
|
|
}
|
2016-11-11 19:30:48 +08:00
|
|
|
|
});
|
|
|
|
|
}, 5000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-18 00:56:58 +08:00
|
|
|
|
helpers.flashAlertMsg = function(message, type) {
|
|
|
|
|
var alertType;
|
|
|
|
|
var glyphSign;
|
|
|
|
|
$('#notifications').html('');
|
|
|
|
|
if (type === 'success') {
|
|
|
|
|
alertType = ' alert-success ';
|
|
|
|
|
glyphSign = ' glyphicon-ok-sign ';
|
|
|
|
|
} else if (type === 'danger') {
|
|
|
|
|
alertType = ' alert-danger ';
|
|
|
|
|
glyphSign = ' glyphicon-exclamation-sign ';
|
2017-03-28 21:14:05 +08:00
|
|
|
|
} else if (type === 'info') {
|
|
|
|
|
alertType = ' alert-info ';
|
|
|
|
|
glyphSign = ' glyphicon-exclamation-sign ';
|
2017-03-18 00:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
var htmlSnippet = '<div class="alert alert' + alertType +
|
|
|
|
|
'alert-dismissable alert-floating">' +
|
|
|
|
|
'<div class="container">' +
|
|
|
|
|
'<button type="button" class="close" ' +
|
|
|
|
|
'data-dismiss="alert" aria-label="Close">' +
|
|
|
|
|
'<span aria-hidden="true">×</span></button>' +
|
|
|
|
|
'<span class="glyphicon' + glyphSign + '"></span>' +
|
|
|
|
|
'<span>' + message + '</span>' +
|
|
|
|
|
'</div>' +
|
|
|
|
|
'</div>';
|
|
|
|
|
$('#notifications').html(htmlSnippet);
|
|
|
|
|
$('#content-wrapper').addClass('alert-shown');
|
|
|
|
|
helpers.hideFlashMsg();
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-11 19:30:48 +08:00
|
|
|
|
$( document ).ready(function() {
|
2016-12-28 21:52:03 +08:00
|
|
|
|
helpers.treeLinkTruncation();
|
|
|
|
|
helpers.hideFlashMsg();
|
2016-08-30 19:51:16 +08:00
|
|
|
|
});
|
2016-12-28 21:52:03 +08:00
|
|
|
|
|
|
|
|
|
return helpers;
|
2016-11-11 19:30:48 +08:00
|
|
|
|
})();
|
2017-01-19 05:40:08 +08:00
|
|
|
|
|
2017-01-19 19:54:48 +08:00
|
|
|
|
// initialize code markup in rich text fields
|
2017-01-19 05:40:08 +08:00
|
|
|
|
(function() {
|
|
|
|
|
$(document).ready(function() {
|
2017-01-20 00:09:25 +08:00
|
|
|
|
$('[class^=language]').each(function(i, block) {
|
2017-01-19 05:40:08 +08:00
|
|
|
|
hljs.highlightBlock(block);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
})();
|