handle file upload server responses
[scpubgit/stemmaweb.git] / root / src / index.tt
1 [% WRAPPER header.tt
2         pagetitle = "Stemmaweb - Text tradition tools"
3         applicationjs = c.uri_for( 'js/componentload.js' )
4 %]
5     <script type="text/javascript">
6 var selectedTextID;
7 var selectedStemmaID = -1;
8 var stemmata = [];
9
10 function refreshDirectory () {
11         var lmesg = $('#loading_message').clone();
12         $('#directory').empty().append( lmesg.contents() );
13     $('#directory').load( "[% c.uri_for( 'directory' ) %]", 
14         function(response, status, xhr) {
15                         if (status == "error") {
16                                 var msg = "An error occurred: ";
17                                 $("#directory").html(msg + xhr.status + " " + xhr.statusText);
18                         }
19                 }
20         );
21 }
22
23 function start_upload_dialog() {
24     if( typeof uploader != 'undefined' ){ uploader.destroy() };
25     $('#upload-collation-dialog').dialog('option', 'attach_uploader')();
26     $('#upload_button').button('disable');
27     $('#upload-collation-dialog').dialog('open');
28 }
29
30 $(document).ready( function() {
31     // call out to load the directory div
32     $('#textinfo_container').hide();
33     $('#textinfo_waitbox').hide();
34         refreshDirectory();
35         $('#upload-collation-dialog').dialog({
36                 autoOpen: false,
37                 height: 325,
38                 width: 480,
39                 modal: true,
40                 buttons: {
41                   pick: {
42                     text: "Pick File",
43                     id: "pick_uploadfile_button",
44                     click: function() {}       
45                   },
46                   upload: {
47                     text: 'Upload',
48                     id: 'upload_button',
49                     click: function() {
50                             $('#upload_status').empty();
51                 uploader.start();
52                 return false;
53             }
54                   },
55                   cancel: function() {
56                     $('#upload-collation-dialog').dialog('close');
57                   }
58                 },
59                 attach_uploader: function() {
60                     create_uploader( "[% c.uri_for ( '/newtradition' ) %]" );
61                     $('#filelist').empty().html( 'Use the \'Pick\' button to choose a source fileā€¦' );
62                 }
63         });
64 });
65     </script>
66
67 [% END %]
68
69     <div id="topbanner">
70       <h1>Stemmaweb - a collection of tools for analysis of collated texts</h1>
71       <span class="mainnav">[% IF c.user_exists %]Hello! [% c.user.get_object.email %] <a class="navlink" href="[% c.uri_for( '/logout' ) %]">Sign out</a> | [% ELSE %]<a class="navlink" onclick="window.open('[% c.uri_for( '/login' ) %]', 'loginwindow', 'height=385,width=445')">Login</a> | <a class="navlink" onclick="window.open('[% c.uri_for( '/register' ) %]', 'regwindow', 'height=385,width=445')">Register</a> | [% END %]<a class="navlink" href="[% c.uri_for( 'about.html' ) %]">About</a> </span>
72     </div>
73     <div id="directory_container">
74       <h2>Text directory</h2>
75       <div id="directory"></div>
76 [% IF c.user_exists -%]
77           <div class="button" id="new_trad_button" onClick="start_upload_dialog();">
78             <span>Add a new text tradition</span>
79           </div>
80 [% END %]
81     </div>
82     <div id="textinfo_waitbox">
83         <img src="[% c.uri_for( 'images', 'ajax-loader.gif' ) %]" alt="Loading tradition info..."/>
84     </div>
85     <div id="textinfo_container">
86       <div id="textinfo_load_status"></div>
87       <h2>Text <span class="texttitle"></span></h2>
88       <ul>
89               <li>has <span id="witness_num"></span> witnesses: <span id="witness_list"></span></li>
90               <li>has <span id="reading_num"></span> distinct readings</li>
91               <li>has <span id="relationship_num"></span> distinct reading relationships</li>
92       </ul>
93       
94       <!-- TODO buttons on either side of the graph div to flip through the stemmata -->
95       <div id="textinfo_container_buttons">
96           <form id="stemma_pager" action="" method="GET" name="stemma_pager">
97             <div class="button" id="stemma_pager_button" onClick="$('#stemma_pager').submit()">
98                   <span>Left &amp; right go here</span>
99             </div>
100           </form>
101           <form id="run_stexaminer" action="" method="GET" name="run_stexaminer">
102             <div class="button" id="stexaminer_button" onClick="$('#run_stexaminer').submit()">
103                   <span>Examine variants against this stemma</span>
104             </div>
105           </form>
106           <form id="run_relater" action="" method="GET" name="run_relater">
107             <div class="button" id="relater_button" onClick="$('#run_relater').submit()">
108               <span>Run relationship mapper</span>
109             </div>
110           </form>
111       </div>
112       <div id="stemma_graph"></div>
113     </div>
114
115     <!-- Interim 'loading' message for directory box -->
116     <div id="loading_message">
117         <h3>Loading texts, please wait...</h3>
118         <img src="[% c.uri_for( 'images', 'ajax-loader.gif' ) %]" />
119     </div>
120
121     <!-- File upload dialog box -->
122     <div id="upload-collation-dialog" title="Upload a collation">
123       <div id="upload_container">
124         <form id="new_tradition">
125             <label for="traditionname">Name of this text / tradition: </label>
126             <input id="traditionname" type="text" name="name" size="40"/><br/>
127             <div id="filelist"></div>
128         <form>
129         <div id="upload_status"></div>
130         <div>
131           <h4>Supported file types / extensions:</h4>
132           <ul>
133             <li>*.txt - spreadsheet collation, tab-separated values</li>
134             <li>*.csv - spreadsheet collation, comma-separated values</li>
135             <li>*.xls - spreadsheet collation, Excel 97-2004 format</li>
136             <li>*.xlsx - spreadsheet collation, Excel 2007 XML format</li>
137             <li>*.xml - TEI XML parallel segmentation format</li>
138             <li>*.xml - TEI XML export from Classical Text Editor</li>
139             <li>*.xml - GraphML export from the CollateX tool</li>
140           </ul>
141           <p>All spreadsheet collations should be arranged with the witness sigla in the first row, and the words aligned by row each in its correct witness column.</p>
142         </div>
143       </div>
144     </div>    
145 [% PROCESS footer.tt %]