e62ebb05ba
* Mass Edit MOD api JS (WIP) In continuity with the mass edit mod api, this is the javascript use of it. ##What does it do? * Delete of multiple torrents on index/search * Category change of multiple torrents * Change of owner of multiple torrents * Lock & delete of multiple torrents ##How? * New toolbar only visible for mods * Checkboxes added only for mods * Selection and click on the button in toolbar * Nothing is submitted, you have to review the changes in a modal window listing them. * Then the ajax queries are initialized one at a time with a progression bar * You can always at any moment delete entries from the queuing list * Improved progress bar * Deleting part almost done Improved modal design All dom interactions should be done Prepared Query for only one callback Improved Modal to keep a link to the active modal * Finished =D Added some translation string * Forgot the refreshing of the page Just an option that can be disabled by making refreshTimeout to 0
84 lignes
Pas d'EOL
3,1 Kio
JavaScript
84 lignes
Pas d'EOL
3,1 Kio
JavaScript
// Get the modal
|
|
var Modal = {
|
|
active: 0,
|
|
Init: function (params) {
|
|
var elements = params.elements
|
|
var button = (params.button != undefined) ? params.button : false
|
|
if (elements.innerHTML != undefined) {
|
|
|
|
} else {
|
|
var nbEl = elements.length
|
|
for (var i=0; i < nbEl; i++) {
|
|
var modal = elements[i];
|
|
this.addModal(modal, button, i, params.before, params.after, params.close)
|
|
}
|
|
}
|
|
},
|
|
addModal: function(modal, btn, i, before_callback, after_callback, close_callback) {
|
|
var isBtnArray = false;
|
|
// Get the button that opens the modal
|
|
if (!btn) {
|
|
btn = document.getElementById("modal_btn_"+modal.id)
|
|
} else if (btn.match(/^#/)) {
|
|
btn = document.getElementById(btn.substr(1));
|
|
} else if (btn.match(/^\./)) {
|
|
btn = document.getElementsByClassName(btn.substr(1));
|
|
isBtnArray = true;
|
|
} else {
|
|
console.error("Couldn't find the button")
|
|
return
|
|
}
|
|
if ((isBtnArray) && (i > 0) && (btn.length > 0) && (btn.length > i)) {
|
|
btn[i].addEventListener("click", function(e) {
|
|
if (before_callback != undefined) before_callback()
|
|
modal.style.display = "block";
|
|
Modal.active = modal;
|
|
if (after_callback != undefined) after_callback()
|
|
e.preventDefault();
|
|
});
|
|
} else {
|
|
btn = (isBtnArray) ? btn[0] : btn;
|
|
// When the user clicks on the button, open the modal
|
|
btn.addEventListener("click", function(e) {
|
|
if (before_callback != undefined) before_callback()
|
|
modal.style.display = "block";
|
|
Modal.active = modal;
|
|
if (after_callback != undefined) after_callback()
|
|
e.preventDefault();
|
|
});
|
|
}
|
|
// Get the <span> element that closes the modal
|
|
var span = document.querySelectorAll("#"+modal.id+" .close")[0]
|
|
// When the user clicks on <span> (x), close the modal
|
|
span.addEventListener("click", function(e) {
|
|
modal.style.display = "none";
|
|
Modal.active = 0;
|
|
if (close_callback != undefined) close_callback()
|
|
e.preventDefault();
|
|
});
|
|
// When the user clicks anywhere outside of the modal, close it
|
|
window.addEventListener("click", function(event) {
|
|
if (event.target == modal) {
|
|
modal.style.display = "none";
|
|
Modal.active = 0;
|
|
if (close_callback != undefined) close_callback()
|
|
}
|
|
});
|
|
},
|
|
CloseActive: function() {
|
|
if (this.active != 0) {
|
|
this.active.style.display= "none";
|
|
this.active = 0;
|
|
}
|
|
},
|
|
GetActive: function() {
|
|
return this.active;
|
|
},
|
|
Open: function(q) {
|
|
var modal = document.querySelector(q);
|
|
if (modal != undefined) {
|
|
modal.style.display= "none";
|
|
this.active = modal;
|
|
}
|
|
}
|
|
}; |