Commit cdabbf1e authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Files selected: use checkbox instead of buttons

parent e24aac1d
...@@ -5,6 +5,11 @@ ...@@ -5,6 +5,11 @@
var selectedFiles; var selectedFiles;
var updateNbFilesSelected = function() {
var nbFiles = selectedFiles.length;
$(".fileDialogDialog .ui-dialog-buttonpane .nbFiles").html(nbFiles + " file" + (nbFiles == 1 ? "" : "s") + " selected.");
}
self.exec = function(fillFunction, multiple) { self.exec = function(fillFunction, multiple) {
selectedFiles = []; selectedFiles = [];
$("#fileDialog").remove(); //Remove old instance $("#fileDialog").remove(); //Remove old instance
...@@ -32,8 +37,8 @@ ...@@ -32,8 +37,8 @@
selectedFiles.splice(fileIndex, 1); selectedFiles.splice(fileIndex, 1);
} }
} }
var nbFiles = selectedFiles.length; updateNbFilesSelected();
$(".fileDialogDialog .ui-dialog-buttonpane .nbFiles").html(nbFiles + " file" + (nbFiles == 1 ? "" : "s") + " selected.");
}); });
$(dom).dialog({ $(dom).dialog({
title: multiple ? "Choose files" : "Choose one file", title: multiple ? "Choose files" : "Choose one file",
...@@ -77,10 +82,10 @@ ...@@ -77,10 +82,10 @@
if (selectedFiles.length > 0) { if (selectedFiles.length > 0) {
$("#filesSelected").remove(); $("#filesSelected").remove();
$("body").append("<div id='filesSelected'>"); $("body").append("<div id='filesSelected'>");
var selectedHtml = ""; var selectedHtml = "<label class='checkAll'><input class='checkAll' type='checkbox'/> Check all</label>";
for (var f = 0; f < selectedFiles.length; f++) { for (var f = 0; f < selectedFiles.length; f++) {
var file = selectedFiles[f]; var file = selectedFiles[f];
selectedHtml += "<label rel='" + file + "' class='labelBlock'><input rel='" + file + "' type='checkbox'/> " + file + "</label>"; selectedHtml += "<label rel='" + file + "' class='labelBlock'><input rel='" + file + "' type='checkbox' class='files'/> " + file + "</label>";
} }
$("#filesSelected").html(selectedHtml); $("#filesSelected").html(selectedHtml);
$("#filesSelected").dialog({ $("#filesSelected").dialog({
...@@ -90,24 +95,15 @@ ...@@ -90,24 +95,15 @@
dialogClass: "filesSelectedDialog", dialogClass: "filesSelectedDialog",
buttons: [ buttons: [
{ {
text: "Check all",
click: function() {
$("#filesSelected input[type=checkbox]").prop("checked", true);
}
}, {
text: "Uncheck all",
click: function () {
$("#filesSelected input[type=checkbox]").prop("checked", false);
}
}, {
text: "Unselect", text: "Unselect",
click: function () { click: function () {
$("#filesSelected input[type=checkbox]:checked").each(function() { $("#filesSelected input.files[type=checkbox]:checked").each(function() {
var file = $(this).attr("rel"); var file = $(this).attr("rel");
$("#fileDialog a[rel='" + file + "']").parent("li").removeClass("selected"); $("#fileDialog a[rel='" + file + "']").parent("li").removeClass("selected");
$("#fileDialog a[rel='" + file + "']").parent("li").find("input[type=checkbox]").prop("checked", false); $("#fileDialog a[rel='" + file + "']").parent("li").find("input[type=checkbox]").prop("checked", false);
$("#filesSelected label[rel='" + file + "']").remove(); $("#filesSelected label[rel='" + file + "']").remove();
selectedFiles.splice(selectedFiles.indexOf(file), 1); selectedFiles.splice(selectedFiles.indexOf(file), 1);
updateNbFilesSelected();
}) })
} }
}, { }, {
...@@ -118,6 +114,14 @@ ...@@ -118,6 +114,14 @@
} }
] ]
}); });
$("#filesSelected input.checkAll").off("change").on("change", function() {
if ($(this).is(":checked")) {
$("#filesSelected input.files[type=checkbox]").prop("checked", true);
}
else {
$("#filesSelected input.files[type=checkbox]").prop("checked", false);
}
})
} }
}) })
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment