diff browser_side/radiocol.py @ 283:0eba1c4f9c6f

browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
author souliane <souliane@mailoo.org>
date Mon, 25 Nov 2013 20:39:28 +0100
parents a763b2ac5d41
children bee4719af9b9
line wrap: on
line diff
--- a/browser_side/radiocol.py	Tue Dec 10 09:07:03 2013 +0100
+++ b/browser_side/radiocol.py	Mon Nov 25 20:39:28 2013 +0100
@@ -26,7 +26,6 @@
 from pyjamas.ui.FlexTable import FlexTable
 from pyjamas.ui.FormPanel import FormPanel
 from pyjamas.ui.NamedFrame import NamedFrame
-from pyjamas.ui.FileUpload import FileUpload
 from pyjamas.ui.Label import Label
 from pyjamas.ui.Button import Button
 from pyjamas.ui.ClickListener import ClickHandler
@@ -39,6 +38,7 @@
 
 from jid import JID
 from tools import html_sanitize
+from tools import FilterFileUpload
 
 
 class MetadataPanel(FlexTable):
@@ -88,8 +88,10 @@
 
         hPanel = HorizontalPanel()
         hPanel.setSpacing(5)
-        self.file_upload = FileUpload()
-        self.file_upload.setName("song")
+        types = [('audio/ogg', '*.ogg', 'Ogg Vorbis Audio'),
+                 ('video/ogg', '*.ogv', 'Ogg Vorbis Video'),
+                 ('application/ogg', '*.ogx', 'Ogg Vorbis Multiplex')]
+        self.file_upload = FilterFileUpload("song", 5, types)
         hPanel.add(self.file_upload)
 
         self.upload_btn = Button("Upload song", getattr(self, "onBtnClick"))
@@ -111,7 +113,10 @@
         self.status.setText('')
 
     def onBtnClick(self):
-        self.submit()
+        if self.file_upload.check():
+            self.submit()
+            self.file_upload.setFilename("")
+            self.status.setText('[Submitting, please wait...]')
 
     def onSubmit(self, event):
         pass
@@ -133,8 +138,10 @@
         elif result == "KO":
             self.status.setText('[Something went wrong during your song upload]')
             self.status.setStyleName('radiocol_upload_status_ko')
+            self._timer.schedule(5000)
         else:
             Window.alert('Submit error: %s' % result)
+            self.status.setText('')
 
 
 class Player(HTML):