implement the server side part of ajax add from file

implement the client side javascript (file input still needs themeing)
This commit is contained in:
Damien Churchill 2008-11-11 11:14:02 +00:00
parent 5eb92ab9b7
commit d919a452dd
5 changed files with 52 additions and 11 deletions

View File

@ -220,7 +220,7 @@ class json_rpc:
"info_hash" the torrents info_hash
}
"""
return common.get_torrent_info(filename)
return common.get_torrent_info(filename.strip())
def add_torrents(self, torrents):
"""
@ -242,8 +242,19 @@ class json_upload:
def GET(self):
pass
@deco.check_session
def POST(self, name=None):
pass
import os
import shutil
import tempfile
vars = web.input(torrentFile = {})
vars.torrentFile
path = os.path.join(tempfile.gettempdir(), vars.torrentFile.filename)
tmp_file = open(path, 'w')
shutil.copyfileobj(vars.torrentFile.file, tmp_file)
tmp_file.close()
print path
def register():
component.get("PageManager").register_page("/json/rpc",json_rpc)

View File

@ -6,7 +6,7 @@
<link rel="shortcut icon" href="$base/static/images/deluge-icon.png" type="image/png" />
<link rel="stylesheet" type="text/css" href="$base/template/static/css/mooui.css" />
<link rel="stylesheet" type="text/css" href="$base/template_style.css" />
<script src="$base/static/mootools-1.2.1-core-yc.js" type="text/javascript"></script>
<script src="$base/static/mootools-1.2-core.js" type="text/javascript"></script>
<script src="$base/static/mootools-1.2-more.js" type="text/javascript"></script>
<script src="$base/template/static/js/Rpc.js" type="text/javascript"></script>
<script src="$base/static/mooui.js" type="text/javascript"></script>

View File

@ -4,7 +4,7 @@
</head>
<body style="background: none;">
<form method="post" action="/json/upload" enctype="multipart/form-data">
<label>$_('File'):</label><input type="file" name="torrentFile" /> <br/>
<label>$_('File'):</label><div id="torrentFileDiv"><input type="file" name="torrentFile" /></div><br/>
<button class="ok">$_('Ok')</button><button class="cancel">$_('Cancel')</button>
</form>
</body>

View File

@ -100,7 +100,7 @@ Deluge.Widgets.AddTorrent.File = new Class({
Extends: Widgets.Window,
options: {
width: 300,
width: 400,
height: 100,
title: _('From File')
},
@ -110,12 +110,18 @@ Deluge.Widgets.AddTorrent.File = new Class({
this.bound = {
onLoad: this.onLoad.bindWithEvent(this),
onCancel: this.onCancel.bindWithEvent(this),
onSubmit: this.onSubmit.bindWithEvent(this)
onSubmit: this.onSubmit.bindWithEvent(this),
onComplete: this.onComplete.bindWithEvent(this),
onGetInfoSuccess: this.onGetInfoSuccess.bindWithEvent(this)
};
this.iframe = new Element('iframe', {
src: '/template/render/html/window_add_torrent_file.html',
height: 100,
width: 300
height: 65,
width: 390,
style: {
background: 'White',
overflow: 'hidden'
}
});
this.iframe.addEvent('load', this.bound.onLoad);
this.content.grab(this.iframe);
@ -135,7 +141,20 @@ Deluge.Widgets.AddTorrent.File = new Class({
},
onSubmit: function(e) {
alert('form sent');
this.iframe.addEvent('load', this.bound.onComplete);
this.iframe.set('opacity', 0);
},
onComplete: function(e) {
filename = this.iframe.contentDocument.body.get('text');
Deluge.Client.get_torrent_info(filename, {
onSuccess: this.bound.onGetInfoSuccess
});
},
onGetInfoSuccess: function(info) {
this.fireEvent('torrentAdded', info);
this.hide();
}
});
@ -219,6 +238,7 @@ Deluge.Widgets.AddTorrent.FilesTab = new Class({
onLoad: function(e) {
this.table = this.element.getElement('table');
alert('boo');
},
setTorrent: function(torrent) {

View File

@ -1,3 +1,8 @@
html, body {
padding: 0;
margin: 0;
}
body {
font-family: trebuchet ms;
font-size: 0.7em;
@ -29,6 +34,11 @@ form input, form select {
line-height: 20px;
}
form torrentFileDiv {
position: relative;
opacity: 0;
}
form textarea {
border:1px solid #23344b;
background: #99acc3;
@ -39,7 +49,7 @@ form .disabled {
color: Gray;
}
form .deluge_button, button {
form button {
background-color: #37506f;
border:1px solid #68a;
cursor: pointer;
@ -51,7 +61,7 @@ form .deluge_button, button {
margin: 2px;
}
form .deluge_button:hover, button:hover {
form button:hover {
background-color:#68a;
}