mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-06 12:43:06 +08:00
Add missing dropdown_actions.js
This commit is contained in:
parent
a29b56b0bd
commit
c16eed5e63
1 changed files with 54 additions and 0 deletions
54
app/assets/javascripts/experiments/dropdown_actions.js
Normal file
54
app/assets/javascripts/experiments/dropdown_actions.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
|
||||
(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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Bind modal to new-experiment action
|
||||
initializeModal($("#new-experiment"), '#new-experiment-modal');
|
||||
|
||||
// Bind modal to all actions listed on dropdown accesible from experiment
|
||||
// panel
|
||||
initializeDropdownActions();
|
||||
})();
|
Loading…
Reference in a new issue