-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add save path and category editing to WebUI #9228
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,55 +7,113 @@ | |
<link rel="stylesheet" href="css/style.css" type="text/css" /> | ||
<script src="scripts/lib/mootools-1.2-core-yc.js"></script> | ||
<script src="scripts/lib/mootools-1.2-more.js"></script> | ||
<script src="scripts/misc.js"></script> | ||
<script> | ||
var newCategoryKeyboardEvents = new Keyboard({ | ||
defaultEventType: 'keydown', | ||
events: { | ||
'enter': function(event) { | ||
$('newCategoryButton').click(); | ||
$('categoryNameButton').click(); | ||
event.preventDefault(); | ||
} | ||
} | ||
}); | ||
newCategoryKeyboardEvents.activate(); | ||
|
||
window.addEvent('domready', function() { | ||
$('newCategory').focus(); | ||
$('newCategoryButton').addEvent('click', function(e) { | ||
new Event(e).stop(); | ||
// check field | ||
var categoryName = $('newCategory').value.trim(); | ||
if (categoryName == null || categoryName == "") | ||
return false; | ||
if (categoryName.match("^([^\\\\\\/]|[^\\\\\\/]([^\\\\\\/]|\\/(?=[^\\/]))*[^\\\\\\/])$") === null) { | ||
alert("QBT_TR(Invalid category name:\nPlease do not use any special characters in the category name.)QBT_TR[CONTEXT=HttpServer]"); | ||
var uriAction = safeTrim(new URI().getData('action')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it is possible to write it as: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
var uriHashes = safeTrim(new URI().getData('hashes')); | ||
var uriCategoryName = safeTrim(new URI().getData('categoryName')); | ||
var uriSavePath = safeTrim(new URI().getData('savePath')); | ||
|
||
if (uriAction === "create") { | ||
$('categoryName').focus(); | ||
} | ||
else if (uriAction === "edit") { | ||
if (!uriCategoryName) | ||
return false; | ||
} | ||
var hashesList = new URI().getData('hashes'); | ||
if (!hashesList) { | ||
new Request({ | ||
url: 'api/v2/torrents/createCategory', | ||
method: 'post', | ||
data: { | ||
category: categoryName | ||
}, | ||
onComplete: function() { | ||
window.parent.closeWindows(); | ||
} | ||
}).send(); | ||
} | ||
else { | ||
new Request({ | ||
url: 'api/v2/torrents/setCategory', | ||
method: 'post', | ||
data: { | ||
hashes: hashesList, | ||
category: categoryName | ||
}, | ||
onComplete: function() { | ||
window.parent.closeWindows(); | ||
} | ||
}).send(); | ||
|
||
$('categoryName').set('disabled', true); | ||
$('categoryName').set('value', escapeHtml(uriCategoryName)); | ||
$('savePath').set('value', escapeHtml(uriSavePath)); | ||
$('savePath').focus(); | ||
} | ||
|
||
$('categoryNameButton').addEvent('click', function(e) { | ||
new Event(e).stop(); | ||
|
||
var savePath = $('savePath').value.trim(); | ||
var categoryName = $('categoryName').value.trim(); | ||
|
||
var verifyCategoryName = function(name) { | ||
if ((name === null) || (name === "")) | ||
return false; | ||
if (name.match("^([^\\\\\\/]|[^\\\\\\/]([^\\\\\\/]|\\/(?=[^\\/]))*[^\\\\\\/])$") === null) { | ||
alert("QBT_TR(Invalid category name:\nPlease do not use any special characters in the category name.)QBT_TR[CONTEXT=HttpServer]"); | ||
return false; | ||
} | ||
return true; | ||
}; | ||
|
||
switch (uriAction) { | ||
case "set": | ||
if ((uriHashes === "") || !verifyCategoryName(categoryName)) | ||
return; | ||
|
||
new Request({ | ||
url: 'api/v2/torrents/createCategory', | ||
method: 'post', | ||
data: { | ||
category: categoryName, | ||
savePath: savePath | ||
}, | ||
onSuccess: function() { | ||
new Request({ | ||
url: 'api/v2/torrents/setCategory', | ||
method: 'post', | ||
data: { | ||
hashes: uriHashes, | ||
category: categoryName | ||
}, | ||
onComplete: function() { | ||
window.parent.closeWindows(); | ||
} | ||
}).send(); | ||
}, | ||
onError: function() { | ||
alert("QBT_TR(Unable to create category)QBT_TR[CONTEXT=HttpServer] " + escapeHtml(categoryName)); | ||
} | ||
}).send(); | ||
break; | ||
case "create": | ||
if (!verifyCategoryName(categoryName)) | ||
return; | ||
|
||
new Request({ | ||
url: 'api/v2/torrents/createCategory', | ||
method: 'post', | ||
data: { | ||
category: categoryName, | ||
savePath: savePath | ||
}, | ||
onComplete: function() { | ||
window.parent.closeWindows(); | ||
} | ||
}).send(); | ||
break; | ||
case "edit": | ||
new Request({ | ||
url: 'api/v2/torrents/editCategory', | ||
method: 'post', | ||
data: { | ||
category: uriCategoryName, // category name can't be changed | ||
savePath: savePath | ||
}, | ||
onComplete: function() { | ||
window.parent.closeWindows(); | ||
} | ||
}).send(); | ||
break; | ||
} | ||
}); | ||
}); | ||
|
@@ -65,9 +123,11 @@ | |
<body> | ||
<div style="padding: 10px 10px 0px 10px;"> | ||
<p style="font-weight: bold;">QBT_TR(Category)QBT_TR[CONTEXT=TransferListWidget]:</p> | ||
<input type="text" id="newCategory" value="" maxlength="100" style="width: 220px;" /> | ||
<input type="text" id="categoryName" value="" maxlength="100" style="width: 220px;" /> | ||
<p style="font-weight: bold;">QBT_TR(Save path)QBT_TR[CONTEXT=TransferListWidget]:</p> | ||
<input type="text" id="savePath" value="" style="width: 220px;" /> | ||
<div style="text-align: center; padding-top: 10px;"> | ||
<input type="button" value="QBT_TR(Add)QBT_TR[CONTEXT=HttpServer]" id="newCategoryButton" /> | ||
<input type="button" value="QBT_TR(Add)QBT_TR[CONTEXT=HttpServer]" id="categoryNameButton" /> | ||
</div> | ||
</div> | ||
</body> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,3 +120,14 @@ function escapeHtml(str) { | |
div.appendChild(document.createTextNode(str)); | ||
return div.innerHTML; | ||
} | ||
|
||
function safeTrim(value) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
OK, however I think a true "safe trim" should look like this: function safeTrim(str) {
try {
return str.trim();
}
catch (e) {
if (e instanceof TypeError)
return "";
throw e;
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, will update the implementation. |
||
try { | ||
return value.trim(); | ||
} | ||
catch (e) { | ||
if (e instanceof TypeError) | ||
return ""; | ||
throw e; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please replace "map" with "dictionary" since such term is used in other place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both are used throughout the documentation