scinote-web/app/assets/javascripts/experiments/dropdown_actions.js
Zmago Devetak 9dc7708b73 Merge pull request #85 from ZmagoD/zd_SCI_360
fixes project overview style and add no description link [fixes SCI-360]
2016-08-23 16:24:22 +02:00

68 lines
1.9 KiB
JavaScript

(function(){
// Create ajax hook on given 'element', which should return modal with 'id' =>
// show that modal
function initializeModal(element, id){
$(element)
.on("ajax:beforeSend", function(){
animateSpinner();
})
.on("ajax:success", function(e, data){
$('body').append($.parseHTML(data.html));
$(id).modal('show',{
backdrop: true,
keyboard: false,
});
})
.on("ajax:error", function() {
animateSpinner(null, false);
// TODO
})
.on("ajax:complete", function(){
animateSpinner(null, false);
});
}
// Initialize dropdown actions on experiment:
// - edit
// - clone
function initializeDropdownActions(){
// { buttonClass: modalName } mappings
// click on buttonClass summons modalName dialog
modals = {
'.edit-experiment': '#edit-experiment-modal-',
'.clone-experiment': '#clone-experiment-modal-',
'.move-experiment': '#move-experiment-modal-'
};
$.each($(".dropdown-experiment-actions"), function(){
var $dropdown = $(this);
$.each(modals, function(buttonClass, modalName) {
var id = modalName + $dropdown.data('id');
initializeModal($dropdown.find(buttonClass), id);
});
});
}
// Initialize no description edit link
function initEditNoDescription(){
var modal = "#edit-experiment-modal-";
$.each($(".no-description-experiment"), function(){
var id = modal + $(this).data("id");
initializeModal($(this), id);
});
}
// Bind modal to new-experiment action
initializeModal($("#new-experiment"), '#new-experiment-modal');
// Bind modal to big-plus new experiment actions
initializeModal('.big-plus', '#new-experiment-modal');
// Bind modal to all actions listed on dropdown accesible from experiment
// panel
initializeDropdownActions();
// init
initEditNoDescription();
})();