many small bugfixes to display and server logic
[scpubgit/stemmaweb.git] / root / src / index.tt
CommitLineData
fb6e49b3 1[% WRAPPER header.tt
2 pagetitle = "Stemmaweb - Text tradition tools"
538715bd 3 applicationjs = c.uri_for( 'js/componentload.js' )
fb6e49b3 4%]
5 <script type="text/javascript">
75354c3a 6var basepath = window.location.pathname
7if( basepath.lastIndexOf('/') == basepath.length - 1 ) {
8 basepath = basepath.slice( 0, basepath.length - 1)
9};
f007ac1e 10var selectedTextID;
75354c3a 11var selectedTextInfo;
98a45925 12var selectedStemmaID = -1;
13var stemmata = [];
40ed7ca6 14
15function refreshDirectory () {
04469f3e 16 var lmesg = $('#loading_message').clone();
17 $('#directory').empty().append( lmesg.contents() );
69799996 18 $('#directory').load( "[% c.uri_for( 'directory' ) %]",
19 function(response, status, xhr) {
20 if (status == "error") {
21 var msg = "An error occurred: ";
22 $("#directory").html(msg + xhr.status + " " + xhr.statusText);
23 }
40ed7ca6 24 }
25 );
26}
27
5cc32d47 28function start_upload_dialog() {
29 if( typeof uploader != 'undefined' ){ uploader.destroy() };
30 $('#upload-collation-dialog').dialog('option', 'attach_uploader')();
9f7aeb53 31 $('#upload_status').empty();
5cc32d47 32 $('#upload_button').button('disable');
33 $('#upload-collation-dialog').dialog('open');
34}
35
40ed7ca6 36$(document).ready( function() {
37 // call out to load the directory div
38 $('#textinfo_container').hide();
39 $('#textinfo_waitbox').hide();
40 refreshDirectory();
75354c3a 41
42 // Set up the textinfo edit dialog
43 $('#textinfo-edit-dialog').dialog({
44 autoOpen: false,
45 height: 200,
46 width: 300,
47 modal: true,
48 buttons: {
49 Save: function (evt) {
ce1c5863 50 $("#edit_textinfo_status").empty();
75354c3a 51 $(evt.target).button("disable");
52 var requrl = "[% c.uri_for( '/textinfo' ) %]/" + selectedTextID;
53 var reqparam = $('#edit_textinfo').serialize();
54 $.post( requrl, reqparam, function (data) {
55 // Reload the selected text fields
56 selectedTextInfo = data;
57 load_textinfo();
58 // Reenable the button and close the form
59 $(evt.target).button("enable");
60 $('#textinfo-edit-dialog').dialog('close');
61 }, 'json' );
62 },
63 Cancel: function() {
64 $('#textinfo-edit-dialog').dialog('close');
65 }
66 },
67 open: function() {
68 $("#edit_textinfo_status").empty();
69 // Populate the form fields with the current values
70 // edit_(name, language, public, owner)
71 $.each([ 'name', 'language', 'owner' ], function( idx, k ) {
72 var fname = '#edit_' + k;
ce1c5863 73 // Special case: language Default is basically language null
74 if( k == 'language' && selectedTextInfo[k] == 'Default' ) {
75 $(fname).val( "" );
76 } else {
77 $(fname).val( selectedTextInfo[k] );
78 }
75354c3a 79 });
80 if( selectedTextInfo['public'] == true ) {
81 $('#edit_public').attr('checked','true');
82 } else {
83 $('#edit_public').removeAttr('checked');
84 }
85 },
86 }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
87 $(event.target).parent().find('.ui-button').button("enable");
88 if( ajaxSettings.url.indexOf( 'textinfo' ) > -1
89 && ajaxSettings.type == 'POST' ) {
90 display_error( jqXHR, $("#edit_textinfo_status") );
91 }
92 });
93
94
95 // Set up the stemma editor dialog
96 $('#stemma-edit-dialog').dialog({
97 autoOpen: false,
98 height: 700,
99 width: 600,
100 modal: true,
101 buttons: {
102 Save: function (evt) {
ce1c5863 103 $("#edit_stemma_status").empty();
75354c3a 104 $(evt.target).button("disable");
105 var stemmaseq = $('#stemmaseq').val();
106 var requrl = "[% c.uri_for( '/stemma' ) %]/" + selectedTextID + "/" + stemmaseq;
107 var reqparam = { 'dot': $('#dot_field').val() };
108 // TODO We need to stash the literal SVG string in stemmata
109 // somehow. Implement accept header on server side to decide
110 // whether to send application/json or application/xml?
111 $.post( requrl, reqparam, function (data) {
112 // We received a stemma SVG string in return.
113 // Update the current stemma sequence number
ce1c5863 114 selectedStemmaID = data.stemmaid;
75354c3a 115 // Stash the answer in our SVG array
ce1c5863 116 stemmata[selectedStemmaID] = data.stemmasvg;
75354c3a 117 // Display the new stemma
118 load_stemma( selectedStemmaID );
119 // Reenable the button and close the form
ce1c5863 120 $(evt.target).button("enable");
75354c3a 121 $('#stemma-edit-dialog').dialog('close');
ce1c5863 122 }, 'json' );
75354c3a 123 },
124 Cancel: function() {
125 $('#stemma-edit-dialog').dialog('close');
126 }
127 },
128 open: function(evt) {
129 $("#edit_stemma_status").empty();
130 var stemmaseq = $('#stemmaseq').val();
131 if( stemmaseq == 'n' ) {
132 // If we are creating a new stemma, populate the textarea with a
133 // bare digraph.
134 $(evt.target).dialog('option', 'title', 'Add a new stemma')
135 $('#dot_field').val( "digraph stemma {\n\n}" );
136 } else {
137 // If we are editing a stemma, grab its stemmadot and populate the
138 // textarea with that.
139 $(evt.target).dialog('option', 'title', 'Edit selected stemma')
140 $('#dot_field').val( 'Loading, please wait...' );
141 var doturl = "[% c.uri_for( '/stemmadot' ) %]/" + selectedTextID + "/" + stemmaseq;
142 $.getJSON( doturl, function (data) {
143 // Re-insert the line breaks
144 var dotstring = data.dot.replace(/\|n/gm, "\n");
145 $('#dot_field').val( dotstring );
146 });
147 }
148 },
149 }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
150 $(event.target).parent().find('.ui-button').button("enable");
151 if( ajaxSettings.url.indexOf( 'stemma' ) > -1
152 && ajaxSettings.type == 'POST' ) {
153 display_error( jqXHR, $("#edit_stemma_status") );
154 }
155 });
156
40ed7ca6 157 $('#upload-collation-dialog').dialog({
158 autoOpen: false,
159 height: 325,
160 width: 480,
161 modal: true,
162 buttons: {
5cc32d47 163 pick: {
164 text: "Pick File",
165 id: "pick_uploadfile_button",
166 click: function() {}
167 },
168 upload: {
169 text: 'Upload',
170 id: 'upload_button',
171 click: function() {
172 $('#upload_status').empty();
173 uploader.start();
174 return false;
175 }
176 },
75354c3a 177 Cancel: function() {
5cc32d47 178 $('#upload-collation-dialog').dialog('close');
40ed7ca6 179 }
5cc32d47 180 },
181 attach_uploader: function() {
182 create_uploader( "[% c.uri_for ( '/newtradition' ) %]" );
183 $('#filelist').empty().html( 'Use the \'Pick\' button to choose a source file…' );
40ed7ca6 184 }
5cc32d47 185 });
40ed7ca6 186});
fb6e49b3 187 </script>
188
189[% END %]
190
7439e248 191 <div id="topbanner">
192 <h1>Stemmaweb - a collection of tools for analysis of collated texts</h1>
69799996 193 <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>
7439e248 194 </div>
fb792f63 195 <div id="directory_container">
196 <h2>Text directory</h2>
04469f3e 197 <div id="directory"></div>
98a45925 198[% IF c.user_exists -%]
5cc32d47 199 <div class="button" id="new_trad_button" onClick="start_upload_dialog();">
98a45925 200 <span>Add a new text tradition</span>
201 </div>
202[% END %]
203 </div>
204 <div id="textinfo_waitbox">
75354c3a 205 <h3>Loading tradition information, please wait...</h3>
206 <img src="[% c.uri_for( 'images', 'ajax-loader.gif' ) %]" alt="Loading tradition info..." />
98a45925 207 </div>
208 <div id="textinfo_container">
04469f3e 209 <div id="textinfo_load_status"></div>
98a45925 210 <h2>Text <span class="texttitle"></span></h2>
211 <ul>
75354c3a 212 <li>is owned by <span id="owner_id"></span></li>
213 <li>is <span id="not_public"></span>public</li>
214 <li>has <span id="marked_language"></span> as its primary language</li>
98a45925 215 <li>has <span id="witness_num"></span> witnesses: <span id="witness_list"></span></li>
98a45925 216 </ul>
217
218 <!-- TODO buttons on either side of the graph div to flip through the stemmata -->
a35b3190 219 <div id="textinfo_container_buttons">
75354c3a 220 <form id="open_textinfo_edit" action="" method="GET" name="edit_textinfo">
221 <div class="button" id="edit_textinfo_button"
222 onClick="$('#textinfo-edit-dialog').dialog('open')">
223 <span>Modify information about this tradition</span>
224 </div>
225 </form>
a35b3190 226 <form id="stemma_pager" action="" method="GET" name="stemma_pager">
227 <div class="button" id="stemma_pager_button" onClick="$('#stemma_pager').submit()">
228 <span>Left &amp; right go here</span>
229 </div>
230 </form>
75354c3a 231 <form id="open_stemma_add" action="" method="GET" name="add_new_stemma">
232 <div class="button" id="stemma_add_button"
233 onClick="$('#stemmaseq').val('n'); $('#stemma-edit-dialog').dialog('open');">
234 <span>Add a new stemma</span>
235 </div>
236 </form>
237 <form id="open_stemma_edit" action="" method="GET" name="edit_current_stemma">
238 <div class="button" id="stemma_edit_button"
239 onClick="$('#stemmaseq').val(selectedStemmaID); $('#stemma-edit-dialog').dialog('open');">
240 <span>Edit this stemma</span>
241 </div>
242 </form>
a35b3190 243 <form id="run_stexaminer" action="" method="GET" name="run_stexaminer">
244 <div class="button" id="stexaminer_button" onClick="$('#run_stexaminer').submit()">
245 <span>Examine variants against this stemma</span>
246 </div>
247 </form>
248 <form id="run_relater" action="" method="GET" name="run_relater">
249 <div class="button" id="relater_button" onClick="$('#run_relater').submit()">
250 <span>Run relationship mapper</span>
251 </div>
252 </form>
253 </div>
98a45925 254 <div id="stemma_graph"></div>
7439e248 255 </div>
fb6e49b3 256
04469f3e 257 <!-- Interim 'loading' message for directory box -->
258 <div id="loading_message">
259 <h3>Loading texts, please wait...</h3>
75354c3a 260 <img src="[% c.uri_for( 'images', 'ajax-loader.gif' ) %]" alt="Loading tradition list..."/>
261 </div>
262
263 <!-- Textinfo editor dialog -->
264 <div id="textinfo-edit-dialog" title="Edit information about this tradition">
265 <div id="textinfo_edit_container">
266 <form id="edit_textinfo">
267 <label for="edit_name">Tradition name: </label>
268 <input id="edit_name" type="text" size="30" name="name"/><br/>
269 <label for="edit_language">Language: </label>
270 <input id="edit_language" type="text" size="12" name="language"/>
271 <label for="edit_public">Publicly viewable: </label>
272 <input id="edit_public" type="checkbox" name="public"/><br/>
273[% IF c.user_exists -%]
274[% IF c.user.get_object.is_admin -%]
ce1c5863 275 <label for="edit_owner">Tradition owner: </label>
75354c3a 276 <input id="edit_owner" type="text" size="30" name="owner"/><br/>
277[% END -%]
278[% END -%]
279 </form>
280 <div id="edit_textinfo_status"></div>
281 </div>
282 </div>
283
284 <!-- Stemma dot editor dialog, simple textarea for now -->
285 <div id="stemma-edit-dialog">
286 <div id="stemma_edit_container">
287 <form id="edit_stemma">
288 <label for="dot_field">Dot definition for this stemma: </label><br/>
289 <textarea id="dot_field" rows="30" cols="40"></textarea>
290 <input id="stemmaseq" type="hidden" name="stemmaseq" val="n"/>
291 <div id="edit_instructions">
292 <p>All definitions begin with the line
293 <pre>digraph stemma {</pre>
294 and end with the line
295 <pre>}</pre>Please do not change these lines.</p>
296 <p>First list each witness in your stemma, whether extant or lost /
297 reconstructed / hypothetical, and assign them a class of either "extant"
298 or "hypothetical". For example:</p><pre>
299 α [ class=hypothetical ]
300 C [ class=extant ]
301 </pre>
302 <p>Next, list the direct links between witnesses, one per line. For example, if
303 witness C descends directly from witness α, note it as follows:</p><pre>
304 α -> C
305 </pre>
306 <p>A witness may be the exemplar for any number of other witnesses, whether
307 extant or not; likewise, a witness may inherit from any number of other
308 witnesses. Use as may "A -> B" pairings as necessary to describe the links.</p>
309 </div>
310 </form>
311 <div id="edit_stemma_status"></div>
312 </div>
04469f3e 313 </div>
40ed7ca6 314
315 <!-- File upload dialog box -->
316 <div id="upload-collation-dialog" title="Upload a collation">
5cc32d47 317 <div id="upload_container">
318 <form id="new_tradition">
75354c3a 319 <label for="new_name">Name of this text / tradition: </label>
320 <input id="new_name" type="text" name="name" size="40"/><br/>
321 <label for="new_lang">Primary language of the text: </label>
322 <input id="new_lang" type="text" name="language" size="20"/><br/>
323 <label for="new_public">Allow public display: </label>
324 <input id="new_public" name="public" type="checkbox"/><br/>
5cc32d47 325 <div id="filelist"></div>
326 <form>
327 <div id="upload_status"></div>
40ed7ca6 328 <div>
329 <h4>Supported file types / extensions:</h4>
330 <ul>
331 <li>*.txt - spreadsheet collation, tab-separated values</li>
332 <li>*.csv - spreadsheet collation, comma-separated values</li>
333 <li>*.xls - spreadsheet collation, Excel 97-2004 format</li>
334 <li>*.xlsx - spreadsheet collation, Excel 2007 XML format</li>
335 <li>*.xml - TEI XML parallel segmentation format</li>
336 <li>*.xml - TEI XML export from Classical Text Editor</li>
337 <li>*.xml - GraphML export from the CollateX tool</li>
338 </ul>
339 <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>
340 </div>
5cc32d47 341 </div>
40ed7ca6 342 </div>
fb6e49b3 343[% PROCESS footer.tt %]