##// END OF EJS Templates
alternate notebook upload methods...
Matthias BUSSONNIER -
Show More
@@ -0,0 +1,23 b''
1 /* We need an invisible input field on top of the sentense*/
2 /* "Drag file onto the list ..." */
3
4 .alternate_upload
5 {
6 background-color:none;
7 display: inline;
8 }
9
10 .alternate_upload.form
11 {
12 padding: 0;
13 margin:0;
14 }
15
16 .alternate_upload input.fileinput
17 {
18 background-color:red;
19 position:relative;
20 opacity: 0;
21 z-index: 2;
22 width: 356px;
23 }
@@ -43,33 +43,45 b' var IPython = (function (IPython) {'
43 this.element.bind('dragover', function () {
43 this.element.bind('dragover', function () {
44 return false;
44 return false;
45 });
45 });
46 this.element.bind('drop', function (event) {
46 this.element.bind('drop', function(event){
47 var files = event.originalEvent.dataTransfer.files;
47 console.log('bound to drop');
48 for (var i = 0, f; f = files[i]; i++) {
48 that.handelFilesUpload(event,'drop');
49 var reader = new FileReader();
50 reader.readAsText(f);
51 var fname = f.name.split('.');
52 var nbname = fname.slice(0,-1).join('.');
53 var nbformat = fname.slice(-1)[0];
54 if (nbformat === 'ipynb') {nbformat = 'json';};
55 if (nbformat === 'py' || nbformat === 'json') {
56 var item = that.new_notebook_item(0);
57 that.add_name_input(nbname, item);
58 item.data('nbformat', nbformat);
59 // Store the notebook item in the reader so we can use it later
60 // to know which item it belongs to.
61 $(reader).data('item', item);
62 reader.onload = function (event) {
63 var nbitem = $(event.target).data('item');
64 that.add_notebook_data(event.target.result, nbitem);
65 that.add_upload_button(nbitem);
66 };
67 };
68 }
69 return false;
49 return false;
70 });
50 });
71 };
51 };
72
52
53 NotebookList.prototype.handelFilesUpload = function(event, dropOrForm) {
54 var that = this;
55 var files;
56 if(dropOrForm =='drop'){
57 files = event.originalEvent.dataTransfer.files;
58 } else
59 {
60 files = event.originalEvent.target.files
61 }
62 for (var i = 0, f; f = files[i]; i++) {
63 var reader = new FileReader();
64 reader.readAsText(f);
65 var fname = f.name.split('.');
66 var nbname = fname.slice(0,-1).join('.');
67 var nbformat = fname.slice(-1)[0];
68 if (nbformat === 'ipynb') {nbformat = 'json';};
69 if (nbformat === 'py' || nbformat === 'json') {
70 var item = that.new_notebook_item(0);
71 that.add_name_input(nbname, item);
72 item.data('nbformat', nbformat);
73 // Store the notebook item in the reader so we can use it later
74 // to know which item it belongs to.
75 $(reader).data('item', item);
76 reader.onload = function (event) {
77 var nbitem = $(event.target).data('item');
78 that.add_notebook_data(event.target.result, nbitem);
79 that.add_upload_button(nbitem);
80 };
81 };
82 }
83 return false;
84 };
73
85
74 NotebookList.prototype.clear_list = function () {
86 NotebookList.prototype.clear_list = function () {
75 this.element.children('.list_item').remove();
87 this.element.children('.list_item').remove();
@@ -32,8 +32,11 b' $(document).ready(function () {'
32
32
33 IPython.notebook_list.load_list();
33 IPython.notebook_list.load_list();
34 IPython.cluster_list.load_list();
34 IPython.cluster_list.load_list();
35
36 IPython.page.show();
35 IPython.page.show();
37
36
37 // bound the upload method to the on change of the file select list
38 $("#alternate_upload").change(function (event){
39 IPython.notebook_list.handelFilesUpload(event,'form');
40 });
38 });
41 });
39
42
@@ -4,6 +4,7 b''
4
4
5 {% block stylesheet %}
5 {% block stylesheet %}
6 <link rel="stylesheet" href="{{static_url("css/projectdashboard.css") }}" type="text/css" />
6 <link rel="stylesheet" href="{{static_url("css/projectdashboard.css") }}" type="text/css" />
7 <link rel="stylesheet" href="{{static_url("css/alternate_uploadform.css") }}" type="text/css" />
7 {% end %}
8 {% end %}
8
9
9
10
@@ -30,8 +31,14 b' data-read-only={{read_only}}'
30 <div id="tab1">
31 <div id="tab1">
31 {% if logged_in or not read_only %}
32 {% if logged_in or not read_only %}
32 <div id="notebook_toolbar">
33 <div id="notebook_toolbar">
33 <span id="drag_info">Drag files onto the list to import
34
34 notebooks.</span>
35 <form id='alternate_upload' action="notebooks" enctype="multipart/form-data" method="post" class='alternate_upload'>
36 <span id="drag_info" style="position:absolute" >Drag files
37 onto the list, or click here, to import
38 notebooks.</span>
39 <input type="file" name="datafile" class="fileinput">
40 </form>
41
35
42
36 <span id="notebook_buttons">
43 <span id="notebook_buttons">
37 <button id="refresh_notebook_list" title="Refresh notebook list">Refresh</button>
44 <button id="refresh_notebook_list" title="Refresh notebook list">Refresh</button>
General Comments 0
You need to be logged in to leave comments. Login now