Merge pull request #880 from NyaaPantsu/mass-edit-api-international
Added translations support to mass edit api + improvements
Cette révision appartient à :
révision
b3f2b7bc8c
4 fichiers modifiés avec 141 ajouts et 21 suppressions
|
@ -19,6 +19,7 @@ var TorrentsMod = {
|
||||||
progress_count: 0,
|
progress_count: 0,
|
||||||
progress_max: 0,
|
progress_max: 0,
|
||||||
pause: false,
|
pause: false,
|
||||||
|
enabled: false,
|
||||||
|
|
||||||
// Init method
|
// Init method
|
||||||
Create: function() {
|
Create: function() {
|
||||||
|
@ -47,17 +48,17 @@ var TorrentsMod = {
|
||||||
checkbox.addEventListener("change", this.checkboxEventHandler)
|
checkbox.addEventListener("change", this.checkboxEventHandler)
|
||||||
}
|
}
|
||||||
sh_btn.addEventListener("click", function(e) {
|
sh_btn.addEventListener("click", function(e) {
|
||||||
var display = "inline"
|
|
||||||
var divActions = this.nextElementSibling;
|
var divActions = this.nextElementSibling;
|
||||||
console.log(divActions)
|
|
||||||
if (divActions.style.display == "inline") {
|
if (divActions.style.display == "inline") {
|
||||||
display = "none";
|
TorrentsMod.enabled = false;
|
||||||
|
} else {
|
||||||
|
TorrentsMod.enabled = true;
|
||||||
}
|
}
|
||||||
divActions.style.display = display;
|
divActions.style.display = (TorrentsMod.enabled) ? "inline" : "none";
|
||||||
var td_cbs = document.getElementsByClassName("tr-cb")
|
var td_cbs = document.getElementsByClassName("tr-cb")
|
||||||
for (var i=0; i < td_cbs.length; i++) {
|
for (var i=0; i < td_cbs.length; i++) {
|
||||||
td_cb = td_cbs[i];
|
td_cb = td_cbs[i];
|
||||||
td_cb.style.display = (display == "inline") ? "table-cell" : "none";
|
td_cb.style.display = (TorrentsMod.enabled) ? "table-cell" : "none";
|
||||||
}
|
}
|
||||||
var toggleText = this.dataset.toggleText;
|
var toggleText = this.dataset.toggleText;
|
||||||
this.dataset.toggleText = this.innerText;
|
this.dataset.toggleText = this.innerText;
|
||||||
|
@ -229,17 +230,17 @@ var TorrentsMod = {
|
||||||
TorrentsMod.addToLog("error", errorMsg);
|
TorrentsMod.addToLog("error", errorMsg);
|
||||||
TorrentsMod.error_count++;
|
TorrentsMod.error_count++;
|
||||||
if (TorrentsMod.error_count < 2) {
|
if (TorrentsMod.error_count < 2) {
|
||||||
TorrentsMod.addToLog("success", "Trying a new attempt...");
|
TorrentsMod.addToLog("success", T.r("try_new_attempt"));
|
||||||
TorrentsMod.newQueryAttempt(queryUrl, queryPost, callback)
|
TorrentsMod.newQueryAttempt(queryUrl, queryPost, callback)
|
||||||
} else {
|
} else {
|
||||||
TorrentsMod.addToLog("error", "The query ("+queryUrl+"?"+queryPost+") seems broken!");
|
TorrentsMod.addToLog("error", T.r("query_is_broken", queryUrl, queryPost));
|
||||||
if (callback != undefined) {
|
if (callback != undefined) {
|
||||||
TorrentsMod.addToLog("error", "Passing to the next query...");
|
TorrentsMod.addToLog("error", "Passing to the next query...");
|
||||||
callback(response) // So we can query only one item
|
callback(response) // So we can query only one item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var succesMsg = (response.infos != null) ? response.infos.join("<br>") : "Query executed with success!";
|
var succesMsg = (response.infos != null) ? response.infos.join("<br>") : T.r("query_executed_success");
|
||||||
TorrentsMod.addToLog("success", succesMsg)
|
TorrentsMod.addToLog("success", succesMsg)
|
||||||
if (callback != undefined) callback(response) // So we can query only one item
|
if (callback != undefined) callback(response) // So we can query only one item
|
||||||
}
|
}
|
||||||
|
@ -266,9 +267,9 @@ var TorrentsMod = {
|
||||||
}
|
}
|
||||||
TorrentsMod.newQueryAttempt(queryUrl, queryPost, callback)
|
TorrentsMod.newQueryAttempt(queryUrl, queryPost, callback)
|
||||||
} else {
|
} else {
|
||||||
TorrentsMod.addToLog("success", "All operations are done!")
|
TorrentsMod.addToLog("success", T.r("all_operations_done"))
|
||||||
if (TorrentsMod.refreshTimeout > 0) {
|
if (TorrentsMod.refreshTimeout > 0) {
|
||||||
TorrentsMod.addToLog("success", "Refreshing the page in 3 seconds...")
|
TorrentsMod.addToLog("success", T.r("refreshing_in", TorrentsMod.refreshTimeout/1000))
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
window.location.reload()
|
window.location.reload()
|
||||||
}, TorrentsMod.refreshTimeout);
|
}, TorrentsMod.refreshTimeout);
|
||||||
|
@ -300,20 +301,20 @@ var TorrentsMod = {
|
||||||
|
|
||||||
// Action Methods
|
// Action Methods
|
||||||
DeleteHandler: function(locked) {
|
DeleteHandler: function(locked) {
|
||||||
var withReport = confirm("Do you want to delete the reports along the selected torrents?")
|
var withReport = confirm(T.r("delete_reports_with_torrents"))
|
||||||
var selection = TorrentsMod.selected;
|
var selection = TorrentsMod.selected;
|
||||||
if (locked)
|
if (locked)
|
||||||
TorrentsMod.AddToQueue({ action: "delete",
|
TorrentsMod.AddToQueue({ action: "delete",
|
||||||
withReport: withReport,
|
withReport: withReport,
|
||||||
selection: selection,
|
selection: selection,
|
||||||
queryPost: "",
|
queryPost: "",
|
||||||
infos: "with lock"+ ((withReport) ? " and reports" : ""),
|
infos: T.r("with_lock")+ ((withReport) ? T.r("and_reports") : ""),
|
||||||
status: "5" });
|
status: "5" });
|
||||||
else TorrentsMod.AddToQueue({
|
else TorrentsMod.AddToQueue({
|
||||||
action: "delete",
|
action: "delete",
|
||||||
withReport: withReport,
|
withReport: withReport,
|
||||||
selection: selection,
|
selection: selection,
|
||||||
infos: (withReport) ? "with reports" : "",
|
infos: (withReport) ? T.r("with_reports") : "",
|
||||||
queryPost: ""});
|
queryPost: ""});
|
||||||
for (i in selection) document.getElementById("torrent_"+i).style.display="none";
|
for (i in selection) document.getElementById("torrent_"+i).style.display="none";
|
||||||
TorrentsMod.selected = []
|
TorrentsMod.selected = []
|
||||||
|
@ -333,14 +334,14 @@ var TorrentsMod = {
|
||||||
var owner_id = document.querySelector(".modtools *[name='"+TorrentsMod.owner_input_name+"']").value;
|
var owner_id = document.querySelector(".modtools *[name='"+TorrentsMod.owner_input_name+"']").value;
|
||||||
var category = document.querySelector(".modtools *[name='"+TorrentsMod.category_input_name+"']").value;
|
var category = document.querySelector(".modtools *[name='"+TorrentsMod.category_input_name+"']").value;
|
||||||
var infos = "";
|
var infos = "";
|
||||||
infos += (status != "") ? "status: "+status : "";
|
infos += (status != "") ? T.r("status_js", status) : "";
|
||||||
infos += (owner_id != "") ? " owner_id: "+owner_id : "";
|
infos += (owner_id != "") ? T.r("owner_id_js", owner_id) : "";
|
||||||
infos += (category != "") ? " category: "+category : "";
|
infos += (category != "") ? T.r("category_js", category) : "";
|
||||||
TorrentsMod.AddToQueue({
|
TorrentsMod.AddToQueue({
|
||||||
action: "edit",
|
action: "edit",
|
||||||
selection: selection,
|
selection: selection,
|
||||||
queryPost: "", // We don't format now, we wait until the query is sent
|
queryPost: "", // We don't format now, we wait until the query is sent
|
||||||
infos: (infos != "" ) ? "with "+infos : "No changes",
|
infos: (infos != "" ) ? T.r("with_st", infos) : T.r("no_changes"),
|
||||||
status: status,
|
status: status,
|
||||||
category: category,
|
category: category,
|
||||||
owner: owner_id });
|
owner: owner_id });
|
||||||
|
|
29
public/js/translation.js
Fichier normal
29
public/js/translation.js
Fichier normal
|
@ -0,0 +1,29 @@
|
||||||
|
function Translations() {
|
||||||
|
var translations = {};
|
||||||
|
this.Add = function(tr, val) {
|
||||||
|
if (val != undefined) {
|
||||||
|
tr[tr] = val;
|
||||||
|
}
|
||||||
|
Object.assign(translations, tr);
|
||||||
|
};
|
||||||
|
this.r = function(string, ...args) {
|
||||||
|
if ((string != undefined) && (translations[string] != undefined)) {
|
||||||
|
if (args != undefined) {
|
||||||
|
return this.format(translations[string], ...args);
|
||||||
|
}
|
||||||
|
return translations[string];
|
||||||
|
}
|
||||||
|
console.error("No translation string for %s! Please check!", string);
|
||||||
|
return "";
|
||||||
|
};
|
||||||
|
this.format = function(format, ...args) {
|
||||||
|
return format.replace(/{(\d+)}/g, function(match, number) {
|
||||||
|
return typeof args[number] != 'undefined'
|
||||||
|
? args[number]
|
||||||
|
: match
|
||||||
|
;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var T = new Translations();
|
|
@ -107,7 +107,7 @@ Your browser does not support the audio element.
|
||||||
<option value="{{ $id_cat }}">{{call $.T $name_cat }}</option>
|
<option value="{{ $id_cat }}">{{call $.T $name_cat }}</option>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</select>
|
</select>
|
||||||
<input class="cb_action" type="text" name="owner_id" placeholder="Owner ID (eg. Renchon = 0)">
|
<input class="cb_action" type="text" name="owner_id" placeholder="{{ call $.T "owner_id_placeholder" }}">
|
||||||
<select class="cb_action" name="status_id">
|
<select class="cb_action" name="status_id">
|
||||||
<option value="">{{call $.T "torrent_status"}}</option>
|
<option value="">{{call $.T "torrent_status"}}</option>
|
||||||
<option value="5">{{ call $.T "torrent_status_blocked" }}</option>
|
<option value="5">{{ call $.T "torrent_status_blocked" }}</option>
|
||||||
|
@ -160,8 +160,28 @@ Your browser does not support the audio element.
|
||||||
<script type="text/javascript" src="{{ $.URL.Parse "/js/modal.js" }}"></script>
|
<script type="text/javascript" src="{{ $.URL.Parse "/js/modal.js" }}"></script>
|
||||||
<script type="text/javascript" src="{{ $.URL.Parse "/js/torrents.js" }}"></script>
|
<script type="text/javascript" src="{{ $.URL.Parse "/js/torrents.js" }}"></script>
|
||||||
{{ if HasAdmin $.User }}
|
{{ if HasAdmin $.User }}
|
||||||
|
<script type="text/javascript" src="{{ $.URL.Parse "/js/translation.js" }}"></script>
|
||||||
<script type="text/javascript" src="{{ $.URL.Parse "/js/torrentsMod.js" }}"></script>
|
<script type="text/javascript" src="{{ $.URL.Parse "/js/torrentsMod.js" }}"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
// We add translations string
|
||||||
|
T.Add({
|
||||||
|
try_new_attempt: "{{ call $.T "try_new_attempt" }}",
|
||||||
|
query_is_broken: "{{ call $.T "query_is_broken" }}",
|
||||||
|
query_executed_success: "{{ call $.T "query_executed_success" }}",
|
||||||
|
all_operations_done: "{{ call $.T "all_operations_done" }}",
|
||||||
|
refreshing_in: "{{ call $.T "refreshing_in" }}",
|
||||||
|
delete_reports_with_torrents: "{{ call $.T "delete_reports_with_torrents" }}",
|
||||||
|
with_st: "{{ call $.T "with_st" }}",
|
||||||
|
and_reports: "{{ call $.T "and_reports" }}",
|
||||||
|
reports: "{{ call $.T "reports" }}",
|
||||||
|
lock: "{{ call $.T "lock" }}",
|
||||||
|
status_js: "{{ call $.T "status_js" }}",
|
||||||
|
owner_id_js: "{{ call $.T "owner_id_js" }}",
|
||||||
|
category_js: "{{ call $.T "category_js" }}",
|
||||||
|
no_changes: "{{ call $.T "no_changes" }}",
|
||||||
|
query_nb: "{{ call $.T "query_nb" }}"
|
||||||
|
});
|
||||||
|
// Modal initialization
|
||||||
Modal.Init({elements: document.getElementsByClassName("modal"),
|
Modal.Init({elements: document.getElementsByClassName("modal"),
|
||||||
button: "#modal_active",
|
button: "#modal_active",
|
||||||
before: function() {
|
before: function() {
|
||||||
|
@ -171,13 +191,14 @@ Your browser does not support the audio element.
|
||||||
TorrentsMod.resetModal();
|
TorrentsMod.resetModal();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// Templates initialization
|
||||||
Templates.Add("torrents.delete.item", function(torrent) {
|
Templates.Add("torrents.delete.item", function(torrent) {
|
||||||
return '<div class="delete_item" id="list_item_'+torrent.id+'"><span>'+Templates.EncodeEntities(torrent.name)+'</span>'+
|
return '<div class="delete_item" id="list_item_'+torrent.id+'"><span>'+Templates.EncodeEntities(torrent.name)+'</span>'+
|
||||||
'<a href="#" onclick="return TorrentsMod.RemoveItemFromQueue('+torrent.key+', '+torrent.id+')"><i class="trash-icon"></i></a></div>'
|
'<a href="#" onclick="return TorrentsMod.RemoveItemFromQueue('+torrent.key+', '+torrent.id+')"><i class="trash-icon"></i></a></div>'
|
||||||
});
|
});
|
||||||
Templates.Add("torrents.delete.block", function(torrentQuery){
|
Templates.Add("torrents.delete.block", function(torrentQuery){
|
||||||
return '<div class="delete_list" id="list_'+torrentQuery.unique_id+'"><div class="title">'+
|
return '<div class="delete_list" id="list_'+torrentQuery.unique_id+'"><div class="title">'+
|
||||||
'<h3 style="display:inline-block;" onclick="TorrentsMod.toggleList(this);">Query #'+torrentQuery.unique_id+
|
'<h3 style="display:inline-block;" onclick="TorrentsMod.toggleList(this);">'+T.r("query_nb", torrentQuery.unique_id)+
|
||||||
'</h3>'+
|
'</h3>'+
|
||||||
'<span class="infos">'+torrentQuery.infos+'<a href="#" class="icon" onclick="return TorrentsMod.RemoveFromQueue('+torrentQuery.key+')"><div class="trash-icon"></div></a>'+
|
'<span class="infos">'+torrentQuery.infos+'<a href="#" class="icon" onclick="return TorrentsMod.RemoveFromQueue('+torrentQuery.key+')"><div class="trash-icon"></div></a>'+
|
||||||
'</span></div>'+
|
'</span></div>'+
|
||||||
|
@ -189,7 +210,7 @@ Your browser does not support the audio element.
|
||||||
});
|
});
|
||||||
Templates.Add("torrents.edit.block", function(torrentQuery){
|
Templates.Add("torrents.edit.block", function(torrentQuery){
|
||||||
return '<div class="edit_list" id="list_'+torrentQuery.unique_id+'"><div class="title">'+
|
return '<div class="edit_list" id="list_'+torrentQuery.unique_id+'"><div class="title">'+
|
||||||
'<h3 style="display:inline-block;" onclick="TorrentsMod.toggleList(this);">Query #'+torrentQuery.unique_id+
|
'<h3 style="display:inline-block;" onclick="TorrentsMod.toggleList(this);">'+T.r("query_nb", torrentQuery.unique_id)+
|
||||||
'</h3>'+
|
'</h3>'+
|
||||||
'<span class="infos">'+torrentQuery.infos+'<a href="#" class="icon" onclick="return TorrentsMod.RemoveFromQueue('+torrentQuery.key+')"><div class="trash-icon"></div></a>'+
|
'<span class="infos">'+torrentQuery.infos+'<a href="#" class="icon" onclick="return TorrentsMod.RemoveFromQueue('+torrentQuery.key+')"><div class="trash-icon"></div></a>'+
|
||||||
'</span></div>'+
|
'</span></div>'+
|
||||||
|
@ -203,10 +224,15 @@ Your browser does not support the audio element.
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{{end}}
|
{{end}}
|
||||||
<!-- JS Template -->
|
<!-- JS Template for torrents ajax -->
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
Templates.Add("torrents.item", function(torrent) {
|
Templates.Add("torrents.item", function(torrent) {
|
||||||
return "<tr class=\"torrent-info"+ ((torrent.status == 2) ? " remake" : ((torrent.status == 3) ? " trusted" : ((torrent.status == 3) ? " aplus" : "" )))+"\">"+
|
return "<tr class=\"torrent-info"+ ((torrent.status == 2) ? " remake" : ((torrent.status == 3) ? " trusted" : ((torrent.status == 3) ? " aplus" : "" )))+"\">"+
|
||||||
|
{{ if HasAdmin $.User }}
|
||||||
|
"<td class=\"tr-cb\""+ ((TorrentsMod.enabled) ? "style=\"display:table-cell;\"" : "") +">"+
|
||||||
|
"<input data-name=\""+Templates.EncodeEntities(torrent.name)+"\" type=\"checkbox\" id=\"torrent_cb_"+torrent.id+"\" name=\"torrent_id\" value=\""+torrent.id+"\">"+
|
||||||
|
"</td>"+
|
||||||
|
{{ end }}
|
||||||
"<td class=\"tr-cat home-td\">"+
|
"<td class=\"tr-cat home-td\">"+
|
||||||
"<a href=\"{{$.URL.Parse "/search?c=" }}"+ torrent.category + "_" + torrent.sub_category +"\">"+
|
"<a href=\"{{$.URL.Parse "/search?c=" }}"+ torrent.category + "_" + torrent.sub_category +"\">"+
|
||||||
{{ if Sukebei }}
|
{{ if Sukebei }}
|
||||||
|
|
|
@ -1038,5 +1038,69 @@
|
||||||
{
|
{
|
||||||
"id": "delete_changes",
|
"id": "delete_changes",
|
||||||
"translation": "Delete Changes"
|
"translation": "Delete Changes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "owner_id_placeholder",
|
||||||
|
"translation": "Owner ID (eg. Renchon = 0)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "try_new_attempt",
|
||||||
|
"translation": "Trying a new attempt..."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "query_is_broken",
|
||||||
|
"translation": "The query ({0}?{1}) seems broken!"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "query_executed_success",
|
||||||
|
"translation": "Query executed with success!"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "all_operations_done",
|
||||||
|
"translation": "All operations are done!"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "refreshing_in",
|
||||||
|
"translation": "Refreshing the page in {0} seconds..."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "delete_reports_with_torrents",
|
||||||
|
"translation": "Do you want to delete the reports along the selected torrents?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "with_st",
|
||||||
|
"translation": "with {0}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "and_reports",
|
||||||
|
"translation": " and reports"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "reports",
|
||||||
|
"translation": "reports"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "lock",
|
||||||
|
"translation": "lock"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "status_js",
|
||||||
|
"translation": "status: {0}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "owner_id_js",
|
||||||
|
"translation": "owner_id: {0}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "category_js",
|
||||||
|
"translation": "category: {0}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "no_changes",
|
||||||
|
"translation": "No changes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "query_nb",
|
||||||
|
"translation": "Query #{0}"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
Référencer dans un nouveau ticket