מדיה ויקי:Gadget-Cat-a-lot.js: הבדלים בין גרסאות בדף

fix last edit; only show "remove" if != searchmode
mark done images, rmv paranoia
שורה 7: שורה 7:
// RegExes by Ilmari Karonen
// RegExes by Ilmari Karonen
// Completely rewritten by DieBuche
// Completely rewritten by DieBuche
var catALot = {
var catALot = {
apiUrl: wgScriptPath + "/api.php",
apiUrl: wgScriptPath + "/api.php",
searchmode: false,
searchmode: false,
version: 2.03,
version: 2.03,
 
init: function () {
init: function () {
//jQuery UI is not loaded on all pages:
//jQuery UI is not loaded on all pages:
שורה 20: שורה 19:
}
}
$("#column-one, #mw-panel").append('<div id="cat_a_lot">' + '<div id="cat_a_lot_data"><div>' + '<input type="text" id="cat_a_lot_searchcatname" placeholder="Enter category name"/>' + '</div><div id="cat_a_lot_category_list"></div>' + '<div id="cat_a_lot_mark_counter"> </div>' + '<div id="cat_a_lot_selections">Select <a  id="cat_a_lot_select_all">all</a> / ' + '<a  id="cat_a_lot_select_none">none</a>' + '<br>' + '</div></div><div id="cat_a_lot_head">' + '<a id="cat_a_lot_toggle">Cat-a-lot</a></div></div>');
$("#column-one, #mw-panel").append('<div id="cat_a_lot">' + '<div id="cat_a_lot_data"><div>' + '<input type="text" id="cat_a_lot_searchcatname" placeholder="Enter category name"/>' + '</div><div id="cat_a_lot_category_list"></div>' + '<div id="cat_a_lot_mark_counter"> </div>' + '<div id="cat_a_lot_selections">Select <a  id="cat_a_lot_select_all">all</a> / ' + '<a  id="cat_a_lot_select_none">none</a>' + '<br>' + '</div></div><div id="cat_a_lot_head">' + '<a id="cat_a_lot_toggle">Cat-a-lot</a></div></div>');
 
if (!this.searchmode) $('#cat_a_lot_selections').append('<a id="cat_a_lot_remove"><b>Remove from this category</b></a>');
if (!this.searchmode) $('#cat_a_lot_selections').append('<a id="cat_a_lot_remove"><b>Remove from this category</b></a>');
 
$('#cat_a_lot_searchcatname').keypress(function(e){
$('#cat_a_lot_searchcatname').keypress(function (e) {
if(e.which == 13) catALot.updateCats($(this).val());
if (e.which == 13) catALot.updateCats($(this).val());
});
});
$('#cat_a_lot_remove').click(function () {
$('#cat_a_lot_remove').click(function () {
שורה 69: שורה 68:
});
});
},
},
toggleAll: function (select) {
toggleAll: function (select) {
this.labels.toggleClass('cat_a_lot_selected', select);
this.labels.toggleClass('cat_a_lot_selected', select);
this.updateSelectionCounter();
this.updateSelectionCounter();
שורה 228: שורה 227:
};
};


this.doAPICall(data, function () {
this.markAsDone(filename, mode, targetcat);
 
this.doAPICall(data, function (ret) {
catALot.updateCounter();
catALot.updateCounter();
});
});
},
},
markAsDone: function (filename, mode, targetcat) {


var label = $('a[title=' + filename + ']').parent();
label.addClass('cat_a_lot_markAsDone');
switch (mode) {
case 'add':
label.append('<br>Added category ' + targetcat);
break;
case 'copy':
label.append('<br>Copied to category ' + targetcat);
break;
case 'move':
label.append('<br>Moved to category ' + targetcat);
break;
case 'remove':
label.append('<br>Removed from category');
break;
}
},
updateCounter: function () {
updateCounter: function () {


שורה 248: שורה 267:
rep.html('<h3>Done!</h3>');
rep.html('<h3>Done!</h3>');
rep.append('All pages are processed.<br />');
rep.append('All pages are processed.<br />');
 
var close = $('<a>Return to page</a>')
var close = $('<a>Return to page</a>')
close.click(function() {
close.click(function () {
  catALot.progressDialog.remove();
catALot.progressDialog.remove();
  catALot.toggleAll(false);
catALot.toggleAll(false);
});
});
    rep.append(close);
rep.append(close);
if (this.alreadyThere.length) {
if (this.alreadyThere.length) {
rep.append('<h5>The following pages were skipped, because the page was already in the category:</h5>');
rep.append('<h5>The following pages were skipped, because the page was already in the category:</h5>');
שורה 287: שורה 306:


doSomething: function (targetcat, mode) {
doSomething: function (targetcat, mode) {
//Paranoia
if (this.lock) return alert('Please reload page');
var files = this.getMarkedLabels();
var files = this.getMarkedLabels();
if (files.length == 0) {
if (files.length == 0) {
שורה 295: שורה 311:
return;
return;
}
}
this.lock = true;
this.notFound = [];
this.notFound = [];
this.alreadyThere = [];
this.alreadyThere = [];
שורה 359: שורה 374:
}
}
},
},
 
getCategoryList: function () {
getCategoryList: function () {
this.catCounter = 0;
this.catCounter = 0;
שורה 365: שורה 380:
this.getSubCats();
this.getSubCats();
},
},
 
showCategoryList: function () {
showCategoryList: function () {
var thiscat = [this.currentCategory];
var thiscat = [this.currentCategory];