X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=root%2Fjs%2Frelationship.js;h=e822d70846d717dff217e35738a9dc95e62290b5;hb=f6516f222feb909cd3999fc0ca29ac90311a0266;hp=7f6ed879c165b0ffb576158468bdcc9fe7cb1dfd;hpb=065c7cf2799ee9e71c8ed953bfc0a166e4a6b902;p=scpubgit%2Fstemmaweb.git
diff --git a/root/js/relationship.js b/root/js/relationship.js
index 7f6ed87..e822d70 100644
--- a/root/js/relationship.js
+++ b/root/js/relationship.js
@@ -5,36 +5,23 @@ var start_element_height = 0;
var reltypes = {};
var readingdata = {};
-function getTextPath() {
- var currpath = window.location.pathname;
- // Get rid of trailing slash
- if( currpath.lastIndexOf('/') == currpath.length - 1 ) {
- currpath = currpath.slice( 0, currpath.length - 1)
- };
- // Get rid of query parameters
- if( currpath.lastIndexOf('?') != -1 ) {
- currpath = currpath.slice( 0, currpath.lastIndexOf('?') );
- };
- var path_elements = currpath.split('/');
- var textid = path_elements.pop();
- var basepath = path_elements.join( '/' );
- var path_parts = [ basepath, textid ];
- return path_parts;
-}
-
-function getRelativePath() {
- var path_parts = getTextPath();
- return path_parts[0];
-}
+function arrayUnique(array) {
+ var a = array.concat();
+ for(var i=0; i
') ];
return morphel;
}
+function color_inactive ( el ) {
+ var reading_id = $(el).parent().attr('id');
+ var reading_info = readingdata[reading_id];
+ // If the reading info has any non-disambiguated lexemes, color it yellow;
+ // otherwise color it green.
+ $(el).attr( {stroke:'green', fill:'#b3f36d'} );
+ if( reading_info ) {
+ $.each( reading_info['lexemes'], function ( idx, lex ) {
+ if( !lex['is_disambiguated'] || lex['is_disambiguated'] == 0 ) {
+ $(el).attr( {stroke:'orange', fill:'#fee233'} );
+ }
+ });
+ }
+}
+
+function relemmatize () {
+ // Send the reading for a new lemmatization and reopen the form.
+ $('#relemmatize_pending').show();
+ var reading_id = $('#reading_id').val()
+ ncpath = getReadingURL( reading_id );
+ form_values = {
+ 'normal_form': $('#reading_normal_form').val(),
+ 'relemmatize': 1 };
+ var jqjson = $.post( ncpath, form_values, function( data ) {
+ // Update the form with the return
+ if( 'id' in data ) {
+ // We got back a good answer. Stash it
+ readingdata[reading_id] = data;
+ // and regenerate the morphology form.
+ morphology_form( data['lexemes'] );
+ } else {
+ alert("Could not relemmatize as requested: " + data['error']);
+ }
+ $('#relemmatize_pending').hide();
+ });
+}
+
// Initialize the SVG once it exists
function svgEnlargementLoaded() {
//Give some visual evidence that we are working
@@ -118,11 +179,16 @@ function svgEnlargementLoaded() {
$("#loading_message").offset(
{ 'top': lo_height / 2 - $("#loading_message").height() / 2,
'left': lo_width / 2 - $("#loading_message").width() / 2 });
- //Set viewbox widht and height to widht and height of $('#svgenlargement svg').
- $('#update_workspace_button').data('locked', false);
- $('#update_workspace_button').css('background-position', '0px 44px');
- //This is essential to make sure zooming and panning works properly.
- $('#svgenlargement ellipse').attr( {stroke:'green', fill:'#b3f36d'} );
+ if( editable ) {
+ // Show the update toggle button.
+ $('#update_workspace_button').data('locked', false);
+ $('#update_workspace_button').css('background-position', '0px 44px');
+ }
+ var rdgpath = getTextURL( 'readings' );
+ $.getJSON( rdgpath, function( data ) {
+ readingdata = data;
+ $('#svgenlargement ellipse').each( function( i, el ) { color_inactive( el ) });
+ });
$('#svgenlargement ellipse').parent().dblclick( node_dblclick_listener );
var graph_svg = $('#svgenlargement svg');
var svg_g = $('#svgenlargement svg g')[0];
@@ -137,6 +203,8 @@ function svgEnlargementLoaded() {
}
}
+ //Set viewbox width and height to width and height of $('#svgenlargement svg').
+ //This is essential to make sure zooming and panning works properly.
svg_root.viewBox.baseVal.width = graph_svg.attr( 'width' );
svg_root.viewBox.baseVal.height = graph_svg.attr( 'height' );
//Now set scale and translate so svg height is about 150px and vertically centered in viewbox.
@@ -150,37 +218,51 @@ function svgEnlargementLoaded() {
var transform = 'rotate(0) scale(' + scale + ') translate(4 ' + translate + ')';
svg_g.setAttribute('transform', transform);
//used to calculate min and max zoom level:
- start_element_height = $('#__START__ ellipse')[0].getBBox().height;
+ start_element_height = $('#__START__').children('ellipse')[0].getBBox().height;
add_relations( function() { $('#loading_overlay').hide(); });
+
+ //initialize marquee
+ marquee = new Marquee();
+
}
function add_relations( callback_fn ) {
- var basepath = getRelativePath();
+ // Add the relationship types to the keymap list
+ $.each( relationship_types, function(index, typedef) {
+ li_elm = $('
Error: ' + errobj.error + 'The relationship cannot be made.
' ); - } - } ); + $(evt.target).button("enable"); + }); + $( "#dialog-form" ).dialog( "close" ); + }, 'json' ); + }, + Cancel: function() { + $( this ).dialog( "close" ); + } + }, + create: function(event, ui) { + $(this).data( 'relation_drawn', false ); + $('#rel_type').data( 'changed_after_open', false ); + $.each( relationship_types, function(index, typedef) { + $('#rel_type').append( $('').attr( "value", typedef.name ).text(typedef.name) ); + }); + $.each( relationship_scopes, function(index, value) { + $('#scope').append( $('').attr( "value", value ).text(value) ); + }); + // Handler to clear the annotation field, the first time the relationship is + // changed after opening the form. + $('#rel_type').change( function () { + if( !$(this).data( 'changed_after_open' ) ) { + $('#note').val(''); + } + $(this).data( 'changed_after_open', true ); + }); + }, + open: function() { + relation_manager.create_temporary( $('#source_node_id').val(), $('#target_node_id').val() ); + $(".ui-widget-overlay").css("background", "none"); + $("#dialog_overlay").show(); + $("#dialog_overlay").height( $("#enlargement_container").height() ); + $("#dialog_overlay").width( $("#enlargement_container").innerWidth() ); + $("#dialog_overlay").offset( $("#enlargement_container").offset() ); + $('#rel_type').data( 'changed_after_open', false ); + }, + close: function() { + relation_manager.remove_temporary(); + $( '#status' ).empty(); + $("#dialog_overlay").hide(); + } + }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) { + if( ajaxSettings.url == getTextURL('relationships') + && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) { + var error; + if( jqXHR.responseText.indexOf('do not have permission to modify') > -1 ) { + error = 'You are not authorized to modify this tradition. (Try logging in again?)'; + } else { + try { + var errobj = jQuery.parseJSON( jqXHR.responseText ); + error = errobj.error + 'The relationship cannot be made.'; + } catch(e) { + error = jqXHR.responseText; + } + } + $('#status').append( 'Error: ' + error ); + } + $(event.target).parent().find('.ui-button').button("enable"); + } ); + } + var deletion_buttonset = { + cancel: function() { $( this ).dialog( "close" ); }, + global: function () { delete_relation( true ); }, + delete: function() { delete_relation( false ); } + }; + $( "#delete-form" ).dialog({ autoOpen: false, height: 135, - width: 160, + width: 250, modal: false, - buttons: { - Cancel: function() { - $( this ).dialog( "close" ); - }, - Delete: function() { - form_values = $('#delete_relation_form').serialize(); - ncpath = getTextURL( 'relationships' ); - var jqjson = $.ajax({ url: ncpath, data: form_values, success: function(data) { - $.each( data, function(item, source_target) { - relation_manager.remove( get_relation_id( source_target[0], source_target[1] ) ); - }); - $( "#delete-form" ).dialog( "close" ); - }, dataType: 'json', type: 'DELETE' }); - } - }, create: function(event, ui) { + // TODO What is this logic doing? + // This scales the buttons in the dialog and makes it look proper + // Not sure how essential it is, does anything break if it's not here? var buttonset = $(this).parent().find( '.ui-dialog-buttonset' ).css( 'width', '100%' ); buttonset.find( "button:contains('Cancel')" ).css( 'float', 'right' ); + // A: This makes sure that the pop up delete relation dialogue for a hovered over + // relation auto closes if the user doesn't engage (mouseover) with it. var dialog_aria = $("div[aria-labelledby='ui-dialog-title-delete-form']"); dialog_aria.mouseenter( function() { if( mouseWait != null ) { clearTimeout(mouseWait) }; @@ -680,49 +870,180 @@ $(document).ready(function () { }) }, open: function() { + if( !editable ) { + $( this ).dialog( "option", "buttons", + [{ text: "OK", click: deletion_buttonset['cancel'] }] ); + } else if( $('#delete_relation_scope').text() === 'local' ) { + $( this ).dialog( "option", "width", 160 ); + $( this ).dialog( "option", "buttons", + [{ text: "Delete", click: deletion_buttonset['delete'] }, + { text: "Cancel", click: deletion_buttonset['cancel'] }] ); + } else { + $( this ).dialog( "option", "width", 200 ); + $( this ).dialog( "option", "buttons", + [{ text: "Delete", click: deletion_buttonset['delete'] }, + { text: "Delete all", click: deletion_buttonset['global'] }, + { text: "Cancel", click: deletion_buttonset['cancel'] }] ); + } + mouseWait = setTimeout( function() { $("#delete-form").dialog( "close" ) }, 2000 ); }, - close: function() { - } + close: function() {} + }); + + var multipleselect_buttonset = { + cancel: function() { $( this ).dialog( "close" ); }, + button1: function () { }, + button2: function() { } + }; + + $( "#multipleselect-form" ).dialog({ + autoOpen: false, + height: 150, + width: 250, + modal: true, + create: function(event, ui) { + var buttonset = $(this).parent().find( '.ui-dialog-buttonset' ).css( 'width', '100%' ); + buttonset.find( "button:contains('Cancel')" ).css( 'float', 'right' ); + }, + open: function() { + $( this ).dialog( "option", "width", 200 ); + $( this ).dialog( "option", "buttons", + [{ text: "Button_1", click: multipleselect_buttonset['button1'] }, + { text: "Button_2", click: multipleselect_buttonset['button2'] }, + { text: "Cancel", click: multipleselect_buttonset['cancel'] }] ); + }, + close: function() { marquee.unselect(); } }); - // function for reading form dialog should go here; for now hide the element - $('#reading-form').dialog({ - autoOpen: false, - height: 400, - width: 600, - modal: true, - buttons: { - Cancel: function() { - $( this ).dialog( "close" ); - }, - Update: function() { - form_values = $('#reading_data_form').serialize(); - ncpath = getReadingURL(); - var reading_element = get_node_obj( $('#reading_data_id').val() ); - $(':button :contains("Update")').attr("disabled", true); - var jqjson = $.post( ncpath, form_values, function(data) { - $.each( data, function(key, value) { - reading_element.data( key, value ); + // Helpers for relationship deletion + + function delete_relation( scopewide ) { + form_values = $('#delete_relation_form').serialize(); + if( scopewide ) { + form_values += "&scopewide=true"; + } + ncpath = getTextURL( 'relationships' ); + var jqjson = $.ajax({ url: ncpath, data: form_values, success: function(data) { + $.each( data, function(item, source_target) { + relation_manager.remove( get_relation_id( source_target[0], source_target[1] ) ); + }); + $( "#delete-form" ).dialog( "close" ); + }, dataType: 'json', type: 'DELETE' }); + } + + function toggle_relation_active( node_id ) { + $('#svgenlargement .relation').find( "title:contains('" + node_id + "')" ).each( function(index) { + matchid = new RegExp( "^" + node_id ); + if( $(this).text().match( matchid ) != null ) { + var relation_id = $(this).parent().attr('id'); + relation_manager.toggle_active( relation_id ); + }; + }); + } + + // function for reading form dialog should go here; + // just hide the element for now if we don't have morphology + if( can_morphologize ) { + if( editable ) { + $('#reading_decollate_witnesses').multiselect(); + } else { + $('#decollation').hide(); + } + $('#reading-form').dialog({ + autoOpen: false, + // height: 400, + width: 450, + modal: true, + buttons: { + Cancel: function() { + $( this ).dialog( "close" ); + }, + Update: function( evt ) { + // Disable the button + $(evt.target).button("disable"); + $('#reading_status').empty(); + var reading_id = $('#reading_id').val() + form_values = { + 'id' : reading_id, + 'is_nonsense': $('#reading_is_nonsense').is(':checked'), + 'grammar_invalid': $('#reading_grammar_invalid').is(':checked'), + 'normal_form': $('#reading_normal_form').val() }; + // Add the morphology values + $('.reading_morphology').each( function() { + if( $(this).val() != '(Click to select)' ) { + var rmid = $(this).attr('id'); + rmid = rmid.substring(8); + form_values[rmid] = $(this).val(); + } }); - $( "#reading-form" ).dialog( "close" ); - }); - } - }, - create: function() {}, - open: function() { - $(".ui-widget-overlay").css("background", "none"); - $("#dialog_overlay").show(); - $("#dialog_overlay").height( $("#enlargement_container").height() ); - $("#dialog_overlay").width( $("#enlargement_container").innerWidth() ); - $("#dialog_overlay").offset( $("#enlargement_container").offset() ); - }, - close: function() { - $("#dialog_overlay").hide(); + // Make the JSON call + ncpath = getReadingURL( reading_id ); + var reading_element = readingdata[reading_id]; + // $(':button :contains("Update")').attr("disabled", true); + var jqjson = $.post( ncpath, form_values, function(data) { + $.each( data, function(key, value) { + reading_element[key] = value; + }); + if( $('#update_workspace_button').data('locked') == false ) { + color_inactive( get_ellipse( reading_id ) ); + } + $(evt.target).button("enable"); + $( "#reading-form" ).dialog( "close" ); + }); + // Re-color the node if necessary + return false; + } + }, + create: function() { + if( !editable ) { + // Get rid of the disallowed editing UI bits + $( this ).dialog( "option", "buttons", + [{ text: "OK", click: function() { $( this ).dialog( "close" ); }}] ); + $('#reading_relemmatize').hide(); + } + }, + open: function() { + $(".ui-widget-overlay").css("background", "none"); + $('#reading_decollate_witnesses').multiselect("refresh"); + $('#reading_decollate_witnesses').multiselect("uncheckAll"); + $("#dialog_overlay").show(); + $('#reading_status').empty(); + $("#dialog_overlay").height( $("#enlargement_container").height() ); + $("#dialog_overlay").width( $("#enlargement_container").innerWidth() ); + $("#dialog_overlay").offset( $("#enlargement_container").offset() ); + $("#reading-form").parent().find('.ui-button').button("enable"); + }, + close: function() { + $("#dialog_overlay").hide(); + } + }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) { + if( ajaxSettings.url.lastIndexOf( getReadingURL('') ) > -1 + && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) { + var error; + if( jqXHR.responseText.indexOf('do not have permission to modify') > -1 ) { + error = 'You are not authorized to modify this tradition. (Try logging in again?)'; + } else { + try { + var errobj = jQuery.parseJSON( jqXHR.responseText ); + error = errobj.error + 'The relationship cannot be made.
'; + } catch(e) { + error = jqXHR.responseText; + } + } + $('#status').append( 'Error: ' + error ); + } + $(event.target).parent().find('.ui-button').button("enable"); + }); + } else { + $('#reading-form').hide(); } - }); + $('#update_workspace_button').click( function() { + if( !editable ) { + return; + } var svg_enlargement = $('#svgenlargement').svg().svg('get').root(); mouse_scale = svg_root_element.getScreenCTM().a; if( $(this).data('locked') == true ) { @@ -764,6 +1085,13 @@ $(document).ready(function () { $(this).data('locked', true ); } }); + + if( !editable ) { + // Hide the unused elements + $('#dialog-form').hide(); + $('#update_workspace_button').hide(); + } + $('.helptag').popupWindow({ height:500, @@ -773,17 +1101,6 @@ $(document).ready(function () { scrollbars:1 }); - - function toggle_relation_active( node_id ) { - $('#svgenlargement .relation').find( "title:contains('" + node_id + "')" ).each( function(index) { - matchid = new RegExp( "^" + node_id ); - if( $(this).text().match( matchid ) != null ) { - var relation_id = $(this).parent().attr('id'); - relation_manager.toggle_active( relation_id ); - }; - }); - } - expandFillPageClients(); $(window).resize(function() { expandFillPageClients(); @@ -810,6 +1127,7 @@ function loadSVG(svgData) { } + /* OS Gadget stuff function svg_select_callback(topic, data, subscriberData) {